1From e47de5cb2d4dbecb58f569ed241e8e95c568f03c Mon Sep 17 00:00:00 2001
2From: Florian Weimer <fweimer@redhat.com>
3Date: Fri, 29 Apr 2022 16:37:51 +0200
4Subject: [PATCH] Do not use --hash-style=both for building glibc shared
5 objects
6
7The comment indicates that --hash-style=both was used to maintain
8compatibility with static dlopen, but we had many internal ABI
9changes since then, so this compatiblity does not add value anymore.
10
11Reviewed-by: Carlos O'Donell <carlos@redhat.com>
12---
13 Makeconfig | 9 +++++++++
14 Makerules | 7 +++++++
15 config.make.in | 1 +
16 configure | 28 ++++++++++++++++++++++++++++
17 configure.ac | 16 ++++++++++++++++
18 5 files changed, 61 insertions(+)
19
20diff --git b/Makeconfig a/Makeconfig
21index 760f14e92f..0aa5fb0099 100644
22--- b/Makeconfig
23+++ a/Makeconfig
24@@ -362,6 +362,15 @@ relro-LDFLAGS = -Wl,-z,relro
25 LDFLAGS.so += $(relro-LDFLAGS)
26 LDFLAGS-rtld += $(relro-LDFLAGS)
27
28+ifeq (yes,$(have-hash-style))
29+# For the time being we unconditionally use 'both'. At some time we
30+# should declare statically linked code as 'out of luck' and compile
31+# with --hash-style=gnu only.
32+hashstyle-LDFLAGS = -Wl,--hash-style=both
33+LDFLAGS.so += $(hashstyle-LDFLAGS)
34+LDFLAGS-rtld += $(hashstyle-LDFLAGS)
35+endif
36+
37 ifeq (no,$(build-pie-default))
38 pie-default = $(no-pie-ccflag)
39 else # build-pie-default
40diff --git b/Makerules a/Makerules
41index 354528b8c7..428464f092 100644
42--- b/Makerules
43+++ a/Makerules
44@@ -557,6 +557,13 @@ $(common-objpfx)shlib.lds: $(common-objpfx)config.make $(..)Makerules
45 -Wl,--verbose 2>/dev/null | \
46 sed > $@T \
47 -e '/^=========/,/^=========/!d;/^=========/d' \
48+ $(if $(filter yes,$(have-hash-style)), \
49+ -e 's/^.*\.gnu\.hash[ ]*:.*$$/ .note.ABI-tag : { *(.note.ABI-tag) } &/' \
50+ -e '/^[ ]*\.hash[ ]*:.*$$/{h;d;}' \
51+ -e '/DATA_SEGMENT_ALIGN/{H;g}' \
52+ , \
53+ -e 's/^.*\.hash[ ]*:.*$$/ .note.ABI-tag : { *(.note.ABI-tag) } &/' \
54+ ) \
55 -e 's/^.*\*(\.dynbss).*$$/& \
56 PROVIDE(__start___libc_freeres_ptrs = .); \
57 *(__libc_freeres_ptrs) \
58diff --git b/config.make.in a/config.make.in
59index fff4c78dd0..bf728c71c0 100644
60--- b/config.make.in
61+++ a/config.make.in
62@@ -70,6 +70,7 @@ have-libcap = @have_libcap@
63 have-cc-with-libunwind = @libc_cv_cc_with_libunwind@
64 fno-unit-at-a-time = @fno_unit_at_a_time@
65 bind-now = @bindnow@
66+have-hash-style = @libc_cv_hashstyle@
67 use-default-link = @use_default_link@
68 have-cxx-thread_local = @libc_cv_cxx_thread_local@
69 have-loop-to-function = @libc_cv_cc_loop_to_function@
70diff --git b/configure a/configure
71index 716dc041b6..5a730dc5fc 100755
72--- b/configure
73+++ a/configure
74@@ -622,6 +622,7 @@ libc_cv_cc_nofma
75 libc_cv_mtls_dialect_gnu2
76 fno_unit_at_a_time
77 libc_cv_has_glob_dat
78+libc_cv_hashstyle
79 libc_cv_fpie
80 libc_cv_z_execstack
81 ASFLAGS_config
82@@ -6193,6 +6194,33 @@ $as_echo "$libc_cv_fpie" >&6; }
83
84
85
86+{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for --hash-style option" >&5
87+$as_echo_n "checking for --hash-style option... " >&6; }
88+if ${libc_cv_hashstyle+:} false; then :
89+ $as_echo_n "(cached) " >&6
90+else
91+ cat > conftest.c <<EOF
92+int _start (void) { return 42; }
93+EOF
94+if { ac_try='${CC-cc} $CFLAGS $CPPFLAGS $LDFLAGS $no_ssp
95+ -fPIC -shared -o conftest.so conftest.c
96+ -Wl,--hash-style=both -nostdlib 1>&5'
97+ { { eval echo "\"\$as_me\":${as_lineno-$LINENO}: \"$ac_try\""; } >&5
98+ (eval $ac_try) 2>&5
99+ ac_status=$?
100+ $as_echo "$as_me:${as_lineno-$LINENO}: \$? = $ac_status" >&5
101+ test $ac_status = 0; }; }
102+then
103+ libc_cv_hashstyle=yes
104+else
105+ libc_cv_hashstyle=no
106+fi
107+rm -f conftest*
108+fi
109+{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $libc_cv_hashstyle" >&5
110+$as_echo "$libc_cv_hashstyle" >&6; }
111+
112+
113 { $as_echo "$as_me:${as_lineno-$LINENO}: checking for GLOB_DAT reloc" >&5
114 $as_echo_n "checking for GLOB_DAT reloc... " >&6; }
115 if ${libc_cv_has_glob_dat+:} false; then :
116diff --git b/configure.ac a/configure.ac
117index d08ad4d64e..a045f6608e 100644
118--- b/configure.ac
119+++ a/configure.ac
120@@ -1360,6 +1360,22 @@ LIBC_TRY_CC_OPTION([-fpie], [libc_cv_fpie=yes], [libc_cv_fpie=no])
121
122 AC_SUBST(libc_cv_fpie)
123
124+AC_CACHE_CHECK(for --hash-style option,
125+ libc_cv_hashstyle, [dnl
126+cat > conftest.c <<EOF
127+int _start (void) { return 42; }
128+EOF
129+if AC_TRY_COMMAND([${CC-cc} $CFLAGS $CPPFLAGS $LDFLAGS $no_ssp
130+ -fPIC -shared -o conftest.so conftest.c
131+ -Wl,--hash-style=both -nostdlib 1>&AS_MESSAGE_LOG_FD])
132+then
133+ libc_cv_hashstyle=yes
134+else
135+ libc_cv_hashstyle=no
136+fi
137+rm -f conftest*])
138+AC_SUBST(libc_cv_hashstyle)
139+
140 AC_CACHE_CHECK(for GLOB_DAT reloc,
141 libc_cv_has_glob_dat, [dnl
142 cat > conftest.c <<EOF
143--
1442.37.1
145