[lld] [lld-macho] Category merger: handle addends when getting symbol at offset (PR #91238)
Kyungwoo Lee via llvm-commits
llvm-commits at lists.llvm.org
Wed May 8 14:37:51 PDT 2024
================
@@ -518,12 +519,32 @@ void ObjcCategoryMerger::collectSectionWriteInfoFromIsec(
Symbol *
ObjcCategoryMerger::tryGetSymbolAtIsecOffset(const ConcatInputSection *isec,
uint32_t offset) {
+ if (!isec)
+ return nullptr;
const Reloc *reloc = isec->getRelocAt(offset);
if (!reloc)
return nullptr;
- return reloc->referent.get<Symbol *>();
+ Symbol *sym = reloc->referent.get<Symbol *>();
+
+ if (reloc->addend) {
+ assert(isa<Defined>(sym) && "Expected defined for non-zero addend");
+ Defined *definedSym = cast<Defined>(sym);
+ sym = tryFindDefinedOnIsec(definedSym->isec(),
+ definedSym->value + reloc->addend);
+ }
+
+ return sym;
+}
+
+Defined *ObjcCategoryMerger::tryFindDefinedOnIsec(const InputSection *isec,
+ uint32_t offset) {
+ for (Defined *sym : isec->symbols)
+ if ((sym->value <= offset) && (sym->value + sym->size > offset))
----------------
kyulee-com wrote:
Basically, I'd like to understand why we have an offset in the middle of symbol. If it's unexpected, we should fix the root-cause. If expected, we should document it.
https://github.com/llvm/llvm-project/pull/91238
More information about the llvm-commits
mailing list