llvm-project
132 строки · 6.5 Кб
1# REQUIRES: x86
2# RUN: rm -rf %t; split-file %s %t
3
4## With -flat_namespace, non-weak extern symbols in dylibs become interposable.
5## Check that we generate the correct bindings for them. The test also includes
6## other symbol types like weak externs to verify we continue to do the same
7## (correct) thing even when `-flat_namespace` is enabled, instead of generating
8## spurious bindings.
9
10# RUN: llvm-mc -filetype=obj -triple=x86_64-apple-macos -o %t/foo.o %t/foo.s
11# RUN: %lld -lSystem -flat_namespace -o %t/foo %t/foo.o
12# RUN: %lld -lSystem -flat_namespace -fixup_chains -o %t/chained %t/foo.o
13# RUN: %lld -lSystem -dylib -flat_namespace -o %t/foo.dylib %t/foo.o
14# RUN: %lld -lSystem -dylib -flat_namespace -fixup_chains -o %t/chained.dylib %t/foo.o
15# RUN: %lld -lSystem -bundle -flat_namespace -o %t/foo.bundle %t/foo.o
16# RUN: %lld -lSystem -bundle -flat_namespace -fixup_chains -o %t/chained.bundle %t/foo.o
17# RUN: llvm-objdump --macho --syms --rebase --bind --lazy-bind --weak-bind %t/foo | \
18# RUN: FileCheck %s --check-prefixes=SYMS,EXEC --implicit-check-not=_private_extern
19# RUN: llvm-objdump --macho --syms %t/chained >> %t/chained.objdump
20# RUN: llvm-objdump --macho --dyld-info %t/chained >> %t/chained.objdump
21# RUN: FileCheck %s --check-prefixes=SYMS,CHAINED-EXEC < %t/chained.objdump
22# RUN: llvm-objdump --macho --syms %t/chained.dylib >> %t/dylib.objdump
23# RUN: llvm-objdump --macho --dyld-info %t/chained.dylib >> %t/dylib.objdump
24# RUN: FileCheck %s --check-prefixes=SYMS,CHAINED-DYLIB < %t/dylib.objdump
25# RUN: llvm-objdump --macho --syms %t/chained.bundle >> %t/bundle.objdump
26# RUN: llvm-objdump --macho --dyld-info %t/chained.bundle >> %t/bundle.objdump
27# RUN: FileCheck %s --check-prefixes=SYMS,CHAINED-DYLIB < %t/bundle.objdump
28
29# SYMS: SYMBOL TABLE:
30# SYMS-DAG: [[#%x, EXTERN_REF:]] l O __DATA,__data _extern_ref
31# SYMS-DAG: [[#%x, LOCAL_REF:]] l O __DATA,__data _local_ref
32# SYMS-DAG: [[#%x, WEAK_REF:]] l O __DATA,__data _weak_ref
33# SYMS-DAG: [[#%x, TLV_REF:]] g O __DATA,__thread_vars _tlv
34
35## Executables with -flat_namespace don't have interposable externs.
36# EXEC: Rebase table:
37# EXEC-NEXT: segment section address type
38# EXEC-DAG: __DATA __la_symbol_ptr 0x[[#%X, WEAK_LAZY:]] pointer
39# EXEC-DAG: __DATA __data 0x[[#%.8X, EXTERN_REF]] pointer
40# EXEC-DAG: __DATA __data 0x[[#%.8X, LOCAL_REF]] pointer
41# EXEC-DAG: __DATA __data 0x[[#%.8X, WEAK_REF]] pointer
42# EXEC-EMPTY:
43# EXEC-NEXT: Bind table:
44# EXEC-NEXT: segment section address type addend dylib symbol
45# EXEC-EMPTY:
46# EXEC-NEXT: Lazy bind table:
47# EXEC-NEXT: segment section address dylib symbol
48# EXEC-EMPTY:
49# EXEC-NEXT: Weak bind table:
50# EXEC-NEXT: segment section address type addend symbol
51# EXEC-NEXT: __DATA __la_symbol_ptr 0x[[#%.8X, WEAK_LAZY]] pointer 0 _weak_extern
52# EXEC-NEXT: __DATA __data 0x[[#%.8X, WEAK_REF]] pointer 0 _weak_extern
53# EXEC-EMPTY:
54
55# CHAINED-EXEC: dyld information:
56# CHAINED-EXEC-NEXT: segment section address pointer type addend dylib symbol/vm address
57# CHAINED-EXEC-DAG: __DATA_CONST __got {{.*}} {{.*}} bind 0x0 weak _weak_extern
58# CHAINED-EXEC-DAG: __DATA __data 0x[[#%x, EXTERN_REF]] {{.*}} rebase {{.*}}
59# CHAINED-EXEC-DAG: __DATA __data 0x[[#%x, WEAK_REF]] {{.*}} bind 0x0 weak _weak_extern
60# CHAINED-EXEC-DAG: __DATA __data 0x[[#%x, LOCAL_REF]] {{.*}} rebase {{.*}}
61# CHAINED-EXEC-EMPTY:
62
63# DYLIB: Rebase table:
64# DYLIB-NEXT: segment section address type
65# DYLIB-DAG: __DATA __la_symbol_ptr 0x[[#%X, WEAK_LAZY:]] pointer
66# DYLIB-DAG: __DATA __la_symbol_ptr 0x[[#%X, EXTERN_LAZY:]] pointer
67# DYLIB-DAG: __DATA __data 0x[[#%.8X, EXTERN_REF]] pointer
68# DYLIB-DAG: __DATA __data 0x[[#%.8X, LOCAL_REF]] pointer
69# DYLIB-DAG: __DATA __data 0x[[#%.8X, WEAK_REF]] pointer
70# DYLIB-DAG: __DATA __thread_ptrs 0x[[#%.8X, TLV_REF]] pointer
71# DYLIB-EMPTY:
72# DYLIB-NEXT: Bind table:
73# DYLIB-NEXT: segment section address type addend dylib symbol
74# DYLIB-DAG: __DATA_CONST __got {{.*}} pointer 0 flat-namespace dyld_stub_binder
75# DYLIB-DAG: __DATA __data 0x[[#%.8X, EXTERN_REF]] pointer 0 flat-namespace _extern
76# DYLIB-DAG: __DATA __thread_ptrs 0x[[#%.8X, TLV_REF]] pointer 0 flat-namespace _tlv
77# DYLIB-EMPTY:
78# DYLIB-NEXT: Lazy bind table:
79# DYLIB-NEXT: segment section address dylib symbol
80# DYLIB-NEXT: __DATA __la_symbol_ptr 0x[[#%.8X, EXTERN_LAZY]] flat-namespace _extern
81# DYLIB-EMPTY:
82# DYLIB-NEXT: Weak bind table:
83# DYLIB-NEXT: segment section address type addend symbol
84# DYLIB-NEXT: __DATA __la_symbol_ptr 0x[[#%.8X, WEAK_LAZY]] pointer 0 _weak_extern
85# DYLIB-NEXT: __DATA __data 0x[[#%.8X, WEAK_REF]] pointer 0 _weak_extern
86# DYLIB-EMPTY:
87
88# CHAINED-DYLIB: dyld information:
89# CHAINED-DYLIB-NEXT: segment section address pointer type addend dylib symbol/vm address
90# CHAINED-DYLIB-DAG: __DATA_CONST __got {{.*}} {{.*}} bind 0x0 weak _weak_extern
91# CHAINED-DYLIB-DAG: __DATA_CONST __got {{.*}} {{.*}} bind 0x0 flat-namespace _extern
92# CHAINED-DYLIB-DAG: __DATA __data 0x[[#%x, EXTERN_REF]] {{.*}} bind 0x0 flat-namespace _extern
93# CHAINED-DYLIB-DAG: __DATA __data 0x[[#%x, WEAK_REF]] {{.*}} bind 0x0 weak _weak_extern
94# CHAINED-DYLIB-DAG: __DATA __data 0x[[#%x, LOCAL_REF]] {{.*}} rebase {{.*}}
95# CHAINED-DYLIB-DAG: __DATA __thread_ptrs 0x[[#%x, TLV_REF]] {{.*}} bind 0x0 flat-namespace _tlv
96# CHAINED-DYLIB-EMPTY:
97
98#--- foo.s
99
100.globl _main, _extern, _weak_extern, _tlv
101.weak_definition _weak_extern
102.private_extern _private_extern
103
104_extern:
105retq
106_weak_extern:
107retq
108_private_extern:
109retq
110_local:
111retq
112
113_main:
114callq _extern
115callq _weak_extern
116callq _private_extern
117callq _local
118mov _tlv@TLVP(%rip), %rax
119retq
120
121.data
122_extern_ref:
123.quad _extern
124_weak_ref:
125.quad _weak_extern
126_local_ref:
127.quad _local
128
129.section __DATA,__thread_vars,thread_local_variables
130_tlv:
131
132.subsections_via_symbols
133