[PATCH] D77893: WIP [lld] Merge Mach-O input sections

Jez Ng via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Thu Apr 16 12:51:01 PDT 2020


int3 added inline comments.


================
Comment at: lld/MachO/OutputSection.cpp:20
+uint64_t OutputSection::getFileOffset() const {
+  return parent->fileOff + addr - parent->firstSection()->addr;
+}
----------------
int3 wrote:
> smeenai wrote:
> > Ktwu wrote:
> > > smeenai wrote:
> > > > What's this computation doing?
> > > It's copying what InputSection did to calculate its file offset. I didn't entirely comprehend this math tbh.
> > Okay, this makes sense.
> The parent segment's start address is defined as the address of the first section it contains. So `addr - parent->firstSection()->addr` computes the section's offset within the segment. Maybe we don't need this any more if we have `outSecOff` (going to investigate)
Oh, outSecOff is for the InputSection's offset within the OutputSection, but this computation is for the OutputSection's offset within its segment. So having `outSecOff` doesn't impact this. That said the ELF implementation seems to have an explicit `OutputSection::offset` field, though I'm not sure what populates it... but I think this scheme of computing the offset from the address is fine for now


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D77893/new/

https://reviews.llvm.org/D77893





More information about the llvm-commits mailing list