file_id.diz
GNU GENERAL PUBLIC LICENSE
Version 2, June 1991
Copyright (C) 1989, 1991 Free Software Foundation, Inc.
59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
Everyone is permitted to copy and distribute verbatim copies
of this license document, but changing it is not allowed.
Preamble
The licenses for most software are designed to take away your
freedom to share and change it. By contrast, the GNU General Public
License is intended to guarantee your freedom to share and change free
software--to make sure the software is free for all its users. This
General Public License applies to most of the Free Software
Foundation's software and to any other program whose authors commit to
using it. (Some other Free Software Foundation software is covered by
the GNU Library General Public License instead.) You can apply it to
your programs, too.
When we speak of free software, we are referring to freedom, not
price. Our General Public Licenses are designed to make sure that you
have the freedom to distribute copies of free software (and charge for
this service if you wish), that you receive source code or can get it
if you want it, that you can change the software or use pieces of it
in new free programs; and that you know you can do these things.
To protect your rights, we need to make restrictions that forbid
anyone to deny you these rights or to ask you to surrender the rights.
These restrictions translate to certain responsibilities for you if you
distribute copies of the software, or if you modify it.
For example, if you distribute copies of such a program, whether
gratis or for a fee, you must give the recipients all the rights that
you have. You must make sure that they, too, receive or can get the
source code. And you must show them these terms so they know their
rights.
We protect your rights with two steps: (1) copyright the software, and
(2) offer you this license which gives you legal permission to copy,
distribute and/or modify the software.
Also, for each author's protection and ours, we want to make certain
that everyone understands that there is no warranty for this free
software. If the software is modified by someone else and passed on, we
want its recipients to know that what they have is not the original, so
that any problems introduced by others will not reflect on the original
authors' reputations.
Finally, any free program is threatened constantly by software
patents. We wish to avoid the danger that redistributors of a free
program will individually obtain patent licenses, in effect making the
program proprietary. To prevent this, we have made it clear that any
patent must be licensed for everyone's free use or not licensed at all.
The precise terms and conditions for copying, distribution and
modification follow.
GNU GENERAL PUBLIC LICENSE
TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION
0. This License applies to any program or other work which contains
a notice placed by the copyright holder saying it may be distributed
under the terms of this General Public License. The "Program", below,
refers to any such program or work, and a "work based on the Program"
means either the Program or any derivative work under copyright law:
that is to say, a work containing the Program or a portion of it,
either verbatim or with modifications and/or translated into another
language. (Hereinafter, translation is included without limitation in
the term "modification".) Each licensee is addressed as "you".
Activities other than copying, distribution and modification are not
covered by this License; they are outside its scope. The act of
running the Program is not restricted, and the output from the Program
is covered only if its contents constitute a work based on the
Program (independent of having been made by running the Program).
Whether that is true depends on what the Program does.
1. You may copy and distribute verbatim copies of the Program's
source code as you receive it, in any medium, provided that you
conspicuously and appropriately publish on each copy an appropriate
copyright notice and disclaimer of warranty; keep intact all the
notices that refer to this License and to the absence of any warranty;
and give any other recipients of the Program a copy of this License
along with the Program.
You may charge a fee for the physical act of transferring a copy, and
you may at your option offer warranty protection in exchange for a fee.
2. You may modify your copy or copies of the Program or any portion
of it, thus forming a work based on the Program, and copy and
distribute such modifications or work under the terms of Section 1
above, provided that you also meet all of these conditions:
a) You must cause the modified files to carry prominent notices
stating that you changed the files and the date of any change.
b) You must cause any work that you distribute or publish, that in
whole or in part contains or is derived from the Program or any
part thereof, to be licensed as a whole at no charge to all third
parties under the terms of this License.
c) If the modified program normally reads commands interactively
when run, you must cause it, when started running for such
interactive use in the most ordinary way, to print or display an
announcement including an appropriate copyright notice and a
notice that there is no warranty (or else, saying that you provide
a warranty) and that users may redistribute the program under
these conditions, and telling the user how to view a copy of this
License. (Exception: if the Program itself is interactive but
does not normally print such an announcement, your work based on
the Program is not required to print an announcement.)
These requirements apply to the modified work as a whole. If
identifiable sections of that work are not derived from the Program,
and can be reasonably considered independent and separate works in
themselves, then this License, and its terms, do not apply to those
sections when you distribute them as separate works. But when you
distribute the same sections as part of a whole which is a work based
on the Program, the distribution of the whole must be on the terms of
this License, whose permissions for other licensees extend to the
entire whole, and thus to each and every part regardless of who wrote it.
Thus, it is not the intent of this section to claim rights or contest
your rights to work written entirely by you; rather, the intent is to
exercise the right to control the distribution of derivative or
collective works based on the Program.
In addition, mere aggregation of another work not based on the Program
with the Program (or with a work based on the Program) on a volume of
a storage or distribution medium does not bring the other work under
the scope of this License.
3. You may copy and distribute the Program (or a work based on it,
under Section 2) in object code or executable form under the terms of
Sections 1 and 2 above provided that you also do one of the following:
a) Accompany it with the complete corresponding machine-readable
source code, which must be distributed under the terms of Sections
1 and 2 above on a medium customarily used for software interchange; or,
b) Accompany it with a written offer, valid for at least three
years, to give any third party, for a charge no more than your
cost of physically performing source distribution, a complete
machine-readable copy of the corresponding source code, to be
distributed under the terms of Sections 1 and 2 above on a medium
customarily used for software interchange; or,
c) Accompany it with the information you received as to the offer
to distribute corresponding source code. (This alternative is
allowed only for noncommercial distribution and only if you
received the program in object code or executable form with such
an offer, in accord with Subsection b above.)
The source code for a work means the preferred form of the work for
making modifications to it. For an executable work, complete source
code means all the source code for all modules it contains, plus any
associated interface definition files, plus the scripts used to
control compilation and installation of the executable. However, as a
special exception, the source code distributed need not include
anything that is normally distributed (in either source or binary
form) with the major components (compiler, kernel, and so on) of the
operating system on which the executable runs, unless that component
itself accompanies the executable.
If distribution of executable or object code is made by offering
access to copy from a designated place, then offering equivalent
access to copy the source code from the same place counts as
distribution of the source code, even though third parties are not
compelled to copy the source along with the object code.
4. You may not copy, modify, sublicense, or distribute the Program
except as expressly provided under this License. Any attempt
otherwise to copy, modify, sublicense or distribute the Program is
void, and will automatically terminate your rights under this License.
However, parties who have received copies, or rights, from you under
this License will not have their licenses terminated so long as such
parties remain in full compliance.
5. You are not required to accept this License, since you have not
signed it. However, nothing else grants you permission to modify or
distribute the Program or its derivative works. These actions are
prohibited by law if you do not accept this License. Therefore, by
modifying or distributing the Program (or any work based on the
Program), you indicate your acceptance of this License to do so, and
all its terms and conditions for copying, distributing or modifying
the Program or works based on it.
6. Each time you redistribute the Program (or any work based on the
Program), the recipient automatically receives a license from the
original licensor to copy, distribute or modify the Program subject to
these terms and conditions. You may not impose any further
restrictions on the recipients' exercise of the rights granted herein.
You are not responsible for enforcing compliance by third parties to
this License.
7. If, as a consequence of a court judgment or allegation of patent
infringement or for any other reason (not limited to patent issues),
conditions are imposed on you (whether by court order, agreement or
otherwise) that contradict the conditions of this License, they do not
excuse you from the conditions of this License. If you cannot
distribute so as to satisfy simultaneously your obligations under this
License and any other pertinent obligations, then as a consequence you
may not distribute the Program at all. For example, if a patent
license would not permit royalty-free redistribution of the Program by
all those who receive copies directly or indirectly through you, then
the only way you could satisfy both it and this License would be to
refrain entirely from distribution of the Program.
If any portion of this section is held invalid or unenforceable under
any particular circumstance, the balance of the section is intended to
apply and the section as a whole is intended to apply in other
circumstances.
It is not the purpose of this section to induce you to infringe any
patents or other property right claims or to contest validity of any
such claims; this section has the sole purpose of protecting the
integrity of the free software distribution system, which is
implemented by public license practices. Many people have made
generous contributions to the wide range of software distributed
through that system in reliance on consistent application of that
system; it is up to the author/donor to decide if he or she is willing
to distribute software through any other system and a licensee cannot
impose that choice.
This section is intended to make thoroughly clear what is believed to
be a consequence of the rest of this License.
8. If the distribution and/or use of the Program is restricted in
certain countries either by patents or by copyrighted interfaces, the
original copyright holder who places the Program under this License
may add an explicit geographical distribution limitation excluding
those countries, so that distribution is permitted only in or among
countries not thus excluded. In such case, this License incorporates
the limitation as if written in the body of this License.
9. The Free Software Foundation may publish revised and/or new versions
of the General Public License from time to time. Such new versions will
be similar in spirit to the present version, but may differ in detail to
address new problems or concerns.
Each version is given a distinguishing version number. If the Program
specifies a version number of this License which applies to it and "any
later version", you have the option of following the terms and conditions
either of that version or of any later version published by the Free
Software Foundation. If the Program does not specify a version number of
this License, you may choose any version ever published by the Free Software
Foundation.
10. If you wish to incorporate parts of the Program into other free
programs whose distribution conditions are different, write to the author
to ask for permission. For software which is copyrighted by the Free
Software Foundation, write to the Free Software Foundation; we sometimes
make exceptions for this. Our decision will be guided by the two goals
of preserving the free status of all derivatives of our free software and
of promoting the sharing and reuse of software generally.
NO WARRANTY
11. BECAUSE THE PROGRAM IS LICENSED FREE OF CHARGE, THERE IS NO WARRANTY
FOR THE PROGRAM, TO THE EXTENT PERMITTED BY APPLICABLE LAW. EXCEPT WHEN
OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR OTHER PARTIES
PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED
OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE ENTIRE RISK AS
TO THE QUALITY AND PERFORMANCE OF THE PROGRAM IS WITH YOU. SHOULD THE
PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF ALL NECESSARY SERVICING,
REPAIR OR CORRECTION.
12. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING
WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY AND/OR
REDISTRIBUTE THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES,
INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING
OUT OF THE USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED
TO LOSS OF DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY
YOU OR THIRD PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER
PROGRAMS), EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE
POSSIBILITY OF SUCH DAMAGES.
END OF TERMS AND CONDITIONS
How to Apply These Terms to Your New Programs
If you develop a new program, and you want it to be of the greatest
possible use to the public, the best way to achieve this is to make it
free software which everyone can redistribute and change under these terms.
To do so, attach the following notices to the program. It is safest
to attach them to the start of each source file to most effectively
convey the exclusion of warranty; and each file should have at least
the "copyright" line and a pointer to where the full notice is found.
<one line to give the program's name and a brief idea of what it does.>
Copyright (C) <year> <name of author>
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
Also add information on how to contact you by electronic and paper mail.
If the program is interactive, make it output a short notice like this
when it starts in an interactive mode:
Gnomovision version 69, Copyright (C) year name of author
Gnomovision comes with ABSOLUTELY NO WARRANTY; for details type `show w'.
This is free software, and you are welcome to redistribute it
under certain conditions; type `show c' for details.
The hypothetical commands `show w' and `show c' should show the appropriate
parts of the General Public License. Of course, the commands you use may
be called something other than `show w' and `show c'; they could even be
mouse-clicks or menu items--whatever suits your program.
You should also get your employer (if you work as a programmer) or your
school, if any, to sign a "copyright disclaimer" for the program, if
necessary. Here is a sample; alter the names:
Yoyodyne, Inc., hereby disclaims all copyright interest in the program
`Gnomovision' (which makes passes at compilers) written by James Hacker.
<signature of Ty Coon>, 1 April 1989
Ty Coon, President of Vice
This General Public License does not permit incorporating your program into
proprietary programs. If your program is a subroutine library, you may
consider it more useful to permit linking proprietary applications with the
library. If this is what you want to do, use the GNU Library General
Public License instead of this License.
Sources for Rose Shank, a 4k intro for Assembly 2007
-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
Intro by:
Jere Sanisalo - http://www.xmunkki.org
Jetro Lauha - http://jet.ro
Source release and the IL4 compiler by:
Jere Sanisalo - http://www.xmunkki.org
Introduction
-=-=-=-=-=-=
Rose Shank was an experimental 4k intro. The experiment was to see if it was
feasible to build a small virtual machine with a custom bytecode to run the
intro, and if it was easier/smaller. It was a given that faster it is not. :)
This language was named IL4 Lisp-ahtava (the compiler is called il4c). As the
name says, the language uses the lisp syntax as its syntax. That's about all
there's common to it. The reason the lisp parantheses syntax was chosen, was
to facilitate fast turnabout while developing the language further (adding new
constructs was a lot easier this way, as the lexer/parser stayed the same).
Overview
-=-=-=-=
Il4c reads and parses all the given source files given to it at once. The files
are interpreted as if they were joined together, and all symbols are globally
visible. IL4 then performs a number of simple optimizations over the code.
This includes stripping functions that are never called. Not much is done to
the actual code. This gives greater control to the IL4 programmer (for example
in C a small change may make a huge effect on the inlining and code size in
general). All inlining and such should be done by hand. Il4c then generates a
suitable bytecode for the remaining code. Only the operations that are needed
are assigned a bytecode. As a last step, il4c generates one assembly file
"out.asm" which contains both the generated bytecode interpreter and the
actual bytecode. This asm file is designed to be compiled by nasm. The linker
used may be the microsoft linker, but Crinkler is the only linker ever tested
with il4c.
To compile Rose Shank, run compile.sh with cygwin. You may need to modify it
to set the correct library paths (uses the win32 libraries from Visual Studio).
IL4
-=-
A few words about the IL4 language (as there is virtually no ducmentation
about it) to get the prominent reader started.
Start from "test.il4" (the startup function "main" is there) and "core.il4"
(most of the basic math functions and such are there).
Comments start with a # char and go up to the end of the line.
The language is totally untyped (well, strictly speaking the type is
"32-bits" :). That means you have to be careful to call the right arithmetic
and comparison functions (as well as others). The values may very well be
pointers, integers, floats or whatever.
On the top level an IL4 file may contain roughly the following elements:
- Constants. When referenced, the reference is replaced with the constant
value. These are just handy shorthands for giving names to numbers.
Example:
(const pi 3.1415926535897932384626433832795)
- Global variables. These may have a constant value set to them or not.
Example:
(var room_floor_lights)
(var cam_ang 0.0)
- Bytecode functions. These take 0 or more arguments, then execute the code
in their body.
Example:
# Random function returning a float with an integer interval [mini,maxi[.
(fun rand_rangef (mini maxi)
i2f (rand_range mini maxi))
Notes on example:
"i2f" is a function that takes one argument, and it changes an integer
to a float. "rand_range" is another function that takes 2 arguments.
- Assembly functions. These are special functions. When called, these
functions compile to one bytecode, and their raw assembly is executed
instead. The code is copied as-is to the final output to the relevant
location. Note that the arguments are passed to the stack from left to
right (for asmfuns); that is, pop eax would pop the last argument. It's
assumed that every asmfun pops all of their arguments from the stack, and
place one value to the stack after they're done (every function returns
something always).
Example:
(asmfun +i (a b)
"pop eax"
"add [esp], eax")
- Compiler directives. Currently there is only one, "heapsize". This isn't
used in Rose Shank, but it sets the amount of heap to allocate for the
executable. The allocator in Rose Shank is a simple pointer incrementer,
so make sure you have enough heap so the pointer doesn't grow over it.
Most of the things inside function bodies are:
- Other function calls
- "(if (expr) (then) (else))" where "expr", "then" and "else" are some code
blocks.
- Variable definitions (same as globals but inside functions).
- Variable sets, "(set var-name value)"
- While loops, "(while (expr) code)"
This is the only looping mechanism in IL4.
- External symbol pointer lookups, "(external_symbol "_wglCreateContext@4)"
This compiles directly to a constant value, which is a pointer to the
symbol. This helper form is used to call external C/asm functions.
- Stdcalls/Cdecl calls. Some examples:
(fun glVertex3fv (arr) (stdcall (external_symbol "_glVertex3fv@4") arr))
(fun glViewport (x y w h) (stdcall (external_symbol "_glViewport@16") x y w h))
There are different forms for functions which return a floating point value,
namely "stdcall-fp" and "cdecl-fp".
Tips
-=-=
Modify the compile.sh script and change the parameters a little. There are a
few optimizations which really made the packed code bigger (even though the
raw object file was smaller). Also the "-save-debug" switch is useful as it
saves the middle forms (tree forms before/after optimization) for the program.
"il4c -help" gives the list of command line options.
Read & try to understand the generated "out.asm" file. Some quick notes about
it:
- Every assembly function end with a "jmp ebx"
- Every opcode has a 16bit loopup index to it's code
- Every bytecode function has a 16bit lookup index to it's code
- Every bytecode function has 16bits of function header and one return
bytecode at the end (8bit); total overhead 3 bytes
- Constants currently take 4 bytes each.
- Every global that has a preset value takes 4 bytes (even if the same value
is used as a constant elsewhere).
- Globals that have no preset values take no space.
Doubles were a bit hacked in (as the general type is "32-bits"). The only
functions that required doubles in Rose Shank were OpenGL calls which follow
the stdcall calling convention. What we do, is use a asmfun which converts a
float to a double on the stack. Because the stdcall convention requires for
the function to clean it's own arguments, this hack works (as the correct
amount of items are on the stack after the call).
To compile the HD version, modify compile.sh to use "resolution_hd.il4"
instead of "resolution.il4".
License
-=-=-=-
These sources and the IL4 compiler are released under the GPLv2 license (see
LICENSE.txt).
Contact
-=-=-=-
Web: http://www.xmunkki.org/
"Rose Shank" by XZM & tAAt
4k intro for Assembly 2007
Coded with Lisp-ahtava (IL4).
Websites for contacting us
--------------------------
Jere Sanisalo - http://www.xmunkki.org
Jetro Lauha - http://jet.ro
Credits
-------
Created by:
Jere "XMunkki" Sanisalo
Jetro "tonic" Lauha
Acknowledgements:
Dibhda - Design help.
st Rana - Design help.
Sol - Absolutely nothing.
The excellent Crinkler was used to compress the intro:
http://www.crinkler.net
This product has been verified to be compliant with
Assembly rules and regulations.
CRINKLER - Compressing linker for Windows specialized for 4k intros
Aske Simon Christensen "Blueberry/Loonies"
Rune L. H. Stubbe "Mentor/TBC"
Version 1.0a (January 7, 2007)
VERSION HISTORY
---------------
07.01.07: 1.0a: New /VERBOSE:FUNCTIONS options to sort the functions.
Various verbose output fixes.
Various crash fixes.
A fix to the /FIX Crinkler version recognizer.
27.12.06: 1.0: Output EXE files are now Windows Vista compatible.
Compression tweak for greatly improved compression ratio.
Much faster compression.
Automatically takes advantage of multiple processors.
Improved Visual Studio 2005 integration.
/COMPMODE:INSTANT option for very quick compression.
/ORDERTRIES option to try out different section orderings.
/SAFEIMPORT option to insert a check for nonexisting DLLs.
/PROGRESSGUI option for a graphical progress bar.
/REPLACEDLL option to replace one DLL with another.
/FIX option to fix compatibility problems of older versions.
09.02.06: 0.4a: Fixed linker crash problem with blank member entries
in some library files (such as glut32).
The /PRIORITY option was not mentioned in the
commandline usage help.
18.12.05: 0.4: Changed header and import code to make output EXE files
compatible with 64-bit versions of Windows.
Fixed a bug in the ordinal range import mechanism.
Added a switch to control the process priority.
Added a warning for range import of an unused DLL.
Some more header squeezing.
31.10.05: 0.3: Output EXE files are now Windows 2000 compatible.
Added a number of verbose options to output useful
information about the program being compressed.
Added an option for transforming function calls to
use absolute offsets to improve compression.
Fixed a bug in the linker regarding identically named
sections.
Fixed a potential crash bug in the linker.
Various small tweaks and optimizations.
23.07.05: 0.2: Fixed bug in the decompressor.
Changed the behaviour of the /CRINKLER option.
Added timing to the progress bars.
Some updates to the manual and usage description.
21.07.05: 0.1: First release.
BACKGROUND
----------
Ever since the concept of size-limited demo competitions was
introduced in the early 1990's (and before that as well), people have
been using executable file compressors to reduce the size of their
final executables. An executable file compressor is a program that
takes as input an executable file and produces a new executable file
which has the same behaviour as the original one but is (hopefully)
smaller.
The usual technique employed by executable file compressors is to
compress the contents of the executable file using some general
purpose data compression method and prepend to this compressed data a
small piece of code (the decompressor) which decompresses the contents
into memory in such a way that it looks to the code as if the original
executable file had been loaded into memory in the normal way.
The size of the decompressor is usually around a few hundred bytes,
depending on the complexity of the compression method. This
constitutes an unavoidable overhead in the compressed file, which is
particularly evident for small files, such as 4k intros. Furthermore,
the header of the Windows EXE file format contains a lot of
information that needs to be there at fixed offsets in order for
Windows to be able to load the file. The presence of these overheads
from the header and decompressor has motivated people to look for
other means of compressing their 4k intros.
Until Crinkler came around, the most popular strategy for compressing
4k intros for Windows was CAB dropping: A few simple transformations
are performed on the executable to make it compress better (such as
merging sections and setting unused header fields to zero), and the
result is compressed using the Cabinet Compression tool included with
Windows. The resulting .CAB file is renamed to have .BAT extension,
and some commands are inserted into the file such that when the .BAT
file is executed, it decompresses the executable to disk (using the
Cabinet decompression command), runs the executable and then deletes
the executable again. This saves the size of the decompression code
(since an external program is used to do the decompression) and some
of the size of the header (since the header can be compressed).
Various dropping strategies combined with other space-saving hacks
people have employed on their 4k intros (in particular import by
ordinal) have caused severe compatibility problems. More often than
not, people who want to run a newly released 4k intro find that it
does not work on their own machine. In recent years, it has been
customary to include a 'compatible' version in the distribution which
is larger than 4k but works on all machines. The term '4k intro' seems
to mean '4k on the compo machine' intro.
The main motivation for starting the Crinkler project has been the
feeling that the existing means available for compressing 4k intros
are unsatisfactory. We want 4k intros that are self-contained EXE
files. We want 4k intros that are 4 kilobytes in size. Our aim for
Crinkler is to be the cleanest, most effective and most compatible
executable compressor for Windows 4k intros.
INTRODUCTION
------------
Crinkler is a different approach to executable file compression. While
an ordinary executable file compressor operates on the executable file
produced by the linker from object files, Crinkler replaces the linker
by a combined linker and compressor. The result is an EXE file which
does not do any kind of dropping. It decompresses into memory like a
traditional executable file compressor.
Crinkler employs a range of techniques to reduce the size of the
resulting EXE file beyond what is usually obtained by using CAB
compression:
- Having control over the linking step gives much more flexibility in
the optimizations and transformations possible on the data before
and after compression.
- The compression technique used by Crinkler is based on context
modelling, which is far superior in compression ratio to the LZ
variants used by CAB and most other compressors. The disadvantage of
context modelling is that it is extremely slow, but this is of
little importance when only 4 kilobytes need to be compressed. It
also needs quite a lot of memory for decompression, but this is
again not a problem, since the typical 4k intro uses a lot of memory
anyway.
- The actual compression algorithm performs many passes over the data
in order to optimize the internal parameters of the compressor. This
results in slower compression, but this is usually a reasonable
price to pay for the extra bytes gained on the file size.
- The contents of the executable are split into two parts - a code
part and a data part - and each of these are compressed
individually. This leads to better compression, as code and data are
usually very different in structure and so do not benefit from being
compressed together.
- DLL functions are imported by hash code. This is robust to
structural changes to the DLL between different versions while being
quite compact - only 4 bytes per imported function. For DLLs with
fixed relative ordinals (such as opengl32), a special technique,
ordinal range import, can be used to further reduce the number of
hash codes needed.
- Much of the data in the EXE header is actually ignored by the EXE
loader. Some of this space is used for some of the decompression
code, and the rest is used to store hash codes for imported
functions.
Using Crinkler is somewhat different from using an ordinary executable
file compressor because of the linking step. In the following
sections, we describe its use in detail.
INSTALLATION
------------
To use as a stand-alone linker, Crinkler does not need any
installation. Simply run crinkler.exe from the commandline with
appropriate arguments, as described in the next section.
However, if you are using Microsoft Visual Studio to develop your
intro, the easiest way to use Crinkler is to run it in place of the
normal Visual Studio linker. Crinkler has been designed as a drop-in
replacement of the Visual Studio linker, supporting the same basic
options. All of the options can then be set using the Visual Studio
configuration window.
Unfortunately, Visual Studio does not (as of this writing) support
replacing its linker by a different one. So what you have to do is the
following:
- Copy crinkler.exe to your project directory and rename it to
link.exe. Visual Studio will then find it when it tries to invoke
the linker. If you are using some other linker with a different
name, such as the one used with the Intel C++ compiler, call it
whatever the name of the linker is.
- If you are using Visual Studio 2005, select Tools/Options... and go
to Projects and Solutions/VC++ Directories. At the top of the list
for Executable files, add $(SolutionDir). This will make sure that
the project directory is searched for the linker executable.
- In the Release configuration (or whichever configuration you want to
enable compression), under Linker/Command Line/Additional Options,
type in /CRINKLER, along with any other Crinkler options you want to
set. See the next section for more details on options. If you are
using Visual Studio 2005, set Linker/Manifest File/Generate Manifest
to No.
If you have Visual Studio installed but want to run Crinkler from the
commandline, the easiest way is to use the Visual Studio Command
Prompt (available from the Start menu), since this sets up the LIB
environment variable correctly. You can read off the value of the
environment variables by running the 'set' command in this command
prompt. If you are using a different command prompt, you will have to
set up the LIB environment variable manually, or use the /LIBPATH
option.
USAGE
-----
The general form of the command line for Crinkler is:
CRINKLER [options] [object files] [library files] [@commandfile]
When running from within Visual Studio, the object files will be the
ones generated from the sources in the project. The library files will
be the standard set of Win32 libraries, plus any additional library
files specified under Linker/Input/Additional Dependencies. If you are
using a standard runtime library, such as libc or msvcrt, you will
have to specify this one manually.
The following options are compatible with the VS linker and can be set
using switches in the Visual Studio configuration window:
/SUBSYSTEM:CONSOLE
/SUBSYSTEM:WINDOWS
(Linker/System/SubSystem)
Specify the Windows subsystem to use. If the subsystem is CONSOLE,
a console window will be opened when the program starts. The
subsystem also determines the name of the default entry point (see
/ENTRY). The default subsystem is WINDOWS.
/OUT:[file]
(Linker/General/Output File)
Specify the name of the resulting executable file. The default
name is out.exe.
/ENTRY:[symbol]
(Linker/Advanced/Entry Point)
Specify the entry label in the code. The default entry label is
mainCRTStartup for CONSOLE subsystem applications and
WinMainCRTStartup for WINDOWS subsystem applications.
/LIBPATH:[path]
(Linker/General/Additional Library Directories)
Add a number of directories (separated by semicolons) to the ones
searched for library files. If a library is not found in any of
these, the directories mentioned in the LIB environment variable
are searched.
@commandfile
Commandline arguments will be read from the given file, as if they
were given directly on the commandline.
In addition to the above options, a number of options can be given to
control the compression process. These can be specified under
Linker/Command Line/Additional Options:
/CRINKLER
Enable the Crinkler compressor. If this option is disabled,
Crinkler will search through the path for a command with the same
name as itself, skipping itself, and pass all arguments on to this
command instead. This will normally invoke the Visual Studio
linker. If the name of the Crinkler executable is crinkler.exe,
this option is enabled by default, otherwise it is disabled by
default.
/FIX
Fix a program compressed using an older version of Crinkler so
that it works on all versions of Windows 2000, XP and Vista. When
this option is specified, all other options except /OUT are
ignored, and Crinkler takes a single file argument, which must be
an output EXE file from Crinkler 0.3 or newer.
/PRIORITY:IDLE
/PRIORITY:BELOWNORMAL
/PRIORITY:NORMAL
Select the process priority at which Crinkler will run while
compressing. The default priority is BELOWNORMAL. Use IDLE if you
want Crinkler to disturb you as little as possible. Use NORMAL if
you don't need your machine for anything else while compressing.
/COMPMODE:INSTANT
/COMPMODE:FAST
/COMPMODE:SLOW
Choose between three different compression modes. The FAST mode
usually compresses in a couple of seconds, while the SLOW one can
take up to a few minutes to complete. The slow one usually
compresses about 10-40 bytes better on a 4k executable. Use
INSTANT if you just want to check that your program works in
compressed form and don't care about the size. The default
compression mode is FAST.
/HASHSIZE:[memory size]
Specify the amount of memory the decompressor is allowed to use
while decompressing, in megabytes. In general, the more memory the
decompressor is allowed to use, the better the compression ratio
will be, though only slightly. The memory requirements of the
final executable (the size of the executable image when loaded
into memory) will be the maximum of this value and the original
image size. The memory will not be deallocated until the program
terminates, and any heap allocation the program performs will add
to this memory usage. The default value is 100, which is usually a
good compromise.
/HASHTRIES:[number of retries]
Specify the number of different hash table sizes the compressor
will try in order to find one with few collisions. More tries lead
to longer compression time but slightly better compression. The
default value is 20. Higher values rarely improve the size by more
than a few bytes.
/ORDERTRIES:[number of retries]
Specify the number of section reordering iterations that the
linker will try out in search for the ordering that gives the best
compression ratio. The default is not to do any reordering.
Specifying this option drastically increases the compression time,
since Crinkler has to calculate the compressed size anew on every
reordering. Usually, the size does not improve noticeably after a
few thousand iterations.
/RANGE:[DLL name]
Import functions from the given DLL (without the .dll suffix)
using ordinal range import. Ordinal range import imports the first
used function by hash and the rest by ordinal relative to the
first one. Ordinal range import is safe to use on DLLs in which
the ordinals are fixed relative to each other, such as opengl32 or
d3dx9_??. This option can be specified multiple times, for
different DLLs.
/REPLACEDLL:[oldDLL=newDLL]
Whenever a function is imported from oldDLL, import it from newDLL
instead. DLL replacement is useful when the end user might not
have the version of the DLL that you are linking to. Typical
examples are replacing msvcr70, msvcr71 or msvcr80 by msvcrt and
replacing one version of d3dx9_?? by another. Only use this option
if you know that the two DLLs are compatible. When REPLACEDLL and
RANGE are used together, RANGE must refer to the new DLL.
/SAFEIMPORT
If the executable fails to load some DLL, it will pop up a message
box with the DLL name rather than crash. This will increase the
file size by around 20 bytes.
/TRANSFORM:CALLS
Change the relative jump offsets in all internal call instructions
(E8 opcode) into absolute offsets from the start of the code. This
usually improves compression, since multiple calls to the same
function become identical. The transformation has an overhead of
about 20 bytes for the detransformation code, but the net savings
on a full 4k can be as large as 50 bytes, depending on the number
of calls in your code.
Finally, Crinkler has a number of options for controlling the output
during compression. Just like the other options, these can be
specified under Linker/Command Line/Additional Options:
/VERBOSE:FUNCTIONS
/VERBOSE:FUNCTIONS-BYNAME
/VERBOSE:FUNCTIONS-BYSIZE
For each function in the program, output the size of the function
in bytes before and after compression. This can help you decide
whether specific optimizations you try out on your code are
worthwhile. Note that the compressed size of a function depends
heavily on what comes before it. If you have two almost identical
functions, the second one will be much smaller, since the contents
of the first one will guide the compression of the second.
By default, the functions are written in the order in which they
occur in the linked code. If you specify -BYNAME or -BYSIZE, they
will be sorted in alphabetical order or by decreasing compressed
size, respectively.
For this option to work, you must enable debugging information in
your object files. In Visual Studio, this is done by selecting a
debugging information format under C/C++/General/Debug Information
Format. Any format other than Disbled will work.
/VERBOSE:LABELS
As /VERBOSE:FUNCTIONS, but instead of showing the size of
functions, the sizes between every label is shown. This will show
the sizes of code as well as data and does not require any
debugging information apart from the labels.
/VERBOSE:IMPORTS
List all functions imported from DLLs. The functions are grouped
by DLL, and functions imported by ordinal range import are grouped
into ranges.
/VERBOSE:MODELS
List the model masks and weights selected by the compressor. This
is mostly for internal use.
/PROGRESSGUI
Open a window showing a graphical progress indicator.
An example commandline for linking and compressing an intro could look
like this (split on multiple lines for readability):
crinkler.exe /OUT:micropolis.exe /SUBSYSTEM:WINDOWS /RANGE:opengl32
/COMPMODE:SLOW /ORDERTRIES:1000 /VERBOSE:IMPORTS /VERBOSE:LABELS
kernel32.lib user32.lib gdi32.lib opengl32.lib glu32.lib winmm.lib
micropolis\startup.obj micropolis\render.obj
micropolis\render-asm.obj micropolis\sound.obj
micropolis\sound-asm.obj
RECOMMENDATIONS
---------------
There are a number of things you can do as intro programmer to boost
the compression achieved by Crinkler even further. This section
gives some advice on these.
- Do not use a standard runtime library. If you really need some
standard library functions, use msvcrt.lib and use your own entry
point using the /ENTRY option. This will skip the standard startup
code, saving you around half a kilobyte.
- Since much of the effectiveness of Crinkler comes from separating
code and data into different parts of the file and compressing each
part individually, it is important that this separation is
possible. Mark your code and data sections as containing code and
data, respectively, and do not put both code and data into the same
section. See your assembler manual for information about how to do
this. For instance, in Nasm, you can write the keyword "text" or
"data" after the section name and give sections different names to
prevent them from being merged by the assembler.
- Split both your code and your data into as many sections as
possible. This gives Crinkler more opportunities to select the
ordering of the sections to optimize the compression ratio.
- If you are using OpenGL, use ordinal range import for opengl32. If
you are using Direct3D, use ordinal range import for d3dx9_??. This
drastically reduces the space needed for function hash codes.
- Avoid large blocks of data, even if they are all zero. Use
uninitialized (bss) sections instead. Crinkler does not cope well
with large amounts of data. Be aware that the compressor may use an
amount of memory up to about 4000 times the uncompressed code/data
size (whichever is largest).
- When you perform detailed size comparisons, always use the SLOW
compression mode with plenty of HASHTRIES. The INSTANT and FAST
modes are only intended for use during testing and to give a rough
estimate of the compressed size. Also note that the compression is
tuned for the 4k size target, so any size comparisons you perform on
smaller files might turn out to behave differently when you get
nearer to 4k.
- As a matter of good conduct, always use SAFEIMPORT if you can spare
the space, and do not set HASHSIZE higher than you need. In other
words, if your final intro is well below the size limit, enable
SAFEIMPORT and then lower HASHSIZE in order not to waste memory
unnecessarily.
COMMON PROBLEMS, KNOWN BUGS AND LIMITATIONS
-------------------------------------------
Any DLL that is needed by a program that Crinkler compresses must be
available to Crinkler itself. If you get the error message 'Could not
open DLL ...', it means that Crinkler needed the DLL but could not
find it. You must place it either in the same directory as the
Crinkler executable or somewhere in the DLL path, such as
C:\WINDOWS\system32. Alternatively, you can use the REPLACEDLL option
to replace it by one that is available.
If you launch your Crinkler-compressed program from within Visual
Studio, use Start Without Debugging (Ctrl+F5) rather than Start
Debugging (F5). The debugger cannot handle Crinkler-compressed
executables. If the program crashes, you can still attach the debugger
in the normal way.
When running inside Visual Studio, the textual progress bars are not
updated correctly, since the Visual Studio console does not flush the
output until a newline is reached, even when explicitly flushed by the
running program. Use the /PROGRESSGUI option to get a graphical
progress bar.
The code for parsing object and library files contains only a minimum
of sanity checks. If you pass a corrupt file to Crinkler, it will most
likely crash.
The import code does not support forwarded RVA imports, which means
that some functions, such as HeapAlloc, cannot be used. This makes
Crinkler unable to link with libc. What a loss.
The final compressed size must be less than 64k, or Crinkler will fail
horribly. You shouldn't use it for such big files anyway.
Crinkler does not support the whole program optimization feature of
Visual Studio (General/Whole Program Optimization). Do not turn it on.
SUPPORT
-------
Try out Crinkler, and let us know what you think about it. If you have
any problems, comments or suggestions, please write a message at the
Pouet.net forum:
http://www.pouet.net/prod.php?which=18158
If you want to contact us directly, e.g. for sending us a file, write
to authors@crinkler.net.
The newest released version of Crinkler can always be found at
http://www.crinkler.net.
ACKNOWLEDGEMENTS
----------------
The compression technique used by Crinkler is much inspired by the PAQ
compressor by Matt Mahoney.
The import code is loosely based on the hashed imports code by Peci.
Many thanks to all the people who have given us comments, bug reports
and test material, especially to Rambo, Kusma, Polaris, Gargaj,
Frenetic, Buzzie, Shash, Auld, Minas, Skarab, Dwing, Freak5, Hunta,
Snq, Darkblade, Abductee, Las and Hitchhikr. Also thanks to Dwarf,
Polygon7 and Gargaj for suggestions for our web design.
Our special thanks to the many people who have demostrated the
usefulness of Crinkler by using it for their own productions.
Keep it going! We greatly appreciate your feedback.