This is an archive of the discontinued LLVM Phabricator instance.

[lld-macho] Coalesce local symbol aliases along with their aliased weak def
ClosedPublic

Authored by int3 on Mar 6 2023, 6:01 PM.

Details

Summary

This supersedes D139069: [lld-macho] Private label aliases to weak symbols should not retain section data. In some ways we are now closer to ld64's
behavior: we previously only did this coalescing for private-label
symbols, but now we do it for all locals, just like ld64. However, we no
longer generate weak binds when a local alias to a weak symbol is
referenced. This is merely for implementation simplicity; it's not clear
to me that any real-world programs depend on us emulating this behavior.

The problem with the previous approach is that we ended up with
duplicate references to the same symbol instance in our InputFiles,
which translated into duplicate symbols in our output. While we could
work around that problem by performing a dedup step before emitting the
symbol table, it seems cleaner to not generate duplicate references in
the first place.

Numbers for chromium_framework on my 16 Core Intel Mac Pro:

           base           diff           difference (95% CI)
sys_time   2.243 ± 0.093  2.231 ± 0.066  [  -2.5% ..   +1.4%]
user_time  6.529 ± 0.087  6.080 ± 0.050  [  -7.5% ..   -6.3%]
wall_time  6.928 ± 0.175  6.474 ± 0.112  [  -7.7% ..   -5.4%]
samples    26             31

Yep, that's a massive win... because it turns out that D140606: [lld-macho] Only fold private-label aliases that do not have flags and
D139069: [lld-macho] Private label aliases to weak symbols should not retain section data caused a regression (of about the same size.) I just didn't
think to measure them back then. I'm guessing all the extra symbols we
have been emitting did not help perf at all...

Diff Detail

Event Timeline

int3 created this revision.Mar 6 2023, 6:01 PM
Herald added projects: Restricted Project, Restricted Project. · View Herald TranscriptMar 6 2023, 6:01 PM
int3 requested review of this revision.Mar 6 2023, 6:01 PM
Herald added a project: Restricted Project. · View Herald TranscriptMar 6 2023, 6:01 PM
int3 added a reviewer: lgrey.EditedMar 6 2023, 6:02 PM

TODO: add tests for the non-subsections-via-symbols case

int3 updated this revision to Diff 502899.Mar 6 2023, 6:39 PM

update

lgrey accepted this revision.Mar 7 2023, 11:22 AM

LGTM, thanks! Patched this in, and this fixes both the bug I mentioned on the other change as well as another one that was setting aliasee sizes to zero in STABS.

lld/MachO/SymbolTable.cpp
79

insertIt

This revision is now accepted and ready to land.Mar 7 2023, 11:22 AM
int3 updated this revision to Diff 503632.Mar 8 2023, 10:35 PM
int3 marked an inline comment as done.

fix double-unwindEntry assertion

int3 updated this revision to Diff 504338.Mar 10 2023, 10:38 PM
int3 edited the summary of this revision. (Show Details)

update commit message with perf numbers

This revision was landed with ongoing or failed builds.Mar 10 2023, 10:40 PM
This revision was automatically updated to reflect the committed changes.
lld/test/MachO/local-alias-to-weak.s