/OPT:REF | NOREF /OPT:ICF[=iterations] | NOICF] /OPT:WIN98 | NOWIN98
/OPT controls the optimizations that LINK performs during a build. Optimizations generally decrease the image size and increase the program speed, at a cost of increased link time.
LINK removes unreferenced packaged functions by default. An object contains packaged functions (COMDATs) if it has been compiled with the /Gy option. This optimization is called transitive COMDAT elimination. To override this default and keep unreferenced COMDATs in the program, specify /OPT:NOREF. You can use the /INCLUDE option to override the removal of a specific symbol.
If the /DEBUG option is specified, the default for /OPT changes from REF to NOREF, and all functions are preserved in the image. To override this default and optimize a debugging build, specify /OPT:REF. The /OPT:REF option disables incremental linking.
You have to explicitly mark data as a COMDAT; use __declspec(selectany).
If /OPT:REF is specified, /OPT:ICF is on by default. If you want /OPT:REF but not /OPT:ICF, you must specify the following:
link /opt:ref /opt:noicf
Specifying /OPT:ICF does not activate the /OPT:REF option.
Functions are placed in COMDATs with the /Gy compiler option and const data is placed in COMDATs. See selectany for an example of how to specify data for folding.
ICF is on by default if REF is on and needs to be explicitly turned on in a debug build.
If you build images intended to run on Windows 98, especially those that are redistributable, you should use the WIN98 option. This allows the Windows 98 memory manager to cache executable images with a minimum of wasted space. Specifically, WIN98 aligns sections on a 4K boundary to improve load time. WIN98 is on by default. WIN98 is not on when,
/OPT:WIN98 is not enabled by default for small images; you should enable /OPT:WIN98 explicitly to ensure that you are not affected by this tuning. Specify /opt:nowin98 to get a smaller, but slower on Win98, version of your application.
The enhancements in Windows 98 only work when the sections in a portable executable image begin on a page boundary. The /OPT:WIN98 option performs the necessary file alignment.
If you are building components that run only on NT, you should use /OPT:NOWIN98.
This change impacts neither Windows NT's or Windows 95's loading of images nor the working set of the process. The only impact is to the on-disk size. The average wasted space for 4096-byte file alignment can be characterized by:
count-of-sections-in-image * 4096/2
The average for the current 512-byte file alignment is:
count-of-sections-in-image * 512/2
The growth is therefore:
cbGrowth = count-of-sections-in-image * (4096/2 - 512/2)
average count-of-bytes-Growth = count-of-sections-in-image * 1792 + 3584
maximum count-of-bytes-Growth = count-of-sections-in-image * 4095 + 3584
To get the count of sections, use dumpbin on an executable. The summary will give you a list of sections in that image. Typically, you will see from 3 to 5 sections and you need to add one to that value, because it does not account for the portable executable header.
The only time you should not use /OPT:WIN98 is when your portable executable image is very small. Even if an image is slated for downloads, the wasted space is zero-filled and compresses well.
You can use /VERBOSE to see the functions removed by /OPT:REF and the the functions that are folded by /OPT:ICF.
Setting Linker Options | Linker Options | FAQ: Building Your Program