/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.
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. See /Gy (Enable Function-Level Linking) for more information.