natalie
natalie copied to clipboard
Integrate AddressSanitizer
We currently have CI running a few files through Valgrind, but it would be better to integrate AddressSanitizer (supported by both gcc and clang) so we find bugs faster. Also, not all the code is running through Valgrind, so I'm sure there are bugs we are not catching.
I started a branch called asan, but there are screen-fulls of errors when running the test suite. Some of them are no doubt false-positives, due to our stack manipulation in Fiber and our shady behavior in the GC :wink:.
I added a macro NO_SANITIZE_ADDRESS
to ignore such shenanigans, but I need to spend some time investigating each error to see if it's something we should ignore or address as a bug...
We're getting the following error when Fibers are in use, due to the stack switching:
==639366==WARNING: ASan is ignoring requested __asan_handle_no_return: stack type: default top: 0x7ffd57cd4000; bottom 0x7ffb271fb000; size: 0x000230ad9000 (9406615552)
False positive error reports may follow
For details see https://github.com/google/sanitizers/issues/189
=================================================================
==639366==ERROR: AddressSanitizer: stack-buffer-overflow on address 0x7ffb271fd080 at pc 0x7ffb2b581017 bp 0x7ffb271fd050 sp 0x7ffb271fc7f8
WRITE of size 24 at 0x7ffb271fd080 thread T0
#0 0x7ffb2b581016 in __interceptor_sigaltstack ../../../../src/libsanitizer/sanitizer_common/sanitizer_common_interceptors.inc:9996
#1 0x7ffb2b5e7853 in __asan::PlatformUnpoisonStacks() ../../../../src/libsanitizer/asan/asan_posix.cpp:44
#2 0x7ffb2b5ed3ec in __asan_handle_no_return ../../../../src/libsanitizer/asan/asan_rtl.cpp:612
#3 0x5622fb54a96e in Natalie::Block::_run(Natalie::Env*, unsigned long, Natalie::ValuePtr*, Natalie::Block*) (/tmp/natalie20210801-639337-qjksy8+0x14896e)
#4 0x5622fb787482 in Natalie::KernelModule::loop(Natalie::Env*, Natalie::Block*) /home/tim/pp/natalie/src/kernel_module.cpp:154
...
The fix, as indicated in google/sanitizers#189, seems to be to call __sanitizer_start_switch_fiber
and __sanitizer_finish_switch_fiber
, as documented in https://github.com/llvm-mirror/compiler-rt/blob/69445f095c22aac2388f939bedebf224a6efcdaf/include/sanitizer/common_interface_defs.h#L299-L342.
I'll work on that soon... just wanted to document it here for my own sake. :smile:
Closed in #1455 🎉