// 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;
};
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(
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"});
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);
}
};
- 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.
Type: SHT_SYMTAB_SHNDX
Entries: [ 0, 1 ]
Link: .symtab
+Symbols: []
## Check that llvm-readobj reports an error if the e_phentsize field is broken.
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
- 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).
# 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:
- Name: .rela.text
Type: SHT_RELA
Address: 0x0000000000000038
- Link: .symtab
Info: .text
Relocations:
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
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
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
Type: SHT_PROGBITS
Flags: [ ]
-# CHECK: SectionHeaderCount: 5
+# CHECK: SectionHeaderCount: 3
# CHECK: Name: .test
-# CHECK: Name: .symtab
-# CHECK: Name: .strtab
# CHECK: Name: .shstrtab
Type: SHT_PROGBITS
Flags: [ ]
-# CHECK: SectionHeaderCount: 5
+# CHECK: SectionHeaderCount: 4
# CHECK: Name: .test
-# CHECK: Name: .symtab
# CHECK: Name: .strtab
# CHECK: Name: .shstrtab
Type: SHT_PROGBITS
Flags: [ ]
-# CHECK: SectionHeaderCount: 5
+# CHECK: SectionHeaderCount: 3
# CHECK: Name: .test
-# CHECK: Name: .symtab
-# CHECK: Name: .strtab
# CHECK: Name: .shstrtab
Sections:
- Name: .foo
Type: SHT_PROGBITS
+Symbols: []
# CASE2: error: '[[INPUT]]': section header table goes past the end of the file: e_shoff = 0x40000000
- 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
- Name: .alloc
Type: SHT_PROGBITS
Flags: [ SHF_ALLOC ]
+Symbols: []
# ALL: SectionHeaderCount: 3
# ALL: Name: .alloc
Content: "0000000000000000"
- Name: .rel.text
Type: SHT_REL
- Link: .symtab
Info: .text
Relocations:
- Offset: 0x1000
Address: 0x1000
AddressAlign: 0x0000000000000010
Size: 8
+Symbols: []
#CHECK: Symbols [
#CHECK-NEXT: Symbol {
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
- Type: PT_LOAD
Sections:
- Section: .keep_me
+Symbols: []
- Name: .test3
Type: SHT_PROGBITS
Flags: [ ]
+Symbols: []
# CHECK: SectionHeaderCount: 6
Flags: [ SHF_ALLOC ]
Content: "37373737"
-# CHECK: SectionHeaderCount: 7
+# CHECK: SectionHeaderCount: 6
# CHECK: Name: .test2
# CHECK: SectionData (
# CHECK: SectionData (
# CHECK-NEXT: 0000: 37373737
# CHECK-NEXT: )
-# CHECK: Name: .symtab
# CHECK: Name: .strtab
# CHECK: Name: .shstrtab
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
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
- 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
# CHECK-NEXT: ]
# CHECK-NEXT: Address:
# CHECK-NEXT: Offset:
-# CHECK-NEXT: Size: 36
+# CHECK-NEXT: Size: 28
!ELF
FileHeader:
- 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
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'
Link: .symtab
Type: SHT_PROGBITS
Flags: [ ]
+Symbols: []
# CHECK: Name: .foo
# CHECK-NEXT: Type:
Type: SHT_PROGBITS
- Name: .bar
Type: SHT_PROGBITS
+Symbols: []
## Use a separate test file with special characters for the following tests.
Type: SHT_PROGBITS
- Name: .foo
Type: SHT_PROGBITS
+Symbols: []
# WARN: warning: invalid glob pattern: ][]
Type: SHT_PROGBITS
Flags: [ ]
Content: '11112222'
+Symbols: []
Sections:
- Name: .rela.foo
Type: SHT_RELA
- Link: .symtab
Info: 0x255
Relocations:
- Offset: 0x1
Entries:
- Tag: DT_NULL
Value: 0
+Symbols: []
ProgramHeaders:
- Type: PT_DYNAMIC
Sections:
Type: SHT_DYNAMIC
Address: 0x1000
Content: "01234567"
+Symbols: []
ProgramHeaders:
- Type: PT_LOAD
VAddr: 0x1000
Value: 0
- Tag: DT_NULL
Value: 0
+Symbols: []
ProgramHeaders:
- Type: PT_LOAD
VAddr: 0x1000
Value: 1
- Tag: DT_NULL
Value: 0
+Symbols: []
ProgramHeaders:
- Type: PT_LOAD
VAddr: 0x1000
Value: 1
- Tag: DT_NULL
Value: 0x0
+Symbols: []
ProgramHeaders:
- Type: PT_LOAD
VAddr: 0x1000
Value: 0x1000000
- Tag: DT_NULL
Value: 0x0
+Symbols: []
ProgramHeaders:
- Type: PT_LOAD
VAddr: 0x1000
# 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:{{.}}
# 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:{{.}}
# 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:{{.}}
# 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
# 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:
# 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
# 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:
- Name: .rela.text
Type: SHT_RELA
Info: .text
- Link: .symtab
- Name: .rel.text
Type: SHT_REL
Info: .text
- Link: .symtab
Link: .symtab
AddressAlign: 0x0000000000000001
Content: 600D0100000000000301000000000000000002000000000001050F00000000000900405005700A00
+Symbols: []
...
# RUN: yaml2obj -docnum 2 %s \
Link: .symtab
AddressAlign: 0x00000001
Content: 600D0100030100000000020001050F0009004050
+Symbols: []
...
# 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
# 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
# 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.
Content: 00
- Name: .rela.text
Type: SHT_RELA
- Link: .symtab
AddressAlign: 0x0000000000000008
EntSize: 0x0000000000000018
Info: .text
Content: 00
- Name: .rel.text
Type: SHT_REL
- Link: .symtab
AddressAlign: 0x0000000000000004
EntSize: 0x0000000000000008
Info: .text
Content: 00
- Name: .rela.text
Type: SHT_RELA
- Link: .symtab
AddressAlign: 0x0000000000000004
EntSize: 0x000000000000000C
Info: .text
Content: 00
- Name: .rel.text
Type: SHT_REL
- Link: .symtab
AddressAlign: 0x0000000000000004
EntSize: 0x0000000000000008
Info: .text
Content: 00
- Name: .rela.text
Type: SHT_RELA
- Link: .symtab
AddressAlign: 0x0000000000000008
EntSize: 0x0000000000000018
Info: .text
# INVALID-ENTRY: - Name: .llvm_addrsig
# INVALID-ENTRY-NEXT: Type: SHT_LLVM_ADDRSIG
-# INVALID-ENTRY-NEXT: Link: .symtab
# INVALID-ENTRY-NEXT: Content: FFFFFFFFFF
--- !ELF
# EMPTY: - Name: .llvm_addrsig
# EMPTY-NEXT: Type: SHT_LLVM_ADDRSIG
-# EMPTY-NEXT: Link: .symtab
# EMPTY-NEXT: Symbols: []
--- !ELF
--- /dev/null
+## 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: []
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).
# CHECK-NEXT: - Offset: 0x0000000000000004
# CHECK-NEXT: Symbol: ''
# CHECK-NEXT: Type: R_X86_64_NONE
+# CHECK-NEXT: Symbols: []
# CHECK-NEXT: ...
--- !ELF
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)
# NUM: Name: bar
# NUM: Section:
-# NUM-SAME: .symtab (0x2)
+# NUM-SAME: .strtab (0x2)
# NUM: error: '[[FILE]]': invalid section index: 255
Sections:
- Name: .group
Type: SHT_GROUP
- Link: .symtab
Info: 12345
Members:
- SectionOrType: GRP_COMDAT
# 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:
# 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:
# 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:
Type: SHT_SYMTAB_SHNDX
Entries: [ 0 ]
EntSize: 2
- Link: .symtab
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
- 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: []
Content: "00000000"
- Name: .rel.text
Type: SHT_REL
- Link: .symtab
Info: .text
Relocations:
- Offset: 0x1000
Sections:
- Name: .rela.text
Type: SHT_RELA
- Link: .symtab
Info: 12345
Relocations:
Content: "00000000"
- Name: .rel.text
Type: SHT_REL
- Link: .symtab
Info: .text
Relocations:
- Offset: 0x1000
Data: ELFDATA2LSB
Type: ET_DYN
Machine: EM_X86_64
+Symbols: []
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);