[PATCH] Add check-symbol-verion.awk

"H.J. Lu" <[email protected]>
Newsgroups gmane.comp.lib.glibc.alpha
Message-ID <CAMe9rOpb0QJqFnEp6sz3wnNGqO-KMM_TnX+hWUA1BMYpejbjKw@mail.gmail.com>
commit 6deadd4eb6ab4f59d116b2d7ad97be0d0848cb7f
Author: Adhemerval Zanella <[email protected]>
Date:   Wed Oct 8 10:55:05 2025 -0300

didn't remove sysdeps/m68k/m680x0/fpu/w_fmod_compat.c.  As the result,
due to a linker bug:

https://sourceware.org/bugzilla/show_bug.cgi?id=34550

there were 2 default versions of fmod in m68k libm:

   996: 0001433c   174 FUNC    WEAK   DEFAULT   12 fmod@@GLIBC_2.0
   997: 000307d4   214 FUNC    GLOBAL DEFAULT   12 fmod@@GLIBC_2.43

Add check-symbol-verion.awk to verify that versioned symbols only have
one default version in dynamic symbol table.

-- 
H.J.
0001-Add-check-symbol-verion.awk.patch (text/x-patch, 4.1 KB)
From 091bdd07bd4526cce96145f7cf2e2cf75b9809e0 Mon Sep 17 00:00:00 2001
From: "H.J. Lu" <[email protected]>
Date: Wed, 26 Aug 2026 15:18:35 +0800
Subject: [PATCH] Add check-symbol-verion.awk

commit 6deadd4eb6ab4f59d116b2d7ad97be0d0848cb7f
Author: Adhemerval Zanella <[email protected]>
Date:   Wed Oct 8 10:55:05 2025 -0300

didn't remove sysdeps/m68k/m680x0/fpu/w_fmod_compat.c.  As the result,
due to a linker bug:

https://sourceware.org/bugzilla/show_bug.cgi?id=34550

there were 2 default versions of fmod in m68k libm:

   996: 0001433c   174 FUNC    WEAK   DEFAULT   12 fmod@@GLIBC_2.0
   997: 000307d4   214 FUNC    GLOBAL DEFAULT   12 fmod@@GLIBC_2.43

Add check-symbol-verion.awk to verify that versioned symbols only have
one default version in dynamic symbol table.

Signed-off-by: H.J. Lu <[email protected]>
---
 elf/Makefile                    |  7 ++++
 scripts/check-symbol-verion.awk | 67 +++++++++++++++++++++++++++++++++
 2 files changed, 74 insertions(+)
 create mode 100644 scripts/check-symbol-verion.awk

diff --git a/elf/Makefile b/elf/Makefile
index c5bf1f38cb..5122a77075 100644
--- a/elf/Makefile
+++ b/elf/Makefile
@@ -1436,6 +1436,7 @@ tests-special += \
   $(objpfx)check-execstack.out \
   $(objpfx)check-initfini.out \
   $(objpfx)check-localplt.out \
+  $(objpfx)check-symbol-version.out \
   $(objpfx)check-textrel.out \
   $(objpfx)check-wx-segment.out \
   # tests-special
@@ -2381,6 +2382,12 @@ $(objpfx)check-initfini.out: $(..)scripts/check-initfini.awk \
 	$(evaluate-test)
 generated += check-initfini.out
 
+$(objpfx)check-symbol-version.out: $(..)scripts/check-symbol-verion.awk \
+			    $(all-built-dso:=.dynsym)
+	LC_ALL=C $(AWK) -f $^ > $@; \
+	$(evaluate-test)
+generated += check-symbol-version.out
+
 $(objpfx)tst-dlopenrpath: $(objpfx)tst-dlopenrpathmod.so
 CFLAGS-tst-dlopenrpath.c += -DPFX=\"$(objpfx)\"
 LDFLAGS-tst-dlopenrpathmod.so += -Wl,-rpath,\$$ORIGIN/test-subdir
diff --git a/scripts/check-symbol-verion.awk b/scripts/check-symbol-verion.awk
new file mode 100644
index 0000000000..2ddaa0edc9
--- /dev/null
+++ b/scripts/check-symbol-verion.awk
@@ -0,0 +1,67 @@
+# Copyright (C) 2026 Free Software Foundation, Inc.
+# This file is part of the GNU C Library.
+
+# The GNU C Library is free software; you can redistribute it and/or
+# modify it under the terms of the GNU Lesser General Public
+# License as published by the Free Software Foundation; either
+# version 2.1 of the License, or (at your option) any later version.
+
+# The GNU C Library is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+# Lesser General Public License for more details.
+
+# You should have received a copy of the GNU Lesser General Public
+# License along with the GNU C Library; if not, see
+# <https://www.gnu.org/licenses/>.
+
+# This awk script expects to get command-line files that are each
+# the output of 'readelf -W --dyn-syms' on a single shared object.
+# It exits successfully (0) if there are versioned symbols with more
+# than one default version in dynamic symbol table.
+# It fails (1) if any did contain versioned symbols with more than one
+# default version in dynamic symbol table.
+# It fails (2) if the input did not take the expected form.
+
+BEGIN { result = incorrect = sanity = 0 }
+
+function check_one(name) {
+  if (!sanity) {
+    print name ": *** input did not look like readelf -d output";
+    result = 2;
+  } else {
+    ok = 1;
+    if (incorrect) {
+      print name ": *** incorrect dynamic symbol table";
+      result = result ? result : 1;
+      ok = 0;
+    }
+    if (ok)
+      print name ": OK";
+  }
+
+  delete version
+  incorrect = sanity = 0
+}
+
+FILENAME != lastfile {
+  if (lastfile)
+    check_one(lastfile);
+  lastfile = FILENAME;
+}
+
+$1 == "Symbol" && $2 == "table" && $3 == "'.dynsym'" { sanity = 1 }
+$8 ~ "@@" {
+  split($8,a,"@");
+  if (version[a[1]] != "") {
+    incorrect = 1;
+    print a[1] " has 2 default versions: " version[a[1]] ", " a[3];
+  } else {
+    version[a[1]] = a[3];
+  }
+}
+
+END {
+  check_one(lastfile);
+  exit(result);
+}
-- 
2.55.0
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.