[lld-macho] Improve hiding of unnamed_addr symbols
authorJez Ng <jezng@fb.com>
Fri, 18 Feb 2022 17:03:11 +0000 (12:03 -0500)
committerJez Ng <jezng@fb.com>
Fri, 18 Feb 2022 17:09:38 +0000 (12:09 -0500)
commitfd3669c2567302d34d9dd2222ee97204e4e26d4a
tree85f42942c509e48d64af1be0ac0f9dfea496200f
parent622ea723ccfdc4495ac3a1283598a8d15f1524a3
[lld-macho] Improve hiding of unnamed_addr symbols

Symbols for which `canBeOmittedFromSymbolTable()` is true should be
treated as private externs. This diff tries to do that by unsetting the
ExportDynamic bit. It seems to mostly work with the FullLTO backend, but
with the ThinLTO backend, the `local_unnamed_addr` symbols still fail to
be properly hidden. Nonetheless, this is a step in the right direction.

I've documented all the remaining differences between our behavior and
LD64's in the lto-internalized-unnamed-addr.ll test.

See also https://discourse.llvm.org/t/mach-o-lto-handling-of-linkonce-odr-unnamed-addr/60015

Reviewed By: #lld-macho, thevinster

Differential Revision: https://reviews.llvm.org/D119767
lld/MachO/InputFiles.cpp
lld/test/MachO/lto-internalize-unnamed-addr.ll [new file with mode: 0644]