diff options
author | Michael Trent <mtrent@apple.com> | 2018-01-03 23:28:32 +0000 |
---|---|---|
committer | Michael Trent <mtrent@apple.com> | 2018-01-03 23:28:32 +0000 |
commit | ca30902ff841ab4f505a0732c1e517e4ed231b1c (patch) | |
tree | 19dff876c5918934a303764f688ead4a987f5406 /llvm/lib/Object/MachOObjectFile.cpp | |
parent | bba410668a7c2b2af2d23a047260e568e5b622ee (diff) | |
download | llvm-ca30902ff841ab4f505a0732c1e517e4ed231b1c.zip llvm-ca30902ff841ab4f505a0732c1e517e4ed231b1c.tar.gz llvm-ca30902ff841ab4f505a0732c1e517e4ed231b1c.tar.bz2 |
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
Diffstat (limited to 'llvm/lib/Object/MachOObjectFile.cpp')
-rw-r--r-- | llvm/lib/Object/MachOObjectFile.cpp | 4 |
1 files changed, 4 insertions, 0 deletions
diff --git a/llvm/lib/Object/MachOObjectFile.cpp b/llvm/lib/Object/MachOObjectFile.cpp index 2e34156..3140316 100644 --- a/llvm/lib/Object/MachOObjectFile.cpp +++ b/llvm/lib/Object/MachOObjectFile.cpp @@ -1659,6 +1659,10 @@ void MachOObjectFile::moveSymbolNext(DataRefImpl &Symb) const { Expected<StringRef> 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) + |