]> git.ipfire.org Git - thirdparty/glibc.git/commitdiff
Use hidden visibility for early static PIE code
authorSzabolcs Nagy <szabolcs.nagy@arm.com>
Fri, 15 Jan 2021 12:49:24 +0000 (12:49 +0000)
committerSzabolcs Nagy <szabolcs.nagy@arm.com>
Thu, 21 Jan 2021 15:55:01 +0000 (15:55 +0000)
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>
csu/libc-start.c
elf/dl-reloc-static-pie.c
elf/dl-support.c
elf/dl-tunables.c
elf/enbl-secure.c
misc/sbrk.c
sysdeps/unix/sysv/linux/aarch64/libc-start.c
sysdeps/x86/libc-start.c

index 5b9ce1d158c14883469e5315fd8a5e71fb3b080b..a2f6e1272819c099b0b8f24cbadcf14e4bece437 100644 (file)
    License along with the GNU C Library; if not, see
    <https://www.gnu.org/licenses/>.  */
 
+/* Mark symbols hidden in static PIE for early self relocation to work.  */
+#if BUILD_PIE_DEFAULT
+# pragma GCC visibility push(hidden)
+#endif
 #include <assert.h>
 #include <stdlib.h>
 #include <stdio.h>
index a8d964061e9fc4c66936d7c7dae6ec483dda0be9..d5bd2f31e9ca50ced7f29e4ef6f4f087134e7a37 100644 (file)
@@ -17,6 +17,8 @@
    <https://www.gnu.org/licenses/>.  */
 
 #if ENABLE_STATIC_PIE
+/* Mark symbols hidden in static PIE for early self relocation to work.  */
+# pragma GCC visibility push(hidden)
 #include <unistd.h>
 #include <ldsodefs.h>
 #include "dynamic-link.h"
index 2434c470c70ae2cfa5ec2ca1c309aa7f248529ca..7abb65d8e393d9ee9c7ec3f1409a15f4643c5402 100644 (file)
 /* 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>
index e44476f2043447f0b86c7bc9bb6472472e75273c..b1a50b84693d15de59eaedb4cd5b7db24e223845 100644 (file)
    License along with the GNU C Library; if not, see
    <https://www.gnu.org/licenses/>.  */
 
+/* Mark symbols hidden in static PIE for early self relocation to work.  */
+#if BUILD_PIE_DEFAULT
+# pragma GCC visibility push(hidden)
+#endif
 #include <startup.h>
 #include <stdint.h>
 #include <stdbool.h>
index 5dcf649626e5b17147fbbaeafeb053e664c868d6..9e47526bd3e444e1a19a8ea9fd310b6f47c4db52 100644 (file)
 /* This file is used in the static libc.  For the shared library,
    dl-sysdep.c defines and initializes __libc_enable_secure.  */
 
+/* Mark symbols hidden in static PIE for early self relocation to work.  */
+#if BUILD_PIE_DEFAULT
+# pragma GCC visibility push(hidden)
+#endif
 #include <startup.h>
 #include <libc-internal.h>
 
index 99b3fb517e3f58cff1ab9f1154df495d7e4173d9..95800b32aa2e9015fbf93ebef7f0ecef71d39746 100644 (file)
    License along with the GNU C Library; if not, see
    <https://www.gnu.org/licenses/>.  */
 
+/* Mark symbols hidden in static PIE for early self relocation to work.  */
+#if BUILD_PIE_DEFAULT
+# pragma GCC visibility push(hidden)
+#endif
 #include <errno.h>
 #include <libc-internal.h>
 #include <stdbool.h>
index f816f04ee112bf417e8ca766fe4e2a68a09dbcae..e1604a6ed079defb6169c1e6883b9082a139cd8b 100644 (file)
    <https://www.gnu.org/licenses/>.  */
 
 #ifndef SHARED
+
+/* Mark symbols hidden in static PIE for early self relocation to work.  */
+# if BUILD_PIE_DEFAULT
+#  pragma GCC visibility push(hidden)
+# endif
 # include <ldsodefs.h>
 # include <cpu-features.c>
 
index 4bbd7d555bcb524b7ccad2d6cb6dec22d449268a..d30aec2aa1ed48135c4d8f2d249567af05b7f83b 100644 (file)
    <https://www.gnu.org/licenses/>.  */
 
 #ifndef SHARED
+
+/* Mark symbols hidden in static PIE for early self relocation to work.  */
+# if BUILD_PIE_DEFAULT
+#  pragma GCC visibility push(hidden)
+# endif
 /* Define I386_USE_SYSENTER to support syscall during startup in static
    PIE.  */
 # include <startup.h>