mirror of
https://github.com/RPCS3/llvm-mirror.git
synced 2024-11-25 04:02:41 +01:00
[asan] Prevent folding of globals with redzones
Summary: ICF prevented by removing unnamed_addr and local_unnamed_addr for all sanitized globals. Also in general unnamed_addr is not valid here as address now is important for ODR violation detector and redzone poisoning. Before the patch ICF on globals caused: 1. false ODR reports when we register global on the same address more than once 2. globals buffer overflow if we fold variables of smaller type inside of large type. Then the smaller one will poison redzone which overlaps with the larger one. Reviewers: eugenis, pcc Subscribers: hiraditya, llvm-commits Differential Revision: https://reviews.llvm.org/D55857 llvm-svn: 349706
This commit is contained in:
parent
4ca15610d7
commit
30b20f259e
@ -2150,6 +2150,10 @@ bool AddressSanitizerModule::InstrumentGlobals(IRBuilder<> &IRB, Module &M, bool
|
||||
NewGlobal->copyAttributesFrom(G);
|
||||
NewGlobal->setComdat(G->getComdat());
|
||||
NewGlobal->setAlignment(MinRZ);
|
||||
// Don't fold globals with redzones. ODR violation detector and redzone
|
||||
// poisoning implicitly creates a dependence on the global's address, so it
|
||||
// is no longer valid for it to be marked unnamed_addr.
|
||||
NewGlobal->setUnnamedAddr(GlobalValue::UnnamedAddr::None);
|
||||
|
||||
// Move null-terminated C strings to "__asan_cstring" section on Darwin.
|
||||
if (TargetTriple.isOSBinFormatMachO() && !G->hasSection() &&
|
||||
|
@ -8,14 +8,14 @@ target triple = "x86_64-apple-macosx10.10.0"
|
||||
@.str.1 = private unnamed_addr constant [13 x i8] c"Hello world.\00", align 1
|
||||
@.str.2 = private unnamed_addr constant [4 x i8] c"%s\0A\00", align 1
|
||||
|
||||
; CHECK: @.str.1 = internal unnamed_addr constant { [13 x i8], [51 x i8] } { [13 x i8] c"Hello world.\00", [51 x i8] zeroinitializer }, section "__TEXT,__asan_cstring,regular", align 32
|
||||
; CHECK: @.str.2 = internal unnamed_addr constant { [4 x i8], [60 x i8] } { [4 x i8] c"%s\0A\00", [60 x i8] zeroinitializer }, section "__TEXT,__asan_cstring,regular", align 32
|
||||
; CHECK: @.str.1 = internal constant { [13 x i8], [51 x i8] } { [13 x i8] c"Hello world.\00", [51 x i8] zeroinitializer }, section "__TEXT,__asan_cstring,regular", align 32
|
||||
; CHECK: @.str.2 = internal constant { [4 x i8], [60 x i8] } { [4 x i8] c"%s\0A\00", [60 x i8] zeroinitializer }, section "__TEXT,__asan_cstring,regular", align 32
|
||||
|
||||
; Shouldn't be put into special section:
|
||||
@.str.3 = private unnamed_addr constant [4 x i8] c"\00\01\02\03", align 1
|
||||
@.str.4 = private unnamed_addr global [7 x i8] c"Hello.\00", align 1
|
||||
@.str.5 = private unnamed_addr constant [8 x i8] c"Hello.\00\00", align 1
|
||||
|
||||
; CHECK: @.str.3 = internal unnamed_addr constant { [4 x i8], [60 x i8] } { [4 x i8] c"\00\01\02\03", [60 x i8] zeroinitializer }, align 32
|
||||
; CHECK: @.str.4 = private unnamed_addr global { [7 x i8], [57 x i8] } { [7 x i8] c"Hello.\00", [57 x i8] zeroinitializer }, align 32
|
||||
; CHECK: @.str.5 = internal unnamed_addr constant { [8 x i8], [56 x i8] } { [8 x i8] c"Hello.\00\00", [56 x i8] zeroinitializer }, align 32
|
||||
; CHECK: @.str.3 = internal constant { [4 x i8], [60 x i8] } { [4 x i8] c"\00\01\02\03", [60 x i8] zeroinitializer }, align 32
|
||||
; CHECK: @.str.4 = private global { [7 x i8], [57 x i8] } { [7 x i8] c"Hello.\00", [57 x i8] zeroinitializer }, align 32
|
||||
; CHECK: @.str.5 = internal constant { [8 x i8], [56 x i8] } { [8 x i8] c"Hello.\00\00", [56 x i8] zeroinitializer }, align 32
|
||||
|
@ -15,7 +15,7 @@ target triple = "x86_64-unknown-linux-gnu"
|
||||
; Check that globals were instrumented:
|
||||
|
||||
; CHECK: @global = global { i32, [60 x i8] } zeroinitializer, comdat, align 32
|
||||
; CHECK: @.str = internal unnamed_addr constant { [14 x i8], [50 x i8] } { [14 x i8] c"Hello, world!\00", [50 x i8] zeroinitializer }, comdat($".str${{[01-9a-f]+}}"), align 32
|
||||
; CHECK: @.str = internal constant { [14 x i8], [50 x i8] } { [14 x i8] c"Hello, world!\00", [50 x i8] zeroinitializer }, comdat($".str${{[01-9a-f]+}}"), align 32
|
||||
|
||||
; Check emitted location descriptions:
|
||||
; CHECK: [[VARNAME:@___asan_gen_.[0-9]+]] = private unnamed_addr constant [7 x i8] c"global\00", align 1
|
||||
|
@ -15,7 +15,7 @@ target datalayout = "e-m:e-i64:64-f80:128-n8:16:32:64-S128"
|
||||
|
||||
; Check that globals were instrumented:
|
||||
; CHECK: @global = global { i32, [60 x i8] } zeroinitializer, align 32
|
||||
; CHECK: @.str = internal unnamed_addr constant { [14 x i8], [50 x i8] } { [14 x i8] c"Hello, world!\00", [50 x i8] zeroinitializer }{{.*}}, align 32
|
||||
; CHECK: @.str = internal constant { [14 x i8], [50 x i8] } { [14 x i8] c"Hello, world!\00", [50 x i8] zeroinitializer }{{.*}}, align 32
|
||||
|
||||
; Check emitted location descriptions:
|
||||
; CHECK: [[VARNAME:@___asan_gen_.[0-9]+]] = private unnamed_addr constant [7 x i8] c"global\00", align 1
|
||||
|
@ -14,8 +14,8 @@ $mystr = comdat any
|
||||
; CHECK: $dead_global = comdat noduplicates
|
||||
; CHECK: $private_str = comdat noduplicates
|
||||
|
||||
; CHECK: @dead_global = local_unnamed_addr global { i32, [60 x i8] } { i32 42, [60 x i8] zeroinitializer }, comdat, align 32
|
||||
; CHECK: @private_str = internal unnamed_addr constant { [8 x i8], [56 x i8] } { [8 x i8] c"private\00", [56 x i8] zeroinitializer }, comdat, align 32
|
||||
; CHECK: @dead_global = global { i32, [60 x i8] } { i32 42, [60 x i8] zeroinitializer }, comdat, align 32
|
||||
; CHECK: @private_str = internal constant { [8 x i8], [56 x i8] } { [8 x i8] c"private\00", [56 x i8] zeroinitializer }, comdat, align 32
|
||||
|
||||
; CHECK: @__asan_global_dead_global = private global { {{.*}} }, section ".ASAN$GL", comdat($dead_global), align 64
|
||||
; CHECK: @__asan_global_private_str = private global { {{.*}} }, section ".ASAN$GL", comdat($private_str), align 64
|
||||
|
@ -7,7 +7,7 @@
|
||||
; CHECK: $"??_C@_04JIHMPGLA@asdf?$AA@" = comdat any
|
||||
|
||||
; CHECK: @"??_C@_04JIHMPGLA@asdf?$AA@" =
|
||||
; CHECK-SAME: linkonce_odr dso_local unnamed_addr constant { [5 x i8], [59 x i8] }
|
||||
; CHECK-SAME: linkonce_odr dso_local constant { [5 x i8], [59 x i8] }
|
||||
; CHECK-SAME: { [5 x i8] c"asdf\00", [59 x i8] zeroinitializer }, comdat, align 32
|
||||
|
||||
; CHECK: @"__asan_global_??_C@_04JIHMPGLA@asdf?$AA@" =
|
||||
|
Loading…
Reference in New Issue
Block a user