Require -funwind-tables for compiler-rt on ARM?

I recently debugged an issue where I wasn’t getting stack traces from ASAN on 32-bit ARM (on Android) when using a libclang_rt.asan-arm-android.so I’d built myself. I finally ended up tracing it to a build issue; the CMake build check for -funwind-tables was failing (because of some missing link libraries), so compiler-rt wasn’t being built with that flag, which in turn led to all backtraces failing with an error like the following:

==21748==AddressSanitizer CHECK failed: …/compiler-rt/lib/sanitizer_common/sanitizer_stacktrace.cc:116 “((count)) < ((size))” (0x0, 0x0)

I’m not entirely sure why omitting -funwind-tables would result in this outcome. I guess stack walking on ARM relies on those tables; I was building with -fno-omit-frame-pointer, but perhaps frame pointer walking isn’t sufficient. I’d appreciate more insight here.

Regardless of the root cause, however, if -funwind-tables is required for stack traces to work on ARM, should we make it required in the CMake build config? I’m gonna enforce the use of the flag locally (by adding it to the global compile flags, so we at least get a loud compile/link error if something’s wrong with our setup instead of a silent CMake configuration check failure), but I was wondering if this was something that should be upstream as well.

I recently debugged an issue where I wasn't getting stack traces from ASAN on 32-bit ARM (on Android) when using a libclang_rt.asan-arm-android.so I'd built myself. I finally ended up tracing it to a build issue; the CMake build check for -funwind-tables was failing (because of some missing link libraries), so compiler-rt wasn't being built with that flag, which in turn led to all backtraces failing with an error like the following:

==21748==AddressSanitizer CHECK failed: …/compiler-rt/lib/sanitizer_common/sanitizer_stacktrace.cc:116 "((count)) < ((size))" (0x0, 0x0)

    <empty stack>

I'm not entirely sure why omitting -funwind-tables would result in this outcome. I guess stack walking on ARM relies on those tables; I was building with -fno-omit-frame-pointer, but perhaps frame pointer walking isn't sufficient. I'd appreciate more insight here.

My limited understanding is that there are some interoperability
problems with LLVM and GCC. There seems to be more detail in
https://github.com/google/sanitizers/issues/640 and
https://bugs.llvm.org/show_bug.cgi?id=18505

Regardless of the root cause, however, if -funwind-tables is required for stack traces to work on ARM, should we make it required in the CMake build config? I'm gonna enforce the use of the flag locally (by adding it to the global compile flags, so we at least get a loud compile/link error if something's wrong with our setup instead of a silent CMake configuration check failure), but I was wondering if this was something that should be upstream as well.

Adding -funwind-tables by default could add to the overall code-size,
this might not be appreciated in cases where unwinding isn't required,
particularly bare-metal builds for cortex-m where ASAN won't be used.
There may be a case for requiring it for A profile architectures,
particularly if ASAN is also being built.

Peter

Thanks for the bug report; that makes sense.

And I should have been clearer … I meant specifically requiring -funwind-tables for the sanitizers, since they all require some form of unwinding. compiler-rt’s build adds -funwind-tables to the sanitizer compile flags if its configure check succeeded: https://github.com/llvm/llvm-project/blob/a8dcd47688764faf90c44dfefd0cc321b3e8d9df/compiler-rt/CMakeLists.txt#L274. I’m wondering if for ARM (and any other architecture with similar issues) we should error if the configure check for -funwind-tables failed and you’re building a sanitizer.

Thanks for the bug report; that makes sense.

And I should have been clearer … I meant specifically requiring -funwind-tables for the sanitizers, since they all require some form of unwinding. compiler-rt's build adds -funwind-tables to the sanitizer compile flags if its configure check succeeded: llvm-project/CMakeLists.txt at a8dcd47688764faf90c44dfefd0cc321b3e8d9df · llvm/llvm-project · GitHub. I'm wondering if for ARM (and any other architecture with similar issues) we should error if the configure check for -funwind-tables failed and you're building a sanitizer.

Thanks for the clarification. I think that for many of the sanitizers
the unwinding is used in an error message, but isn't required to
detect an error? In that case a hard error for funwind-tables not
being present might be considered overly strict. However I agree that
it is far more likely to be a mistake somewhere in the build system
than intentionally removing it.

In summary; no objections to adding an error for Arm. Would be good to
get some input from someone more familiar with the sanitizers than me
though.

Peter