1## REQUIRES: x86
2## Test that we can parse SHT_GNU_verneed in a shared object and report certain errors.
3
4# RUN: echo '.globl _start; _start:' | llvm-mc -filetype=obj -triple=x86_64 - -o %t.o
5
6## sh_offset(SHT_GNU_verneed) is out of bounds.
7# RUN: yaml2obj --docnum=1 %s -o %t1.so
8# RUN: not ld.lld %t.o %t1.so -o /dev/null 2>&1 | FileCheck --check-prefix=SHOFFSET %s
9# SHOFFSET: error: {{.*}}.so: section [index 1] has a sh_offset (0xffffffff) + sh_size (0x0) that is greater than the file size (0x168)
10--- !ELF
11FileHeader:
12  Class:   ELFCLASS64
13  Data:    ELFDATA2LSB
14  Type:    ET_DYN
15  Machine: EM_X86_64
16Sections:
17  - Name:     .gnu.version_r
18    Type:     SHT_GNU_verneed
19    Flags:    [ SHF_ALLOC ]
20    ShOffset: 0xFFFFFFFF
21
22## A Verneed entry is misaligned (not a multiple of 4). This may happen
23## some interface shared objects. We use memcpy to read the fields, so
24## misalignment isn't a problem and there is no need to diagnose.
25# RUN: yaml2obj --docnum=2 %s -o %t2.so
26# RUN: ld.lld %t.o %t2.so -o /dev/null
27--- !ELF
28FileHeader:
29  Class:   ELFCLASS64
30  Data:    ELFDATA2LSB
31  Type:    ET_DYN
32  Machine: EM_X86_64
33Sections:
34  - Type: Fill
35    Size: 0x1
36  - Name:  .gnu.version_r
37    Type:  SHT_GNU_verneed
38    Flags: [ SHF_ALLOC ]
39    Dependencies:
40      - Version: 1
41        File:    foo
42        Entries:
43          - Name:  'foo'
44            Hash:  0
45            Flags: 0
46            Other: 0
47DynamicSymbols:
48  - Name: foo
49
50## vn_aux points to a place outside of the file.
51# RUN: yaml2obj --docnum=3 -D VERNEED=0100010001000000040200000000000000000000 %s -o %t3.so
52# RUN: not ld.lld %t.o %t3.so -o /dev/null 2>&1 | FileCheck --check-prefix=AUX-OOB %s
53# AUX-OOB: {{.*}}.so has an invalid Vernaux
54--- !ELF
55FileHeader:
56  Class:   ELFCLASS64
57  Data:    ELFDATA2LSB
58  Type:    ET_DYN
59  Machine: EM_X86_64
60Sections:
61  - Name:  .gnu.version_r
62    Type:  SHT_GNU_verneed
63    Flags: [ SHF_ALLOC ]
64    Info:  1
65    Content: "[[VERNEED]]"
66DynamicSymbols:
67  - Name: foo
68
69## vn_aux is misaligned.
70# RUN: yaml2obj --docnum=3 -D VERNEED=0100010001000000110000000000000000000000 %s -o %t4.so
71# RUN: not ld.lld %t.o %t4.so -o /dev/null 2>&1 | FileCheck --check-prefix=AUX-MISALIGNED %s
72# AUX-MISALIGNED: {{.*}}.so has an invalid Vernaux
73
74## vna_name is out of bounds.
75# RUN: yaml2obj --docnum=3 -D VERNEED=010001000000000010000000000000009107000000000000ff00000000000000 %s -o %t5.so
76# RUN: not ld.lld %t.o %t5.so -o /dev/null 2>&1 | FileCheck --check-prefix=NAME-OOB %s
77# NAME-OOB: {{.*}}.so has a Vernaux with an invalid vna_name
78