[PATCH] D75382: [lld] Initial commit for new Mach-O backend

Jez Ng via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Tue Mar 3 10:56:29 PST 2020


int3 marked an inline comment as done.
int3 added inline comments.


================
Comment at: lld/MachO/InputFiles.cpp:37
+// a Mach-O relocation has a bit indicating whether it refers a symbol or a
+// location within the same section. R_SCATTERED is that bit.
+//
----------------
pcc wrote:
> int3 wrote:
> > pcc wrote:
> > > int3 wrote:
> > > > pcc wrote:
> > > > > I don't believe that this is true in general. In the case where R_SCATTERED is false, bit 27 of r_word1 (the `extern` bit) indicates whether the relocation refers to a symbol or a section address. You can see this by grepping for `rExtern` in the existing lld, and seeing how relocations with/without the bit are handled (e.g. http://llvm-cs.pcc.me.uk/tools/lld/lib/ReaderWriter/MachO/ArchHandler_arm64.cpp#434 ).
> > > > This was originally written by @ruiu, but I *think* what this means is that R_SCATTERED determines whether the relocation is referring to something within the same section, and not whether it's referring to a symbol or a section. I'll rephrase things...
> > > I think that both non-R_SCATTERED and R_SCATTERED can refer to locations within different sections. You can see this in the implementation of "atomByAddr" in the old linker:
> > > http://llvm-cs.pcc.me.uk/tools/lld/lib/ReaderWriter/MachO/MachONormalizedFileToAtoms.cpp#527
> > > which contains code to look up potentially different sections.
> > > 
> > > This function is called e.g. here:
> > > http://llvm-cs.pcc.me.uk/tools/lld/lib/ReaderWriter/MachO/ArchHandler_arm64.cpp#444
> > > 
> > > and the "symbol" field (which becomes the first argument of that function) is filled in here:
> > > http://llvm-cs.pcc.me.uk/tools/lld/lib/ReaderWriter/MachO/MachONormalizedFileBinaryUtils.h#144
> > > (and code below to handle the non-R_SCATTERED case).
> > > 
> > > I would summarise the situation as being:
> > > - non-scattered relocations may refer to either an external symbol or a location within a (same or different) section (index is specified in relocation, or inferred from address if 0)
> > > - scattered relocations may only refer to a location within a (same or different) section (index is inferred from address).
> > Thanks for the pointers! That makes sense. One question:
> > 
> > > section (index is specified in relocation, or inferred from address if 0)
> > 
> > Can a valid relocation actually have 0 as the section index? `Relocation::value` for a non-scattered relocation is always zero, so I'm not sure what address we could infer things from...
> In this case, the address that we infer things from is stored inline in the section data (see `getImplicitAddend` here, or the second argument to `atomByAddr` in the old linker).
I see, thanks!


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D75382





More information about the llvm-commits mailing list