------- Comment #3 from jakub at gcc dot gnu dot org 2010-01-28 15:37 ------- x86 ABI doesn't have any such guarantees. Consider a function foo exported from the library which just calls this static or visibility ("internal") function bar (but doesn't call any function through PLT nor uses any global variables). When this function foo is called from main, %ebx will contain garbage, when it is called from a function inside of some other shared library, %ebx will contain __GLOBAL_OFFSET_TABLE__ of the other shared library. As foo doesn't call anything through PLT, it doesn't need to compute the PIC register in %ebx (and, as it doesn't use any global variable, it doesn't need to compute it at all, not even in some other register). It then calls this bar function, which would assume %ebx contains right value of PIC register for the shared library in question.
This optimization would be only possible if some whole file (or LTO) analysis has been performed and detected that some static (or hidden, but without address taken) function is only called from functions that are already known to compute the PIC register in %ebx, or alternatively have a mode in which the exported functions would always set it up in case they might directly or indirectly call such functions, then those could have it optimized away. Unfortunately whether %ebx is needed or not (or any kind of PIC pointer) is something determined late during the RTL optimizations, a long time after the IPA passes that could determine this are run. -- http://gcc.gnu.org/bugzilla/show_bug.cgi?id=23756