https://gcc.gnu.org/bugzilla/show_bug.cgi?id=65888

            Bug ID: 65888
           Summary: Need a way to disable copy relocations
           Product: gcc
           Version: 5.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c
          Assignee: unassigned at gcc dot gnu.org
          Reporter: thiago at kde dot org

Qt would like to optimise libraries by resolving relocations that loop back
into the library in question at link-time, disallowing interposing. The
libraries remain position-independent by always resolving symbols via
PC-relative addressing or via R_xxx_RELATIVE relocations for what pointers need
to be stored in memory (such as virtual tables).

Do do that, we use -Bsymbolic or -Bsymbolic-functions. Either way, this is not
enough:

The problem happens when the symbols used from the libraries get used in the
main application. Due to copy relocation and position-dependent code
generation, those symbols "transfer" to the main application:
 * variables are copy-relocated
 * functions' entry points are now the PLT location in the application

Since the official address of certain variables or functions change, the
link-time resolving that happened inside the library is now different from what
the application and other libraries will resolve.

So far, using -fPIE has been enough to make the main executable not create copy
relocations on i386 and x86-64, with GCC 4.9 and earlier, Clang and ICC. GCC 5
breaks that.

Given the relative code size of the application vs the libraries (the libraries
are at least 10x larger and more complex), I argue that we're optimising for
the wrong thing by using copy relocations. It's a historic mistake that needs
fixing in the ABI.

Please provide a way for libraries to be allowed to use -Bsymbolic and
-fvisibility=protected by making applications never use copy relocations.
Applications should resolve symbols coming from libraries via indirect,
position-independent addressing. We are ok with tagging every symbol in
question with a new __attribute__ (they are already all tagged with
__attribute__((visibility("default")))).

Reply via email to