2 # RUN: rm -rf %t; split-file %s %t
4 ## This tests that if two input files define the same weak symbol, we only
5 ## write it to the output once (...assuming both input files use
6 ## .subsections_via_symbols).
8 # RUN: llvm-mc -filetype=obj -triple=x86_64-apple-darwin %t/weak-sub.s -o %t/weak-sub.o
9 # RUN: llvm-mc -filetype=obj -triple=x86_64-apple-darwin %t/weak-nosub.s -o %t/weak-nosub.o
11 ## Test that weak symbols are emitted just once with .subsections_via_symbols
12 # RUN: %lld -dylib -o %t/out.dylib %t/weak-sub.o %t/weak-sub.o
13 # RUN: llvm-otool -jtV %t/out.dylib | FileCheck --check-prefix=SUB %s
14 # RUN: %lld -dylib -o %t/out.dylib %t/weak-nosub.o %t/weak-sub.o
15 # RUN: llvm-otool -jtV %t/out.dylib | FileCheck --check-prefix=SUB %s
16 # RUN: %lld -dylib -o %t/out.dylib %t/weak-sub.o %t/weak-nosub.o
17 # RUN: llvm-otool -jtV %t/out.dylib | FileCheck --check-prefix=SUB %s
25 ## We can even strip weak symbols without subsections_via_symbols as long
26 ## as none of the weak symbols in a section are needed.
27 # RUN: %lld -dylib -o %t/out.dylib %t/weak-nosub.o %t/weak-nosub.o
28 # RUN: llvm-otool -jtV %t/out.dylib | FileCheck --check-prefix=SUB %s
30 ## Test that omitted weak symbols don't add entries to the compact unwind table.
31 # RUN: llvm-mc -filetype=obj -triple=x86_64-apple-darwin19.0.0 %t/weak-sub-lsda.s -o %t/weak-sub-lsda.o
32 # RUN: %lld -dylib -lc++ -o %t/out.dylib %t/weak-sub-lsda.o %t/weak-sub-lsda.o
33 # RUN: llvm-objdump --macho --unwind-info --syms %t/out.dylib | FileCheck %s --check-prefix=ONE-UNWIND
34 # RUN: %lld -dylib -lc++ -o %t/out.dylib %t/weak-sub.o %t/weak-sub-lsda.o
35 # RUN: llvm-objdump --macho --unwind-info --syms %t/out.dylib | FileCheck %s --check-prefix=NO-UNWIND
36 # RUN: yaml2obj %t/weak-sub-lsda-r.yaml -o %t/weak-sub-lsda-r.o
37 # RUN: %lld -dylib -lc++ -o %t/out.dylib %t/weak-sub.o %t/weak-sub-lsda-r.o
38 # RUN: llvm-objdump --macho --unwind-info --syms %t/out.dylib | FileCheck %s --check-prefix=NO-UNWIND
40 # ONE-UNWIND: SYMBOL TABLE:
41 # ONE-UNWIND-DAG: [[#%x,FOO:]] w F __TEXT,__text _foo
42 # ONE-UNWIND-NOT: __TEXT,__text _foo
44 # ONE-UNWIND: Contents of __unwind_info section:
45 # ONE-UNWIND: LSDA descriptors:
46 # ONE-UNWIND: [0]: function offset=0x[[#%.8x,FOO]]
47 # ONE-UNWIND-NOT: [1]:
48 # ONE-UNWIND: Second level indices:
49 # ONE-UNWIND-DAG: [0]: function offset=0x[[#%.8x,FOO]]
50 # ONE-UNWIND-NOT: [1]:
52 # NO-UNWIND: SYMBOL TABLE:
53 # NO-UNWIND-DAG: [[#%x,FOO:]] w F __TEXT,__text _foo
54 # NO-UNWIND-NOT: __TEXT,__text _foo
55 # NO-UNWIND-NOT: Contents of __unwind_info section:
57 ## Test interaction with .alt_entry
58 ## FIXME: ld64 manages to strip both one copy of _foo and _bar each.
59 ## We only manage this if we're lucky and the object files are in
60 ## the right order. We're happy to not crash at link time for now.
61 # RUN: llvm-mc -filetype=obj -triple=x86_64-apple-darwin19.0.0 %t/weak-sub-alt.s -o %t/weak-sub-alt.o
62 # RUN: llvm-mc -filetype=obj -triple=x86_64-apple-darwin19.0.0 %t/weak-sub-alt2.s -o %t/weak-sub-alt2.o
63 # RUN: %lld -dylib -o %t/out.dylib %t/weak-sub-alt.o %t/weak-sub-alt2.o
64 # RUN: %lld -dylib -o %t/out.dylib %t/weak-sub-alt2.o %t/weak-sub-alt.o
66 # RUN: llvm-mc -filetype=obj -triple=x86_64-apple-darwin19.0.0 %t/weak-aligned-1.s -o %t/weak-aligned-1.o
67 # RUN: llvm-mc -filetype=obj -triple=x86_64-apple-darwin19.0.0 %t/weak-aligned-2.s -o %t/weak-aligned-2.o
68 # RUN: %lld -o %t/out -lSystem %t/weak-aligned-1.o %t/weak-aligned-2.o
69 # RUN: llvm-objdump --syms --section=__const --full-contents %t/out | FileCheck --check-prefixes=ALIGN,ALIGN2 %s
70 # RUN: %lld -o %t/out -lSystem %t/weak-aligned-1.o %t/weak-aligned-2.o -dead_strip
71 # RUN: llvm-objdump --syms --section=__const --full-contents %t/out | FileCheck --check-prefixes=ALIGN,ALIGN3 %s
72 # ALIGN: SYMBOL TABLE:
73 # ALIGN-DAG: [[#%x, ADDR:]] l O __DATA_CONST,__const .hidden _weak1
74 # ALIGN2-DAG: {{0*}}[[#ADDR+ 0x4]] l O __DATA_CONST,__const .hidden _weak3
75 # ALIGN3-DAG: {{0*}}[[#ADDR+ 0x4]] l O __DATA_CONST,__const .hidden _weak2
76 # ALIGN2-DAG: {{0*}}[[#ADDR+ 0x8]] l O __DATA_CONST,__const .hidden _weak2
77 # ALIGN-DAG: {{0*}}[[#ADDR+0x10]] g O __DATA_CONST,__const _aligned
78 # ALIGN: Contents of section __DATA_CONST,__const:
79 # ALIGN2-NEXT: {{0*}}[[#ADDR]] 11111111 33333333 22222222 00000000
80 # ALIGN3-NEXT: {{0*}}[[#ADDR]] 11111111 22222222 00000000 00000000
81 # ALIGN-NEXT: {{0*}}[[#ADDR+0x10]] 81818181 81818181 82828282 82828282
83 # RUN: llvm-mc -filetype=obj -triple=x86_64-apple-darwin19.0.0 %t/weak-def.s -o %t/weak-def.o
84 # RUN: llvm-mc -filetype=obj -triple=x86_64-apple-darwin19.0.0 %t/strong-def.s -o %t/strong-def.o
85 # RUN: %lld -dylib -lc++ -o %t/weak-strong-mixed.dylib %t/weak-def.o %t/strong-def.o
86 # RUN: %lld -dylib -lc++ -o %t/strong-weak-mixed.dylib %t/strong-def.o %t/weak-def.o
87 ## Check that omitted weak symbols are not adding their section and unwind stuff.
89 # RUN: llvm-otool -jtV %t/weak-strong-mixed.dylib | FileCheck --check-prefix=MIXED %s
90 # RUN: llvm-otool -jtV %t/strong-weak-mixed.dylib | FileCheck --check-prefix=MIXED %s
91 # MIXED: (__TEXT,__text) section
93 # MIXED-NEXT: {{.+}} 33 33 xorl (%rbx), %esi
94 # MIXED-NEXT: {{.+}} 33 33 xorl (%rbx), %esi
95 # MIXED-NEXT: {{.+}} c3 retq
97 # RUN: llvm-objdump --macho --syms --unwind-info %t/weak-strong-mixed.dylib | FileCheck --check-prefix=MIXED-UNWIND %s
98 # RUN: llvm-objdump --macho --syms --unwind-info %t/strong-weak-mixed.dylib | FileCheck --check-prefix=MIXED-UNWIND %s
99 # MIXED-UNWIND: g F __TEXT,__text _foo
100 # MIXED-UNWIND-NOT: Contents of __unwind_info section:
104 .weak_definition _foo, _bar
109 .subsections_via_symbols
113 .weak_definition _foo, _bar
120 .section __TEXT,__text,regular,pure_instructions
123 .weak_definition _foo
126 .cfi_personality 155, ___gxx_personality_v0
127 .cfi_lsda 16, Lexception
129 .cfi_def_cfa_offset 128
132 .cfi_def_cfa_register %rbp
137 .section __TEXT,__gcc_except_tab
141 .subsections_via_symbols
145 .weak_definition _foo
149 # Alternative entry point to _foo (strong)
159 .subsections_via_symbols
163 .weak_definition _foo
167 # Alternative entry point to _foo (weak)
168 .weak_definition _bar
177 .subsections_via_symbols
179 #--- weak-aligned-1.s
180 .section __DATA,__const
183 .weak_def_can_be_hidden _weak1
188 .weak_def_can_be_hidden _weak3
192 .subsections_via_symbols
194 #--- weak-aligned-2.s
195 # _weak1 and _weak3 are already in weak-aligned-1,
196 # so from _weak1-3 in this file only _weak2 is used.
197 # However, _aligned still has to stay aligned to a 16-byte boundary.
198 .section __DATA,__const
201 .weak_def_can_be_hidden _weak1
206 .weak_def_can_be_hidden _weak2
211 .weak_def_can_be_hidden _weak3
215 .section __DATA,__const
219 .8byte
0x8181818181818181
220 .8byte
0x8282828282828282
222 .section __TEXT,__text
225 movl _weak1
(%rip
), %eax
226 movl _weak2
(%rip
), %ebx
227 movaps _aligned
(%rip
), %xmm0
230 .subsections_via_symbols
233 .section __TEXT,__text,regular,pure_instructions
236 .weak_definition _foo
239 .cfi_personality 155, ___gxx_personality_v0
240 .cfi_lsda 16, Lexception
242 .cfi_def_cfa_offset 128
245 .cfi_def_cfa_register %rbp
250 .section __TEXT,__gcc_except_tab
254 .subsections_via_symbols
262 .subsections_via_symbols
264 #--- weak-sub-lsda-r.yaml
265 ## This was generated from compiling weak-sub-lsda.s above at rev a2404f11c77e
266 ## and then running it through `ld -r`. This converts a number of unwind-related
267 ## relocations from section- to symbol-based ones.
303 content
: 554889E55DC3
304 - sectname
: __gcc_except_tab
316 content
: '0000000000000000000000000000000000000000000000000000000000000000'
317 - sectname
: __eh_frame
329 content
: 1C00000000000000017A504C5200017810079B0400000010100C0708900100002C00000004000000F8FFFFFFFFFFFFFF060000000000000008E7FFFFFFFFFFFFFF410E800111067A430D060000000000
387 - sectname
: __compact_unwind
399 content
: '0000000000000000060000000000004100000000000000000000000000000000'
474 - ___gxx_personality_v0