1## Check how we produce SHT_DYNSYM sections.
2
3## Check we do not crash/assert when .dynsym is specified
4## explicitly, but .dynstr is not present.
5## Check we set the sh_link field to 0 for the .dynsym section in this case.
6
7# RUN: yaml2obj %s -o %t1
8# RUN: llvm-readelf --section-headers %t1 | FileCheck %s
9
10# CHECK:      Section Headers:
11# CHECK-NEXT:  [Nr] Name    Type   Address          Off    Size   ES Flg Lk
12# CHECK-NEXT:  [ 0]         NULL   0000000000000000 000000 000000 00 0   0
13# CHECK-NEXT:  [ 1] .dynsym DYNSYM 0000000000000000 000040 000018 18 A   0
14
15--- !ELF
16FileHeader:
17  Class: ELFCLASS64
18  Data:  ELFDATA2LSB
19  Type:  ET_DYN
20Sections:
21  - Name:   .dynsym
22    Type:   SHT_DYNSYM
23    Offset: [[OFFSET=<none>]]
24
25## Check we can use the "Offset" key to to set an arbitrary offset for the SHT_DYNSYM section.
26
27# RUN: yaml2obj %s -DOFFSET=0x100 -o %t2
28# RUN: llvm-readelf --section-headers %t2 | FileCheck %s --check-prefix=OFFSET
29
30# OFFSET:      Section Headers:
31# OFFSET-NEXT:   [Nr] Name    Type   Address          Off    Size   ES Flg Lk Inf Al
32# OFFSET-NEXT:   [ 0]         NULL   0000000000000000 000000 000000 00     0   0  0
33# OFFSET-NEXT:   [ 1] .dynsym DYNSYM 0000000000000000 000100 000018 18   A 0   1  0
34
35## Check we are able to set Link = 0 for the .dynsym section explicitly.
36
37# RUN: yaml2obj %s --docnum=2 -DLINK=0 -o %t2
38# RUN: llvm-readelf --section-headers %t2 | FileCheck %s --check-prefix=LINK-NULL
39
40# LINK-NULL: [Nr] Name    {{.*}} Flg Lk Inf
41# LINK-NULL: [ 1] .dynsym {{.*}}   A 0   1
42
43--- !ELF
44FileHeader:
45  Class: ELFCLASS64
46  Data:  ELFDATA2LSB
47  Type:  ET_DYN
48Sections:
49  - Name: .dynsym
50    Type: SHT_DYNSYM
51    Link: [[LINK=<none>]]
52  - Name: .dynstr
53    Type: SHT_STRTAB
54  - Name: .foo
55    Type: SHT_PROGBITS
56
57## Check that by default the .dynsym section will be linked to the .dynstr section,
58## when the latter one exists.
59
60# RUN: yaml2obj %s --docnum=2 -o %t3
61# RUN: llvm-readelf --section-headers %t3 | FileCheck %s --check-prefix=LINK-DEFAULT
62
63# LINK-DEFAULT: [Nr] Name    {{.*}} Flg Lk Inf
64# LINK-DEFAULT: [ 1] .dynsym {{.*}}   A 2   1
65# LINK-DEFAULT: [ 2] .dynstr {{.*}}   A 0   0
66
67## Even when the .dynstr section exists, we can explicitly link the .dynsym section
68## to another section.
69
70# RUN: yaml2obj %s --docnum=2 -DLINK=3 -o %t4
71# RUN: llvm-readelf --section-headers %t4 | FileCheck %s --check-prefix=LINK-FOO
72
73# LINK-FOO: [Nr] Name     {{.*}} Flg Lk Inf
74# LINK-FOO: [ 1] .dynsym  {{.*}}   A 3   1
75# LINK-FOO: [ 3] .foo
76
77## Check we can use a section name as a Link value for .dynsym.
78
79# RUN: yaml2obj %s --docnum=2 -DLINK=.foo -o %t5
80# RUN: llvm-readelf --section-headers %t5 | FileCheck %s --check-prefix=LINK-FOO
81