• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1# REQUIRES: x86
2# RUN: split-file %s %t
3# RUN: llvm-mc -filetype=obj -triple=x86_64-apple-darwin %t/libfoo.s -o %t/libfoo.o
4# RUN: llvm-mc -filetype=obj -triple=x86_64-apple-darwin %t/nonweakdef.s -o %t/nonweakdef.o
5# RUN: llvm-mc -filetype=obj -triple=x86_64-apple-darwin %t/weakdef.s -o %t/weakdef.o
6# RUN: llvm-mc -filetype=obj -triple=x86_64-apple-darwin %t/common.s -o %t/common.o
7# RUN: %lld -dylib %t/libfoo.o -o %t/libfoo.dylib
8
9## Check that non-weak defined symbols override weak dylib symbols.
10# RUN: %lld %t/nonweakdef.o -L%t -lfoo -o %t/nonweakdef -lSystem
11# RUN: llvm-objdump --macho --weak-bind %t/nonweakdef | FileCheck %s
12
13## Test loading the dylib before the obj file.
14# RUN: %lld -L%t -lfoo %t/nonweakdef.o -o %t/nonweakdef -lSystem
15# RUN: llvm-objdump --macho --weak-bind %t/nonweakdef | FileCheck %s
16
17# CHECK:       Weak bind table:
18# CHECK-NEXT:  segment  section            address     type       addend   symbol
19# CHECK-NEXT:                                          strong              _weak_in_dylib
20# CHECK-EMPTY:
21
22## Check that weak defined symbols do not override weak dylib symbols.
23# RUN: %lld %t/weakdef.o -L%t -lfoo -o %t/weakdef -lSystem
24# RUN: llvm-objdump --macho --weak-bind %t/weakdef | FileCheck %s --check-prefix=NO-WEAK-OVERRIDE
25
26## Test loading the dylib before the obj file.
27# RUN: %lld -L%t -lfoo %t/weakdef.o -o %t/weakdef -lSystem
28# RUN: llvm-objdump --macho --weak-bind %t/weakdef | FileCheck %s --check-prefix=NO-WEAK-OVERRIDE
29
30# NO-WEAK-OVERRIDE:       Weak bind table:
31# NO-WEAK-OVERRIDE-NEXT:  segment section address type addend symbol
32# NO-WEAK-OVERRIDE-EMPTY:
33
34## Check that common symbols take precedence over weak dylib symbols, but do not
35## generate an overridding weak binding.
36# RUN: %lld -L%t -lfoo %t/common.o -o %t/common -lSystem
37# RUN: llvm-objdump --macho --weak-bind %t/common | FileCheck %s --check-prefix=NO-WEAK-OVERRIDE
38# RUN: llvm-objdump --syms %t/common | FileCheck %s --check-prefix=COMMON
39# COMMON-DAG: g     O __DATA,__common _nonweak_in_dylib
40# COMMON-DAG: g     O __DATA,__common _weak_in_dylib
41
42#--- libfoo.s
43
44.globl _weak_in_dylib, _nonweak_in_dylib
45.weak_definition _weak_in_dylib
46
47_weak_in_dylib:
48_nonweak_in_dylib:
49
50#--- nonweakdef.s
51
52.globl _main, _weak_in_dylib, _nonweak_in_dylib
53
54_weak_in_dylib:
55_nonweak_in_dylib:
56
57_main:
58  ret
59
60#--- weakdef.s
61
62.globl _main, _weak_in_dylib, _nonweak_in_dylib
63.weak_definition _weak_in_dylib, _nonweak_in_dylib
64
65_weak_in_dylib:
66_nonweak_in_dylib:
67
68_main:
69  ret
70
71#--- common.s
72
73.globl _main
74.comm _weak_in_dylib, 1
75.comm _nonweak_in_dylib, 1
76
77_main:
78  ret
79