summaryrefslogtreecommitdiffstats
path: root/llvm/test
diff options
context:
space:
mode:
Diffstat (limited to 'llvm/test')
-rw-r--r--llvm/test/Object/obj2yaml.test7
-rw-r--r--llvm/test/Object/yaml2obj-elf-section-invalid-size.yaml2
-rw-r--r--llvm/test/tools/obj2yaml/elf-shinfo.yaml1
-rw-r--r--llvm/test/tools/yaml2obj/dynsymtab-implicit-sections-size-content.yaml222
-rw-r--r--llvm/test/tools/yaml2obj/section-size-content.yaml158
-rw-r--r--llvm/test/tools/yaml2obj/strtab-implicit-sections-size-content.yaml167
-rw-r--r--llvm/test/tools/yaml2obj/symtab-implicit-sections-size-content.yaml190
7 files changed, 738 insertions, 9 deletions
diff --git a/llvm/test/Object/obj2yaml.test b/llvm/test/Object/obj2yaml.test
index fbceca5413e..043bf7951be 100644
--- a/llvm/test/Object/obj2yaml.test
+++ b/llvm/test/Object/obj2yaml.test
@@ -389,7 +389,6 @@ ELF-MIPSEL-NEXT: - Name: .data
ELF-MIPSEL-NEXT: Type: SHT_PROGBITS
ELF-MIPSEL-NEXT: Flags: [ SHF_WRITE, SHF_ALLOC ]
ELF-MIPSEL-NEXT: AddressAlign: 0x0000000000000004
-ELF-MIPSEL-NEXT: Content: ''
ELF-MIPSEL-NEXT: - Name: .bss
ELF-MIPSEL-NEXT: Type: SHT_NOBITS
ELF-MIPSEL-NEXT: Flags: [ SHF_WRITE, SHF_ALLOC ]
@@ -398,7 +397,6 @@ ELF-MIPSEL-NEXT: Size: 0x0000000000000004
ELF-MIPSEL-NEXT: - Name: .mdebug.abi32
ELF-MIPSEL-NEXT: Type: SHT_PROGBITS
ELF-MIPSEL-NEXT: AddressAlign: 0x0000000000000001
-ELF-MIPSEL-NEXT: Content: ''
ELF-MIPSEL-NEXT: - Name: .rodata.str1.1
ELF-MIPSEL-NEXT: Type: SHT_PROGBITS
ELF-MIPSEL-NEXT: Flags: [ SHF_ALLOC, SHF_MERGE, SHF_STRINGS ]
@@ -477,7 +475,6 @@ ELF-MIPS64EL-NEXT: - Name: .text
ELF-MIPS64EL-NEXT: Type: SHT_PROGBITS
ELF-MIPS64EL-NEXT: Flags: [ SHF_ALLOC, SHF_EXECINSTR ]
ELF-MIPS64EL-NEXT: AddressAlign: 0x0000000000000010
-ELF-MIPS64EL-NEXT: Content: ''
ELF-MIPS64EL-NEXT: - Name: .data
ELF-MIPS64EL-NEXT: Type: SHT_PROGBITS
ELF-MIPS64EL-NEXT: Flags: [ SHF_WRITE, SHF_ALLOC ]
@@ -506,7 +503,6 @@ ELF-MIPS64EL-NEXT: Content: '012800000000000000000000000000000000000
ELF-MIPS64EL-NEXT: - Name: .pdr
ELF-MIPS64EL-NEXT: Type: SHT_PROGBITS
ELF-MIPS64EL-NEXT: AddressAlign: 0x0000000000000004
-ELF-MIPS64EL-NEXT: Content: ''
ELF-MIPS64EL-NEXT: Symbols:
ELF-MIPS64EL-NEXT: - Name: .text
ELF-MIPS64EL-NEXT: Type: STT_SECTION
@@ -550,7 +546,6 @@ ELF-X86-64-NEXT: - Name: .note.GNU-stack
ELF-X86-64-NEXT: Type: SHT_PROGBITS
ELF-X86-64-NEXT: Address: 0x0000000000000033
ELF-X86-64-NEXT: AddressAlign: 0x0000000000000001
-ELF-X86-64-NEXT: Content: ''
ELF-X86-64-NEXT: - Name: .rela.text
ELF-X86-64-NEXT: Type: SHT_RELA
ELF-X86-64-NEXT: Address: 0x0000000000000038
@@ -610,7 +605,6 @@ ELF-AVR-NEXT: Type: SHT_PROGBITS
ELF-AVR-NEXT: Flags: [ SHF_WRITE, SHF_ALLOC ]
ELF-AVR-NEXT: Address: 0x0000000000800060
ELF-AVR-NEXT: AddressAlign: 0x0000000000000001
-ELF-AVR-NEXT: Content: ''
ELF-AVR-NEXT: Symbols:
ELF-AVR-NEXT: - Name: .text
ELF-AVR-NEXT: Type: STT_SECTION
@@ -706,7 +700,6 @@ ELF-X86-64-UNWIND: - Name: .eh_frame
ELF-X86-64-UNWIND-NEXT: Type: SHT_X86_64_UNWIND
ELF-X86-64-UNWIND-NEXT: Flags: [ SHF_ALLOC ]
ELF-X86-64-UNWIND-NEXT: AddressAlign: 0x0000000000000001
-ELF-X86-64-UNWIND-NEXT: Content: ''
RUN: not obj2yaml %t.blah 2>&1 | FileCheck --check-prefix=ENOENT %s
ENOENT: Error reading file: {{.*}}.blah: {{[Nn]}}o such file or directory
diff --git a/llvm/test/Object/yaml2obj-elf-section-invalid-size.yaml b/llvm/test/Object/yaml2obj-elf-section-invalid-size.yaml
index b896c9d6afc..b9086c6d1ca 100644
--- a/llvm/test/Object/yaml2obj-elf-section-invalid-size.yaml
+++ b/llvm/test/Object/yaml2obj-elf-section-invalid-size.yaml
@@ -20,7 +20,7 @@ Sections:
Content: 0000000000000000
Size: 2
-# CHECK: YAML:17:5: error: Section size must be greater or equal to the content size
+# CHECK: YAML:17:5: error: Section size must be greater than or equal to the content size
# CHECK-NEXT: - Name: .data
# CHECK-NEXT: ^
# CHECK-NEXT: yaml2obj: Failed to parse YAML file!
diff --git a/llvm/test/tools/obj2yaml/elf-shinfo.yaml b/llvm/test/tools/obj2yaml/elf-shinfo.yaml
index e77fc62e9d0..6187cdbae92 100644
--- a/llvm/test/tools/obj2yaml/elf-shinfo.yaml
+++ b/llvm/test/tools/obj2yaml/elf-shinfo.yaml
@@ -5,7 +5,6 @@
# CHECK: - Name: .test
# CHECK-NEXT: Type: SHT_PROGBITS
-# CHECK-NEXT: Content: ''
# CHECK-NEXT: Info: 0x000000000000002A
--- !ELF
diff --git a/llvm/test/tools/yaml2obj/dynsymtab-implicit-sections-size-content.yaml b/llvm/test/tools/yaml2obj/dynsymtab-implicit-sections-size-content.yaml
new file mode 100644
index 00000000000..9833cb45584
--- /dev/null
+++ b/llvm/test/tools/yaml2obj/dynsymtab-implicit-sections-size-content.yaml
@@ -0,0 +1,222 @@
+## For implicit dynamic symbol table sections, `Size` and/or `Content`
+## fields can also be specified in YAML. Here we test the behavior in
+## different cases.
+
+## When no `Size` or `Content` is specified for a dynamic symbol table section,
+## yaml2obj writes the default content.
+
+# RUN: yaml2obj --docnum=1 %s -o %t1
+# RUN: llvm-readelf %t1 --dyn-symbols | FileCheck %s --check-prefix=CASE1
+
+# CASE1: Symbol table '.dynsym' contains 2 entries:
+# CASE1-NEXT: Num: Value Size Type Bind Vis Ndx Name
+# CASE1-NEXT: 0: 0000000000000000 0 NOTYPE LOCAL DEFAULT UND
+# CASE1-NEXT: 1: 0000000000000000 0 NOTYPE GLOBAL DEFAULT UND foo
+# CASE1-EMPTY:
+
+--- !ELF
+FileHeader:
+ Class: ELFCLASS64
+ Data: ELFDATA2LSB
+ Type: ET_DYN
+ Machine: EM_X86_64
+Sections:
+ - Name: .dynsym
+ Type: SHT_DYNSYM
+DynamicSymbols:
+ - Name: foo
+ Binding: STB_GLOBAL
+
+## Specifying both `Size` and symbols at the same time is not allowed.
+# RUN: not yaml2obj --docnum=2 %s -o %t2 2>&1 | FileCheck %s --check-prefix=CASE2
+
+# CASE2: error: Cannot specify both `Size` and `DynamicSymbols` for symbol table section '.dynsym'.
+
+--- !ELF
+FileHeader:
+ Class: ELFCLASS64
+ Data: ELFDATA2LSB
+ Type: ET_DYN
+ Machine: EM_X86_64
+Sections:
+ - Name: .dynsym
+ Type: SHT_DYNSYM
+ Size: 0x100
+DynamicSymbols:
+ - Name: foo
+ Binding: STB_GLOBAL
+
+## Specifying both `Content` and symbols at the same time is not allowed.
+# RUN: not yaml2obj --docnum=3 %s -o %t3 2>&1 | FileCheck %s --check-prefix=CASE3
+
+# CASE3: error: Cannot specify both `Content` and `DynamicSymbols` for symbol table section '.dynsym'.
+
+--- !ELF
+FileHeader:
+ Class: ELFCLASS64
+ Data: ELFDATA2LSB
+ Type: ET_DYN
+ Machine: EM_X86_64
+Sections:
+ - Name: .dynsym
+ Type: SHT_DYNSYM
+ Content: "00"
+DynamicSymbols:
+ - Name: foo
+ Binding: STB_GLOBAL
+
+## Check we can use just `Content` to emit custom data in the symbol table section.
+# RUN: yaml2obj --docnum=4 %s -o %t4
+# RUN: llvm-readobj --section-data -S %t4 | FileCheck %s --check-prefix=CASE4
+
+# CASE4: Name: .dynsym
+# CASE4-NEXT: Type: SHT_DYNSYM
+# CASE4-NEXT: Flags [
+# CASE4-NEXT: SHF_ALLOC
+# CASE4-NEXT: ]
+# CASE4-NEXT: Address: 0x0
+# CASE4-NEXT: Offset: 0x1C0
+# CASE4-NEXT: Size: 2
+# CASE4-NEXT: Link: 2
+# CASE4-NEXT: Info: 0
+# CASE4-NEXT: AddressAlignment: 0
+# CASE4-NEXT: EntrySize: 24
+# CASE4-NEXT: SectionData (
+# CASE4-NEXT: 0000: 0123
+# CASE4-NEXT: )
+
+--- !ELF
+FileHeader:
+ Class: ELFCLASS64
+ Data: ELFDATA2LSB
+ Type: ET_DYN
+ Machine: EM_X86_64
+Sections:
+ - Name: .dynsym
+ Type: SHT_DYNSYM
+ Content: "0123"
+## TODO: .dynstr here is needed to set a proper Link for .dynsym.
+## Without this, llvm-readobj reports an error.
+## See https://bugs.llvm.org/show_bug.cgi?id=42215.
+ - Name: .dynstr
+ Type: SHT_STRTAB
+ Content: "00"
+
+## Check we can use just `Size` to emit custom data filled with zeroes
+## in the symbol table section.
+# RUN: yaml2obj --docnum=5 %s -o %t5
+# RUN: llvm-readobj --section-data -S %t5 | FileCheck %s --check-prefix=CASE5
+
+# CASE5: Name: .dynsym
+# CASE5-NEXT: Type: SHT_DYNSYM
+# CASE5-NEXT: Flags [
+# CASE5-NEXT: SHF_ALLOC
+# CASE5-NEXT: ]
+# CASE5-NEXT: Address: 0x0
+# CASE5-NEXT: Offset: 0x1C0
+# CASE5-NEXT: Size: 5
+# CASE5-NEXT: Link: 2
+# CASE5-NEXT: Info: 0
+# CASE5-NEXT: AddressAlignment: 0
+# CASE5-NEXT: EntrySize: 24
+# CASE5-NEXT: SectionData (
+# CASE5-NEXT: 0000: 00000000 00
+# CASE5-NEXT: )
+
+--- !ELF
+FileHeader:
+ Class: ELFCLASS64
+ Data: ELFDATA2LSB
+ Type: ET_DYN
+ Machine: EM_X86_64
+Sections:
+ - Name: .dynsym
+ Type: SHT_DYNSYM
+ Size: 5
+## TODO: .dynstr here is needed to set a proper Link for .dynsym.
+## Without this, llvm-readobj reports an error.
+## See https://bugs.llvm.org/show_bug.cgi?id=42215.
+ - Name: .dynstr
+ Type: SHT_STRTAB
+ Content: "00"
+
+## Check we can specify both `Size` and `Content` when size is greater
+## than content size. In this case zeroes are added as padding
+## after after the specified content.
+
+# RUN: yaml2obj --docnum=6 %s -o %t6
+# RUN: llvm-readobj %t6 --section-data -S | FileCheck %s --check-prefix=CASE6
+
+# CASE6: Name: .dynsym
+# CASE6-NEXT: Type: SHT_DYNSYM
+# CASE6-NEXT: Flags [
+# CASE6-NEXT: SHF_ALLOC
+# CASE6-NEXT: ]
+# CASE6-NEXT: Address: 0x0
+# CASE6-NEXT: Offset: 0x1C0
+# CASE6-NEXT: Size: 4
+# CASE6-NEXT: Link: 2
+# CASE6-NEXT: Info: 0
+# CASE6-NEXT: AddressAlignment: 0
+# CASE6-NEXT: EntrySize: 24
+# CASE6-NEXT: SectionData (
+# CASE6-NEXT: 0000: 01230000
+# CASE6-NEXT: )
+
+--- !ELF
+FileHeader:
+ Class: ELFCLASS64
+ Data: ELFDATA2LSB
+ Type: ET_DYN
+ Machine: EM_X86_64
+Sections:
+ - Name: .dynsym
+ Type: SHT_DYNSYM
+ Content: "0123"
+ Size: 4
+## TODO: .dynstr here is needed to set a proper Link for .dynsym.
+## Without this, llvm-readobj reports an error.
+## See https://bugs.llvm.org/show_bug.cgi?id=42215.
+ - Name: .dynstr
+ Type: SHT_STRTAB
+ Content: "00"
+
+## Check we can specify both `Size` and `Content` when size is
+## equal to content size.
+
+# RUN: yaml2obj --docnum=7 %s -o %t7
+# RUN: llvm-readobj --section-data -S %t7 | FileCheck %s --check-prefix=CASE7
+
+# CASE7: Name: .dynsym
+# CASE7-NEXT: Type: SHT_DYNSYM
+# CASE7-NEXT: Flags [
+# CASE7-NEXT: SHF_ALLOC
+# CASE7-NEXT: ]
+# CASE7-NEXT: Address: 0x0
+# CASE7-NEXT: Offset: 0x1C0
+# CASE7-NEXT: Size: 2
+# CASE7-NEXT: Link: 2
+# CASE7-NEXT: Info: 0
+# CASE7-NEXT: AddressAlignment: 0
+# CASE7-NEXT: EntrySize: 24
+# CASE7-NEXT: SectionData (
+# CASE7-NEXT: 0000: 0123
+# CASE7-NEXT: )
+
+--- !ELF
+FileHeader:
+ Class: ELFCLASS64
+ Data: ELFDATA2LSB
+ Type: ET_DYN
+ Machine: EM_X86_64
+Sections:
+ - Name: .dynsym
+ Type: SHT_DYNSYM
+ Content: "0123"
+ Size: 2
+## TODO: .dynstr here is needed to set a proper Link for .dynsym.
+## Without this, llvm-readobj reports an error.
+## See https://bugs.llvm.org/show_bug.cgi?id=42215.
+ - Name: .dynstr
+ Type: SHT_STRTAB
+ Content: "00"
diff --git a/llvm/test/tools/yaml2obj/section-size-content.yaml b/llvm/test/tools/yaml2obj/section-size-content.yaml
new file mode 100644
index 00000000000..8a94cb4d6a8
--- /dev/null
+++ b/llvm/test/tools/yaml2obj/section-size-content.yaml
@@ -0,0 +1,158 @@
+## For regular sections, it is common to specify `Size` and/or `Content` fields in YAML.
+## Here we test the behavior in different cases.
+
+## In this case, we have both `Content` and `Size` fields specified and `Size`
+## is less than content size. Check we report an error.
+
+# RUN: not yaml2obj --docnum=1 %s -o %t1 2>&1 | FileCheck %s --check-prefix=ERR
+# ERR: error: Section size must be greater than or equal to the content size
+
+--- !ELF
+FileHeader:
+ Class: ELFCLASS64
+ Data: ELFDATA2LSB
+ Type: ET_DYN
+ Machine: EM_X86_64
+Sections:
+ - Name: .foo
+ Type: SHT_PROGBITS
+ Content: "FF"
+ Size: 0
+
+## In this case, we have both `Content` and `Size` fields specified and
+## `Size` is equal to the content size. We check that this is allowed and
+## that the output section has a correct size value.
+
+# RUN: yaml2obj --docnum=2 %s -o %t2
+# RUN: llvm-readobj --section-data -S %t2 | FileCheck %s --check-prefix=CASE2
+
+# CASE2: Name: .foo
+# CASE2-NEXT: Type: SHT_PROGBITS
+# CASE2-NEXT: Flags [
+# CASE2-NEXT: ]
+# CASE2-NEXT: Address: 0x0
+# CASE2-NEXT: Offset: 0x180
+# CASE2-NEXT: Size: 1
+# CASE2-NEXT: Link: 0
+# CASE2-NEXT: Info: 0
+# CASE2-NEXT: AddressAlignment: 0
+# CASE2-NEXT: EntrySize: 0
+# CASE2-NEXT: SectionData (
+# CASE2-NEXT: 0000: FF
+# CASE2-NEXT: )
+
+--- !ELF
+FileHeader:
+ Class: ELFCLASS64
+ Data: ELFDATA2LSB
+ Type: ET_DYN
+ Machine: EM_X86_64
+Sections:
+ - Name: .foo
+ Type: SHT_PROGBITS
+ Content: "FF"
+ Size: 1
+
+## Check we can specify only `Content`.
+
+# RUN: yaml2obj --docnum=3 %s -o %t3
+# RUN: llvm-readobj --section-data -S %t3 | FileCheck %s --check-prefix=CASE2
+
+--- !ELF
+FileHeader:
+ Class: ELFCLASS64
+ Data: ELFDATA2LSB
+ Type: ET_DYN
+ Machine: EM_X86_64
+Sections:
+ - Name: .foo
+ Type: SHT_PROGBITS
+ Content: "FF"
+
+## Check we can specify only `Size`.
+
+# RUN: yaml2obj --docnum=4 %s -o %t4
+# RUN: llvm-readobj --section-data -S %t4 | FileCheck %s --check-prefix=CASE3
+
+# CASE3: Name: .foo
+# CASE3-NEXT: Type: SHT_PROGBITS
+# CASE3-NEXT: Flags [
+# CASE3-NEXT: ]
+# CASE3-NEXT: Address: 0x0
+# CASE3-NEXT: Offset: 0x180
+# CASE3-NEXT: Size: 1
+# CASE3-NEXT: Link: 0
+# CASE3-NEXT: Info: 0
+# CASE3-NEXT: AddressAlignment: 0
+# CASE3-NEXT: EntrySize: 0
+# CASE3-NEXT: SectionData (
+# CASE3-NEXT: 0000: 00
+# CASE3-NEXT: )
+
+--- !ELF
+FileHeader:
+ Class: ELFCLASS64
+ Data: ELFDATA2LSB
+ Type: ET_DYN
+ Machine: EM_X86_64
+Sections:
+ - Name: .foo
+ Type: SHT_PROGBITS
+ Size: 1
+
+## Check we can specify both `Size` and `Content` when size is greater
+## than content size. In this case zeroes are added as padding
+## after the specified content.
+
+# RUN: yaml2obj --docnum=5 %s -o %t5
+# RUN: llvm-readobj --section-data -S %t5 | FileCheck %s --check-prefix=CASE4
+
+# CASE4: Name: .foo
+# CASE4-NEXT: Type: SHT_PROGBITS
+# CASE4-NEXT: Flags [
+# CASE4-NEXT: ]
+# CASE4-NEXT: Address: 0x0
+# CASE4-NEXT: Offset: 0x180
+# CASE4-NEXT: Size: 3
+# CASE4-NEXT: Link: 0
+# CASE4-NEXT: Info: 0
+# CASE4-NEXT: AddressAlignment: 0
+# CASE4-NEXT: EntrySize: 0
+# CASE4-NEXT: SectionData (
+# CASE4-NEXT: 0000: FF0000
+# CASE4-NEXT: )
+
+--- !ELF
+FileHeader:
+ Class: ELFCLASS64
+ Data: ELFDATA2LSB
+ Type: ET_DYN
+ Machine: EM_X86_64
+Sections:
+ - Name: .foo
+ Type: SHT_PROGBITS
+ Content: "FF"
+ Size: 3
+
+## Check we emit an empty section if neither 'Content' nor 'Size' were set.
+
+# RUN: yaml2obj --docnum=6 %s -o %t6
+# RUN: llvm-readobj %t6 --sections | FileCheck %s --check-prefix=CASE5
+
+# CASE5: Name: .foo
+# CASE5-NEXT: Type: SHT_PROGBITS
+# CASE5-NEXT: Flags [
+# CASE5-NEXT: ]
+# CASE5-NEXT: Address: 0x0
+# CASE5-NEXT: Offset: 0x180
+# CASE5-NEXT: Size: 0
+
+--- !ELF
+FileHeader:
+ Class: ELFCLASS64
+ Data: ELFDATA2LSB
+ Type: ET_DYN
+ Machine: EM_X86_64
+Sections:
+ - Name: .foo
+ Type: SHT_PROGBITS
diff --git a/llvm/test/tools/yaml2obj/strtab-implicit-sections-size-content.yaml b/llvm/test/tools/yaml2obj/strtab-implicit-sections-size-content.yaml
new file mode 100644
index 00000000000..a634997b42d
--- /dev/null
+++ b/llvm/test/tools/yaml2obj/strtab-implicit-sections-size-content.yaml
@@ -0,0 +1,167 @@
+## For implicit string table sections, `Size` and/or `Content` fields can also
+## be specified in YAML. Here we test the behavior in different cases.
+
+## When no `Size` or `Content` is specified for a string table section,
+## yaml2obj writes the default content.
+
+# RUN: yaml2obj --docnum=1 %s -o %t1
+# RUN: llvm-objdump %t1 -s | FileCheck %s --check-prefix=CASE1
+
+# CASE1: Contents of section .strtab:
+# CASE1-NEXT: 0000 00666f6f 00 .foo.
+
+--- !ELF
+FileHeader:
+ Class: ELFCLASS64
+ Data: ELFDATA2LSB
+ Type: ET_DYN
+ Machine: EM_X86_64
+Sections:
+ - Name: .strtab
+ Type: SHT_STRTAB
+## Used to trigger adding string `foo` to the string table section.
+Symbols:
+ - Name: foo
+
+## For string table sections, `Size` can be used to override the
+## implicit string table data. The content is filled with zeroes in this case.
+
+# RUN: yaml2obj --docnum=2 %s -o %t2
+# RUN: llvm-readobj --section-data -S %t2 | FileCheck %s --check-prefix=CASE2
+
+# CASE2: Name: .strtab
+# CASE2-NEXT: Type: SHT_STRTAB
+# CASE2-NEXT: Flags [
+# CASE2-NEXT: ]
+# CASE2-NEXT: Address: 0x0
+# CASE2-NEXT: Offset: 0x140
+# CASE2-NEXT: Size: 2
+# CASE2-NEXT: Link: 0
+# CASE2-NEXT: Info: 0
+# CASE2-NEXT: AddressAlignment: 0
+# CASE2-NEXT: EntrySize: 0
+# CASE2-NEXT: SectionData (
+# CASE2-NEXT: 0000: 0000
+# CASE2-NEXT: )
+
+--- !ELF
+FileHeader:
+ Class: ELFCLASS64
+ Data: ELFDATA2LSB
+ Type: ET_DYN
+ Machine: EM_X86_64
+Sections:
+ - Name: .strtab
+ Type: SHT_STRTAB
+ Size: 2
+## Used to trigger adding string `foo` to the string table section.
+Symbols:
+ - Name: foo
+
+## For string table sections, `Content` can be used to override the
+## implicit string table data.
+
+# RUN: yaml2obj --docnum=3 %s -o %t3
+# RUN: llvm-readobj --section-data -S %t3 | FileCheck %s --check-prefix=CASE3
+
+# CASE3: Name: .strtab
+# CASE3-NEXT: Type: SHT_STRTAB
+# CASE3-NEXT: Flags [
+# CASE3-NEXT: ]
+# CASE3-NEXT: Address: 0x0
+# CASE3-NEXT: Offset: 0x140
+# CASE3-NEXT: Size: 2
+# CASE3-NEXT: Link: 0
+# CASE3-NEXT: Info: 0
+# CASE3-NEXT: AddressAlignment: 0
+# CASE3-NEXT: EntrySize: 0
+# CASE3-NEXT: SectionData (
+# CASE3-NEXT: 0000: 0102
+# CASE3-NEXT: )
+
+--- !ELF
+FileHeader:
+ Class: ELFCLASS64
+ Data: ELFDATA2LSB
+ Type: ET_DYN
+ Machine: EM_X86_64
+Sections:
+ - Name: .strtab
+ Type: SHT_STRTAB
+ Content: "0102"
+## Used to trigger adding string `foo` to the string table section.
+Symbols:
+ - Name: foo
+
+## For string table sections, check we can specify both `Size` and `Content`
+## when size is greater than content size. In this case zeroes are
+## added as padding after the specified content.
+
+# RUN: yaml2obj --docnum=4 %s -o %t4
+# RUN: llvm-readobj --section-data -S %t4 | FileCheck %s --check-prefix=CASE4
+
+# CASE4: Name: .strtab
+# CASE4-NEXT: Type: SHT_STRTAB
+# CASE4-NEXT: Flags [
+# CASE4-NEXT: ]
+# CASE4-NEXT: Address: 0x0
+# CASE4-NEXT: Offset: 0x140
+# CASE4-NEXT: Size: 3
+# CASE4-NEXT: Link: 0
+# CASE4-NEXT: Info: 0
+# CASE4-NEXT: AddressAlignment: 0
+# CASE4-NEXT: EntrySize: 0
+# CASE4-NEXT: SectionData (
+# CASE4-NEXT: 0000: 010200
+# CASE4-NEXT: )
+
+--- !ELF
+FileHeader:
+ Class: ELFCLASS64
+ Data: ELFDATA2LSB
+ Type: ET_DYN
+ Machine: EM_X86_64
+Sections:
+ - Name: .strtab
+ Type: SHT_STRTAB
+ Content: "0102"
+ Size: 3
+## Used to trigger adding string `foo` to the string table section.
+Symbols:
+ - Name: foo
+
+## For string table sections, check we can specify both `Size` and `Content`
+## when size is equal to content size.
+
+# RUN: yaml2obj --docnum=5 %s -o %t5
+# RUN: llvm-readobj --section-data -S %t5 | FileCheck %s --check-prefix=CASE5
+
+# CASE5: Name: .strtab
+# CASE5-NEXT: Type: SHT_STRTAB
+# CASE5-NEXT: Flags [ (0x0)
+# CASE5-NEXT: ]
+# CASE5-NEXT: Address: 0x0
+# CASE5-NEXT: Offset: 0x140
+# CASE5-NEXT: Size: 2
+# CASE5-NEXT: Link: 0
+# CASE5-NEXT: Info: 0
+# CASE5-NEXT: AddressAlignment: 0
+# CASE5-NEXT: EntrySize: 0
+# CASE5-NEXT: SectionData (
+# CASE5-NEXT: 0000: 0102
+# CASE5-NEXT: )
+
+--- !ELF
+FileHeader:
+ Class: ELFCLASS64
+ Data: ELFDATA2LSB
+ Type: ET_DYN
+ Machine: EM_X86_64
+Sections:
+ - Name: .strtab
+ Type: SHT_STRTAB
+ Content: "0102"
+ Size: 2
+## Used to trigger adding string `foo` to the string table section.
+Symbols:
+ - Name: foo
diff --git a/llvm/test/tools/yaml2obj/symtab-implicit-sections-size-content.yaml b/llvm/test/tools/yaml2obj/symtab-implicit-sections-size-content.yaml
new file mode 100644
index 00000000000..3dd9640c43d
--- /dev/null
+++ b/llvm/test/tools/yaml2obj/symtab-implicit-sections-size-content.yaml
@@ -0,0 +1,190 @@
+## For implicit symbol table sections, `Size` and/or `Content` fields can also
+## be specified in YAML. Here we test the behavior in different cases.
+
+## When no `Size` or `Content` is specified for a symbol table section,
+## yaml2obj writes the default content.
+
+# RUN: yaml2obj --docnum=1 %s -o %t1
+# RUN: llvm-readelf %t1 -s | FileCheck %s --check-prefix=CASE1
+
+# CASE1: Symbol table '.symtab' contains 2 entries:
+# CASE1-NEXT: Num: Value Size Type Bind Vis Ndx Name
+# CASE1-NEXT: 0: 0000000000000000 0 NOTYPE LOCAL DEFAULT UND
+# CASE1-NEXT: 1: 0000000000000000 0 NOTYPE LOCAL DEFAULT UND foo
+# CASE1-EMPTY:
+
+--- !ELF
+FileHeader:
+ Class: ELFCLASS64
+ Data: ELFDATA2LSB
+ Type: ET_DYN
+ Machine: EM_X86_64
+Sections:
+ - Name: .symtab
+ Type: SHT_SYMTAB
+Symbols:
+ - Name: foo
+
+## Specifying both `Size` and symbols at the same time is not allowed.
+# RUN: not yaml2obj --docnum=2 %s -o %t2 2>&1 | FileCheck %s --check-prefix=CASE2
+
+# CASE2: error: Cannot specify both `Size` and `Symbols` for symbol table section '.symtab'.
+
+--- !ELF
+FileHeader:
+ Class: ELFCLASS64
+ Data: ELFDATA2LSB
+ Type: ET_DYN
+ Machine: EM_X86_64
+Sections:
+ - Name: .symtab
+ Type: SHT_SYMTAB
+ Size: 0x100
+Symbols:
+ - Name: foo
+
+## Specifying both `Content` and symbols at the same time is not allowed.
+# RUN: not yaml2obj --docnum=3 %s -o %t3 2>&1 | FileCheck %s --check-prefix=CASE3
+
+# CASE3: error: Cannot specify both `Content` and `Symbols` for symbol table section '.symtab'.
+
+--- !ELF
+FileHeader:
+ Class: ELFCLASS64
+ Data: ELFDATA2LSB
+ Type: ET_DYN
+ Machine: EM_X86_64
+Sections:
+ - Name: .symtab
+ Type: SHT_SYMTAB
+ Content: "00"
+Symbols:
+ - Name: foo
+
+## Check we can use just `Content` to emit custom data in the symbol table section.
+# RUN: yaml2obj --docnum=4 %s -o %t4
+# RUN: llvm-readobj --section-data -S %t4 | FileCheck %s --check-prefix=CASE4
+
+# CASE4: Name: .symtab
+# CASE4-NEXT: Type: SHT_SYMTAB
+# CASE4-NEXT: Flags [ (0x0)
+# CASE4-NEXT: ]
+# CASE4-NEXT: Address: 0x0
+# CASE4-NEXT: Offset: 0x140
+# CASE4-NEXT: Size: 2
+# CASE4-NEXT: Link: 2
+# CASE4-NEXT: Info: 0
+# CASE4-NEXT: AddressAlignment: 0
+# CASE4-NEXT: EntrySize: 24
+# CASE4-NEXT: SectionData (
+# CASE4-NEXT: 0000: 0123
+# CASE4-NEXT: )
+
+--- !ELF
+FileHeader:
+ Class: ELFCLASS64
+ Data: ELFDATA2LSB
+ Type: ET_DYN
+ Machine: EM_X86_64
+Sections:
+ - Name: .symtab
+ Type: SHT_SYMTAB
+ Content: "0123"
+
+## Check we can use just `Size` to emit custom data filled with zeroes
+## in the symbol table section.
+# RUN: yaml2obj --docnum=5 %s -o %t5
+# RUN: llvm-readobj --section-data -S %t5 | FileCheck %s --check-prefix=CASE5
+
+# CASE5: Name: .symtab (19)
+# CASE5-NEXT: Type: SHT_SYMTAB (0x2)
+# CASE5-NEXT: Flags [ (0x0)
+# CASE5-NEXT: ]
+# CASE5-NEXT: Address: 0x0
+# CASE5-NEXT: Offset: 0x140
+# CASE5-NEXT: Size: 5
+# CASE5-NEXT: Link: 2
+# CASE5-NEXT: Info: 0
+# CASE5-NEXT: AddressAlignment: 0
+# CASE5-NEXT: EntrySize: 24
+# CASE5-NEXT: SectionData (
+# CASE5-NEXT: 0000: 00000000 00
+# CASE5-NEXT: )
+
+--- !ELF
+FileHeader:
+ Class: ELFCLASS64
+ Data: ELFDATA2LSB
+ Type: ET_DYN
+ Machine: EM_X86_64
+Sections:
+ - Name: .symtab
+ Type: SHT_SYMTAB
+ Size: 5
+
+## Check we can specify both `Size` and `Content` when size is greater
+## than content size. In this case zeroes are added as padding
+## after the specified content.
+
+# RUN: yaml2obj --docnum=6 %s -o %t6
+# RUN: llvm-readobj %t6 --section-data -S | FileCheck %s --check-prefix=CASE6
+
+# CASE6: Name: .symtab
+# CASE6-NEXT: Type: SHT_SYMTAB
+# CASE6-NEXT: Flags [
+# CASE6-NEXT: ]
+# CASE6-NEXT: Address: 0x0
+# CASE6-NEXT: Offset: 0x140
+# CASE6-NEXT: Size: 4
+# CASE6-NEXT: Link: 2
+# CASE6-NEXT: Info: 0
+# CASE6-NEXT: AddressAlignment: 0
+# CASE6-NEXT: EntrySize: 24
+# CASE6-NEXT: SectionData (
+# CASE6-NEXT: 0000: 01230000
+# CASE6-NEXT: )
+
+--- !ELF
+FileHeader:
+ Class: ELFCLASS64
+ Data: ELFDATA2LSB
+ Type: ET_DYN
+ Machine: EM_X86_64
+Sections:
+ - Name: .symtab
+ Type: SHT_SYMTAB
+ Content: "0123"
+ Size: 4
+
+## Check we can specify both `Size` and `Content` when size is
+## equal to content size.
+
+# RUN: yaml2obj --docnum=7 %s -o %t7
+# RUN: llvm-readobj --section-data -S %t7 | FileCheck %s --check-prefix=CASE7
+
+# CASE7: Name: .symtab
+# CASE7-NEXT: Type: SHT_SYMTAB
+# CASE7-NEXT: Flags [
+# CASE7-NEXT: ]
+# CASE7-NEXT: Address: 0x0
+# CASE7-NEXT: Offset: 0x140
+# CASE7-NEXT: Size: 2
+# CASE7-NEXT: Link: 2
+# CASE7-NEXT: Info: 0
+# CASE7-NEXT: AddressAlignment: 0
+# CASE7-NEXT: EntrySize: 24
+# CASE7-NEXT: SectionData (
+# CASE7-NEXT: 0000: 0123
+# CASE7-NEXT: )
+
+--- !ELF
+FileHeader:
+ Class: ELFCLASS64
+ Data: ELFDATA2LSB
+ Type: ET_DYN
+ Machine: EM_X86_64
+Sections:
+ - Name: .symtab
+ Type: SHT_SYMTAB
+ Content: "0123"
+ Size: 2
OpenPOWER on IntegriCloud