This makes -fsanitize=kernel-address emit the correct globals
constructors for the kernel. We had to do the following:
- Disable generation of constructors that rely on linker features such as dead-global elimination.
- Only emit constructors for globals *not* in explicit sections. The kernel uses sections for special globals, which we should not touch.
Bugzilla: https://bugzilla.kernel.org/show_bug.cgi?id=203493
Tested:
- With 'clang/test/CodeGen/asan-globals.cpp'.
- With test_kasan.ko, we can see:
BUG: KASAN: global-out-of-bounds in kasan_global_oob+0xb3/0xba [test_kasan]
/Users/thakis/src/llvm-project/clang/test/CodeGen/asan-globals.cpp:14:28: error: argument to 'section' attribute is not valid for this target: mach-o section specifier requires a segment and section separated by a comma
int attribute((section(".foo.bar"))) sectioned_global;
http://45.33.8.238/mac/14998/step_7.txt
Using an explicit Linux target triple would avoid this.
See also attribute-section-data-common.c for the OSX portable example.