llvm-project/compiler-rt/lib
Dmitry Vyukov 3c503d1b52 asan: allow __asan_{before,after}_dynamic_init without registered globals
When optimizing, GCC optimizes away aggressively unused static globals.
The __asan_before_dynamic_init/__asan_after_dynamic_init calls are placed
in static constructor earlier while the registration of the globals is done
later in the compilation process.  If all the globals with
dynamic initialization are optimized away from some particular TU in between
those two, libasan can fail on an assertion that dynamic_init_globals is
empty.

While I'm going to commit a GCC change which will remove the
__asan_before_dynamic_init/__asan_after_dynamic_init in many cases when this
happens (basically if the optimizers can prove there are no memory
references in between the two calls), there are still testcases where such
pair of calls is left, e.g. for
struct S { S () { asm volatile ("" : : : "memory"); } };
static S c;

int
main ()
{
  return 0;
}
with -O2 -fsanitize=address and ASAN_OPTIONS=check_initialization_order=true
this still fails the assertion.  Trying to avoid this problem on the
compiler side would decrease code quality I'm afraid, whether it is making
sure for -fsanitize=address we keep around at least one dynamically
initialized global if the
__asan_before_dynamic_init/__asan_after_dynamic_init pair has been emitted,
or adding some artificial global which would be used as the condition for
those calls etc.
So, can the assertion be instead just removed, this really shouldn't slow
down the calls measurably (for __asan_before_dynamic_init it is even
cheaper) and the assertion doesn't check something worthwhile anyway (it is
sufficient if there is a single dynamically initialized global in any other
TU to make it happy).

Details in http://gcc.gnu.org/PR77396

Author: Jakub Jelinek
llvm-svn: 280657
2016-09-05 12:22:56 +00:00
..
BlocksRuntime Move tests for BlocksRuntime and builtins to corresponding directories under test/ 2014-02-14 09:47:31 +00:00
asan asan: allow __asan_{before,after}_dynamic_init without registered globals 2016-09-05 12:22:56 +00:00
builtins [CMake] Add option (defaulted off) to exclude atomic.c 2016-09-01 21:05:49 +00:00
cfi [CMake] Connect Compiler-RT targets to LLVM Runtimes directory 2016-08-26 20:52:22 +00:00
dfsan [CMake] Connect Compiler-RT targets to LLVM Runtimes directory 2016-08-26 20:52:22 +00:00
esan [CMake] Connect Compiler-RT targets to LLVM Runtimes directory 2016-08-26 20:52:22 +00:00
interception [compilter-rt] Try to fix correctly rL277560 2016-08-03 05:03:35 +00:00
lsan [CMake] Connect Compiler-RT targets to LLVM Runtimes directory 2016-08-26 20:52:22 +00:00
msan [asan] first attempt at releasing free-d memory back to the system using madvise. Requires quite some tuning. 2016-08-26 23:58:42 +00:00
profile profile: add missing include for Windows 2016-08-30 20:15:44 +00:00
safestack [CMake] Connect Compiler-RT targets to LLVM Runtimes directory 2016-08-26 20:52:22 +00:00
sanitizer_common [sanitizer] extend SizeClassMap to take more template parameters, add VeryCompactSizeClassMap for testing purposes 2016-08-31 17:52:55 +00:00
scudo [CMake] Connect Compiler-RT targets to LLVM Runtimes directory 2016-08-26 20:52:22 +00:00
stats stats: define WIN32_LEAN_AND_MEAN when including windows.h 2016-08-30 20:15:46 +00:00
tsan [tsan] Bump stack frame size limit. 2016-09-01 20:43:59 +00:00
ubsan [CMake] Connect Compiler-RT targets to LLVM Runtimes directory 2016-08-26 20:52:22 +00:00
xray [CMake] Connect Compiler-RT targets to LLVM Runtimes directory 2016-08-26 20:52:22 +00:00
CMakeLists.txt build: allow building a specific set of sanitizers 2016-08-19 15:13:21 +00:00