Skip to content

Conversation

@jrtc27
Copy link
Collaborator

@jrtc27 jrtc27 commented Dec 8, 2025

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.

Created using spr 1.3.5
@llvmbot
Copy link
Member

llvmbot commented Dec 8, 2025

@llvm/pr-subscribers-lld-elf

Author: Jessica Clarke (jrtc27)

Changes

This is just a copy of InputSectionBase::addReloc, so we can just
forward to that rathe than poking into the internals. Whilst here, move
the implementation to the header so it can be inlined.


Full diff: https://github.com/llvm/llvm-project/pull/171177.diff

2 Files Affected:

  • (modified) lld/ELF/SyntheticSections.cpp (-1)
  • (modified) lld/ELF/SyntheticSections.h (+1-1)
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 e01a5ad8abc60..79fa8140c2498 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);

@llvmbot
Copy link
Member

llvmbot commented Dec 8, 2025

@llvm/pr-subscribers-lld

Author: Jessica Clarke (jrtc27)

Changes

This is just a copy of InputSectionBase::addReloc, so we can just
forward to that rathe than poking into the internals. Whilst here, move
the implementation to the header so it can be inlined.


Full diff: https://github.com/llvm/llvm-project/pull/171177.diff

2 Files Affected:

  • (modified) lld/ELF/SyntheticSections.cpp (-1)
  • (modified) lld/ELF/SyntheticSections.h (+1-1)
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 e01a5ad8abc60..79fa8140c2498 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);

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants