Skip to content

Commit 5cb1940

Browse files
committed
use lambda for getting attributes values
1 parent da33de6 commit 5cb1940

File tree

1 file changed

+13
-22
lines changed

1 file changed

+13
-22
lines changed

lld/ELF/InputFiles.cpp

Lines changed: 13 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -221,33 +221,24 @@ static AArch64BuildAttrSubsections
221221
extractBuildAttributesSubsections(const AArch64AttributeParser &attributes) {
222222

223223
AArch64BuildAttrSubsections subSections;
224+
auto getPauthValue = [&](unsigned tag) -> unsigned {
225+
return attributes.getAttributeValue("aeabi_pauthabi", tag).value_or(0);
226+
};
224227
subSections.pauth.tagPlatform =
225-
attributes
226-
.getAttributeValue("aeabi_pauthabi",
227-
llvm::AArch64BuildAttributes::TAG_PAUTH_PLATFORM)
228-
.value_or(0);
228+
getPauthValue(llvm::AArch64BuildAttributes::TAG_PAUTH_PLATFORM);
229229
subSections.pauth.tagSchema =
230-
attributes
231-
.getAttributeValue("aeabi_pauthabi",
232-
llvm::AArch64BuildAttributes::TAG_PAUTH_SCHEMA)
233-
.value_or(0);
230+
getPauthValue(llvm::AArch64BuildAttributes::TAG_PAUTH_SCHEMA);
231+
232+
auto getFeatureValue = [&](unsigned tag) -> unsigned {
233+
return attributes.getAttributeValue("aeabi_feature_and_bits", tag)
234+
.value_or(0);
235+
};
234236
subSections.andFeatures |=
235-
attributes
236-
.getAttributeValue("aeabi_feature_and_bits",
237-
llvm::AArch64BuildAttributes::TAG_FEATURE_BTI)
238-
.value_or(0);
237+
getFeatureValue(llvm::AArch64BuildAttributes::TAG_FEATURE_BTI);
239238
subSections.andFeatures |=
240-
(attributes
241-
.getAttributeValue("aeabi_feature_and_bits",
242-
llvm::AArch64BuildAttributes::TAG_FEATURE_PAC)
243-
.value_or(0))
244-
<< 1;
239+
getFeatureValue(llvm::AArch64BuildAttributes::TAG_FEATURE_PAC) << 1;
245240
subSections.andFeatures |=
246-
(attributes
247-
.getAttributeValue("aeabi_feature_and_bits",
248-
llvm::AArch64BuildAttributes::TAG_FEATURE_GCS)
249-
.value_or(0))
250-
<< 2;
241+
getFeatureValue(llvm::AArch64BuildAttributes::TAG_FEATURE_GCS) << 2;
251242

252243
return subSections;
253244
}

0 commit comments

Comments
 (0)