[llvm] r363377 - [yaml2obj] - Allow setting custom section types for implicit sections.
George Rimar via llvm-commits
llvm-commits at lists.llvm.org
Fri Jun 14 05:17:00 PDT 2019
Author: grimar
Date: Fri Jun 14 05:16:59 2019
New Revision: 363377
URL: http://llvm.org/viewvc/llvm-project?rev=363377&view=rev
Log:
[yaml2obj] - Allow setting custom section types for implicit sections.
We were hardcoding the final section type for sections that
are usually implicit. The patch fixes that.
This also fixes a few issues in existent test cases and removes
one precompiled object.
Differential revision: https://reviews.llvm.org/D63267
Added:
llvm/trunk/test/tools/yaml2obj/implicit-sections-types.test
Removed:
llvm/trunk/test/tools/llvm-readobj/Inputs/wrong-shstrtab-type.elf-x86-64
Modified:
llvm/trunk/test/tools/llvm-readobj/elf-wrong-shstrtab-type.test
llvm/trunk/test/tools/yaml2obj/elf-symtab-shinfo.yaml
llvm/trunk/test/tools/yaml2obj/elf-symtab-shtype.yaml
llvm/trunk/test/tools/yaml2obj/explicit-dynsym-no-dynstr.yaml
llvm/trunk/tools/yaml2obj/yaml2elf.cpp
Removed: llvm/trunk/test/tools/llvm-readobj/Inputs/wrong-shstrtab-type.elf-x86-64
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/tools/llvm-readobj/Inputs/wrong-shstrtab-type.elf-x86-64?rev=363376&view=auto
==============================================================================
Binary file - no diff available.
Modified: llvm/trunk/test/tools/llvm-readobj/elf-wrong-shstrtab-type.test
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/tools/llvm-readobj/elf-wrong-shstrtab-type.test?rev=363377&r1=363376&r2=363377&view=diff
==============================================================================
--- llvm/trunk/test/tools/llvm-readobj/elf-wrong-shstrtab-type.test (original)
+++ llvm/trunk/test/tools/llvm-readobj/elf-wrong-shstrtab-type.test Fri Jun 14 05:16:59 2019
@@ -1,11 +1,22 @@
-## wrong-shstrtab-type.elf-x86-64 contains .shstrtab section which has SHT_PROGBITS type.
-## Check we do not fail to dump the section headers in this case.
+## Check we do not fail to dump the section headers when
+## a .shstrtab section does not have a SHT_STRTAB type.
-# RUN: llvm-readobj -S %p/Inputs/wrong-shstrtab-type.elf-x86-64 | FileCheck %s --check-prefix LLVM
-# RUN: llvm-readelf -S %p/Inputs/wrong-shstrtab-type.elf-x86-64 | FileCheck %s --check-prefix GNU
+# RUN: yaml2obj %s -o %t1
+# RUN: llvm-readobj -S %t1 | FileCheck %s --check-prefix LLVM
+# RUN: llvm-readelf -S %t1 | FileCheck %s --check-prefix GNU
# LLVM: Name: .shstrtab
# LLVM-NEXT: Type: SHT_PROGBITS
# GNU: [Nr] Name Type
-# GNU: [ 3] .shstrtab PROGBITS
+# GNU: [ 1] .shstrtab PROGBITS
+
+--- !ELF
+FileHeader:
+ Class: ELFCLASS64
+ Data: ELFDATA2LSB
+ Type: ET_DYN
+ Machine: EM_X86_64
+Sections:
+ - Name: .shstrtab
+ Type: SHT_PROGBITS
Modified: 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=363377&r1=363376&r2=363377&view=diff
==============================================================================
--- llvm/trunk/test/tools/yaml2obj/elf-symtab-shinfo.yaml (original)
+++ llvm/trunk/test/tools/yaml2obj/elf-symtab-shinfo.yaml Fri Jun 14 05:16:59 2019
@@ -24,17 +24,17 @@
--- !ELF
FileHeader:
- Class: ELFCLASS64
- Data: ELFDATA2LSB
- Type: ET_REL
- Machine: EM_X86_64
+ 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
+ - Name: .symtab
+ Info: 42
+ Type: SHT_SYMTAB
+ - Name: .dynsym
+ Info: 26
+ Type: SHT_DYNSYM
Symbols:
- Name: foo
Binding: STB_GLOBAL
Modified: 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=363377&r1=363376&r2=363377&view=diff
==============================================================================
--- llvm/trunk/test/tools/yaml2obj/elf-symtab-shtype.yaml (original)
+++ llvm/trunk/test/tools/yaml2obj/elf-symtab-shtype.yaml Fri Jun 14 05:16:59 2019
@@ -2,20 +2,18 @@
# 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
+# CHECK-NEXT: Type: SHT_DYNAMIC
--- !ELF
-FileHeader:
- Class: ELFCLASS64
- Data: ELFDATA2LSB
- Type: ET_REL
- Machine: EM_X86_64
-Sections:
- - Name: .symtab
- Type: SHT_DYNAMIC
+FileHeader:
+ Class: ELFCLASS64
+ Data: ELFDATA2LSB
+ Type: ET_REL
+ Machine: EM_X86_64
+Sections:
+ - Name: .symtab
+ Type: SHT_DYNAMIC
Symbols:
- Name: foo
Binding: STB_GLOBAL
Modified: llvm/trunk/test/tools/yaml2obj/explicit-dynsym-no-dynstr.yaml
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/tools/yaml2obj/explicit-dynsym-no-dynstr.yaml?rev=363377&r1=363376&r2=363377&view=diff
==============================================================================
--- llvm/trunk/test/tools/yaml2obj/explicit-dynsym-no-dynstr.yaml (original)
+++ llvm/trunk/test/tools/yaml2obj/explicit-dynsym-no-dynstr.yaml Fri Jun 14 05:16:59 2019
@@ -19,4 +19,4 @@ FileHeader:
Machine: EM_X86_64
Sections:
- Name: .dynsym
- Type: SHT_SYMTAB
+ Type: SHT_DYNSYM
Added: llvm/trunk/test/tools/yaml2obj/implicit-sections-types.test
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/tools/yaml2obj/implicit-sections-types.test?rev=363377&view=auto
==============================================================================
--- llvm/trunk/test/tools/yaml2obj/implicit-sections-types.test (added)
+++ llvm/trunk/test/tools/yaml2obj/implicit-sections-types.test Fri Jun 14 05:16:59 2019
@@ -0,0 +1,69 @@
+## Here we check the types set for implicit sections
+## in different cases.
+
+## Check the types set by default in case sections were implicitly
+## added and not described in the YAML.
+
+# RUN: yaml2obj --docnum=1 %s -o %t1
+# RUN: llvm-readobj -S %t1 | FileCheck %s --check-prefix=CASE1
+
+# CASE1: Name: .symtab
+# CASE1-NEXT: Type: SHT_SYMTAB
+# CASE1: Name: .strtab
+# CASE1-NEXT: Type: SHT_STRTAB
+# CASE1: Name: .shstrtab
+# CASE1-NEXT: Type: SHT_STRTAB
+# CASE1: Name: .dynsym
+# CASE1-NEXT: Type: SHT_DYNSYM
+# CASE1: Name: .dynstr
+# CASE1-NEXT: Type: SHT_STRTAB
+
+--- !ELF
+FileHeader:
+ Class: ELFCLASS64
+ Data: ELFDATA2LSB
+ Type: ET_DYN
+ Machine: EM_X86_64
+## Needed to force the creation of the .dynsym and .dynstr.
+DynamicSymbols:
+ - Name: foo
+ - Binding: STB_GLOBAL
+
+## Check we can set any arbitrary types when describing sections
+## that are usually implicit.
+
+# RUN: yaml2obj --docnum=2 %s -o %t2
+# RUN: llvm-readobj -S %t2 | FileCheck %s --check-prefix=CASE2
+
+# CASE2: Name: .symtab
+# CASE2-NEXT: Type: SHT_DYNAMIC
+# CASE2: Name: .strtab
+# CASE2-NEXT: Type: SHT_RELA
+# CASE2: Name: .shstrtab
+# CASE2-NEXT: Type: SHT_PROGBITS
+# CASE2: Name: .dynsym
+# CASE2-NEXT: Type: SHT_NOTE
+# CASE2: Name: .dynstr
+# CASE2-NEXT: Type: SHT_NOBITS
+
+--- !ELF
+FileHeader:
+ Class: ELFCLASS64
+ Data: ELFDATA2LSB
+ Type: ET_DYN
+ Machine: EM_X86_64
+Sections:
+ - Name: .symtab
+ Type: SHT_DYNAMIC
+ - Name: .strtab
+ Type: SHT_RELA
+ - Name: .shstrtab
+ Type: SHT_PROGBITS
+ - Name: .dynsym
+ Type: SHT_NOTE
+ - Name: .dynstr
+ Type: SHT_NOBITS
+## Needed to set the proper content size for .symtab, so
+## that llvm-readobj can dump this section.
+Symbols:
+ - Name: foo
Modified: llvm/trunk/tools/yaml2obj/yaml2elf.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/tools/yaml2obj/yaml2elf.cpp?rev=363377&r1=363376&r2=363377&view=diff
==============================================================================
--- llvm/trunk/tools/yaml2obj/yaml2elf.cpp (original)
+++ llvm/trunk/tools/yaml2obj/yaml2elf.cpp Fri Jun 14 05:16:59 2019
@@ -403,7 +403,11 @@ void ELFState<ELFT>::initSymtabSectionHe
zero(SHeader);
SHeader.sh_name = DotShStrtab.getOffset(IsStatic ? ".symtab" : ".dynsym");
- SHeader.sh_type = IsStatic ? ELF::SHT_SYMTAB : ELF::SHT_DYNSYM;
+
+ if (YAMLSec)
+ SHeader.sh_type = YAMLSec->Type;
+ else
+ SHeader.sh_type = IsStatic ? ELF::SHT_SYMTAB : ELF::SHT_DYNSYM;
if (RawSec && !RawSec->Link.empty()) {
// If the Link field is explicitly defined in the document,
@@ -467,7 +471,7 @@ void ELFState<ELFT>::initStrtabSectionHe
ELFYAML::Section *YAMLSec) {
zero(SHeader);
SHeader.sh_name = DotShStrtab.getOffset(Name);
- SHeader.sh_type = ELF::SHT_STRTAB;
+ SHeader.sh_type = YAMLSec ? YAMLSec->Type : ELF::SHT_STRTAB;
SHeader.sh_addralign = YAMLSec ? (uint64_t)YAMLSec->AddressAlign : 1;
ELFYAML::RawContentSection *RawSec =
More information about the llvm-commits
mailing list