Skip to content

Commit bc79ffd

Browse files
committed
llvm-objdump: ensure a MachO symbol isn't STAB before looking up section.
The section field has been repurposed for some STAB symbol types, and if we blindly look it up we'll produce an error and terminate. Logic already existed Existing stabs test had a section that was in range. Unfortunately I don't know of an easy way to produce stabs entries in LLVM (I thought they died in the 90s until this came up) so I just binary-edited it to cause a failure on existing llvm-objdump.
1 parent a51d13f commit bc79ffd

File tree

2 files changed

+10
-10
lines changed

2 files changed

+10
-10
lines changed
Binary file not shown.

llvm/tools/llvm-objdump/llvm-objdump.cpp

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -2824,16 +2824,6 @@ void Dumper::printSymbol(const SymbolRef &Symbol,
28242824
reportUniqueWarning(AddrOrErr.takeError());
28252825
return;
28262826
}
2827-
uint64_t Address = *AddrOrErr;
2828-
section_iterator SecI = unwrapOrError(Symbol.getSection(), FileName);
2829-
if (SecI != O.section_end() && shouldAdjustVA(*SecI))
2830-
Address += AdjustVMA;
2831-
if ((Address < StartAddress) || (Address > StopAddress))
2832-
return;
2833-
SymbolRef::Type Type =
2834-
unwrapOrError(Symbol.getType(), FileName, ArchiveName, ArchitectureName);
2835-
uint32_t Flags =
2836-
unwrapOrError(Symbol.getFlags(), FileName, ArchiveName, ArchitectureName);
28372827

28382828
// Don't ask a Mach-O STAB symbol for its section unless you know that
28392829
// STAB symbol's section field refers to a valid section index. Otherwise
@@ -2852,6 +2842,16 @@ void Dumper::printSymbol(const SymbolRef &Symbol,
28522842
: unwrapOrError(Symbol.getSection(), FileName,
28532843
ArchiveName, ArchitectureName);
28542844

2845+
uint64_t Address = *AddrOrErr;
2846+
if (Section != O.section_end() && shouldAdjustVA(*Section))
2847+
Address += AdjustVMA;
2848+
if ((Address < StartAddress) || (Address > StopAddress))
2849+
return;
2850+
SymbolRef::Type Type =
2851+
unwrapOrError(Symbol.getType(), FileName, ArchiveName, ArchitectureName);
2852+
uint32_t Flags =
2853+
unwrapOrError(Symbol.getFlags(), FileName, ArchiveName, ArchitectureName);
2854+
28552855
StringRef Name;
28562856
if (Type == SymbolRef::ST_Debug && Section != O.section_end()) {
28572857
if (Expected<StringRef> NameOrErr = Section->getName())

0 commit comments

Comments
 (0)