Index: llvm/test/tools/llvm-objcopy/relocatable-phdr.test =================================================================== --- llvm/test/tools/llvm-objcopy/relocatable-phdr.test +++ llvm/test/tools/llvm-objcopy/relocatable-phdr.test @@ -2,7 +2,7 @@ # for offset and header size when copied with llvm-objcopy. # RUN: yaml2obj %s > %t # RUN: llvm-objcopy %t %t2 -# RUN: llvm-readelf -file-headers %t2 | FileCheck %s +# RUN: llvm-readobj -file-headers %t2 | FileCheck %s !ELF FileHeader: @@ -11,6 +11,6 @@ Type: ET_EXEC Machine: EM_X86_64 -# CHECK: Start of program headers: 0 (bytes into file) -# CHECK: Size of program headers: 0 (bytes) -# CHECK-NEXT:Number of program headers: 0 +# CHECK: ProgramHeaderOffset: 0x0 +# CHECK: ProgramHeaderEntrySize: 0 +# CHECK-NEXT:ProgramHeaderCount: 0 Index: llvm/tools/llvm-objcopy/Object.cpp =================================================================== --- llvm/tools/llvm-objcopy/Object.cpp +++ llvm/tools/llvm-objcopy/Object.cpp @@ -1050,8 +1050,8 @@ Ehdr.e_version = Obj.Version; Ehdr.e_entry = Obj.Entry; Ehdr.e_phnum = size(Obj.segments()); - Ehdr.e_phoff = (size(Obj.segments()) != 0) ? Obj.ProgramHdrSegment.Offset : 0; - Ehdr.e_phentsize = (size(Obj.segments()) != 0) ? sizeof(Elf_Phdr) : 0; + Ehdr.e_phoff = (Ehdr.e_phnum != 0) ? Obj.ProgramHdrSegment.Offset : 0; + Ehdr.e_phentsize = (Ehdr.e_phnum != 0) ? sizeof(Elf_Phdr) : 0; Ehdr.e_flags = Obj.Flags; Ehdr.e_ehsize = sizeof(Elf_Ehdr); Ehdr.e_shentsize = sizeof(Elf_Shdr);