llvm-capstone/lld/MachO
Nico Weber a5645513db [lld/mac] Implement -dead_strip
Also adds support for live_support sections, no_dead_strip sections,
.no_dead_strip symbols.

Chromium Framework 345MB unstripped -> 250MB stripped
(vs 290MB unstripped -> 236M stripped with ld64).

Doing dead stripping is a bit faster than not, because so much less
data needs to be processed:

    % ministat lld_*
    x lld_nostrip.txt
    + lld_strip.txt
        N           Min           Max        Median           Avg        Stddev
    x  10      3.929414       4.07692     4.0269079     4.0089678   0.044214794
    +  10     3.8129408     3.9025559     3.8670411     3.8642573   0.024779651
    Difference at 95.0% confidence
            -0.144711 +/- 0.0336749
            -3.60967% +/- 0.839989%
            (Student's t, pooled s = 0.0358398)

This interacts with many parts of the linker. I tried to add test coverage
for all added `isLive()` checks, so that some test will fail if any of them
is removed. I checked that the test expectations for the most part match
ld64's behavior (except for live-support-iterations.s, see the comment
in the test). Interacts with:
- debug info
- export tries
- import opcodes
- flags like -exported_symbol(s_list)
- -U / dynamic_lookup
- mod_init_funcs, mod_term_funcs
- weak symbol handling
- unwind info
- stubs
- map files
- -sectcreate
- undefined, dylib, common, defined (both absolute and normal) symbols

It's possible it interacts with more features I didn't think of,
of course.

I also did some manual testing:
- check-llvm check-clang check-lld work with lld with this patch
  as host linker and -dead_strip enabled
- Chromium still starts
- Chromium's base_unittests still pass, including unwind tests

Implemenation-wise, this is InputSection-based, so it'll work for
object files with .subsections_via_symbols (which includes all
object files generated by clang). I first based this on the COFF
implementation, but later realized that things are more similar to ELF.
I think it'd be good to refactor MarkLive.cpp to look more like the ELF
part at some point, but I'd like to get a working state checked in first.

Mechanical parts:
- Rename canOmitFromOutput to wasCoalesced (no behavior change)
  since it really is for weak coalesced symbols
- Add noDeadStrip to Defined, corresponding to N_NO_DEAD_STRIP
  (`.no_dead_strip` in asm)

Fixes PR49276.

Differential Revision: https://reviews.llvm.org/D103324
2021-06-02 11:09:26 -04:00
..
Arch
CMakeLists.txt [lld/mac] Implement -dead_strip 2021-06-02 11:09:26 -04:00
ConcatOutputSection.cpp [lld/mac] Implement -dead_strip 2021-06-02 11:09:26 -04:00
ConcatOutputSection.h [lld-macho][nfc] Rename MergedOutputSection to ConcatOutputSection 2021-05-25 14:58:29 -04:00
Config.h [lld/mac] Implement -dead_strip 2021-06-02 11:09:26 -04:00
Driver.cpp [lld/mac] Implement -dead_strip 2021-06-02 11:09:26 -04:00
Driver.h [lld-macho][nfc] Remove unnecessary use of Optional<T*> 2021-06-01 18:35:31 -04:00
DriverUtils.cpp [lld/mac] Address review feedback and improve a comment 2021-06-02 10:54:53 -04:00
Dwarf.cpp
Dwarf.h
ExportTrie.cpp
ExportTrie.h
InputFiles.cpp [lld/mac] Implement -dead_strip 2021-06-02 11:09:26 -04:00
InputFiles.h [lld/mac] Implement -needed_framework, -needed_library, -needed-l 2021-06-02 11:06:42 -04:00
InputSection.cpp [lld][MachO] Adjust isCodeSection signature 2021-05-17 22:09:47 -07:00
InputSection.h [lld/mac] Implement -dead_strip 2021-06-02 11:09:26 -04:00
LTO.cpp
LTO.h
MachOStructs.h
MapFile.cpp [lld/mac] Implement -dead_strip 2021-06-02 11:09:26 -04:00
MapFile.h
MarkLive.cpp [lld/mac] Implement -dead_strip 2021-06-02 11:09:26 -04:00
MarkLive.h [lld/mac] Implement -dead_strip 2021-06-02 11:09:26 -04:00
ObjC.cpp
ObjC.h
Options.td [lld/mac] Implement -dead_strip 2021-06-02 11:09:26 -04:00
OutputSection.cpp
OutputSection.h [lld-macho][nfc] Sort OutputSections based on explicit order of command-line inputs 2021-05-25 14:58:29 -04:00
OutputSegment.cpp [lld-macho][nfc] Remove unnecessary parameterization of section sort 2021-05-25 14:58:30 -04:00
OutputSegment.h [lld-macho][nfc] Remove unnecessary parameterization of section sort 2021-05-25 14:58:30 -04:00
Relocations.cpp
Relocations.h
Symbols.cpp [lld/mac] Implement -dead_strip 2021-06-02 11:09:26 -04:00
Symbols.h [lld/mac] Implement -dead_strip 2021-06-02 11:09:26 -04:00
SymbolTable.cpp [lld/mac] Implement -dead_strip 2021-06-02 11:09:26 -04:00
SymbolTable.h [lld/mac] Implement -dead_strip 2021-06-02 11:09:26 -04:00
SyntheticSections.cpp [lld/mac] Implement -dead_strip 2021-06-02 11:09:26 -04:00
SyntheticSections.h [lld/mac] Implement -dead_strip 2021-06-02 11:09:26 -04:00
Target.cpp
Target.h
UnwindInfoSection.cpp [lld/mac] Implement -dead_strip 2021-06-02 11:09:26 -04:00
UnwindInfoSection.h [lld/mac] Implement -dead_strip 2021-06-02 11:09:26 -04:00
Writer.cpp [lld/mac] Implement -dead_strip 2021-06-02 11:09:26 -04:00
Writer.h