[PATCH 19/39] elf: Enable tst-dlopen-nodelete-reloc if TEST_CXX supports STB_GNU_UNIQUE

H.J. Lu hjl.tools@gmail.com
Sun Dec 22 00:04:42 GMT 2024


tst-dlopen-nodelete-reloc requires STB_GNU_UNIQUE support so that NODELETE
is propagated by do_lookup_unique.  Enable it only if TEST_CXX supports
STB_GNU_UNIQUE,

Signed-off-by: H.J. Lu <hjl.tools@gmail.com>
---
 configure    | 58 ++++++++++++++++++++++++++++++++++++++++++++++++++++
 configure.ac | 33 ++++++++++++++++++++++++++++++
 elf/Makefile | 22 +++++++++++++-------
 3 files changed, 106 insertions(+), 7 deletions(-)

diff --git a/configure b/configure
index 85d4832fac..f5e8096099 100755
--- a/configure
+++ b/configure
@@ -8034,6 +8034,64 @@ CXX="$saved_CXX"
 config_vars="$config_vars
 test-config-cxxflags-finput-charset-ascii = $libc_cv_test_cxxflags_finput_charset_ascii"
 
+conftest_code="
+extern int not_exist (void);
+
+inline int make_unique (void)
+{
+  /* Static variables in inline functions and classes
+     generate STB_GNU_UNIQUE symbols.  */
+  static int unique;
+  return ++unique;
+}
+
+int foo (void)
+{
+  return make_unique () + not_exist ();
+}
+"
+
+
+cat > conftest.cc <<EOF
+$conftest_code
+EOF
+
+saved_CXX="$CXX"
+CXX="$TEST_CXX"
+{ printf "%s\n" "$as_me:${as_lineno-$LINENO}: checking for STB_GNU_UNIQUE in testing" >&5
+printf %s "checking for STB_GNU_UNIQUE in testing... " >&6; }
+if test ${libc_cv_test_stb_gnu_unique+y}
+then :
+  printf %s "(cached) " >&6
+else case e in #(
+  e)     if { ac_try='${CXX-c++} $CXXFLAGS $CPPFLAGS -c conftest.cc -o conftest 1>&5'
+  { { eval echo "\"\$as_me\":${as_lineno-$LINENO}: \"$ac_try\""; } >&5
+  (eval $ac_try) 2>&5
+  ac_status=$?
+  printf "%s\n" "$as_me:${as_lineno-$LINENO}: \$? = $ac_status" >&5
+  test $ac_status = 0; }; }
+    then
+
+if $READELF -sW conftest | grep -q "UNIQUE.* _ZZ11make_uniquevE6unique"; then
+  libc_cv_test_stb_gnu_unique=yes
+else
+  libc_cv_test_stb_gnu_unique=no
+fi
+
+    else
+      libc_cv_test_stb_gnu_unique=no
+    fi ;;
+esac
+fi
+{ printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: $libc_cv_test_stb_gnu_unique" >&5
+printf "%s\n" "$libc_cv_test_stb_gnu_unique" >&6; }
+
+CXX="$saved_CXX"
+
+rm -f conftest*
+config_vars="$config_vars
+have-test-stb-gnu-unique = $libc_cv_test_stb_gnu_unique"
+
 { printf "%s\n" "$as_me:${as_lineno-$LINENO}: checking for libgd" >&5
 printf %s "checking for libgd... " >&6; }
 if test "$with_gd" != "no"; then
diff --git a/configure.ac b/configure.ac
index bc6babe548..e331557350 100644
--- a/configure.ac
+++ b/configure.ac
@@ -1600,6 +1600,39 @@ LIBC_TRY_TEST_CXX_OPTION([-finput-charset=ascii],
 LIBC_CONFIG_VAR(test-config-cxxflags-finput-charset-ascii,
 		$libc_cv_test_cxxflags_finput_charset_ascii)
 
+conftest_code="
+extern int not_exist (void);
+
+inline int make_unique (void)
+{
+  /* Static variables in inline functions and classes
+     generate STB_GNU_UNIQUE symbols.  */
+  static int unique;
+  return ++unique;
+}
+
+int foo (void)
+{
+  return make_unique () + not_exist ();
+}
+"
+
+dnl Check if TEST_CXX supports STB_GNU_UNIQUE.
+LIBC_TRY_TEST_CXX_COMMAND([for STB_GNU_UNIQUE],
+  [$conftest_code],
+  [-c],
+  libc_cv_test_stb_gnu_unique,
+  [
+if $READELF -sW conftest | grep -q "UNIQUE.* _ZZ11make_uniquevE6unique"; then
+  libc_cv_test_stb_gnu_unique=yes
+else
+  libc_cv_test_stb_gnu_unique=no
+fi
+  ],
+  [libc_cv_test_stb_gnu_unique=no],
+)
+LIBC_CONFIG_VAR([have-test-stb-gnu-unique], [$libc_cv_test_stb_gnu_unique])
+
 dnl Check whether we have the gd library available.
 AC_MSG_CHECKING(for libgd)
 if test "$with_gd" != "no"; then
diff --git a/elf/Makefile b/elf/Makefile
index 3c17688f19..e8fc6bd65f 100644
--- a/elf/Makefile
+++ b/elf/Makefile
@@ -505,11 +505,15 @@ tests += \
   valgrind-test \
   # tests
 tests-cxx = \
-  tst-dlopen-nodelete-reloc \
   tst-nodelete \
   tst-unique3 \
   tst-unique4 \
   # tests-cxx
+ifeq ($(have-test-stb-gnu-unique), yes)
+tests-cxx += \
+  tst-dlopen-nodelete-reloc \
+  # tests-cxx
+endif
 
 tests += $(if $(CXX),$(tests-cxx))
 
@@ -1042,6 +1046,15 @@ modules-names += \
   # modules-names
 
 modules-names-cxx = \
+  tst-nodelete-rtldmod \
+  tst-nodelete-uniquemod \
+  tst-nodelete-zmod \
+  tst-unique3lib \
+  tst-unique3lib2 \
+  tst-unique4lib \
+  # modules-names-cxx
+ifeq ($(have-test-stb-gnu-unique), yes)
+modules-names-cxx += \
   tst-dlopen-nodelete-reloc-mod1 \
   tst-dlopen-nodelete-reloc-mod2 \
   tst-dlopen-nodelete-reloc-mod3 \
@@ -1059,13 +1072,8 @@ modules-names-cxx = \
   tst-dlopen-nodelete-reloc-mod15 \
   tst-dlopen-nodelete-reloc-mod16 \
   tst-dlopen-nodelete-reloc-mod17 \
-  tst-nodelete-rtldmod \
-  tst-nodelete-uniquemod \
-  tst-nodelete-zmod \
-  tst-unique3lib \
-  tst-unique3lib2 \
-  tst-unique4lib \
   # modules-names-cxx
+endif
 
 modules-names += \
   $(if $(CXX),$(modules-names-cxx)) \
-- 
2.47.1



More information about the Libc-alpha mailing list