Skip to content

Commit e15d67c

Browse files
[Clang][ARM][AArch64] Alway emit protection attributes for functions. (#82819)
So far branch protection, sign return address, guarded control stack attributes are only emitted as module flags to indicate the functions need to be generated with those features. The problem is in case of an LTO build the module flags are merged with the `min` rule which means if one of the module is not build with sign return address then the features will be turned off for all functions. Due to the functions take the branch-protection and sign-return-address features from the module flags. The sign-return-address is function level option therefore it is expected functions from files that is compiled with -mbranch-protection=pac-ret to be protected. The inliner might inline functions with different set of flags as it doesn't consider the module flags. This patch adds the attributes to all functions and drops the checking of the module flags for the code generation. Module flag is still used for generating the ELF markers. Also drops the "true"/"false" values from the branch-protection-enforcement, branch-protection-pauth-lr, guarded-control-stack attributes as presence of the attribute means it is on absence means off and no other option.
1 parent 9ae24c9 commit e15d67c

File tree

60 files changed

+292
-316
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

60 files changed

+292
-316
lines changed

clang/include/clang/Basic/TargetInfo.h

+41-3
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,9 @@
3232
#include "llvm/ADT/StringRef.h"
3333
#include "llvm/ADT/StringSet.h"
3434
#include "llvm/Frontend/OpenMP/OMPGridValues.h"
35+
#include "llvm/IR/Attributes.h"
3536
#include "llvm/IR/DerivedTypes.h"
37+
#include "llvm/IR/Function.h"
3638
#include "llvm/Support/DataTypes.h"
3739
#include "llvm/Support/Error.h"
3840
#include "llvm/Support/VersionTuple.h"
@@ -1400,15 +1402,15 @@ class TargetInfo : public TransferrableTargetInfo,
14001402
return true;
14011403
}
14021404

1403-
struct BranchProtectionInfo {
1405+
class BranchProtectionInfo {
1406+
public:
14041407
LangOptions::SignReturnAddressScopeKind SignReturnAddr;
14051408
LangOptions::SignReturnAddressKeyKind SignKey;
14061409
bool BranchTargetEnforcement;
14071410
bool BranchProtectionPAuthLR;
14081411
bool GuardedControlStack;
14091412

1410-
BranchProtectionInfo() = default;
1411-
1413+
protected:
14121414
const char *getSignReturnAddrStr() const {
14131415
switch (SignReturnAddr) {
14141416
case LangOptions::SignReturnAddressScopeKind::None:
@@ -1430,6 +1432,42 @@ class TargetInfo : public TransferrableTargetInfo,
14301432
}
14311433
llvm_unreachable("Unexpected SignReturnAddressKeyKind");
14321434
}
1435+
1436+
public:
1437+
BranchProtectionInfo() = default;
1438+
BranchProtectionInfo(const LangOptions &LangOpts) {
1439+
SignReturnAddr =
1440+
LangOpts.hasSignReturnAddress()
1441+
? (LangOpts.isSignReturnAddressScopeAll()
1442+
? LangOptions::SignReturnAddressScopeKind::All
1443+
: LangOptions::SignReturnAddressScopeKind::NonLeaf)
1444+
: LangOptions::SignReturnAddressScopeKind::None;
1445+
SignKey = LangOpts.isSignReturnAddressWithAKey()
1446+
? LangOptions::SignReturnAddressKeyKind::AKey
1447+
: LangOptions::SignReturnAddressKeyKind::BKey;
1448+
BranchTargetEnforcement = LangOpts.BranchTargetEnforcement;
1449+
BranchProtectionPAuthLR = LangOpts.BranchProtectionPAuthLR;
1450+
GuardedControlStack = LangOpts.GuardedControlStack;
1451+
}
1452+
1453+
void setFnAttributes(llvm::Function &F) {
1454+
llvm::AttrBuilder FuncAttrs(F.getContext());
1455+
setFnAttributes(FuncAttrs);
1456+
F.addFnAttrs(FuncAttrs);
1457+
}
1458+
1459+
void setFnAttributes(llvm::AttrBuilder &FuncAttrs) {
1460+
if (SignReturnAddr != LangOptions::SignReturnAddressScopeKind::None) {
1461+
FuncAttrs.addAttribute("sign-return-address", getSignReturnAddrStr());
1462+
FuncAttrs.addAttribute("sign-return-address-key", getSignKeyStr());
1463+
}
1464+
if (BranchTargetEnforcement)
1465+
FuncAttrs.addAttribute("branch-target-enforcement");
1466+
if (BranchProtectionPAuthLR)
1467+
FuncAttrs.addAttribute("branch-protection-pauth-lr");
1468+
if (GuardedControlStack)
1469+
FuncAttrs.addAttribute("guarded-control-stack");
1470+
}
14331471
};
14341472

14351473
/// Determine if the Architecture in this TargetInfo supports branch

clang/lib/CodeGen/Targets/AArch64.cpp

+13-30
Original file line numberDiff line numberDiff line change
@@ -120,37 +120,20 @@ class AArch64TargetCodeGenInfo : public TargetCodeGenInfo {
120120
if (!FD)
121121
return;
122122

123-
const auto *TA = FD->getAttr<TargetAttr>();
124-
if (TA == nullptr)
125-
return;
126-
127-
ParsedTargetAttr Attr =
128-
CGM.getTarget().parseTargetAttr(TA->getFeaturesStr());
129-
if (Attr.BranchProtection.empty())
130-
return;
131-
132-
TargetInfo::BranchProtectionInfo BPI;
133-
StringRef Error;
134-
(void)CGM.getTarget().validateBranchProtection(Attr.BranchProtection,
135-
Attr.CPU, BPI, Error);
136-
assert(Error.empty());
137-
138-
auto *Fn = cast<llvm::Function>(GV);
139-
Fn->addFnAttr("sign-return-address", BPI.getSignReturnAddrStr());
140-
141-
if (BPI.SignReturnAddr != LangOptions::SignReturnAddressScopeKind::None) {
142-
Fn->addFnAttr("sign-return-address-key",
143-
BPI.SignKey == LangOptions::SignReturnAddressKeyKind::AKey
144-
? "a_key"
145-
: "b_key");
123+
TargetInfo::BranchProtectionInfo BPI(CGM.getLangOpts());
124+
125+
if (const auto *TA = FD->getAttr<TargetAttr>()) {
126+
ParsedTargetAttr Attr =
127+
CGM.getTarget().parseTargetAttr(TA->getFeaturesStr());
128+
if (!Attr.BranchProtection.empty()) {
129+
StringRef Error;
130+
(void)CGM.getTarget().validateBranchProtection(Attr.BranchProtection,
131+
Attr.CPU, BPI, Error);
132+
assert(Error.empty());
133+
}
146134
}
147-
148-
Fn->addFnAttr("branch-target-enforcement",
149-
BPI.BranchTargetEnforcement ? "true" : "false");
150-
Fn->addFnAttr("branch-protection-pauth-lr",
151-
BPI.BranchProtectionPAuthLR ? "true" : "false");
152-
Fn->addFnAttr("guarded-control-stack",
153-
BPI.GuardedControlStack ? "true" : "false");
135+
auto *Fn = cast<llvm::Function>(GV);
136+
BPI.setFnAttributes(*Fn);
154137
}
155138

156139
bool isScalarizableAsmOperand(CodeGen::CodeGenFunction &CGF,

clang/lib/CodeGen/Targets/ARM.cpp

+5-3
Original file line numberDiff line numberDiff line change
@@ -152,9 +152,7 @@ class ARMTargetCodeGenInfo : public TargetCodeGenInfo {
152152
diag::warn_target_unsupported_branch_protection_attribute)
153153
<< Arch;
154154
} else {
155-
Fn->addFnAttr("sign-return-address", BPI.getSignReturnAddrStr());
156-
Fn->addFnAttr("branch-target-enforcement",
157-
BPI.BranchTargetEnforcement ? "true" : "false");
155+
BPI.setFnAttributes(*Fn);
158156
}
159157
} else if (CGM.getLangOpts().BranchTargetEnforcement ||
160158
CGM.getLangOpts().hasSignReturnAddress()) {
@@ -167,6 +165,10 @@ class ARMTargetCodeGenInfo : public TargetCodeGenInfo {
167165
diag::warn_target_unsupported_branch_protection_attribute)
168166
<< Attr.CPU;
169167
}
168+
} else if (CGM.getTarget().isBranchProtectionSupportedArch(
169+
CGM.getTarget().getTargetOpts().CPU)) {
170+
TargetInfo::BranchProtectionInfo BPI(CGM.getLangOpts());
171+
BPI.setFnAttributes(*Fn);
170172
}
171173

172174
const ARMInterruptAttr *Attr = FD->getAttr<ARMInterruptAttr>();

clang/test/CodeGen/aarch64-branch-protection-attr.c

+13-13
Original file line numberDiff line numberDiff line change
@@ -67,29 +67,29 @@ __attribute__ ((target("branch-protection=gcs")))
6767
void gcs() {}
6868
// CHECK: define{{.*}} void @gcs() #[[#GCS:]]
6969

70-
// CHECK-DAG: attributes #[[#NONE]] = { {{.*}} "branch-target-enforcement"="false" "guarded-control-stack"="false" {{.*}} "sign-return-address"="none"
70+
// CHECK-DAG: attributes #[[#NONE]] = { {{.*}}
7171

72-
// CHECK-DAG: attributes #[[#STD]] = { {{.*}} "branch-target-enforcement"="true" "guarded-control-stack"="true" {{.*}} "sign-return-address"="non-leaf" "sign-return-address-key"="a_key"
72+
// CHECK-DAG: attributes #[[#STD]] = { {{.*}} "branch-target-enforcement" "guarded-control-stack" {{.*}} "sign-return-address"="non-leaf" "sign-return-address-key"="a_key"
7373

74-
// CHECK-DAG: attributes #[[#BTI]] = { {{.*}} "branch-target-enforcement"="true" "guarded-control-stack"="false" {{.*}} "sign-return-address"="none"
74+
// CHECK-DAG: attributes #[[#BTI]] = { {{.*}} "branch-target-enforcement"
7575

76-
// CHECK-DAG: attributes #[[#PAC]] = { {{.*}} "branch-target-enforcement"="false" "guarded-control-stack"="false" {{.*}} "sign-return-address"="non-leaf" "sign-return-address-key"="a_key"
76+
// CHECK-DAG: attributes #[[#PAC]] = { {{.*}} "sign-return-address"="non-leaf" "sign-return-address-key"="a_key"
7777

78-
// CHECK-DAG: attributes #[[#PACLEAF]] = { {{.*}} "branch-target-enforcement"="false" "guarded-control-stack"="false" {{.*}}"sign-return-address"="all" "sign-return-address-key"="a_key"
78+
// CHECK-DAG: attributes #[[#PACLEAF]] = { {{.*}} "sign-return-address"="all" "sign-return-address-key"="a_key"
7979

80-
// CHECK-DAG: attributes #[[#PACBKEY]] = { {{.*}}"branch-target-enforcement"="false" "guarded-control-stack"="false" {{.*}} "sign-return-address"="non-leaf" "sign-return-address-key"="b_key"
80+
// CHECK-DAG: attributes #[[#PACBKEY]] = { {{.*}} "sign-return-address"="non-leaf" "sign-return-address-key"="b_key"
8181

82-
// CHECK-DAG: attributes #[[#PACBKEYLEAF]] = { {{.*}} "branch-target-enforcement"="false" "guarded-control-stack"="false" {{.*}}"sign-return-address"="all" "sign-return-address-key"="b_key"
82+
// CHECK-DAG: attributes #[[#PACBKEYLEAF]] = { {{.*}} "sign-return-address"="all" "sign-return-address-key"="b_key"
8383

84-
// CHECK-DAG: attributes #[[#BTIPACLEAF]] = { {{.*}}"branch-target-enforcement"="true" "guarded-control-stack"="false" {{.*}} "sign-return-address"="all" "sign-return-address-key"="a_key"
84+
// CHECK-DAG: attributes #[[#BTIPACLEAF]] = { {{.*}} "branch-target-enforcement" {{.*}}"sign-return-address"="all" "sign-return-address-key"="a_key"
8585

8686

87-
// CHECK-DAG: attributes #[[#PAUTHLR]] = { {{.*}}"branch-protection-pauth-lr"="true" {{.*}}"branch-target-enforcement"="false" "guarded-control-stack"="false" {{.*}}"sign-return-address"="non-leaf" "sign-return-address-key"="a_key"
87+
// CHECK-DAG: attributes #[[#PAUTHLR]] = { {{.*}} "branch-protection-pauth-lr" {{.*}}"sign-return-address"="non-leaf" "sign-return-address-key"="a_key"
8888

89-
// CHECK-DAG: attributes #[[#PAUTHLR_BKEY]] = { {{.*}}"branch-protection-pauth-lr"="true" {{.*}}"branch-target-enforcement"="false" "guarded-control-stack"="false" {{.*}}"sign-return-address"="non-leaf" "sign-return-address-key"="b_key"
89+
// CHECK-DAG: attributes #[[#PAUTHLR_BKEY]] = { {{.*}} "branch-protection-pauth-lr" {{.*}}"sign-return-address"="non-leaf" "sign-return-address-key"="b_key"
9090

91-
// CHECK-DAG: attributes #[[#PAUTHLR_LEAF]] = { {{.*}}"branch-protection-pauth-lr"="true" {{.*}}"branch-target-enforcement"="false" "guarded-control-stack"="false" {{.*}}"sign-return-address"="all" "sign-return-address-key"="a_key"
91+
// CHECK-DAG: attributes #[[#PAUTHLR_LEAF]] = { {{.*}} "branch-protection-pauth-lr" {{.*}}"sign-return-address"="all" "sign-return-address-key"="a_key"
9292

93-
// CHECK-DAG: attributes #[[#PAUTHLR_BTI]] = { {{.*}}"branch-protection-pauth-lr"="true" {{.*}}"branch-target-enforcement"="true" "guarded-control-stack"="false" {{.*}}"sign-return-address"="non-leaf" "sign-return-address-key"="a_key"
93+
// CHECK-DAG: attributes #[[#PAUTHLR_BTI]] = { {{.*}} "branch-protection-pauth-lr" {{.*}}"branch-target-enforcement" {{.*}}"sign-return-address"="non-leaf" "sign-return-address-key"="a_key"
9494

95-
// CHECK-DAG: attributes #[[#GCS]] = { {{.*}}"branch-target-enforcement"="false" "guarded-control-stack"="true" {{.*}} "sign-return-address"="none"
95+
// CHECK-DAG: attributes #[[#GCS]] = { {{.*}} "guarded-control-stack"

clang/test/CodeGen/aarch64-sign-return-address.c

+9-3
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,15 @@
1313

1414
// CHECK-LABEL: @foo() #[[#ATTR:]]
1515

16-
// CHECK-NOT: attributes #[[#ATTR]] = { {{.*}} "sign-return-address"
17-
// CHECK-NOT: attributes #[[#ATTR]] = { {{.*}} "sign-return-address-key"
18-
// CHECK-NOT: attributes #[[#ATTR]] = { {{.*}} "branch-target-enforcement"
16+
// NONE-NOT: attributes #[[#ATTR]] = { {{.*}} "sign-return-address"
17+
// NONE-NOT: attributes #[[#ATTR]] = { {{.*}} "sign-return-address-key"
18+
// NONE-NOT: attributes #[[#ATTR]] = { {{.*}} "branch-target-enforcement"
19+
20+
// ALL: attributes #[[#ATTR]] = { {{.*}} "sign-return-address"
21+
// PART: attributes #[[#ATTR]] = { {{.*}} "sign-return-address-key"="a_key"
22+
// B-KEY: attributes #[[#ATTR]] = { {{.*}} "sign-return-address-key"="b_key"
23+
// BTE: attributes #[[#ATTR]] = { {{.*}} "branch-target-enforcement"
24+
1925

2026
// Check module attributes
2127

clang/test/CodeGen/arm-branch-protection-attr-1.c

+6-6
Original file line numberDiff line numberDiff line change
@@ -29,14 +29,14 @@ __attribute__((target("branch-protection=pac-ret+leaf"))) void leaf() {}
2929
__attribute__((target("branch-protection=pac-ret+leaf+bti"))) void btileaf() {}
3030
// CHECK: define{{.*}} void @btileaf() #[[#BTIPACLEAF:]]
3131

32-
// CHECK-DAG: attributes #[[#NONE]] = { {{.*}} "branch-target-enforcement"="false" {{.*}} "sign-return-address"="none"
32+
// CHECK-DAG: attributes #[[#NONE]] = { {{.*}}
3333

34-
// CHECK-DAG: attributes #[[#STD]] = { {{.*}} "branch-target-enforcement"="true" {{.*}} "sign-return-address"="non-leaf"
34+
// CHECK-DAG: attributes #[[#STD]] = { {{.*}} "branch-target-enforcement" {{.*}} "sign-return-address"="non-leaf"
3535

36-
// CHECK-DAG: attributes #[[#BTI]] = { {{.*}} "branch-target-enforcement"="true" {{.*}} "sign-return-address"="none"
36+
// CHECK-DAG: attributes #[[#BTI]] = { {{.*}} "branch-target-enforcement"
3737

38-
// CHECK-DAG: attributes #[[#PAC]] = { {{.*}} "branch-target-enforcement"="false" {{.*}} "sign-return-address"="non-leaf"
38+
// CHECK-DAG: attributes #[[#PAC]] = { {{.*}} "sign-return-address"="non-leaf"
3939

40-
// CHECK-DAG: attributes #[[#PACLEAF]] = { {{.*}} "branch-target-enforcement"="false" {{.*}}"sign-return-address"="all"
40+
// CHECK-DAG: attributes #[[#PACLEAF]] = { {{.*}} "sign-return-address"="all"
4141

42-
// CHECK-DAG: attributes #[[#BTIPACLEAF]] = { {{.*}}"branch-target-enforcement"="true" {{.*}} "sign-return-address"="all"
42+
// CHECK-DAG: attributes #[[#BTIPACLEAF]] = { {{.*}} "branch-target-enforcement" {{.*}} "sign-return-address"="all"

clang/test/CodeGen/arm-branch-protection-attr-2.c

+9-4
Original file line numberDiff line numberDiff line change
@@ -5,13 +5,18 @@
55
// RUN: %clang -target arm-arm-none-eabi -march=armv8.1-m.main -S -emit-llvm -o - -mbranch-protection=pac-ret+b-key %s | FileCheck %s --check-prefix=CHECK --check-prefix=PART
66
// RUN: %clang -target arm-arm-none-eabi -march=armv8.1-m.main -S -emit-llvm -o - -mbranch-protection=bti %s | FileCheck %s --check-prefix=CHECK --check-prefix=BTE
77

8-
// Check there are no branch protection function attributes
8+
// Check there are branch protection function attributes
99

1010
// CHECK-LABEL: @foo() #[[#ATTR:]]
1111

12-
// CHECK-NOT: attributes #[[#ATTR]] = { {{.*}} "sign-return-address"
13-
// CHECK-NOT: attributes #[[#ATTR]] = { {{.*}} "sign-return-address-key"
14-
// CHECK-NOT: attributes #[[#ATTR]] = { {{.*}} "branch-target-enforcement"
12+
// NONE-NOT: attributes #[[#ATTR]] = { {{.*}} "sign-return-address"
13+
// NONE-NOT: attributes #[[#ATTR]] = { {{.*}} "sign-return-address-key"
14+
// NONE-NOT: attributes #[[#ATTR]] = { {{.*}} "branch-target-enforcement"
15+
16+
// ALL: attributes #[[#ATTR]] = { {{.*}} "sign-return-address"="all"
17+
// PART: attributes #[[#ATTR]] = { {{.*}} "sign-return-address"="non-leaf"
18+
// BTE: attributes #[[#ATTR]] = { {{.*}} "branch-target-enforcement"
19+
1520

1621
// Check module attributes
1722

Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
// REQUIRES: arm-registered-target
2+
3+
// RUN: %clang_cc1 -triple=thumbv7m-unknown-unknown-eabi -msign-return-address=non-leaf %s -emit-llvm -o - 2>&1 | FileCheck %s --check-prefix=CHECK --check-prefix=SIGN
4+
// RUN: %clang_cc1 -triple=thumbv7m-unknown-unknown-eabi -mbranch-target-enforce %s -emit-llvm -o - 2>&1 | FileCheck %s --check-prefix=CHECK --check-prefix=BTE
5+
// RUN: %clang_cc1 -triple=thumbv7m-unknown-unknown-eabi -mbranch-target-enforce -msign-return-address=all %s -emit-llvm -o - 2>&1 | FileCheck %s --check-prefix=CHECK --check-prefix=ALL
6+
7+
// RUN: %clang_cc1 -flto -triple=thumbv7m-unknown-unknown-eabi -msign-return-address=non-leaf %s -emit-llvm -o - 2>&1 | FileCheck %s --check-prefix=CHECK --check-prefix=SIGN
8+
// RUN: %clang_cc1 -flto -triple=thumbv7m-unknown-unknown-eabi -mbranch-target-enforce %s -emit-llvm -o - 2>&1 | FileCheck %s --check-prefix=CHECK --check-prefix=BTE
9+
// RUN: %clang_cc1 -flto -triple=thumbv7m-unknown-unknown-eabi -mbranch-target-enforce -msign-return-address=all %s -emit-llvm -o - 2>&1 | FileCheck %s --check-prefix=CHECK --check-prefix=ALL
10+
11+
// RUN: %clang_cc1 -flto=thin -triple=thumbv7m-unknown-unknown-eabi -msign-return-address=non-leaf %s -emit-llvm -o - 2>&1 | FileCheck %s --check-prefix=CHECK --check-prefix=SIGN
12+
// RUN: %clang_cc1 -flto=thin -triple=thumbv7m-unknown-unknown-eabi -mbranch-target-enforce %s -emit-llvm -o - 2>&1 | FileCheck %s --check-prefix=CHECK --check-prefix=BTE
13+
// RUN: %clang_cc1 -flto=thin -triple=thumbv7m-unknown-unknown-eabi -mbranch-target-enforce -msign-return-address=all %s -emit-llvm -o - 2>&1 | FileCheck %s --check-prefix=CHECK --check-prefix=ALL
14+
15+
void foo() {}
16+
17+
// Check there are branch protection function attributes.
18+
// CHECK-LABEL: @foo() #[[#ATTR:]]
19+
20+
// SIGN-NOT: attributes #[[#ATTR]] = { {{.*}} "branch-target-enforcement"
21+
// SIGN: attributes #[[#ATTR]] = { {{.*}} "sign-return-address"="non-leaf"
22+
// BTE: attributes #[[#ATTR]] = { {{.*}} "sign-return-address"
23+
// BTE: attributes #[[#ATTR]] = { {{.*}} "branch-target-enforcement"
24+
// ALL: attributes #[[#ATTR]] = { {{.*}} "branch-target-enforcement"{{.*}} "sign-return-address"="all"

llvm/lib/CodeGen/SelectionDAG/SelectionDAGBuilder.cpp

+1-11
Original file line numberDiff line numberDiff line change
@@ -12012,17 +12012,7 @@ void SelectionDAGBuilder::lowerWorkItem(SwitchWorkListItem W, Value *Cond,
1201212012
// table branch.
1201312013
if (FallthroughUnreachable) {
1201412014
Function &CurFunc = CurMF->getFunction();
12015-
bool HasBranchTargetEnforcement = false;
12016-
if (CurFunc.hasFnAttribute("branch-target-enforcement")) {
12017-
HasBranchTargetEnforcement =
12018-
CurFunc.getFnAttribute("branch-target-enforcement")
12019-
.getValueAsBool();
12020-
} else {
12021-
HasBranchTargetEnforcement =
12022-
CurMF->getMMI().getModule()->getModuleFlag(
12023-
"branch-target-enforcement");
12024-
}
12025-
if (!HasBranchTargetEnforcement)
12015+
if (!CurFunc.hasFnAttribute("branch-target-enforcement"))
1202612016
JTH->FallthroughUnreachable = true;
1202712017
}
1202812018

llvm/lib/IR/Verifier.cpp

+19-1
Original file line numberDiff line numberDiff line change
@@ -2348,15 +2348,33 @@ void Verifier::verifyFunctionAttrs(FunctionType *FT, AttributeList Attrs,
23482348
if (S != "a_key" && S != "b_key")
23492349
CheckFailed("invalid value for 'sign-return-address-key' attribute: " + S,
23502350
V);
2351+
if (auto AA = Attrs.getFnAttr("sign-return-address"); !AA.isValid()) {
2352+
CheckFailed(
2353+
"'sign-return-address-key' present without `sign-return-address`");
2354+
}
23512355
}
23522356

23532357
if (auto A = Attrs.getFnAttr("branch-target-enforcement"); A.isValid()) {
23542358
StringRef S = A.getValueAsString();
2355-
if (S != "true" && S != "false")
2359+
if (S != "" && S != "true" && S != "false")
23562360
CheckFailed(
23572361
"invalid value for 'branch-target-enforcement' attribute: " + S, V);
23582362
}
23592363

2364+
if (auto A = Attrs.getFnAttr("branch-protection-pauth-lr"); A.isValid()) {
2365+
StringRef S = A.getValueAsString();
2366+
if (S != "" && S != "true" && S != "false")
2367+
CheckFailed(
2368+
"invalid value for 'branch-protection-pauth-lr' attribute: " + S, V);
2369+
}
2370+
2371+
if (auto A = Attrs.getFnAttr("guarded-control-stack"); A.isValid()) {
2372+
StringRef S = A.getValueAsString();
2373+
if (S != "" && S != "true" && S != "false")
2374+
CheckFailed("invalid value for 'guarded-control-stack' attribute: " + S,
2375+
V);
2376+
}
2377+
23602378
if (auto A = Attrs.getFnAttr("vector-function-abi-variant"); A.isValid()) {
23612379
StringRef S = A.getValueAsString();
23622380
const std::optional<VFInfo> Info = VFABI::tryDemangleForVFABI(S, FT);

llvm/lib/Target/AArch64/AArch64AsmPrinter.cpp

+3-3
Original file line numberDiff line numberDiff line change
@@ -272,17 +272,17 @@ void AArch64AsmPrinter::emitStartOfAsmFile(Module &M) {
272272
unsigned Flags = 0;
273273
if (const auto *BTE = mdconst::extract_or_null<ConstantInt>(
274274
M.getModuleFlag("branch-target-enforcement")))
275-
if (BTE->getZExtValue())
275+
if (!BTE->isZero())
276276
Flags |= ELF::GNU_PROPERTY_AARCH64_FEATURE_1_BTI;
277277

278278
if (const auto *GCS = mdconst::extract_or_null<ConstantInt>(
279279
M.getModuleFlag("guarded-control-stack")))
280-
if (GCS->getZExtValue())
280+
if (!GCS->isZero())
281281
Flags |= ELF::GNU_PROPERTY_AARCH64_FEATURE_1_GCS;
282282

283283
if (const auto *Sign = mdconst::extract_or_null<ConstantInt>(
284284
M.getModuleFlag("sign-return-address")))
285-
if (Sign->getZExtValue())
285+
if (!Sign->isZero())
286286
Flags |= ELF::GNU_PROPERTY_AARCH64_FEATURE_1_PAC;
287287

288288
uint64_t PAuthABIPlatform = -1;

0 commit comments

Comments
 (0)