Index: lld/trunk/ELF/InputFiles.cpp =================================================================== --- lld/trunk/ELF/InputFiles.cpp +++ lld/trunk/ELF/InputFiles.cpp @@ -523,11 +523,11 @@ if (!DynamicSec) return; - auto *Begin = - reinterpret_cast(Obj.base() + DynamicSec->sh_offset); - const Elf_Dyn *End = Begin + DynamicSec->sh_size / sizeof(Elf_Dyn); - for (const Elf_Dyn &Dyn : make_range(Begin, End)) { + ArrayRef Arr = + check(Obj.template getSectionContentsAsArray(DynamicSec), + getFilename(this) + ": getSectionContentsAsArray failed"); + for (const Elf_Dyn &Dyn : Arr) { if (Dyn.d_tag == DT_SONAME) { uintX_t Val = Dyn.getVal(); if (Val >= this->StringTable.size()) Index: lld/trunk/test/ELF/invalid/dynamic-section-size.s =================================================================== --- lld/trunk/test/ELF/invalid/dynamic-section-size.s +++ lld/trunk/test/ELF/invalid/dynamic-section-size.s @@ -0,0 +1,4 @@ +## dynamic-section-sh_size.elf has incorrect sh_size of dynamic section. +# RUN: not ld.lld %p/Inputs/dynamic-section-sh_size.elf -o %t2 2>&1 | \ +# RUN: FileCheck %s +# CHECK: getSectionContentsAsArray failed: Invalid data was encountered while parsing the file