diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt index e572dbb..d0afa78 100644 --- a/tests/CMakeLists.txt +++ b/tests/CMakeLists.txt @@ -7,6 +7,7 @@ add_executable(mach_detours_tests test_threads.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. # Between attach and commit the target function's code page is not executable, which can mean our test driver code would not @@ -15,10 +16,11 @@ add_library(mach_detours_tests_lib SHARED lib_function.c lib_function.h ) +target_compile_options(mach_detours_tests_lib PRIVATE "-O0") target_link_libraries(mach_detours_tests PRIVATE mach_detours Catch2::Catch2WithMain mach_detours_tests_lib -) \ No newline at end of file +) diff --git a/tests/test_local_function.cpp b/tests/test_local_function.cpp index 49b2d60..2f29e06 100644 --- a/tests/test_local_function.cpp +++ b/tests/test_local_function.cpp @@ -4,6 +4,9 @@ #include +// 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; int localFunction() {