2 # RUN: rm -rf %t; split-file %s %t
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
7 # RUN: llvm-mc -filetype=obj -triple=x86_64-apple-macos -o %t/main.o %t/main.s
9 # _foo starts out as a (non-weak) dynamically looked up symbol and is merged
10 # against the Undefined from foo.o. _bar isn't referenced in any object file,
11 # but starts out as Undefined because of the -u flag. _baz isn't referenced
13 # RUN: %lld -lSystem %t/main.o -U _foo -U _bar -u _bar -U _baz -o %t/out
14 # RUN: llvm-objdump --macho --lazy-bind %t/out | FileCheck --check-prefix=DYNAMIC %s
15 # RUN: llvm-nm -m %t/out | FileCheck --check-prefix=DYNAMICSYM %s
17 # Same thing should happen if _foo starts out as an Undefined.
18 # `-U _foo` being passed twice shouldn't have an effect either.
19 # RUN: %lld -lSystem %t/main.o -u _foo -U _foo -U _foo -u _bar -U _bar -U _baz -o %t/out
20 # RUN: llvm-objdump --macho --lazy-bind %t/out | FileCheck --check-prefix=DYNAMIC %s
21 # RUN: llvm-nm -m %t/out | FileCheck --check-prefix=DYNAMICSYM %s
23 # Unreferenced dynamic lookup symbols don't make it into the bind tables, but
24 # they do make it into the symbol table in ld64 if they're an undefined from -u
25 # for some reason. lld happens to have the same behavior when no explicit code
26 # handles this case, so match ld64's behavior.
30 # DYNAMIC: flat-namespace _foo
32 # DYNAMICSYM: (undefined) external _bar (dynamically looked up)
33 # DYNAMICSYM-NOT: (undefined) external _bar (dynamically looked up)
34 # DYNAMICSYM-NEXT: (undefined) external _foo (dynamically looked up)
36 # Test with a Defined. Here, foo.o provides _foo and the symbol doesn't need
38 # RUN: %lld -lSystem %t/main.o %t/foo.o -U _foo -o %t/out
39 # RUN: llvm-objdump --macho --lazy-bind %t/out | FileCheck --check-prefix=NOTDYNAMIC %s
41 # NOTDYNAMIC-NOT: _foo
43 # Here, foo.dylib provides _foo and the symbol doesn't need to be imported
45 # RUN: %lld -lSystem %t/main.o %t/foo.dylib -U _foo -o %t/out
46 # RUN: llvm-objdump --macho --lazy-bind %t/out | FileCheck --check-prefix=TWOLEVEL %s
47 # RUN: llvm-nm -m %t/out | FileCheck --check-prefix=TWOLEVELSYM %s
50 # TWOLEVELSYM: (undefined) external _foo (from foo)
52 # Test resolving dynamic lookup symbol with weak defined.
53 # RUN: llvm-mc -filetype=obj -triple=x86_64-apple-macos -o %t/weak-foo.o %t/weak-foo.s
54 # RUN: %lld -dylib -o %t/weak-foo.dylib %t/weak-foo.o -U _foo
55 # RUN: llvm-objdump --macho --bind --lazy-bind --weak-bind %t/weak-foo.dylib | FileCheck --check-prefix=WEAKDEF %s
56 # RUN: llvm-nm -m %t/weak-foo.dylib | FileCheck --check-prefix=WEAKDEFSYM %s
58 # WEAKDEFSYM: weak external _foo
60 # Same if foo.dylib provides _foo weakly, except that the symbol is weak then.
61 # RUN: %lld -lSystem %t/main.o %t/weak-foo.dylib -U _foo -o %t/out
62 # RUN: llvm-objdump --macho --bind --lazy-bind --weak-bind %t/out | FileCheck --check-prefix=TWOLEVELWEAK %s
63 # RUN: llvm-nm -m %t/out | FileCheck --check-prefix=TWOLEVELWEAKSYM %s
65 # TWOLEVELWEAK-LABEL: Bind table:
66 # TWOLEVELWEAK: __DATA __la_symbol_ptr 0x[[#%x,ADDR:]] pointer 0 weak-foo _foo
67 # TWOLEVELWEAK-LABEL: Lazy bind table:
68 # TWOLEVELWEAK-NOT: weak-foo _foo
69 # TWOLEVELWEAK-LABEL: Weak bind table:
70 # TWOLEVELWEAK: __DATA __la_symbol_ptr 0x[[#ADDR]] pointer 0 _foo
72 # TWOLEVELWEAKSYM: (undefined) weak external _foo (from weak-foo)