[llvm] ed605b7 - [yaml2obj] - Fix an issue with NoHeaders key.

Georgii Rymar via llvm-commits llvm-commits at lists.llvm.org
Thu Jul 16 04:23:05 PDT 2020


Author: Georgii Rymar
Date: 2020-07-16T14:22:36+03:00
New Revision: ed605b7b96b93a4418ec124552654785574e9f71

URL: https://github.com/llvm/llvm-project/commit/ed605b7b96b93a4418ec124552654785574e9f71
DIFF: https://github.com/llvm/llvm-project/commit/ed605b7b96b93a4418ec124552654785574e9f71.diff

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

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

This patch fixes this bug.

Differential revision: https://reviews.llvm.org/D83941

Added: 
    

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

Removed: 
    


################################################################################
diff  --git a/llvm/lib/ObjectYAML/ELFEmitter.cpp b/llvm/lib/ObjectYAML/ELFEmitter.cpp
index f9f2f128e2e8..a7f4a5d25237 100644
--- a/llvm/lib/ObjectYAML/ELFEmitter.cpp
+++ b/llvm/lib/ObjectYAML/ELFEmitter.cpp
@@ -432,7 +432,8 @@ void ELFState<ELFT>::writeELFHeader(raw_ostream &OS, uint64_t SHOff) {
 
   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;

diff  --git a/llvm/test/tools/yaml2obj/ELF/section-headers.yaml b/llvm/test/tools/yaml2obj/ELF/section-headers.yaml
index f593d76929fe..97288cb659a2 100644
--- a/llvm/test/tools/yaml2obj/ELF/section-headers.yaml
+++ b/llvm/test/tools/yaml2obj/ELF/section-headers.yaml
@@ -122,13 +122,20 @@ SectionHeaderTable:
 ## 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


        


More information about the llvm-commits mailing list