Index: llvm/lib/ObjectYAML/ELFEmitter.cpp =================================================================== --- llvm/lib/ObjectYAML/ELFEmitter.cpp +++ llvm/lib/ObjectYAML/ELFEmitter.cpp @@ -225,7 +225,7 @@ 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); Index: llvm/test/tools/yaml2obj/elf-header-ephoff.yaml =================================================================== --- /dev/null +++ llvm/test/tools/yaml2obj/elf-header-ephoff.yaml @@ -0,0 +1,13 @@ +## Check that e_phoff is set to 0 when there are no program headers + +# RUN: yaml2obj %s -o %t +# RUN: llvm-readobj --file-headers %t | FileCheck %s + +# CHECK: ProgramHeaderOffset: 0 + +--- !ELF +FileHeader: + Class: ELFCLASS64 + Data: ELFDATA2LSB + Type: ET_REL + Machine: EM_X86_64