This is an archive of the discontinued LLVM Phabricator instance.

[lld-macho] Emit local symbols in symtab; record metadata in LC_DYSYMTAB
ClosedPublic

Authored by int3 on Oct 12 2020, 6:49 PM.

Details

Summary

Symbols of the same type must be laid out contiguously: following ld64's
lead, we choose to emit all local symbols first, then external symbols,
and finally undefined symbols. For each symbol type, the LC_DYSYMTAB
load command will record the range (start index and total number) of
those symbols in the symbol table.

This work was motivated by the fact that LLDB won't search for debug
info if LC_DYSYMTAB says there are no local symbols (since STABS symbols
are all local symbols). With this change, LLDB is now able to display
the source lines at a given breakpoint when debugging our binaries.

Some tests had to be updated due to local symbol names now appearing in
llvm-objdump's output.

Diff Detail

Event Timeline

int3 created this revision.Oct 12 2020, 6:49 PM
Herald added a project: Restricted Project. · View Herald TranscriptOct 12 2020, 6:49 PM
int3 requested review of this revision.Oct 12 2020, 6:49 PM
int3 updated this revision to Diff 298165.Oct 14 2020, 9:30 AM

test dysymtab

int3 updated this revision to Diff 298198.Oct 14 2020, 11:17 AM

don't match unnecessarily on exact addresses in test

Given that Darwin has fully moved to DWARF at this point, why STABS?

int3 added a comment.Oct 15 2020, 9:00 AM

I'm not familiar with Darwin's history with STABS, but these symbols are still necessary for dsymutil / lldb to locate the DWARF debug info.

smeenai accepted this revision.Nov 9 2020, 6:24 PM
smeenai added a subscriber: smeenai.

LGTM

This revision is now accepted and ready to land.Nov 9 2020, 6:24 PM
clayborg accepted this revision.Nov 11 2020, 2:12 PM

LGTM as long as local symbols always have names (see inlined comment).

lld/MachO/SyntheticSections.cpp
643

Do all symbols have names? If not we should check that the symbol has a name and not add it if it doesn't?

Given that Darwin has fully moved to DWARF at this point, why STABS?

STABS are deprecated for normal actually containing debug info, but they are used for the DWARF in .o file format. This allows the linker to not have to link DWARF from all of the .o files, it just needs to emit a debug map, using STAB entries in the symbol table. Since the entries are debug entries, "strip" can strip the debug map out prior to shipping.

int3 added inline comments.Nov 11 2020, 4:46 PM
lld/MachO/SyntheticSections.cpp
643

To my knowledge, yes they do... are you aware of a way to generate unnamed local symbols?

clayborg added inline comments.Nov 12 2020, 2:31 PM
lld/MachO/SyntheticSections.cpp
643

No I am not.

This revision was landed with ongoing or failed builds.Dec 1 2020, 3:05 PM
This revision was automatically updated to reflect the committed changes.