[PATCH] D102076: [lld/mac] Write every weak symbol only once in the output

Nico Weber via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Fri May 7 08:22:25 PDT 2021


thakis created this revision.
thakis added a reviewer: lld-macho.
Herald added a subscriber: kristof.beyls.
Herald added a reviewer: int3.
Herald added a project: lld-macho.
thakis requested review of this revision.

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.


https://reviews.llvm.org/D102076

Files:
  lld/MachO/InputFiles.cpp
  lld/MachO/InputSection.cpp
  lld/MachO/InputSection.h
  lld/MachO/MapFile.cpp
  lld/MachO/SymbolTable.cpp
  lld/MachO/Symbols.h
  lld/MachO/UnwindInfoSection.cpp
  lld/MachO/Writer.cpp
  lld/test/MachO/weak-definition-gc.s

-------------- next part --------------
A non-text attachment was scrubbed...
Name: D102076.343692.patch
Type: text/x-patch
Size: 14870 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20210507/3b809d9b/attachment.bin>


More information about the llvm-commits mailing list