[lld-macho][nfc] Refactor in preparation for 32-bit support
authorJez Ng <jezng@fb.com>
Fri, 2 Apr 2021 22:46:18 +0000 (18:46 -0400)
committerJez Ng <jezng@fb.com>
Fri, 2 Apr 2021 22:46:39 +0000 (18:46 -0400)
commit817d98d84186c3508ba7a9a58202e616b23f344a
tree9a8596357f07e0abb2bbaca6bd15a41974aeacd5
parent8156d899ab2f31d7c8fa012ca32530adcae228b0
[lld-macho][nfc] Refactor in preparation for 32-bit support

The main challenge was handling the different on-disk structures (e.g.
`mach_header` vs `mach_header_64`). I tried to strike a balance between
sprinkling `target->wordSize == 8` checks everywhere (branchy = slow, and ugly)
and templatizing everything (causes code bloat, also ugly). I think I struck a
decent balance by judicious use of type erasure.

Note that LLD-ELF has a similar architecture, though it seems to use more templating.

Linking chromium_framework takes about the same time before and after this
change:

      N           Min           Max        Median           Avg        Stddev
  x  20          4.52          4.67         4.595        4.5945   0.044423204
  +  20           4.5          4.71         4.575         4.582   0.056344803
  No difference proven at 95.0% confidence

Reviewed By: #lld-macho, oontvoo

Differential Revision: https://reviews.llvm.org/D99633
16 files changed:
lld/MachO/Arch/ARM64.cpp
lld/MachO/Arch/X86_64.cpp
lld/MachO/Driver.cpp
lld/MachO/DriverUtils.cpp
lld/MachO/InputFiles.cpp
lld/MachO/InputFiles.h
lld/MachO/InputSection.cpp
lld/MachO/LTO.cpp
lld/MachO/MachOStructs.h
lld/MachO/ObjC.cpp
lld/MachO/SyntheticSections.cpp
lld/MachO/SyntheticSections.h
lld/MachO/Target.h
lld/MachO/UnwindInfoSection.cpp
lld/MachO/Writer.cpp
lld/MachO/Writer.h