@@ -5178,11 +5178,11 @@ void llvm::UpgradeFunctionAttributes(Function &F) {
5178
5178
Arg.removeAttrs (AttributeFuncs::typeIncompatible (Arg.getType ()));
5179
5179
}
5180
5180
5181
- // Check if the module attribute is present and not zero .
5182
- static bool isModuleAttributeSet (Module &M, const StringRef &ModAttr) {
5181
+ // Check if the module attribute is present and set to one .
5182
+ static bool isModuleAttributeOne (Module &M, const StringRef &ModAttr) {
5183
5183
const auto *Attr =
5184
5184
mdconst::extract_or_null<ConstantInt>(M.getModuleFlag (ModAttr));
5185
- return Attr && ! Attr->isZero ();
5185
+ return Attr && Attr->isOne ();
5186
5186
}
5187
5187
5188
5188
// Check if the function attribute is not present and set it.
@@ -5197,31 +5197,36 @@ void llvm::CopyModuleAttrToFunctions(Module &M) {
5197
5197
if (!T.isThumb () && !T.isARM () && !T.isAArch64 ())
5198
5198
return ;
5199
5199
5200
- StringRef SignTypeValue = " none" ;
5201
- if (isModuleAttributeSet (M, " sign-return-address-all" ))
5200
+ bool BTE = isModuleAttributeOne (M, " branch-target-enforcement" );
5201
+ bool BPPLR = isModuleAttributeOne (M, " branch-protection-pauth-lr" );
5202
+ bool GCS = isModuleAttributeOne (M, " guarded-control-stack" );
5203
+ bool SRA = isModuleAttributeOne (M, " sign-return-address" );
5204
+
5205
+ if (!BTE && !BPPLR && !GCS && !SRA)
5206
+ return ;
5207
+
5208
+ StringRef SignTypeValue = " non-leaf" ;
5209
+ if (SRA && isModuleAttributeOne (M, " sign-return-address-all" ))
5202
5210
SignTypeValue = " all" ;
5203
- else if (isModuleAttributeSet (M, " sign-return-address" ))
5204
- SignTypeValue = " non-leaf" ;
5205
-
5206
- StringRef BTEValue =
5207
- isModuleAttributeSet (M, " branch-target-enforcement" ) ? " true" : " false" ;
5208
- StringRef BPPLValue =
5209
- isModuleAttributeSet (M, " branch-protection-pauth-lr" ) ? " true" : " false" ;
5210
- StringRef GCSValue =
5211
- isModuleAttributeSet (M, " guarded-control-stack" ) ? " true" : " false" ;
5212
- StringRef SignKeyValue =
5213
- isModuleAttributeSet (M, " sign-return-address-with-bkey" ) ? " b_key"
5214
- : " a_key" ;
5211
+
5212
+ StringRef SignKeyValue = " a_key" ;
5213
+ if (SRA && isModuleAttributeOne (M, " sign-return-address-with-bkey" ))
5214
+ SignKeyValue = " b_key" ;
5215
5215
5216
5216
for (Function &F : M.getFunctionList ()) {
5217
5217
if (F.isDeclaration ())
5218
5218
continue ;
5219
5219
5220
- SetFunctionAttrIfNotSet (F, " sign-return-address" , SignTypeValue);
5221
- SetFunctionAttrIfNotSet (F, " branch-target-enforcement" , BTEValue);
5222
- SetFunctionAttrIfNotSet (F, " branch-protection-pauth-lr" , BPPLValue);
5223
- SetFunctionAttrIfNotSet (F, " guarded-control-stack" , GCSValue);
5224
- SetFunctionAttrIfNotSet (F, " sign-return-address-key" , SignKeyValue);
5220
+ if (SRA) {
5221
+ SetFunctionAttrIfNotSet (F, " sign-return-address" , SignTypeValue);
5222
+ SetFunctionAttrIfNotSet (F, " sign-return-address-key" , SignKeyValue);
5223
+ }
5224
+ if (BTE)
5225
+ SetFunctionAttrIfNotSet (F, " branch-target-enforcement" , " true" );
5226
+ if (BPPLR)
5227
+ SetFunctionAttrIfNotSet (F, " branch-protection-pauth-lr" , " true" );
5228
+ if (GCS)
5229
+ SetFunctionAttrIfNotSet (F, " guarded-control-stack" , " true" );
5225
5230
}
5226
5231
}
5227
5232
0 commit comments