Skip to content

Commit 8215060

Browse files
committed
Sanitizer built against glibc 2.34 doesn't work
As mentioned in https://gcc.gnu.org/PR100114 , glibc starting with the https://sourceware.org/git/?p=glibc.git;a=commit;h=6c57d320484988e87e446e2e60ce42816bf51d53 change doesn't define SIGSTKSZ and MINSIGSTKSZ macros to constants, but to sysconf function call. sanitizer_posix_libcdep.cpp has static const uptr kAltStackSize = SIGSTKSZ * 4; // SIGSTKSZ is not enough. which is generally fine, just means that when SIGSTKSZ is not a compile time constant will be initialized later. The problem is that kAltStackSize is used in SetAlternateSignalStack which is called very early, from .preinit_array initialization, i.e. far before file scope variables are constructed, which means it is not initialized and mmapping 0 will fail: ==145==ERROR: AddressSanitizer failed to allocate 0x0 (0) bytes of SetAlternateSignalStack (error code: 22) Here is one possible fix, another one could be to make kAltStackSize a preprocessor macro if _SG_SIGSTKSZ is defined (but perhaps with having an automatic const variable initialized to it so that sysconf isn't at least called twice during SetAlternateSignalStack. Reviewed By: vitalybuka Differential Revision: https://reviews.llvm.org/D100645
1 parent 3dc24bc commit 8215060

File tree

1 file changed

+8
-4
lines changed

1 file changed

+8
-4
lines changed

compiler-rt/lib/sanitizer_common/sanitizer_posix_libcdep.cpp

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -165,7 +165,11 @@ bool SupportsColoredOutput(fd_t fd) {
165165

166166
#if !SANITIZER_GO
167167
// TODO(glider): different tools may require different altstack size.
168-
static const uptr kAltStackSize = SIGSTKSZ * 4; // SIGSTKSZ is not enough.
168+
static uptr GetAltStackSize() {
169+
// SIGSTKSZ is not enough.
170+
static const uptr kAltStackSize = SIGSTKSZ * 4;
171+
return kAltStackSize;
172+
}
169173

170174
void SetAlternateSignalStack() {
171175
stack_t altstack, oldstack;
@@ -176,18 +180,18 @@ void SetAlternateSignalStack() {
176180
// TODO(glider): the mapped stack should have the MAP_STACK flag in the
177181
// future. It is not required by man 2 sigaltstack now (they're using
178182
// malloc()).
179-
void* base = MmapOrDie(kAltStackSize, __func__);
183+
void *base = MmapOrDie(GetAltStackSize(), __func__);
180184
altstack.ss_sp = (char*) base;
181185
altstack.ss_flags = 0;
182-
altstack.ss_size = kAltStackSize;
186+
altstack.ss_size = GetAltStackSize();
183187
CHECK_EQ(0, sigaltstack(&altstack, nullptr));
184188
}
185189

186190
void UnsetAlternateSignalStack() {
187191
stack_t altstack, oldstack;
188192
altstack.ss_sp = nullptr;
189193
altstack.ss_flags = SS_DISABLE;
190-
altstack.ss_size = kAltStackSize; // Some sane value required on Darwin.
194+
altstack.ss_size = GetAltStackSize(); // Some sane value required on Darwin.
191195
CHECK_EQ(0, sigaltstack(&altstack, &oldstack));
192196
UnmapOrDie(oldstack.ss_sp, oldstack.ss_size);
193197
}

0 commit comments

Comments
 (0)