xref: /llvm-project/lld/test/MachO/flat-namespace-dysyms.s (revision c77c3663dbea07264ba760bc17b913cebd7986ba)
1# REQUIRES: x86
2# RUN: rm -rf %t; split-file %s %t
3
4# RUN: llvm-mc -filetype=obj -triple=x86_64-apple-macos -o %t/foo.o %t/foo.s
5# RUN: %lld -dylib -o %t/foo.dylib %t/foo.o
6
7# RUN: llvm-mc -filetype=obj -triple=x86_64-apple-macos -o %t/bar.o %t/bar.s
8# RUN: %lld -lSystem -dylib -o %t/bar.dylib %t/bar.o %t/foo.dylib
9
10# RUN: llvm-mc -filetype=obj -triple=x86_64-apple-macos -o %t/baz.o %t/baz.s
11# RUN: %lld -lSystem -dylib -o %t/baz.dylib %t/baz.o %t/bar.dylib
12
13# RUN: llvm-mc -filetype=obj -triple=x86_64-apple-macos -o %t/main.o %t/main.s
14
15## With flat_namespace, the linker automatically looks in foo.dylib and
16## bar.dylib too, but it doesn't add a LC_LOAD_DYLIB for it.
17# RUN: %lld -flat_namespace -lSystem %t/main.o %t/baz.dylib -o %t/out -t \
18# RUN:  --reproduce %t/repro.tar | FileCheck --check-prefix=T %s
19## FIXME: The `bar.dylib` line should use `T-NEXT`, but on Windows we load
20## libSystem.tbd with different slash styles and end up loading it twice
21## for that reason.
22# T:      main.o
23# T-NEXT: baz.dylib
24# T:      bar.dylib
25# T-NEXT: foo.dylib
26# RUN: llvm-objdump --macho --all-headers %t/out \
27# RUN:     | FileCheck --check-prefix=HEADERBITS %s
28# RUN: llvm-objdump --macho --bind --lazy-bind --weak-bind %t/out \
29# RUN:     | FileCheck --check-prefix=FLAT %s
30# RUN: llvm-nm -m %t/out | FileCheck --check-prefix=FLATSYM %s
31# RUN: llvm-readobj --syms %t/out | FileCheck --check-prefix=FLATSYM-READOBJ %s
32# RUN: cd %t
33# RUN: tar -tf repro.tar | FileCheck -DPATH='%:t.dir' --check-prefix=REPRO %s
34# RUN: tar -xf repro.tar repro/response.txt
35# RUN: FileCheck --implicit-check-not=.dylib --check-prefix=RESPONSE %s \
36# RUN:     < %t/repro/response.txt
37
38# HEADERBITS-NOT: NOUNDEFS
39# HEADERBITS-NOT: TWOLEVEL
40# HEADERBITS: DYLDLINK
41# HEADERBITS-NOT: foo.dylib
42# HEADERBITS-NOT: bar.dylib
43
44# FLAT: Bind table:
45# FLAT: __DATA_CONST __got          0x{{[0-9a-f]*}} pointer         0 flat-namespace   dyld_stub_binder
46# FLAT: Lazy bind table:
47# FLAT-DAG: __DATA   __la_symbol_ptr    0x{{[0-9a-f]*}} flat-namespace   _bar
48# FLAT-DAG: __DATA   __la_symbol_ptr    0x{{[0-9a-f]*}} flat-namespace   _baz
49# FLAT-DAG: __DATA   __la_symbol_ptr    0x{{[0-9a-f]*}} flat-namespace   _foo
50
51## No "(dynamically looked up)" because llvm-nm -m doesn't print that
52## for files without MH_TWOLEVEL for some reason.
53# FLATSYM: (undefined) external _bar
54# FLATSYM: (undefined) external _baz
55# FLATSYM: (undefined) external _foo
56
57## ...but `llvm-readobj --syms` does, so verify we put the right thing there.
58# FLATSYM-READOBJ: Flags [ (0xFE00)
59
60## All 3 .dylibs should be in a --reproduce archive.
61# REPRO: baz.dylib
62# REPRO: bar.dylib
63# REPRO: foo.dylib
64
65## ...but only baz.dylib should be in the response file:
66# RESPONSE: baz.dylib
67
68# Undefined symbols should still cause errors by default.
69# RUN: llvm-mc -filetype=obj -triple=x86_64-apple-macos \
70# RUN:     -o %t/main-with-undef.o %t/main-with-undef.s
71# RUN: not %lld -flat_namespace -lSystem %t/main-with-undef.o %t/bar.dylib \
72# RUN:     -o %t/out 2>&1 | FileCheck --check-prefix=UNDEF %s
73# UNDEF: error: undefined symbol: _quux
74
75#--- foo.s
76.globl _foo
77_foo:
78  ret
79
80#--- bar.s
81.globl _bar
82_bar:
83  callq _foo
84  ret
85
86#--- baz.s
87.globl _baz
88_baz:
89  callq _bar
90  ret
91
92#--- main.s
93.globl _main
94_main:
95  callq _foo
96  callq _bar
97  callq _baz
98  ret
99
100#--- main-with-undef.s
101.globl _main
102_main:
103  callq _foo
104  callq _bar
105  callq _baz
106  callq _quux
107  ret
108