do not optimize the test lib

else localFunction in test_local_function is likely inlined and the tests fail
This commit is contained in:
Lysann Tranvouez 2025-11-21 13:16:01 +01:00
parent ec870ef992
commit 701d6c78f2
2 changed files with 6 additions and 1 deletions

View file

@ -7,6 +7,7 @@ add_executable(mach_detours_tests
test_threads.cpp test_threads.cpp
test_transaction.cpp test_transaction.cpp
) )
target_compile_options(mach_detours_tests PRIVATE "-O0")
# The target function must be in a shared library because otherwise it might be in the same code page as the test.cpp functions. # The target function must be in a shared library because otherwise it might be in the same code page as the test.cpp functions.
# Between attach and commit the target function's code page is not executable, which can mean our test driver code would not # Between attach and commit the target function's code page is not executable, which can mean our test driver code would not
@ -15,6 +16,7 @@ add_library(mach_detours_tests_lib SHARED
lib_function.c lib_function.c
lib_function.h lib_function.h
) )
target_compile_options(mach_detours_tests_lib PRIVATE "-O0")
target_link_libraries(mach_detours_tests target_link_libraries(mach_detours_tests
PRIVATE PRIVATE

View file

@ -4,6 +4,9 @@
#include <mach_detours.h> #include <mach_detours.h>
// Note that this file must be compiled without optimizations (or at least without inlining)
// else localFunction() calls below are likely going to be inlined at the call site, and detours will not work.
static int localFunctionCounter = 0; static int localFunctionCounter = 0;
int localFunction() int localFunction()
{ {