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
9# RUN: llvm-readobj -dyn-symbols %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-symbols %t3.so | FileCheck --check-prefix=DSO2 %s
16
17# --version-script filters --dynamic-list.
18# RUN: echo "{ foo1; foo2; };" > %t.list
19# RUN: ld.lld --version-script %t.script --dynamic-list %t.list %t.o %t2.so -o %t
20# RUN: llvm-readobj -dyn-symbols %t | FileCheck --check-prefix=EXE %s
21
22# RUN: echo "VERSION_1.0{      \
23# RUN:          global: foo1;  \
24# RUN:          local: *; };   \
25# RUN:       VERSION_2.0{      \
26# RUN:          global: foo3;  \
27# RUN:          local: *; }; " > %t4.script
28# RUN: ld.lld --version-script %t4.script -shared %t.o %t2.so -o %t4.so
29# RUN: llvm-readobj -dyn-symbols %t4.so | FileCheck --check-prefix=VERDSO %s
30
31# RUN: echo "VERSION_1.0{     \
32# RUN:          global: foo1; \
33# RUN:          local: *; };  \
34# RUN:          {             \
35# RUN:          global: foo3; \
36# RUN:          local: *; }; " > %t5.script
37# RUN: not ld.lld --version-script %t5.script -shared %t.o %t2.so -o %t5.so 2>&1 | \
38# RUN:   FileCheck -check-prefix=ERR %s
39# ERR: anonymous version definition is used in combination with other version definitions
40
41# RUN: echo    "{             \
42# RUN:          global: foo1; \
43# RUN:          local: *; };  \
44# RUN:       VERSION_2.0 {    \
45# RUN:          global: foo3; \
46# RUN:          local: *; }; " > %t5.script
47# RUN: not ld.lld --version-script %t5.script -shared %t.o %t2.so -o %t5.so 2>&1 | \
48# RUN:   FileCheck -check-prefix=ERR %s
49
50# RUN: echo "VERSION_1.0{     \
51# RUN:          global: foo1; \
52# RUN:          local: *; };  \
53# RUN:       VERSION_2.0 {    \
54# RUN:          global: foo1; \
55# RUN:          local: *; }; " > %t6.script
56# RUN: ld.lld --version-script %t6.script -shared %t.o %t2.so -o %t6.so 2>&1 | \
57# RUN:   FileCheck -check-prefix=WARN2 %s
58# WARN2: duplicate symbol foo1 in version script
59
60# RUN: ld.lld --version-script %t.script --dynamic-list %t.list %t.o %t2.so -o %t2
61# RUN: llvm-readobj %t2 > /dev/null
62
63# DSO:      DynamicSymbols [
64# DSO-NEXT:   Symbol {
65# DSO-NEXT:     Name: @ (0)
66# DSO-NEXT:     Value: 0x0
67# DSO-NEXT:     Size: 0
68# DSO-NEXT:     Binding: Local (0x0)
69# DSO-NEXT:     Type: None (0x0)
70# DSO-NEXT:     Other: 0
71# DSO-NEXT:     Section: Undefined (0x0)
72# DSO-NEXT:   }
73# DSO-NEXT:   Symbol {
74# DSO-NEXT:     Name: bar@ (1)
75# DSO-NEXT:     Value: 0x0
76# DSO-NEXT:     Size: 0
77# DSO-NEXT:     Binding: Global (0x1)
78# DSO-NEXT:     Type: Function (0x2)
79# DSO-NEXT:     Other: 0
80# DSO-NEXT:     Section: Undefined (0x0)
81# DSO-NEXT:   }
82# DSO-NEXT:   Symbol {
83# DSO-NEXT:     Name: foo1@ (5)
84# DSO-NEXT:     Value: 0x1000
85# DSO-NEXT:     Size: 0
86# DSO-NEXT:     Binding: Global (0x1)
87# DSO-NEXT:     Type: None (0x0)
88# DSO-NEXT:     Other: 0
89# DSO-NEXT:     Section: .text
90# DSO-NEXT:   }
91# DSO-NEXT:   Symbol {
92# DSO-NEXT:     Name: foo3@ (10)
93# DSO-NEXT:     Value: 0x1007
94# DSO-NEXT:     Size: 0
95# DSO-NEXT:     Binding: Global (0x1)
96# DSO-NEXT:     Type: None (0x0)
97# DSO-NEXT:     Other: 0
98# DSO-NEXT:     Section: .text
99# DSO-NEXT:   }
100# DSO-NEXT: ]
101
102# DSO2:      DynamicSymbols [
103# DSO2-NEXT:   Symbol {
104# DSO2-NEXT:     Name: @ (0)
105# DSO2-NEXT:     Value: 0x0
106# DSO2-NEXT:     Size: 0
107# DSO2-NEXT:     Binding: Local (0x0)
108# DSO2-NEXT:     Type: None (0x0)
109# DSO2-NEXT:     Other: 0
110# DSO2-NEXT:     Section: Undefined (0x0)
111# DSO2-NEXT:   }
112# DSO2-NEXT:   Symbol {
113# DSO2-NEXT:     Name: bar@ (1)
114# DSO2-NEXT:     Value: 0x0
115# DSO2-NEXT:     Size: 0
116# DSO2-NEXT:     Binding: Global (0x1)
117# DSO2-NEXT:     Type: Function (0x2)
118# DSO2-NEXT:     Other: 0
119# DSO2-NEXT:     Section: Undefined (0x0)
120# DSO2-NEXT:   }
121# DSO2-NEXT: ]
122
123# EXE:      DynamicSymbols [
124# EXE-NEXT:   Symbol {
125# EXE-NEXT:     Name: @ (0)
126# EXE-NEXT:     Value: 0x0
127# EXE-NEXT:     Size: 0
128# EXE-NEXT:     Binding: Local (0x0)
129# EXE-NEXT:     Type: None (0x0)
130# EXE-NEXT:     Other: 0
131# EXE-NEXT:     Section: Undefined (0x0)
132# EXE-NEXT:   }
133# EXE-NEXT:   Symbol {
134# EXE-NEXT:     Name: bar@ (1)
135# EXE-NEXT:     Value: 0x0
136# EXE-NEXT:     Size: 0
137# EXE-NEXT:     Binding: Global (0x1)
138# EXE-NEXT:     Type: Function (0x2)
139# EXE-NEXT:     Other: 0
140# EXE-NEXT:     Section: Undefined (0x0)
141# EXE-NEXT:   }
142# EXE-NEXT:   Symbol {
143# EXE-NEXT:     Name: foo1@ (5)
144# EXE-NEXT:     Value: 0x11000
145# EXE-NEXT:     Size: 0
146# EXE-NEXT:     Binding: Global (0x1)
147# EXE-NEXT:     Type: None (0x0)
148# EXE-NEXT:     Other: 0
149# EXE-NEXT:     Section: .text
150# EXE-NEXT:   }
151# EXE-NEXT: ]
152
153# VERDSO:      DynamicSymbols [
154# VERDSO-NEXT:   Symbol {
155# VERDSO-NEXT:     Name: @
156# VERDSO-NEXT:     Value: 0x0
157# VERDSO-NEXT:     Size: 0
158# VERDSO-NEXT:     Binding: Local
159# VERDSO-NEXT:     Type: None
160# VERDSO-NEXT:     Other: 0
161# VERDSO-NEXT:     Section: Undefined
162# VERDSO-NEXT:   }
163# VERDSO-NEXT:   Symbol {
164# VERDSO-NEXT:     Name: bar@
165# VERDSO-NEXT:     Value: 0x0
166# VERDSO-NEXT:     Size: 0
167# VERDSO-NEXT:     Binding: Global
168# VERDSO-NEXT:     Type: Function
169# VERDSO-NEXT:     Other: 0
170# VERDSO-NEXT:     Section: Undefined
171# VERDSO-NEXT:   }
172# VERDSO-NEXT:   Symbol {
173# VERDSO-NEXT:     Name: foo1@@VERSION_1.0
174# VERDSO-NEXT:     Value: 0x1000
175# VERDSO-NEXT:     Size: 0
176# VERDSO-NEXT:     Binding: Global
177# VERDSO-NEXT:     Type: None
178# VERDSO-NEXT:     Other: 0
179# VERDSO-NEXT:     Section: .text
180# VERDSO-NEXT:   }
181# VERDSO-NEXT:   Symbol {
182# VERDSO-NEXT:     Name: foo3@@VERSION_2.0
183# VERDSO-NEXT:     Value: 0x1007
184# VERDSO-NEXT:     Size: 0
185# VERDSO-NEXT:     Binding: Global
186# VERDSO-NEXT:     Type: None
187# VERDSO-NEXT:     Other: 0
188# VERDSO-NEXT:     Section: .text
189# VERDSO-NEXT:   }
190# VERDSO-NEXT: ]
191
192# RUN: llvm-mc -filetype=obj -triple=x86_64-unknown-linux %s -o %t.o
193# RUN: ld.lld -shared %t.o %t2.so -o %t.so
194# RUN: llvm-readobj -dyn-symbols %t.so | FileCheck --check-prefix=ALL %s
195
196# RUN: echo "{ global: foo1; foo3; };" > %t2.script
197# RUN: llvm-mc -filetype=obj -triple=x86_64-unknown-linux %s -o %t.o
198# RUN: ld.lld --version-script %t2.script -shared %t.o %t2.so -o %t.so
199# RUN: llvm-readobj -dyn-symbols %t.so | FileCheck --check-prefix=ALL %s
200
201# ALL:      DynamicSymbols [
202# ALL-NEXT:   Symbol {
203# ALL-NEXT:     Name: @
204# ALL-NEXT:     Value: 0x0
205# ALL-NEXT:     Size: 0
206# ALL-NEXT:     Binding: Local
207# ALL-NEXT:     Type: None
208# ALL-NEXT:     Other: 0
209# ALL-NEXT:     Section: Undefined
210# ALL-NEXT:   }
211# ALL-NEXT:  Symbol {
212# ALL-NEXT:    Name: _start@
213# ALL-NEXT:    Value:
214# ALL-NEXT:    Size: 0
215# ALL-NEXT:    Binding: Global
216# ALL-NEXT:    Type: None
217# ALL-NEXT:    Other: 0
218# ALL-NEXT:    Section: .text
219# ALL-NEXT:  }
220# ALL-NEXT:  Symbol {
221# ALL-NEXT:    Name: bar@
222# ALL-NEXT:    Value:
223# ALL-NEXT:    Size: 0
224# ALL-NEXT:    Binding: Global
225# ALL-NEXT:    Type: Function
226# ALL-NEXT:    Other: 0
227# ALL-NEXT:    Section: Undefined
228# ALL-NEXT:  }
229# ALL-NEXT:  Symbol {
230# ALL-NEXT:    Name: foo1@
231# ALL-NEXT:    Value:
232# ALL-NEXT:    Size: 0
233# ALL-NEXT:    Binding: Global
234# ALL-NEXT:    Type: None
235# ALL-NEXT:    Other: 0
236# ALL-NEXT:    Section: .text
237# ALL-NEXT:  }
238# ALL-NEXT:  Symbol {
239# ALL-NEXT:    Name: foo2@
240# ALL-NEXT:    Value:
241# ALL-NEXT:    Size: 0
242# ALL-NEXT:    Binding: Global
243# ALL-NEXT:    Type: None
244# ALL-NEXT:    Other: 0
245# ALL-NEXT:    Section: .text
246# ALL-NEXT:  }
247# ALL-NEXT:  Symbol {
248# ALL-NEXT:    Name: foo3@
249# ALL-NEXT:    Value:
250# ALL-NEXT:    Size: 0
251# ALL-NEXT:    Binding: Global
252# ALL-NEXT:    Type: None
253# ALL-NEXT:    Other: 0
254# ALL-NEXT:    Section: .text
255# ALL-NEXT:  }
256# ALL-NEXT: ]
257
258.globl foo1
259foo1:
260  call bar@PLT
261  ret
262
263.globl foo2
264foo2:
265  ret
266
267.globl foo3
268foo3:
269  call foo2@PLT
270  ret
271
272.globl _start
273_start:
274  ret
275