From c57f7d58e5ef95daf674ae51dc3171e8a12751a9 Mon Sep 17 00:00:00 2001 From: John Safranek Date: Thu, 13 Aug 2026 14:56:45 -0700 Subject: [PATCH] Stop the linker folding main() into a skipped test on macOS When a test is configured out, its entry function compiles down to "return 77", the automake skip code, and the main() that forwards to it inlines to the same two instructions. Apple's ld folds the two identical bodies together and then writes LC_MAIN entryoff 0, so the binary starts executing at the Mach-O header and dies with SIGILL instead of skipping. tests/kex.test, tests/api.test and tests/auth.test all hit this under --enable-all CPPFLAGS=-DWOLFSSH_TEST_BLOCK, and kex.test hits it again under --disable-server. Probe for -Wl,-no_deduplicate and add it to AM_LDFLAGS when the linker takes it. GNU ld rejects the flag, so the check leaves Linux alone. Making the skipped body differ does not help: anything added to the entry function inlines into main() and the two fold again. --- configure.ac | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/configure.ac b/configure.ac index a99ef3bd8..83e6ab9cc 100644 --- a/configure.ac +++ b/configure.ac @@ -388,6 +388,15 @@ AM_CONDITIONAL([BUILD_KEYBOARD_INTERACTIVE],[test "x$ENABLED_KEYBOARD_INTERACTIV AX_HARDEN_CC_COMPILER_FLAGS +dnl A test that is configured out compiles down to "return 77", the automake +dnl skip code, and so does the main() that forwards to it. Apple's linker folds +dnl the two identical bodies together, then writes LC_MAIN entryoff 0, so the +dnl binary starts executing at the Mach-O header and dies with SIGILL instead +dnl of skipping. Turn the folding off where the linker understands the flag; +dnl GNU ld rejects it and is unaffected. +AX_CHECK_LINK_FLAG([-Wl,-no_deduplicate], + [AM_LDFLAGS="$AM_LDFLAGS -Wl,-no_deduplicate"]) + CREATE_HEX_VERSION AC_SUBST([AM_CPPFLAGS]) AC_SUBST([AM_CFLAGS])