Paul Eggert wrote: > If I understand things correctly a similar problem was also on FreeBSD > with PIE and the bug wasn't fixed until November of last year: > > https://github.com/llvm/llvm-project/commit/7440e4ed85aa992718d4b5ccd1c97724bc3bdd2c
This issue does not affect the Gnulib 'stack-trace' module, because we link only to GCC's sanitizer library, not to clang's sanitizer library. But looking into the situation on FreeBSD, it appears that the 'stack-trace' module could be enhanced with clang-specific approaches: (A) Use the fact that clang's internal libraries libclang_rt.{asan,msan,tsan,ubsan_standalone}.a define the symbol __sanitizer_print_stack_trace, like GCC's libasan does. This would mean that m4/stack-trace.m4 would add to $CC and $CXX the option '-fsanitize=return' [1]. This appears to be the cheapest way to include __sanitizer_print_stack_trace in the executable. However, there are several drawbacks: * An autoconf macro should not modify the value of CC (or CFLAGS). * Programs compiled this way link to 6 additional shared libraries: libthr.so.3 librt.so.1 libm.so.5 libexecinfo.so.1 libgcc_s.so.1 libelf.so.2 * The behaviour becomes dependent on some environment variables. * The approach does not work if $CC already contains the option '-fsanitize-minimal-runtime'. (B) Do what __sanitizer_print_stack_trace does, namely invoke the program 'llvm-symbolizer' [2]. This program is installed by default in /usr/bin in FreeBSD ≥ 13. There are several drawbacks here as well: * Gnulib would need extra code to get the addresses from libexecinfo, determine VMA boundaries (using /proc, I guess), then invoke llvm-symbolizer as a subprocess. * The approach does not work if llvm-symbolizer is not found in $PATH. * Extra command-line options are needed on macOS, due to .dSYM. The existing first-choice approach (libbacktrace) is better than either of (A) or (B). Therefore I see no reason for implementing (A) or (B). Bruno [1] https://clang.llvm.org/docs/UndefinedBehaviorSanitizer.html#stack-traces-and-report-symbolization [2] https://llvm.org/docs/CommandGuide/llvm-symbolizer.html