An implementation for sigaltstack to make its side effect be visible to MSAN.
ninja check-msan
Differential D73816
[compiler-rt] implement sigaltstack interception sugak on Jan 31 2020, 3:48 PM. Authored by
Details An implementation for sigaltstack to make its side effect be visible to MSAN. ninja check-msan
Diff Detail
Event TimelineComment Actions I manually tested this on CentOS and would need guidance about the use of SI_POSIX, as well as how to make a unittest for this (if needed). Comment Actions SI_POSIX seems alright. Please add a simple test under compiler-rt/test/msan - just call the function and check that accessing memory does not trigger msan.
Comment Actions This seems to have broken NetBSD: FAILED: projects/compiler-rt/lib/tsan/CMakeFiles/clang_rt.tsan-x86_64.dir/rtl/tsan_interceptors_posix.cpp.o /home/motus/netbsd8/netbsd8/wrappers/clang++ -D__STDC_CONSTANT_MACROS -D__STDC_FORMAT_MACROS -D__STDC_LIMIT_MACROS -Iprojects/compiler-rt/lib/tsan -I/home/motus/netbsd8/netbsd8/llvm-project/llvm/projects/compiler-rt/lib/tsan -Iinclude -I/home/motus/netbsd8/netbsd8/llvm-project/llvm/include -I/home/motus/netbsd8/netbsd8/llvm-project/llvm/projects/compiler-rt/lib/tsan/.. -fPIC -fvisibility-inlines-hidden -Werror=date-time -Werror=unguarded-availability-new -Wall -Wextra -Wno-unused-parameter -Wwrite-strings -Wcast-qual -Wmissing-field-initializers -pedantic -Wno-long-long -Wimplicit-fallthrough -Wcovered-switch-default -Wno-noexcept-type -Wnon-virtual-dtor -Wdelete-non-virtual-dtor -Wstring-conversion -fdiagnostics-color -ffunction-sections -fdata-sections -Wall -std=c++14 -Wno-unused-parameter -O3 -DNDEBUG -m64 -fno-lto -fPIC -fno-builtin -fno-exceptions -fomit-frame-pointer -funwind-tables -fno-stack-protector -fno-sanitize=safe-stack -fvisibility=hidden -fno-lto -O3 -gline-tables-only -Wno-gnu -Wno-variadic-macros -Wno-c99-extensions -Wno-non-virtual-dtor -fPIE -fno-rtti -msse3 -Wframe-larger-than=530 -Wglobal-constructors -std=c++14 -MD -MT projects/compiler-rt/lib/tsan/CMakeFiles/clang_rt.tsan-x86_64.dir/rtl/tsan_interceptors_posix.cpp.o -MF projects/compiler-rt/lib/tsan/CMakeFiles/clang_rt.tsan-x86_64.dir/rtl/tsan_interceptors_posix.cpp.o.d -o projects/compiler-rt/lib/tsan/CMakeFiles/clang_rt.tsan-x86_64.dir/rtl/tsan_interceptors_posix.cpp.o -c /home/motus/netbsd8/netbsd8/llvm-project/llvm/projects/compiler-rt/lib/tsan/rtl/tsan_interceptors_posix.cpp In file included from /home/motus/netbsd8/netbsd8/llvm-project/llvm/projects/compiler-rt/lib/tsan/rtl/tsan_interceptors_posix.cpp:2337: /home/motus/netbsd8/netbsd8/llvm-project/llvm/projects/compiler-rt/lib/tsan/../sanitizer_common/sanitizer_common_interceptors.inc:9739:44: error: use of undeclared identifier 'struct_stack_t_sz'; did you mean 'struct_stat_sz'? COMMON_INTERCEPTOR_READ_RANGE(ctx, ss, struct_stack_t_sz); ^~~~~~~~~~~~~~~~~ struct_stat_sz /home/motus/netbsd8/netbsd8/llvm-project/llvm/projects/compiler-rt/lib/tsan/rtl/tsan_interceptors_posix.cpp:2223:71: note: expanded from macro 'COMMON_INTERCEPTOR_READ_RANGE' ((TsanInterceptorContext *) ctx)->pc, (uptr) ptr, size, \ ^ /home/motus/netbsd8/netbsd8/llvm-project/llvm/projects/compiler-rt/lib/tsan/../sanitizer_common/sanitizer_platform_limits_netbsd.h:35:17: note: 'struct_stat_sz' declared here extern unsigned struct_stat_sz; ^ http://lab.llvm.org:8014/builders/netbsd-amd64/builds/968/steps/ninja%20build%20local/logs/stdio Comment Actions For fixing NetBSD, remember to go for #define sigaltstack __sigaltstack14 as the symbol is renamed. Comment Actions Another problem with this interceptor - stack_t on linux has internal padding that is not required to be initialized. See this bug: https://bugs.chromium.org/p/chromium/issues/detail?id=1050279 Comment Actions I've removed the check in https://github.com/llvm/llvm-project/commit/987f153929e813db1ea7e3354fd7a0b6b4adf4c0 |
POST_READ is unnecessary here - it is mainly for the case when the read range is not known until the syscall returns.