Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Can I see what is eliminated by the Visual C++ /OPT:REF linker option?

The /OPT:REF option causes the Visual C++ linker to

Exclude functions and/or data that are never referenced

(MSDN)

This seems like it would be a good way to identify obsolete code in a legacy codebase. Is there any way to get the linker to output what is eliminated?

like image 212
Aidan Ryan Avatar asked Oct 02 '09 11:10

Aidan Ryan


People also ask

What is OPT REF?

The /OPT:REF option causes the Visual C++ linker to. Exclude functions and/or data that are never referenced.

What is incremental linker file?

The Incremental Linker files (*. ilk) are used by the linker to speed up the generation of your app (.exe) or library (. lib). When your project has 100 files and only one changes, you'll be happy of this quicken.

What is incremental linking Visual Studio?

Incremental linking links your exe/dll in a way which makes it easier for the linker to update the existing exe/dll when you make a small change and re-compile. So, incremental linking just makes it faster to compile and link your project.


2 Answers

In /OPT (Optimizations), the Remarks section states:

You can use the /VERBOSE option to see the functions removed by /OPT:REF and the functions that are folded by /OPT:ICF.

I have not tried using it for your purpose yet.

Also, you may want to refer to SO Question 641826 to eliminate compiler-generated symbols if you take the route given by @JamesMcNellis answer.

like image 108
bgoodr Avatar answered Oct 06 '22 20:10

bgoodr


This isn't ideal, but...

You can do two builds, one with /OPT:REF and one without, then run dumpbin /symbols on the resulting binaries, parse out the symbols, and diff the results. The trick will be weeding out the library symbols so you are only left with your symbols. Since you'll end up with a list of mangled names, it's not going to be pretty.

I don't know of a way to get the linker to just tell you what it's removing.

like image 37
James McNellis Avatar answered Oct 06 '22 19:10

James McNellis