[lld-macho] Implement -headerpad
authorJez Ng <jezng@fb.com>
Thu, 30 Jul 2020 21:28:45 +0000 (14:28 -0700)
committerJez Ng <jezng@fb.com>
Thu, 30 Jul 2020 21:29:31 +0000 (14:29 -0700)
commit22e6648a1834aa6680064eaf83e1e051a7248e17
treed40dc2d2e5a6bec34d5f5bc02e537179b02e1622
parent3587de22819869a2925994d8bd75fa1386464660
[lld-macho] Implement -headerpad

Tools like `install_name_tool` and `codesign` may modify the Mach-O
header and increase its size. The linker has to provide padding to make this
possible. This diff does that, plus sets its default value to 32 bytes (which
is what ld64 does).

Unlike ld64, however, we lay out our sections *exactly* `-headerpad` bytes from
the header, whereas ld64 just treats the padding requirement as a lower bound.
ld64 actually starts laying out the non-header sections in the __TEXT segment
from the end of the (page-aligned) segment rather than the front, so its
binaries typically have more than `-headerpad` bytes of actual padding.
We should consider implementing the same alignment behavior.

Reviewed By: #lld-macho, compnerd

Differential Revision: https://reviews.llvm.org/D84714
lld/Common/Args.cpp
lld/MachO/Config.h
lld/MachO/Driver.cpp
lld/MachO/Options.td
lld/MachO/SyntheticSections.cpp
lld/include/lld/Common/Args.h
lld/test/MachO/headerpad.s [new file with mode: 0644]
lld/test/MachO/local-got.s
lld/test/MachO/relocations.s