Skip to content

Commit bbb33fe

Browse files
committed
only serialize, reduce message size
1 parent 9e70cbe commit bbb33fe

File tree

2 files changed

+31
-70
lines changed

2 files changed

+31
-70
lines changed

lld/ELF/InputFiles.cpp

Lines changed: 29 additions & 58 deletions
Original file line numberDiff line numberDiff line change
@@ -688,73 +688,44 @@ handleAArch64BAAndGnuProperties(const ELFT &tPointer, Ctx &ctx, bool isBE,
688688
bool hasBA, bool hasGP,
689689
const AArch64BuildAttrSubsections &baInfo,
690690
const gnuPropertiesInfo &gpInfo) {
691+
692+
auto serializeUnsigned = [&](unsigned valueLow, unsigned valueHigh,
693+
bool isBE) -> std::array<uint8_t, 16> {
694+
std::array<uint8_t, 16> arr;
695+
for (size_t i = 0; i < 8; ++i) {
696+
arr[i] = static_cast<uint8_t>(
697+
(static_cast<uint64_t>(valueLow) >> (8 * (isBE ? (7 - i) : i))) &
698+
0xFF);
699+
arr[i + 8] = static_cast<uint8_t>(
700+
(static_cast<uint64_t>(valueHigh) >> (8 * (isBE ? (7 - i) : i))) &
701+
0xFF);
702+
};
703+
return arr;
704+
};
705+
691706
if (hasBA && hasGP) {
692707
if (!gpInfo.aarch64PauthAbiCoreInfo.empty()) {
693-
// check for a mismatch
694-
auto deserializeArray = [&](size_t offset, bool isBE) {
695-
unsigned value = 0;
696-
for (size_t i = 0; i < 8; ++i) {
697-
if (isBE)
698-
value = (value << 8) | gpInfo.aarch64PauthAbiCoreInfo[i + offset];
699-
else
700-
value |= static_cast<uint64_t>(
701-
gpInfo.aarch64PauthAbiCoreInfo[i + offset])
702-
<< (8 * i);
703-
};
704-
return value;
705-
};
706-
unsigned gnuPropPauthPlatform = deserializeArray(0, isBE);
707-
if (baInfo.pauth.tagPlatform != gnuPropPauthPlatform)
708-
ErrAlways(ctx)
709-
<< tPointer
710-
<< "Pauth Platform mismatch: file contains both GNU properties and "
711-
"AArch64 build attributes sections\nGNU properties: "
712-
<< gnuPropPauthPlatform
713-
<< "\nAArch64 build attributes: " << baInfo.pauth.tagPlatform;
714-
unsigned gnuPropPauthScheme = deserializeArray(8, isBE);
715-
if (baInfo.pauth.tagSchema != gnuPropPauthScheme)
708+
auto baPauth = serializeUnsigned(baInfo.pauth.tagPlatform,
709+
baInfo.pauth.tagSchema, isBE);
710+
if (gpInfo.aarch64PauthAbiCoreInfo != ArrayRef<uint8_t>(baPauth))
716711
ErrAlways(ctx)
717712
<< tPointer
718-
<< "Pauth Schema mismatch: file contains both GNU properties and "
719-
"AArch64 build attributes sections\nGNU properties: "
720-
<< gnuPropPauthScheme
721-
<< "\nAArch64 build attributes: " << baInfo.pauth.tagSchema;
713+
<< " Pauth Data mismatch: file contains both GNU properties and "
714+
"AArch64 build attributes sections with different Pauth data";
722715
}
723-
if (baInfo.fAndB.tagBTI != (gpInfo.andFeatures & 0x01))
724-
ErrAlways(ctx)
725-
<< tPointer
726-
<< "Features BTI mismatch: file contains both GNU properties and "
727-
"AArch64 build attributes sections\nGNU properties: "
728-
<< (gpInfo.andFeatures & 0x01)
729-
<< "\nAArch64 build attributes: " << baInfo.fAndB.tagBTI;
730-
if (baInfo.fAndB.tagPAC != ((gpInfo.andFeatures >> 1) & 0x01))
731-
ErrAlways(ctx)
732-
<< tPointer
733-
<< "Feature PAC mismatch: file contains both GNU properties and "
734-
"AArch64 build attributes sections\nGNU properties: "
735-
<< ((gpInfo.andFeatures >> 1) & 0x01)
736-
<< "\nAArch64 build attributes: " << baInfo.fAndB.tagPAC;
737-
if (baInfo.fAndB.tagGCS != ((gpInfo.andFeatures >> 2) & 0x01))
738-
ErrAlways(ctx)
739-
<< tPointer
740-
<< "Feature GCS mismatch: file contains both GNU properties and "
741-
"AArch64 build attributes sections\nGNU properties: "
742-
<< ((gpInfo.andFeatures >> 2) & 0x01)
743-
<< "\nAArch64 build attributes: " << baInfo.fAndB.tagGCS;
716+
if (baInfo.fAndB.tagBTI != (gpInfo.andFeatures & 0x01) ||
717+
baInfo.fAndB.tagPAC != ((gpInfo.andFeatures >> 1) & 0x01) ||
718+
baInfo.fAndB.tagGCS != ((gpInfo.andFeatures >> 2) & 0x01))
719+
ErrAlways(ctx) << tPointer
720+
<< " Features Data mismatch: file contains both GNU "
721+
"properties and AArch64 build attributes sections with "
722+
"different And Features data";
744723
}
745724

746725
if (hasBA && !hasGP) {
747726
if (baInfo.pauth.tagPlatform || baInfo.pauth.tagSchema) {
748-
auto serializeUnsigned = [&](unsigned value, size_t offset, bool isBE) {
749-
for (size_t i = 0; i < 8; ++i) {
750-
tPointer->aarch64PauthAbiCoreInfoStorage[i + offset] =
751-
static_cast<uint8_t>(
752-
(static_cast<uint64_t>(value) >> (8 * (isBE ? (7 - i) : i))) &
753-
0xFF);
754-
};
755-
};
756-
serializeUnsigned(baInfo.pauth.tagPlatform, 0, isBE);
757-
serializeUnsigned(baInfo.pauth.tagSchema, 8, isBE);
727+
tPointer->aarch64PauthAbiCoreInfoStorage = serializeUnsigned(
728+
baInfo.pauth.tagPlatform, baInfo.pauth.tagSchema, isBE);
758729
tPointer->aarch64PauthAbiCoreInfo =
759730
tPointer->aarch64PauthAbiCoreInfoStorage;
760731
}

lld/test/ELF/aarch64-build-attributes-both-err.s

Lines changed: 2 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -13,18 +13,8 @@
1313
// RUN: llvm-mc -triple=aarch64_be %s -filetype=obj -o %t.o
1414
// RUN: not ld.lld -EB %t.o -o /dev/null 2>&1 | FileCheck %s --check-prefix=ERR
1515

16-
// ERR: Pauth Platform mismatch: file contains both GNU properties and AArch64 build attributes sections
17-
// ERR-NEXT: GNU properties: 305419896
18-
// ERR-NEXT: AArch64 build attributes: 5
19-
// ERR: Pauth Schema mismatch: file contains both GNU properties and AArch64 build attributes sections
20-
// ERR-NEXT: GNU properties: 2271560481
21-
// ERR-NEXT: AArch64 build attributes: 5
22-
// ERR: Features BTI mismatch: file contains both GNU properties and AArch64 build attributes sections
23-
// ERR-NEXT: GNU properties: 0
24-
// ERR-NEXT: AArch64 build attributes: 1
25-
// ERR: Feature GCS mismatch: file contains both GNU properties and AArch64 build attributes sections
26-
// ERR-NEXT: GNU properties: 0
27-
// ERR-NEXT: AArch64 build attributes: 1
16+
// ERR: Pauth Data mismatch: file contains both GNU properties and AArch64 build attributes sections with different Pauth data
17+
// ERR-NEXT: Features Data mismatch: file contains both GNU properties and AArch64 build attributes sections with different And Features data
2818

2919
.aeabi_subsection aeabi_pauthabi, required, uleb128
3020
.aeabi_attribute Tag_PAuth_Platform, 5

0 commit comments

Comments
 (0)