Controls the optimizations that LINK performs during a build.
- REF | NOREF
/OPT:REF eliminates functions and/or data that are never referenced while /OPT:NOREF keeps functions and/or data that are never referenced.
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 /DEBUG is specified, the default for /OPT is NOREF (otherwise, it is REF), 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.
- ICF[= iterations ] | NOICF
Use /OPT:ICF[=iterations] to perform identical COMDAT folding. Redundant COMDATs can be removed from the linker output. iterations specifies the number of times to traverse the symbols for duplicates. The default number of iterations is two. Additional iterations may locate more duplicates uncovered through folding in the previous iteration.
Note that there is a difference in linker behavior when ICF is in effect by default with /OPT:REF explicitly specified and when you explicitly specify /OPT:REF,ICF. The default ICF with /OPT:REF does not fold read-only data. This includes any .rdata, .pdata, and .xdata. However, the default ICF with /OPT:REF results in fewer functions folded when producing images for Itanium and x64 because functions in these modules have more read only data dependency, such as .pdata and .xdata. To get full ICF, explicitly specify /OPT:ICF.
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. It is possible to specify NOICF if REF is specified.
/OPT:ICF can result in the same address being assigned to different functions or read only data members (const variables compiled with /Gy). So, /OPT:ICF can break a program that depends on the address of functions or read-only data members being different. Seefor more information.
- WIN98 | NOWIN98
WIN98 and NOWIN98 control the section alignment in the final image. For Windows 98 applications, it is optimal to align sections on a 4K boundary to improve load time (allows Windows 98 memory manager to cache executable images with a minimum of wasted space). This is on by default in the linker, so you need to specify /OPT:NOWIN98 to get a trimmed-down (but slower on Windows 98) version of the application.
WIN98 is on by default. WIN98 is not on when:
/ALIGN is used.
/MACHINE does not target x86.
/SUBSYSTEM specifies something other than WINDOWS or CONSOLE.
/OPT:WIN98 is not enabled by default for images that would grow (according to the average growth equations, below) by more than 25 percent. In other words, /OPT:WIN98 would not be enabled for smaller 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 Windows 98) 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 Windows NT or Windows 2000, you should use /OPT:NOWIN98.
This change does not impact loading of images or the working set of the process. The only impact is to the on-disk size.
The following helps you compute the average growth of an image using /OPT:WIN98:
The average wasted space for 4096-byte file alignment can be characterized by: count-of-sections-in-image * 4096/2
The average wasted space for the current 512-byte file alignment is: count-of-sections-in-image * 512/2
The growth is therefore:
count-of-bytes-Growth = count-of-sections-in-image * (4096/2 - 512/2)
count-of-bytes-Growth = count-of-sections-in-image * 1792
However, this does not take into account the fact that the image header must be padded to the section alignment. Since the header is always 512 byes or less, the extra growth is a constant of 4096 - 512, or 3584.
average count-of-bytes-Growth = count-of-sections-in-image * 1792 + 3584
maximum count-of-bytes-Growth = count-of-sections-in-image * (4096 - 512 + 3584
To get the count of sections, use the DUMPBIN tool on an executable file. The summary will give you a list of sections in that image. Typically, you will see from 3 to 5 sections added to that value.
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.
Optimizations generally decrease the image size and increase the program speed at a cost of increased link time.
You can use the /VERBOSE option to see the functions removed by /OPT:REF and the functions that are folded by /OPT:ICF.
To set this linker option in the Visual Studio development environment
Open the project's Property Pages dialog box. For details, see Setting Visual C++ Project Properties.
Click the Linker folder.
Click the Optimization property page.
Modify one of the following properties:
Enable COMDAT Folding
Optimize for Windows98
To set this linker option programmatically
See, , and properties.