[llvm] llvm-objdump: ensure a MachO symbol isn't STAB before looking up secion (PR #86667)
Tim Northover via llvm-commits
llvm-commits at lists.llvm.org
Tue Mar 26 07:14:55 PDT 2024
https://github.com/TNorthover created https://github.com/llvm/llvm-project/pull/86667
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.
>From 352288dadcf3b4c9be4736a0100e9e99d70cb0b7 Mon Sep 17 00:00:00 2001
From: Tim Northover <tnorthover at apple.com>
Date: Tue, 26 Mar 2024 14:10:22 +0000
Subject: [PATCH] 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.
---
.../MachO/Inputs/macho-stabs-x86_64 | Bin 8552 -> 8552 bytes
llvm/tools/llvm-objdump/llvm-objdump.cpp | 21 +++++++++---------
2 files changed, 11 insertions(+), 10 deletions(-)
diff --git a/llvm/test/tools/llvm-objdump/MachO/Inputs/macho-stabs-x86_64 b/llvm/test/tools/llvm-objdump/MachO/Inputs/macho-stabs-x86_64
index e95c8204c710e035ae03dd55c4796e8ed835b96b..c41573aa4bf3b0cb7654d77de06c7115226bfd7d 100755
GIT binary patch
delta 14
VcmaFi^ulR_tpcOdW;+EfMgT671mOSx
delta 14
VcmaFi^ulR_tpX#%W;+EfMgT1a1fKu^
diff --git a/llvm/tools/llvm-objdump/llvm-objdump.cpp b/llvm/tools/llvm-objdump/llvm-objdump.cpp
index 78cf67b1e630bb..f9f073e586913f 100644
--- a/llvm/tools/llvm-objdump/llvm-objdump.cpp
+++ b/llvm/tools/llvm-objdump/llvm-objdump.cpp
@@ -2824,16 +2824,6 @@ void Dumper::printSymbol(const SymbolRef &Symbol,
reportUniqueWarning(AddrOrErr.takeError());
return;
}
- uint64_t Address = *AddrOrErr;
- section_iterator SecI = unwrapOrError(Symbol.getSection(), FileName);
- if (SecI != O.section_end() && shouldAdjustVA(*SecI))
- Address += AdjustVMA;
- if ((Address < StartAddress) || (Address > StopAddress))
- return;
- SymbolRef::Type Type =
- unwrapOrError(Symbol.getType(), FileName, ArchiveName, ArchitectureName);
- uint32_t Flags =
- unwrapOrError(Symbol.getFlags(), FileName, ArchiveName, ArchitectureName);
// Don't ask a Mach-O STAB symbol for its section unless you know that
// STAB symbol's section field refers to a valid section index. Otherwise
@@ -2852,6 +2842,17 @@ void Dumper::printSymbol(const SymbolRef &Symbol,
: unwrapOrError(Symbol.getSection(), FileName,
ArchiveName, ArchitectureName);
+ uint64_t Address = *AddrOrErr;
+ if (Section != O.section_end() && shouldAdjustVA(*Section))
+ Address += AdjustVMA;
+ if ((Address < StartAddress) || (Address > StopAddress))
+ return;
+ SymbolRef::Type Type =
+ unwrapOrError(Symbol.getType(), FileName, ArchiveName, ArchitectureName);
+ uint32_t Flags =
+ unwrapOrError(Symbol.getFlags(), FileName, ArchiveName, ArchitectureName);
+
+
StringRef Name;
if (Type == SymbolRef::ST_Debug && Section != O.section_end()) {
if (Expected<StringRef> NameOrErr = Section->getName())
More information about the llvm-commits
mailing list