Skip to content

Commit cc40b7c

Browse files
committed
Handle code review comments
1 parent b3e62ec commit cc40b7c

File tree

3 files changed

+39
-42
lines changed

3 files changed

+39
-42
lines changed

lld/ELF/InputFiles.cpp

Lines changed: 36 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -542,61 +542,59 @@ uint32_t ObjFile<ELFT>::getSectionIndex(const Elf_Sym &sym) const {
542542

543543
template <class ELFT>
544544
static void
545-
handleAArch64BAAndGnuProperties(const ELFT &tPointer, Ctx &ctx, bool isBE,
546-
bool hasBA, bool hasGP,
545+
handleAArch64BAAndGnuProperties(ObjFile<ELFT> *file, Ctx &ctx, bool hasGP,
547546
const AArch64BuildAttrSubsections &baInfo,
548-
const gnuPropertiesInfo &gpInfo) {
547+
const GnuPropertiesInfo &gpInfo) {
549548

550-
auto serializeUnsigned = [&](unsigned valueLow, unsigned valueHigh,
551-
bool isBE) -> std::array<uint8_t, 16> {
549+
auto serializeUnsigned = [](unsigned valueLow, unsigned valueHigh) {
552550
std::array<uint8_t, 16> arr;
553-
for (size_t i = 0; i < 8; ++i) {
554-
arr[i] = static_cast<uint8_t>(
555-
(static_cast<uint64_t>(valueLow) >> (8 * (isBE ? (7 - i) : i))) &
556-
0xFF);
557-
arr[i + 8] = static_cast<uint8_t>(
558-
(static_cast<uint64_t>(valueHigh) >> (8 * (isBE ? (7 - i) : i))) &
559-
0xFF);
560-
};
551+
support::endian::write64<ELFT::Endianness>(arr.data(), valueLow);
552+
support::endian::write64<ELFT::Endianness>(arr.data() + 8, valueHigh);
561553
return arr;
562554
};
563555

564-
if (hasBA && hasGP) {
556+
if (hasGP) {
565557
// Check for data mismatch
566558
if (!gpInfo.aarch64PauthAbiCoreInfo.empty()) {
567-
auto baPauth = serializeUnsigned(baInfo.Pauth.TagPlatform,
568-
baInfo.Pauth.TagSchema, isBE);
569-
if (gpInfo.aarch64PauthAbiCoreInfo != ArrayRef<uint8_t>(baPauth))
559+
uint64_t valueLow, valueHigh;
560+
std::memcpy(&valueLow, &gpInfo.aarch64PauthAbiCoreInfo[0], 8);
561+
std::memcpy(&valueHigh, &gpInfo.aarch64PauthAbiCoreInfo[8], 8);
562+
if (baInfo.Pauth.TagPlatform != valueLow)
570563
Err(ctx)
571-
<< tPointer
572-
<< " Pauth Data mismatch: file contains both GNU properties and "
573-
"AArch64 build attributes sections with different Pauth data";
564+
<< file
565+
<< " Pauth TagPlatform mismatch: file contains different values in "
566+
"GNU properties and AArch64 build attributes sections: "
567+
<< "GNU = " << llvm::format_hex(valueLow, 16)
568+
<< ", AArch64 = " << llvm::format_hex(baInfo.Pauth.TagPlatform, 16);
569+
if (baInfo.Pauth.TagSchema != valueHigh)
570+
Err(ctx) << file
571+
<< " Pauth TagSchema mismatch: file contains different values "
572+
"in GNU properties and AArch64 build attributes sections: "
573+
<< "GNU = " << llvm::format_hex(valueHigh, 16)
574+
<< ", AArch64 = "
575+
<< llvm::format_hex(baInfo.Pauth.TagSchema, 16);
574576
}
575577
if (baInfo.AndFeatures != gpInfo.andFeatures)
576-
Err(ctx) << tPointer
578+
Err(ctx) << file
577579
<< " Features Data mismatch: file contains both GNU "
578580
"properties and AArch64 build attributes sections with "
579581
"different And Features data";
580-
}
581-
582-
if (hasBA && !hasGP) {
582+
} else {
583583
// Write missing data
584584
// We can only know when Pauth is missing.
585585
// Unlike AArch64 Build Attributes, GNU properties does not give a way to
586586
// distinguish between no-value given to value of '0' given.
587587
if (baInfo.Pauth.TagPlatform || baInfo.Pauth.TagSchema) {
588-
tPointer->aarch64PauthAbiCoreInfoStorage = serializeUnsigned(
589-
baInfo.Pauth.TagPlatform, baInfo.Pauth.TagSchema, isBE);
590-
tPointer->aarch64PauthAbiCoreInfo =
591-
tPointer->aarch64PauthAbiCoreInfoStorage;
588+
file->aarch64PauthAbiCoreInfoStorage =
589+
serializeUnsigned(baInfo.Pauth.TagPlatform, baInfo.Pauth.TagSchema);
590+
file->aarch64PauthAbiCoreInfo = file->aarch64PauthAbiCoreInfoStorage;
592591
}
593-
tPointer->andFeatures = baInfo.AndFeatures;
592+
file->andFeatures = baInfo.AndFeatures;
594593
}
595594
}
596595

597-
// Forward declaration:
598596
template <typename ELFT>
599-
static gnuPropertiesInfo readGnuProperty(Ctx &, const InputSection &,
597+
static GnuPropertiesInfo readGnuProperty(Ctx &, const InputSection &,
600598
ObjFile<ELFT> &);
601599

602600
template <class ELFT> void ObjFile<ELFT>::parse(bool ignoreComdats) {
@@ -617,7 +615,7 @@ template <class ELFT> void ObjFile<ELFT>::parse(bool ignoreComdats) {
617615

618616
// For handling AArch64 Build attributes and GNU properties
619617
AArch64BuildAttrSubsections aarch64BAsubSections;
620-
gnuPropertiesInfo gnuPropertiesInformation;
618+
GnuPropertiesInfo gnuProperty;
621619
bool hasAArch64BuildAttributes = false;
622620
bool hasGNUProperties = false;
623621

@@ -629,7 +627,7 @@ template <class ELFT> void ObjFile<ELFT>::parse(bool ignoreComdats) {
629627
// .note.gnu.property section containing a bitfield of feature bits like the
630628
// GNU_PROPERTY_X86_FEATURE_1_IBT flag. Read a bitmap containing the flag.
631629
if (check(obj.getSectionName(sec, shstrtab)) == ".note.gnu.property") {
632-
gnuPropertiesInformation = readGnuProperty(
630+
gnuProperty = readGnuProperty(
633631
ctx,
634632
InputSection(*this, sec, check(obj.getSectionName(sec, shstrtab))),
635633
*this);
@@ -756,13 +754,11 @@ template <class ELFT> void ObjFile<ELFT>::parse(bool ignoreComdats) {
756754
}
757755

758756
if (hasAArch64BuildAttributes) {
759-
bool isBE = ELFT::Endianness == llvm::endianness::big;
760757
// Handle AArch64 Build Attributes and GNU properties:
761758
// - Err on mismatched values.
762759
// - Store missing values as GNU properties.
763-
handleAArch64BAAndGnuProperties(this, ctx, isBE, hasAArch64BuildAttributes,
764-
hasGNUProperties, aarch64BAsubSections,
765-
gnuPropertiesInformation);
760+
handleAArch64BAAndGnuProperties<ELFT>(this, ctx, hasGNUProperties,
761+
aarch64BAsubSections, gnuProperty);
766762
}
767763

768764
// Read a symbol table.
@@ -1083,7 +1079,7 @@ static void parseGnuPropertyNote(Ctx &ctx, ELFFileBase &f,
10831079
// hardware-assisted call flow control;
10841080
// - AArch64 PAuth ABI core info (16 bytes).
10851081
template <class ELFT>
1086-
static gnuPropertiesInfo readGnuProperty(Ctx &ctx, const InputSection &sec,
1082+
static GnuPropertiesInfo readGnuProperty(Ctx &ctx, const InputSection &sec,
10871083
ObjFile<ELFT> &f) {
10881084
using Elf_Nhdr = typename ELFT::Nhdr;
10891085
using Elf_Note = typename ELFT::Note;
@@ -1100,7 +1096,7 @@ static gnuPropertiesInfo readGnuProperty(Ctx &ctx, const InputSection &sec,
11001096
auto *nhdr = reinterpret_cast<const Elf_Nhdr *>(data.data());
11011097
if (data.size() < sizeof(Elf_Nhdr) ||
11021098
data.size() < nhdr->getSize(sec.addralign))
1103-
return (err(data.data()) << "data is too short", gnuPropertiesInfo{});
1099+
return (err(data.data()) << "data is too short", GnuPropertiesInfo{});
11041100

11051101
Elf_Note note(*nhdr);
11061102
if (nhdr->n_type != NT_GNU_PROPERTY_TYPE_0 || note.getName() != "GNU") {
@@ -1120,7 +1116,7 @@ static gnuPropertiesInfo readGnuProperty(Ctx &ctx, const InputSection &sec,
11201116
// Go to next NOTE record to look for more FEATURE_1_AND descriptions.
11211117
data = data.slice(nhdr->getSize(sec.addralign));
11221118
}
1123-
return gnuPropertiesInfo{f.andFeatures, f.aarch64PauthAbiCoreInfo};
1119+
return {f.andFeatures, f.aarch64PauthAbiCoreInfo};
11241120
}
11251121

11261122
template <class ELFT>

lld/ELF/InputFiles.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -245,7 +245,7 @@ class ELFFileBase : public InputFile {
245245
std::array<uint8_t, 16> aarch64PauthAbiCoreInfoStorage;
246246
};
247247

248-
struct gnuPropertiesInfo {
248+
struct GnuPropertiesInfo {
249249
uint32_t andFeatures = 0;
250250
ArrayRef<uint8_t> aarch64PauthAbiCoreInfo;
251251
};

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,8 @@
33
// RUN: llvm-mc -triple=aarch64 %s -filetype=obj -o %t.o
44
// RUN: not ld.lld %t.o -o /dev/null 2>&1 | FileCheck %s --check-prefix=ERR
55

6-
// ERR: Pauth Data mismatch: file contains both GNU properties and AArch64 build attributes sections with different Pauth data
6+
// ERR: Pauth TagPlatform mismatch: file contains different values in GNU properties and AArch64 build attributes sections: GNU = 0x00000012345678, AArch64 = 0x00000000000005
7+
// ERR-NEXT: Pauth TagSchema mismatch: file contains different values in GNU properties and AArch64 build attributes sections: GNU = 0x00000087654321, AArch64 = 0x00000000000005
78
// ERR-NEXT: Features Data mismatch: file contains both GNU properties and AArch64 build attributes sections with different And Features data
89

910
.aeabi_subsection aeabi_pauthabi, required, uleb128

0 commit comments

Comments
 (0)