[lld/mac] Add support for -flat_namespace
authorNico Weber <thakis@chromium.org>
Mon, 1 Mar 2021 20:25:10 +0000 (15:25 -0500)
committerNico Weber <thakis@chromium.org>
Mon, 1 Mar 2021 20:25:10 +0000 (15:25 -0500)
commit8174f33dc9bf34e1cde57931e2e028bd4d49c98e
tree0f1e754828e5d20781e0247d301c6ad3693a9c3b
parent3e6b6cee00819d256f30e84aec7ae634e0725534
[lld/mac] Add support for -flat_namespace

-flat_namespace makes lld emit binaries that use name lookup that's more in
line with other POSIX systems: Instead of looking up symbols as (dylib,name)
pairs by dyld, they're instead looked up just by name.

-flat_namespace has three effects:

1. MH_TWOLEVEL and MH_NNOUNDEFS are no longer set in the Mach-O header
2. All symbols use BIND_SPECIAL_DYLIB_FLAT_LOOKUP as ordinal
3. When a dylib is added to the link, its dependent dylibs are also added,
   so that lld can verify that no undefined symbols remain at the end of
   a link with -flat_namespace. These transitive dylibs are added for symbol
   resolution, but they are not emitted in LC_LOAD_COMMANDs.

-undefined with -flat_namespace still isn't implemented. Before this change,
it was impossible to hit that combination because -flat_namespace caused a
diagnostic. Now that it no longer does, emit a dedicated temporary diagnostic
when both flags are used.

Differential Revision: https://reviews.llvm.org/D97641
lld/MachO/Driver.cpp
lld/MachO/InputFiles.cpp
lld/MachO/Options.td
lld/MachO/SymbolTable.cpp
lld/MachO/SyntheticSections.cpp
lld/test/MachO/flat-namespace.s [new file with mode: 0644]
lld/test/MachO/header.s