On Fri, Jul 18, 2008 at 8:43 PM, Brian Dessent <brian@xxxxxxxxxxx> wrote: > Mathieu Lacage wrote: > >> Right, but if I do that, gcc will use GOT/PLT lookups to access these >> symbols even when doing accesses from within the library and that is >> precisely what I would like to avoid. > > In that case you need to create a second alias of the symbol with hidden > visibility for internal use within the library. The Drepper paper > explains how to do this in section 2.2.7. > > The problem with doing this in C++ code is that the alias declaration > needs the assembler name of the function which includes the mangling, > and there's no way to automatically generate that short of compiling a > testcase and looking at the assembly output. You could arrange for this > to be done automatically with some kind of multi-pass compilation scheme > with tons of macro magic: first run g++ -S over the source, then use a > perl/awk/whatever script to extract the mangled names of exported > functions and substitute them back into a second compilation of the same > file with the alias declarations added. To me that sounds like a > fragile and complicated way of achieving a modest optimization. The > wrapper function approach mentioned in that same section is probably the > best way to go in the face of C++. Both options require different names to be used when calling a function internally and when calling a function through the GOT/PLT. That is clearly not something I will be able to retrofit in our codebase. So, it looks like all bets are off and that I should just build everything statically without -fpic if I want to avoid the GOT/PLT lookups. Mathieu -- Mathieu Lacage <mathieu.lacage@xxxxxxxxx>