[llvm] 3ac5a12 - [ARM] Add Thumb Attributes for thumb thunks created in SLSHarding
David Green via llvm-commits
llvm-commits at lists.llvm.org
Fri Mar 24 11:12:00 PDT 2023
Author: David Green
Date: 2023-03-24T18:11:54Z
New Revision: 3ac5a123d95c4caa194b2f0b54ad963ce3034ca8
URL: https://github.com/llvm/llvm-project/commit/3ac5a123d95c4caa194b2f0b54ad963ce3034ca8
DIFF: https://github.com/llvm/llvm-project/commit/3ac5a123d95c4caa194b2f0b54ad963ce3034ca8.diff
LOG: [ARM] Add Thumb Attributes for thumb thunks created in SLSHarding
Without this the function will be use an Arm subtarget, meaning the
instructions in it will be invalid for the current subtarget.
Differential Revision: https://reviews.llvm.org/D144733
Added:
Modified:
llvm/include/llvm/CodeGen/IndirectThunks.h
llvm/lib/Target/ARM/ARMSLSHardening.cpp
llvm/test/CodeGen/ARM/speculation-hardening-sls-boththunks.ll
Removed:
################################################################################
diff --git a/llvm/include/llvm/CodeGen/IndirectThunks.h b/llvm/include/llvm/CodeGen/IndirectThunks.h
index 6da60fb658aec..b0a8e3043be5c 100644
--- a/llvm/include/llvm/CodeGen/IndirectThunks.h
+++ b/llvm/include/llvm/CodeGen/IndirectThunks.h
@@ -33,7 +33,7 @@ class ThunkInserter {
InsertedThunksTy InsertedThunks;
void doInitialization(Module &M) {}
void createThunkFunction(MachineModuleInfo &MMI, StringRef Name,
- bool Comdat = true);
+ bool Comdat = true, StringRef TargetAttrs = "");
public:
void init(Module &M) {
@@ -46,7 +46,8 @@ class ThunkInserter {
template <typename Derived, typename InsertedThunksTy>
void ThunkInserter<Derived, InsertedThunksTy>::createThunkFunction(
- MachineModuleInfo &MMI, StringRef Name, bool Comdat) {
+ MachineModuleInfo &MMI, StringRef Name, bool Comdat,
+ StringRef TargetAttrs) {
assert(Name.startswith(getDerived().getThunkPrefix()) &&
"Created a thunk with an unexpected prefix!");
@@ -67,6 +68,8 @@ void ThunkInserter<Derived, InsertedThunksTy>::createThunkFunction(
AttrBuilder B(Ctx);
B.addAttribute(llvm::Attribute::NoUnwind);
B.addAttribute(llvm::Attribute::Naked);
+ if (TargetAttrs != "")
+ B.addAttribute("target-features", TargetAttrs);
F->addFnAttrs(B);
// Populate our function a bit so that we can verify.
diff --git a/llvm/lib/Target/ARM/ARMSLSHardening.cpp b/llvm/lib/Target/ARM/ARMSLSHardening.cpp
index 3dd9428c75891..09357ae2e3a38 100644
--- a/llvm/lib/Target/ARM/ARMSLSHardening.cpp
+++ b/llvm/lib/Target/ARM/ARMSLSHardening.cpp
@@ -202,7 +202,8 @@ ArmInsertedThunks SLSBLRThunkInserter::insertThunks(MachineModuleInfo &MMI,
const ARMSubtarget *ST = &MF.getSubtarget<ARMSubtarget>();
for (auto T : SLSBLRThunks)
if (ST->isThumb() == T.isThumb)
- createThunkFunction(MMI, T.Name, ComdatThunks);
+ createThunkFunction(MMI, T.Name, ComdatThunks,
+ T.isThumb ? "+thumb-mode" : "");
return ST->isThumb() ? ThumbThunk : ArmThunk;
}
diff --git a/llvm/test/CodeGen/ARM/speculation-hardening-sls-boththunks.ll b/llvm/test/CodeGen/ARM/speculation-hardening-sls-boththunks.ll
index dd258696090ec..9fbda66ca5085 100644
--- a/llvm/test/CodeGen/ARM/speculation-hardening-sls-boththunks.ll
+++ b/llvm/test/CodeGen/ARM/speculation-hardening-sls-boththunks.ll
@@ -1,4 +1,4 @@
-; RUN: llc -mattr=harden-sls-retbr -mattr=harden-sls-blr -verify-machineinstrs -mtriple=armv8-linux-gnueabi < %s | FileCheck %s
+; RUN: llc -mattr=harden-sls-retbr -mattr=harden-sls-blr -verify-machineinstrs -mtriple=armv8-linux-gnueabi -stop-after=arm-sls-hardening %s -o - | FileCheck %s
; Given both Arm and Thumb functions in the same compilation unit, we should
; get both arm and thumb thunks.
@@ -11,7 +11,13 @@ define i32 @test2(i32 %a, i32 %b) "target-features"="+thumb-mode" {
ret i32 %a
}
-; CHECK: test1
-; CHECK: test2
-; CHECK: __llvm_slsblr_thunk_arm_sp
-; CHECK: __llvm_slsblr_thunk_thumb_sp
\ No newline at end of file
+; CHECK: define i32 @test1(i32 %a, i32 %b) #0
+; CHECK: define i32 @test2(i32 %a, i32 %b) #1
+; CHECK: define linkonce_odr hidden void @__llvm_slsblr_thunk_arm_sp() #2 comdat
+; CHECK: define linkonce_odr hidden void @__llvm_slsblr_thunk_thumb_sp() #3 comdat
+
+; CHECK: attributes #0 = { "target-features"="+harden-sls-retbr,+harden-sls-blr" }
+; CHECK: attributes #1 = { "target-features"="+thumb-mode,+harden-sls-retbr,+harden-sls-blr" }
+; CHECK: attributes #2 = { naked nounwind }
+; CHECK: attributes #3 = { naked nounwind "target-features"="+thumb-mode" }
+
More information about the llvm-commits
mailing list