This is an archive of the discontinued LLVM Phabricator instance.

[lldb][COFF] Rewrite ParseSymtab to list both export and symbol tables
ClosedPublic

Authored by alvinhochun on Sep 19 2022, 10:05 AM.

Details

Summary

This reimplements ObjectFilePECOFF::ParseSymtab to replace the manual
data extraction with what COFFObjectFile already provides. Also use
SymTab::AddSymbol instead of resizing the SymTab then assigning each
elements afterwards.

Previously, ParseSymTab loads symbols from both the COFF symbol table
and the export table, but if there are any entries in the export table,
it overwrites all the symbols already loaded from the COFF symbol table.
Due to the change to use AddSymbols, this no longer happens, and so the
SymTab now contains all symbols from both tables as expected.

The export symbols are now ordered by ordinal, instead of by the name
table order.

In its current state, it is possible for symbols in the COFF symbol
table to be duplicated by those in the export table. This behaviour will
be modified in a separate change.

Diff Detail

Event Timeline

alvinhochun created this revision.Sep 19 2022, 10:05 AM
Herald added a project: Restricted Project. · View Herald TranscriptSep 19 2022, 10:05 AM
alvinhochun requested review of this revision.Sep 19 2022, 10:05 AM
Herald added projects: Restricted Project, Restricted Project. · View Herald TranscriptSep 19 2022, 10:05 AM

I don't know how coff symbol tables work, but this seems reasonable to me.

lldb/test/Shell/ObjectFile/PECOFF/symbols-export-table.yaml
11

Even though it does not look like that, this will match an entry with any flags (because FileCheck does a substring match). The simplest solution would be to match the preceding UserID field as well.

35–76

Could this be reduced? Maybe by removing these zero fields?

Updated test

alvinhochun marked 2 inline comments as done.Sep 20 2022, 5:13 AM

Thanks for reviewing. The COFF symbol table seems to be used by MinGW binaries in conjunction with DWARF debugging symbols. Some symbols (those added by the linker in particular) are not included in the DWARF symbol. I understand that it is not used by MSVC, in which all debugging symbols are stored in PDB format.

This looks good to me, nothing to add from my PoV. Nice to have this condensed to a small enough rewrite, with few enough functional changes to wrap one's head around.

labath accepted this revision.Sep 21 2022, 6:28 AM
This revision is now accepted and ready to land.Sep 21 2022, 6:28 AM

Updated the test to include more symbols used in later changes