diff --git a/llvm/lib/Object/ELF.cpp b/llvm/lib/Object/ELF.cpp --- a/llvm/lib/Object/ELF.cpp +++ b/llvm/lib/Object/ELF.cpp @@ -542,11 +542,9 @@ } if (Dyn.empty()) - // TODO: this error is untested. return createError("invalid empty dynamic section"); if (Dyn.back().d_tag != ELF::DT_NULL) - // TODO: this error is untested. return createError("dynamic sections must be DT_NULL terminated"); return Dyn; diff --git a/llvm/test/Object/elf-invalid-dynamic-section.test b/llvm/test/Object/elf-invalid-dynamic-section.test new file mode 100644 --- /dev/null +++ b/llvm/test/Object/elf-invalid-dynamic-section.test @@ -0,0 +1,35 @@ +## Test LLVM emits a proper error message when parsing an invalid .dynamic section. + +# RUN: yaml2obj --docnum=1 %s -o %t1.o +# RUN: not llvm-objdump -p %t1.o 2>&1 | FileCheck %s --check-prefix=EMPTY + +# EMPTY: error: '{{.*}}': invalid empty dynamic section + +--- !ELF +FileHeader: + Class: ELFCLASS64 + Data: ELFDATA2LSB + Type: ET_DYN + Machine: EM_X86_64 +Sections: + - Name: .dynamic + Type: SHT_DYNAMIC + Content: "" + +# RUN: yaml2obj --docnum=2 %s -o %t2.o +# RUN: not llvm-objdump -p %t2.o 2>&1 | FileCheck %s --check-prefix=MALFORMED + +# MALFORMED: error: '{{.*}}': dynamic sections must be DT_NULL terminated + +--- !ELF +FileHeader: + Class: ELFCLASS64 + Data: ELFDATA2LSB + Type: ET_DYN + Machine: EM_X86_64 +Sections: + - Name: .dynamic + Type: SHT_DYNAMIC + Entries: + - Tag: DT_NEEDED + Value: 0x1