File 0006-re-enable-DT_HASH.patch of Package glibc

From 4431f5b96d85c3badffb2d058ad094a6e4e147b0 Mon Sep 17 00:00:00 2001
From: Thomas Crider <tcrider@localhost.localdomain>
Date: Wed, 16 Nov 2022 12:43:48 -0700
Subject: [PATCH 6/6] re-enable DT_HASH

---
 Makeconfig     |  9 +++++++++
 Makerules      |  7 +++++++
 config.make.in |  1 +
 configure      | 28 ++++++++++++++++++++++++++++
 configure.ac   | 16 ++++++++++++++++
 5 files changed, 61 insertions(+)

diff --git a/Makeconfig b/Makeconfig
index ba70321a..e2131d43 100644
--- a/Makeconfig
+++ b/Makeconfig
@@ -371,6 +371,15 @@ dt-relr-ldflag =
 no-dt-relr-ldflag =
 endif
 
+ifeq (yes,$(have-hash-style))
+# For the time being we unconditionally use 'both'.  At some time we
+# should declare statically linked code as 'out of luck' and compile
+# with --hash-style=gnu only.
+hashstyle-LDFLAGS = -Wl,--hash-style=both
+LDFLAGS.so += $(hashstyle-LDFLAGS)
+LDFLAGS-rtld += $(hashstyle-LDFLAGS)
+endif
+
 ifeq (no,$(build-pie-default))
 pie-default = $(no-pie-ccflag)
 else # build-pie-default
diff --git a/Makerules b/Makerules
index 513432c4..ad58ba15 100644
--- a/Makerules
+++ b/Makerules
@@ -558,6 +558,13 @@ $(common-objpfx)shlib.lds: $(common-objpfx)config.make $(..)Makerules
 		  -Wl,--verbose 2>/dev/null | \
 	  sed > $@T \
 	      -e '/^=========/,/^=========/!d;/^=========/d' \
+	      $(if $(filter yes,$(have-hash-style)), \
+		   -e 's/^.*\.gnu\.hash[ 	]*:.*$$/  .note.ABI-tag : { *(.note.ABI-tag) } &/' \
+		   -e '/^[ 	]*\.hash[ 	]*:.*$$/{h;d;}' \
+		   -e '/DATA_SEGMENT_ALIGN/{H;g}' \
+		, \
+		   -e 's/^.*\.hash[ 	]*:.*$$/  .note.ABI-tag : { *(.note.ABI-tag) } &/' \
+	       ) \
 	      -e 's/^.*\*(\.dynbss).*$$/& \
 		 PROVIDE(__start___libc_freeres_ptrs = .); \
 		 *(__libc_freeres_ptrs) \
diff --git a/config.make.in b/config.make.in
index d7c416cb..130e639d 100644
--- a/config.make.in
+++ b/config.make.in
@@ -69,6 +69,7 @@ have-libaudit = @have_libaudit@
 have-libcap = @have_libcap@
 have-cc-with-libunwind = @libc_cv_cc_with_libunwind@
 bind-now = @bindnow@
+have-hash-style = @libc_cv_hashstyle@
 use-default-link = @use_default_link@
 have-cxx-thread_local = @libc_cv_cxx_thread_local@
 have-loop-to-function = @libc_cv_cc_loop_to_function@
diff --git a/configure b/configure
index ff2c406b..07f93766 100755
--- a/configure
+++ b/configure
@@ -621,6 +621,7 @@ libc_cv_cc_submachine
 libc_cv_cc_nofma
 libc_cv_mtls_dialect_gnu2
 libc_cv_has_glob_dat
+libc_cv_hashstyle
 libc_cv_fpie
 libc_cv_z_execstack
 ASFLAGS_config
@@ -6192,6 +6193,33 @@ $as_echo "$libc_cv_fpie" >&6; }
 
 
 
+{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for --hash-style option" >&5
+$as_echo_n "checking for --hash-style option... " >&6; }
+if ${libc_cv_hashstyle+:} false; then :
+  $as_echo_n "(cached) " >&6
+else
+  cat > conftest.c <<EOF
+int _start (void) { return 42; }
+EOF
+if { ac_try='${CC-cc} $CFLAGS $CPPFLAGS $LDFLAGS $no_ssp
+			    -fPIC -shared -o conftest.so conftest.c
+			    -Wl,--hash-style=both -nostdlib 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_hashstyle=yes
+else
+  libc_cv_hashstyle=no
+fi
+rm -f conftest*
+fi
+{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $libc_cv_hashstyle" >&5
+$as_echo "$libc_cv_hashstyle" >&6; }
+
+
 { $as_echo "$as_me:${as_lineno-$LINENO}: checking for GLOB_DAT reloc" >&5
 $as_echo_n "checking for GLOB_DAT reloc... " >&6; }
 if ${libc_cv_has_glob_dat+:} false; then :
diff --git a/configure.ac b/configure.ac
index eb5bc6a1..870347c5 100644
--- a/configure.ac
+++ b/configure.ac
@@ -1360,6 +1360,22 @@ LIBC_TRY_CC_OPTION([-fpie], [libc_cv_fpie=yes], [libc_cv_fpie=no])
 
 AC_SUBST(libc_cv_fpie)
 
+AC_CACHE_CHECK(for --hash-style option,
+	       libc_cv_hashstyle, [dnl
+cat > conftest.c <<EOF
+int _start (void) { return 42; }
+EOF
+if AC_TRY_COMMAND([${CC-cc} $CFLAGS $CPPFLAGS $LDFLAGS $no_ssp
+			    -fPIC -shared -o conftest.so conftest.c
+			    -Wl,--hash-style=both -nostdlib 1>&AS_MESSAGE_LOG_FD])
+then
+  libc_cv_hashstyle=yes
+else
+  libc_cv_hashstyle=no
+fi
+rm -f conftest*])
+AC_SUBST(libc_cv_hashstyle)
+
 AC_CACHE_CHECK(for GLOB_DAT reloc,
 	       libc_cv_has_glob_dat, [dnl
 cat > conftest.c <<EOF
-- 
2.38.1

openSUSE Build Service is sponsored by