[PATCH] D97521: [lld/mac] Add some support for dynamic lookup symbols, and implement -U

Nico Weber via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Thu Feb 25 18:54:19 PST 2021


thakis created this revision.
thakis added a reviewer: lld-macho.
Herald added a subscriber: dang.
Herald added a reviewer: int3.
Herald added a project: lld-macho.
thakis requested review of this revision.

Dynamic lookup symbols are symbols that work like dynamic symbols
in ELF: They're not bound to a dylib like normal Mach-O twolevel lookup
symbols, but they live in a global pool and dyld resolves them against
exported symbols from all loaded dylibs.

This adds support for dynamical lookup symbols to lld/mac. They are
represented as DylibSymbols with file set to nullptr.

This also uses this support to implement the -U flag, which makes
a specific symbol that's undefined at the end of the link a
dynamic lookup symbol.

For -U, it'd be sufficient to just to a pass over remaining undefined symbols
at the end of the link and to replace them with dynamic lookup symbols then.
But I'd like to use this code to implement flat_namespace too, and that will
require real support for resolving dynamic lookup symbols in SymbolTable. So
this patch adds this now already.

While writing tests for this, I noticed that we didn't set N_WEAK_DEF in the
symbol table for DylibSymbols, so this fixes that too.

---

In addition to -flat_namespace, this will also be useful for implementing
`-undefined dynamic_lookup`, and, with `-flat_namespace`, `-undefined warning`
and `-undefined suppress`  – but for these, the pass at the end would've sufficed too.

This isn't 100% done, there are a few XXXs left, but I'm out of evening, and what's
left is pretty basic. So I'm sending it out now for better timezone overlap :)


https://reviews.llvm.org/D97521

Files:
  lld/MachO/Driver.cpp
  lld/MachO/Options.td
  lld/MachO/SymbolTable.cpp
  lld/MachO/SymbolTable.h
  lld/MachO/Symbols.h
  lld/MachO/SyntheticSections.cpp
  lld/MachO/Writer.cpp
  lld/test/MachO/U_dynamic_lookup.s

-------------- next part --------------
A non-text attachment was scrubbed...
Name: D97521.326579.patch
Type: text/x-patch
Size: 11574 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20210226/00635cf5/attachment-0001.bin>


More information about the llvm-commits mailing list