Bug 65888 - Need a way to disable copy relocations
Summary: Need a way to disable copy relocations
Status: RESOLVED DUPLICATE of bug 65886
Alias: None
Product: gcc
Classification: Unclassified
Component: c (show other bugs)
Version: 5.0
: P3 normal
Target Milestone: ---
Assignee: Not yet assigned to anyone
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2015-04-25 16:21 UTC by Thiago Macieira
Modified: 2015-04-25 16:33 UTC (History)
1 user (show)

See Also:
Host:
Target:
Build:
Known to work:
Known to fail:
Last reconfirmed:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Thiago Macieira 2015-04-25 16:21:55 UTC
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")))).
Comment 1 H.J. Lu 2015-04-25 16:33:00 UTC
Dup.

*** This bug has been marked as a duplicate of bug 65886 ***