Message ID | CAMe9rOpD5Hw3qM-Ri5B4qXob9ZvknSdkYVC3Md1ySva3S3onhw@mail.gmail.com |
---|---|
State | New |
Headers | show |
Series | V2 [PATCH v4 06/10] elf: Avoid RELATIVE relocation for _dl_sysinfo | expand |
On 19/01/2021 11:25, H.J. Lu wrote: > On Tue, Jan 19, 2021 at 5:51 AM Adhemerval Zanella via Libc-alpha > <libc-alpha@sourceware.org> wrote: >> >> >> >> On 18/01/2021 13:24, Szabolcs Nagy via Libc-alpha wrote: >>> From: "H.J. Lu" <hjl.tools@gmail.com> >>> >>> In static PIE, set the default _dl_sysinfo in _dl_aux_init, instead of >>> using the RELATIVE relocation to intialize it. >>> >>> This is needed for fixing bug 27072 on x86. >>> --- >>> elf/dl-support.c | 12 +++++++++++- >>> 1 file changed, 11 insertions(+), 1 deletion(-) >>> >>> diff --git a/elf/dl-support.c b/elf/dl-support.c >>> index 384080dd80..5acd59290f 100644 >>> --- a/elf/dl-support.c >>> +++ b/elf/dl-support.c >>> @@ -200,7 +200,12 @@ struct dl_scope_free_list *_dl_scope_free_list; >>> >>> #ifdef NEED_DL_SYSINFO >>> /* Needed for improved syscall handling on at least x86/Linux. */ >>> -uintptr_t _dl_sysinfo = DL_SYSINFO_DEFAULT; >>> +uintptr_t _dl_sysinfo >>> +/* NB: Avoid RELATIVE relocation in static PIE. */ >>> +# ifndef BUILD_PIE_DEFAULT >>> + = DL_SYSINFO_DEFAULT >>> +# endif >>> +; >>> #endif >>> #ifdef NEED_DL_SYSINFO_DSO >>> /* Address of the ELF headers in the vsyscall page. */ >>> @@ -238,6 +243,11 @@ _dl_aux_init (ElfW(auxv_t) *av) >>> uid_t uid = 0; >>> gid_t gid = 0; >>> >>> +#if defined NEED_DL_SYSINFO && BUILD_PIE_DEFAULT >>> + /* NB: Avoid RELATIVE relocation in static PIE. */ >>> + GL(dl_sysinfo) = DL_SYSINFO_DEFAULT; >>> +#endif >>> + >> >> Couldn't we make it the default instead? >> >>> _dl_auxv = av; >>> for (; av->a_type != AT_NULL; ++av) >>> switch (av->a_type) >>> > > Like this? > > From af3c44826b8ff07082eb5020213652e6b1fadfa4 Mon Sep 17 00:00:00 2001 > From: "H.J. Lu" <hjl.tools@gmail.com> > Date: Mon, 18 Jan 2021 11:45:46 +0000 > Subject: [PATCH] elf: Avoid RELATIVE relocation for _dl_sysinfo > > Set the default _dl_sysinfo in _dl_aux_init to avoid RELATIVE relocation > in static PIE. > > This is needed for fixing bug 27072 on x86. LGTM, thanks. Reviewed-by: Adhemerval Zanella <adhemerval.zanella@linaro.org> > --- > elf/dl-support.c | 10 ++++++++-- > 1 file changed, 8 insertions(+), 2 deletions(-) > > diff --git a/elf/dl-support.c b/elf/dl-support.c > index 384080dd80..7abb65d8e3 100644 > --- a/elf/dl-support.c > +++ b/elf/dl-support.c > @@ -199,8 +199,9 @@ int _dl_thread_gscope_count; > struct dl_scope_free_list *_dl_scope_free_list; > > #ifdef NEED_DL_SYSINFO > -/* Needed for improved syscall handling on at least x86/Linux. */ > -uintptr_t _dl_sysinfo = DL_SYSINFO_DEFAULT; > +/* Needed for improved syscall handling on at least x86/Linux. NB: Don't > + initialize it here to avoid RELATIVE relocation in static PIE. */ > +uintptr_t _dl_sysinfo; > #endif > #ifdef NEED_DL_SYSINFO_DSO > /* Address of the ELF headers in the vsyscall page. */ > @@ -238,6 +239,11 @@ _dl_aux_init (ElfW(auxv_t) *av) > uid_t uid = 0; > gid_t gid = 0; > > +#ifdef NEED_DL_SYSINFO > + /* NB: Avoid RELATIVE relocation in static PIE. */ > + GL(dl_sysinfo) = DL_SYSINFO_DEFAULT; > +#endif > + > _dl_auxv = av; > for (; av->a_type != AT_NULL; ++av) > switch (av->a_type) > -- > 2.29.2
From af3c44826b8ff07082eb5020213652e6b1fadfa4 Mon Sep 17 00:00:00 2001 From: "H.J. Lu" <hjl.tools@gmail.com> Date: Mon, 18 Jan 2021 11:45:46 +0000 Subject: [PATCH] elf: Avoid RELATIVE relocation for _dl_sysinfo Set the default _dl_sysinfo in _dl_aux_init to avoid RELATIVE relocation in static PIE. This is needed for fixing bug 27072 on x86. --- elf/dl-support.c | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/elf/dl-support.c b/elf/dl-support.c index 384080dd80..7abb65d8e3 100644 --- a/elf/dl-support.c +++ b/elf/dl-support.c @@ -199,8 +199,9 @@ int _dl_thread_gscope_count; struct dl_scope_free_list *_dl_scope_free_list; #ifdef NEED_DL_SYSINFO -/* Needed for improved syscall handling on at least x86/Linux. */ -uintptr_t _dl_sysinfo = DL_SYSINFO_DEFAULT; +/* Needed for improved syscall handling on at least x86/Linux. NB: Don't + initialize it here to avoid RELATIVE relocation in static PIE. */ +uintptr_t _dl_sysinfo; #endif #ifdef NEED_DL_SYSINFO_DSO /* Address of the ELF headers in the vsyscall page. */ @@ -238,6 +239,11 @@ _dl_aux_init (ElfW(auxv_t) *av) uid_t uid = 0; gid_t gid = 0; +#ifdef NEED_DL_SYSINFO + /* NB: Avoid RELATIVE relocation in static PIE. */ + GL(dl_sysinfo) = DL_SYSINFO_DEFAULT; +#endif + _dl_auxv = av; for (; av->a_type != AT_NULL; ++av) switch (av->a_type) -- 2.29.2