This is an archive of the discontinued LLVM Phabricator instance.

llvm-objdump should ignore Mach-O stab symbols for disassembly.
ClosedPublic

Authored by mtrent on Dec 11 2019, 10:56 PM.

Details

Summary

llvm-objdump will commonly error out when disassembling a Mach-O binary with
stab symbols, or when printing a Mach-O symbol table that includesstab symbols.
That is because the Mach-O N_OSO symbol has been modified to include the
bottom 8-bit value of the Mach-O's cpusubtype value in the section field. In
general, one cannot blindly assume a stab symbol's section field is valid
unless one has actually consulted the specification for the specific stab.

Since objdump mostly just walks the symbol table to get mnemonics for code
disassembly it's best for objdump to just ignore stab symbols. llvm-nm will
do a more complete and correct job of displaying Mach-O symbol table contents.

Diff Detail

Event Timeline

mtrent created this revision.Dec 11 2019, 10:56 PM
Herald added a project: Restricted Project. · View Herald Transcript
MaskRay added inline comments.
llvm/tools/llvm-objdump/llvm-objdump.cpp
1833

Move the variable inside if.

Can you lift MachO below outside the loop?

1833

Please ignore Move the variable inside if.

mtrent marked 2 inline comments as done.Dec 12 2019, 7:42 AM
mtrent added inline comments.
llvm/tools/llvm-objdump/llvm-objdump.cpp
1833

Ignoring the variable, is it still desirable to make the MachO available in to the entire function?

mtrent marked an inline comment as done.Dec 12 2019, 9:30 AM
mtrent added inline comments.
llvm/tools/llvm-objdump/llvm-objdump.cpp
1833

Oh I see. Ill have a look.

mtrent updated this revision to Diff 233649.Dec 12 2019, 9:46 AM

Move MachO casts out of work loops.

MaskRay added inline comments.Dec 12 2019, 10:08 AM
llvm/tools/llvm-objdump/llvm-objdump.cpp
1152

I think that this comment could be clearer.

Does this comment suggest that the reader should skip this piece of code if they don't know what a STAB section is? (I don't know what a STAB section is.)

mtrent marked an inline comment as done.Dec 12 2019, 5:58 PM
mtrent added inline comments.
llvm/tools/llvm-objdump/llvm-objdump.cpp
1152

“Don’t ask a Mach-O STAB symbol for its section unless you know the STAB symbol section field refers to a section index. Otherwise SymbolRef may error trying to load a section that does not exist.” ?

mtrent updated this revision to Diff 233842.Dec 13 2019, 11:34 AM

Attempt to clarify STAB symbol restriction comment.

thegameg accepted this revision.Dec 17 2019, 1:49 PM

Thanks for the clarification in the comment. This LGTM!

This revision is now accepted and ready to land.Dec 17 2019, 1:49 PM
MaskRay accepted this revision.Dec 17 2019, 6:21 PM
This revision was automatically updated to reflect the committed changes.