Effect of weak symbols on llvm tools/clang startup time

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
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

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

0001-Define-CINDEX_LINKAGE-for-GCC-based-builds.patch (696 Bytes)

0001-Add-fvisibility-hidden-to-CXXFLAGS.patch (962 Bytes)