elf: Replace PI_STATIC_AND_HIDDEN with opposite HIDDEN_VAR_NEEDS_DYNAMIC_RELOC
authorFangrui Song <maskray@google.com>
Tue, 26 Apr 2022 16:26:22 +0000 (09:26 -0700)
committerFangrui Song <maskray@google.com>
Tue, 26 Apr 2022 16:26:22 +0000 (09:26 -0700)
PI_STATIC_AND_HIDDEN indicates whether accesses to internal linkage
variables and hidden visibility variables in a shared object (ld.so)
need dynamic relocations (usually R_*_RELATIVE). PI (position
independent) in the macro name is a misnomer: a code sequence using GOT
is typically position-independent as well, but using dynamic relocations
does not meet the requirement.

Not defining PI_STATIC_AND_HIDDEN is legacy and we expect that all new
ports will define PI_STATIC_AND_HIDDEN. Current ports defining
PI_STATIC_AND_HIDDEN are more than the opposite. Change the configure
default.

No functional change.

Reviewed-by: Adhemerval Zanella <adhemerval.zanella@linaro.org>
41 files changed:
config.h.in
elf/rtld.c
sysdeps/aarch64/configure
sysdeps/aarch64/configure.ac
sysdeps/alpha/configure
sysdeps/alpha/configure.ac
sysdeps/arc/configure
sysdeps/arc/configure.ac
sysdeps/arm/configure
sysdeps/arm/configure.ac
sysdeps/csky/configure
sysdeps/csky/configure.ac
sysdeps/hppa/configure
sysdeps/hppa/configure.ac
sysdeps/ia64/configure
sysdeps/ia64/configure.ac
sysdeps/m68k/configure [new file with mode: 0644]
sysdeps/m68k/configure.ac [new file with mode: 0644]
sysdeps/microblaze/configure
sysdeps/microblaze/configure.ac
sysdeps/mips/configure
sysdeps/mips/configure.ac
sysdeps/nios2/configure
sysdeps/nios2/configure.ac
sysdeps/or1k/configure
sysdeps/or1k/configure.ac
sysdeps/powerpc/powerpc32/configure
sysdeps/powerpc/powerpc32/configure.ac
sysdeps/powerpc/powerpc64/configure
sysdeps/powerpc/powerpc64/configure.ac
sysdeps/powerpc/tst-tlsifunc.c
sysdeps/riscv/configure
sysdeps/riscv/configure.ac
sysdeps/s390/configure
sysdeps/s390/configure.ac
sysdeps/sh/configure
sysdeps/sh/configure.ac
sysdeps/sparc/configure
sysdeps/sparc/configure.ac
sysdeps/x86/configure
sysdeps/x86/configure.ac

index a94f756..916465f 100644 (file)
@@ -84,9 +84,9 @@
 /* Define if the compiler\'s exception support is based on libunwind.  */
 #undef HAVE_CC_WITH_LIBUNWIND
 
-/* Define if the access to static and hidden variables is position independent
-   and does not need relocations.  */
-#undef PI_STATIC_AND_HIDDEN
+/* Define if the accesses to static and hidden variables in a shared object
+   need dynamic relocations.  */
+#undef HIDDEN_VAR_NEEDS_DYNAMIC_RELOC
 
 /* Define this to disable the 'hidden_proto' et al macros in
    include/libc-symbols.h that avoid PLT slots in PIE.  */
index 9318046..be6daa1 100644 (file)
@@ -424,7 +424,7 @@ DL_SYSINFO_IMPLEMENTATION
    is fine, too.  The latter is important here.  We can avoid setting
    up a temporary link map for ld.so if we can mark _rtld_global as
    hidden.  */
-#ifdef PI_STATIC_AND_HIDDEN
+#ifndef HIDDEN_VAR_NEEDS_DYNAMIC_RELOC
 # define DONT_USE_BOOTSTRAP_MAP        1
 #endif
 
index 4c1fac4..bf97212 100644 (file)
@@ -1,11 +1,6 @@
 # This file is generated from configure.ac by Autoconf.  DO NOT EDIT!
  # Local configure fragment for sysdeps/aarch64.
 
-# Static and hidden objects are accessed without dynamic relocations.
-# The exception is -mcmodel=large which is unsupported with PIC/PIE.
-$as_echo "#define PI_STATIC_AND_HIDDEN 1" >>confdefs.h
-
-
 # Static PIE is supported.
 $as_echo "#define SUPPORT_STATIC_PIE 1" >>confdefs.h
 
index 3347c13..51253d9 100644 (file)
@@ -1,10 +1,6 @@
 GLIBC_PROVIDES dnl See aclocal.m4 in the top level source directory.
 # Local configure fragment for sysdeps/aarch64.
 
-# Static and hidden objects are accessed without dynamic relocations.
-# The exception is -mcmodel=large which is unsupported with PIC/PIE.
-AC_DEFINE(PI_STATIC_AND_HIDDEN)
-
 # Static PIE is supported.
 AC_DEFINE(SUPPORT_STATIC_PIE)
 
index 3d665d9..f67a0e2 100644 (file)
@@ -1,11 +1,6 @@
 # This file is generated from configure.ac by Autoconf.  DO NOT EDIT!
  # Local configure fragment for sysdeps/alpha.
 
-# With required gcc+binutils, we can always access static and hidden
-# symbols in a position independent way.
-$as_echo "#define PI_STATIC_AND_HIDDEN 1" >>confdefs.h
-
-
 # PIE builds fail on binutils 2.37 and earlier, see:
 # https://sourceware.org/bugzilla/show_bug.cgi?id=28672
 $as_echo "#define PIE_UNSUPPORTED 1" >>confdefs.h
index 8f9a39e..465665d 100644 (file)
@@ -1,10 +1,6 @@
 GLIBC_PROVIDES dnl See aclocal.m4 in the top level source directory.
 # Local configure fragment for sysdeps/alpha.
 
-# With required gcc+binutils, we can always access static and hidden
-# symbols in a position independent way.
-AC_DEFINE(PI_STATIC_AND_HIDDEN)
-
 # PIE builds fail on binutils 2.37 and earlier, see:
 # https://sourceware.org/bugzilla/show_bug.cgi?id=28672
 AC_DEFINE(PIE_UNSUPPORTED)
index bce7d3c..92050f4 100644 (file)
@@ -1,8 +1,6 @@
 # This file is generated from configure.ac by Autoconf.  DO NOT EDIT!
  # Local configure fragment for sysdeps/arc.
 
-$as_echo "#define PI_STATIC_AND_HIDDEN 1" >>confdefs.h
-
 libc_cv_have_sdata_section=no
 
 # For ARC, historically ; was used for comments and not newline
index cb490e4..619da4e 100644 (file)
@@ -1,7 +1,6 @@
 GLIBC_PROVIDES dnl See aclocal.m4 in the top level source directory.
 # Local configure fragment for sysdeps/arc.
 
-AC_DEFINE(PI_STATIC_AND_HIDDEN)
 libc_cv_have_sdata_section=no
 
 # For ARC, historically ; was used for comments and not newline
index 431e843..b40ce60 100644 (file)
@@ -1,9 +1,6 @@
 # This file is generated from configure.ac by Autoconf.  DO NOT EDIT!
  # Local configure fragment for sysdeps/arm.
 
-$as_echo "#define PI_STATIC_AND_HIDDEN 1" >>confdefs.h
-
-
 # We check to see if the compiler and flags are
 # selecting the hard-float ABI and if they are then
 # we set libc_cv_arm_pcs_vfp to yes which causes
index 90cdd69..da078ce 100644 (file)
@@ -1,11 +1,6 @@
 GLIBC_PROVIDES dnl See aclocal.m4 in the top level source directory.
 # Local configure fragment for sysdeps/arm.
 
-dnl It is always possible to access static and hidden symbols in an
-dnl position independent way.  This has been true since GCC 4.1,
-dnl which is older than the minimum version required to build libc.
-AC_DEFINE(PI_STATIC_AND_HIDDEN)
-
 # We check to see if the compiler and flags are
 # selecting the hard-float ABI and if they are then
 # we set libc_cv_arm_pcs_vfp to yes which causes
index 27464eb..bcbcea0 100644 (file)
@@ -1,9 +1,6 @@
 # This file is generated from configure.ac by Autoconf.  DO NOT EDIT!
  # Local configure fragment for sysdeps/csky.
 
-$as_echo "#define PI_STATIC_AND_HIDDEN 1" >>confdefs.h
-
-
 # PIE builds fail on binutils 2.37 and earlier, see:
 # https://sourceware.org/bugzilla/show_bug.cgi?id=28672
 $as_echo "#define PIE_UNSUPPORTED 1" >>confdefs.h
index 8e00824..ffd8c1c 100644 (file)
@@ -1,8 +1,6 @@
 GLIBC_PROVIDES dnl See aclocal.m4 in the top level source directory.
 # Local configure fragment for sysdeps/csky.
 
-AC_DEFINE(PI_STATIC_AND_HIDDEN)
-
 # PIE builds fail on binutils 2.37 and earlier, see:
 # https://sourceware.org/bugzilla/show_bug.cgi?id=28672
 AC_DEFINE(PIE_UNSUPPORTED)
index cf5acf9..ebb42c5 100644 (file)
@@ -32,6 +32,9 @@ cat >>confdefs.h <<_ACEOF
 _ACEOF
 
 
+$as_echo "#define HIDDEN_VAR_NEEDS_DYNAMIC_RELOC 1" >>confdefs.h
+
+
 # PIE builds fail on binutils 2.37 and earlier, see:
 # https://sourceware.org/bugzilla/show_bug.cgi?id=28672
 $as_echo "#define PIE_UNSUPPORTED 1" >>confdefs.h
index 3e1c35b..5e59a63 100644 (file)
@@ -20,6 +20,8 @@ fi
 rm -f conftest*])
 AC_DEFINE_UNQUOTED(ASM_LINE_SEP, $libc_cv_asm_line_sep)
 
+AC_DEFINE(HIDDEN_VAR_NEEDS_DYNAMIC_RELOC)
+
 # PIE builds fail on binutils 2.37 and earlier, see:
 # https://sourceware.org/bugzilla/show_bug.cgi?id=28672
 AC_DEFINE(PIE_UNSUPPORTED)
index 748cb52..90be9c0 100644 (file)
@@ -1,9 +1,6 @@
 # This file is generated from configure.ac by Autoconf.  DO NOT EDIT!
  # Local configure fragment for sysdeps/ia64.
 
-$as_echo "#define PI_STATIC_AND_HIDDEN 1" >>confdefs.h
-
-
 # PIE builds fail on binutils 2.37 and earlier, see:
 # https://sourceware.org/bugzilla/show_bug.cgi?id=28672
 $as_echo "#define PIE_UNSUPPORTED 1" >>confdefs.h
index 8e5fba3..6958c26 100644 (file)
@@ -1,10 +1,6 @@
 GLIBC_PROVIDES dnl See aclocal.m4 in the top level source directory.
 # Local configure fragment for sysdeps/ia64.
 
-dnl It is always possible to access static and hidden symbols in an
-dnl position independent way.
-AC_DEFINE(PI_STATIC_AND_HIDDEN)
-
 # PIE builds fail on binutils 2.37 and earlier, see:
 # https://sourceware.org/bugzilla/show_bug.cgi?id=28672
 AC_DEFINE(PIE_UNSUPPORTED)
diff --git a/sysdeps/m68k/configure b/sysdeps/m68k/configure
new file mode 100644 (file)
index 0000000..983836a
--- /dev/null
@@ -0,0 +1,7 @@
+# This file is generated from configure.ac by Autoconf.  DO NOT EDIT!
+ # Local configure fragment for sysdeps/m68k.
+
+# Accessing static and hidden variables in a shared object needs relative
+# relocation.
+$as_echo "#define HIDDEN_VAR_NEEDS_DYNAMIC_RELOC 1" >>confdefs.h
+
diff --git a/sysdeps/m68k/configure.ac b/sysdeps/m68k/configure.ac
new file mode 100644 (file)
index 0000000..1c373b1
--- /dev/null
@@ -0,0 +1,6 @@
+GLIBC_PROVIDES dnl See aclocal.m4 in the top level source directory.
+# Local configure fragment for sysdeps/m68k.
+
+# Accessing static and hidden variables in a shared object needs relative
+# relocation.
+AC_DEFINE(HIDDEN_VAR_NEEDS_DYNAMIC_RELOC)
index e665256..b530633 100755 (executable)
@@ -1,6 +1,9 @@
 # This file is generated from configure.ac by Autoconf.  DO NOT EDIT!
  # Local configure fragment for sysdeps/microblaze.
 
+$as_echo "#define HIDDEN_VAR_NEEDS_DYNAMIC_RELOC 1" >>confdefs.h
+
+
 # gcc 11.2.1 and earlier crash with an internal compiler error, see:
 # https://gcc.gnu.org/bugzilla/show_bug.cgi?id=103613
 $as_echo "#define PIE_UNSUPPORTED 1" >>confdefs.h
index 1c58f70..0b451df 100644 (file)
@@ -1,6 +1,8 @@
 GLIBC_PROVIDES dnl See aclocal.m4 in the top level source directory.
 # Local configure fragment for sysdeps/microblaze.
 
+AC_DEFINE(HIDDEN_VAR_NEEDS_DYNAMIC_RELOC)
+
 # gcc 11.2.1 and earlier crash with an internal compiler error, see:
 # https://gcc.gnu.org/bugzilla/show_bug.cgi?id=103613
 AC_DEFINE(PIE_UNSUPPORTED)
index 4e13248..3f4d9e9 100644 (file)
@@ -1,6 +1,8 @@
 # This file is generated from configure.ac by Autoconf.  DO NOT EDIT!
  # Local configure fragment for sysdeps/mips.
 
+$as_echo "#define HIDDEN_VAR_NEEDS_DYNAMIC_RELOC 1" >>confdefs.h
+
 
 
 
index bcbdaff..d3cd780 100644 (file)
@@ -3,7 +3,7 @@ GLIBC_PROVIDES dnl See aclocal.m4 in the top level source directory.
 
 dnl No MIPS GCC supports accessing static and hidden symbols in an
 dnl position independent way.
-dnl AC_DEFINE(PI_STATIC_AND_HIDDEN)
+AC_DEFINE(HIDDEN_VAR_NEEDS_DYNAMIC_RELOC)
 
 AC_CACHE_CHECK([whether the compiler is using the 2008 NaN encoding],
   libc_cv_mips_nan2008, [AC_EGREP_CPP(yes, [dnl
index 14c8a3a..b3cd283 100644 (file)
@@ -160,3 +160,6 @@ $as_echo "$libc_cv_nios2_be" >&6; }
 if test $libc_cv_nios2_be = yes; then
   as_fn_error $? "Big endian not supported for Nios II" "$LINENO" 5
 fi
+
+$as_echo "#define HIDDEN_VAR_NEEDS_DYNAMIC_RELOC 1" >>confdefs.h
+
index f05f438..f738e9a 100644 (file)
@@ -11,3 +11,5 @@ AC_CACHE_CHECK([for big endian],
 if test $libc_cv_nios2_be = yes; then
   AC_MSG_ERROR([Big endian not supported for Nios II])
 fi
+
+AC_DEFINE(HIDDEN_VAR_NEEDS_DYNAMIC_RELOC)
index 1fe508c..16146a8 100644 (file)
@@ -1,5 +1,2 @@
 # This file is generated from configure.ac by Autoconf.  DO NOT EDIT!
  # Local configure fragment for sysdeps/or1k.
-
-$as_echo "#define PI_STATIC_AND_HIDDEN 1" >>confdefs.h
-
index 76ff97d..b0214c6 100644 (file)
@@ -1,4 +1,2 @@
 GLIBC_PROVIDES dnl See aclocal.m4 in the top level source directory.
 # Local configure fragment for sysdeps/or1k.
-
-AC_DEFINE(PI_STATIC_AND_HIDDEN)
index 29cfd53..5515053 100644 (file)
@@ -1,6 +1,9 @@
 # This file is generated from configure.ac by Autoconf.  DO NOT EDIT!
  # Local configure fragment for sysdeps/powerpc/powerpc32.
 
+$as_echo "#define HIDDEN_VAR_NEEDS_DYNAMIC_RELOC 1" >>confdefs.h
+
+
 # See whether GCC uses -msecure-plt.
 { $as_echo "$as_me:${as_lineno-$LINENO}: checking for -msecure-plt by default" >&5
 $as_echo_n "checking for -msecure-plt by default... " >&6; }
index 5d3a9b5..2f0ea63 100644 (file)
@@ -1,6 +1,8 @@
 GLIBC_PROVIDES dnl See aclocal.m4 in the top level source directory.
 # Local configure fragment for sysdeps/powerpc/powerpc32.
 
+AC_DEFINE(HIDDEN_VAR_NEEDS_DYNAMIC_RELOC)
+
 # See whether GCC uses -msecure-plt.
 AC_CACHE_CHECK(for -msecure-plt by default, libc_cv_ppc_secure_plt, [dnl
 echo 'int foo (void) { extern int bar; return bar; }' > conftest.c
index fddea03..f57c58a 100644 (file)
@@ -1,6 +1,9 @@
 # This file is generated from configure.ac by Autoconf.  DO NOT EDIT!
  # Local configure fragment for sysdeps/powerpc/powerpc64.
 
+$as_echo "#define HIDDEN_VAR_NEEDS_DYNAMIC_RELOC 1" >>confdefs.h
+
+
 { $as_echo "$as_me:${as_lineno-$LINENO}: checking for support for overlapping .opd entries" >&5
 $as_echo_n "checking for support for overlapping .opd entries... " >&6; }
 if ${libc_cv_overlapping_opd+:} false; then :
index 1f3d544..111a0ae 100644 (file)
@@ -1,6 +1,8 @@
 GLIBC_PROVIDES dnl See aclocal.m4 in the top level source directory.
 # Local configure fragment for sysdeps/powerpc/powerpc64.
 
+AC_DEFINE(HIDDEN_VAR_NEEDS_DYNAMIC_RELOC)
+
 AC_CACHE_CHECK(for support for overlapping .opd entries,
 libc_cv_overlapping_opd, [dnl
 libc_cv_overlapping_opd=no
index 6b256c6..8e559b5 100644 (file)
@@ -102,7 +102,7 @@ do_test (void)
   if (&bar == bar_ptr)
     printf ("PASS: bar address read from IFUNC resolver is correct.\n");
 #if !defined TST_TLSIFUNC_STATIC || !defined PIC \
-    || !defined PI_STATIC_AND_HIDDEN
+    || defined HIDDEN_VAR_NEEDS_DYNAMIC_RELOC
   else
     {
       printf ("FAIL: bar address read from IFUNC resolver is incorrect.\n");
index 4a56fca..2372225 100644 (file)
@@ -1,9 +1,6 @@
 # This file is generated from configure.ac by Autoconf.  DO NOT EDIT!
  # Local configure fragment for sysdeps/riscv/elf.
 
-$as_echo "#define PI_STATIC_AND_HIDDEN 1" >>confdefs.h
-
-
 # Check if static linker supports R_RISCV_ALIGN
 { $as_echo "$as_me:${as_lineno-$LINENO}: checking for R_RISCV_ALIGN linker relaxation support" >&5
 $as_echo_n "checking for R_RISCV_ALIGN linker relaxation support... " >&6; }
index 44a5279..dbcc216 100644 (file)
@@ -1,8 +1,6 @@
 GLIBC_PROVIDES dnl See aclocal.m4 in the top level source directory.
 # Local configure fragment for sysdeps/riscv/elf.
 
-AC_DEFINE(PI_STATIC_AND_HIDDEN)
-
 # Check if static linker supports R_RISCV_ALIGN
 AC_CACHE_CHECK([for R_RISCV_ALIGN linker relaxation support], [libc_cv_riscv_r_align],[dnl
   cat > conftest.S <<EOF
index 431088a..cc68cbb 100644 (file)
@@ -1,9 +1,6 @@
 # This file is generated from configure.ac by Autoconf.  DO NOT EDIT!
  # Local configure fragment for sysdeps/s390.
 
-$as_echo "#define PI_STATIC_AND_HIDDEN 1" >>confdefs.h
-
-
 { $as_echo "$as_me:${as_lineno-$LINENO}: checking for __builtin_tbegin" >&5
 $as_echo_n "checking for __builtin_tbegin... " >&6; }
 if ${libc_cv_gcc_builtin_tbegin+:} false; then :
index 14948c8..daf1bc6 100644 (file)
@@ -1,10 +1,6 @@
 GLIBC_PROVIDES dnl See aclocal.m4 in the top level source directory.
 # Local configure fragment for sysdeps/s390.
 
-dnl It is always possible to access static and hidden symbols in an
-dnl position independent way.
-AC_DEFINE(PI_STATIC_AND_HIDDEN)
-
 AC_CACHE_CHECK(for __builtin_tbegin, libc_cv_gcc_builtin_tbegin, [dnl
 cat > conftest.c <<\EOF
 #include <htmintrin.h>
index 110eb65..3c05bb6 100644 (file)
@@ -1,5 +1,2 @@
 # This file is generated from configure.ac by Autoconf.  DO NOT EDIT!
  # Local configure fragment for sysdeps/sh.
-
-$as_echo "#define PI_STATIC_AND_HIDDEN 1" >>confdefs.h
-
index 21400c4..28d9e9a 100644 (file)
@@ -1,6 +1,2 @@
 GLIBC_PROVIDES dnl See aclocal.m4 in the top level source directory.
 # Local configure fragment for sysdeps/sh.
-
-dnl It is always possible to access static and hidden symbols in an
-dnl position independent way.
-AC_DEFINE(PI_STATIC_AND_HIDDEN)
index 491b00f..70c084d 100644 (file)
@@ -1,4 +1,2 @@
 # This file is generated from configure.ac by Autoconf.  DO NOT EDIT!
  # Local configure fragment for sysdeps/sparc.
-
-$as_echo "#define PI_STATIC_AND_HIDDEN 1" >>confdefs.h
index 5cdc0a9..4fc6d6d 100644 (file)
@@ -1,4 +1,2 @@
 GLIBC_PROVIDES dnl See aclocal.m4 in the top level source directory.
 # Local configure fragment for sysdeps/sparc.
-
-AC_DEFINE(PI_STATIC_AND_HIDDEN)
index 46d436f..a9c8c2e 100644 (file)
@@ -190,8 +190,5 @@ fi
 config_vars="$config_vars
 enable-x86-isa-level = $libc_cv_include_x86_isa_level"
 
-$as_echo "#define PI_STATIC_AND_HIDDEN 1" >>confdefs.h
-
-
 $as_echo "#define SUPPORT_STATIC_PIE 1" >>confdefs.h
 
index 918b636..edd43a2 100644 (file)
@@ -128,9 +128,5 @@ if test $libc_cv_include_x86_isa_level = yes; then
 fi
 LIBC_CONFIG_VAR([enable-x86-isa-level], [$libc_cv_include_x86_isa_level])
 
-dnl It is always possible to access static and hidden symbols in an
-dnl position independent way.
-AC_DEFINE(PI_STATIC_AND_HIDDEN)
-
 dnl Static PIE is supported.
 AC_DEFINE(SUPPORT_STATIC_PIE)