[lld] [lld-macho] Category merger: handle addends when getting symbol at offset (PR #91238)
via llvm-commits
llvm-commits at lists.llvm.org
Thu Jun 20 18:40:26 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))
----------------
alx32 wrote:
In the test, the addend comes from:
```
__CATEGORY__TtC11SimpleClass11SimpleClass_$_SimpleClass:
[...]
.quad _$s11SimpleClassAACMf+24 // <---- Addend = 24
```
https://github.com/llvm/llvm-project/pull/91238
More information about the llvm-commits
mailing list