Skip to content

Commit c8637a0

Browse files
committed
refactor by using lambda
1 parent 4620091 commit c8637a0

File tree

1 file changed

+8
-28
lines changed

1 file changed

+8
-28
lines changed

lld/ELF/InputFiles.cpp

Lines changed: 8 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -717,35 +717,15 @@ template <class ELFT> void ObjFile<ELFT>::parse(bool ignoreComdats) {
717717
Warn(ctx) << &isec << ": " << std::move(e);
718718
} else {
719719
if (!hasGnuProperties) {
720-
KnownAArch64BuildAttrSubsections subSections =
721-
extractBuildAttributesSubsections(attributes);
722-
if (ELFT::Endianness == llvm::endianness::big) {
720+
KnownAArch64BuildAttrSubsections subSections = extractBuildAttributesSubsections(attributes);
721+
auto serializeUnsigned = [&](unsigned value, size_t offset, bool isBE) {
723722
for (size_t i = 0; i < 8; ++i) {
724-
this->aarch64PauthAbiCoreInfoStorage[i] = static_cast<uint8_t>(
725-
(static_cast<uint64_t>(subSections.pauth.tagPlatform) >>
726-
(8 * (7 - i))) &
727-
0xFF);
728-
this->aarch64PauthAbiCoreInfoStorage[i + 8] =
729-
static_cast<uint8_t>(
730-
(static_cast<uint64_t>(subSections.pauth.tagSchema) >>
731-
(8 * (7 - i))) &
732-
0xFF);
733-
}
734-
} else {
735-
for (size_t i = 0; i < 8; ++i) {
736-
this->aarch64PauthAbiCoreInfoStorage[i] = static_cast<uint8_t>(
737-
(static_cast<uint64_t>(subSections.pauth.tagPlatform) >>
738-
(8 * i)) &
739-
0xFF);
740-
this->aarch64PauthAbiCoreInfoStorage[i + 8] =
741-
static_cast<uint8_t>(
742-
(static_cast<uint64_t>(subSections.pauth.tagSchema) >>
743-
(8 * i)) &
744-
0xFF);
745-
}
746-
}
747-
this->aarch64PauthAbiCoreInfo =
748-
this->aarch64PauthAbiCoreInfoStorage;
723+
this->aarch64PauthAbiCoreInfoStorage[i + offset] = static_cast<uint8_t>((static_cast<uint64_t>(value) >> (8 * (isBE ? (7 - i): i))) & 0xFF); };
724+
};
725+
serializeUnsigned(subSections.pauth.tagPlatform, 0, ELFT::Endianness == llvm::endianness::big);
726+
serializeUnsigned(subSections.pauth.tagSchema, 8, ELFT::Endianness == llvm::endianness::big);
727+
this->aarch64PauthAbiCoreInfo = this->aarch64PauthAbiCoreInfoStorage;
728+
749729
this->andFeatures = 0;
750730
this->andFeatures |= (subSections.fAndB.tagBTI) << 0;
751731
this->andFeatures |= (subSections.fAndB.tagPAC) << 1;

0 commit comments

Comments
 (0)