1# REQUIRES: x86 2# RUN: rm -rf %t; 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: 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 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## 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 50 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 56 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 59 60# COMMON: g O __DATA,__common _foo 61# DEFINED: g F __TEXT,__text _foo 62# WEAK-DEFINED: w F __TEXT,__text _foo 63 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 69 70#--- common.s 71.comm _foo, 1 72 73.globl _bar 74_bar: 75 76#--- weak-common.s 77.weak_definition _foo 78.comm _foo, 2 79 80#--- defined.s 81.globl _foo 82_foo: 83 .quad 0x1234 84 85#--- weak-defined.s 86.globl _foo 87.weak_definition _foo 88_foo: 89 .quad 0x1234 90 91#--- libfoo.s 92.globl _foo 93_foo: 94 .quad 0x1234 95 96#--- test.s 97.comm _foo_end, 1 98 99.globl _main 100_main: 101 ret 102 103#--- calls-foo.s 104.comm _foo_end, 1 105 106.globl _main 107_main: 108 callq _foo 109 ret 110