I did:
> 2024-09-20  Bruno Haible  <br...@clisp.org>
> 
>       jit/cache tests: Fix crash with clang's UBSAN + ASAN.
>       * tests/jit/test-cache.c (clang_ubsan_workaround): New variable.
>       (CODE, SET_CODE): Use it.
>       (main): Initialize it.


Oops, this leads to a build failure:

clang   -Wno-error -g -O2   -o test-cache jit/test_cache-test-cache.o 
libtests.a ../gllib/libgnu.a libtests.a ../gllib/libgnu.a libtests.a   
-lbacktrace -lm -lm -lm -lm -lm -lm -lm -lm -lm -lm -lm
/usr/bin/ld: /usr/bin/ld: DWARF error: invalid or unhandled FORM value: 0x25
jit/test_cache-test-cache.o: in function `main':
test-cache.c:(.text+0x16): undefined reference to `dlsym'
clang: error: linker command failed with exit code 1 (use -v to see invocation)
make[4]: *** [Makefile:18978: test-cache] Error 1

This patch should fix it.


2024-09-23  Bruno Haible  <br...@clisp.org>

        jit/cache tests: Fix link error (regression 2024-09-20).
        * m4/libdl.m4: New file.
        * modules/jit/cache-tests (Files): Add it.
        (configure.ac): Invoke gl_LIBDL.
        (Makefile.am): Link test-cache with $(LIBDL).

diff --git a/m4/libdl.m4 b/m4/libdl.m4
new file mode 100644
index 0000000000..f613960b61
--- /dev/null
+++ b/m4/libdl.m4
@@ -0,0 +1,45 @@
+# libdl.m4
+# serial 1
+dnl Copyright (C) 2024 Free Software Foundation, Inc.
+dnl This file is free software; the Free Software Foundation
+dnl gives unlimited permission to copy and/or distribute it,
+dnl with or without modifications, as long as this notice is preserved.
+
+dnl From Bruno Haible.
+
+dnl Set LIBDL to '-ldl' if it is needed to use the functions declared
+dnl in <dlfcn.h> (dlopen, dlsym, etc.), or to empty otherwise.
+AC_DEFUN([gl_LIBDL],
+[
+  dnl dlopen, dlsym are
+  dnl - in libc on glibc >= 2.34, musl libc, macOS, FreeBSD, NetBSD, OpenBSD,
+  dnl   AIX, IRIX,  Solaris, Cygwin, Haiku,
+  dnl - in a separate libdl on glibc < 2.34, Android.
+  AC_CACHE_CHECK([for library needed for dlopen and dlsym],
+    [gl_cv_lib_dl],
+    [AC_LINK_IFELSE(
+       [AC_LANG_PROGRAM(
+          [[#include <dlfcn.h>
+          ]],
+          [[return ! dlsym (RTLD_DEFAULT, "main");]])],
+       [gl_cv_lib_dl=none],
+       [gl_cv_lib_dl=maybe])
+     if test $gl_cv_lib_dl = maybe; then
+       saved_LIBS="$LIBS"
+       LIBS="$LIBS -ldl"
+       AC_LINK_IFELSE(
+         [AC_LANG_PROGRAM(
+            [[#include <dlfcn.h>
+            ]],
+            [[return ! dlsym (RTLD_DEFAULT, "main");]])],
+         [gl_cv_lib_dl='-ldl'],
+         [gl_cv_lib_dl=none])
+       LIBS="$saved_LIBS"
+     fi
+    ])
+  case "$gl_cv_lib_dl" in
+    none) LIBDL='' ;;
+    *)    LIBDL="$gl_cv_lib_dl" ;;
+  esac
+  AC_SUBST([LIBDL])
+])
diff --git a/modules/jit/cache-tests b/modules/jit/cache-tests
index aa6f37ce87..d8163d6206 100644
--- a/modules/jit/cache-tests
+++ b/modules/jit/cache-tests
@@ -3,6 +3,7 @@ tests/jit/test-cache.c
 tests/macros.h
 m4/mmap-anon.m4
 m4/warnings.m4
+m4/libdl.m4
 
 Status:
 unportable-test
@@ -17,6 +18,7 @@ xalloc
 configure.ac:
 AC_CHECK_HEADERS_ONCE([sys/mman.h])
 gl_FUNC_MMAP_ANON
+gl_LIBDL
 dnl Disable the OpenBSD "retguard" stack protector for this test.
 gl_COMPILER_OPTION_IF([-fno-ret-protector],
   [DISABLE_OPENBSD_RETGUARD='-fno-ret-protector'],
@@ -29,4 +31,4 @@ TESTS += test-cache
 check_PROGRAMS += test-cache
 test_cache_SOURCES = jit/test-cache.c
 test_cache_CFLAGS = $(AM_CFLAGS) $(DISABLE_OPENBSD_RETGUARD)
-test_cache_LDADD = $(LDADD) $(LIBINTL)
+test_cache_LDADD = $(LDADD) $(LIBINTL) @LIBDL@




Reply via email to