This is the mail archive of the
mailing list for the binutils project.
Re: Preventing preemption of 'protected' symbols in GNU ld 2.26
- From: "H.J. Lu" <hjl dot tools at gmail dot com>
- To: Joe Groff <jgroff at apple dot com>
- Cc: Cary Coutant <ccoutant at gmail dot com>, Binutils <binutils at sourceware dot org>
- Date: Mon, 28 Mar 2016 10:17:17 -0700
- Subject: Re: Preventing preemption of 'protected' symbols in GNU ld 2.26
- Authentication-results: sourceware.org; auth=none
- References: <9106B2FB-BB06-413A-A04D-EEFB992784FA at apple dot com> <CAJimCsEzZ8GDByd8r9x5J9sQ__V0o1mn21FD1xLPe7OhWdikKQ at mail dot gmail dot com> <CAMe9rOqipnAMa-OeYfks6=FYRffxSrcLuJnJD=wX-PjoKcGWRA at mail dot gmail dot com> <CAJimCsFxza3TWVXorqYLa--SfUZ_LznR=m2GkJ_Mq6YZ9Ga3YQ at mail dot gmail dot com> <CAMe9rOphSdEp8mO7OpuEAVpUz-hT8eRb=6RJmaP1XWvDC_UNpQ at mail dot gmail dot com> <CAJimCsHGnHp+s4OXVMt5K=AOsz=nPqY_W7L_M0Ey5rSdK7nk1g at mail dot gmail dot com> <CAMe9rOowzNKqmgf+5A6R-BdEjv2_KAnEYO=PxUH6=MYST_Fu3w at mail dot gmail dot com> <9EFBBDCE-4054-4867-B3E9-9DFE216A234F at apple dot com> <CAMe9rOqqPVeaRZ8SPD-uoxRnHFOCGV3xXFNnDY5ez6xY8uG6hw at mail dot gmail dot com> <CAJimCsFffshMvsDoRq_33Ss8u9Y_Z4y2NKsqDbxJQuO6SyJNbg at mail dot gmail dot com> <CAMe9rOqcw2P_ZU2u-mQ5m7wrVygLKxD3R=KwkxdpiXkeM6o_2g at mail dot gmail dot com> <BC969B3B-87A2-4238-90C8-DA2E166707AF at apple dot com>
On Mon, Mar 28, 2016 at 10:01 AM, Joe Groff <firstname.lastname@example.org> wrote:
> On Mar 28, 2016, at 5:11 AM, H.J. Lu <email@example.com> wrote:
> On Thu, Mar 24, 2016 at 11:31 AM, Cary Coutant <firstname.lastname@example.org> wrote:
> What relocation do you propose to access external protected
> symbol on x86 for non-PIC code?
> Non-PIC code can still use a GOT, can't it?
> Some additional thoughts:
> - This has nothing to do with PIE. Non-PIC-non-PIE code has been
> living with this restriction for at least 18 years (since visiblity
> was introduced into the gABI).
> - This has nothing to do with Ulrich's diatribe against protected
> visibility, which applies only to function symbols (and really only to
> one platform, due to how function pointer comparison works).
> Copy relocation and protected symbol are mutually exclusive.
> Since copy relocation is the part of x86 psABIs, it limits
> protected symbol effectiveness on x86. In glibc, we add a
> local alias to symbol we want to protect and access the local
> alias within glibc without GOT.
> I had thought about doing this as a workaround for us, but if I understand
> correctly, this would result in two canonical copies of the object in the
That is correct.
> process's memory. For what we're using protected symbols for in Swift, we
> really want only one canonical object, and would prefer that protected
> references from the executable go through a GOT, similar to how references
> to external symbols always work in Mach-O.
> - You don't need to go full-on PIC to reference a protected data
> symbol in a shared library. You can always statically initialize a
> pointer variable, and go indirect through that ("poor-man's PIC").
> - We could add support for __attribute__((dllimport)) or
> __declspec(dllimport) when declaring an external variable that is
> expected to be defined in a shared library (ideally, that attribute
> ought to be placed in the library's public interface). The compiler
> can generate a PIC-style reference for that variable without
> penalizing all the other variables in the main program. This is how
> HP-UX compilers work on PA and Itanium (using #pragma external).
> This is a useful feature, similar to -fno-plt, like -fgot, but only on
> selective symbols.
> "protected" is already selective, though. The code generator had to
> intentionally set protected visibility on symbols.
Compiler needs a way to know if an external symbol is protected
or not if we don't want to force to use GOT to access ALL external
symbols, even if they turn out to be defined locally at link-time.
> - Compilers could also generate tentative PIC-style references, with
> sufficient relocations to allow the linker to convert the indirect
> reference to a direct reference when possible (changing the second
> load into a nop or copy). HP-UX also does this.
> I extended the x86 psABIs with relaxable GOT relocations and
> implemented the similar linker optimization in ld in binutils 2.26
> and gold also implemented the subset of the linker optimization.
> - Indirect references from PIC code to a protected symbol penalize the
> common case (referencing a symbol within its own module) to support
> the uncommon case, while introducing the nasty side effects of a COPY
> - COPY relocations are evil. They bind an application to a specific
> version of a shared library's ABI, and introduce a hidden startup
> cost. If we're going to make any changes, we should be moving towards
> elimination of COPY relocations, rather than disabling features that
> were designed to improve performance.
> Copy relocation can improve performance. Google enabled copy
> relocations for PIE in ld/gold and GCC to improve prefomance by
> up to 5%:
> It is in GCC 5.
> Did you look at what the costs were in startup time and dirty pages by using
No, I haven't. It will be a very useful data.
> copy relocations? What do you do if the size of the definition changes in a
> new version of the library?
The size of sys_errlist data symbol in glibc changed over time. We
use symbol versioning to provide backward binary compatibility:
1326: 001c7a80 492 OBJECT GLOBAL DEFAULT 29 sys_errlist@GLIBC_2.0
1327: 001c7a80 500 OBJECT GLOBAL DEFAULT 29 sys_errlist@GLIBC_2.1
1324: 001c7a80 540 OBJECT GLOBAL DEFAULT 29 sys_errlist@@GLIBC_2.12
1328: 001c7a80 504 OBJECT GLOBAL DEFAULT 29 sys_errlist@GLIBC_2.3
1330: 001c7a80 528 OBJECT GLOBAL DEFAULT 29 sys_errlist@GLIBC_2.4