Skip to content

Commit 3760fc9

Browse files
committed
[asan] In llvm.asan.globals, allow entries to be non-GlobalVariable and skip over them
Looks like there are valid reasons why we need to allow bitcasts in llvm.asan.globals, see discussion at apple/swift-llvm#133. Let's look through bitcasts when iterating over entries in the llvm.asan.globals list. Differential Revision: https://reviews.llvm.org/D55794 llvm-svn: 349544
1 parent 73c8685 commit 3760fc9

File tree

2 files changed

+17
-1
lines changed

2 files changed

+17
-1
lines changed

llvm/lib/Transforms/Instrumentation/AddressSanitizer.cpp

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -441,8 +441,11 @@ class GlobalsMetadata {
441441
for (auto MDN : Globals->operands()) {
442442
// Metadata node contains the global and the fields of "Entry".
443443
assert(MDN->getNumOperands() == 5);
444-
auto *GV = mdconst::extract_or_null<GlobalVariable>(MDN->getOperand(0));
444+
auto *V = mdconst::extract_or_null<Constant>(MDN->getOperand(0));
445445
// The optimizer may optimize away a global entirely.
446+
if (!V) continue;
447+
auto *StrippedV = V->stripPointerCasts();
448+
auto *GV = dyn_cast<GlobalVariable>(StrippedV);
446449
if (!GV) continue;
447450
// We can already have an entry for GV if it was merged with another
448451
// global.
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
; Test that the compiler doesn't crash when the llvm.asan.globals containts
2+
; an entry that points to a BitCast instruction.
3+
4+
; RUN: opt < %s -asan -asan-module -asan-globals-live-support=1 -S
5+
6+
target datalayout = "e-m:o-i64:64-f80:128-n8:16:32:64-S128"
7+
target triple = "x86_64-apple-macosx10.11.0"
8+
9+
@g = global [1 x i32] zeroinitializer, align 4
10+
11+
!llvm.asan.globals = !{!0, !1}
12+
!0 = !{[1 x i32]* @g, null, !"name", i1 false, i1 false}
13+
!1 = !{i8* bitcast ([1 x i32]* @g to i8*), null, !"name", i1 false, i1 false}

0 commit comments

Comments
 (0)