Skip to content
This repository was archived by the owner on Mar 28, 2020. It is now read-only.

Commit fe02928

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 #133. Let's look through bitcasts when iterating over entries in the llvm.asan.globals list. Differential Revision: https://reviews.llvm.org/D55794 git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@349544 91177308-0d34-0410-b5e6-96231b3b80d8
1 parent f2ffb04 commit fe02928

File tree

2 files changed

+17
-1
lines changed

2 files changed

+17
-1
lines changed

lib/Transforms/Instrumentation/AddressSanitizer.cpp

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -436,8 +436,11 @@ class GlobalsMetadata {
436436
for (auto MDN : Globals->operands()) {
437437
// Metadata node contains the global and the fields of "Entry".
438438
assert(MDN->getNumOperands() == 5);
439-
auto *GV = mdconst::extract_or_null<GlobalVariable>(MDN->getOperand(0));
439+
auto *V = mdconst::extract_or_null<Constant>(MDN->getOperand(0));
440440
// The optimizer may optimize away a global entirely.
441+
if (!V) continue;
442+
auto *StrippedV = V->stripPointerCasts();
443+
auto *GV = dyn_cast<GlobalVariable>(StrippedV);
441444
if (!GV) continue;
442445
// We can already have an entry for GV if it was merged with another
443446
// 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)