[PATCH] D41657: Do not look up symbol names when n_strx == 0
Michael Trent via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Mon Jan 1 14:13:31 PST 2018
mtrent created this revision.
mtrent added a reviewer: enderby.
Herald added a subscriber: JDevlieghere.
Historical tools for working with mach-o binaries verify the nlist field
n_strx has a non-zero value before using that value to retrieve symbol names.
Under some cirumstances, llvm-nm will attempt to display the symbol name at
position 0, even though symbol names at that position are not well defined.
This change addresses this problem by returning an empty string when n_strx
is zero.
rdar://problem/35750548
https://reviews.llvm.org/D41657
Files:
lib/Object/MachOObjectFile.cpp
test/tools/llvm-nm/X86/Inputs/macho-dwarf-x86_64
test/tools/llvm-nm/X86/macho-dwarf.test
Index: test/tools/llvm-nm/X86/macho-dwarf.test
===================================================================
--- /dev/null
+++ test/tools/llvm-nm/X86/macho-dwarf.test
@@ -0,0 +1,5 @@
+# RUN: llvm-nm -ap %p/Inputs/macho-dwarf-x86_64 | cat -e | FileCheck %s
+
+# CHECK-NOT: ENSYM $
+# CHECK: ENSYM $
+
Index: lib/Object/MachOObjectFile.cpp
===================================================================
--- lib/Object/MachOObjectFile.cpp
+++ lib/Object/MachOObjectFile.cpp
@@ -1659,6 +1659,10 @@
Expected<StringRef> MachOObjectFile::getSymbolName(DataRefImpl Symb) const {
StringRef StringTable = getStringTableData();
MachO::nlist_base Entry = getSymbolTableEntryBase(*this, Symb);
+ if (Entry.n_strx == 0) {
+ // contents of the StringTable at n_strx 0 are not defined
+ return StringRef();
+ }
const char *Start = &StringTable.data()[Entry.n_strx];
if (Start < getData().begin() || Start >= getData().end()) {
return malformedError("bad string index: " + Twine(Entry.n_strx) +
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D41657.128394.patch
Type: text/x-patch
Size: 1016 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20180101/b520203f/attachment.bin>
More information about the llvm-commits
mailing list