[clang] e018cbf - [IR] Make stack protector symbol dso_local according to -f[no-]direct-access-external-data
Fangrui Song via cfe-commits
cfe-commits at lists.llvm.org
Tue May 23 09:50:03 PDT 2023
Author: Fangrui Song
Date: 2023-05-23T09:49:57-07:00
New Revision: e018cbf7208b3d34f18997ddee84c66cee32fb1b
URL: https://github.com/llvm/llvm-project/commit/e018cbf7208b3d34f18997ddee84c66cee32fb1b
DIFF: https://github.com/llvm/llvm-project/commit/e018cbf7208b3d34f18997ddee84c66cee32fb1b.diff
LOG: [IR] Make stack protector symbol dso_local according to -f[no-]direct-access-external-data
There are two motivations.
`-fno-pic -fstack-protector -mstack-protector-guard=global` created
`__stack_chk_guard` is referenced directly on all ELF OSes except FreeBSD.
This patch allows referencing the symbol indirectly with
-fno-direct-access-external-data.
Some Linux kernel folks want
`-fno-pic -fstack-protector -mstack-protector-guard-reg=gs -mstack-protector-guard-symbol=__stack_chk_guard`
created `__stack_chk_guard` to be referenced directly, avoiding
R_X86_64_REX_GOTPCRELX (even if the relocation may be optimized out by the linker).
https://github.com/llvm/llvm-project/issues/60116
Why they need this isn't so clear to me.
---
Add module flag "direct-access-external-data" and set the dso_local property of
the stack protector symbol. The module flag can benefit other LLVMCodeGen
synthesized symbols that are not represented in LLVM IR.
Nowadays, with `-fno-pic` being uncommon, ideally we should set
"direct-access-external-data" when it is true. However, doing so would require
~90 clang/test tests to be updated, which are too much.
As a compromise, we set "direct-access-external-data" only when it's different
from the implied default value.
Reviewed By: nickdesaulniers
Differential Revision: https://reviews.llvm.org/D150841
Added:
Modified:
clang/lib/CodeGen/CodeGenModule.cpp
clang/test/CodeGen/dso-local-executable.c
llvm/include/llvm/IR/Module.h
llvm/lib/CodeGen/TargetLoweringBase.cpp
llvm/lib/IR/Module.cpp
llvm/lib/Target/X86/X86ISelLowering.cpp
llvm/test/CodeGen/AArch64/arm64_32.ll
llvm/test/CodeGen/AArch64/stack-guard-sve.ll
llvm/test/CodeGen/AArch64/stack-guard-vaarg.ll
llvm/test/CodeGen/AArch64/stack_guard_remat.ll
llvm/test/CodeGen/ARM/expand-pseudos.ll
llvm/test/CodeGen/ARM/stack-guard-rwpi.ll
llvm/test/CodeGen/ARM/stack_guard_remat.ll
llvm/test/CodeGen/Inputs/stack-guard-reassign.ll
llvm/test/CodeGen/PowerPC/stack-guard-oob.ll
llvm/test/CodeGen/Thumb/stack_guard_remat.ll
llvm/test/CodeGen/Thumb2/stack_guard_remat.ll
llvm/test/CodeGen/X86/2009-04-14-IllegalRegs.ll
llvm/test/CodeGen/X86/2010-09-17-SideEffectsInChain.ll
llvm/test/CodeGen/X86/stack-protector-3.ll
Removed:
################################################################################
diff --git a/clang/lib/CodeGen/CodeGenModule.cpp b/clang/lib/CodeGen/CodeGenModule.cpp
index 66c2abdb903aa..d809e7063cf05 100644
--- a/clang/lib/CodeGen/CodeGenModule.cpp
+++ b/clang/lib/CodeGen/CodeGenModule.cpp
@@ -908,6 +908,12 @@ void CodeGenModule::Release() {
if (CodeGenOpts.NoPLT)
getModule().setRtLibUseGOT();
+ if (getTriple().isOSBinFormatELF() &&
+ CodeGenOpts.DirectAccessExternalData !=
+ getModule().getDirectAccessExternalData()) {
+ getModule().setDirectAccessExternalData(
+ CodeGenOpts.DirectAccessExternalData);
+ }
if (CodeGenOpts.UnwindTables)
getModule().setUwtable(llvm::UWTableKind(CodeGenOpts.UnwindTables));
diff --git a/clang/test/CodeGen/dso-local-executable.c b/clang/test/CodeGen/dso-local-executable.c
index 783966a0fe322..5514f7f04ad75 100644
--- a/clang/test/CodeGen/dso-local-executable.c
+++ b/clang/test/CodeGen/dso-local-executable.c
@@ -36,6 +36,8 @@
// STATIC-DAG: define dso_local ptr @zed()
// STATIC-DAG: declare dso_local void @import_func()
+// STATIC-NOT: !"direct-access-external-data"
+
/// If -fno-direct-access-external-data is set, drop dso_local from global variable
/// declarations.
// RUN: %clang_cc1 -triple x86_64 -emit-llvm %s -mrelocation-model static -fno-direct-access-external-data -o - | FileCheck --check-prefix=STATIC-INDIRECT %s
@@ -49,6 +51,8 @@
// STATIC-INDIRECT-DAG: define dso_local ptr @zed()
// STATIC-INDIRECT-DAG: declare void @foo()
+// STATIC-INDIRECT: ![[#]] = !{i32 7, !"direct-access-external-data", i32 0}
+
// RUN: %clang_cc1 -triple x86_64 -emit-llvm -pic-level 1 -pic-is-pie %s -o - | FileCheck --check-prefix=PIE %s
// PIE: @baz = dso_local global i32 42
// PIE-NEXT: @import_var = external global i32
@@ -60,6 +64,8 @@
// PIE-DAG: define dso_local ptr @zed()
// PIE-DAG: declare void @import_func()
+// PIE-NOT: !"direct-access-external-data"
+
// RUN: %clang_cc1 -triple x86_64 -emit-llvm -pic-level 1 -pic-is-pie -fdirect-access-external-data %s -o - | FileCheck --check-prefix=PIE-DIRECT %s
// PIE-DIRECT: @baz = dso_local global i32 42
// PIE-DIRECT-NEXT: @import_var = external dso_local global i32
@@ -71,6 +77,8 @@
// PIE-DIRECT-DAG: define dso_local ptr @zed()
// PIE-DIRECT-DAG: declare void @import_func()
+// PIE-DIRECT: ![[#]] = !{i32 7, !"direct-access-external-data", i32 1}
+
// RUN: %clang_cc1 -triple x86_64 -emit-llvm -mrelocation-model static -fno-plt %s -o - | FileCheck --check-prefix=NOPLT %s
// NOPLT: @baz = dso_local global i32 42
// NOPLT-NEXT: @import_var = external dso_local global i32
diff --git a/llvm/include/llvm/IR/Module.h b/llvm/include/llvm/IR/Module.h
index 83c2594a8ad60..670a40b28eabb 100644
--- a/llvm/include/llvm/IR/Module.h
+++ b/llvm/include/llvm/IR/Module.h
@@ -945,6 +945,11 @@ class LLVM_EXTERNAL_VISIBILITY Module {
/// Set that PLT should be avoid for RTLib calls.
void setRtLibUseGOT();
+ /// Get/set whether referencing global variables can use direct access
+ /// relocations on ELF targets.
+ bool getDirectAccessExternalData() const;
+ void setDirectAccessExternalData(bool Value);
+
/// Get/set whether synthesized functions should get the uwtable attribute.
UWTableKind getUwtable() const;
void setUwtable(UWTableKind Kind);
diff --git a/llvm/lib/CodeGen/TargetLoweringBase.cpp b/llvm/lib/CodeGen/TargetLoweringBase.cpp
index 22472d422ffed..081c9e50b990c 100644
--- a/llvm/lib/CodeGen/TargetLoweringBase.cpp
+++ b/llvm/lib/CodeGen/TargetLoweringBase.cpp
@@ -1977,7 +1977,7 @@ void TargetLoweringBase::insertSSPDeclarations(Module &M) const {
"__stack_chk_guard");
// FreeBSD has "__stack_chk_guard" defined externally on libc.so
- if (TM.getRelocationModel() == Reloc::Static &&
+ if (M.getDirectAccessExternalData() &&
!TM.getTargetTriple().isWindowsGNUEnvironment() &&
!TM.getTargetTriple().isOSFreeBSD())
GV->setDSOLocal(true);
diff --git a/llvm/lib/IR/Module.cpp b/llvm/lib/IR/Module.cpp
index a1f8cd0706d9f..73354a8f36d21 100644
--- a/llvm/lib/IR/Module.cpp
+++ b/llvm/lib/IR/Module.cpp
@@ -672,6 +672,18 @@ void Module::setRtLibUseGOT() {
addModuleFlag(ModFlagBehavior::Max, "RtLibUseGOT", 1);
}
+bool Module::getDirectAccessExternalData() const {
+ auto *Val = cast_or_null<ConstantAsMetadata>(
+ getModuleFlag("direct-access-external-data"));
+ if (Val)
+ return cast<ConstantInt>(Val->getValue())->getZExtValue() > 0;
+ return getPICLevel() == PICLevel::NotPIC;
+}
+
+void Module::setDirectAccessExternalData(bool Value) {
+ addModuleFlag(ModFlagBehavior::Max, "direct-access-external-data", Value);
+}
+
UWTableKind Module::getUwtable() const {
if (auto *Val = cast_or_null<ConstantAsMetadata>(getModuleFlag("uwtable")))
return UWTableKind(cast<ConstantInt>(Val->getValue())->getZExtValue());
diff --git a/llvm/lib/Target/X86/X86ISelLowering.cpp b/llvm/lib/Target/X86/X86ISelLowering.cpp
index 408b1578d2a86..ca643bc7820d8 100644
--- a/llvm/lib/Target/X86/X86ISelLowering.cpp
+++ b/llvm/lib/Target/X86/X86ISelLowering.cpp
@@ -3074,6 +3074,7 @@ Value *X86TargetLowering::getIRStackGuard(IRBuilderBase &IRB) const {
GV = new GlobalVariable(*M, Ty, false, GlobalValue::ExternalLinkage,
nullptr, GuardSymb, nullptr,
GlobalValue::NotThreadLocal, AddressSpace);
+ GV->setDSOLocal(M->getDirectAccessExternalData());
}
return GV;
}
diff --git a/llvm/test/CodeGen/AArch64/arm64_32.ll b/llvm/test/CodeGen/AArch64/arm64_32.ll
index f857c7f7c55a2..b050bf538b74f 100644
--- a/llvm/test/CodeGen/AArch64/arm64_32.ll
+++ b/llvm/test/CodeGen/AArch64/arm64_32.ll
@@ -759,3 +759,6 @@ define void @test_bzero(i64 %in) {
}
declare void @llvm.memset.p0.i32(ptr nocapture writeonly, i8, i32, i1)
+
+!llvm.module.flags = !{!0}
+!0 = !{i32 7, !"PIC Level", i32 2}
diff --git a/llvm/test/CodeGen/AArch64/stack-guard-sve.ll b/llvm/test/CodeGen/AArch64/stack-guard-sve.ll
index d7a6bca2b0cf1..1672a7eb87397 100644
--- a/llvm/test/CodeGen/AArch64/stack-guard-sve.ll
+++ b/llvm/test/CodeGen/AArch64/stack-guard-sve.ll
@@ -337,3 +337,6 @@ entry:
attributes #0 = { ssp "frame-pointer"="non-leaf" }
attributes #1 = { sspstrong "frame-pointer"="non-leaf" }
+
+!llvm.module.flags = !{!0}
+!0 = !{i32 7, !"direct-access-external-data", i32 1}
diff --git a/llvm/test/CodeGen/AArch64/stack-guard-vaarg.ll b/llvm/test/CodeGen/AArch64/stack-guard-vaarg.ll
index 79974536364e5..64f4d5398f1c0 100644
--- a/llvm/test/CodeGen/AArch64/stack-guard-vaarg.ll
+++ b/llvm/test/CodeGen/AArch64/stack-guard-vaarg.ll
@@ -36,3 +36,6 @@ declare void @llvm.va_end(ptr)
declare void @llvm.lifetime.end(i64, ptr nocapture)
attributes #0 = { noinline nounwind optnone ssp }
+
+!llvm.module.flags = !{!0}
+!0 = !{i32 7, !"direct-access-external-data", i32 1}
diff --git a/llvm/test/CodeGen/AArch64/stack_guard_remat.ll b/llvm/test/CodeGen/AArch64/stack_guard_remat.ll
index e6a3432458c7d..523eda6149eef 100644
--- a/llvm/test/CodeGen/AArch64/stack_guard_remat.ll
+++ b/llvm/test/CodeGen/AArch64/stack_guard_remat.ll
@@ -1,14 +1,16 @@
-; RUN: llc < %s -mtriple=arm64-apple-ios -relocation-model=pic -no-integrated-as | FileCheck %s -check-prefix=DARWIN
-; RUN: llc < %s -mtriple=arm64-apple-ios -relocation-model=static -no-integrated-as | FileCheck %s -check-prefix=DARWIN
-; RUN: llc < %s -mtriple=aarch64-linux-gnu -relocation-model=pic -no-integrated-as | FileCheck %s -check-prefix=PIC-LINUX
-; RUN: llc < %s -mtriple=aarch64-linux-gnu -relocation-model=static -code-model=large -no-integrated-as | FileCheck %s -check-prefix=STATIC-LARGE
-; RUN: llc < %s -mtriple=aarch64-linux-gnu -relocation-model=static -code-model=small -no-integrated-as | FileCheck %s -check-prefix=STATIC-SMALL
-
-; RUN: llc < %s -global-isel -global-isel-abort=2 -pass-remarks-missed=gisel* -mtriple=arm64-apple-ios -relocation-model=pic -no-integrated-as 2>&1 | FileCheck %s -check-prefixes=DARWIN,FALLBACK
-; RUN: llc < %s -global-isel -global-isel-abort=2 -pass-remarks-missed=gisel* -mtriple=arm64-apple-ios -relocation-model=static -no-integrated-as 2>&1 | FileCheck %s -check-prefixes=DARWIN,FALLBACK
-; RUN: llc < %s -global-isel -global-isel-abort=2 -pass-remarks-missed=gisel* -mtriple=aarch64-linux-gnu -relocation-model=pic -no-integrated-as 2>&1 | FileCheck %s -check-prefixes=PIC-LINUX,FALLBACK
-; RUN: llc < %s -global-isel -global-isel-abort=2 -pass-remarks-missed=gisel* -mtriple=aarch64-linux-gnu -relocation-model=static -code-model=large -no-integrated-as 2>&1 | FileCheck %s -check-prefixes=STATIC-LARGE,FALLBACK
-; RUN: llc < %s -global-isel -global-isel-abort=2 -pass-remarks-missed=gisel* -mtriple=aarch64-linux-gnu -relocation-model=static -code-model=small -no-integrated-as 2>&1 | FileCheck %s -check-prefixes=STATIC-SMALL,FALLBACK
+; RUN: rm -rf %t && split-file %s %t && cd %t
+; RUN: cat a.ll pic.ll > b.ll
+; RUN: llc < b.ll -mtriple=arm64-apple-ios -relocation-model=pic -no-integrated-as | FileCheck %s -check-prefix=DARWIN
+; RUN: llc < b.ll -mtriple=arm64-apple-ios -relocation-model=static -no-integrated-as | FileCheck %s -check-prefix=DARWIN
+; RUN: llc < b.ll -mtriple=aarch64-linux-gnu -relocation-model=pic -no-integrated-as | FileCheck %s -check-prefix=PIC-LINUX
+; RUN: llc < a.ll -mtriple=aarch64-linux-gnu -relocation-model=static -code-model=large -no-integrated-as | FileCheck %s -check-prefix=STATIC-LARGE
+; RUN: llc < a.ll -mtriple=aarch64-linux-gnu -relocation-model=static -code-model=small -no-integrated-as | FileCheck %s -check-prefix=STATIC-SMALL
+
+; RUN: llc < b.ll -global-isel -global-isel-abort=2 -pass-remarks-missed=gisel* -mtriple=arm64-apple-ios -relocation-model=pic -no-integrated-as 2>&1 | FileCheck %s -check-prefixes=DARWIN,FALLBACK
+; RUN: llc < b.ll -global-isel -global-isel-abort=2 -pass-remarks-missed=gisel* -mtriple=arm64-apple-ios -relocation-model=static -no-integrated-as 2>&1 | FileCheck %s -check-prefixes=DARWIN,FALLBACK
+; RUN: llc < b.ll -global-isel -global-isel-abort=2 -pass-remarks-missed=gisel* -mtriple=aarch64-linux-gnu -relocation-model=pic -no-integrated-as 2>&1 | FileCheck %s -check-prefixes=PIC-LINUX,FALLBACK
+; RUN: llc < a.ll -global-isel -global-isel-abort=2 -pass-remarks-missed=gisel* -mtriple=aarch64-linux-gnu -relocation-model=static -code-model=large -no-integrated-as 2>&1 | FileCheck %s -check-prefixes=STATIC-LARGE,FALLBACK
+; RUN: llc < a.ll -global-isel -global-isel-abort=2 -pass-remarks-missed=gisel* -mtriple=aarch64-linux-gnu -relocation-model=static -code-model=small -no-integrated-as 2>&1 | FileCheck %s -check-prefixes=STATIC-SMALL,FALLBACK
; DARWIN: foo2
; DARWIN: adrp [[R0:x[0-9]+]], ___stack_chk_guard at GOTPAGE
@@ -33,6 +35,7 @@
; FALLBACK-NOT: remark:{{.*}}llvm.lifetime.end
; FALLBACK-NOT: remark:{{.*}}llvm.lifetime.start
+;--- a.ll
define i32 @test_stack_guard_remat() #0 {
entry:
%a1 = alloca [256 x i32], align 4
@@ -52,3 +55,7 @@ declare void @foo3(ptr)
declare void @llvm.lifetime.end.p0(i64, ptr nocapture)
attributes #0 = { nounwind sspstrong "less-precise-fpmad"="false" "frame-pointer"="all" "no-infs-fp-math"="false" "no-nans-fp-math"="false" "stack-protector-buffer-size"="8" "unsafe-fp-math"="false" "use-soft-float"="false" }
+
+;--- pic.ll
+!llvm.module.flags = !{!0}
+!0 = !{i32 8, !"PIC Level", i32 2}
diff --git a/llvm/test/CodeGen/ARM/expand-pseudos.ll b/llvm/test/CodeGen/ARM/expand-pseudos.ll
index 25538f2c1a83d..2c423295143ad 100644
--- a/llvm/test/CodeGen/ARM/expand-pseudos.ll
+++ b/llvm/test/CodeGen/ARM/expand-pseudos.ll
@@ -28,3 +28,6 @@ define void @_ZN2v88internal4wasm16LiftoffAssembler13emit_i32_addiENS0_8Register
}
attributes #0 = { ssp }
+
+!llvm.module.flags = !{!0}
+!0 = !{i32 7, !"PIC Level", i32 2}
diff --git a/llvm/test/CodeGen/ARM/stack-guard-rwpi.ll b/llvm/test/CodeGen/ARM/stack-guard-rwpi.ll
index 25fcc738ef014..f4ae9ca0b1d97 100644
--- a/llvm/test/CodeGen/ARM/stack-guard-rwpi.ll
+++ b/llvm/test/CodeGen/ARM/stack-guard-rwpi.ll
@@ -26,3 +26,6 @@ entry:
}
declare dso_local i32 @baz(ptr)
+
+!llvm.module.flags = !{!0}
+!0 = !{i32 7, !"PIC Level", i32 2}
diff --git a/llvm/test/CodeGen/ARM/stack_guard_remat.ll b/llvm/test/CodeGen/ARM/stack_guard_remat.ll
index f1677a204f9d1..ad40212c9b6f1 100644
--- a/llvm/test/CodeGen/ARM/stack_guard_remat.ll
+++ b/llvm/test/CodeGen/ARM/stack_guard_remat.ll
@@ -66,3 +66,6 @@ declare void @foo3(ptr)
declare void @llvm.lifetime.end.p0(i64, ptr nocapture)
attributes #0 = { nounwind ssp "less-precise-fpmad"="false" "frame-pointer"="all" "no-infs-fp-math"="false" "no-nans-fp-math"="false" "stack-protector-buffer-size"="8" "unsafe-fp-math"="false" "use-soft-float"="false" }
+
+!llvm.module.flags = !{!0}
+!0 = !{i32 7, !"PIC Level", i32 2}
diff --git a/llvm/test/CodeGen/Inputs/stack-guard-reassign.ll b/llvm/test/CodeGen/Inputs/stack-guard-reassign.ll
index 5829b2562e7bb..914f3b79d6df5 100644
--- a/llvm/test/CodeGen/Inputs/stack-guard-reassign.ll
+++ b/llvm/test/CodeGen/Inputs/stack-guard-reassign.ll
@@ -19,3 +19,6 @@ declare i8* @strcpy(i8*, i8*)
declare i32 @puts(i8*)
attributes #0 = { noinline nounwind optnone ssp }
+
+!llvm.module.flags = !{!0}
+!0 = !{i32 7, !"direct-access-external-data", i32 1}
diff --git a/llvm/test/CodeGen/PowerPC/stack-guard-oob.ll b/llvm/test/CodeGen/PowerPC/stack-guard-oob.ll
index f00f846a9f158..998095188fd32 100644
--- a/llvm/test/CodeGen/PowerPC/stack-guard-oob.ll
+++ b/llvm/test/CodeGen/PowerPC/stack-guard-oob.ll
@@ -419,3 +419,6 @@ define i32 @multi_dimensional_array() #0 {
}
attributes #0 = { sspstrong }
+
+!llvm.module.flags = !{!0}
+!0 = !{i32 7, !"direct-access-external-data", i32 1}
diff --git a/llvm/test/CodeGen/Thumb/stack_guard_remat.ll b/llvm/test/CodeGen/Thumb/stack_guard_remat.ll
index f96a67e0e7bc2..cfb3e1b278224 100644
--- a/llvm/test/CodeGen/Thumb/stack_guard_remat.ll
+++ b/llvm/test/CodeGen/Thumb/stack_guard_remat.ll
@@ -57,3 +57,6 @@ declare void @foo3(ptr)
declare void @llvm.lifetime.end.p0(i64, ptr nocapture)
attributes #0 = { nounwind ssp "less-precise-fpmad"="false" "frame-pointer"="all" "no-infs-fp-math"="false" "no-nans-fp-math"="false" "stack-protector-buffer-size"="8" "unsafe-fp-math"="false" "use-soft-float"="false" }
+
+!llvm.module.flags = !{!0}
+!0 = !{i32 7, !"PIC Level", i32 2}
diff --git a/llvm/test/CodeGen/Thumb2/stack_guard_remat.ll b/llvm/test/CodeGen/Thumb2/stack_guard_remat.ll
index 98a15ec9ade1a..4a93c2c2a33cf 100644
--- a/llvm/test/CodeGen/Thumb2/stack_guard_remat.ll
+++ b/llvm/test/CodeGen/Thumb2/stack_guard_remat.ll
@@ -39,3 +39,6 @@ declare void @foo3(ptr)
declare void @llvm.lifetime.end.p0(i64, ptr nocapture)
attributes #0 = { nounwind ssp "less-precise-fpmad"="false" "frame-pointer"="all" "no-infs-fp-math"="false" "no-nans-fp-math"="false" "stack-protector-buffer-size"="8" "unsafe-fp-math"="false" "use-soft-float"="false" }
+
+!llvm.module.flags = !{!0}
+!0 = !{i32 7, !"PIC Level", i32 2}
diff --git a/llvm/test/CodeGen/X86/2009-04-14-IllegalRegs.ll b/llvm/test/CodeGen/X86/2009-04-14-IllegalRegs.ll
index da8e7b16a0cef..822f6a4c4616e 100644
--- a/llvm/test/CodeGen/X86/2009-04-14-IllegalRegs.ll
+++ b/llvm/test/CodeGen/X86/2009-04-14-IllegalRegs.ll
@@ -81,3 +81,6 @@ return: ; preds = %entry
}
declare i32 @f(ptr byval(%struct.X) align 4, ptr byval(%struct.X) align 4) nounwind ssp
+
+!llvm.module.flags = !{!0}
+!0 = !{i32 7, !"PIC Level", i32 2}
diff --git a/llvm/test/CodeGen/X86/2010-09-17-SideEffectsInChain.ll b/llvm/test/CodeGen/X86/2010-09-17-SideEffectsInChain.ll
index f782c530d9566..ecaa105dedcfe 100644
--- a/llvm/test/CodeGen/X86/2010-09-17-SideEffectsInChain.ll
+++ b/llvm/test/CodeGen/X86/2010-09-17-SideEffectsInChain.ll
@@ -49,3 +49,6 @@ entry:
store i8 %e, ptr %c, align 8
ret i32 0
}
+
+!llvm.module.flags = !{!0}
+!0 = !{i32 7, !"direct-access-external-data", i32 1}
diff --git a/llvm/test/CodeGen/X86/stack-protector-3.ll b/llvm/test/CodeGen/X86/stack-protector-3.ll
index 59f583b043802..59784af7168db 100644
--- a/llvm/test/CodeGen/X86/stack-protector-3.ll
+++ b/llvm/test/CodeGen/X86/stack-protector-3.ll
@@ -7,7 +7,8 @@
; RUN: cat %t/main.ll %t/f.ll > %t/f2.ll
; RUN: cat %t/main.ll %t/g.ll > %t/g2.ll
; RUN: cat %t/main.ll %t/h.ll > %t/h2.ll
-; RUN: cat %t/existedGV.ll %t/main.ll %t/h.ll > %t/i2.ll
+; RUN: cat %t/existedGV.ll %t/main.ll %t/h.ll > %t/h3.ll
+; RUN: cat %t/main.ll %t/i.ll > %t/i2.ll
; RUN: llc -mtriple=x86_64-pc-linux-gnu -o - < %t/a2.ll | FileCheck --check-prefix=CHECK-TLS-FS-40 %s
; RUN: llc -mtriple=x86_64-pc-linux-gnu -o - < %t/b2.ll | FileCheck --check-prefix=CHECK-TLS-FS-40 %s
; RUN: llc -mtriple=x86_64-pc-linux-gnu -o - < %t/c2.ll | FileCheck --check-prefix=CHECK-GLOBAL %s
@@ -16,7 +17,8 @@
; RUN: llc -mtriple=x86_64-pc-linux-gnu -o - < %t/f2.ll | FileCheck --check-prefix=CHECK-OFFSET %s
; RUN: llc -mtriple=x86_64-pc-linux-gnu -o - < %t/g2.ll | FileCheck --check-prefix=CHECK-NEGATIVE-OFFSET %s
; RUN: llc -mtriple=x86_64-pc-linux-gnu -o - < %t/h2.ll | FileCheck --check-prefix=CHECK-SYM %s
-; RUN: llc -mtriple=x86_64-pc-linux-gnu -o - < %t/i2.ll | FileCheck --check-prefix=CHECK-SYMGV %s
+; RUN: llc -mtriple=x86_64-pc-linux-gnu -o - < %t/h3.ll | FileCheck --check-prefix=CHECK-SYMGV %s
+; RUN: llc -mtriple=x86_64-pc-linux-gnu -o - < %t/i2.ll | FileCheck --check-prefix=CHECK-SYM2 %s
; CHECK-TLS-FS-40: movq %fs:40, %rax
; CHECK-TLS-FS-40: movq %fs:40, %rax
@@ -67,7 +69,7 @@
; CHECK-SYM-NEXT: jne .LBB0_2
; CHECK-SYM: .LBB0_2:
; CHECK-SYM-NEXT: .cfi_def_cfa_offset 32
-; CHECK-SYM-NEXT: callq __stack_chk_fai
+; CHECK-SYM-NEXT: callq __stack_chk_fail
; CHECK-SYMGV: movq __woof(%rip), %rax
; CHECK-SYMGV-NEXT: movq %rax, 16(%rsp)
@@ -77,6 +79,15 @@
; CHECK-SYMGV-NEXT: .cfi_def_cfa_offset 32
; CHECK-SYMGV-NEXT: callq __stack_chk_fail
+; CHECK-SYM2: movq %fs:__woof(%rip), %rax
+; CHECK-SYM2-NEXT: movq %rax, 16(%rsp)
+; CHECK-SYM2: movq %fs:__woof(%rip), %rax
+; CHECK-SYM2-NEXT: cmpq 16(%rsp), %rax
+; CHECK-SYM2-NEXT: jne .LBB0_2
+; CHECK-SYM2: .LBB0_2:
+; CHECK-SYM2-NEXT: .cfi_def_cfa_offset 32
+; CHECK-SYM2-NEXT: callq __stack_chk_fai
+
; ModuleID = 't.c'
;--- existedGV.ll
@@ -116,7 +127,8 @@ attributes #2 = { nounwind }
!llvm.module.flags = !{!1}
!1 = !{i32 2, !"stack-protector-guard", !"tls"}
;--- c.ll
-!llvm.module.flags = !{!1}
+!llvm.module.flags = !{!0,!1}
+!0 = !{i32 7, !"direct-access-external-data", i32 1}
!1 = !{i32 2, !"stack-protector-guard", !"global"}
;--- d.ll
!llvm.module.flags = !{!1}
@@ -131,5 +143,10 @@ attributes #2 = { nounwind }
!llvm.module.flags = !{!1}
!1 = !{i32 2, !"stack-protector-guard-offset", i32 -20}
;--- h.ll
-!llvm.module.flags = !{!1}
+!llvm.module.flags = !{!0,!1}
+!0 = !{i32 7, !"direct-access-external-data", i32 0}
+!1 = !{i32 2, !"stack-protector-guard-symbol", !"__woof"}
+;--- i.ll
+!llvm.module.flags = !{!0,!1}
+!0 = !{i32 7, !"direct-access-external-data", i32 1}
!1 = !{i32 2, !"stack-protector-guard-symbol", !"__woof"}
More information about the cfe-commits
mailing list