Skip to content
This repository was archived by the owner on May 21, 2019. It is now read-only.

Commit 00f3423

Browse files
committed
[compiler-rt] [sanitizers] Add VMA size check at runtime
This patch adds a runtime check for asan, dfsan, msan, and tsan for architectures that support multiple VMA size (like aarch64). Currently the check only prints a warning indicating which is the VMA built and expected against the one detected at runtime. git-svn-id: https://llvm.org/svn/llvm-project/compiler-rt/trunk@247413 91177308-0d34-0410-b5e6-96231b3b80d8
1 parent fa62bf6 commit 00f3423

File tree

7 files changed

+30
-0
lines changed

7 files changed

+30
-0
lines changed

lib/asan/asan_rtl.cc

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -585,6 +585,7 @@ void NOINLINE __asan_set_death_callback(void (*callback)(void)) {
585585
// Initialize as requested from instrumented application code.
586586
// We use this call as a trigger to wake up ASan from deactivated state.
587587
void __asan_init() {
588+
CheckVMASize();
588589
AsanActivate();
589590
AsanInitInternal();
590591
}

lib/dfsan/dfsan.cc

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -399,6 +399,8 @@ static void dfsan_fini() {
399399
}
400400

401401
static void dfsan_init(int argc, char **argv, char **envp) {
402+
CheckVMASize();
403+
402404
MmapFixedNoReserve(kShadowAddr, kUnusedAddr - kShadowAddr);
403405

404406
// Protect the region of memory we don't use, to preserve the one-to-one

lib/msan/msan.cc

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -375,6 +375,8 @@ void __msan_init() {
375375
msan_init_is_running = 1;
376376
SanitizerToolName = "MemorySanitizer";
377377

378+
CheckVMASize();
379+
378380
InitTlsSize();
379381

380382
CacheBinaryName();

lib/sanitizer_common/sanitizer_common.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,8 @@ void DecreaseTotalMmap(uptr size);
9797
uptr GetRSS();
9898
void NoHugePagesInRegion(uptr addr, uptr length);
9999
void DontDumpShadowMemory(uptr addr, uptr length);
100+
// Check if the built VMA size matches the runtime one.
101+
void CheckVMASize();
100102

101103
// InternalScopedBuffer can be used instead of large stack arrays to
102104
// keep frame size low.

lib/sanitizer_common/sanitizer_posix.cc

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -324,6 +324,22 @@ SignalContext SignalContext::Create(void *siginfo, void *context) {
324324
return SignalContext(context, addr, pc, sp, bp);
325325
}
326326

327+
// This function check is the built VMA matches the runtime one for
328+
// architectures with multiple VMA size.
329+
void CheckVMASize() {
330+
#ifdef __aarch64__
331+
static const unsigned kBuiltVMA = SANITIZER_AARCH64_VMA;
332+
unsigned maxRuntimeVMA =
333+
(MostSignificantSetBitIndex(GET_CURRENT_FRAME()) + 1);
334+
if (kBuiltVMA != maxRuntimeVMA) {
335+
Printf("WARNING: %s runtime VMA is not the one built for.\n",
336+
SanitizerToolName);
337+
Printf("\tBuilt VMA: %u bits\n", kBuiltVMA);
338+
Printf("\tRuntime VMA: %u bits\n", maxRuntimeVMA);
339+
}
340+
#endif
341+
}
342+
327343
} // namespace __sanitizer
328344

329345
#endif // SANITIZER_POSIX

lib/sanitizer_common/sanitizer_win.cc

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -755,6 +755,10 @@ uptr ReadLongProcessName(/*out*/char *buf, uptr buf_len) {
755755
return ReadBinaryName(buf, buf_len);
756756
}
757757

758+
void CheckVMASize() {
759+
// Do nothing.
760+
}
761+
758762
} // namespace __sanitizer
759763

760764
#endif // _WIN32

lib/tsan/rtl/tsan_rtl.cc

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -312,6 +312,9 @@ void Initialize(ThreadState *thr) {
312312
if (is_initialized)
313313
return;
314314
is_initialized = true;
315+
316+
CheckVMASize();
317+
315318
// We are not ready to handle interceptors yet.
316319
ScopedIgnoreInterceptors ignore;
317320
SanitizerToolName = "ThreadSanitizer";

0 commit comments

Comments
 (0)