llvm-project
146 строк · 5.6 Кб
1# REQUIRES: x86
2
3# RUN: rm -rf %t; split-file %s %t
4# RUN: llvm-mc -filetype=obj -triple=x86_64-apple-macos \
5# RUN: %t/basics.s -o %t/basics.o
6
7## Check that .private_extern symbols are marked as local in the symbol table
8## and aren't in the export trie.
9# RUN: %lld -dylib %t/basics.o -o %t/basics
10# RUN: llvm-objdump --syms --exports-trie %t/basics | \
11# RUN: FileCheck --check-prefix=EXPORTS %s
12# RUN: llvm-nm -m %t/basics | FileCheck --check-prefix=EXPORTS-NM %s
13# EXPORTS-LABEL: SYMBOL TABLE:
14# EXPORTS-DAG: [[#%x, FOO_ADDR:]] l {{.*}} _foo
15# EXPORTS-DAG: [[#%x, BAR_ADDR:]] g {{.*}} _bar
16# EXPORTS-LABEL: Exports trie:
17# EXPORTS-NOT: 0x{{0*}}[[#%X, FOO_ADDR]] _foo
18# EXPORTS-DAG: 0x{{0*}}[[#%X, BAR_ADDR]] _bar
19# EXPORTS-NOT: 0x{{0*}}[[#%X, FOO_ADDR]] _foo
20# EXPORTS-NM-DAG: (__TEXT,__cstring) non-external (was a private external) _foo
21# EXPORTS-NM-DAG: (__TEXT,__cstring) external _bar
22
23## The tests for weak .private_extern symbols not being referenced in the
24## weak bind table can be found in weak-private-extern.s
25
26#--- basics.s
27.section __TEXT,__cstring
28
29.globl _foo, _bar
30.private_extern _foo
31
32_foo:
33.asciz "Foo"
34
35_bar:
36.asciz "Bar"
37
38# RUN: llvm-mc -filetype=obj -triple=x86_64-apple-macos \
39# RUN: %t/strong-globl.s -o %t/strong-globl.o
40# RUN: llvm-mc -filetype=obj -triple=x86_64-apple-macos \
41# RUN: %t/weak-globl.s -o %t/weak-globl.o
42
43# RUN: llvm-mc -filetype=obj -triple=x86_64-apple-macos \
44# RUN: %t/strong-private.s -o %t/strong-private.o
45# RUN: llvm-mc -filetype=obj -triple=x86_64-apple-macos \
46# RUN: %t/weak-private.s -o %t/weak-private.o
47
48## weak + strong symbol takes privateness from strong symbol
49## - weak private extern + strong extern = strong extern (for both .o orderings)
50# RUN: %lld -dylib %t/weak-private.o %t/strong-globl.o -o %t/wpsg
51# RUN: llvm-nm -m %t/wpsg | FileCheck --check-prefix=EXTERNAL %s
52# RUN: %lld -dylib %t/strong-globl.o %t/weak-private.o -o %t/sgwp
53# RUN: llvm-nm -m %t/sgwp | FileCheck --check-prefix=EXTERNAL %s
54# EXTERNAL: (__TEXT,__text) external _foo
55## - weak extern + strong private extern = strong private extern
56## (for both .o orderings)
57# RUN: %lld -dylib %t/weak-globl.o %t/strong-private.o -o %t/wgsp
58# RUN: llvm-nm -m %t/wgsp | FileCheck --check-prefix=NONEXTERNAL %s
59# RUN: %lld -dylib %t/strong-private.o %t/weak-globl.o -o %t/spwg
60# RUN: llvm-nm -m %t/spwg | FileCheck --check-prefix=NONEXTERNAL %s
61# NONEXTERNAL: (__TEXT,__text) non-external (was a private external) _foo
62
63## weak + weak symbol take weaker privateness
64## - weak extern + weak private extern = weak extern (both orders)
65# RUN: %lld -dylib %t/weak-private.o %t/weak-globl.o -o %t/wpwg
66# RUN: llvm-nm -m %t/wpwg | FileCheck --check-prefix=WEAK-EXTERNAL %s
67# RUN: %lld -dylib %t/weak-globl.o %t/weak-private.o -o %t/wgwp
68# RUN: llvm-nm -m %t/wgwp | FileCheck --check-prefix=WEAK-EXTERNAL %s
69# WEAK-EXTERNAL: (__TEXT,__text) weak external _foo
70## - weak private extern + weak private extern = weak private extern
71# RUN: %lld -dylib %t/weak-private.o %t/weak-private.o -o %t/wpwp
72# RUN: llvm-nm -m %t/wpwp | FileCheck --check-prefix=NONEXTERNAL %s
73
74#--- strong-globl.s
75.globl _foo
76_foo:
77retq
78
79#--- weak-globl.s
80.globl _foo
81.weak_definition _foo
82_foo:
83retq
84
85#--- strong-private.s
86.private_extern _foo
87.globl _foo
88_foo:
89retq
90
91#--- weak-private.s
92.private_extern _foo
93.globl _foo
94.weak_definition _foo
95_foo:
96retq
97
98# RUN: llvm-mc -filetype=obj -triple=x86_64-apple-macos \
99# RUN: %t/comm-small.s -o %t/comm-small.o
100# RUN: llvm-mc -filetype=obj -triple=x86_64-apple-macos \
101# RUN: %t/comm-large.s -o %t/comm-large.o
102
103# RUN: llvm-mc -filetype=obj -triple=x86_64-apple-macos \
104# RUN: %t/comm-small-private.s -o %t/comm-small-private.o
105# RUN: llvm-mc -filetype=obj -triple=x86_64-apple-macos \
106# RUN: %t/comm-large-private.s -o %t/comm-large-private.o
107
108## For common symbols the larger one wins.
109## - smaller private extern + larger extern = larger extern
110# RUN: %lld -dylib %t/comm-small-private.o %t/comm-large.o -o %t/cspcl
111# RUN: llvm-nm -m %t/cspcl | FileCheck --check-prefix=COMMON-EXTERNAL %s
112# RUN: %lld -dylib %t/comm-large.o %t/comm-small-private.o -o %t/clcsp
113# RUN: llvm-nm -m %t/clcsp | FileCheck --check-prefix=COMMON-EXTERNAL %s
114# COMMON-EXTERNAL: (__DATA,__common) external _foo
115## - smaller extern + larger private extern = larger private extern
116# RUN: %lld -dylib %t/comm-large-private.o %t/comm-small.o -o %t/clpcs
117# RUN: llvm-nm -m %t/clpcs | FileCheck --check-prefix=COMMON-NONEXTERNAL %s
118# RUN: %lld -dylib %t/comm-small.o %t/comm-large-private.o -o %t/csclp
119# RUN: llvm-nm -m %t/csclp | FileCheck --check-prefix=COMMON-NONEXTERNAL %s
120# COMMON-NONEXTERNAL: (__DATA,__common) non-external (was a private external) _foo
121
122# For common symbols with the same size, the privateness of the symbol seen
123# later wins (!).
124## - equal private extern + equal extern = equal extern (both orders)
125# RUN: %lld -dylib %t/comm-small-private.o %t/comm-small.o -o %t/cspcs
126# RUN: llvm-nm -m %t/cspcs | FileCheck --check-prefix=COMMON-EXTERNAL %s
127## - equal extern + equal private extern = equal private extern (both orders)
128# RUN: %lld -dylib %t/comm-small.o %t/comm-small-private.o -o %t/cscsp
129# RUN: llvm-nm -m %t/cscsp | FileCheck --check-prefix=COMMON-NONEXTERNAL %s
130## - equal private extern + equal private extern = equal private extern
131# RUN: %lld -dylib %t/comm-small-private.o %t/comm-small-private.o -o %t/cspcsp
132# RUN: llvm-nm -m %t/cspcsp | FileCheck --check-prefix=COMMON-NONEXTERNAL %s
133
134#--- comm-small.s
135.comm _foo,4,2
136
137#--- comm-large.s
138.comm _foo,8,3
139
140#--- comm-small-private.s
141.private_extern _foo
142.comm _foo,4,2
143
144#--- comm-large-private.s
145.private_extern _foo
146.comm _foo,8,3
147