[1/3] Check linker suppor for -z indirect-extern-access

Message ID 20211007200813.1626777-2-hjl.tools@gmail.com
State New, archived
Headers
Series Update tests for protected symbol access |

Checks

Context Check Description
dj/TryBot-apply_patch success Patch applied to master at the time it was sent

Commit Message

H.J. Lu Oct. 7, 2021, 8:08 p.m. UTC
  Binutils 2.37 supports -z indirect-extern-access.  If
GNU_PROPERTY_1_NEEDED_INDIRECT_EXTERN_ACCESS is set on any input
relocatable files:
1. Don't generate copy relocations.
2. Turn off extern_protected_data since it implies
   GNU_PROPERTY_NO_COPY_ON_PROTECTED.
3. Treate reference to protected symbols with indirect external access
   as local.
4. Set GNU_PROPERTY_1_NEEDED_INDIRECT_EXTERN_ACCESS on output.
5. When generating executable, clear this bit when there are non-GOT
   or non-PLT relocations in input relocatable files without the bit set.
6. Add -z [no]indirect-extern-access to control indirect external access.
---
 configure    | 32 ++++++++++++++++++++++++++++++++
 configure.ac | 21 +++++++++++++++++++++
 2 files changed, 53 insertions(+)
  

Patch

diff --git a/configure b/configure
index 39d75eb4ed..ac24218009 100755
--- a/configure
+++ b/configure
@@ -5819,6 +5819,38 @@  fi
 $as_echo "$libc_cv_insert" >&6; }
 
 
+{ $as_echo "$as_me:${as_lineno-$LINENO}: checking -z indirect-extern-access" >&5
+$as_echo_n "checking -z indirect-extern-access... " >&6; }
+if ${libc_cv_z_indirect_extern_access+:} false; then :
+  $as_echo_n "(cached) " >&6
+else
+  cat > conftest.c <<EOF
+		__attribute__ ((visibility ("protected")))
+		void bar (void) {}
+		void *bar_p (void) { return &bar; }
+EOF
+		libc_cv_z_indirect_extern_access=no
+		if { ac_try='${CC-cc} -Wl,-z,indirect-extern-access
+			-nostdlib -nostartfiles $CFLAGS $CPPFLAGS $LDFLAGS
+			-fPIC -shared $no_ssp -o conftest.so conftest.c
+			1>&5'
+  { { eval echo "\"\$as_me\":${as_lineno-$LINENO}: \"$ac_try\""; } >&5
+  (eval $ac_try) 2>&5
+  ac_status=$?
+  $as_echo "$as_me:${as_lineno-$LINENO}: \$? = $ac_status" >&5
+  test $ac_status = 0; }; }; then
+		  libc_cv_z_indirect_extern_access=yes
+		else
+		  libc_cv_z_indirect_extern_access=no
+		fi
+		rm -f conftest.*
+
+fi
+{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $libc_cv_z_indirect_extern_access" >&5
+$as_echo "$libc_cv_z_indirect_extern_access" >&6; }
+config_vars="$config_vars
+have-z-indirect-extern-access = $libc_cv_z_indirect_extern_access"
+
 { $as_echo "$as_me:${as_lineno-$LINENO}: checking for broken __attribute__((alias()))" >&5
 $as_echo_n "checking for broken __attribute__((alias()))... " >&6; }
 if ${libc_cv_broken_alias_attribute+:} false; then :
diff --git a/configure.ac b/configure.ac
index 00f49f09f7..8bb0d1a838 100644
--- a/configure.ac
+++ b/configure.ac
@@ -1235,6 +1235,27 @@  EOF
 	       ])
 AC_SUBST(libc_cv_insert)
 
+AC_CACHE_CHECK(-z indirect-extern-access,
+	       libc_cv_z_indirect_extern_access,
+	       [cat > conftest.c <<EOF
+		__attribute__ ((visibility ("protected")))
+		void bar (void) {}
+		void *bar_p (void) { return &bar; }
+EOF
+		libc_cv_z_indirect_extern_access=no
+		if AC_TRY_COMMAND([${CC-cc} -Wl,-z,indirect-extern-access
+			-nostdlib -nostartfiles $CFLAGS $CPPFLAGS $LDFLAGS
+			-fPIC -shared $no_ssp -o conftest.so conftest.c
+			1>&AS_MESSAGE_LOG_FD]); then
+		  libc_cv_z_indirect_extern_access=yes
+		else
+		  libc_cv_z_indirect_extern_access=no
+		fi
+		rm -f conftest.*
+	       ])
+LIBC_CONFIG_VAR([have-z-indirect-extern-access],
+		[$libc_cv_z_indirect_extern_access])
+
 AC_CACHE_CHECK(for broken __attribute__((alias())),
 	       libc_cv_broken_alias_attribute,
 	       [cat > conftest.c <<EOF