[lld-macho] -flat_namespace for dylibs should make all externs interposable
authorJez Ng <jezng@fb.com>
Tue, 15 Mar 2022 01:51:15 +0000 (21:51 -0400)
committerJez Ng <jezng@fb.com>
Tue, 15 Mar 2022 02:18:32 +0000 (22:18 -0400)
commitceff23c6e39118fbbfb053e70d786fad40987c5b
treef03b8f930952cf0443ef963de59612401425e5e2
parent7f3ddf8443272626186c7d1408737d2d72fd8b00
[lld-macho] -flat_namespace for dylibs should make all externs interposable

All references to interposable symbols can be redirected at runtime to
point to a different symbol definition (with the same name). For
example, if both dylib A and B define symbol _foo, and we load A before
B at runtime, then all references to _foo within dylib B will point to
the definition in dylib A.

ld64 makes all extern symbols interposable when linking with
`-flat_namespace`.

TODO 1: Support `-interposable` and `-interposable_list`, which should
just be a matter of parsing those CLI flags and setting the
`Defined::interposable` bit.

TODO 2: Set Reloc::FinalDefinitionInLinkageUnit correctly with this info
(we are currently not setting it at all, so we're erring on the
conservative side, but we should help the LTO backend generate more
optimal code.)

Reviewed By: modimo, MaskRay

Differential Revision: https://reviews.llvm.org/D119294
lld/MachO/SymbolTable.cpp
lld/MachO/Symbols.cpp
lld/MachO/Symbols.h
lld/MachO/SyntheticSections.cpp
lld/MachO/Writer.cpp
lld/test/MachO/flat-namespace-dysyms.s [new file with mode: 0644]
lld/test/MachO/flat-namespace-interposable.s [new file with mode: 0644]
lld/test/MachO/flat-namespace.s [deleted file]