1 From e47de5cb2d4dbecb58f569ed241e8e95c568f03c Mon Sep 17 00:00:00 2001
2 From: Florian Weimer <fweimer@redhat.com>
3 Date: Fri, 29 Apr 2022 16:37:51 +0200
4 Subject: [PATCH] Do not use --hash-style=both for building glibc shared
7 The comment indicates that --hash-style=both was used to maintain
8 compatibility with static dlopen, but we had many internal ABI
9 changes since then, so this compatiblity does not add value anymore.
11 Reviewed-by: Carlos O'Donell <carlos@redhat.com>
13 Makeconfig | 9 +++++++++
16 configure | 28 ++++++++++++++++++++++++++++
17 configure.ac | 16 ++++++++++++++++
18 5 files changed, 61 insertions(+)
20 diff --git b/Makeconfig a/Makeconfig
21 index 760f14e92f..0aa5fb0099 100644
24 @@ -362,6 +362,15 @@ relro-LDFLAGS = -Wl,-z,relro
25 LDFLAGS.so += $(relro-LDFLAGS)
26 LDFLAGS-rtld += $(relro-LDFLAGS)
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)
37 ifeq (no,$(build-pie-default))
38 pie-default = $(no-pie-ccflag)
39 else # build-pie-default
40 diff --git b/Makerules a/Makerules
41 index 354528b8c7..428464f092 100644
44 @@ -557,6 +557,13 @@ $(common-objpfx)shlib.lds: $(common-objpfx)config.make $(..)Makerules
45 -Wl,--verbose 2>/dev/null | \
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}' \
53 + -e 's/^.*\.hash[ ]*:.*$$/ .note.ABI-tag : { *(.note.ABI-tag) } &/' \
55 -e 's/^.*\*(\.dynbss).*$$/& \
56 PROVIDE(__start___libc_freeres_ptrs = .); \
57 *(__libc_freeres_ptrs) \
58 diff --git b/config.make.in a/config.make.in
59 index fff4c78dd0..bf728c71c0 100644
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@
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@
70 diff --git b/configure a/configure
71 index 716dc041b6..5a730dc5fc 100755
74 @@ -622,6 +622,7 @@ libc_cv_cc_nofma
75 libc_cv_mtls_dialect_gnu2
82 @@ -6193,6 +6194,33 @@ $as_echo "$libc_cv_fpie" >&6; }
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
91 + cat > conftest.c <<EOF
92 +int _start (void) { return 42; }
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
100 + $as_echo "$as_me:${as_lineno-$LINENO}: \$? = $ac_status" >&5
101 + test $ac_status = 0; }; }
103 + libc_cv_hashstyle=yes
105 + libc_cv_hashstyle=no
109 +{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $libc_cv_hashstyle" >&5
110 +$as_echo "$libc_cv_hashstyle" >&6; }
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 :
116 diff --git b/configure.ac a/configure.ac
117 index d08ad4d64e..a045f6608e 100644
120 @@ -1360,6 +1360,22 @@ LIBC_TRY_CC_OPTION([-fpie], [libc_cv_fpie=yes], [libc_cv_fpie=no])
122 AC_SUBST(libc_cv_fpie)
124 +AC_CACHE_CHECK(for --hash-style option,
125 + libc_cv_hashstyle, [dnl
126 +cat > conftest.c <<EOF
127 +int _start (void) { return 42; }
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])
133 + libc_cv_hashstyle=yes
135 + libc_cv_hashstyle=no
138 +AC_SUBST(libc_cv_hashstyle)
140 AC_CACHE_CHECK(for GLOB_DAT reloc,
141 libc_cv_has_glob_dat, [dnl
142 cat > conftest.c <<EOF