[clang][modules] Don't prevent translation of FW_Private includes when explicitly...
[llvm-project.git] / lld / test / MachO / common-symbol-resolution.s
blobf1d7da4d702a8dea868456d2959553091d3209e4
1 # REQUIRES: x86
2 # RUN: rm -rf %t; split-file %s %t
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
12 # RUN: %lld -lSystem -order_file %t/order -dylib %t/libfoo.o -o %t/libfoo.dylib
14 # RUN: llvm-ar rcs %t/defined.a %t/defined.o
15 # RUN: llvm-ar rcs %t/weak-defined-and-common.a %t/weak-defined.o %t/common.o
16 # RUN: llvm-ar rcs %t/common-and-weak-defined.a %t/common.o %t/weak-defined.o
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
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
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
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
45 ## Defined symbols have the same precedence as common symbols within an archive.
46 # RUN: %lld -lSystem -order_file %t/order %t/weak-defined-and-common.a %t/calls-foo.o -o %t/calls-foo
47 # RUN: llvm-objdump --syms %t/calls-foo | FileCheck %s --check-prefix=WEAK-DEFINED
48 # RUN: %lld -lSystem -order_file %t/order %t/calls-foo.o %t/common-and-weak-defined.a -o %t/calls-foo
49 # RUN: llvm-objdump --syms %t/calls-foo | FileCheck %s --check-prefix=COMMON
51 ## Common symbols take precedence over dylib symbols.
52 # RUN: %lld -lSystem -order_file %t/order %t/libfoo.dylib %t/weak-common.o %t/test.o -o %t/test
53 # RUN: llvm-objdump --syms %t/test | FileCheck %s --check-prefix=LARGER-COMMON
54 # RUN: %lld -lSystem -order_file %t/order %t/weak-common.o %t/libfoo.dylib %t/test.o -o %t/test
55 # RUN: llvm-objdump --syms %t/test | FileCheck %s --check-prefix=LARGER-COMMON
57 # LARGER-COMMON-DAG: [[#%x, FOO_ADDR:]] g O __DATA,__common _foo
58 # LARGER-COMMON-DAG: [[#FOO_ADDR + 2]] g O __DATA,__common _foo_end
60 # COMMON: g O __DATA,__common _foo
61 # DEFINED: g F __TEXT,__text _foo
62 # WEAK-DEFINED: w F __TEXT,__text _foo
64 #--- order
65 ## %t/order is important as we determine the size of a given symbol via the
66 ## address of the next symbol.
67 _foo
68 _foo_end
70 #--- common.s
71 .comm _foo, 1
73 .globl _bar
74 _bar:
76 #--- weak-common.s
77 .weak_definition _foo
78 .comm _foo, 2
80 #--- defined.s
81 .globl _foo
82 _foo:
83 .quad 0x1234
85 #--- weak-defined.s
86 .globl _foo
87 .weak_definition _foo
88 _foo:
89 .quad 0x1234
91 #--- libfoo.s
92 .globl _foo
93 _foo:
94 .quad 0x1234
96 #--- test.s
97 .comm _foo_end, 1
99 .globl _main
100 _main:
103 #--- calls-foo.s
104 .comm _foo_end, 1
106 .globl _main
107 _main:
108 callq _foo