Index: llvm/test/tools/obj2yaml/ELF/eshnum.yaml =================================================================== --- /dev/null +++ llvm/test/tools/obj2yaml/ELF/eshnum.yaml @@ -0,0 +1,30 @@ +## Check cases related to the value of the e_shnum field of the ELF header live here. + +## Normally an object that does not have sections has e_shoff == 0. +## Also, e_shoff might be 0, when the the number of entries in the section +## header table is larger than or equal to SHN_LORESERVE (0xff00). In this case +## the real number of entries in the section header table is held in the sh_size +## member of the initial entry in section header table. +## In the test case below we have an object with a non-zero section header table +## file offset and the zero number of sections. Here we check that we are +## able to dump such objects properly. + +# RUN: yaml2obj %s -o %t +# RUN: obj2yaml %t | FileCheck %s + +# CHECK: --- !ELF +# CHECK-NEXT: FileHeader: +# CHECK-NEXT: Class: ELFCLASS64 +# CHECK-NEXT: Data: ELFDATA2LSB +# CHECK-NEXT: Type: ET_REL +# CHECK-NEXT: ... + +--- !ELF +FileHeader: + Class: ELFCLASS64 + Data: ELFDATA2LSB + Type: ET_REL + EShNum: 0x0 +Sections: + - Type: SHT_NULL + Size: 0x0 Index: llvm/tools/obj2yaml/elf2yaml.cpp =================================================================== --- llvm/tools/obj2yaml/elf2yaml.cpp +++ llvm/tools/obj2yaml/elf2yaml.cpp @@ -237,6 +237,9 @@ ArrayRef Phdrs, std::vector> &V, ArrayRef S) { + if (V.empty()) + return; + uint64_t ExpectedOffset; if (Header.e_phoff > 0) ExpectedOffset = Header.e_phoff + Header.e_phentsize * Header.e_phnum;