[lld] [ELF][NFC] Allow non-GotSection for addAddendOnlyRelocIfNonPreemptible (PR #104228)

Jessica Clarke via llvm-commits llvm-commits at lists.llvm.org
Wed Aug 14 13:17:52 PDT 2024


https://github.com/jrtc27 created https://github.com/llvm/llvm-project/pull/104228

This was done as an afterthought in c3c9e4531287 without justification.
Nothing relies on it being a specific kind of section, and downstream in
CHERI LLVM we pass a non-GotSection to this function. Thus revert this
overly-restrictive change and allow downstreams to pass other section
types again.

This partially reverts commit c3c9e45312874ff890723f54cabfd41e43b2dbc4.


>From d1c0e479575b4e505fb7c6f6bef6aef9e8f0900a Mon Sep 17 00:00:00 2001
From: Jessica Clarke <jrtc27 at jrtc27.com>
Date: Wed, 14 Aug 2024 21:10:03 +0100
Subject: [PATCH] [ELF][NFC] Allow non-GotSection for
 addAddendOnlyRelocIfNonPreemptible

This was done as an afterthought in c3c9e4531287 without justification.
Nothing relies on it being a specific kind of section, and downstream in
CHERI LLVM we pass a non-GotSection to this function. Thus revert this
overly-restrictive change and allow downstreams to pass other section
types again.

This partially reverts commit c3c9e45312874ff890723f54cabfd41e43b2dbc4.
---
 lld/ELF/SyntheticSections.cpp | 6 +++---
 lld/ELF/SyntheticSections.h   | 3 ++-
 2 files changed, 5 insertions(+), 4 deletions(-)

diff --git a/lld/ELF/SyntheticSections.cpp b/lld/ELF/SyntheticSections.cpp
index c27ab2b67dc2b..7d26fa9aea74a 100644
--- a/lld/ELF/SyntheticSections.cpp
+++ b/lld/ELF/SyntheticSections.cpp
@@ -1639,14 +1639,14 @@ void RelocationBaseSection::addSymbolReloc(
 }
 
 void RelocationBaseSection::addAddendOnlyRelocIfNonPreemptible(
-    RelType dynType, GotSection &sec, uint64_t offsetInSec, Symbol &sym,
+    RelType dynType, InputSectionBase &isec, uint64_t offsetInSec, Symbol &sym,
     RelType addendRelType) {
   // No need to write an addend to the section for preemptible symbols.
   if (sym.isPreemptible)
-    addReloc({dynType, &sec, offsetInSec, DynamicReloc::AgainstSymbol, sym, 0,
+    addReloc({dynType, &isec, offsetInSec, DynamicReloc::AgainstSymbol, sym, 0,
               R_ABS});
   else
-    addReloc(DynamicReloc::AddendOnlyWithTargetVA, dynType, sec, offsetInSec,
+    addReloc(DynamicReloc::AddendOnlyWithTargetVA, dynType, isec, offsetInSec,
              sym, 0, R_ABS, addendRelType);
 }
 
diff --git a/lld/ELF/SyntheticSections.h b/lld/ELF/SyntheticSections.h
index d4169e1e1acaf..43eb82cbb3e28 100644
--- a/lld/ELF/SyntheticSections.h
+++ b/lld/ELF/SyntheticSections.h
@@ -523,7 +523,8 @@ class RelocationBaseSection : public SyntheticSection {
   }
   /// Add a dynamic relocation using the target address of \p sym as the addend
   /// if \p sym is non-preemptible. Otherwise add a relocation against \p sym.
-  void addAddendOnlyRelocIfNonPreemptible(RelType dynType, GotSection &sec,
+  void addAddendOnlyRelocIfNonPreemptible(RelType dynType,
+                                          InputSectionBase &isec,
                                           uint64_t offsetInSec, Symbol &sym,
                                           RelType addendRelType);
   template <bool shard = false>



More information about the llvm-commits mailing list