[lld] [lld-macho] Handle InputSection targets in branch range extension logic (PR #126347)
via llvm-commits
llvm-commits at lists.llvm.org
Sun Feb 9 19:30:30 PST 2025
================
@@ -116,6 +116,30 @@ void ConcatOutputSection::addInput(ConcatInputSection *input) {
DenseMap<Symbol *, ThunkInfo> lld::macho::thunkMap;
+// Returns the target Symbol that a relocation refers to.
+// A Reloc can refer to either a Symbol directly, or to an InputSection.
+// For InputSection referents, we return the first Symbol at offset 0.
+// This conversion is necessary because the thunk generation algorithm
+// can only handle Symbols as branch targets, not InputSections.
+static Symbol *getReferentSymbol(const Reloc &r) {
+ if (auto *sym = r.referent.dyn_cast<Symbol *>()) {
+ return sym;
+ } else if (auto *isec = r.referent.dyn_cast<InputSection *>()) {
+ // Use the first symbol at offset 0 in the InputSection
+ for (Defined *sym : isec->symbols) {
+ if (sym->value == 0) {
+ return sym;
+ }
+ }
+ // Handle absence of suitable symbol
+ warn("Branch-range extension: No symbol at offset 0 in InputSection '" +
----------------
alx32 wrote:
We could but I haven't encountered this scenario yet so we might not want to add the extra complexity without a way of testing it.
https://github.com/llvm/llvm-project/pull/126347
More information about the llvm-commits
mailing list