[lld] [lld-macho] Handle InputSection targets in branch range extension logic (PR #126347)
YongKang Zhu via llvm-commits
llvm-commits at lists.llvm.org
Sun Feb 9 11:57:55 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 '" +
----------------
yozhu wrote:
If no symbol at offset 0, could we create a local fake symbol at offset 0, and later after relocation is done skip emitting this created symbol into symbol table?
https://github.com/llvm/llvm-project/pull/126347
More information about the llvm-commits
mailing list