[yaml2obj][obj2yaml] - Do not create a symbol table by default.

This patch tries to resolve problems faced in D68943
and uses some of the code written by Konrad Wilhelm Kleine
in that patch.

Previously, yaml2obj tool always created a .symtab section.
This patch changes that. With it we only create it when
have a "Symbols:" tag in the YAML document or when
we need to create it because it is used by another section(s).

obj2yaml follows the new behavior and does not print "Symbols:"
anymore when there is no symbol table.

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

llvm-svn: 375361
This commit is contained in:
George Rimar 2019-10-20 14:47:17 +00:00
parent 3f6974f76d
commit cb7a47f782
62 changed files with 178 additions and 87 deletions

View File

@ -376,7 +376,7 @@ struct Object {
// cleaner and nicer if we read them from the YAML as a separate
// top-level key, which automatically ensures that invariants like there
// being a single SHT_SYMTAB section are upheld.
std::vector<Symbol> Symbols;
Optional<std::vector<Symbol>> Symbols;
std::vector<Symbol> DynamicSymbols;
};

View File

@ -200,10 +200,17 @@ template <class ELFT>
ELFState<ELFT>::ELFState(ELFYAML::Object &D, yaml::ErrorHandler EH)
: Doc(D), ErrHandler(EH) {
StringSet<> DocSections;
for (std::unique_ptr<ELFYAML::Section> &D : Doc.Sections)
for (std::unique_ptr<ELFYAML::Section> &D : Doc.Sections) {
if (!D->Name.empty())
DocSections.insert(D->Name);
// Some sections wants to link to .symtab by default.
// That means we want to create the symbol table for them.
if (D->Type == llvm::ELF::SHT_REL || D->Type == llvm::ELF::SHT_RELA)
if (!Doc.Symbols && D->Link.empty())
Doc.Symbols.emplace();
}
// Insert SHT_NULL section implicitly when it is not defined in YAML.
if (Doc.Sections.empty() || Doc.Sections.front()->Type != ELF::SHT_NULL)
Doc.Sections.insert(
@ -211,7 +218,11 @@ ELFState<ELFT>::ELFState(ELFYAML::Object &D, yaml::ErrorHandler EH)
std::make_unique<ELFYAML::Section>(
ELFYAML::Section::SectionKind::RawContent, /*IsImplicit=*/true));
std::vector<StringRef> ImplicitSections = {".symtab", ".strtab", ".shstrtab"};
std::vector<StringRef> ImplicitSections;
if (Doc.Symbols)
ImplicitSections.push_back(".symtab");
ImplicitSections.insert(ImplicitSections.end(), {".strtab", ".shstrtab"});
if (!Doc.DynamicSymbols.empty())
ImplicitSections.insert(ImplicitSections.end(), {".dynsym", ".dynstr"});
@ -508,7 +519,11 @@ void ELFState<ELFT>::initSymtabSectionHeader(Elf_Shdr &SHeader,
ELFYAML::Section *YAMLSec) {
bool IsStatic = STType == SymtabType::Static;
const auto &Symbols = IsStatic ? Doc.Symbols : Doc.DynamicSymbols;
ArrayRef<ELFYAML::Symbol> Symbols;
if (IsStatic && Doc.Symbols)
Symbols = *Doc.Symbols;
else if (!IsStatic)
Symbols = Doc.DynamicSymbols;
ELFYAML::RawContentSection *RawSec =
dyn_cast_or_null<ELFYAML::RawContentSection>(YAMLSec);
@ -1044,14 +1059,16 @@ template <class ELFT> void ELFState<ELFT>::buildSymbolIndexes() {
}
};
Build(Doc.Symbols, SymN2I);
if (Doc.Symbols)
Build(*Doc.Symbols, SymN2I);
Build(Doc.DynamicSymbols, DynSymN2I);
}
template <class ELFT> void ELFState<ELFT>::finalizeStrings() {
// Add the regular symbol names to .strtab section.
for (const ELFYAML::Symbol &Sym : Doc.Symbols)
DotStrtab.add(ELFYAML::dropUniqueSuffix(Sym.Name));
if (Doc.Symbols)
for (const ELFYAML::Symbol &Sym : *Doc.Symbols)
DotStrtab.add(ELFYAML::dropUniqueSuffix(Sym.Name));
DotStrtab.finalize();
// Add the dynamic symbol names to .dynstr section.

View File

@ -226,6 +226,7 @@ Sections:
Type: SHT_SYMTAB_SHNDX
Entries: [ 0, 1 ]
Link: .symtab
Symbols: []
## Check that llvm-readobj reports an error if the e_phentsize field is broken.
@ -274,8 +275,8 @@ Sections:
Type: SHT_RELA
ShOffset: 0x10000
## Check that llvm-objdump reports an error when .shstrtab has a broken sh_offset
## so large that sh_offset + sh_size overflows the platform address size type.
## Check that llvm-objdump reports an error when we try to print symbols and
## .shstrtab has a broken sh_offset so large that sh_offset + sh_size overflows the platform address size type.
# RUN: yaml2obj %s --docnum=14 -o %t14
# RUN: not llvm-readobj --symbols %t14 2>&1 | FileCheck -DFILE=%t14 --check-prefix=INVALID-SECTION-SIZE2 %s
@ -292,6 +293,7 @@ Sections:
- Name: .shstrtab
Type: SHT_STRTAB
ShOffset: 0xFFFFFFFF
Symbols: []
## Check that llvm-readobj reports an error when trying to dump sections
## when the e_shnum field is broken (is greater than the actual number of sections).
@ -565,7 +567,7 @@ Sections:
# RUN: yaml2obj --docnum=26 %s -o %t26
# RUN: not llvm-readobj -h %t26 2>&1 | FileCheck -DFILE=%t26 --check-prefix=INVALID-SEC-NUM1 %s
# INVALID-SEC-NUM1: error: '[[FILE]]': invalid section header table offset (e_shoff = 0x78) or invalid number of sections specified in the first section header's sh_size field (0x3ffffffffffffff)
# INVALID-SEC-NUM1: error: '[[FILE]]': invalid section header table offset (e_shoff = 0x58) or invalid number of sections specified in the first section header's sh_size field (0x3ffffffffffffff)
--- !ELF
FileHeader:

View File

@ -37,6 +37,5 @@ Sections:
- Name: .rela.text
Type: SHT_RELA
Address: 0x0000000000000038
Link: .symtab
Info: .text
Relocations:

View File

@ -23,11 +23,10 @@ Sections:
Flags: [ SHF_ALLOC ]
Content: "32323232"
# CHECK: SectionHeaderCount: 7
# CHECK: SectionHeaderCount: 6
# CHECK: Name: .test1
# CHECK: Name: .test3
# CHECK: Name: .symtab
# CHECK: Name: .strtab
# CHECK: Name: .shstrtab
# CHECK: Name: .test2

View File

@ -24,11 +24,10 @@ Sections:
Flags: [ SHF_ALLOC ]
Content: "32323232"
# CHECK: SectionHeaderCount: 7
# CHECK: SectionHeaderCount: 6
# CHECK: Name: .test1
# CHECK: Name: .test3
# CHECK: Name: .symtab
# CHECK: Name: .strtab
# CHECK: Name: .shstrtab
# CHECK: Name: .test2

View File

@ -58,6 +58,9 @@ ProgramHeaders:
Align: 0x1000
Sections:
- Section: .data
## TODO (grimar): llvm-objcopy seems produce a broken output without
## the following line, i.e. when there is no symbol table in the input.
Symbols: []
# CHECK: 0: 00000000 0 NOTYPE LOCAL DEFAULT UND
# CHECK-NEXT: 1: 00000001 0 NOTYPE GLOBAL DEFAULT ABS abs1

View File

@ -15,9 +15,7 @@ Sections:
Type: SHT_PROGBITS
Flags: [ ]
# CHECK: SectionHeaderCount: 5
# CHECK: SectionHeaderCount: 3
# CHECK: Name: .test
# CHECK: Name: .symtab
# CHECK: Name: .strtab
# CHECK: Name: .shstrtab

View File

@ -13,9 +13,8 @@ Sections:
Type: SHT_PROGBITS
Flags: [ ]
# CHECK: SectionHeaderCount: 5
# CHECK: SectionHeaderCount: 4
# CHECK: Name: .test
# CHECK: Name: .symtab
# CHECK: Name: .strtab
# CHECK: Name: .shstrtab

View File

@ -13,9 +13,7 @@ Sections:
Type: SHT_PROGBITS
Flags: [ ]
# CHECK: SectionHeaderCount: 5
# CHECK: SectionHeaderCount: 3
# CHECK: Name: .test
# CHECK: Name: .symtab
# CHECK: Name: .strtab
# CHECK: Name: .shstrtab

View File

@ -28,5 +28,6 @@ FileHeader:
Sections:
- Name: .foo
Type: SHT_PROGBITS
Symbols: []
# CASE2: error: '[[INPUT]]': section header table goes past the end of the file: e_shoff = 0x40000000

View File

@ -20,19 +20,15 @@ Sections:
- Name: .test3
Type: SHT_PROGBITS
# CHECK: SectionHeaderCount: 6
# CHECK: SectionHeaderCount: 4
# CHECK: Name: .test
# CHECK: Name: .test2
# CHECK: Name: .symtab
# CHECK: Name: .strtab
# CHECK: Name: .shstrtab
# REGEX: SectionHeaderCount: 7
# REGEX: SectionHeaderCount: 5
# REGEX: Name: .test
# REGEX: Name: .test2
# REGEX: Name: .test3
# REGEX: Name: .symtab
# REGEX: Name: .strtab
# REGEX: Name: .shstrtab

View File

@ -37,6 +37,7 @@ Sections:
- Name: .alloc
Type: SHT_PROGBITS
Flags: [ SHF_ALLOC ]
Symbols: []
# ALL: SectionHeaderCount: 3
# ALL: Name: .alloc

View File

@ -17,7 +17,6 @@ Sections:
Content: "0000000000000000"
- Name: .rel.text
Type: SHT_REL
Link: .symtab
Info: .text
Relocations:
- Offset: 0x1000

View File

@ -15,6 +15,7 @@ Sections:
Address: 0x1000
AddressAlign: 0x0000000000000010
Size: 8
Symbols: []
#CHECK: Symbols [
#CHECK-NEXT: Symbol {

View File

@ -19,10 +19,8 @@ Sections:
Type: SHT_PROGBITS
Flags: [ ]
# CHECK: SectionHeaderCount: 6
# CHECK: SectionHeaderCount: 4
# CHECK: Name: .test1
# CHECK: Name: .test2
# CHECK: Name: .symtab
# CHECK: Name: .strtab
# CHECK: Name: .shstrtab

View File

@ -39,3 +39,4 @@ ProgramHeaders:
- Type: PT_LOAD
Sections:
- Section: .keep_me
Symbols: []

View File

@ -30,6 +30,7 @@ Sections:
- Name: .test3
Type: SHT_PROGBITS
Flags: [ ]
Symbols: []
# CHECK: SectionHeaderCount: 6

View File

@ -22,7 +22,7 @@ Sections:
Flags: [ SHF_ALLOC ]
Content: "37373737"
# CHECK: SectionHeaderCount: 7
# CHECK: SectionHeaderCount: 6
# CHECK: Name: .test2
# CHECK: SectionData (
@ -36,6 +36,5 @@ Sections:
# CHECK: SectionData (
# CHECK-NEXT: 0000: 37373737
# CHECK-NEXT: )
# CHECK: Name: .symtab
# CHECK: Name: .strtab
# CHECK: Name: .shstrtab

View File

@ -16,13 +16,12 @@ Sections:
Flags: [ SHF_ALLOC ]
Content: "c3c3c3c3"
# CHECK: SectionHeaderCount: 5
# CHECK: SectionHeaderCount: 4
# CHECK: Name: .bar
# CHECK: SectionData (
# CHECK-NEXT: 0000: C3C3C3C3
# CHECK-NEXT: )
# CHECK: Name: .symtab
# CHECK: Name: .strtab
# CHECK: Name: .shstrtab

View File

@ -40,6 +40,9 @@ ProgramHeaders:
PAddr: 0x3000
Sections:
- Section: .text3
## TODO (grimar): without the following line (i.e. without an empty symbol table),
## llvm-objcopy adds an empty .strtab section. It doesn't look correct.
Symbols: []
#CHECK: SectionHeaderCount: 4

View File

@ -42,6 +42,9 @@ ProgramHeaders:
- Section: .text
- Section: .text2
- Section: .text3
## TODO (grimar): without the following line (i.e. without an empty symbol table),
## llvm-objcopy adds an empty .strtab section. It doesn't look correct.
Symbols: []
# Make sure that when we remove a section we overwrite it with zeros
# DATA: {{^[^[:blank:]]+}} 00 00 00 00

View File

@ -11,7 +11,7 @@
# CHECK-NEXT: ]
# CHECK-NEXT: Address:
# CHECK-NEXT: Offset:
# CHECK-NEXT: Size: 36
# CHECK-NEXT: Size: 28
!ELF
FileHeader:

View File

@ -20,11 +20,10 @@ Sections:
- Name: .debugfoo
Type: SHT_PROGBITS
# CHECK: There are 6 section headers
# CHECK: There are 5 section headers
# CHECK: [ 0]
# CHECK-NEXT: [ 1] .text
# CHECK-NEXT: [ 2] .symtab
# CHECK-NEXT: [ 3] .strtab
# CHECK-NEXT: [ 4] .shstrtab
# CHECK-NEXT: [ 5] .gnu_debuglink
# CHECK-NEXT: [ 2] .strtab
# CHECK-NEXT: [ 3] .shstrtab
# CHECK-NEXT: [ 4] .gnu_debuglink

View File

@ -9,6 +9,7 @@ FileHeader:
Data: ELFDATA2LSB
Type: ET_REL
Machine: EM_X86_64
Symbols: []
# ERR1: error: '[[INPUT]]': string table '.strtab' cannot be removed because it is referenced by the symbol table '.symtab'
# ERR2: error: '[[INPUT]]': string table '.strtab' cannot be removed because it is referenced by the symbol table '.symtab'

View File

@ -16,6 +16,7 @@ Sections:
Link: .symtab
Type: SHT_PROGBITS
Flags: [ ]
Symbols: []
# CHECK: Name: .foo
# CHECK-NEXT: Type:

View File

@ -57,6 +57,7 @@ Sections:
Type: SHT_PROGBITS
- Name: .bar
Type: SHT_PROGBITS
Symbols: []
## Use a separate test file with special characters for the following tests.
@ -128,6 +129,7 @@ Sections:
Type: SHT_PROGBITS
- Name: .foo
Type: SHT_PROGBITS
Symbols: []
# WARN: warning: invalid glob pattern: ][]

View File

@ -64,3 +64,4 @@ Sections:
Type: SHT_PROGBITS
Flags: [ ]
Content: '11112222'
Symbols: []

View File

@ -86,7 +86,6 @@ FileHeader:
Sections:
- Name: .rela.foo
Type: SHT_RELA
Link: .symtab
Info: 0x255
Relocations:
- Offset: 0x1

View File

@ -39,6 +39,7 @@ Sections:
Entries:
- Tag: DT_NULL
Value: 0
Symbols: []
ProgramHeaders:
- Type: PT_DYNAMIC
Sections:

View File

@ -34,6 +34,7 @@ Sections:
Type: SHT_DYNAMIC
Address: 0x1000
Content: "01234567"
Symbols: []
ProgramHeaders:
- Type: PT_LOAD
VAddr: 0x1000
@ -76,6 +77,7 @@ Sections:
Value: 0
- Tag: DT_NULL
Value: 0
Symbols: []
ProgramHeaders:
- Type: PT_LOAD
VAddr: 0x1000
@ -143,6 +145,7 @@ Sections:
Value: 1
- Tag: DT_NULL
Value: 0
Symbols: []
ProgramHeaders:
- Type: PT_LOAD
VAddr: 0x1000
@ -189,6 +192,7 @@ Sections:
Value: 1
- Tag: DT_NULL
Value: 0x0
Symbols: []
ProgramHeaders:
- Type: PT_LOAD
VAddr: 0x1000
@ -231,6 +235,7 @@ Sections:
Value: 0x1000000
- Tag: DT_NULL
Value: 0x0
Symbols: []
ProgramHeaders:
- Type: PT_LOAD
VAddr: 0x1000

View File

@ -21,15 +21,15 @@
# I386-NEXT: Version: 1
# I386-NEXT: Entry: 0x0
# I386-NEXT: ProgramHeaderOffset: 0x0
# I386-NEXT: SectionHeaderOffset: 0x64
# I386-NEXT: SectionHeaderOffset: 0x48
# I386-NEXT: Flags [ (0x0)
# I386-NEXT: ]
# I386-NEXT: HeaderSize: 52
# I386-NEXT: ProgramHeaderEntrySize: 0
# I386-NEXT: ProgramHeaderCount: 0
# I386-NEXT: SectionHeaderEntrySize: 40
# I386-NEXT: SectionHeaderCount: 4
# I386-NEXT: StringTableSectionIndex: 3
# I386-NEXT: SectionHeaderCount: 3
# I386-NEXT: StringTableSectionIndex: 2
# I386-NEXT:}
# I386-NOT:{{.}}
@ -65,15 +65,15 @@ FileHeader:
# X86-64-NEXT: Version: 1
# X86-64-NEXT: Entry: 0x0
# X86-64-NEXT: ProgramHeaderOffset: 0x0
# X86-64-NEXT: SectionHeaderOffset: 0x78
# X86-64-NEXT: SectionHeaderOffset: 0x58
# X86-64-NEXT: Flags [ (0x0)
# X86-64-NEXT: ]
# X86-64-NEXT: HeaderSize: 64
# X86-64-NEXT: ProgramHeaderEntrySize: 0
# X86-64-NEXT: ProgramHeaderCount: 0
# X86-64-NEXT: SectionHeaderEntrySize: 64
# X86-64-NEXT: SectionHeaderCount: 4
# X86-64-NEXT: StringTableSectionIndex: 3
# X86-64-NEXT: SectionHeaderCount: 3
# X86-64-NEXT: StringTableSectionIndex: 2
# X86-64-NEXT:}
# X86-64-NOT:{{.}}
@ -116,14 +116,14 @@ FileHeader:
# LANAI-NEXT: Version: 1
# LANAI-NEXT: Entry: 0x0
# LANAI-NEXT: ProgramHeaderOffset: 0x0
# LANAI-NEXT: SectionHeaderOffset: 0x64
# LANAI-NEXT: SectionHeaderOffset: 0x48
# LANAI-NEXT: Flags [ (0x0)
# LANAI-NEXT: ]
# LANAI-NEXT: HeaderSize: 52
# LANAI-NEXT: ProgramHeaderEntrySize: 0
# LANAI-NEXT: ProgramHeaderCount: 0
# LANAI-NEXT: SectionHeaderEntrySize: 40
# LANAI-NEXT: SectionHeaderCount: 4
# LANAI-NEXT: StringTableSectionIndex: 3
# LANAI-NEXT: SectionHeaderCount: 3
# LANAI-NEXT: StringTableSectionIndex: 2
# LANAI-NEXT:}
# LANAI-NOT:{{.}}

View File

@ -2,7 +2,7 @@
# RUN: llvm-readelf -V %t | FileCheck %s --check-prefix=HIDDEN
# HIDDEN: Version symbols section '.gnu.version' contains 2 entries:
# HIDDEN-NEXT: Addr: 0000000000200210 Offset: 0x000040 Link: 6 (.dynsym)
# HIDDEN-NEXT: Addr: 0000000000200210 Offset: 0x000040 Link: 5 (.dynsym)
# HIDDEN-NEXT: 000: 0 (*local*) 3h(hiddensym)
--- !ELF

View File

@ -4,7 +4,7 @@
# GNU: ELF Header:
# GNU: Section header string table index: 255
# GNU-NEXT: There are 4 section headers, starting at offset 0x78:
# GNU-NEXT: There are 3 section headers, starting at offset 0x58:
# GNU: Section Headers:
# GNU-NEXT: [Nr] Name
# GNU-EMPTY:

View File

@ -2,7 +2,7 @@
# RUN: llvm-readelf -V %t | FileCheck %s --check-prefix=INVALID
# INVALID: Version symbols section '.gnu.version' contains 2 entries:
# INVALID-NEXT: Addr: 0000000000200210 Offset: 0x000040 Link: 6 (.dynsym)
# INVALID-NEXT: Addr: 0000000000200210 Offset: 0x000040 Link: 5 (.dynsym)
# INVALID-NEXT: 000: 0 (*local*) 3 (*invalid*)
--- !ELF

View File

@ -14,7 +14,7 @@
# GNU-EMPTY:
# GNU-NEXT: Section to Segment mapping:
# GNU-NEXT: Segment Sections...
# GNU-NEXT: None .symtab .strtab .shstrtab
# GNU-NEXT: None .strtab .shstrtab
--- !ELF
FileHeader:

View File

@ -41,8 +41,6 @@ Sections:
- Name: .rela.text
Type: SHT_RELA
Info: .text
Link: .symtab
- Name: .rel.text
Type: SHT_REL
Info: .text
Link: .symtab

View File

@ -91,6 +91,7 @@ Sections:
Link: .symtab
AddressAlign: 0x0000000000000001
Content: 600D0100000000000301000000000000000002000000000001050F00000000000900405005700A00
Symbols: []
...
# RUN: yaml2obj -docnum 2 %s \
@ -169,4 +170,5 @@ Sections:
Link: .symtab
AddressAlign: 0x00000001
Content: 600D0100030100000000020001050F0009004050
Symbols: []
...

View File

@ -164,12 +164,12 @@ DynamicSymbols:
# LLVM-NEXT: ]
# GNU: Version symbols section '.gnu.version' contains 6 entries:
# GNU-NEXT: Addr: 0000000000000000 Offset: 0x000040 Link: 7 (.dynsym)
# GNU-NEXT: Addr: 0000000000000000 Offset: 0x000040 Link: 6 (.dynsym)
# GNU-NEXT: 000: 0 (*local*) 2 (VERSION1) 3 (VERSION2) 4 (v1)
# GNU-NEXT: 004: 5 (v2) 6 (v3)
# GNU-EMPTY:
# GNU-NEXT: Version definition section '.gnu.version_d' contains 3 entries:
# GNU-NEXT: Addr: 0000000000000000 Offset: 0x00004c Link: 8 (.dynstr)
# GNU-NEXT: Addr: 0000000000000000 Offset: 0x00004c Link: 7 (.dynstr)
# GNU-NEXT: 0x0000: Rev: 1 Flags: none Index: 2 Cnt: 1 Name: VERSION1
# GNU-NEXT: 0x001c: Rev: 1 Flags: none Index: 3 Cnt: 2 Name: VERSION2
# GNU-NEXT: 0x0038: Parent 1: VERSION1
@ -177,7 +177,7 @@ DynamicSymbols:
# GNU-NEXT: 0x0038: Parent 1: VERSION1
# GNU-EMPTY:
# GNU-NEXT: Version needs section '.gnu.version_r' contains 2 entries:
# GNU-NEXT: Addr: 0000000000000000 Offset: 0x00008c Link: 8 (.dynstr)
# GNU-NEXT: Addr: 0000000000000000 Offset: 0x00008c Link: 7 (.dynstr)
# GNU-NEXT: 0x0000: Version: 1 File: verneed1.so.0 Cnt: 2
# GNU-NEXT: 0x0010: Name: v1 Flags: none Version: 4
# GNU-NEXT: 0x0020: Name: v2 Flags: none Version: 5

View File

@ -15,7 +15,7 @@
# GNU: Section Headers:
# GNU: [Nr] Name Type Address Off Size ES Flg Lk Inf Al
# GNU: warning: '[[FILE]]': invalid sh_type for string table section [index 1]: expected SHT_STRTAB, but got SHT_PROGBITS
# GNU: [ 1] .shstrtab PROGBITS 0000000000000000 000040 00001b 00 0 0 0
# GNU: [ 1] .shstrtab PROGBITS 0000000000000000 000040 000013 00 0 0 0
## Test we report multiple identical warnings (one for each object) when dumping an archive.

View File

@ -140,7 +140,6 @@ Sections:
Content: 00
- Name: .rela.text
Type: SHT_RELA
Link: .symtab
AddressAlign: 0x0000000000000008
EntSize: 0x0000000000000018
Info: .text

View File

@ -149,7 +149,6 @@ Sections:
Content: 00
- Name: .rel.text
Type: SHT_REL
Link: .symtab
AddressAlign: 0x0000000000000004
EntSize: 0x0000000000000008
Info: .text

View File

@ -26,7 +26,6 @@ Sections:
Content: 00
- Name: .rela.text
Type: SHT_RELA
Link: .symtab
AddressAlign: 0x0000000000000004
EntSize: 0x000000000000000C
Info: .text

View File

@ -70,7 +70,6 @@ Sections:
Content: 00
- Name: .rel.text
Type: SHT_REL
Link: .symtab
AddressAlign: 0x0000000000000004
EntSize: 0x0000000000000008
Info: .text

View File

@ -70,7 +70,6 @@ Sections:
Content: 00
- Name: .rela.text
Type: SHT_RELA
Link: .symtab
AddressAlign: 0x0000000000000008
EntSize: 0x0000000000000018
Info: .text

View File

@ -62,7 +62,6 @@ Symbols:
# INVALID-ENTRY: - Name: .llvm_addrsig
# INVALID-ENTRY-NEXT: Type: SHT_LLVM_ADDRSIG
# INVALID-ENTRY-NEXT: Link: .symtab
# INVALID-ENTRY-NEXT: Content: FFFFFFFFFF
--- !ELF
@ -83,7 +82,6 @@ Sections:
# EMPTY: - Name: .llvm_addrsig
# EMPTY-NEXT: Type: SHT_LLVM_ADDRSIG
# EMPTY-NEXT: Link: .symtab
# EMPTY-NEXT: Symbols: []
--- !ELF

View File

@ -0,0 +1,43 @@
## Check that obj2yaml doesn't create a "Symbols" tag for the objects
## without a symbol table.
# RUN: yaml2obj --docnum=1 %s -o %t1
# RUN: obj2yaml %t1 | FileCheck %s --check-prefix=NOSYMTAB
# NOSYMTAB: --- !ELF
# NOSYMTAB-NEXT: FileHeader:
# NOSYMTAB-NEXT: Class: ELFCLASS64
# NOSYMTAB-NEXT: Data: ELFDATA2LSB
# NOSYMTAB-NEXT: Type: ET_DYN
# NOSYMTAB-NEXT: Machine: EM_X86_64
# NOSYMTAB-NEXT: ...
--- !ELF
FileHeader:
Class: ELFCLASS64
Data: ELFDATA2LSB
Type: ET_DYN
Machine: EM_X86_64
## Check that obj2yaml creates a "Symbols" tag for the objects
## that have a symbol table.
# RUN: yaml2obj --docnum=2 %s -o %t2
# RUN: obj2yaml %t2 | FileCheck %s --check-prefix=SYMTAB
# SYMTAB: --- !ELF
# SYMTAB-NEXT: FileHeader:
# SYMTAB-NEXT: Class: ELFCLASS64
# SYMTAB-NEXT: Data: ELFDATA2LSB
# SYMTAB-NEXT: Type: ET_DYN
# SYMTAB-NEXT: Machine: EM_X86_64
# SYMTAB-NEXT: Symbols: []
# SYMTAB-NEXT: ...
--- !ELF
FileHeader:
Class: ELFCLASS64
Data: ELFDATA2LSB
Type: ET_DYN
Machine: EM_X86_64
Symbols: []

View File

@ -142,6 +142,7 @@ Sections:
Type: SHT_SYMTAB_SHNDX
Entries: [ 0 ]
Link: .symtab
Symbols: []
## Check that yaml2obj can't dump the object if SHT_SYMTAB_SHNDX is
## not associated with a SHT_SYMTAB section (this case is illegal).

View File

@ -26,6 +26,7 @@
# CHECK-NEXT: - Offset: 0x0000000000000004
# CHECK-NEXT: Symbol: ''
# CHECK-NEXT: Type: R_X86_64_NONE
# CHECK-NEXT: Symbols: []
# CHECK-NEXT: ...
--- !ELF

View File

@ -66,5 +66,6 @@ Sections:
Info: 0xFF
Members:
- SectionOrType: GRP_COMDAT
Symbols: []
# ERR: Error reading file: {{.*}}2.o: unable to get symbol from section [index 2]: invalid symbol index (255)

View File

@ -52,7 +52,7 @@ DynamicSymbols:
# NUM: Name: bar
# NUM: Section:
# NUM-SAME: .symtab (0x2)
# NUM-SAME: .strtab (0x2)
# NUM: error: '[[FILE]]': invalid section index: 255

View File

@ -12,7 +12,6 @@ FileHeader:
Sections:
- Name: .group
Type: SHT_GROUP
Link: .symtab
Info: 12345
Members:
- SectionOrType: GRP_COMDAT

View File

@ -8,9 +8,8 @@
# DEFAULT: Section Headers:
# DEFAULT-NEXT: [Nr] Name Type Address Off Size ES Flg Lk Inf Al
# DEFAULT-NEXT: [ 0] NULL 0000000000000000 000000 000000 00 0 0 0
# DEFAULT-NEXT: [ 1] .symtab SYMTAB 0000000000000000 000040 000018 18 2 1 8
# DEFAULT-NEXT: [ 2] .strtab STRTAB 0000000000000000 000058 000001 00 0 0 1
# DEFAULT-NEXT: [ 3] .shstrtab STRTAB 0000000000000000 000059 00001b 00 0 0 1
# DEFAULT-NEXT: [ 1] .strtab STRTAB 0000000000000000 000040 000001 00 0 0 1
# DEFAULT-NEXT: [ 2] .shstrtab STRTAB 0000000000000000 000041 000013 00 0 0 1
--- !ELF
FileHeader:
@ -105,9 +104,8 @@ Sections:
# OTHER-SECTION-NEXT: [Nr] Name Type Address Off Size ES Flg Lk Inf Al
# OTHER-SECTION-NEXT: [ 0] NULL 0000000000000000 000000 000000 00 0 0 0
# OTHER-SECTION-NEXT: [ 1] foo PROGBITS 0000000000000000 000040 000000 00 0 0 0
# OTHER-SECTION-NEXT: [ 2] .symtab SYMTAB 0000000000000000 000040 000018 18 3 1 8
# OTHER-SECTION-NEXT: [ 3] .strtab STRTAB 0000000000000000 000058 000001 00 0 0 1
# OTHER-SECTION-NEXT: [ 4] .shstrtab STRTAB 0000000000000000 000059 00001f 00 0 0 1
# OTHER-SECTION-NEXT: [ 2] .strtab STRTAB 0000000000000000 000040 000001 00 0 0 1
# OTHER-SECTION-NEXT: [ 3] .shstrtab STRTAB 0000000000000000 000041 000017 00 0 0 1
--- !ELF
FileHeader:

View File

@ -6,10 +6,10 @@
# RUN: yaml2obj --docnum=1 %s -o %t1
# RUN: llvm-readelf --file-headers %t1 | FileCheck %s --check-prefix=DEFAULT
# DEFAULT: Start of section headers: 120 (bytes into file)
# DEFAULT: Start of section headers: 88 (bytes into file)
# DEFAULT: Size of section headers: 64 (bytes)
# DEFAULT: Number of section headers: 4
# DEFAULT: Section header string table index: 3
# DEFAULT: Number of section headers: 3
# DEFAULT: Section header string table index: 2
--- !ELF
FileHeader:

View File

@ -126,4 +126,3 @@ Sections:
Type: SHT_SYMTAB_SHNDX
Entries: [ 0 ]
EntSize: 2
Link: .symtab

View File

@ -24,6 +24,8 @@ FileHeader:
Data: ELFDATA2LSB
Type: ET_DYN
Machine: EM_X86_64
## Needed to force the creation of the .symtab.
Symbols: []
## Needed to force the creation of the .dynsym and .dynstr.
DynamicSymbols:
- Name: foo

View File

@ -84,3 +84,30 @@ Sections:
- Name: .text.foo
Type: SHT_PROGBITS
Address: 0x200
## Check we don't add a symbol table when no "Symbols" key is specified.
# RUN: yaml2obj --docnum=3 %s -o %t3
# RUN: llvm-readelf -S %t3 | FileCheck /dev/null --implicit-check-not=.symtab
--- !ELF
FileHeader:
Class: ELFCLASS64
Data: ELFDATA2LSB
Type: ET_DYN
Machine: EM_X86_64
## Check we add a symbol table when "Symbols" key is specified.
# RUN: yaml2obj --docnum=4 %s -o %t4
# RUN: llvm-readelf -S %t4 | FileCheck %s --check-prefix=SYMTAB
# SYMTAB: .symtab
--- !ELF
FileHeader:
Class: ELFCLASS64
Data: ELFDATA2LSB
Type: ET_DYN
Machine: EM_X86_64
Symbols: []

View File

@ -16,7 +16,6 @@ Sections:
Content: "00000000"
- Name: .rel.text
Type: SHT_REL
Link: .symtab
Info: .text
Relocations:
- Offset: 0x1000

View File

@ -20,7 +20,6 @@ FileHeader:
Sections:
- Name: .rela.text
Type: SHT_RELA
Link: .symtab
Info: 12345
Relocations:

View File

@ -14,7 +14,6 @@ Sections:
Content: "00000000"
- Name: .rel.text
Type: SHT_REL
Link: .symtab
Info: .text
Relocations:
- Offset: 0x1000

View File

@ -77,3 +77,4 @@ FileHeader:
Data: ELFDATA2LSB
Type: ET_DYN
Machine: EM_X86_64
Symbols: []

View File

@ -200,9 +200,13 @@ template <class ELFT> Expected<ELFYAML::Object *> ELFDumper<ELFT>::dump() {
return TableOrErr.takeError();
ShndxTable = *TableOrErr;
}
if (SymTab)
if (Error E = dumpSymbols(SymTab, Y->Symbols))
if (SymTab) {
Y->Symbols.emplace();
if (Error E = dumpSymbols(SymTab, *Y->Symbols))
return std::move(E);
}
if (DynSymTab)
if (Error E = dumpSymbols(DynSymTab, Y->DynamicSymbols))
return std::move(E);