[Sanitizers] Platforms that don't support stack unwinding

Hi,

In sanitizer code we have two notions of stack unwinders: fast and slow. [1] In the context of sanitizers, stack unwinding is most often for printing error reports that include a stack trace.

I am currently trying to fix an issue that is related to some platforms (Darwin) only supporting the fast unwinder, but calling code not being aware of that possibility.
My mental model was that platforms are required to at least support one kind of unwinder, so I turned a runtime check [2] into a compile time assert [3]. Apparently this is not the case.

What do (or should) we do on platforms without supported unwinders?
Or is my mental model correct, and this a runtime (instead of compile time) check for other reasons? Compilation/build system convenience?

Thanks,
Julian

[1] https://github.com/llvm/llvm-project/blob/fcbd7f64953b04f42dd59f606e45dc8e88a27548/compiler-rt/lib/sanitizer_common/sanitizer_stacktrace.h#L21

[2] https://github.com/llvm/llvm-project/blob/fcbd7f64953b04f42dd59f606e45dc8e88a27548/compiler-rt/lib/sanitizer_common/sanitizer_stacktrace_libcdep.cc#L78

[3] https://github.com/llvm/llvm-project/blob/fcbd7f64953b04f42dd59f606e45dc8e88a27548/compiler-rt/lib/sanitizer_common/sanitizer_stacktrace.h#L21

Existence of unwind information is a runtime property. It is possible for a given binary to have zero unwind information. The easiest example is a 32-bit x86 Windows binary (and maybe Linux?) built with frame-pointer-omission. There are no unwind tables in that situation, and you can’t just follow frame pointers backwards, because they don’t exist. This kind of unwinding generally requires debug information. Maybe, in some specific cases, you could analyze the assembly to figure out how to unwind it, but in the general case, that requires solving the halting problem.

Embedded platforms often omit all unwinding information to save space.

If you have a recent instruction pointer from user code, then just reporting that one instruction pointer can still be useful.

Thank you for the explanation, Ben!

I realized I didn’t give enough context for my question:
As you noted, the slow/fast unwinder can only do its work if there is enough (runtime) information.
Otherwise stack printing usually does exactly what you suggested: printing the one frame corresponding to the recent pc.

When I asked if “platforms are required to at least support one kind of unwinder” I meant:
Shouldn’t there be at least an implementation for one kind of unwinder on each platform (so that in the presence of runtime information, they can do their work).

Phrased differently: isn’t a platform not having an unwinder implementation an oversight?

If the target is almost always memory constrained, implementing an (optional) unwinder may be considered not worth the effort. AVR microprocessors typically have less than a megabyte worth of storage available. Getting your “regular” program to fit is often pretty challenging. Getting an unwinder and UBSan and unwinding information would be even more challenging. “Only” getting UBSAN (or ASAN) without unwinding information is still valuable in these situations.

So you could consider it an oversight, but an unwinder in these kinds of platforms probably wouldn’t get used much.

Thanks, got it!