about summary refs log tree commit diff
path: root/elf/dl-support.c
diff options
context:
space:
mode:
authorSzabolcs Nagy <szabolcs.nagy@arm.com>2021-01-15 12:49:24 +0000
committerSzabolcs Nagy <szabolcs.nagy@arm.com>2021-01-21 15:55:01 +0000
commit47618209d05a0e77932038f21c6bba2425bd75c6 (patch)
tree640fcd2ab46ab26165d7c5f02cb4c16ca0fc2dbf /elf/dl-support.c
parent04af1eb3132904519f9bc8fdcca49525bec83fc7 (diff)
downloadglibc-47618209d05a0e77932038f21c6bba2425bd75c6.tar.gz
glibc-47618209d05a0e77932038f21c6bba2425bd75c6.tar.xz
glibc-47618209d05a0e77932038f21c6bba2425bd75c6.zip
Use hidden visibility for early static PIE code
Extern symbol access in position independent code usually involves GOT
indirection which needs RELATIVE reloc in a static linked PIE. (On
some targets this is avoided e.g. because the linker can relax a GOT
access to a pc-relative access, but this is not generally true.) Code
that runs before static PIE self relocation must avoid relying on
dynamic relocations which can be ensured by using hidden visibility.
However we cannot just make all symbols 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.

This patch aims to make symbol references hidden in code that is used
before and by _dl_relocate_static_pie when building a static PIE libc.
Note: for an object that is used in the startup code, its references
and definition may not have consistent visibility: it is only forced
hidden in the startup code.

This is needed for fixing bug 27072.

Co-authored-by: H.J. Lu <hjl.tools@gmail.com>
Reviewed-by: Adhemerval Zanella  <adhemerval.zanella@linaro.org>
Diffstat (limited to 'elf/dl-support.c')
-rw-r--r--elf/dl-support.c6
1 files changed, 6 insertions, 0 deletions
diff --git a/elf/dl-support.c b/elf/dl-support.c
index 2434c470c7..7abb65d8e3 100644
--- a/elf/dl-support.c
+++ b/elf/dl-support.c
@@ -19,6 +19,12 @@
 /* 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 <string.h>
+/* Mark symbols hidden in static PIE for early self relocation to work.
+   Note: string.h may have ifuncs which cannot be hidden on i686.  */
+#if BUILD_PIE_DEFAULT
+# pragma GCC visibility push(hidden)
+#endif
 #include <errno.h>
 #include <libintl.h>
 #include <stdlib.h>