bug-gnulib
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

jit/cache tests: Avoid test failure on OpenBSD


From: Bruno Haible
Subject: jit/cache tests: Avoid test failure on OpenBSD
Date: Mon, 08 Jan 2024 18:14:37 +0100

I still see test-cache fail on OpenBSD/x86_64. The cause is that due to the
OpenBSD "retguard" stack protector [1][2][3], the functions 'return1' and
'return2' are not position-independent.

This patch fixes it, by turning off the "retguard" stack protector for this
specific compilation unit.

[1] https://lwn.net/Articles/732201/
[2] https://lwn.net/Articles/732202/
[3] https://news.ycombinator.com/item?id=17246537


2024-01-08  Bruno Haible  <bruno@clisp.org>

        jit/cache tests: Avoid test failure on OpenBSD.
        * modules/jit/cache-tests (Files): Add m4/warnings.m4.
        (configure.ac): Set and substitute DISABLE_OPENBSD_RETGUARD.
        (Makefile.am): Set test_cache_CFLAGS.
        * tests/jit/test-cache.c (main): If the compiler defines _RET_PROTECTOR,
        skip the test.

diff --git a/modules/jit/cache-tests b/modules/jit/cache-tests
index e4229476c8..d777684093 100644
--- a/modules/jit/cache-tests
+++ b/modules/jit/cache-tests
@@ -2,6 +2,7 @@ Files:
 tests/jit/test-cache.c
 tests/macros.h
 m4/mmap-anon.m4
+m4/warnings.m4
 
 Status:
 unportable-test
@@ -15,8 +16,14 @@ stdint
 configure.ac:
 AC_CHECK_HEADERS_ONCE([sys/mman.h])
 gl_FUNC_MMAP_ANON
+dnl Disable the OpenBSD "retguard" stack protector for this test.
+gl_COMPILER_OPTION_IF([-fno-ret-protector],
+  [DISABLE_OPENBSD_RETGUARD='-fno-ret-protector'],
+  [DISABLE_OPENBSD_RETGUARD=])
+AC_SUBST([DISABLE_OPENBSD_RETGUARD])
 
 Makefile.am:
 TESTS += test-cache
 check_PROGRAMS += test-cache
 test_cache_SOURCES = jit/test-cache.c
+test_cache_CFLAGS = $(AM_CFLAGS) $(DISABLE_OPENBSD_RETGUARD)
diff --git a/tests/jit/test-cache.c b/tests/jit/test-cache.c
index 35d63b7842..1d77dadaa5 100644
--- a/tests/jit/test-cache.c
+++ b/tests/jit/test-cache.c
@@ -107,7 +107,14 @@ return2 (void)
 int
 main ()
 {
-#if !HAVE_SYS_MMAN_H
+#if defined _RET_PROTECTOR
+  /* The OpenBSD "retguard" stack protector produces code for 'return1' and
+     'return2' that is not position independent, and there is no clang
+     attribute for turning this instrumentation off for specific functions.
+     If this stack protector has not been disabled through a configure test,
+     we need to skip this unit test.  */
+  return 77;
+#elif !HAVE_SYS_MMAN_H
   return 77;
 #else
   int const pagesize = getpagesize ();






reply via email to

[Prev in Thread] Current Thread [Next in Thread]