[lld] d48eb71 - [NFC][ELF] Don't reimplement addReloc in GotSection::addConstant
via llvm-commits
llvm-commits at lists.llvm.org
Wed Dec 24 02:58:08 PST 2025
Author: Jessica Clarke
Date: 2025-12-24T10:58:05Z
New Revision: d48eb719d240dc93150ca11e29e6c3b7353fddc9
URL: https://github.com/llvm/llvm-project/commit/d48eb719d240dc93150ca11e29e6c3b7353fddc9
DIFF: https://github.com/llvm/llvm-project/commit/d48eb719d240dc93150ca11e29e6c3b7353fddc9.diff
LOG: [NFC][ELF] Don't reimplement addReloc in GotSection::addConstant
This is just a copy of InputSectionBase::addReloc, so we can just
forward to that rather than poking into the internals. Whilst here, move
the implementation to the header so it can be inlined.
This is helpful downstream for CHERI, as static relocations to emit an
entire capability (whether for a relative relocation or for an undefined
weak symbol) need to be split in two, one per word, as getRelocTargetVA
only returns a uint64_t. Having a single function that pushes to
InputSectionBase's static relocations array centralises that so the
outside world can pretend it's a singular relocation, and internally it
gets mapped to the pair.
Reviewers: MaskRay
Reviewed By: MaskRay
Pull Request: https://github.com/llvm/llvm-project/pull/171177
Added:
Modified:
lld/ELF/SyntheticSections.cpp
lld/ELF/SyntheticSections.h
Removed:
################################################################################
diff --git a/lld/ELF/SyntheticSections.cpp b/lld/ELF/SyntheticSections.cpp
index 1e9d44fa37bea..d6e214f9d0f48 100644
--- a/lld/ELF/SyntheticSections.cpp
+++ b/lld/ELF/SyntheticSections.cpp
@@ -674,7 +674,6 @@ GotSection::GotSection(Ctx &ctx)
numEntries = ctx.target->gotHeaderEntriesNum;
}
-void GotSection::addConstant(const Relocation &r) { relocations.push_back(r); }
void GotSection::addEntry(const Symbol &sym) {
assert(sym.auxIdx == ctx.symAux.size() - 1);
ctx.symAux.back().gotIdx = numEntries++;
diff --git a/lld/ELF/SyntheticSections.h b/lld/ELF/SyntheticSections.h
index 16bdda8ef75bb..9e6ae59869092 100644
--- a/lld/ELF/SyntheticSections.h
+++ b/lld/ELF/SyntheticSections.h
@@ -113,7 +113,7 @@ class GotSection final : public SyntheticSection {
bool isNeeded() const override;
void writeTo(uint8_t *buf) override;
- void addConstant(const Relocation &r);
+ void addConstant(const Relocation &r) { addReloc(r); }
void addEntry(const Symbol &sym);
void addAuthEntry(const Symbol &sym);
bool addTlsDescEntry(const Symbol &sym);
More information about the llvm-commits
mailing list