Hacker News new | ask | show | jobs
by jeffbee 1468 days ago
ICF exists but no linker is going to silently do it behind your back without an explicit directive, because it breaks debugging in certain ways. Folded identical functions can't be disambiguated in the file/line tables, so symbolized backtraces may contain impossible calls.
1 comments

> CF exists but no linker is going to silently do it behind your back without an explicit directive,

Those explicit directives might be more implicit than you think. A linker will likely fold functions declared as inline. Template functions and template classes are implicitly inline, so for example, all uses of std::vector<std::string> will (likely) be implicitly folded together.

Aren't these folded by the compiler already?
Not if they're compiled by separate invocations of the compiler. If a.cpp and b.cpp both have a vector<string> and are compiled independently, the first tool that actually gets to see them both is likely a linker (or archiver but that's a glorified zip tool)
Ok, but if these functions are inlined, would a linker then be able to fold these definitions?

(Or are you assuming that a debug flag is used so that all inlined functions are not really inlined by the compiler?)

OK but removing functions that are identical and that have the same name is not "identical code folding". ICF is removing functions that have identical bodies and different names.