Skip to content

[NFCI][ELF] Introduce explicit Computed state for DynamicReloc #150799

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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
4 changes: 3 additions & 1 deletion lld/ELF/SyntheticSections.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1647,6 +1647,8 @@ uint64_t DynamicReloc::getOffset() const {

int64_t DynamicReloc::computeAddend(Ctx &ctx) const {
switch (kind) {
case Computed:
llvm_unreachable("addend already computed");
case AddendOnly:
assert(sym == nullptr);
return addend;
Expand Down Expand Up @@ -1748,7 +1750,7 @@ void DynamicReloc::computeRaw(Ctx &ctx, SymbolTableBaseSection *symt) {
r_offset = getOffset();
r_sym = getSymIndex(symt);
addend = computeAddend(ctx);
kind = AddendOnly; // Catch errors
kind = Computed; // Catch errors
}

void RelocationBaseSection::computeRels() {
Expand Down
4 changes: 4 additions & 0 deletions lld/ELF/SyntheticSections.h
Original file line number Diff line number Diff line change
Expand Up @@ -419,6 +419,9 @@ 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 does not reference a symbol (#sym must
/// be nullptr) and uses #addend as the result of computeAddend(ctx).
AddendOnly,
Expand Down Expand Up @@ -461,6 +464,7 @@ 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 || kind == AgainstSymbolWithTargetVA;
}

Expand Down
Loading