[cfe-dev] Using Clang -O4 with CMake
David Chisnall
theraven at sucs.org
Sun Jun 20 01:42:56 PDT 2010
On 20 Jun 2010, at 05:39, Rafael Espindola wrote:
> One thing that is different is that gold (or the Apple linker) knows
> what symbols are used and can optimize:
>
> http://llvm.org/releases/2.6/docs/LinkTimeOptimization.html
Reading that document, that's not quite correct. In the example given, foo2() should not be removed by the optimiser in the general case, because it is externally visible. There is a special case here - you are compiling an executable, not a library. Running the internalize pass when you run opt on the linked bitcode will have the same effect, allowing the optimizer to remove everything that is not reachable from main().
Of course, this is not the correct thing to do in the general case. For example, if you provide some helper functions in your main executable that are only used by loadable modules, then LTO will 'helpfully' remove them for you if it takes the list of public symbols from the ones that the linker knows are used.
If you use the internalize pass instead, then you can provide a list of functions that should not be removed, removing this problem.
One of the things on my to-do list is allowing clang to drive the internalize pass based on the contents of a header, using clang's ability to parse C++ decls and mangle the names, so only symbols declared in a given header are exported from the resulting library.
David
-- Sent from my Apple II
More information about the cfe-dev
mailing list