Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 7 additions & 14 deletions lld/ELF/SyntheticSections.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1643,17 +1643,10 @@ uint64_t DynamicReloc::getOffset() const {
}

int64_t DynamicReloc::computeAddend(Ctx &ctx) const {
switch (kind) {
case Computed:
llvm_unreachable("addend already computed");
case AddendOnly:
case AgainstSymbol: {
uint64_t ca = inputSec->getRelocTargetVA(
ctx, Relocation{expr, type, 0, addend, sym}, getOffset());
return ctx.arg.is64 ? ca : SignExtend64<32>(ca);
}
}
llvm_unreachable("Unknown DynamicReloc::Kind enum");
assert(!isFinal && "addend already computed");
uint64_t ca = inputSec->getRelocTargetVA(
ctx, Relocation{expr, type, 0, addend, sym}, getOffset());
return ctx.arg.is64 ? ca : SignExtend64<32>(ca);
}

uint32_t DynamicReloc::getSymIndex(SymbolTableBaseSection *symTab) const {
Expand Down Expand Up @@ -1734,17 +1727,17 @@ void RelocationBaseSection::finalizeContents() {
}
}

void DynamicReloc::computeRaw(Ctx &ctx, SymbolTableBaseSection *symt) {
void DynamicReloc::finalize(Ctx &ctx, SymbolTableBaseSection *symt) {
r_offset = getOffset();
r_sym = getSymIndex(symt);
addend = computeAddend(ctx);
kind = Computed; // Catch errors
isFinal = true; // Catch errors
}

void RelocationBaseSection::computeRels() {
SymbolTableBaseSection *symTab = getPartition(ctx).dynSymTab.get();
parallelForEach(relocs, [&ctx = ctx, symTab](DynamicReloc &rel) {
rel.computeRaw(ctx, symTab);
rel.finalize(ctx, symTab);
});

auto irelative = std::stable_partition(
Expand Down
23 changes: 13 additions & 10 deletions lld/ELF/SyntheticSections.h
Original file line number Diff line number Diff line change
Expand Up @@ -421,9 +421,6 @@ class StringTableSection final : public SyntheticSection {
class DynamicReloc {
public:
enum Kind {
/// The resulting dynamic relocation has already had its addend computed.
/// Calling computeAddend() is an error. Only for internal use.
Computed,
/// The resulting dynamic relocation will not reference a symbol: #sym is
/// only used to compute the addend with InputSection::getRelocTargetVA().
/// Useful for various relative and TLS relocations (e.g. R_X86_64_TPOFF64).
Expand All @@ -438,7 +435,8 @@ class DynamicReloc {
uint64_t offsetInSec, Kind kind, Symbol &sym, int64_t addend,
RelExpr expr)
: sym(&sym), inputSec(inputSec), offsetInSec(offsetInSec), type(type),
addend(addend), kind(kind), expr(expr) {}
addend(addend), isAgainstSymbol(kind == AgainstSymbol), isFinal(false),
expr(expr) {}
/// This constructor records a relative relocation with no symbol.
DynamicReloc(RelType type, const InputSectionBase *inputSec,
uint64_t offsetInSec, int64_t addend = 0)
Expand All @@ -447,17 +445,14 @@ class DynamicReloc {

uint64_t getOffset() const;
uint32_t getSymIndex(SymbolTableBaseSection *symTab) const;
bool needsDynSymIndex() const {
assert(kind != Computed && "cannot check kind after computeRaw");
return kind == AgainstSymbol;
}
bool needsDynSymIndex() const { return isAgainstSymbol; }

/// Computes the addend of the dynamic relocation. Note that this is not the
/// same as the #addend member variable as it may also include the symbol
/// address/the address of the corresponding GOT entry/etc.
int64_t computeAddend(Ctx &) const;

void computeRaw(Ctx &, SymbolTableBaseSection *symt);
void finalize(Ctx &, SymbolTableBaseSection *symt);

Symbol *sym;
const InputSectionBase *inputSec;
Expand All @@ -470,7 +465,15 @@ class DynamicReloc {
int64_t addend;

private:
Kind kind;
/// Whether this was constructed with a Kind of AgainstSymbol.
LLVM_PREFERRED_TYPE(bool)
uint8_t isAgainstSymbol : 1;

/// The resulting dynamic relocation has already had its addend computed.
/// Calling computeAddend() is an error.
LLVM_PREFERRED_TYPE(bool)
uint8_t isFinal : 1;

// The kind of expression used to calculate the added (required e.g. for
// relative GOT relocations).
RelExpr expr;
Expand Down
Loading