Skip to content

Commit

Permalink
Delete RELR-related changes
Browse files Browse the repository at this point in the history
  • Loading branch information
kovdan01 committed Apr 2, 2024
1 parent e4a37a6 commit 05cf361
Show file tree
Hide file tree
Showing 6 changed files with 46 additions and 233 deletions.
13 changes: 0 additions & 13 deletions lld/ELF/Arch/AArch64.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -400,19 +400,6 @@ void AArch64::relocate(uint8_t *loc, const Relocation &rel,
case R_AARCH64_PREL64:
write64(loc, val);
break;
case R_AARCH64_AUTH_ABS64:
// If val is wider than 32 bits, the relocation must have been moved from
// .relr.auth.dyn to .rela.dyn, and the addend write is not needed.
//
// If val fits in 32 bits, we have two potential scenarios:
// * True RELR: Write the 32-bit `val`
// * RELA: Even if the value now fits in 32 bits, it might have been
// converted from RELR during an iteration in
// finalizeAddressDependentContent(). Writing the value is harmless
// because dynamic linking ignores it.
if (isInt<32>(val))
write32(loc, val);
break;
case R_AARCH64_ADD_ABS_LO12_NC:
or32AArch64Imm(loc, val);
break;
Expand Down
10 changes: 2 additions & 8 deletions lld/ELF/Relocations.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -898,9 +898,9 @@ static void addRelativeReloc(InputSectionBase &isec, uint64_t offsetInSec,
isec.addReloc({expr, type, offsetInSec, addend, &sym});
if (shard)
part.relrDyn->relocsVec[parallel::getThreadIndex()].push_back(
{&isec, isec.relocs().size() - 1});
{&isec, offsetInSec});
else
part.relrDyn->relocs.push_back({&isec, isec.relocs().size() - 1});
part.relrDyn->relocs.push_back({&isec, offsetInSec});
return;
}
part.relaDyn->addRelativeReloc<shard>(target->relativeRel, isec, offsetInSec,
Expand Down Expand Up @@ -1154,12 +1154,6 @@ void RelocationScanner::processAux(RelExpr expr, RelType type, uint64_t offset,
// relative relocation. Use a symbolic relocation instead.
if (sym.isPreemptible) {
part.relaDyn->addSymbolReloc(type, *sec, offset, sym, addend, type);
} else if (part.relrAuthDyn && sec->addralign >= 2 && offset % 2 == 0) {
// When symbol values are determined in
// finalizeAddressDependentContent, some .relr.auth.dyn relocations
// may be moved to .rela.dyn.
sec->addReloc({expr, type, offset, addend, &sym});
part.relrAuthDyn->relocs.push_back({sec, sec->relocs().size() - 1});
} else {
part.relaDyn->addReloc({R_AARCH64_AUTH_RELATIVE, sec, offset,
DynamicReloc::AddendOnlyWithTargetVA, sym,
Expand Down
21 changes: 6 additions & 15 deletions lld/ELF/SyntheticSections.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1417,12 +1417,6 @@ DynamicSection<ELFT>::computeContents() {
addInt(config->useAndroidRelrTags ? DT_ANDROID_RELRENT : DT_RELRENT,
sizeof(Elf_Relr));
}
if (part.relrAuthDyn && part.relrAuthDyn->getParent() &&
!part.relrAuthDyn->relocs.empty()) {
addInSec(DT_AARCH64_AUTH_RELR, *part.relrAuthDyn);
addInt(DT_AARCH64_AUTH_RELRSZ, part.relrAuthDyn->getParent()->size);
addInt(DT_AARCH64_AUTH_RELRENT, sizeof(Elf_Relr));
}
if (isMain && in.relaPlt->isNeeded()) {
addInSec(DT_JMPREL, *in.relaPlt);
entries.emplace_back(DT_PLTRELSZ, addPltRelSz());
Expand Down Expand Up @@ -1733,13 +1727,10 @@ template <class ELFT> void RelocationSection<ELFT>::writeTo(uint8_t *buf) {
}
}

RelrBaseSection::RelrBaseSection(unsigned concurrency, bool isAArch64Auth)
: SyntheticSection(
SHF_ALLOC,
isAArch64Auth
? SHT_AARCH64_AUTH_RELR
: (config->useAndroidRelrTags ? SHT_ANDROID_RELR : SHT_RELR),
config->wordsize, isAArch64Auth ? ".relr.auth.dyn" : ".relr.dyn"),
RelrBaseSection::RelrBaseSection(unsigned concurrency)
: SyntheticSection(SHF_ALLOC,
config->useAndroidRelrTags ? SHT_ANDROID_RELR : SHT_RELR,
config->wordsize, ".relr.dyn"),
relocsVec(concurrency) {}

void RelrBaseSection::mergeRels() {
Expand Down Expand Up @@ -2007,8 +1998,8 @@ bool AndroidPackedRelocationSection<ELFT>::updateAllocSize() {
}

template <class ELFT>
RelrSection<ELFT>::RelrSection(unsigned concurrency, bool isAArch64Auth)
: RelrBaseSection(concurrency, isAArch64Auth) {
RelrSection<ELFT>::RelrSection(unsigned concurrency)
: RelrBaseSection(concurrency) {
this->entsize = config->wordsize;
}

Expand Down
15 changes: 5 additions & 10 deletions lld/ELF/SyntheticSections.h
Original file line number Diff line number Diff line change
Expand Up @@ -543,9 +543,7 @@ class RelocationBaseSection : public SyntheticSection {
static bool classof(const SectionBase *d) {
return SyntheticSection::classof(d) &&
(d->type == llvm::ELF::SHT_RELA || d->type == llvm::ELF::SHT_REL ||
d->type == llvm::ELF::SHT_RELR ||
(config->emachine == llvm::ELF::EM_AARCH64 &&
d->type == llvm::ELF::SHT_AARCH64_AUTH_RELR));
d->type == llvm::ELF::SHT_RELR);
}
int32_t dynamicTag, sizeDynamicTag;
SmallVector<DynamicReloc, 0> relocs;
Expand Down Expand Up @@ -593,17 +591,15 @@ class AndroidPackedRelocationSection final : public RelocationBaseSection {
};

struct RelativeReloc {
uint64_t getOffset() const {
return inputSec->getVA(inputSec->relocs()[relocIdx].offset);
}
uint64_t getOffset() const { return inputSec->getVA(offsetInSec); }

const InputSectionBase *inputSec;
size_t relocIdx;
uint64_t offsetInSec;
};

class RelrBaseSection : public SyntheticSection {
public:
RelrBaseSection(unsigned concurrency, bool isAArch64Auth = false);
RelrBaseSection(unsigned concurrency);
void mergeRels();
bool isNeeded() const override {
return !relocs.empty() ||
Expand All @@ -621,7 +617,7 @@ template <class ELFT> class RelrSection final : public RelrBaseSection {
using Elf_Relr = typename ELFT::Relr;

public:
RelrSection(unsigned concurrency, bool isAArch64Auth = false);
RelrSection(unsigned concurrency);

bool updateAllocSize() override;
size_t getSize() const override { return relrRelocs.size() * this->entsize; }
Expand Down Expand Up @@ -1323,7 +1319,6 @@ struct Partition {
std::unique_ptr<PackageMetadataNote> packageMetadataNote;
std::unique_ptr<RelocationBaseSection> relaDyn;
std::unique_ptr<RelrBaseSection> relrDyn;
std::unique_ptr<RelrBaseSection> relrAuthDyn;
std::unique_ptr<VersionDefinitionSection> verDef;
std::unique_ptr<SyntheticSection> verNeed;
std::unique_ptr<VersionTableSection> verSym;
Expand Down
39 changes: 0 additions & 39 deletions lld/ELF/Writer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -456,9 +456,6 @@ template <class ELFT> void elf::createSyntheticSections() {
if (config->relrPackDynRelocs) {
part.relrDyn = std::make_unique<RelrSection<ELFT>>(threadCount);
add(*part.relrDyn);
part.relrAuthDyn = std::make_unique<RelrSection<ELFT>>(
threadCount, /*isAArch64Auth=*/true);
add(*part.relrAuthDyn);
}

if (!config->relocatable) {
Expand Down Expand Up @@ -1733,33 +1730,9 @@ template <class ELFT> void Writer<ELFT>::finalizeAddressDependentContent() {
in.mipsGot->updateAllocSize();

for (Partition &part : partitions) {
// The R_AARCH64_AUTH_RELATIVE has a smaller addend field as bits [63:32]
// encode the signing schema. We've put relocations in .relr.auth.dyn
// during RelocationScanner::processAux, but the target VA for some of
// them might be wider than 32 bits. We can only know the final VA at this
// point, so move relocations with large values from .relr.auth.dyn to
// .rela.dyn.
if (part.relrAuthDyn) {
auto it = llvm::remove_if(
part.relrAuthDyn->relocs, [&part](const RelativeReloc &elem) {
const Relocation &reloc = elem.inputSec->relocs()[elem.relocIdx];
if (isInt<32>(reloc.sym->getVA(reloc.addend)))
return false;
part.relaDyn->addReloc({R_AARCH64_AUTH_RELATIVE, elem.inputSec,
reloc.offset,
DynamicReloc::AddendOnlyWithTargetVA,
*reloc.sym, reloc.addend, R_ABS});
// See also AArch64::relocate
return true;
});
changed |= (it != part.relrAuthDyn->relocs.end());
part.relrAuthDyn->relocs.erase(it, part.relrAuthDyn->relocs.end());
}
changed |= part.relaDyn->updateAllocSize();
if (part.relrDyn)
changed |= part.relrDyn->updateAllocSize();
if (part.relrAuthDyn)
changed |= part.relrAuthDyn->updateAllocSize();
if (part.memtagGlobalDescriptors)
changed |= part.memtagGlobalDescriptors->updateAllocSize();
}
Expand Down Expand Up @@ -1910,14 +1883,6 @@ static void removeUnusedSyntheticSections() {
auto *sec = cast<SyntheticSection>(s);
if (sec->getParent() && sec->isNeeded())
return false;
// .relr.auth.dyn relocations may be moved to .rela.dyn in
// finalizeAddressDependentContent, making .rela.dyn no longer empty.
// Conservatively keep .rela.dyn. .relr.auth.dyn can be made empty, but
// we would fail to remove it here.
if (config->emachine == EM_AARCH64 && config->relrPackDynRelocs)
if (auto *relSec = dyn_cast<RelocationBaseSection>(sec))
if (relSec == mainPart->relaDyn.get())
return false;
unused.insert(sec);
return true;
});
Expand Down Expand Up @@ -2230,10 +2195,6 @@ template <class ELFT> void Writer<ELFT>::finalizeSections() {
part.relrDyn->mergeRels();
finalizeSynthetic(part.relrDyn.get());
}
if (part.relrAuthDyn) {
part.relrAuthDyn->mergeRels();
finalizeSynthetic(part.relrAuthDyn.get());
}

finalizeSynthetic(part.dynSymTab.get());
finalizeSynthetic(part.gnuHashTab.get());
Expand Down
Loading

0 comments on commit 05cf361

Please sign in to comment.