From 0d2a8c061475b86880323ad31731fa717e270150 Mon Sep 17 00:00:00 2001 From: Steven Wu Date: Wed, 17 Mar 2021 15:05:51 -0700 Subject: [PATCH] [Object][MachO] Handle end iterator in getSymbolType() 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 Reviewed By: davide, ab Differential Revision: https://reviews.llvm.org/D98739 --- lib/Object/MachOObjectFile.cpp | 2 ++ 1 file changed, 2 insertions(+) diff --git a/lib/Object/MachOObjectFile.cpp b/lib/Object/MachOObjectFile.cpp index 30225592628..498e99bdb82 100644 --- a/lib/Object/MachOObjectFile.cpp +++ b/lib/Object/MachOObjectFile.cpp @@ -1836,6 +1836,8 @@ MachOObjectFile::getSymbolType(DataRefImpl Symb) const { 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;