Skip to content

Commit 4de7d4e

Browse files
authored
[ASan][X86] Mark asan_globals section large (#74514)
We'd like to make the asan_globals section large to make it not contribute to relocation pressure since there are no direct PC32 references to it. Following #74498, we can do that by marking the code model for the global explicitly large. Without this change, asan_globals gets placed between .data and .bss. With this change, it gets placed after .bss.
1 parent 97f3be2 commit 4de7d4e

File tree

3 files changed

+17
-2
lines changed

3 files changed

+17
-2
lines changed

llvm/lib/Transforms/Instrumentation/AddressSanitizer.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2144,6 +2144,11 @@ ModuleAddressSanitizer::CreateMetadataGlobal(Module &M, Constant *Initializer,
21442144
M, Initializer->getType(), false, Linkage, Initializer,
21452145
Twine("__asan_global_") + GlobalValue::dropLLVMManglingEscape(OriginalName));
21462146
Metadata->setSection(getGlobalMetadataSection());
2147+
// Place metadata in a large section for x86-64 ELF binaries to mitigate
2148+
// relocation pressure.
2149+
if (TargetTriple.getArch() == Triple::x86_64 &&
2150+
TargetTriple.getObjectFormat() == Triple::ELF)
2151+
Metadata->setCodeModel(CodeModel::Large);
21472152
return Metadata;
21482153
}
21492154

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
; RUN: opt < %s -mtriple=x86_64-unknown-linux-gnu -passes=asan -S | FileCheck %s --check-prefix=LARGE
2+
; RUN: opt < %s -mtriple=aarch64-unknown-linux-gnu -passes=asan -S | FileCheck %s --check-prefix=NORMAL
3+
; RUN: opt < %s -mtriple=x86_64-pc-windows -passes=asan -S | FileCheck %s --check-prefix=NORMAL
4+
5+
; check that asan globals metadata are emitted to a large section for x86-64 ELF
6+
7+
; LARGE: @__asan_global_global = {{.*}}global {{.*}}, code_model "large"
8+
; NORMAL-NOT: code_model "large"
9+
10+
@global = global i32 0, align 4

llvm/test/Instrumentation/AddressSanitizer/global_with_comdat.ll

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -102,8 +102,8 @@ target triple = "x86_64-unknown-linux-gnu"
102102
;; Don't place the instrumented globals in a comdat when the unique module ID is empty.
103103
; NOMODULEID: @.str = internal constant { [4 x i8], [28 x i8] } { [4 x i8] c"str\00", [28 x i8] zeroinitializer }, align 32
104104
; NOMODULEID: @_ZL3buf = internal global { [4 x i8], [28 x i8] } zeroinitializer, align 32
105-
; NOMODULEID: @__asan_global_.str = private global {{.*}}, section "asan_globals", !associated !0
106-
; NOMODULEID: @__asan_global__ZL3buf = private global {{.*}}, section "asan_globals", !associated !1
105+
; NOMODULEID: @__asan_global_.str = private global {{.*}}, section "asan_globals"{{.*}}, !associated !0
106+
; NOMODULEID: @__asan_global__ZL3buf = private global {{.*}}, section "asan_globals"{{.*}}, !associated !1
107107
; NOMODULEID: @llvm.compiler.used = appending global [4 x ptr] [ptr @.str, ptr @_ZL3buf, ptr @__asan_global_.str, ptr @__asan_global__ZL3buf]
108108

109109
; NOMODULEID: define internal void @asan.module_ctor() #[[#]] comdat {

0 commit comments

Comments
 (0)