[PATCH v3 2/5] Make libc symbols hidden in static PIE

H.J. Lu hjl.tools@gmail.com
Fri Jan 15 04:29:34 GMT 2021


On Thu, Jan 14, 2021 at 7:36 PM H.J. Lu <hjl.tools@gmail.com> wrote:
>
> On Thu, Jan 14, 2021 at 3:18 AM Szabolcs Nagy <szabolcs.nagy@arm.com> wrote:
> >
> > The 01/13/2021 09:50, Szabolcs Nagy via Libc-alpha wrote:
> > > The 01/12/2021 17:19, H.J. Lu wrote:
> > > > On Tue, Jan 12, 2021 at 4:33 PM H.J. Lu <hjl.tools@gmail.com> wrote:
> > > > > On Tue, Jan 12, 2021 at 4:02 PM H.J. Lu <hjl.tools@gmail.com> wrote:
> > > > > > See:
> > > > > >
> > > > > > https://sourceware.org/bugzilla/show_bug.cgi?id=14961
> > > > > >
> > > > >  /* Mark all symbols hidden in static PIE libc to avoid GOT indirections.  */
> > > > > -#if BUILD_PIE_DEFAULT && IS_IN (libc) && !defined LIBC_NONSHARED
> > > > > +#if BUILD_PIE_DEFAULT && !defined NO_HIDDEN_EXTERN_FUNC_IN_PIE \
> > > > > +    && IS_IN (libc) && !defined LIBC_NONSHARED
> > > > >  # pragma GCC visibility push(hidden)
> > > > >  #endif
> > > > >
> > > >
> > > > This works on i686.
> >
> > The series i plan to commit today is in nsz/bug27072 now,
> >
> > This is the v4 of this patch:
> >
> > Hidden matters with static PIE: extern symbol access in position
> > independent code usually involves GOT indirections which needs
> > RELATIVE relocs in a static linked PIE. Hidden visibility avoids
> > indirections and RELATIVE relocs on targets that can access symbols
> > pc-relative.
> >
> > The check should use IS_IN_LIB instead of IS_IN(libc) since all
> > static libraries can use hidden visibility to avoid indirections,
> > however the test system links objects from libcrypt.a into dynamic
> > linked test binaries so hidden does not work there.  I think mixing
> > static and shared libc components in the same binary should not be
> > supported usage, but to be safe only use hidden in libc.a.
> >
> > There are targets (i686) where hidden visibility functions are
> > problematic in PIE code so hidden cannot be applied to all symbols.
> > Then static PIE requires extern object access without relocations
> > (e.g. by relying on copy relocations in shared libraries instead of
> > GOT access in PIE code). See bug 14961.
>
> It isn't about copy relocations.  It is IFUNC, PLT and PIE.   I needed
> additional patches to make static PIE to work on i386 and x86-64.
> I am enclosing my patches.  Please include them in your patch set.
>
> > From -static-pie linked 'int main(){}' this shaves off 73 relative
> > relocs on aarch64 and reduces code size too.
>
>
> --
> H.J.

commit c5ffa46591550d945b009f0e3bcf66603d48ac0b
Author: H.J. Lu <hjl.tools@gmail.com>
Date:   Thu Jan 14 13:26:29 2021 -0800

    i386: Call _dl_aux_init after relocating static PIE

is too complicated.  I will submit a simple version.

-- 
H.J.


More information about the Libc-alpha mailing list