I am developing a C library and have a test harness program that links against the library to test functionality. When buiding for testing, I want both the test harness and the library to have debug symbols as I am using the Address Sanitizer and Leak Sanitizer to detect memory issues.
Library Compile Command
/opt/homebrew/opt/llvm/bin/clang -dynamiclib -framework ApplicationServices -lcups lib/macos/*.c -o ./test/macos/libTest.dylib -Wall -Werror -Wextra -fvisibility=hidden -current_version 1.0 -compatibility_version 1.0 -arch arm64 -arch x86_64 -fno-limit-debug-info -g
-fno-limit-debug-info -g
to include debug symbolsHarness Compile Command
/opt/homebrew/opt/llvm/bin/clang ./test/macos/*.c -o ./test/macos/run -L ./test/macos -lTest -Wall -Werror -Wextra -g -fsanitize=address -fsanitize-address-use-after-return=runtime -fsanitize-address-use-after-scope -fno-optimize-sibling-calls -O1
-g
here to include debug symbolsTest Harness Invocation
ASAN_OPTIONS=detect_stack_use_after_return=1 ASAN_OPTIONS=detect_leaks=1 ./test/macos/run
However, when I run the test harness, I am getting the following runtime error
dyld[3025]: Library not loaded: /var/folders/hp/b8x1q6697_129jnylkn87kh40000gp/T/capability-e861fd/capability-arm64.out
Referenced from: <C216EBD6-3360-33F2-AE1E-CD6FBEB74C74> /<PROJECT DIRECTORY>/test/macos/run
Reason: tried: '/var/folders/hp/b8x1q6697_129jnylkn87kh40000gp/T/capability-e861fd/capability-arm64.out' (no such file), '/System/Volumes/Preboot/Cryptexes/OS/var/folders/hp/b8x1q6697_129jnylkn87kh40000gp/T/capability-e861fd/capability-arm64.out' (no such file), '/var/folders/hp/b8x1q6697_129jnylkn87kh40000gp/T/capability-e861fd/capability-arm64.out' (no such file), '/private/var/folders/hp/b8x1q6697_129jnylkn87kh40000gp/T/capability-e861fd/capability-arm64.out' (no such file), '/System/Volumes/Preboot/Cryptexes/OS/private/var/folders/hp/b8x1q6697_129jnylkn87kh40000gp/T/capability-e861fd/capability-arm64.out' (no such file), '/private/var/folders/hp/b8x1q6697_129jnylkn87kh40000gp/T/capability-e861fd/capability-arm64.out' (no such file)
If I remove the -g
option when compiling the library, I can successfully run the test harness. However, I do not get debug symbols in the Address Sanitizer report when referencing code inside the compiled library.
Is there some other way I should include debug symbols in the C library? Any pointers would be very appreciated!
Apple M3 Pro / Mac OS Sonoma Version 14.3 (23D56)
clang
Homebrew clang version 17.0.6
Target: arm64-apple-darwin23.3.0
Thread model: posix
InstalledDir: /opt/homebrew/opt/llvm/bin
I was able to identify the combination of flags when compiling the library that caused this error.
If I compiled with -arch arm64 -arch x86_64
to build a fat binary that can be loaded on both architectures, then I would get this runtime error. However, removing these flags and just including an arm64 build would allow the library to load with no issue.