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-readobj --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-readobj --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-readobj --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 %t5.so 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 %t5.so 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-readobj --dyn-syms %t7.so | FileCheck --check-prefix=VERDSO %s
44
45# DSO:      DynamicSymbols [
46# DSO-NEXT:   Symbol {
47# DSO-NEXT:     Name:
48# DSO-NEXT:     Value: 0x0
49# DSO-NEXT:     Size: 0
50# DSO-NEXT:     Binding: Local (0x0)
51# DSO-NEXT:     Type: None (0x0)
52# DSO-NEXT:     Other: 0
53# DSO-NEXT:     Section: Undefined (0x0)
54# DSO-NEXT:   }
55# DSO-NEXT:   Symbol {
56# DSO-NEXT:     Name: bar
57# DSO-NEXT:     Value: 0x0
58# DSO-NEXT:     Size: 0
59# DSO-NEXT:     Binding: Global (0x1)
60# DSO-NEXT:     Type: Function (0x2)
61# DSO-NEXT:     Other: 0
62# DSO-NEXT:     Section: Undefined (0x0)
63# DSO-NEXT:   }
64# DSO-NEXT:   Symbol {
65# DSO-NEXT:     Name: foo1
66# DSO-NEXT:     Value: 0x1000
67# DSO-NEXT:     Size: 0
68# DSO-NEXT:     Binding: Global (0x1)
69# DSO-NEXT:     Type: None (0x0)
70# DSO-NEXT:     Other: 0
71# DSO-NEXT:     Section: .text
72# DSO-NEXT:   }
73# DSO-NEXT:   Symbol {
74# DSO-NEXT:     Name: foo3
75# DSO-NEXT:     Value: 0x1007
76# DSO-NEXT:     Size: 0
77# DSO-NEXT:     Binding: Global (0x1)
78# DSO-NEXT:     Type: None (0x0)
79# DSO-NEXT:     Other: 0
80# DSO-NEXT:     Section: .text
81# DSO-NEXT:   }
82# DSO-NEXT: ]
83
84# DSO2:      DynamicSymbols [
85# DSO2-NEXT:   Symbol {
86# DSO2-NEXT:     Name:
87# DSO2-NEXT:     Value: 0x0
88# DSO2-NEXT:     Size: 0
89# DSO2-NEXT:     Binding: Local (0x0)
90# DSO2-NEXT:     Type: None (0x0)
91# DSO2-NEXT:     Other: 0
92# DSO2-NEXT:     Section: Undefined (0x0)
93# DSO2-NEXT:   }
94# DSO2-NEXT:   Symbol {
95# DSO2-NEXT:     Name: bar
96# DSO2-NEXT:     Value: 0x0
97# DSO2-NEXT:     Size: 0
98# DSO2-NEXT:     Binding: Global (0x1)
99# DSO2-NEXT:     Type: Function (0x2)
100# DSO2-NEXT:     Other: 0
101# DSO2-NEXT:     Section: Undefined (0x0)
102# DSO2-NEXT:   }
103# DSO2-NEXT: ]
104
105# VERDSO:      DynamicSymbols [
106# VERDSO-NEXT:   Symbol {
107# VERDSO-NEXT:     Name:
108# VERDSO-NEXT:     Value: 0x0
109# VERDSO-NEXT:     Size: 0
110# VERDSO-NEXT:     Binding: Local
111# VERDSO-NEXT:     Type: None
112# VERDSO-NEXT:     Other: 0
113# VERDSO-NEXT:     Section: Undefined
114# VERDSO-NEXT:   }
115# VERDSO-NEXT:   Symbol {
116# VERDSO-NEXT:     Name: bar
117# VERDSO-NEXT:     Value: 0x0
118# VERDSO-NEXT:     Size: 0
119# VERDSO-NEXT:     Binding: Global
120# VERDSO-NEXT:     Type: Function
121# VERDSO-NEXT:     Other: 0
122# VERDSO-NEXT:     Section: Undefined
123# VERDSO-NEXT:   }
124# VERDSO-NEXT:   Symbol {
125# VERDSO-NEXT:     Name: foo1@@VERSION_1.0
126# VERDSO-NEXT:     Value: 0x1000
127# VERDSO-NEXT:     Size: 0
128# VERDSO-NEXT:     Binding: Global
129# VERDSO-NEXT:     Type: None
130# VERDSO-NEXT:     Other: 0
131# VERDSO-NEXT:     Section: .text
132# VERDSO-NEXT:   }
133# VERDSO-NEXT:   Symbol {
134# VERDSO-NEXT:     Name: foo3@@VERSION_2.0
135# VERDSO-NEXT:     Value: 0x1007
136# VERDSO-NEXT:     Size: 0
137# VERDSO-NEXT:     Binding: Global
138# VERDSO-NEXT:     Type: None
139# VERDSO-NEXT:     Other: 0
140# VERDSO-NEXT:     Section: .text
141# VERDSO-NEXT:   }
142# VERDSO-NEXT: ]
143
144# RUN: llvm-mc -filetype=obj -triple=x86_64-unknown-linux %s -o %t.o
145# RUN: ld.lld --hash-style=sysv -shared %t.o %t2.so -o %t.so
146# RUN: llvm-readobj --dyn-syms %t.so | FileCheck --check-prefix=ALL %s
147
148# RUN: echo "{ global: foo1; foo3; };" > %t2.script
149# RUN: llvm-mc -filetype=obj -triple=x86_64-unknown-linux %s -o %t.o
150# RUN: ld.lld --hash-style=sysv --version-script %t2.script -shared %t.o %t2.so -o %t.so
151# RUN: llvm-readobj --dyn-syms %t.so | FileCheck --check-prefix=ALL %s
152
153# ALL:      DynamicSymbols [
154# ALL-NEXT:   Symbol {
155# ALL-NEXT:     Name:
156# ALL-NEXT:     Value: 0x0
157# ALL-NEXT:     Size: 0
158# ALL-NEXT:     Binding: Local
159# ALL-NEXT:     Type: None
160# ALL-NEXT:     Other: 0
161# ALL-NEXT:     Section: Undefined
162# ALL-NEXT:   }
163# ALL-NEXT:  Symbol {
164# ALL-NEXT:    Name: _start
165# ALL-NEXT:    Value:
166# ALL-NEXT:    Size: 0
167# ALL-NEXT:    Binding: Global
168# ALL-NEXT:    Type: None
169# ALL-NEXT:    Other: 0
170# ALL-NEXT:    Section: .text
171# ALL-NEXT:  }
172# ALL-NEXT:  Symbol {
173# ALL-NEXT:    Name: bar
174# ALL-NEXT:    Value:
175# ALL-NEXT:    Size: 0
176# ALL-NEXT:    Binding: Global
177# ALL-NEXT:    Type: Function
178# ALL-NEXT:    Other: 0
179# ALL-NEXT:    Section: Undefined
180# ALL-NEXT:  }
181# ALL-NEXT:  Symbol {
182# ALL-NEXT:    Name: foo1
183# ALL-NEXT:    Value:
184# ALL-NEXT:    Size: 0
185# ALL-NEXT:    Binding: Global
186# ALL-NEXT:    Type: None
187# ALL-NEXT:    Other: 0
188# ALL-NEXT:    Section: .text
189# ALL-NEXT:  }
190# ALL-NEXT:  Symbol {
191# ALL-NEXT:    Name: foo2
192# ALL-NEXT:    Value:
193# ALL-NEXT:    Size: 0
194# ALL-NEXT:    Binding: Global
195# ALL-NEXT:    Type: None
196# ALL-NEXT:    Other: 0
197# ALL-NEXT:    Section: .text
198# ALL-NEXT:  }
199# ALL-NEXT:  Symbol {
200# ALL-NEXT:    Name: foo3
201# ALL-NEXT:    Value:
202# ALL-NEXT:    Size: 0
203# ALL-NEXT:    Binding: Global
204# ALL-NEXT:    Type: None
205# ALL-NEXT:    Other: 0
206# ALL-NEXT:    Section: .text
207# ALL-NEXT:  }
208# ALL-NEXT: ]
209
210# RUN: echo "VERSION_1.0 { global: foo1; foo1; local: *; };" > %t8.script
211# RUN: ld.lld --version-script %t8.script -shared %t.o -o /dev/null --fatal-warnings
212
213.globl foo1
214foo1:
215  call bar@PLT
216  ret
217
218.globl foo2
219foo2:
220  ret
221
222.globl foo3
223foo3:
224  call foo2@PLT
225  ret
226
227.globl _start
228_start:
229  ret
230