xref: /llvm-project/lld/test/MachO/bundle-loader.s (revision 0f8854f7f5d3e98f32eef7cfd09d5b8915a7d301)
1# REQUIRES: x86
2
3# RUN: rm -rf %t; split-file %s %t
4# RUN: llvm-mc -filetype=obj -triple=x86_64-apple-darwin %t/2.s -o %t/2.o
5# RUN: llvm-mc -filetype=obj -triple=x86_64-apple-darwin %t/3.s -o %t/3.o
6# RUN: llvm-mc -filetype=obj -triple=x86_64-apple-darwin %t/main.s -o %t/main.o
7
8# RUN: %lld -lSystem -dylib -install_name %t/my_lib.dylib -o %t/mylib.dylib %t/2.o
9# RUN: %lld -lSystem %t/2.o %t/main.o -o %t/main
10# RUN: %lld -lSystem -bundle -bundle_loader %t/main -o %t/bundle.bundle %t/3.o %t/mylib.dylib
11## Check bundle.bundle to ensure the `my_func` symbol is from executable
12# RUN: llvm-nm -m %t/bundle.bundle | FileCheck %s --check-prefix BUNDLE
13# BUNDLE: (undefined) external my_func (from executable)
14# RUN: llvm-objdump  --macho --lazy-bind %t/bundle.bundle | FileCheck %s --check-prefix BUNDLE-OBJ
15# BUNDLE-OBJ: segment  section             address            dylib                 symbol
16# BUNDLE-OBJ: __DATA   __la_symbol_ptr     0x{{[0-9a-f]*}}    main-executable       my_fun
17
18# RUN: %lld -lSystem -bundle -bundle_loader %t/main -o %t/bundle2.bundle %t/3.o %t/2.o
19## Check bundle.bundle to ensure the `my_func` symbol is not from executable
20# RUN: llvm-nm -m %t/bundle2.bundle | FileCheck %s --check-prefix BUNDLE2
21# BUNDLE2: (__TEXT,__text) external my_func
22
23# Test that bundle_loader can only be used with MachO bundle output.
24# RUN: not %lld -lSystem -bundle_loader %t/main -o %t/bundle3.bundle 2>&1 | FileCheck %s --check-prefix ERROR
25# ERROR: -bundle_loader can only be used with MachO bundle output
26
27#--- 2.s
28# my_lib: This contains the exported function
29.globl my_func
30my_func:
31  retq
32
33#--- 3.s
34# my_user.s: This is the user/caller of the
35#            exported function
36.text
37my_user:
38  callq my_func()
39  retq
40
41#--- main.s
42# main.s: dummy exec/main loads the exported function.
43# This is basically a way to say `my_user` should get
44# `my_func` from this executable.
45.globl _main
46.text
47 _main:
48  retq
49