[PATCH] D78270: [lld-macho] Support calls to functions in dylibs

Jez Ng via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Wed Apr 15 22:01:35 PDT 2020


int3 created this revision.
int3 added reviewers: ruiu, pcc, MaskRay, smeenai, alexshap, gkm, Ktwu, christylee.
Herald added a project: LLVM.
Herald added a subscriber: llvm-commits.

This diff implements lazy symbol binding -- very similar to the PLT
mechanism in ELF.

ELF's .plt section is broken up into two sections in Mach-O:
StubsSection and StubHelperSection. Calls to functions in dylibs will
end up calling into StubsSection, which contains indirect jumps to
addresses stored in the LazyPointerSection (the counterpart to ELF's
.plt.got).

Initially, the LazyPointerSection contains addresses that point into one
of the entry points in the middle of the StubHelperSection. The code in
StubHelperSection will push on the stack an offset into the
LazyBindingSection. The push is followed by a jump to the beginning of
the StubHelperSection (similar to PLT0), which then calls into
dyld_stub_binder. dyld_stub_binder is a non-lazily bound symbol, so this
call looks it up in the GOT.

The stub binder will look up the bind opcodes in the LazyBindingSection
at the given offset. The bind opcodes will tell the binder to update the
address in the LazyPointerSection to point to the symbol, so that
subsequent calls don't have to redo the symbol resolution. The binder
will then jump to the resolved symbol.

Depends on D78269 <https://reviews.llvm.org/D78269>.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D78270

Files:
  lld/MachO/Arch/X86_64.cpp
  lld/MachO/Driver.cpp
  lld/MachO/InputFiles.cpp
  lld/MachO/InputFiles.h
  lld/MachO/InputSection.cpp
  lld/MachO/OutputSegment.h
  lld/MachO/Symbols.h
  lld/MachO/SyntheticSections.cpp
  lld/MachO/SyntheticSections.h
  lld/MachO/Target.h
  lld/MachO/Writer.cpp
  lld/test/MachO/Inputs/libgoodbye.s
  lld/test/MachO/Inputs/libhello.s
  lld/test/MachO/dylink-lazy.s

-------------- next part --------------
A non-text attachment was scrubbed...
Name: D78270.257955.patch
Type: text/x-patch
Size: 26923 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20200416/3a7b0230/attachment-0001.bin>


More information about the llvm-commits mailing list