From 52dd650d7b231fe20634afe3e261e67f33b66869 Mon Sep 17 00:00:00 2001 From: "H.J. Lu" Date: Thu, 14 Jan 2021 16:40:43 -0800 Subject: [PATCH 2/4] Make all symbols used before and by _dl_relocate_static_pie hidden On i386, all calls to IFUNC functions must go through PLT and calls to hidden functions CANNOT go through PLT in PIE since EBX used in PIE PLT may not be set up for local calls to hidden IFUNC functions. Even if we can't make all libc symbols hidden for static PIE on i386, we must make all symbols used before and by _dl_relocate_static_pie hidden. In static PIE, set the default _dl_sysinfo in _dl_aux_init, instead of using the RELATIVE relocation to intialize it. --- elf/dl-reloc-static-pie.c | 1 + elf/dl-support.c | 16 +++++++++++++++- elf/dl-tunables.c | 3 +++ elf/enbl-secure.c | 3 +++ 4 files changed, 22 insertions(+), 1 deletion(-) diff --git a/elf/dl-reloc-static-pie.c b/elf/dl-reloc-static-pie.c index a8d964061e..cc34c2d2fe 100644 --- a/elf/dl-reloc-static-pie.c +++ b/elf/dl-reloc-static-pie.c @@ -17,6 +17,7 @@ . */ #if ENABLE_STATIC_PIE +#pragma GCC visibility push(hidden) #include #include #include "dynamic-link.h" diff --git a/elf/dl-support.c b/elf/dl-support.c index 9d468d5a4b..4fbf33c982 100644 --- a/elf/dl-support.c +++ b/elf/dl-support.c @@ -19,6 +19,10 @@ /* This file defines some things that for the dynamic linker are defined in rtld.c and dl-sysdep.c in ways appropriate to bootstrap dynamic linking. */ +#include +#if BUILD_PIE_DEFAULT +# pragma GCC visibility push(hidden) +#endif #include #include #include @@ -194,7 +198,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. */ @@ -232,6 +241,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 + _dl_auxv = av; for (; av->a_type != AT_NULL; ++av) switch (av->a_type) diff --git a/elf/dl-tunables.c b/elf/dl-tunables.c index e44476f204..060956902d 100644 --- a/elf/dl-tunables.c +++ b/elf/dl-tunables.c @@ -18,6 +18,9 @@ License along with the GNU C Library; if not, see . */ +#if BUILD_PIE_DEFAULT +# pragma GCC visibility push(hidden) +#endif #include #include #include diff --git a/elf/enbl-secure.c b/elf/enbl-secure.c index bc8c5e96d2..dba39a123e 100644 --- a/elf/enbl-secure.c +++ b/elf/enbl-secure.c @@ -19,6 +19,9 @@ /* This file is used in the static libc. For the shared library, dl-sysdep.c defines and initializes __libc_enable_secure. */ +#if BUILD_PIE_DEFAULT +# pragma GCC visibility push(hidden) +#endif #include #include -- 2.29.2