[lld-macho] Add support for emitting chained fixups
authorDaniel Bertalan <dani@danielbertalan.dev>
Mon, 15 Aug 2022 07:26:28 +0000 (09:26 +0200)
committerDaniel Bertalan <dani@danielbertalan.dev>
Tue, 4 Oct 2022 09:48:45 +0000 (11:48 +0200)
commit0d30e92f59589de44a185c53671b7fe2e83cd2ae
treecae42de35ab6c2c40418eeb10a8d107b7847a50d
parent8344dfab59c9ada81a912f5f68c483e4a04d3cb1
[lld-macho] Add support for emitting chained fixups

This commit adds support for chained fixups, which were introduced in
Apple's late 2020 OS releases. This format replaces the dyld opcodes
used for supplying rebase and binding information, and encodes most of
that data directly in the memory location that will have the fixup
applied.

This reduces binary size and is a requirement for page-in linking, which
will be available starting with macOS 13.

A high-level overview of the format and my implementation can be found
in SyntheticSections.h.

This feature is currently gated behind the `-fixup_chains` flag, and
will be enabled by default for supported targets in a later commit.

Like in ld64, lazy binding is disabled when chained fixups are in use,
and the `-init_offsets` transformation is performed by default.

Differential Revision: https://reviews.llvm.org/D132560
24 files changed:
lld/MachO/Arch/ARM.cpp
lld/MachO/Arch/ARM64.cpp
lld/MachO/Arch/ARM64Common.h
lld/MachO/Arch/ARM64_32.cpp
lld/MachO/Arch/X86_64.cpp
lld/MachO/Config.h
lld/MachO/Driver.cpp
lld/MachO/InputSection.cpp
lld/MachO/InputSection.h
lld/MachO/Options.td
lld/MachO/Symbols.cpp
lld/MachO/Symbols.h
lld/MachO/SyntheticSections.cpp
lld/MachO/SyntheticSections.h
lld/MachO/Target.h
lld/MachO/Writer.cpp
lld/test/MachO/chained-fixups-addend.s [new file with mode: 0644]
lld/test/MachO/chained-fixups-empty.s [new file with mode: 0644]
lld/test/MachO/flat-namespace-interposable.s
lld/test/MachO/invalid/chained-fixups-incompatible.s [new file with mode: 0644]
lld/test/MachO/tlv-dylib.s
lld/test/MachO/weak-binding.s
lld/test/MachO/weak-reference.s
llvm/include/llvm/BinaryFormat/MachO.h