-
Notifications
You must be signed in to change notification settings - Fork 8
/
crinkler-manual.txt
1218 lines (956 loc) · 55.3 KB
/
crinkler-manual.txt
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
CRINKLER - Compressing linker for Windows specialized for 4k intros
Aske Simon Christensen "Blueberry/Loonies"
Rune L. H. Stubbe "Mentor/TBC"
Version 2.3 (July 21, 2020)
Web: http://crinkler.net/
GitHub: https://github.com/runestubbe/Crinkler
Forum: http://www.pouet.net/prod.php?which=18158
Mail: [email protected]
VERSION HISTORY
---------------
21.07.20: 2.3: Crinkler is now open source under the Zlib license!
/TINYHEADER size reduced by another 3 bytes.
Faster hash size optimization, especially with many cores.
Include function name in unresolved symbol error message.
Automatically import from msvcrt. No need for lib any more.
Built-in, minimal console statup code supplying args to main.
Disable built-in startup and msvcrt import via /NODEFAULTLIB.
Support more kinds of lib files (from rustc, for instance).
Don't crash on missing export table (for Wine kernel32.dll).
Only write one dump file if several threads crash.
15.06.19: 2.2: /TINYHEADER decompression code is 6 bytes smaller.
Fixed memory size increase of recompressed /TINYHEADER intros.
19.01.19: 2.1a: Fixed width of report to make room for the 32 hex columns.
/REUSEMODE:WRITE to write the reuse file without reading it.
18.12.18: 2.1: Crinkler executable built for both 32 bit and 64 bit.
New, slightly different model estimation. 8-12x speedup.
Optimized section reordering. About 3-4x speedup.
Optimized and multi-threaded hash size optimization.
New /COMPMODE:VERYSLOW option for a few extra bytes.
Changed default compression mode to SLOW.
Changed default HASHSIZE to 500 and HASHTRIES to 100.
/REUSE option: Use models and ordering from last run.
/REUSEMODE:STABLE to quickly iterate when making changes.
/REUSEMODE:IMPROVE to improve upon previous compression.
Print output file size in report.
More compact bits-per-byte color legend in report.
Choose configuration instead of hiding/showing in report.
32 column hex view and other adjustments in report.
Avoid crash if an existing file could not be opened.
Updated internal function list to Windows version 1809.
28.03.18: 2.0a: Fixed Crinkler crash on recent Windows SDK versions.
Fixed Crinkler crash on forwards from ole32.dll.
Corrected horizontal alignment issue in HTML report.
Support forwarded RVA imports with /TINYIMPORT.
Fixed spurious import of MessageBox with /TINYIMPORT.
Print compatibility warning when using /TINYIMPORT.
Updated internal function list to Windows version 1803.
Extended description in the manual of /TINYIMPORT.
Updated download link for the lib file for msvcrt.dll.
28.07.15: 2.0: /TINYHEADER option: smaller decompressor for 1k intros.
/TINYIMPORT option: smaller import code for 1k intros.
/EXPORT option to export code and data symbols.
/SATURATE option to saturate context counters.
/FALLBACKDLL option for when a DLL is not available.
/UNALIGNCODE option to set alignment of all code to 1.
Support for /REPLACEDLL during recompression.
Consistent size between model estimation and reordering.
Header size reduced by 2 bytes.
Print previous size of output file.
Accept version specifier after /SUBSYSTEM value.
Switched from Intel OpenMP to MSVC concurrency API.
19.01.13: 1.4: Output EXE files work with recent NVIDIA drivers.
New zero-section header layout saving around 30-50 bytes.
Forwarded RVA imports supported via link-time forwarding.
Dynamic C++ initializers supported.
Support for producing Large Address Aware executables.
Crinkler is Large Address Aware, handling larger inputs.
Report all unresolved symbols and the location of each.
Better resolving of ambiguous label references in report.
Various adjustments to textual output.
/RECOMPRESS overwrites input file by default.
05.03.11: 1.3: Fixed Crinkler crash on some AMD systems.
Header size reduced by 21 bytes.
Slightly improved model hash function.
/OVERRIDEALIGNMENTS option to specify label alignments.
No limit on the number of calls in call transform.
Import code and entry point movable by section reordering.
Fixed bug in handling of files with absolute path.
Fixed labels in report showing up in the wrong section.
Crinkler writes .dmp files in case of a crash.
05.09.09: 1.2: Output EXE files are now Windows 7 compatible.
Output EXE files are no longer Windows 2000 compatible.
Header size reduced by 16 bytes.
Non-range import code is (usually) slightly smaller.
Slightly improved section ordering estimation.
/RECOMPRESS option to recompress Crinkler-compressed
executables, optionally with different parameters.
/FIX removed, as it is subsumed by /RECOMPRESS.
14.01.09: 1.1a: Fixed /TRUNCATEFLOATS crashing in some cases.
Improved /ORDERTRIES estimation when call transform is used.
Sometimes sections were misplaced in the HTML report.
Various improvements to the HTML report.
The /FIX option can input and output to the same file.
Helpful error messages for various unsupported features.
Prefer a custom entry point to a standard library one.
New section in the manual about runtime libraries.
12.01.08: 1.1: Support for weak externals (virtual C++ destructors).
Fixed compatibility with Data Execution Prevention.
/REPORT option for a colorful HTML compression report.
/TRUNCATEFLOATS option to mutilate float constants.
/SAFEIMPORT is now default, disabled with /UNSAFEIMPORT.
Slightly smaller overhead if range importing is not used.
Fixed some problems with compressing very small files.
/VERBOSE:FUNCTIONS removed, as it is subsumed by /REPORT.
Remaining /VERBOSE options renamed to /PRINT.
Maximum number of ORDERTRIES increased to 100000.
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 nonexistent 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 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 employed on their 4k intros (in particular import by ordinal)
caused severe compatibility problems. More often than not, people
who wanted to run a newly released 4k intro found that it did not
work on their own machine. It became customary to include a
'compatible' version in the distribution which was larger than 4k
but worked on all machines. For a time, it seemed that the term
'4k intro' meant '4k on the compo machine' intro.
The main motivation for starting the Crinkler project was the feeling
that the existing means available for compressing 4k intros were
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 file compressor for Windows 4k intros.
COMPATIBILITY
-------------
The goal of Crinkler is for the produced EXE files to be compatible
with all widely used Windows versions and configurations. As of
version 2.0a, the EXE files produced by Crinkler are, to the best of
our knowledge, compatible with Windows XP, Windows Vista, Windows 7,
Windows 8 and Windows 10, both 32 bit and 64 bit versions. They are
compatible with Data Execution Prevention and with execution hooks
that inspect the import or export table of launched executables
(graphics drivers are known to do this).
It is not a primary goal of Crinkler to anticipate incompatibilities
that may arise in the future as a consequence of new Windows versions,
graphics drivers or other widespread system changes. Guaranteeing such
compatibility would require Crinkler to follow the EXE file format
specification to the letter, precluding most of the header hacks that
Crinkler utilizes in order to reduce the size overhead of the EXE
format as much as possible. Rather, we strive to continually monitor
the compatibility situation and release a new, fixed version of
Crinkler whenever a situation arises that affects the compatibility
severely (such as a new, incompatible version of Windows). This has
occurred several times already throughout the history of Crinkler.
Each new version of Crinkler not only produces executables that are
compatible with the current majority of targeted systems. It also
includes a way of fixing old Crinkler executables to have the same
level of compatibility. See the section on recompression for more
details on this feature.
This compatibility strategy ensures that intros made using Crinkler
will continue to be accessible to their audience, even if the Windows
EXE loader changes in an incompatible way that could not be
anticipated at the time the intro was produced.
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. This space is used for some of the decompression code.
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 to
make Visual Studio use Crinkler for linking is the following:
- Copy crinkler.exe to your project directory or to some other
directory of your choice and rename it to link.exe. 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.
- For Visual Studio 2008 and older, select Tools/Options... and go to
Projects and Solutions/VC++ Directories. For Visual Studio 2010 or
newer, open a project, select View/Property Manager, expand a project
and a configuration, double click on Microsoft.Cpp.Win32.user and go
to Common Properties/VC++ Directories.
- At the top of the list for Executable files, add the directory where
you placed Crinkler named link.exe, or add $(SolutionDir) to make it
search in the project directory.
- 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. Also set
Linker/Manifest File/Generate Manifest to No and
C/C++/Optimization/Whole Program Optimization 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.
Crinkler automatically links to msvcrt.dll - the Visual Studio 6
runtime library. You don't need to specify a library file for this.
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.
/LARGEADDRESSAWARE
/LARGEADDRESSAWARE:NO
(Linker/System/Enable Large Addresses)
Specify whether the executable is able to handle addresses above
2 gigabytes. If this option is enabled, the executable will be able
to allocate close to 4 gigabytes of memory.
/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.
If you use the CONSOLE subsystem without changing the entry point from
its default value and don't define mainCRTStartup yourself, Crinkler
will insert a small entry point that will read the commandline and
call main with the usual argc and argv parameters.
/NODEFAULTLIB
(Linker/Input/Ignore All Default Libraries)
Disable the automatic linking against msvcrt.dll and the automatic
insertion of mainCRTStartup for CONSOLE 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.
/RECOMPRESS
Decompress a Crinkler-compressed executable and recompress it
using the given options. The resulting executable will have the
same level of compatibility as one produced directly by the
current version of Crinkler. See the section on compatibility for
more information on the compatibility of Crinkler-produced
executables.
When this option is specified, Crinkler takes a single file
argument, which must be an EXE file produced by Crinkler 0.4 or
newer.
See the section on recompression below for a description of the
options that can be given to control the decompression process.
/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
/COMPMODE:VERYSLOW
Choose between four different algorithms for the model estimation.
The FAST compression mode performs a very quick estimation, whereas
the SLOW mode takes up to some tens of seconds for a typical 4k,
but also compresses significantly better. VERYSLOW is about 5-10x
slower than SLOW and typically a few bytes better. INSTANT skips
model estimation entirely and just uses a fixed set of models and
weights. It also skips section reordering and hash table size
optimization. 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 SLOW.
/SATURATE
The compressor and decompressor use pairs of 8-bit counters to
track the distributions of 0 and 1 bits for each context. If your
data is very repetitive (contains large blocks of the same pattern
of values repeated over and over again), these counters may wrap
around, which can sometimes hurt compression of these repetitive
areas.
This option inserts extra code in the decompression header to keep
these counters from wrapping. It is worth trying out if you have
large, repetitive regions and see in the compression report that
the data in these regions suddenly jumps up from lightest green to
slightly darker green for no apparent reason.
/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.
/TINYHEADER
Enables an alternative compression algorithm trading off some
compression efficiency for an even smaller decompression overhead.
This can be beneficial when targeting extremely small file sizes
such as 1kb. The simpler decompressor gathers statistics by
repeated linear searches instead of hashing. This results in
an O(n^2) decompression time which can become prohibitively slow
for files significantly larger than 1kb.
The COMPMODE, HASHSIZE, HASHTRIES, REUSE, SATURATE and EXPORT
options are ignored when TINYHEADER is enabled.
/TINYIMPORT
Enables a more compact, but less future-proof, function importing
scheme which does not require the explicit storage of function
name hashes. This is achieved by indiscriminately importing every
function from the relevant DLLs. The imported functions are
scattered in an import table based on their function name hashes.
Intuitively, this embeds the hash code entropy directly into the
call instruction.
Crinkler ensures that the import table size and hash function are
chosen such that there are no collisions between the functions
used by the linked program and other functions which are imported
later from the DLLs. This way, the desired function pointers will
be intact in the import table.
However, Crinkler can only ensure this for functions that it knows
about. These include the functions present in the DLLs on the
system on which Crinkler is run, plus an internal list consisting
of functions from commonly imported DLLs covering most supported
Windows versions available at the time of release (Spring Creators
Update 2018 version 1803 as of Crinkler 2.0a).
Thus, this import technique is less resilient to changes in
future windows versions, since when functions are added in a
future version of the DLL, they may collide with functions used by
the program, in which case the program will cease to work.
Programs broken this way cannot be fixed by recompression.
When using this options, it is strongly recommended to also
distribute safe versions using ths normal import mechanism.
The UNSAFEIMPORT, FALLBACKDLL and RANGE options are ignored
when TINYIMPORT is enabled.
/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.
Crinkler starts from a heuristic ordering (the one used when
initially estimating models) and incrementally makes small, random
changes to the ordering to see if it can find one that compresses
better.
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.
/REUSE:[reuse parameter file name]
/REUSEMODE:STABLE
/REUSEMODE:IMPROVE
/REUSEMODE:WRITE
/REUSEMODE:OFF
After compression, write information about the selected models,
the ordering of sections and the optimized hash table size to a
text file with the specified name. If the file exists already,
use the parameters in the file as input to the compression in a
manner dependent on the chosen REUSEMODE:
With STABLE (the default), skip all model estimation, section
reordering and hash table size optimization and simply use the
parameters exactly as in the file. Keep the reuse file as is.
This option can be used to try out small changes to the contents
of the code and data with a stable compression. Thus, it gives
a much more reliable estimation of whether the change was an
improvement or not. It is also useful as a way to compress very
quickly after the first time with a similar compression ratio.
With IMPROVE, only the section ordering from the file is reused,
and a normal compression procedure is performed. If section
reordering is enabled, it starts from the ordering in the reuse
file and tries to optimize the ordering based on that. The file is
written back only if the final file size is smaller than what
the parameters in the reuse file would have given (which is not
necessarily the size of the existing file, depending on what
changes and operations are performed in the meantime).
The option can be used to check whether better parameters can be
found than the ones cached in the reuse file. It is also a way to
run some extra reordering iterations (if reordering is enabled)
to see if this improves compression.
For both modes, it can be useful to edit the reuse file by hand
to try out parameters manually or to nudge Crinkler in some
direction.
With WRITE, the reuse file is not read, but is still written
after compression, overwriting the file if it exists. This can be
conveniently used when reuse is not desired, such that it can be
switched on at any time (by changing the reuse mode to STABLE or
IMPROVE) without needing another compression run.
With OFF, it is as if no reuse file is specified. This is simply
a way to disable the option without removing the file from the
commandline.
If COMPMODE is set to INSTANT, the reuse mode is also considered
to be OFF.
/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. A typical use
is to replace 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.
/FALLBACKDLL:[firstDLL]=[otherDLL]
If firstDLL fails to load, try loading otherDLL and import the
functions from there instead. For instance, to use d3dcompiler_47
when available but fall back to d3dcompiler_43 otherwise (since
the shader compiler in d3dcompiler_47 is much faster), link
to d3dcompiler_47 and use:
/FALLBACKDLL:d3dcompiler_47=d3dcompiler_43
The FALLBACKDLL option can be used together with REPLACEDLL to
specify a primary DLL other than the one your SDK links to. For
instance, if you are using the legacy DirectX SDK (which links to
d3dcompiler_43) and want to have the above prioritization, use:
/REPLACEDLL:d3dcompiler_43=d3dcompiler_47
/FALLBACKDLL:d3dcompiler_47=d3dcompiler_43
Arbitrarily long chains of DLL fallback can be used by specifying
the FALLBACKDLL option multiple times, though the chains can of
course not be cyclic.
/EXPORT:[name]
/EXPORT:[name]=[symbol]
/EXPORT:[name]=[value]
Include an export table into the executable, containing an export
with the given name.
The first version exports an existing symbol under its existing
name. The second version exports an existing symbol under a
different name. The third version creates a 32-bit integer with
the given value and exports it under the given name. The value
can be specified in octal (prefixed with 0), decimal or hexadecimal
(prefixed with 0x) format.
The first version is compatible with the VS linker, but there is
currently no specific field for it in the configuration window.
The export table will be compressed along with the other data
in the executable and decompressed to the memory address specified
in the export table pointer in the PE header. Thus, the exports
defined this way are only visible to code inspecting the export
table after decompression has taken place.
For PE header technical reasons, all exports must be placed earlier
in memory than the export table. Thus, only symbols in the code and
data sections can be exported. If an uninitialized (BSS) symbol is
exported, it will be automatically moved to the data section (with
a warning). Beware that this will move the whole section containing
the symbol, so other symbols might be moved along with it.
The EXPORT option can be used to signal to the graphics driver that
your program desires to run on the high-performance GPU in a multi-
GPU system. This saves the user from having to right-click on the
executable and select "Run with graphics processor...".
To request high performance on NVIDIA Optimus systems, use:
/EXPORT:NvOptimusEnablement=1
To request high performance on AMD PowerXpress/Enduro systems, use:
/EXPORT:AmdPowerXpressRequestHighPerformance=1
An arbitrary number of exports can be specified, so the two high
performance declarations can be used together if you have space
enough to spare.
/UNSAFEIMPORT
If the executable fails to load some DLL, it will normally pop up
a message box with the DLL name. This option disables this check
to save a few bytes (usually around 20). With unsafe import, the
executable will crash if a needed DLL is not found.
/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.
/NOINITIALIZERS
Disable the inclusion of dynamic C++ initializers. The default is
to insert calls to each of the initializers just before the entry
point.
/TRUNCATEFLOATS:[number of bits]
Floating point constants can take up a significant amount of space
in an intro, and often much of this space is wasted because the
constants have more precision than needed. Typically, many bytes
can be saved by rounding floating point constants to "nice" values
- that is, values where many bits in the mantissa are zero.
However, such rounding is cumbersome, especially when the
constants are written in decimal notation.
The purpose of the /TRUNCATEFLOATS option is to automate this
rounding process. When this option is given, Crinkler tries to
identify float and double constants and round them to the number
of bits given (between 1 and 64). If no number is given, 64 is
assumed.
Typically, object files do not contain any information about what
data is floating point constants and what is not (though the file
format does support such information). This means that in order to
identify floating point constants, Crinkler has to resort to
heuristics based on label names. These heuristics are able to
recognize constants in code and some variables, but far from all.
You can tell Crinkler explicitly that some variable contains float
data and how much it should be truncated by having the variable
name (or label) start with tf[n]_ where [n] is the number of bits
to truncate the constants to. The number of bits can be omitted,
in which case the number of bits given in the argument to
/TRUNCATEFLOATS is used. Such variables will still only be
truncated if the /TRUNCATEFLOATS option is given. Example:
const float tf14_positions[] = { 0.1f, 0.35f, 0.25f };
This will truncate the constants in the table to 14 bits (5 bits
of mantissa), resulting in the values 0.099609375, 0.3515625 and
0.25, respectively. Tip: rather than changing the variable name
and all references to it each time you want to change the
truncation precision, use a define:
#define positions tf14_positions
Note that /TRUNCATEFLOATS is an unstable and highly experimental
feature. Make sure to test the compressed file to verify that the
result is acceptable. Remember to include the musician in this
verification process. :)
/OVERRIDEALIGNMENTS:[bits of alignment]
It is often possible to improve compression by placing
uninitialized variables at addresses divisible by high powers of
two, since this will cause all references to these addresses to
contain more zeros.
The PE file format only supports up to 13 bits of alignment
(8192), and some tools do not even expose this support fully (for
instance, Nasm only supports alignments up to 64). Usually, much
higher alignments are desirable.
Crinkler supports explicit alignment of labels at up to one
gigabyte (30 bits). When you specify the /OVERRIDEALIGNMENTS
option, Crinkler will look for labels containing the string
align[n] where [n] is the number of bits of alignment desired
(e.g. 8 for 256-byte alignment). It will then align the section
containing that label such that the label address is divisible by
2^[n]. The label does not have to be at the beginning of the
section, but there can be at most one explicitly aligned label in
each section.
The alignment specifier can optionally include an alignment
offset, specified by the string align[n]_[m] where [n] is the
number of bits of alignment and [m] is the offset in bytes. This
will place the label [m] bytes after an aligned address, i.e. such
that the address minus [m] is divisible by 2^[n].
If a numerical argument is given to /OVERRIDEALIGNMENTS, all
uninitialized sections which do not contain an explicitly aligned
label will be aligned to the given number of bits (if larger than
their original alignment). If the option is specified without
argument, uninitialized sections which do not contain an
explicitly aligned label will be aligned as specified in the
object file, as normally.
A convenient way to specify explicit alignments in C++ code is in
a header file included by all files in the project, containing
definitions like this:
#define MusicBuffer MusicBuffer_align24
In assembler files, alignments can be specified as local labels:
MusicBuffer:
.align24
; buffer space here
Explicit alignment can be used on code and data sections as well,
except for the section containing the entry point, which will
always be 1-byte aligned. The space between the sections will be
padded with zero bytes.
/UNALIGNCODE
Force all code sections to use alignment of 1, eliminating all
padding between them. This usually improves compression, but
can result in slightly lower performance if some functions are
called in performance critical loops.
The /OVERRIDEALIGNMENTS mechanism has priority over /UNALIGNCODE,
so if you want to excempt a few functions from being unaligned,
you can specify an explicit alignment for these as described for
/OVERRIDEALIGNMENTS.
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:
/REPORT:[HTML file name]
Write an HTML file with a detailed, colorful, interactive report
on the compression result. The code section will be shown as hex
dump and disassembly of the code, and the data section will be
shown as hex and ascii dump. All bytes will be colored to show how
much that byte was compressed. This report can be useful in
determining which parts of the executable take up the most space
and which things to change to reduce the size.
/PRINT:LABELS
Print a list of all labels in the program along with uncompressed
and compressed sizes for the data between the labels. This is a
stripped down version of the information provided by the /REPORT
option.
/PRINT:IMPORTS
List all functions imported from DLLs. The functions are grouped
by DLL, and functions imported by ordinal range import are grouped
into ranges.
/PRINT: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 /PRINT:IMPORTS /PRINT: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
RECOMPRESSION
-------------
A new feature in Crinkler 1.2 is the abillity to recompress an already
Crinkler-compressed executable. The main purpose for the feature is to
patch an executable compressed using an earlier version of Crinkler so
that it runs on recent Windows versions. But it can also be used
more generally to change some of the compression parameters of a
compressed program without performing the whole linking and
compression process from scratch and without access to the original
object files. Particularly, if your output executable after a long
time spent compressing is just a few bytes too big due to bytes lost
to hashing, you can recompress the output executable, specifying a
higher value for /HASHSIZE and/or /HASHTRIES, and thus avoid running
through the whole compression process again.
Recompression mode is activated by the /RECOMPRESS option. When this
option is specified, Crinkler takes a single file argument, which must
be an EXE file produced by Crinkler 0.4 or newer. Most options then
take on slightly different meanings, as described here.
The /CRINKLER, /PRIORITY, @commandfile and /PROGRESSGUI options work
as normally. The /ENTRY, /LIBPATH, /ORDERTRIES, /RANGE, /FALLBACKDLL,
/UNSAFEIMPORT, /TRANSFORM:CALLS, /NOINITIALIZERS, /TRUNCATEFLOATS,
/OVERRIDEALIGNMENTS, /UNALIGNCODE, /TINYHEADER and /TINYIMPORT options
are ignored, as the parameters specified by these options cannot be
changed via recompression. The /PRINT options are also ignored. The
remaining options work as follows:
/SUBSYSTEM:CONSOLE
/SUBSYSTEM:WINDOWS
If this option is given, it specifies the Windows subsystem to use
as normally. If it is omitted, the original subsystem will be
used.
/LARGEADDRESSAWARE
/LARGEADDRESSAWARE:NO
If this option is given, it specifies large address awareness of the
executable as normally. If it is omitted, the original large address
awareness will be used.
/OUT:[file]
Specify the name of the resulting executable file. The default is
to overwrite the input file.
/COMPMODE:INSTANT
/COMPMODE:FAST
/COMPMODE:SLOW
/COMPMODE:VERYSLOW
If this option is specified, the compression models will be
reestimated using the specified compression mode. If the option is
omitted, the models used for the original compression will be used
for the recompression, and no model estimation will be performed.
If the executable was originally produced by Crinkler 1.0 or
newer, this will typically yield a compression ratio similar to
the original compression.
/SATURATE
/SATURATE:NO
If this option is given, it specifies saturation as normally. If
it is omitted, the original saturation mode will be used.
/HASHSIZE:[memory size]
If neither this option nor a compression mode is specified, the
original, optimized hash size will be used. Recompression speed
will be similar to INSTANT compression mode in this case.
If a compression mode is specified but this option is omitted,
hash size optimization will be performed using the hash size
specified for the original file.
If this option is given, hash size optimization takes place