Page MenuHomePhabricator

[llvm-readobj] [COFF] Print the symbol index for relocations

Authored by mstorsjo on Dec 28 2018, 2:16 PM.



There can be multiple local symbols with the same name (for e.g. comdat sections), and thus the symbol name itself isn't enough to disambiguate symbols.

Diff Detail


Event Timeline

mstorsjo created this revision.Dec 28 2018, 2:16 PM

Neither of the tools that print relocations currently, llvm-readobj, llvm-objdump or yaml2obj, disambiguate between relocations pointing to different symbols with the same name.

ruiu added inline comments.Dec 28 2018, 2:22 PM
438 ↗(On Diff #179663)

Instead of storing an index as a member, can you compute it when you need it from the offset from the beginning of a symbol table?

Btw, do you think the index should be printed in hex? That's what dumpbin -relocations does.

mstorsjo marked an inline comment as done.Dec 28 2018, 11:43 PM
mstorsjo added inline comments.
438 ↗(On Diff #179663)

Yes, that'd be possible, but COFFSymbolRef doesn't have a reference to either the start of the symbol table or the surrounding COFFObjectFile, so it'd have to be a getIndexOf(COFFSymbolRef) member in COFFObjectFile in that case.

mstorsjo updated this revision to Diff 179726.Dec 30 2018, 4:54 AM

Removed the extra member from COFFSymbol, added a method to COFFObjectFile for calculating it instead.

The question about printing hex vs decimal is still open for opinions.

alexshap added inline comments.Dec 31 2018, 10:25 PM
1381 ↗(On Diff #179726)

one minor concern: if I understand correctly if the symbol is not found (Symbol == Obj->symbol_end()) this code still will print SymbolIndex = 0. Maybe we can do smth similar to how SymbolName is handled ?

mstorsjo marked an inline comment as done.Jan 1 2019, 12:03 AM
mstorsjo added inline comments.
1381 ↗(On Diff #179726)

Sure, I guess -1 is the only sensible thing to print then. The index can technically be any uint32_t, so storing it in a local int64_t to allow for -1 should be safe then.

mstorsjo updated this revision to Diff 179946.Jan 2 2019, 2:49 PM

Updated to print -1 for cases when the symbol isn't found.

alexshap accepted this revision.Jan 2 2019, 3:19 PM
This revision is now accepted and ready to land.Jan 2 2019, 3:19 PM
ruiu accepted this revision.Jan 2 2019, 3:29 PM


This revision was automatically updated to reflect the committed changes.