1# REQUIRES: x86
2
3# RUN: llvm-mc -filetype=obj -triple=x86_64-unknown-linux %p/Inputs/shared.s -o %t2.o
4# RUN: ld.lld -shared %t2.o -soname shared -o %t2.so
5
6# RUN: echo "{ global: foo1; foo3; local: *; };" > %t.script
7# RUN: llvm-mc -filetype=obj -triple=x86_64-unknown-linux %s -o %t.o
8# RUN: ld.lld --version-script %t.script -shared %t.o %t2.so -o %t.so --fatal-warnings
9# RUN: llvm-readelf --dyn-syms %t.so | FileCheck --check-prefix=DSO %s
10
11# RUN: echo "# comment" > %t3.script
12# RUN: echo "{ local: *; # comment" >> %t3.script
13# RUN: echo -n "}; # comment" >> %t3.script
14# RUN: ld.lld --version-script %t3.script -shared %t.o %t2.so -o %t3.so
15# RUN: llvm-readelf --dyn-syms %t3.so | FileCheck --check-prefix=DSO2 %s
16
17## Also check that both "global:" and "global :" forms are accepted
18# RUN: echo "VERSION_1.0 { global : foo1; local : *; };" > %t4.script
19# RUN: echo "VERSION_2.0 { global: foo3; local: *; };" >> %t4.script
20# RUN: ld.lld --version-script %t4.script -shared %t.o %t2.so -o %t4.so --fatal-warnings
21# RUN: llvm-readelf --dyn-syms %t4.so | FileCheck --check-prefix=VERDSO %s
22
23# RUN: echo "VERSION_1.0 { global: foo1; local: *; };" > %t5.script
24# RUN: echo "{ global: foo3; local: *; };" >> %t5.script
25# RUN: not ld.lld --version-script %t5.script -shared %t.o %t2.so -o /dev/null 2>&1 | \
26# RUN:   FileCheck -check-prefix=ERR1 %s
27# ERR1: anonymous version definition is used in combination with other version definitions
28
29# RUN: echo "{ global: foo1; local: *; };" > %t5.script
30# RUN: echo "VERSION_2.0 { global: foo3; local: *; };" >> %t5.script
31# RUN: not ld.lld --version-script %t5.script -shared %t.o %t2.so -o /dev/null 2>&1 | \
32# RUN:   FileCheck -check-prefix=ERR2 %s
33# ERR2: EOF expected, but got VERSION_2.0
34
35# RUN: echo "{ foo1; foo2; };" > %t.list
36# RUN: ld.lld --version-script %t.script --dynamic-list %t.list %t.o %t2.so -o %t2
37# RUN: llvm-readobj %t2 > /dev/null
38
39## Check that we can handle multiple "--version-script" options.
40# RUN: echo "VERSION_1.0 { global : foo1; local : *; };" > %t7a.script
41# RUN: echo "VERSION_2.0 { global: foo3; local: *; };" > %t7b.script
42# RUN: ld.lld --version-script %t7a.script --version-script %t7b.script -shared %t.o %t2.so -o %t7.so
43# RUN: llvm-readelf --dyn-syms %t7.so | FileCheck --check-prefix=VERDSO %s
44
45# DSO:      bar{{$}}
46# DSO-NEXT: foo1{{$}}
47# DSO-NEXT: foo3{{$}}
48# DSO-NOT:  {{.}}
49
50# DSO2:      bar{{$}}
51# DSO2-NOT:  {{.}}
52
53# VERDSO:      bar{{$}}
54# VERDSO-NEXT: foo1@@VERSION_1.0
55# VERDSO-NEXT: foo3@@VERSION_2.0
56# VERDSO-NOT:  {{.}}
57
58# RUN: llvm-mc -filetype=obj -triple=x86_64-unknown-linux %s -o %t.o
59# RUN: ld.lld --hash-style=sysv -shared %t.o %t2.so -o %t.so
60# RUN: llvm-readelf --dyn-syms %t.so | FileCheck --check-prefix=ALL %s
61
62# RUN: echo "{ global: foo1; foo3; };" > %t2.script
63# RUN: llvm-mc -filetype=obj -triple=x86_64-unknown-linux %s -o %t.o
64# RUN: ld.lld --hash-style=sysv --version-script %t2.script -shared %t.o %t2.so -o %t.so
65# RUN: llvm-readelf --dyn-syms %t.so | FileCheck --check-prefix=ALL %s
66
67# ALL:      _start{{$}}
68# ALL-NEXT: bar{{$}}
69# ALL-NEXT: foo1{{$}}
70# ALL-NEXT: foo2{{$}}
71# ALL-NEXT: foo3{{$}}
72# ALL-NOT:  {{.}}
73
74# RUN: echo "VERSION_1.0 { global: foo1; foo1; local: *; };" > %t8.script
75# RUN: ld.lld --version-script %t8.script -shared %t.o -o /dev/null --fatal-warnings
76
77.globl foo1
78foo1:
79  call bar@PLT
80  ret
81
82.globl foo2
83foo2:
84  ret
85
86.globl foo3
87foo3:
88  call foo2@PLT
89  ret
90
91.globl _start
92_start:
93  ret
94