Index: lld/MachO/InputFiles.cpp =================================================================== --- lld/MachO/InputFiles.cpp +++ lld/MachO/InputFiles.cpp @@ -1013,7 +1013,7 @@ // FIXME: There can be more than one compile unit per object file. See // PR48637. auto it = units.begin(); - compileUnit = it->get(); + compileUnit = (it != units.end()) ? it->get() : nullptr; } ArrayRef ObjFile::getDataInCode() const { Index: lld/test/MachO/dwarf-no-compile-unit.yaml =================================================================== --- /dev/null +++ lld/test/MachO/dwarf-no-compile-unit.yaml @@ -0,0 +1,103 @@ +# REQUIRES: aarch64 + +## Check that LLD does not crash if it encounters DWARF sections +## without __debug_info compile units DIEs being present. + +# RUN: yaml2obj %s -o %t.o +# RUN: %lld -dylib -arch arm64 -o %t.dylib %t.o + +--- !mach-o +FileHeader: + magic: 0xFEEDFACF + cputype: 0x100000C + cpusubtype: 0x0 + filetype: 0x1 + ncmds: 4 + sizeofcmds: 360 + flags: 0x0 + reserved: 0x0 +LoadCommands: + - cmd: LC_SEGMENT_64 + cmdsize: 232 + segname: '' + vmaddr: 0 + vmsize: 1 + fileoff: 392 + filesize: 1 + maxprot: 7 + initprot: 7 + nsects: 2 + flags: 0 + Sections: + - sectname: __text + segname: __TEXT + addr: 0x0 + size: 0 + offset: 0x188 + align: 0 + reloff: 0x0 + nreloc: 0 + flags: 0x80000000 + reserved1: 0x0 + reserved2: 0x0 + reserved3: 0x0 + content: '' + - sectname: __debug_abbrev + segname: __DWARF + addr: 0x0 + size: 1 + offset: 0x188 + align: 0 + reloff: 0x0 + nreloc: 0 + flags: 0x2000000 + reserved1: 0x0 + reserved2: 0x0 + reserved3: 0x0 + - cmd: LC_BUILD_VERSION + cmdsize: 24 + platform: 1 + minos: 786432 + sdk: 0 + ntools: 0 + - cmd: LC_SYMTAB + cmdsize: 24 + symoff: 400 + nsyms: 1 + stroff: 416 + strsize: 8 + - cmd: LC_DYSYMTAB + cmdsize: 80 + ilocalsym: 0 + nlocalsym: 1 + iextdefsym: 1 + nextdefsym: 0 + iundefsym: 1 + nundefsym: 0 + tocoff: 0 + ntoc: 0 + modtaboff: 0 + nmodtab: 0 + extrefsymoff: 0 + nextrefsyms: 0 + indirectsymoff: 0 + nindirectsyms: 0 + extreloff: 0 + nextrel: 0 + locreloff: 0 + nlocrel: 0 +LinkEditData: + NameList: + - n_strx: 1 + n_type: 0xE + n_sect: 1 + n_desc: 0 + n_value: 0 + StringTable: + - '' + - ltmp0 + - '' +DWARF: + debug_abbrev: + - ID: 0 +... Index: llvm/include/llvm/ADT/STLExtras.h =================================================================== --- llvm/include/llvm/ADT/STLExtras.h +++ llvm/include/llvm/ADT/STLExtras.h @@ -444,6 +444,16 @@ findNextValid(); return *this; } + + decltype(auto) operator*() const { + assert(BaseT::wrapped() != End && "Cannot dereference end iterator!"); + return BaseT::operator*(); + } + + decltype(auto) operator->() const { + assert(BaseT::wrapped() != End && "Cannot dereference end iterator!"); + return BaseT::operator->(); + } }; /// Specialization of filter_iterator_base for forward iteration only.