[LLVMdev] Effect of weak symbols on llvm tools/clang startup time

Alessandro Pignotti alexpigna.dev at gmail.com
Sun Mar 3 10:46:05 PST 2013


Hi everyone,

recently I've been fiddling with callgrind to profile the performance of
clang and other llvm tools. Turns out that a lot of CPU time is spent on
startup in _dl_lookup_symbol_x which is invoked a few thousands times to
resolve all the weak object symbols which comes from LLVM code. Most of
the symbols are virtual table definitions.

Most probably there is a good reason why the -fvisibility=hidden flag is
not applied during the build. Still, I've experimented with a couple of
small changes which seems to greatly improve the situation:

1) I've modified HandleLLVMOptions.cmake to add "-fvisibility=hidden"
where "-fvisibility-inlines-hidden" is currently appended to the
CXXFLAGS
2) I've also modified clang's Platform.h to properly CINDEX_LINKAGE as
__attribute__((visibility ((default)))

The build seems to be working correctly, at least on Linux. I'd like to
ask if there is something I'm missing or if it could be possible to
include such fixes upstream. I'm attaching tentative patches for both
changes.

Regards,
Alessandro Pignotti

PS: Defining CINDEX_LINKAGE as in my patch, actually makes the build
very noisy, since a warning is generated about the attribute being
applied to an 'enum'. I suspect that it should be possible to remove the
CINDEX_LINKAGE usage from the enum completely, since it's not a
definition anyway.

PPS: This simple approach is not good enough when building shared
libraries, since symbols will not be visible as they should. Probably
the hidden visibility by default should only be used on static
libraries.
-------------- next part --------------
A non-text attachment was scrubbed...
Name: 0001-Define-CINDEX_LINKAGE-for-GCC-based-builds.patch
Type: text/x-patch
Size: 696 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-dev/attachments/20130303/7f1027db/attachment.bin>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: 0001-Add-fvisibility-hidden-to-CXXFLAGS.patch
Type: text/x-patch
Size: 962 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-dev/attachments/20130303/7f1027db/attachment-0001.bin>


More information about the llvm-dev mailing list