forked from OSchip/llvm-project
[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 llvm-svn: 363377
This commit is contained in:
parent
e5bd808c3e
commit
3b523c0a2e
Binary file not shown.
|
@ -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
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -19,4 +19,4 @@ FileHeader:
|
|||
Machine: EM_X86_64
|
||||
Sections:
|
||||
- Name: .dynsym
|
||||
Type: SHT_SYMTAB
|
||||
Type: SHT_DYNSYM
|
||||
|
|
|
@ -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
|
|
@ -403,7 +403,11 @@ void ELFState<ELFT>::initSymtabSectionHeader(Elf_Shdr &SHeader,
|
|||
|
||||
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>::initStrtabSectionHeader(Elf_Shdr &SHeader, StringRef Name,
|
|||
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 =
|
||||
|
|
Loading…
Reference in New Issue