llvm-project/lld/MachO
Nico Weber d5a70db193 [lld/mac] Write every weak symbol only once in the output
Before this, if an inline function was defined in several input files,
lld would write each copy of the inline function the output. With this
patch, it only writes one copy.

Reduces the size of Chromium Framework from 378MB to 345MB (compared
to 290MB linked with ld64, which also does dead-stripping, which we
don't do yet), and makes linking it faster:

        N           Min           Max        Median           Avg        Stddev
    x  10     3.9957051     4.3496981     4.1411121      4.156837    0.10092097
    +  10      3.908154      4.169318     3.9712729     3.9846753   0.075773012
    Difference at 95.0% confidence
            -0.172162 +/- 0.083847
            -4.14165% +/- 2.01709%
            (Student's t, pooled s = 0.0892373)

Implementation-wise, when merging two weak symbols, this sets a
"canOmitFromOutput" on the InputSection belonging to the weak symbol not put in
the symbol table. We then don't write InputSections that have this set, as long
as they are not referenced from other symbols. (This happens e.g. for object
files that don't set .subsections_via_symbols or that use .alt_entry.)

Some restrictions:
- not yet done for bitcode inputs
- no "comdat" handling (`kindNoneGroupSubordinate*` in ld64) --
  Frame Descriptor Entries (FDEs), Language Specific Data Areas (LSDAs)
  (that is, catch block unwind information) and Personality Routines
  associated with weak functions still not stripped. This is wasteful,
  but harmless.
- However, this does strip weaks from __unwind_info (which is needed for
  correctness and not just for size)
- This nopes out on InputSections that are referenced form more than
  one symbol (eg from .alt_entry) for now

Things that work based on symbols Just Work:
- map files (change in MapFile.cpp is no-op and not needed; I just
  found it a bit more explicit)
- exports

Things that work with inputSections need to explicitly check if
an inputSection is written (e.g. unwind info).

This patch is useful in itself, but it's also likely also a useful foundation
for dead_strip.

I used to have a "canoncialRepresentative" pointer on InputSection instead of
just the bool, which would be handy for ICF too. But I ended up not needing it
for this patch, so I removed that again for now.

Differential Revision: https://reviews.llvm.org/D102076
2021-05-07 17:11:40 -04:00
..
Arch [lld-macho] Try to unbreak build 2021-05-05 15:47:14 -04:00
CMakeLists.txt [lld-macho] Initial scaffolding for ARM32 support 2021-04-30 16:17:25 -04:00
Config.h [lld-macho] Implement builtin section renaming 2021-05-03 21:26:51 -07:00
Driver.cpp [lld-macho] Have --reproduce account for path rerooting 2021-05-05 14:41:01 -04:00
Driver.h [lld-macho] Have --reproduce account for path rerooting 2021-05-05 14:41:01 -04:00
DriverUtils.cpp [lld-macho] Have --reproduce account for path rerooting 2021-05-05 14:41:01 -04:00
Dwarf.cpp [lld-macho][NFC] define more strings in section_names:: and segment_names:: 2021-04-27 17:48:45 -07:00
Dwarf.h [lld-macho] Emit STABS symbols for debugging, and drop debug sections 2020-12-01 15:05:20 -08:00
ExportTrie.cpp [lld-macho][NFC] add const to pointer/reference induction variables of range-based for loops 2021-03-10 12:07:31 -08:00
ExportTrie.h [lld-macho] Export trie addresses should be relative to the image base 2020-09-20 20:43:15 -07:00
InputFiles.cpp [lld/mac] Write every weak symbol only once in the output 2021-05-07 17:11:40 -04:00
InputFiles.h [lld-macho] Support loading of zippered dylibs 2021-05-06 11:19:40 -04:00
InputSection.cpp [lld/mac] Write every weak symbol only once in the output 2021-05-07 17:11:40 -04:00
InputSection.h [lld/mac] Write every weak symbol only once in the output 2021-05-07 17:11:40 -04:00
LTO.cpp [lld-macho][nfc] Add accessors for commonly-used PlatformInfo fields 2021-04-21 15:43:56 -04:00
LTO.h [lld-macho] Add very basic support for LTO 2020-11-10 12:19:28 -08:00
MachOStructs.h [lld-macho] Add support for arm64_32 2021-04-15 21:16:33 -04:00
MapFile.cpp [lld/mac] Write every weak symbol only once in the output 2021-05-07 17:11:40 -04:00
MapFile.h [lld-macho] implement options -map 2021-03-18 10:39:19 -04:00
MergedOutputSection.cpp [lld-macho] Implement builtin section renaming 2021-05-03 21:26:51 -07:00
MergedOutputSection.h [lld-macho] Implement builtin section renaming 2021-05-03 21:26:51 -07:00
ObjC.cpp [lld-macho] De-templatize mach_header operations 2021-05-03 18:31:23 -04:00
ObjC.h [lld-macho] Implement -ObjC 2020-08-26 19:20:55 -07:00
Options.td [lld-macho] Implement builtin section renaming 2021-05-03 21:26:51 -07:00
OutputSection.cpp [lld-macho] Refactor segment/section creation, sorting, and merging 2020-06-21 17:13:59 -07:00
OutputSection.h [lld-macho] Initial groundwork for -bitcode_bundle 2021-04-16 16:47:14 -04:00
OutputSegment.cpp [lld-macho][nfc] Add accessors for commonly-used PlatformInfo fields 2021-04-21 15:43:56 -04:00
OutputSegment.h [lld-macho][NFC] define more strings in section_names:: and segment_names:: 2021-04-27 17:48:45 -07:00
Relocations.cpp [lld-macho][nfc] Remove DYSYM8 reloc attribute 2021-04-09 19:48:08 -04:00
Relocations.h [lld-macho] Add 32-bit compact unwind support 2021-04-15 21:16:33 -04:00
SymbolTable.cpp [lld/mac] Write every weak symbol only once in the output 2021-05-07 17:11:40 -04:00
SymbolTable.h [lld-macho] Parse & emit the N_ARM_THUMB_DEF symbol flag 2021-04-30 16:17:26 -04:00
Symbols.cpp [lld-macho] clang-format cleanup 2021-04-06 14:26:13 -04:00
Symbols.h [lld/mac] Write every weak symbol only once in the output 2021-05-07 17:11:40 -04:00
SyntheticSections.cpp [lld-macho] De-templatize mach_header operations 2021-05-03 18:31:23 -04:00
SyntheticSections.h [lld-macho] De-templatize mach_header operations 2021-05-03 18:31:23 -04:00
Target.cpp [lld-macho][nfc] Create Relocations.{h,cpp} for relocation-specific code 2021-03-11 13:28:09 -05:00
Target.h [lld-macho] De-templatize mach_header operations 2021-05-03 18:31:23 -04:00
UnwindInfoSection.cpp [lld/mac] Write every weak symbol only once in the output 2021-05-07 17:11:40 -04:00
UnwindInfoSection.h [lld-macho] Add 32-bit compact unwind support 2021-04-15 21:16:33 -04:00
Writer.cpp [lld/mac] Write every weak symbol only once in the output 2021-05-07 17:11:40 -04:00
Writer.h [lld-macho] De-templatize mach_header operations 2021-05-03 18:31:23 -04:00