diff options
-rw-r--r-- | llvm/lib/ObjectYAML/ELFEmitter.cpp | 4 | ||||
-rw-r--r-- | llvm/test/tools/yaml2obj/elf-no-phdrs.yaml | 15 |
2 files changed, 17 insertions, 2 deletions
diff --git a/llvm/lib/ObjectYAML/ELFEmitter.cpp b/llvm/lib/ObjectYAML/ELFEmitter.cpp index 362a9432568..e3dcd8ca077 100644 --- a/llvm/lib/ObjectYAML/ELFEmitter.cpp +++ b/llvm/lib/ObjectYAML/ELFEmitter.cpp @@ -224,10 +224,10 @@ void ELFState<ELFT>::writeELFHeader(ContiguousBlobAccumulator &CBA, raw_ostream Header.e_machine = Doc.Header.Machine; Header.e_version = EV_CURRENT; Header.e_entry = Doc.Header.Entry; - Header.e_phoff = sizeof(Header); + Header.e_phoff = Doc.ProgramHeaders.size() ? sizeof(Header) : 0; Header.e_flags = Doc.Header.Flags; Header.e_ehsize = sizeof(Elf_Ehdr); - Header.e_phentsize = sizeof(Elf_Phdr); + Header.e_phentsize = Doc.ProgramHeaders.size() ? sizeof(Elf_Phdr) : 0; Header.e_phnum = Doc.ProgramHeaders.size(); Header.e_shentsize = diff --git a/llvm/test/tools/yaml2obj/elf-no-phdrs.yaml b/llvm/test/tools/yaml2obj/elf-no-phdrs.yaml new file mode 100644 index 00000000000..e056b808e2f --- /dev/null +++ b/llvm/test/tools/yaml2obj/elf-no-phdrs.yaml @@ -0,0 +1,15 @@ +## Check that e_phoff and e_phentsize are set to 0 when there are no +## program headers. + +# RUN: yaml2obj %s -o %t +# RUN: llvm-readobj --file-headers %t | FileCheck %s + +# CHECK: ProgramHeaderOffset: 0x0{{$}} +# CHECK: ProgramHeaderEntrySize: 0{{$}} + +--- !ELF +FileHeader: + Class: ELFCLASS64 + Data: ELFDATA2LSB + Type: ET_REL + Machine: EM_X86_64 |