llvm-project/lld/test/ELF/invalid/verneed-shared.test
Fangrui Song 754b94638e
[lld] Support RUN_LLD_MAIN_TWICE for the ELF port (#124441)
This enables the LLD_IN_TEST=2 testing mode for
```
path/to/llvm-lit -sv --param RUN_LLD_MAIN_TWICE=1 lld/test/ELF
```

When `Fatal` is called, `RunSafely` will return false.
For the first invocation in LLD_IN_TEST=2 mode, `inTestOutputDisabled`
is true and lld will not write to stdout/stderr, making many tests fail.
(This essentially discourages `Fatal` calls in the source code.)

Add XFAIL: main-run-twice to these tests similar to
https://reviews.llvm.org/D112898 for Mach-O

```
comment="This test intentionally checks for fatal errors, and fatal errors aren't supported for testing when main is run twice."
xargs </tmp/0 sed -Ei "1s/(;|#|\/\/) REQUIRES: .*/\0\n\1 "$comment"\n\1 XFAIL: main-run-twice/;t;1s/^/# "$comment"\n# XFAIL: main-run-twice\n/"
```
2025-01-27 10:04:57 -08:00

80 lines
2.6 KiB
Plaintext

## REQUIRES: x86
# This test intentionally checks for fatal errors, and fatal errors aren't supported for testing when main is run twice.
# XFAIL: main-run-twice
## Test that we can parse SHT_GNU_verneed in a shared object and report certain errors.
# RUN: echo '.globl _start; _start:' | llvm-mc -filetype=obj -triple=x86_64 - -o %t.o
## sh_offset(SHT_GNU_verneed) is out of bounds.
# RUN: yaml2obj --docnum=1 %s -o %t1.so
# RUN: not ld.lld %t.o %t1.so -o /dev/null 2>&1 | FileCheck --check-prefix=SHOFFSET %s
# SHOFFSET: error: {{.*}}.so: section [index 1] has a sh_offset (0xffffffff) + sh_size (0x0) that is greater than the file size (0x168)
--- !ELF
FileHeader:
Class: ELFCLASS64
Data: ELFDATA2LSB
Type: ET_DYN
Machine: EM_X86_64
Sections:
- Name: .gnu.version_r
Type: SHT_GNU_verneed
Flags: [ SHF_ALLOC ]
ShOffset: 0xFFFFFFFF
## A Verneed entry is misaligned (not a multiple of 4). This may happen
## some interface shared objects. We use memcpy to read the fields, so
## misalignment isn't a problem and there is no need to diagnose.
# RUN: yaml2obj --docnum=2 %s -o %t2.so
# RUN: ld.lld %t.o %t2.so -o /dev/null
--- !ELF
FileHeader:
Class: ELFCLASS64
Data: ELFDATA2LSB
Type: ET_DYN
Machine: EM_X86_64
Sections:
- Type: Fill
Size: 0x1
- Name: .gnu.version_r
Type: SHT_GNU_verneed
Flags: [ SHF_ALLOC ]
Dependencies:
- Version: 1
File: foo
Entries:
- Name: 'foo'
Hash: 0
Flags: 0
Other: 0
DynamicSymbols:
- Name: foo
## vn_aux points to a place outside of the file.
# RUN: yaml2obj --docnum=3 -D VERNEED=0100010001000000040200000000000000000000 %s -o %t3.so
# RUN: not ld.lld %t.o %t3.so -o /dev/null 2>&1 | FileCheck --check-prefix=AUX-OOB %s
# AUX-OOB: {{.*}}.so has an invalid Vernaux
--- !ELF
FileHeader:
Class: ELFCLASS64
Data: ELFDATA2LSB
Type: ET_DYN
Machine: EM_X86_64
Sections:
- Name: .gnu.version_r
Type: SHT_GNU_verneed
Flags: [ SHF_ALLOC ]
Info: 1
Content: "[[VERNEED]]"
DynamicSymbols:
- Name: foo
## vn_aux is misaligned.
# RUN: yaml2obj --docnum=3 -D VERNEED=0100010001000000110000000000000000000000 %s -o %t4.so
# RUN: not ld.lld %t.o %t4.so -o /dev/null 2>&1 | FileCheck --check-prefix=AUX-MISALIGNED %s
# AUX-MISALIGNED: {{.*}}.so has an invalid Vernaux
## vna_name is out of bounds.
# RUN: yaml2obj --docnum=3 -D VERNEED=010001000000000010000000000000009107000000000000ff00000000000000 %s -o %t5.so
# RUN: not ld.lld %t.o %t5.so -o /dev/null 2>&1 | FileCheck --check-prefix=NAME-OOB %s
# NAME-OOB: {{.*}}.so has a Vernaux with an invalid vna_name