[PATCH libgpg-error] build: fix mutex size computation on systems without gawk

Alexis Lothoré alexis.lothore at bootlin.com
Mon Jun 22 10:41:53 CEST 2026


The gen-lock-obj.sh generates an internal header exposing the
gpgrt_lock_t structure, based on the size deduced from an objdump on a
test binary generated at configure time. When using gawk, the header is
correctly generated:

  typedef struct
  {
    long _vers;
    union {
      volatile char _priv[24];
      long _x_align;
      long *_xp_align;
    } u;
  } gpgrt_lock_t;

  #define GPGRT_LOCK_INITIALIZER {1,{{0,0,0,0,0,0,0,0, \
                                      0,0,0,0,0,0,0,0, \
                                      0,0,0,0,0,0,0,0}}}

but when the build host does not have gawk but mawk for example, the
script fails to parse correctly the objdump output, leading to a faulty
header being generated:

  typedef struct
  {
    long _vers;
    union {
      volatile char _priv[0];
      long _x_align;
      long *_xp_align;
    } u;
  } gpgrt_lock_t;

  #define GPGRT_LOCK_INITIALIZER {1,{{}}}

The script seems to aim to support different implementations of awk, as
it is conditionally setting the --non-decimal-data argument depending on
whether we are using gawk or any other implementation. There are then
different ways of fixing this:

- enforcing gawk usage
- making the size parsing work with any awk implementation (and so, make
  it not depend on --non-decimal-data anymore)
- use another way of retrieving the symbol size that does output
  directly a decimal value

Fix size parsing by replacing objdump, which outputs a hexadecimal value
(prefixed with 0x) with nm.

Signed-off-by: Alexis Lothoré <alexis.lothore at bootlin.com>
---
 configure.ac        | 10 +++++-----
 src/gen-lock-obj.sh | 21 ++++++++-------------
 2 files changed, 13 insertions(+), 18 deletions(-)

diff --git a/configure.ac b/configure.ac
index e3d1a19d1527..0ef48b4aff45 100644
--- a/configure.ac
+++ b/configure.ac
@@ -635,16 +635,16 @@ if test x"$gl_use_threads" = xno; then
 elif test x$cross_compiling = xyes; then
   case $host in
     *-*-gnu* | *-*-linux-gnu* | *-*-linux-musl* | wasm*-*-emscripten)
-    AC_CHECK_TOOL(OBJDUMP, [objdump])
-    if test -n "$OBJDUMP"; then
+    AC_CHECK_TOOL(NM, [nm])
+    if test -n "$NM"; then
       lock_obj_h_generated=yes
       if test ! -d src; then mkdir src; fi
       LOCK_ABI_VERSION=1 host=$host host_alias=$host_alias \
-          CC=$CC OBJDUMP=$OBJDUMP \
+          CC=$CC NM=$NM AWK=$AWK \
           ac_ext=$ac_ext ac_objext=$ac_objext \
-          AWK=$AWK $srcdir/src/gen-lock-obj.sh \
+          $srcdir/src/gen-lock-obj.sh \
           >src/lock-obj-pub.native.h
-      AC_MSG_NOTICE([generated src/lock-obj-pub.native.h using $host_alias-objdump and $AWK])
+      AC_MSG_NOTICE([generated src/lock-obj-pub.native.h using $host_alias-nm and $AWK])
     else
       force_use_syscfg=yes
     fi
diff --git a/src/gen-lock-obj.sh b/src/gen-lock-obj.sh
index a8d93527fef3..611a46a56780 100755
--- a/src/gen-lock-obj.sh
+++ b/src/gen-lock-obj.sh
@@ -24,7 +24,7 @@
 # Following variables should be defined to invoke this script
 #
 #   CC
-#   OBJDUMP
+#   NM
 #   AWK
 #   ac_ext
 #   ac_object
@@ -34,8 +34,8 @@
 # An example:
 #
 # LOCK_ABI_VERSION=1 host=x86_64-pc-linux-gnu host_alias=x86_64-linux-gnu \
-#     CC=$host_alias-gcc OBJDUMP=$host_alias-objdump ac_ext=c ac_objext=o \
-#     AWK=gawk ./gen-lock-obj.sh
+#     CC=$host_alias-gcc NM=$host_alias-nm AWK=gawk ac_ext=c ac_objext=o \
+#     ./gen-lock-obj.sh
 #
 
 if test -n "`echo -n`"; then
@@ -61,22 +61,17 @@ typedef struct
 #define GPGRT_LOCK_INITIALIZER {-1}
 EOF
 else
-AWK_VERSION_OUTPUT=$($AWK 'BEGIN { print PROCINFO["version"] }')
-if test -n "$AWK_VERSION_OUTPUT"; then
-    # It's GNU awk, which supports PROCINFO.
-    AWK_OPTION=--non-decimal-data
-fi
-
 cat <<'EOF' >conftest.$ac_ext
 #include <pthread.h>
 pthread_mutex_t mtx = PTHREAD_MUTEX_INITIALIZER;
 EOF
 
 if $CC -c conftest.$ac_ext; then :
-  ac_mtx_size=$($OBJDUMP -t conftest.$ac_objext \
-         | $AWK $AWK_OPTION '
-/mtx$/ { mtx_size = int("0x" $5) }
-END { print mtx_size }')
+  ac_mtx_size=$($NM -S -t d conftest.$ac_objext | $AWK '/ mtx$/{print $2+0}')
+  if test -z "$ac_mtx_size"; then
+      echo "Can't determine mutex size"
+      exit 1
+  fi
 else
     echo "Can't determine mutex size"
     exit 1
-- 
2.54.0




More information about the Gnupg-devel mailing list