• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1# REQUIRES: x86
2# RUN: split-file %s %t
3
4# RUN: llvm-mc -filetype=obj -triple=x86_64-apple-darwin %t/common.s -o %t/common.o
5# RUN: llvm-mc -filetype=obj -triple=x86_64-apple-darwin %t/weak-common.s -o %t/weak-common.o
6# RUN: llvm-mc -filetype=obj -triple=x86_64-apple-darwin %t/defined.s -o %t/defined.o
7# RUN: llvm-mc -filetype=obj -triple=x86_64-apple-darwin %t/weak-defined.s -o %t/weak-defined.o
8# RUN: llvm-mc -filetype=obj -triple=x86_64-apple-darwin %t/libfoo.s -o %t/libfoo.o
9# RUN: llvm-mc -filetype=obj -triple=x86_64-apple-darwin %t/test.s -o %t/test.o
10# RUN: llvm-mc -filetype=obj -triple=x86_64-apple-darwin %t/calls-foo.s -o %t/calls-foo.o
11
12# RUN: %lld -lSystem -order_file %t/order -dylib %t/libfoo.o -o %t/libfoo.dylib
13
14# RUN: rm -f %t/defined.a %t/weak-defined-and-common.a
15# RUN: llvm-ar rcs %t/defined.a %t/defined.o
16# RUN: llvm-ar rcs %t/weak-defined-and-common.a %t/weak-defined.o %t/common.o
17
18## The weak attribute appears to have no effect on common symbols. Given two
19## common symbols of the same name, we always pick the one with the larger size,
20## regardless of whether it is weak. Moreover, the resolved symbol in the output
21## file will always be non-weak, even if the winning input symbol definition was
22## weak.
23# RUN: %lld -lSystem -order_file %t/order %t/common.o %t/weak-common.o %t/test.o -o %t/test
24# RUN: llvm-objdump --syms %t/test | FileCheck %s --check-prefix=LARGER-COMMON
25# RUN: %lld -lSystem -order_file %t/order %t/weak-common.o %t/common.o %t/test.o -o %t/test
26# RUN: llvm-objdump --syms %t/test | FileCheck %s --check-prefix=LARGER-COMMON
27
28## Defined symbols are the only ones that take precedence over common symbols.
29# RUN: %lld -lSystem -order_file %t/order %t/defined.o %t/common.o %t/test.o -o %t/test
30# RUN: llvm-objdump --syms %t/test | FileCheck %s --check-prefix=DEFINED
31# RUN: %lld -lSystem -order_file %t/order %t/common.o %t/defined.o %t/test.o -o %t/test
32# RUN: llvm-objdump --syms %t/test | FileCheck %s --check-prefix=DEFINED
33
34# RUN: %lld -lSystem -order_file %t/order %t/weak-defined.o %t/common.o %t/test.o -o %t/test
35# RUN: llvm-objdump --syms %t/test | FileCheck %s --check-prefix=WEAK-DEFINED
36# RUN: %lld -lSystem -order_file %t/order %t/common.o %t/weak-defined.o %t/test.o -o %t/test
37# RUN: llvm-objdump --syms %t/test | FileCheck %s --check-prefix=WEAK-DEFINED
38
39## Common symbols take precedence over archive symbols.
40# RUN: %lld -lSystem -order_file %t/order %t/defined.a %t/weak-common.o %t/test.o -o %t/test
41# RUN: llvm-objdump --syms %t/test | FileCheck %s --check-prefix=LARGER-COMMON
42# RUN: %lld -lSystem -order_file %t/order %t/weak-common.o %t/defined.a %t/test.o -o %t/test
43# RUN: llvm-objdump --syms %t/test | FileCheck %s --check-prefix=LARGER-COMMON
44
45## If an archive has both a common and a defined symbol, the defined one should
46## win.
47# RUN: %lld -lSystem -order_file %t/order %t/weak-defined-and-common.a %t/calls-foo.o -o %t/calls-foo
48# RUN: llvm-objdump --syms %t/calls-foo | FileCheck %s --check-prefix=WEAK-DEFINED
49# RUN: %lld -lSystem -order_file %t/order %t/calls-foo.o %t/weak-defined-and-common.a -o %t/calls-foo
50# RUN: llvm-objdump --syms %t/calls-foo | FileCheck %s --check-prefix=WEAK-DEFINED
51
52## Common symbols take precedence over dylib symbols.
53# RUN: %lld -lSystem -order_file %t/order %t/libfoo.dylib %t/weak-common.o %t/test.o -o %t/test
54# RUN: llvm-objdump --syms %t/test | FileCheck %s --check-prefix=LARGER-COMMON
55# RUN: %lld -lSystem -order_file %t/order %t/weak-common.o %t/libfoo.dylib %t/test.o -o %t/test
56# RUN: llvm-objdump --syms %t/test | FileCheck %s --check-prefix=LARGER-COMMON
57
58# LARGER-COMMON-LABEL: SYMBOL TABLE:
59# LARGER-COMMON-DAG:   [[#%x, FOO_ADDR:]] g     O __DATA,__common _foo
60# LARGER-COMMON-DAG:   [[#FOO_ADDR + 2]]  g     O __DATA,__common _foo_end
61
62# DEFINED-LABEL:       SYMBOL TABLE:
63# DEFINED:             g     F __TEXT,__text _foo
64
65# WEAK-DEFINED-LABEL:  SYMBOL TABLE:
66# WEAK-DEFINED:        w     F __TEXT,__text _foo
67
68#--- order
69## %t/order is important as we determine the size of a given symbol via the
70## address of the next symbol.
71_foo
72_foo_end
73
74#--- common.s
75.comm _foo, 1
76
77.globl _bar
78_bar:
79
80#--- weak-common.s
81.weak_definition _foo
82.comm _foo, 2
83
84#--- defined.s
85.globl _foo
86_foo:
87  .quad 0x1234
88
89#--- weak-defined.s
90.globl _foo
91.weak_definition _foo
92_foo:
93  .quad 0x1234
94
95#--- libfoo.s
96.globl _foo
97_foo:
98  .quad 0x1234
99
100#--- test.s
101.comm _foo_end, 1
102
103.globl _main
104_main:
105  ret
106
107#--- calls-foo.s
108.comm _foo_end, 1
109
110.globl _main
111_main:
112  callq _foo
113  ret
114