Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit e15d67c

Browse files
authoredJul 10, 2024
[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
 

‎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;
There was a problem loading the remainder of the diff.

0 commit comments

Comments
 (0)
Failed to load comments.