Skip to content

Commit 3d89db4

Browse files
committedJul 15, 2016
TestCase null_deref was failing in Win64:
c:\lipo\work\asan\b_llvm>c:\lipo\work\asan\b_llvm\projects\compiler-rt\test\asan\X86_64WindowsConfig\TestCases\Output\null_deref.cc.tmp ================================================================= ==5488==ERROR: AddressSanitizer: access-violation on unknown address 0x000000000028 (pc 0x7ff701f91067 bp 0x000c8cf8fbf0 sp 0x000c8cf8fbb0 T0) ==5488==The signal is caused by a READ memory access. ==5488==Hint: address points to the zero page. #0 0x7ff701f91066 in NullDeref(int *) C:\lipo\work\asan\llvm\projects\compiler-rt\test\asan\TestCases\null_deref.cc:15:10 #1 0x8a0388830a67 (<unknown module>) The reason was symbols was not initilized. In fact, it was first inited with a call to stack.Print(), which calls WinSymbolizerTool::SymbolizePC, then InitializeDbgHelpIfNeeded(). Since the StackWalk was performed before the stack.Print(), stack frames where not gathered correctly. There should be a better place to initialize symbols. For now, this patch makes the test happy. Patch by Wei Wang Differential Revision: https://reviews.llvm.org/D22410 llvm-svn: 275580
1 parent 2025173 commit 3d89db4

File tree

4 files changed

+25
-5
lines changed

4 files changed

+25
-5
lines changed
 

‎compiler-rt/lib/interception/interception_win.cc

+15-3
Original file line numberDiff line numberDiff line change
@@ -410,7 +410,6 @@ static size_t GetInstructionSize(uptr address) {
410410

411411
case 0xb8: // b8 XX XX XX XX : mov eax, XX XX XX XX
412412
case 0xB9: // b9 XX XX XX XX : mov ecx, XX XX XX XX
413-
case 0xA1: // A1 XX XX XX XX : mov eax, dword ptr ds:[XXXXXXXX]
414413
return 5;
415414

416415
// Cannot overwrite control-instruction. Return 0 to indicate failure.
@@ -453,6 +452,11 @@ static size_t GetInstructionSize(uptr address) {
453452
}
454453

455454
#if SANITIZER_WINDOWS64
455+
switch (*(u8*)address) {
456+
case 0xA1: // A1 XX XX XX XX XX XX XX XX :
457+
// movabs eax, dword ptr ds:[XXXXXXXX]
458+
return 8;
459+
}
456460
switch (*(u16*)address) {
457461
case 0x5040: // push rax
458462
case 0x5140: // push rcx
@@ -500,7 +504,12 @@ static size_t GetInstructionSize(uptr address) {
500504
// mov rax, QWORD PTR [rip + XXXXXXXX]
501505
case 0x25ff48: // 48 ff 25 XX XX XX XX :
502506
// rex.W jmp QWORD PTR [rip + XXXXXXXX]
503-
return 7;
507+
// Instructions having offset relative to 'rip' cannot be copied.
508+
return 0;
509+
510+
case 0x2444c7: // C7 44 24 XX YY YY YY YY
511+
// mov dword ptr [rsp + XX], YYYYYYYY
512+
return 8;
504513
}
505514

506515
switch (*(u32*)(address)) {
@@ -512,7 +521,10 @@ static size_t GetInstructionSize(uptr address) {
512521
}
513522

514523
#else
515-
524+
switch (*(u8*)address) {
525+
case 0xA1: // A1 XX XX XX XX : mov eax, dword ptr ds:[XXXXXXXX]
526+
return 5;
527+
}
516528
switch (*(u16*)address) {
517529
case 0x458B: // 8B 45 XX : mov eax, dword ptr [ebp + XX]
518530
case 0x5D8B: // 8B 5D XX : mov ebx, dword ptr [ebp + XX]

‎compiler-rt/lib/sanitizer_common/sanitizer_symbolizer.h

+4
Original file line numberDiff line numberDiff line change
@@ -177,6 +177,10 @@ class Symbolizer final {
177177
};
178178
};
179179

180+
#ifdef SANITIZER_WINDOWS
181+
void InitializeDbgHelpIfNeeded();
182+
#endif
183+
180184
} // namespace __sanitizer
181185

182186
#endif // SANITIZER_SYMBOLIZER_H

‎compiler-rt/lib/sanitizer_common/sanitizer_symbolizer_win.cc

+2-2
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,8 @@ bool TrySymInitialize() {
4242
// FIXME: We don't call SymCleanup() on exit yet - should we?
4343
}
4444

45+
} // namespace
46+
4547
// Initializes DbgHelp library, if it's not yet initialized. Calls to this
4648
// function should be synchronized with respect to other calls to DbgHelp API
4749
// (e.g. from WinSymbolizerTool).
@@ -97,8 +99,6 @@ void InitializeDbgHelpIfNeeded() {
9799
}
98100
}
99101

100-
} // namespace
101-
102102
bool WinSymbolizerTool::SymbolizePC(uptr addr, SymbolizedStack *frame) {
103103
InitializeDbgHelpIfNeeded();
104104

‎compiler-rt/lib/sanitizer_common/sanitizer_win.cc

+4
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@
2828
#include "sanitizer_mutex.h"
2929
#include "sanitizer_placement_new.h"
3030
#include "sanitizer_stacktrace.h"
31+
#include "sanitizer_symbolizer.h"
3132

3233
namespace __sanitizer {
3334

@@ -733,6 +734,9 @@ void BufferedStackTrace::SlowUnwindStackWithContext(uptr pc, void *context,
733734
CONTEXT ctx = *(CONTEXT *)context;
734735
STACKFRAME64 stack_frame;
735736
memset(&stack_frame, 0, sizeof(stack_frame));
737+
738+
InitializeDbgHelpIfNeeded();
739+
736740
size = 0;
737741
#if defined(_WIN64)
738742
int machine_type = IMAGE_FILE_MACHINE_AMD64;

0 commit comments

Comments
 (0)
Please sign in to comment.