mirror of
https://github.com/RPCS3/llvm.git
synced 2025-02-26 05:36:36 +00:00

The aim of this patch is to refactor how we handle and report error. I suggest to use the same approach we use in LLD: delayed error reporting. For that I introduced 'HasError' flag which triggers when we report an error. Now we do not exit instantly on any error. The benefits are: 1) There are no more 'exit(1)' calls in the library code. 2) Code was simplified significantly in a few places. 3) It is now possible to print multiple errors instead of only one. Also, I changed the messages to be lower case and removed a full stop. Differential revision: https://reviews.llvm.org/D67182 git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@371380 91177308-0d34-0410-b5e6-96231b3b80d8
206 lines
5.7 KiB
YAML
206 lines
5.7 KiB
YAML
## In this test we check that can redefine the null section in the YAML.
|
|
|
|
## Test the default output first.
|
|
|
|
# RUN: yaml2obj --docnum=1 %s -o %t1
|
|
# RUN: llvm-readelf --sections %t1 | FileCheck %s --check-prefix=DEFAULT
|
|
|
|
# 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
|
|
|
|
--- !ELF
|
|
FileHeader:
|
|
Class: ELFCLASS64
|
|
Data: ELFDATA2LSB
|
|
Type: ET_REL
|
|
Machine: EM_X86_64
|
|
|
|
## Now define a SHT_NULL section with fields all zeroed.
|
|
## In this case it is equal to the section created by default.
|
|
|
|
# RUN: yaml2obj --docnum=2 %s -o %t2
|
|
# RUN: llvm-readelf --sections %t2 | FileCheck %s --check-prefix=DEFAULT
|
|
|
|
--- !ELF
|
|
FileHeader:
|
|
Class: ELFCLASS64
|
|
Data: ELFDATA2LSB
|
|
Type: ET_REL
|
|
Machine: EM_X86_64
|
|
Sections:
|
|
- Type: SHT_NULL
|
|
Name: ''
|
|
Flags: [ ]
|
|
AddressAlign: 0x0
|
|
Size: 0x0
|
|
EntSize: 0x0
|
|
Link: 0
|
|
Info: 0
|
|
Address: 0x0
|
|
|
|
## Check we can redefine fields of the first SHT_NULL section.
|
|
|
|
# RUN: yaml2obj --docnum=3 %s -o %t3
|
|
# RUN: llvm-readelf --sections %t3 | FileCheck %s --check-prefix=REDEFINE
|
|
|
|
# REDEFINE: Section Headers:
|
|
# REDEFINE-NEXT: [Nr] Name Type Address Off Size ES Flg Lk Inf Al
|
|
# REDEFINE-NEXT: [ 0] .foo NULL 0000000000000006 000000 000002 03 A 4 5 1
|
|
|
|
--- !ELF
|
|
FileHeader:
|
|
Class: ELFCLASS64
|
|
Data: ELFDATA2LSB
|
|
Type: ET_REL
|
|
Machine: EM_X86_64
|
|
Sections:
|
|
- Type: SHT_NULL
|
|
Name: .foo
|
|
Flags: [ SHF_ALLOC ]
|
|
AddressAlign: 0x1
|
|
Size: 0x2
|
|
EntSize: 0x3
|
|
Link: 4
|
|
Info: 5
|
|
Address: 0x6
|
|
|
|
## Check that file size does not change if we redefine the Size
|
|
## of the first SHT_NULL section.
|
|
|
|
# RUN: yaml2obj --docnum=4 %s -o %t4
|
|
# RUN: ls -l %t3 | tr -s ' ' | cut -d ' ' -f 5 > %t.txt
|
|
# RUN: ls -l %t4 | tr -s ' ' | cut -d ' ' -f 5 >> %t.txt
|
|
# RUN: FileCheck %s --input-file=%t.txt --check-prefix=SIZE
|
|
|
|
# SIZE: [[FILESIZE:.*]]
|
|
# SIZE: [[FILESIZE]]
|
|
|
|
--- !ELF
|
|
FileHeader:
|
|
Class: ELFCLASS64
|
|
Data: ELFDATA2LSB
|
|
Type: ET_REL
|
|
Machine: EM_X86_64
|
|
Sections:
|
|
- Type: SHT_NULL
|
|
Name: .foo
|
|
Flags: [ SHF_ALLOC ]
|
|
AddressAlign: 0x1
|
|
Size: 0xFFFF
|
|
EntSize: 0x3
|
|
Link: 4
|
|
Info: 5
|
|
Address: 0x6
|
|
|
|
## Check we are still able to describe other sections too.
|
|
|
|
# RUN: yaml2obj --docnum=5 %s -o %t5
|
|
# RUN: llvm-readelf --sections %t5 | FileCheck %s --check-prefix=OTHER-SECTION
|
|
|
|
# OTHER-SECTION: Section Headers:
|
|
# 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
|
|
|
|
--- !ELF
|
|
FileHeader:
|
|
Class: ELFCLASS64
|
|
Data: ELFDATA2LSB
|
|
Type: ET_REL
|
|
Machine: EM_X86_64
|
|
Sections:
|
|
- Type: SHT_NULL
|
|
Name: ''
|
|
Flags: [ ]
|
|
AddressAlign: 0x0
|
|
Size: 0x0
|
|
EntSize: 0x0
|
|
Link: 0
|
|
- Type: SHT_PROGBITS
|
|
Name: 'foo'
|
|
|
|
## Check we report an error if null section sh_link field refers to an unknown section.
|
|
|
|
# RUN: not yaml2obj --docnum=6 %s -o %t6 2>&1 | FileCheck %s --check-prefix=CASE4
|
|
|
|
# CASE4: error: unknown section referenced: '.foo' by YAML section ''
|
|
|
|
--- !ELF
|
|
FileHeader:
|
|
Class: ELFCLASS64
|
|
Data: ELFDATA2LSB
|
|
Type: ET_REL
|
|
Machine: EM_X86_64
|
|
Sections:
|
|
- Type: SHT_NULL
|
|
Link: .foo
|
|
|
|
## Check that null section fields are set to zero, if they are unspecified.
|
|
|
|
# RUN: yaml2obj --docnum=7 %s -o %t7
|
|
# RUN: llvm-readelf --sections %t7 | FileCheck %s --check-prefix=DEFAULT
|
|
|
|
--- !ELF
|
|
FileHeader:
|
|
Class: ELFCLASS64
|
|
Data: ELFDATA2LSB
|
|
Type: ET_REL
|
|
Machine: EM_X86_64
|
|
Sections:
|
|
- Type: SHT_NULL
|
|
|
|
## Check we do not crash if we have more than one SHT_NULL section.
|
|
|
|
# RUN: yaml2obj --docnum=8 %s -o %t8
|
|
# RUN: llvm-readelf --sections %t8 | FileCheck %s --check-prefix=MULTIPLE
|
|
|
|
# MULTIPLE: Section Headers:
|
|
# MULTIPLE-NEXT: [Nr] Name Type Address Off Size ES Flg Lk Inf Al
|
|
# MULTIPLE-NEXT: [ 0] NULL 0000000000000000 000000 000000 00 0 0 0
|
|
# MULTIPLE-NEXT: [ 1] .foo NULL 0000000000000123 000040 000020 10 A 1 2 0
|
|
|
|
--- !ELF
|
|
FileHeader:
|
|
Class: ELFCLASS64
|
|
Data: ELFDATA2LSB
|
|
Type: ET_REL
|
|
Machine: EM_X86_64
|
|
Sections:
|
|
- Type: SHT_NULL
|
|
- Type: SHT_NULL
|
|
Name: .foo
|
|
Flags: [ SHF_ALLOC ]
|
|
Size: 0x20
|
|
EntSize: 0x10
|
|
Link: 1
|
|
Info: 2
|
|
Address: 0x123
|
|
|
|
## Check we can override the sh_offset/sh_size fields of the first SHT_NULL section if requested.
|
|
|
|
# RUN: yaml2obj --docnum=9 %s -o %t9
|
|
# RUN: llvm-readelf --sections %t9 | FileCheck %s --check-prefix=OVERRIDE
|
|
|
|
# OVERRIDE: Section Headers:
|
|
# OVERRIDE-NEXT: [Nr] Name Type Address Off Size ES Flg Lk Inf Al
|
|
# OVERRIDE-NEXT: [ 0] NULL 0000000000000000 000007 000008 00 0 0 0
|
|
|
|
--- !ELF
|
|
FileHeader:
|
|
Class: ELFCLASS64
|
|
Data: ELFDATA2LSB
|
|
Type: ET_REL
|
|
Machine: EM_X86_64
|
|
Sections:
|
|
- Type: SHT_NULL
|
|
Size: 0x2
|
|
ShOffset: 0x7
|
|
ShSize: 0x8
|