build libc++ and co with -fno-omit-frame-pointer for hwasan
@eugenis
https://developer.android.com/ndk/guides/hwasan#build
Note: A shared library STL is required because implementations of the operators new and delete in the STL are usually built without frame pointers. HWASan brings its own implementation, but it can't be used if the STL is linked statically into the application.
Can we lift that restriction if we build libc++ (and libc++abi, etc) with -fno-omit-frame-pointer, or are HWASan's implementations still needed for other reasons?
i thought arm64 was already -fno-omit-frame-pointer? (as opposed to arm32.)
https://github.com/llvm/llvm-project/blob/main/compiler-rt/CMakeLists.txt#L285-L287 makes it look like that the sanitizer runtimes get built with -fomit-frame-pointer in this case. @enh-google you're thinking about the Android platform build which specifies this flag explicitly for builds, but we don't use that for building LLVM and its libraries.
oh, interesting. i was under the misapprehension that it was the default in the driver.
Yes, frame pointers are on by default for 32-bit ARM/Thumb and 64-bit AArch64 Android [Code]. Surprisingly, the driver default for x86-related targets depends on optimization level [Code]. Ugh.
I guess the part I might be misinterpreting from the top is about how libc++ gets compiled. That should get compiled with the defaults (as you expected). I think we need @eugenis to comment on whether this is going to work. Perhaps the problem is that AArch64 omits frame pointers for leaf functions by default [Code]. There's a flag to prevent that from happening, but I'm not sure if it will be sufficient to make hwasan work.
@eugenis should we be pursuing this?
I think this should work, as long as all stack frames between operator new and malloc have frame pointers (none of them are leaf functions for obvious reasons). In fact, we are moving away from intercepting new/delete in hwasan because that's not consistent with intercepting malloc through malloc_dispatch in bionic - there are ways to end up with mismatching allocators in new vs delete that way.