[PATCH] D83941: [yaml2obj] - Fix an issue with NoHeaders key.

George Rimar via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Thu Jul 16 04:16:39 PDT 2020


grimar created this revision.
grimar added reviewers: jhenderson, MaskRay.
Herald added subscribers: hiraditya, emaste.
Herald added a reviewer: espindola.
Herald added a project: LLVM.

When setting the NoHeaders to false,
the e_shnum field wasn't set correctly.

This patch fixes this bug.


https://reviews.llvm.org/D83941

Files:
  llvm/lib/ObjectYAML/ELFEmitter.cpp
  llvm/test/tools/yaml2obj/ELF/section-headers.yaml


Index: llvm/test/tools/yaml2obj/ELF/section-headers.yaml
===================================================================
--- llvm/test/tools/yaml2obj/ELF/section-headers.yaml
+++ llvm/test/tools/yaml2obj/ELF/section-headers.yaml
@@ -122,13 +122,20 @@
 ## Test that we are able to set NoHeaders to false. In this case the tool produces an output
 ## as if there were no `SectionHeaderTable` key at all.
 # RUN: yaml2obj %s --docnum=3 -DNOHEADERS=false -o %t3.2
-# RUN: llvm-readelf --file-headers %t3.2 | FileCheck %s --check-prefix=NO-HEADERS-FALSE
+# RUN: llvm-readelf --file-headers --sections %t3.2 | FileCheck %s --check-prefix=NO-HEADERS-FALSE
 
 # NO-HEADERS-FALSE: Start of section headers:          96 (bytes into file)
 # NO-HEADERS-FALSE: Size of section headers:           64 (bytes)
-# NO-HEADERS-FALSE: Number of section headers:         1
+# NO-HEADERS-FALSE: Number of section headers:         4
 # NO-HEADERS-FALSE: Section header string table index: 3
 
+# NO-HEADERS-FALSE:      Section Headers:
+# NO-HEADERS-FALSE-NEXT:  [Nr] Name      Type     Address          Off    Size   ES Flg Lk Inf Al
+# NO-HEADERS-FALSE-NEXT:  [ 0]           NULL     0000000000000000 000000 000000 00      0   0  0
+# NO-HEADERS-FALSE-NEXT:  [ 1] .foo      PROGBITS 0000000000000000 000040 000000 00      0   0  0
+# NO-HEADERS-FALSE-NEXT:  [ 2] .strtab   STRTAB   0000000000000000 000040 000001 00      0   0  1
+# NO-HEADERS-FALSE-NEXT:  [ 3] .shstrtab STRTAB   0000000000000000 000041 000018 00      0   0  1
+
 ## Check we do not allow using "Sections" together with "NoHeaders".
 # RUN: not yaml2obj %s --docnum=4 -DNOHEADERS=true -o /dev/null 2>&1 | FileCheck %s --check-prefix=SECTIONS-NO-HEADERS
 # RUN: not yaml2obj %s --docnum=4 -DNOHEADERS=false -o /dev/null 2>&1 | FileCheck %s --check-prefix=SECTIONS-NO-HEADERS
Index: llvm/lib/ObjectYAML/ELFEmitter.cpp
===================================================================
--- llvm/lib/ObjectYAML/ELFEmitter.cpp
+++ llvm/lib/ObjectYAML/ELFEmitter.cpp
@@ -432,7 +432,8 @@
 
   if (Doc.Header.EShNum)
     Header.e_shnum = *Doc.Header.EShNum;
-  else if (!Doc.SectionHeaders)
+  else if (!Doc.SectionHeaders ||
+           (Doc.SectionHeaders->NoHeaders && !*Doc.SectionHeaders->NoHeaders))
     Header.e_shnum = Doc.getSections().size();
   else if (NoShdrs)
     Header.e_shnum = 0;


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D83941.278426.patch
Type: text/x-patch
Size: 2346 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20200716/ea2dd685/attachment.bin>


More information about the llvm-commits mailing list