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
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
65 ## %t/order is important as we determine the size of a given symbol via the
66 ## address of the next symbol.