Index: llvm/test/tools/obj2yaml/ELF/program-headers.yaml =================================================================== --- llvm/test/tools/obj2yaml/ELF/program-headers.yaml +++ llvm/test/tools/obj2yaml/ELF/program-headers.yaml @@ -42,6 +42,7 @@ # YAML-NEXT: FirstSec: .hash # YAML-NEXT: LastSec: .dynstr # YAML-NEXT: Align: 0x1000 +# YAML-NEXT: Offset: 0x0 # YAML-NEXT: - Type: PT_LOAD # YAML-NEXT: Flags: [ PF_X, PF_R ] # YAML-NEXT: FirstSec: .foo Index: llvm/tools/obj2yaml/elf2yaml.cpp =================================================================== --- llvm/tools/obj2yaml/elf2yaml.cpp +++ llvm/tools/obj2yaml/elf2yaml.cpp @@ -10,6 +10,7 @@ #include "llvm/ADT/DenseSet.h" #include "llvm/ADT/STLExtras.h" #include "llvm/ADT/Twine.h" +#include "llvm/BinaryFormat/ELF.h" #include "llvm/DebugInfo/DWARF/DWARFContext.h" #include "llvm/Object/ELFObjectFile.h" #include "llvm/ObjectYAML/DWARFYAML.h" @@ -484,6 +485,13 @@ PH.Flags = Phdr.p_flags; PH.VAddr = Phdr.p_vaddr; PH.PAddr = Phdr.p_paddr; + if (Phdr.p_offset == 0 && Phdr.p_filesz) + PH.Offset = Phdr.p_offset; + + if (Phdr.p_type == ELF::PT_PHDR) { + PH.MemSize = Phdr.p_memsz; + PH.FileSize = Phdr.p_filesz; + } // yaml2obj sets the alignment of a segment to 1 by default. // We do not print the default alignment to reduce noise in the output.