Skip to content

Commit acb7210

Browse files
authored
Revert "[lld][AArch64][ELF][PAC] Support .relr.auth.dyn section (#87635)"
This reverts commit ca1f0d4.
1 parent 2fa14fc commit acb7210

File tree

6 files changed

+47
-216
lines changed

6 files changed

+47
-216
lines changed

lld/ELF/Arch/AArch64.cpp

-13
Original file line numberDiff line numberDiff line change
@@ -429,19 +429,6 @@ void AArch64::relocate(uint8_t *loc, const Relocation &rel,
429429
case R_AARCH64_PREL64:
430430
write64(loc, val);
431431
break;
432-
case R_AARCH64_AUTH_ABS64:
433-
// If val is wider than 32 bits, the relocation must have been moved from
434-
// .relr.auth.dyn to .rela.dyn, and the addend write is not needed.
435-
//
436-
// If val fits in 32 bits, we have two potential scenarios:
437-
// * True RELR: Write the 32-bit `val`.
438-
// * RELA: Even if the value now fits in 32 bits, it might have been
439-
// converted from RELR during an iteration in
440-
// finalizeAddressDependentContent(). Writing the value is harmless
441-
// because dynamic linking ignores it.
442-
if (isInt<32>(val))
443-
write32(loc, val);
444-
break;
445432
case R_AARCH64_ADD_ABS_LO12_NC:
446433
or32AArch64Imm(loc, val);
447434
break;

lld/ELF/Relocations.cpp

+2-8
Original file line numberDiff line numberDiff line change
@@ -898,9 +898,9 @@ static void addRelativeReloc(InputSectionBase &isec, uint64_t offsetInSec,
898898
isec.addReloc({expr, type, offsetInSec, addend, &sym});
899899
if (shard)
900900
part.relrDyn->relocsVec[parallel::getThreadIndex()].push_back(
901-
{&isec, isec.relocs().size() - 1});
901+
{&isec, offsetInSec});
902902
else
903-
part.relrDyn->relocs.push_back({&isec, isec.relocs().size() - 1});
903+
part.relrDyn->relocs.push_back({&isec, offsetInSec});
904904
return;
905905
}
906906
part.relaDyn->addRelativeReloc<shard>(target->relativeRel, isec, offsetInSec,
@@ -1154,12 +1154,6 @@ void RelocationScanner::processAux(RelExpr expr, RelType type, uint64_t offset,
11541154
// relative relocation. Use a symbolic relocation instead.
11551155
if (sym.isPreemptible) {
11561156
part.relaDyn->addSymbolReloc(type, *sec, offset, sym, addend, type);
1157-
} else if (part.relrAuthDyn && sec->addralign >= 2 && offset % 2 == 0) {
1158-
// When symbol values are determined in
1159-
// finalizeAddressDependentContent, some .relr.auth.dyn relocations
1160-
// may be moved to .rela.dyn.
1161-
sec->addReloc({expr, type, offset, addend, &sym});
1162-
part.relrAuthDyn->relocs.push_back({sec, sec->relocs().size() - 1});
11631157
} else {
11641158
part.relaDyn->addReloc({R_AARCH64_AUTH_RELATIVE, sec, offset,
11651159
DynamicReloc::AddendOnlyWithTargetVA, sym,

lld/ELF/SyntheticSections.cpp

+6-18
Original file line numberDiff line numberDiff line change
@@ -1420,12 +1420,6 @@ DynamicSection<ELFT>::computeContents() {
14201420
addInt(config->useAndroidRelrTags ? DT_ANDROID_RELRENT : DT_RELRENT,
14211421
sizeof(Elf_Relr));
14221422
}
1423-
if (part.relrAuthDyn && part.relrAuthDyn->getParent() &&
1424-
!part.relrAuthDyn->relocs.empty()) {
1425-
addInSec(DT_AARCH64_AUTH_RELR, *part.relrAuthDyn);
1426-
addInt(DT_AARCH64_AUTH_RELRSZ, part.relrAuthDyn->getParent()->size);
1427-
addInt(DT_AARCH64_AUTH_RELRENT, sizeof(Elf_Relr));
1428-
}
14291423
if (isMain && in.relaPlt->isNeeded()) {
14301424
addInSec(DT_JMPREL, *in.relaPlt);
14311425
entries.emplace_back(DT_PLTRELSZ, addPltRelSz());
@@ -1737,13 +1731,10 @@ template <class ELFT> void RelocationSection<ELFT>::writeTo(uint8_t *buf) {
17371731
}
17381732
}
17391733

1740-
RelrBaseSection::RelrBaseSection(unsigned concurrency, bool isAArch64Auth)
1741-
: SyntheticSection(
1742-
SHF_ALLOC,
1743-
isAArch64Auth
1744-
? SHT_AARCH64_AUTH_RELR
1745-
: (config->useAndroidRelrTags ? SHT_ANDROID_RELR : SHT_RELR),
1746-
config->wordsize, isAArch64Auth ? ".relr.auth.dyn" : ".relr.dyn"),
1734+
RelrBaseSection::RelrBaseSection(unsigned concurrency)
1735+
: SyntheticSection(SHF_ALLOC,
1736+
config->useAndroidRelrTags ? SHT_ANDROID_RELR : SHT_RELR,
1737+
config->wordsize, ".relr.dyn"),
17471738
relocsVec(concurrency) {}
17481739

17491740
void RelrBaseSection::mergeRels() {
@@ -2011,8 +2002,8 @@ bool AndroidPackedRelocationSection<ELFT>::updateAllocSize() {
20112002
}
20122003

20132004
template <class ELFT>
2014-
RelrSection<ELFT>::RelrSection(unsigned concurrency, bool isAArch64Auth)
2015-
: RelrBaseSection(concurrency, isAArch64Auth) {
2005+
RelrSection<ELFT>::RelrSection(unsigned concurrency)
2006+
: RelrBaseSection(concurrency) {
20162007
this->entsize = config->wordsize;
20172008
}
20182009

@@ -4783,9 +4774,6 @@ template <class ELFT> void elf::createSyntheticSections() {
47834774
if (config->relrPackDynRelocs) {
47844775
part.relrDyn = std::make_unique<RelrSection<ELFT>>(threadCount);
47854776
add(*part.relrDyn);
4786-
part.relrAuthDyn = std::make_unique<RelrSection<ELFT>>(
4787-
threadCount, /*isAArch64Auth=*/true);
4788-
add(*part.relrAuthDyn);
47894777
}
47904778

47914779
if (!config->relocatable) {

lld/ELF/SyntheticSections.h

+5-10
Original file line numberDiff line numberDiff line change
@@ -548,9 +548,7 @@ class RelocationBaseSection : public SyntheticSection {
548548
static bool classof(const SectionBase *d) {
549549
return SyntheticSection::classof(d) &&
550550
(d->type == llvm::ELF::SHT_RELA || d->type == llvm::ELF::SHT_REL ||
551-
d->type == llvm::ELF::SHT_RELR ||
552-
(d->type == llvm::ELF::SHT_AARCH64_AUTH_RELR &&
553-
config->emachine == llvm::ELF::EM_AARCH64));
551+
d->type == llvm::ELF::SHT_RELR);
554552
}
555553
int32_t dynamicTag, sizeDynamicTag;
556554
SmallVector<DynamicReloc, 0> relocs;
@@ -598,17 +596,15 @@ class AndroidPackedRelocationSection final : public RelocationBaseSection {
598596
};
599597

600598
struct RelativeReloc {
601-
uint64_t getOffset() const {
602-
return inputSec->getVA(inputSec->relocs()[relocIdx].offset);
603-
}
599+
uint64_t getOffset() const { return inputSec->getVA(offsetInSec); }
604600

605601
const InputSectionBase *inputSec;
606-
size_t relocIdx;
602+
uint64_t offsetInSec;
607603
};
608604

609605
class RelrBaseSection : public SyntheticSection {
610606
public:
611-
RelrBaseSection(unsigned concurrency, bool isAArch64Auth = false);
607+
RelrBaseSection(unsigned concurrency);
612608
void mergeRels();
613609
bool isNeeded() const override {
614610
return !relocs.empty() ||
@@ -626,7 +622,7 @@ template <class ELFT> class RelrSection final : public RelrBaseSection {
626622
using Elf_Relr = typename ELFT::Relr;
627623

628624
public:
629-
RelrSection(unsigned concurrency, bool isAArch64Auth = false);
625+
RelrSection(unsigned concurrency);
630626

631627
bool updateAllocSize() override;
632628
size_t getSize() const override { return relrRelocs.size() * this->entsize; }
@@ -1464,7 +1460,6 @@ struct Partition {
14641460
std::unique_ptr<PackageMetadataNote> packageMetadataNote;
14651461
std::unique_ptr<RelocationBaseSection> relaDyn;
14661462
std::unique_ptr<RelrBaseSection> relrDyn;
1467-
std::unique_ptr<RelrBaseSection> relrAuthDyn;
14681463
std::unique_ptr<VersionDefinitionSection> verDef;
14691464
std::unique_ptr<SyntheticSection> verNeed;
14701465
std::unique_ptr<VersionTableSection> verSym;

lld/ELF/Writer.cpp

-35
Original file line numberDiff line numberDiff line change
@@ -1458,32 +1458,9 @@ template <class ELFT> void Writer<ELFT>::finalizeAddressDependentContent() {
14581458
in.mipsGot->updateAllocSize();
14591459

14601460
for (Partition &part : partitions) {
1461-
// The R_AARCH64_AUTH_RELATIVE has a smaller addend field as bits [63:32]
1462-
// encode the signing schema. We've put relocations in .relr.auth.dyn
1463-
// during RelocationScanner::processAux, but the target VA for some of
1464-
// them might be wider than 32 bits. We can only know the final VA at this
1465-
// point, so move relocations with large values from .relr.auth.dyn to
1466-
// .rela.dyn. See also AArch64::relocate.
1467-
if (part.relrAuthDyn) {
1468-
auto it = llvm::remove_if(
1469-
part.relrAuthDyn->relocs, [&part](const RelativeReloc &elem) {
1470-
const Relocation &reloc = elem.inputSec->relocs()[elem.relocIdx];
1471-
if (isInt<32>(reloc.sym->getVA(reloc.addend)))
1472-
return false;
1473-
part.relaDyn->addReloc({R_AARCH64_AUTH_RELATIVE, elem.inputSec,
1474-
reloc.offset,
1475-
DynamicReloc::AddendOnlyWithTargetVA,
1476-
*reloc.sym, reloc.addend, R_ABS});
1477-
return true;
1478-
});
1479-
changed |= (it != part.relrAuthDyn->relocs.end());
1480-
part.relrAuthDyn->relocs.erase(it, part.relrAuthDyn->relocs.end());
1481-
}
14821461
changed |= part.relaDyn->updateAllocSize();
14831462
if (part.relrDyn)
14841463
changed |= part.relrDyn->updateAllocSize();
1485-
if (part.relrAuthDyn)
1486-
changed |= part.relrAuthDyn->updateAllocSize();
14871464
if (part.memtagGlobalDescriptors)
14881465
changed |= part.memtagGlobalDescriptors->updateAllocSize();
14891466
}
@@ -1647,14 +1624,6 @@ static void removeUnusedSyntheticSections() {
16471624
auto *sec = cast<SyntheticSection>(s);
16481625
if (sec->getParent() && sec->isNeeded())
16491626
return false;
1650-
// .relr.auth.dyn relocations may be moved to .rela.dyn in
1651-
// finalizeAddressDependentContent, making .rela.dyn no longer empty.
1652-
// Conservatively keep .rela.dyn. .relr.auth.dyn can be made empty, but
1653-
// we would fail to remove it here.
1654-
if (config->emachine == EM_AARCH64 && config->relrPackDynRelocs)
1655-
if (auto *relSec = dyn_cast<RelocationBaseSection>(sec))
1656-
if (relSec == mainPart->relaDyn.get())
1657-
return false;
16581627
unused.insert(sec);
16591628
return true;
16601629
});
@@ -1967,10 +1936,6 @@ template <class ELFT> void Writer<ELFT>::finalizeSections() {
19671936
part.relrDyn->mergeRels();
19681937
finalizeSynthetic(part.relrDyn.get());
19691938
}
1970-
if (part.relrAuthDyn) {
1971-
part.relrAuthDyn->mergeRels();
1972-
finalizeSynthetic(part.relrAuthDyn.get());
1973-
}
19741939

19751940
finalizeSynthetic(part.dynSymTab.get());
19761941
finalizeSynthetic(part.gnuHashTab.get());

0 commit comments

Comments
 (0)