/OPT:REF eliminates functions and/or data that are never referenced; /OPT:NOREF keeps functions and/or data that are never referenced.
By default, LINK removes unreferenced packaged functions. An object contains packaged functions (COMDATs) if it has been compiled with the /Gy option. This optimization is known as 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.
By default, if /OPT:REF is specified, /OPT:ICF is on. If you want /OPT:REF but not /OPT:ICF, you must specify this:
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. The optional iterations parameter specifies the number of times to traverse the symbols for duplicates. The default number of iterations is two. Additional iterations may locate more duplicates that are uncovered through folding in the previous iteration.
There is a difference in linker behavior between explicitly specifying /OPT:REF with ICF in effect by default, and explicitly specifying /OPT:REF,ICF. The default ICF enabled with /OPT:REF does not fold read-only data. This includes any .rdata, .pdata, and .xdata. This results in fewer functions folded when images are produced for x64 because functions in these modules have more read-only data dependency—for example, .pdata and .xdata. To get full ICF folding behavior, explicitly specify /OPT:ICF.
Functions are placed in COMDATs by using the /Gy compiler option, as is const data declared __declspec(selectany). See selectany for an example of how to specify data for folding.
ICF is on by default if REF is on. NOICF can be specified to override this default if REF is specified. You must explicitly specify /OPT:ICF to enable COMDAT folding in a debug build when /OPT:REF is not specified.
/OPT:ICF can cause the same address to be 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 addresses of functions or read-only data members being different. For more information, see /Gy (Enable Function-Level Linking).
LBR | NOLBR
The /OPT:LBR and /OPT:NOLBR options apply only to ARM binaries. Because certain ARM processor branch instructions have a limited range, if the linker detects a jump to an out-of-range address, it replaces the branch instruction’s destination address with the address of a code "island" that contains a branch instruction that targets the actual destination. Use /OPT:LBR to optimize the detection of long branch instructions and the placement of intermediate code islands to minimize overall code size. /OPT:NOLBR instructs the linker to generate code islands for long branch instructions as they are encountered, without optimization.
By default, the /OPT:LBR option is set when incremental linking is not enabled. If you want a non-incremental link but not long branch optimizations, specify /OPT:NOLBR. The /OPT:LBR option disables incremental linking.