2 # RUN: rm -rf %t; split-file %s %t
3 # RUN: llvm-mc -filetype=obj -triple=x86_64-apple-darwin %t/aliases.s -o %t/aliases.o
4 # RUN: llvm-mc -filetype=obj -triple=x86_64-apple-darwin %t/definitions.s -o %t/definitions.o
5 # RUN: llvm-mc -filetype=obj -triple=x86_64-apple-darwin %t/weak-extern-alias-to-weak.s -o %t/weak-extern-alias-to-weak.o
6 # RUN: llvm-mc -filetype=obj -triple=x86_64-apple-darwin %t/weak-extern-alias-to-strong.s -o %t/weak-extern-alias-to-strong.o
8 # RUN: %lld -lSystem %t/aliases.o %t/definitions.o -o %t/out
9 # RUN: llvm-objdump --macho --syms %t/out | FileCheck %s
11 ## local aliases should be dropped entirely. --implicit-check-not doesn't seem
12 ## to work well with -DAG matches, so we check for _local_alias' absence in a
14 # RUN: llvm-objdump --macho --syms %t/out | FileCheck /dev/null --implicit-check-not _local_alias
16 # CHECK-DAG: [[#%.16x,STRONG:]] g F __TEXT,__text _strong
17 # CHECK-DAG: [[#%.16x,WEAK_1:]] w F __TEXT,__text _weak_1
18 # CHECK-DAG: [[#%.16x,PEXT:]] l F __TEXT,__text .hidden _pext
19 # CHECK-DAG: [[#%.16x,DEAD:]] g F __TEXT,__text _dead
20 # CHECK-DAG: [[#STRONG]] l F __TEXT,__text .hidden _pext_alias
21 # CHECK-DAG: [[#PEXT]] l F __TEXT,__text .hidden _alias_to_pext
22 # CHECK-DAG: [[#STRONG]] g F __TEXT,__text _extern_alias_to_strong
23 # CHECK-DAG: [[#WEAK_1]] w F __TEXT,__text _weak_extern_alias_to_weak
24 # CHECK-DAG: [[#DEAD]] g F __TEXT,__text _no_dead_strip_alias
25 # CHECK-DAG: [[#STRONG]] g F __TEXT,__text _weak_extern_alias_to_strong
27 # RUN: %lld -lSystem -dead_strip %t/aliases.o %t/definitions.o -o %t/dead-stripped
28 # RUN: llvm-objdump --macho --syms %t/dead-stripped | FileCheck %s --check-prefix=STRIPPED
30 # STRIPPED: SYMBOL TABLE:
31 # STRIPPED-NEXT: g F __TEXT,__text _main
32 # STRIPPED-NEXT: g F __TEXT,__text __mh_execute_header
33 # STRIPPED-NEXT: *UND* dyld_stub_binder
36 # RUN: not %lld -lSystem %t/aliases.o %t/definitions.o \
37 # RUN: %t/weak-extern-alias-to-strong.o -o /dev/null 2>&1
39 ## Verify that we preserve the file names of the aliases, rather than using the
40 ## filename of the aliased symbols.
41 # DUP: error: duplicate symbol: _weak_extern_alias_to_weak
42 # DUP-NEXT: >>> defined in {{.*}}aliases.o
43 # DUP-NEXT: >>> defined in {{.*}}weak-extern-alias-to-weak.o
45 ## The following cases are actually all dup symbol errors under ld64. Alias
46 ## symbols are treated like strong extern symbols by ld64 even if the symbol they alias
47 ## is actually weak. LLD OTOH does not check for dup symbols until after
48 ## resolving the aliases; this makes for a simpler implementation.
49 ## The following test cases are meant to elucidate what LLD's behavior is, but
50 ## we should feel free to change it in the future should it be helpful for the
53 # RUN: %lld -lSystem %t/aliases.o %t/definitions.o \
54 # RUN: %t/weak-extern-alias-to-weak.o -o %t/alias-clash-1
55 # RUN: llvm-objdump --macho --syms %t/alias-clash-1 | FileCheck %s --check-prefix WEAK-1
57 # RUN: %lld -lSystem %t/weak-extern-alias-to-weak.o %t/aliases.o \
58 # RUN: %t/definitions.o -o %t/alias-clash-2
59 # RUN: llvm-objdump --macho --syms %t/alias-clash-2 | FileCheck %s --check-prefix WEAK-2
61 # RUN: %lld -lSystem %t/aliases.o %t/definitions.o \
62 # RUN: -alias _weak_2 _weak_extern_alias_to_weak -o %t/opt-vs-symbol
63 # RUN: llvm-objdump --macho --syms %t/opt-vs-symbol | FileCheck %s --check-prefix WEAK-2
65 # RUN: %lld -lSystem -alias _weak_2 _weak_extern_alias_to_weak %t/aliases.o \
66 # RUN: %t/definitions.o -o %t/opt-vs-symbol
67 # RUN: llvm-objdump --macho --syms %t/opt-vs-symbol | FileCheck %s --check-prefix WEAK-2
69 # WEAK-1-DAG: [[#%.16x,WEAK_1:]] w F __TEXT,__text _weak_1
70 # WEAK-1-DAG: [[#WEAK_1]] w F __TEXT,__text _weak_extern_alias_to_weak
72 # WEAK-2-DAG: [[#%.16x,WEAK_2:]] w F __TEXT,__text _weak_2
73 # WEAK-2-DAG: [[#WEAK_2]] w F __TEXT,__text _weak_extern_alias_to_weak
76 .globl _extern_alias_to_strong, _weak_extern_alias_to_weak
77 .weak_definition _weak_extern_alias_to_weak
79 ## Private extern aliases result in local symbols in the output (i.e. it is as
80 ## if the aliased symbol is also private extern.)
81 .private_extern _pext_alias
83 ## This test case demonstrates that it doesn't matter whether the alias itself
84 ## is strong or weak. Rather, what matters is whether the aliased symbol is
86 .globl _weak_extern_alias_to_strong
87 .weak_definition _weak_extern_alias_to_strong
89 ## no_dead_strip doesn't retain the aliased symbol if it is dead
90 .globl _no_dead_strip_alias
91 .no_dead_strip _no_dead_strip_alias
94 _alias_to_pext
= _pext
96 _extern_alias_to_strong
= _strong
97 _weak_extern_alias_to_weak
= _weak_1
98 _weak_extern_alias_to_strong
= _strong
100 _pext_alias
= _strong
101 _local_alias
= _strong
102 _no_dead_strip_alias
= _dead
104 .subsections_via_symbols
106 #--- weak-extern-alias-to-weak.s
107 .globl _weak_extern_alias_to_weak
108 .weak_definition _weak_extern_alias_to_weak
109 _weak_extern_alias_to_weak
= _weak_2
111 #--- weak-extern-alias-to-strong.s
112 .globl _weak_extern_alias_to_strong
113 .weak_definition _weak_extern_alias_to_strong
114 _weak_extern_alias_to_strong
= _strong
117 .globl _strong, _weak_1, _weak_2, _dead
118 .private_extern _pext
119 .weak_definition _weak_1
120 .weak_definition _weak_2
136 .subsections_via_symbols