[lld-macho] Don't fold subsections with symbols at nonzero offsets
authorJez Ng <jezng@fb.com>
Tue, 18 Oct 2022 21:21:39 +0000 (17:21 -0400)
committerJez Ng <jezng@fb.com>
Tue, 18 Oct 2022 21:22:09 +0000 (17:22 -0400)
commit16d784159f6873ff5ca860c0e490103127aa2e4e
treed061d48c2faa7b212bb0d854b31b6420aed408e7
parent181b04d276a8976e6ec60bbe178ccaf479ced655
[lld-macho] Don't fold subsections with symbols at nonzero offsets

Symbols occur at non-zero offsets in a subsection if they are
`.alt_entry` symbols, or if `.subsections_via_symbols` is omitted.

It doesn't seem like ld64 supports folding those subsections either.
Moreover, supporting this it makes `foldIdentical` a lot more
complicated to implement. The existing implementation has some
questionable behavior around STABS omission -- if a section with an
non-zero offset symbol was folded into one without, we would omit the
STABS entry for the non-zero offset symbol.

I will be following up with a diff that makes `foldIdentical` zero out
the symbol sizes for folded symbols. Again, this is much easier to
implement if we don't have to worry about non-zero offsets.

Reviewed By: #lld-macho, oontvoo

Differential Revision: https://reviews.llvm.org/D136000
lld/MachO/ICF.cpp
lld/MachO/InputFiles.cpp
lld/MachO/InputSection.cpp
lld/MachO/InputSection.h
lld/test/MachO/icf.s