[PATCH] D98739: [Object][MachO] Handle end iterator in getSymbolType()

Steven Wu via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Tue Mar 16 13:24:19 PDT 2021


steven_wu created this revision.
steven_wu added reviewers: davide, ab.
Herald added subscribers: ributzka, jkorous, hiraditya.
steven_wu requested review of this revision.
Herald added a project: LLVM.

Fix a bug in MachOObjectFile::getSymbolType() that it is not checking if
the iterator is end() before deference the iterator. Instead, return
`Other` type, which aligns with the behavior of `llvm-nm`.

rdar://75291638


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D98739

Files:
  llvm/lib/Object/MachOObjectFile.cpp


Index: llvm/lib/Object/MachOObjectFile.cpp
===================================================================
--- llvm/lib/Object/MachOObjectFile.cpp
+++ llvm/lib/Object/MachOObjectFile.cpp
@@ -1836,6 +1836,8 @@
       if (!SecOrError)
         return SecOrError.takeError();
       section_iterator Sec = *SecOrError;
+      if (Sec == section_end())
+        return SymbolRef::ST_Other;
       if (Sec->isData() || Sec->isBSS())
         return SymbolRef::ST_Data;
       return SymbolRef::ST_Function;


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D98739.331089.patch
Type: text/x-patch
Size: 506 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20210316/abac4d16/attachment.bin>


More information about the llvm-commits mailing list