[llvm] r355193 - [yaml2obj] - Allow setting custom sh_info for RawContentSection sections.

George Rimar via llvm-commits llvm-commits at lists.llvm.org
Fri Mar 1 02:18:16 PST 2019


Author: grimar
Date: Fri Mar  1 02:18:16 2019
New Revision: 355193

URL: http://llvm.org/viewvc/llvm-project?rev=355193&view=rev
Log:
[yaml2obj] - Allow setting custom sh_info for RawContentSection sections.

This is for tweaking SHT_SYMTAB sections.
Their sh_info contains the (number of symbols + 1) usually.
But for creating invalid inputs for test cases it would be convenient
to allow explicitly override this field from YAML.

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

Added:
    llvm/trunk/test/tools/obj2yaml/elf-shinfo.yaml
    llvm/trunk/test/tools/yaml2obj/elf-symtab-shinfo.yaml
    llvm/trunk/test/tools/yaml2obj/elf-symtab-shtype.yaml
Modified:
    llvm/trunk/include/llvm/ObjectYAML/ELFYAML.h
    llvm/trunk/lib/ObjectYAML/ELFYAML.cpp
    llvm/trunk/tools/obj2yaml/elf2yaml.cpp
    llvm/trunk/tools/yaml2obj/yaml2elf.cpp

Modified: llvm/trunk/include/llvm/ObjectYAML/ELFYAML.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/ObjectYAML/ELFYAML.h?rev=355193&r1=355192&r2=355193&view=diff
==============================================================================
--- llvm/trunk/include/llvm/ObjectYAML/ELFYAML.h (original)
+++ llvm/trunk/include/llvm/ObjectYAML/ELFYAML.h Fri Mar  1 02:18:16 2019
@@ -153,6 +153,7 @@ struct DynamicSection : Section {
 struct RawContentSection : Section {
   yaml::BinaryRef Content;
   llvm::yaml::Hex64 Size;
+  llvm::yaml::Hex64 Info;
 
   RawContentSection() : Section(SectionKind::RawContent) {}
 

Modified: llvm/trunk/lib/ObjectYAML/ELFYAML.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/ObjectYAML/ELFYAML.cpp?rev=355193&r1=355192&r2=355193&view=diff
==============================================================================
--- llvm/trunk/lib/ObjectYAML/ELFYAML.cpp (original)
+++ llvm/trunk/lib/ObjectYAML/ELFYAML.cpp Fri Mar  1 02:18:16 2019
@@ -887,6 +887,7 @@ static void sectionMapping(IO &IO, ELFYA
   commonSectionMapping(IO, Section);
   IO.mapOptional("Content", Section.Content);
   IO.mapOptional("Size", Section.Size, Hex64(Section.Content.binary_size()));
+  IO.mapOptional("Info", Section.Info, Hex64(0));
 }
 
 static void sectionMapping(IO &IO, ELFYAML::NoBitsSection &Section) {

Added: llvm/trunk/test/tools/obj2yaml/elf-shinfo.yaml
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/tools/obj2yaml/elf-shinfo.yaml?rev=355193&view=auto
==============================================================================
--- llvm/trunk/test/tools/obj2yaml/elf-shinfo.yaml (added)
+++ llvm/trunk/test/tools/obj2yaml/elf-shinfo.yaml Fri Mar  1 02:18:16 2019
@@ -0,0 +1,20 @@
+# RUN: yaml2obj %s -o %t
+# RUN: obj2yaml %t | FileCheck %s
+
+## Check obj2yaml is able to dump sh_info field of a section.
+
+# CHECK:      - Name:            .test
+# CHECK-NEXT:   Type:            SHT_PROGBITS
+# CHECK-NEXT:   Content:         ''
+# CHECK-NEXT:   Info:            0x000000000000002A
+
+--- !ELF
+FileHeader:
+  Class:           ELFCLASS64
+  Data:            ELFDATA2LSB
+  Type:            ET_REL
+  Machine:         EM_X86_64
+Sections:
+  - Name:            .test
+    Type:            SHT_PROGBITS
+    Info:            42

Added: llvm/trunk/test/tools/yaml2obj/elf-symtab-shinfo.yaml
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/tools/yaml2obj/elf-symtab-shinfo.yaml?rev=355193&view=auto
==============================================================================
--- llvm/trunk/test/tools/yaml2obj/elf-symtab-shinfo.yaml (added)
+++ llvm/trunk/test/tools/yaml2obj/elf-symtab-shinfo.yaml Fri Mar  1 02:18:16 2019
@@ -0,0 +1,43 @@
+## Check we are able to set sh_info field for SHT_SYMTAB sections.
+# RUN: yaml2obj %s -o %t
+# RUN: llvm-readobj -sections %t | FileCheck %s
+
+# CHECK:      Name: .symtab
+# CHECK-NEXT: Type: SHT_SYMTAB
+# CHECK-NEXT: Flags [
+# CHECK-NEXT: ]
+# CHECK-NEXT: Address:
+# CHECK-NEXT: Offset:
+# CHECK-NEXT: Size:
+# CHECK-NEXT: Link:
+# CHECK-NEXT: Info: 42
+# CHECK:      Name: .dynsym
+# CHECK-NEXT: Type: SHT_DYNSYM
+# CHECK-NEXT: Flags [
+# CHECK-NEXT:   SHF_ALLOC
+# CHECK-NEXT: ]
+# CHECK-NEXT: Address:
+# CHECK-NEXT: Offset:
+# CHECK-NEXT: Size:
+# CHECK-NEXT: Link:
+# CHECK-NEXT: Info: 26
+ 
+--- !ELF
+FileHeader:
+  Class:           ELFCLASS64
+  Data:            ELFDATA2LSB
+  Type:            ET_REL
+  Machine:         EM_X86_64
+Sections:
+  - Name:          .symtab
+    Info:          42
+    Type:          SHT_SYMTAB
+  - Name:          .dynsym
+    Info:          26
+    Type:          SHT_SYMTAB
+Symbols:
+  Global:
+    - Name: foo
+DynamicSymbols:
+  Global:
+    - Name: bar

Added: llvm/trunk/test/tools/yaml2obj/elf-symtab-shtype.yaml
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/tools/yaml2obj/elf-symtab-shtype.yaml?rev=355193&view=auto
==============================================================================
--- llvm/trunk/test/tools/yaml2obj/elf-symtab-shtype.yaml (added)
+++ llvm/trunk/test/tools/yaml2obj/elf-symtab-shtype.yaml Fri Mar  1 02:18:16 2019
@@ -0,0 +1,21 @@
+## Check we dont crash when .symtab has type different from SHT_SYMTAB.
+# RUN: yaml2obj %s -o %t
+# RUN: llvm-readobj -sections %t | FileCheck %s
+
+## TODO: the output is still SHT_SYMTAB because we do not yet
+## support changing it.
+# CHECK:      Name: .symtab
+# CHECK-NEXT: Type: SHT_SYMTAB
+
+--- !ELF
+FileHeader:      
+  Class:           ELFCLASS64
+  Data:            ELFDATA2LSB
+  Type:            ET_REL
+  Machine:         EM_X86_64
+Sections:        
+  - Name:            .symtab
+    Type:            SHT_DYNAMIC
+Symbols:
+  Global:
+    - Name: foo

Modified: llvm/trunk/tools/obj2yaml/elf2yaml.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/tools/obj2yaml/elf2yaml.cpp?rev=355193&r1=355192&r2=355193&view=diff
==============================================================================
--- llvm/trunk/tools/obj2yaml/elf2yaml.cpp (original)
+++ llvm/trunk/tools/obj2yaml/elf2yaml.cpp Fri Mar  1 02:18:16 2019
@@ -458,6 +458,7 @@ ELFDumper<ELFT>::dumpContentSection(cons
     return errorToErrorCode(ContentOrErr.takeError());
   S->Content = yaml::BinaryRef(ContentOrErr.get());
   S->Size = S->Content.binary_size();
+  S->Info = Shdr->sh_info;
 
   return S.release();
 }

Modified: llvm/trunk/tools/yaml2obj/yaml2elf.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/tools/yaml2obj/yaml2elf.cpp?rev=355193&r1=355192&r2=355193&view=diff
==============================================================================
--- llvm/trunk/tools/yaml2obj/yaml2elf.cpp (original)
+++ llvm/trunk/tools/yaml2obj/yaml2elf.cpp Fri Mar  1 02:18:16 2019
@@ -341,13 +341,16 @@ void ELFState<ELFT>::initSymtabSectionHe
   SHeader.sh_entsize = sizeof(Elf_Sym);
   SHeader.sh_addralign = 8;
 
-  // If .dynsym section is explicitly described in the YAML
-  // then we want to use its section address.
-  if (!IsStatic) {
-    // Take section index and ignore the SHT_NULL section.
-    unsigned SecNdx = getDotDynSymSecNo() - 1;
-    if (SecNdx < Doc.Sections.size())
-      SHeader.sh_addr = Doc.Sections[SecNdx]->Address;
+  // Get the section index ignoring the SHT_NULL section.
+  unsigned SecNdx =
+      IsStatic ? getDotSymTabSecNo() - 1 : getDotDynSymSecNo() - 1;
+  // If the symbol table section is explicitly described in the YAML
+  // then we should set the fields requested.
+  if (SecNdx < Doc.Sections.size()) {
+    ELFYAML::Section *Sec = Doc.Sections[SecNdx].get();
+    SHeader.sh_addr = Sec->Address;
+    if (auto S = dyn_cast<ELFYAML::RawContentSection>(Sec))
+      SHeader.sh_info = S->Info;
   }
 
   std::vector<Elf_Sym> Syms;
@@ -503,6 +506,7 @@ ELFState<ELFT>::writeSectionContent(Elf_
   else
     SHeader.sh_entsize = 0;
   SHeader.sh_size = Section.Size;
+  SHeader.sh_info = Section.Info;
 }
 
 static bool isMips64EL(const ELFYAML::Object &Doc) {




More information about the llvm-commits mailing list