Skip to content

Commit 595cd45

Browse files
committed
[lld-macho][nfc]Add bounds on sections and subsections check before attempting to dereferencing iterators.
Runnign some tests with asan built of LLD would throw errors similar to the following: AddressSanitizer:DEADLYSIGNAL #0 0x55d8e6da5df7 in operator() /mnt/ssd/repo/lld/llvm-project/lld/MachO/Arch/ARM64.cpp:612 #1 0x55d8e6daa514 in operator() /mnt/ssd/repo/lld/llvm-project/lld/MachO/Arch/ARM64.cpp:650 Differential Revision: https://reviews.llvm.org/D157027
1 parent 3e24a77 commit 595cd45

File tree

1 file changed

+4
-0
lines changed

1 file changed

+4
-0
lines changed

lld/MachO/Arch/ARM64.cpp

+4
Original file line numberDiff line numberDiff line change
@@ -602,11 +602,15 @@ void ARM64::applyOptimizationHints(uint8_t *outBuf, const ObjFile &obj) const {
602602
addr < sectionAddr + section->getSize())
603603
return true;
604604

605+
if (obj.sections.empty())
606+
return false;
605607
auto secIt = std::prev(llvm::upper_bound(
606608
obj.sections, addr,
607609
[](uint64_t off, const Section *sec) { return off < sec->addr; }));
608610
const Section *sec = *secIt;
609611

612+
if (sec->subsections.empty())
613+
return false;
610614
auto subsecIt = std::prev(llvm::upper_bound(
611615
sec->subsections, addr - sec->addr,
612616
[](uint64_t off, Subsection subsec) { return off < subsec.offset; }));

0 commit comments

Comments
 (0)