diff --git a/lld/MachO/Arch/ARM64.cpp b/lld/MachO/Arch/ARM64.cpp --- a/lld/MachO/Arch/ARM64.cpp +++ b/lld/MachO/Arch/ARM64.cpp @@ -605,11 +605,18 @@ auto secIt = std::prev(llvm::upper_bound( obj.sections, addr, [](uint64_t off, const Section *sec) { return off < sec->addr; })); + if (secIt < obj.sections.begin() || secIt > obj.sections.end() || + secIt == obj.sections.end()) + return false; const Section *sec = *secIt; auto subsecIt = std::prev(llvm::upper_bound( sec->subsections, addr - sec->addr, [](uint64_t off, Subsection subsec) { return off < subsec.offset; })); + if (subsecIt < sec->subsections.begin() || + subsecIt > sec->subsections.end() || subsecIt == sec->subsections.end()) + return false; + const Subsection &subsec = *subsecIt; const ConcatInputSection *isec = dyn_cast_or_null(subsec.isec);