[llvm] r371162 - [yaml2obj] Make e_phoff and e_phentsize 0 if there are no program headers
Alex Brachet via llvm-commits
llvm-commits at lists.llvm.org
Thu Sep 5 19:27:55 PDT 2019
Author: abrachet
Date: Thu Sep 5 19:27:55 2019
New Revision: 371162
URL: http://llvm.org/viewvc/llvm-project?rev=371162&view=rev
Log:
[yaml2obj] Make e_phoff and e_phentsize 0 if there are no program headers
Summary: It says [[ http://www.sco.com/developers/gabi/latest/ch4.eheader.html | here ]] that if there are no program headers than e_phoff should be 0, but currently it is always set after the header. GNU's `readelf` (but not `llvm-readelf`) complains about this: `readelf: Warning: possibly corrupt ELF header - it has a non-zero program header offset, but no program headers`.
Reviewers: jhenderson, grimar, MaskRay, rupprecht
Reviewed By: jhenderson, grimar, MaskRay
Subscribers: hiraditya, llvm-commits
Tags: #llvm
Differential Revision: https://reviews.llvm.org/D67054
Added:
llvm/trunk/test/tools/yaml2obj/elf-no-phdrs.yaml
Modified:
llvm/trunk/lib/ObjectYAML/ELFEmitter.cpp
Modified: llvm/trunk/lib/ObjectYAML/ELFEmitter.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/ObjectYAML/ELFEmitter.cpp?rev=371162&r1=371161&r2=371162&view=diff
==============================================================================
--- llvm/trunk/lib/ObjectYAML/ELFEmitter.cpp (original)
+++ llvm/trunk/lib/ObjectYAML/ELFEmitter.cpp Thu Sep 5 19:27:55 2019
@@ -224,10 +224,10 @@ void ELFState<ELFT>::writeELFHeader(Cont
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 =
Added: llvm/trunk/test/tools/yaml2obj/elf-no-phdrs.yaml
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/tools/yaml2obj/elf-no-phdrs.yaml?rev=371162&view=auto
==============================================================================
--- llvm/trunk/test/tools/yaml2obj/elf-no-phdrs.yaml (added)
+++ llvm/trunk/test/tools/yaml2obj/elf-no-phdrs.yaml Thu Sep 5 19:27:55 2019
@@ -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
More information about the llvm-commits
mailing list