diff --git a/lld/MachO/Arch/ARM64.cpp b/lld/MachO/Arch/ARM64.cpp index e28e82a78cbd1f..e3781763c6102b 100644 --- a/lld/MachO/Arch/ARM64.cpp +++ b/lld/MachO/Arch/ARM64.cpp @@ -602,11 +602,15 @@ void ARM64::applyOptimizationHints(uint8_t *outBuf, const ObjFile &obj) const { addr < sectionAddr + section->getSize()) return true; + if (obj.sections.empty()) + return false; auto secIt = std::prev(llvm::upper_bound( obj.sections, addr, [](uint64_t off, const Section *sec) { return off < sec->addr; })); const Section *sec = *secIt; + if (sec->subsections.empty()) + return false; auto subsecIt = std::prev(llvm::upper_bound( sec->subsections, addr - sec->addr, [](uint64_t off, Subsection subsec) { return off < subsec.offset; }));