From ca30902ff841ab4f505a0732c1e517e4ed231b1c Mon Sep 17 00:00:00 2001 From: Michael Trent Date: Wed, 3 Jan 2018 23:28:32 +0000 Subject: Do not look up symbol names when n_strx == 0 Summary: 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 Reviewers: enderby, davide Reviewed By: enderby, davide Subscribers: davide, llvm-commits, JDevlieghere Differential Revision: https://reviews.llvm.org/D41657 llvm-svn: 321773 --- llvm/lib/Object/MachOObjectFile.cpp | 4 ++++ 1 file changed, 4 insertions(+) (limited to 'llvm/lib/Object/MachOObjectFile.cpp') diff --git a/llvm/lib/Object/MachOObjectFile.cpp b/llvm/lib/Object/MachOObjectFile.cpp index 2e3415618e5..3140316b50e 100644 --- a/llvm/lib/Object/MachOObjectFile.cpp +++ b/llvm/lib/Object/MachOObjectFile.cpp @@ -1659,6 +1659,10 @@ void MachOObjectFile::moveSymbolNext(DataRefImpl &Symb) const { Expected MachOObjectFile::getSymbolName(DataRefImpl Symb) const { StringRef StringTable = getStringTableData(); MachO::nlist_base Entry = getSymbolTableEntryBase(*this, Symb); + if (Entry.n_strx == 0) + // A n_strx value of 0 indicates that no name is associated with a + // particular symbol table entry. + 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) + -- cgit v1.2.3