https://gcc.gnu.org/bugzilla/show_bug.cgi?id=100114
Bug ID: 100114 Summary: libasan built against latest glibc doesn't work Product: gcc Version: 11.0 Status: UNCONFIRMED Severity: normal Priority: P3 Component: sanitizer Assignee: unassigned at gcc dot gnu.org Reporter: jakub at gcc dot gnu.org CC: dodji at gcc dot gnu.org, dvyukov at gcc dot gnu.org, jakub at gcc dot gnu.org, kcc at gcc dot gnu.org, marxin at gcc dot gnu.org Target Milestone: --- If libsanitizer is built against glibc trunk, nothing really works: ./a ==91==ERROR: AddressSanitizer failed to allocate 0x0 (0) bytes of SetAlternateSignalStack (error code: 22) ==91==Process memory map follows: I think this is caused by // TODO(glider): different tools may require different altstack size. static const uptr kAltStackSize = SIGSTKSZ * 4; // SIGSTKSZ is not enough. void SetAlternateSignalStack() { stack_t altstack, oldstack; CHECK_EQ(0, sigaltstack(nullptr, &oldstack)); // If the alternate stack is already in place, do nothing. // Android always sets an alternate stack, but it's too small for us. if (!SANITIZER_ANDROID && !(oldstack.ss_flags & SS_DISABLE)) return; // TODO(glider): the mapped stack should have the MAP_STACK flag in the // future. It is not required by man 2 sigaltstack now (they're using // malloc()). void* base = MmapOrDie(kAltStackSize, __func__); altstack.ss_sp = (char*) base; altstack.ss_flags = 0; altstack.ss_size = kAltStackSize; CHECK_EQ(0, sigaltstack(&altstack, nullptr)); } called from #0 0x00007ffff7644650 in sigaltstack () from ./libasan.so.6 #1 0x00007ffff76bca92 in __sanitizer::SetAlternateSignalStack() () from ./libasan.so.6 #2 0x00007ffff76bcc65 in __sanitizer::InstallDeadlySignalHandlers(void (*)(int, void*, void*)) () from ./libasan.so.6 #3 0x00007ffff76ab60c in __asan::AsanInitInternal() [clone .part.0] () from ./libasan.so.6 #4 0x00007ffff7fdb6ee in _dl_init () from /lib64/ld-linux-x86-64.so.2 #5 0x00007ffff7fcc0ca in _dl_start_user () from /lib64/ld-linux-x86-64.so.2 and __asan_init which tail calls AsanInitInternal is registered in .preinit_array. As in newer glibcs SIGSTKSZ is no longer a constant - since https://sourceware.org/git/?p=glibc.git;a=commit;h=6c57d320484988e87e446e2e60ce42816bf51d53 - I think the above is invalid C++, because the function is called before the kAltStackSize variable is constructed (which is why we end up with calling MmapOrDie(0, __func__); and that fails miserably.