xref: /llvm-project/lld/test/MachO/mh-header-link.s (revision 4ae8c8310401b665cb2728c1bf68ecd4b10cee78)
1# REQUIRES: x86
2
3## This tests that we can link against these synthetic symbols even
4## if they are not in the symbol table.
5
6# RUN: rm -rf %t; split-file %s %t
7
8## Test that in a dylib, we can link against __mh_dylib_header
9## (but not in other types of files)
10
11# RUN: llvm-mc %t/dylib.s -triple=x86_64-apple-macos10.15 -filetype=obj -o %t/dylib.o
12# RUN: %lld -dylib -dead_strip %t/dylib.o -o %t/dylib.out
13# RUN: llvm-objdump -m --syms %t/dylib.out | FileCheck %s --check-prefix DYLIB
14
15# RUN: not %lld -o /dev/null %t/dylib.o 2>&1 | FileCheck %s --check-prefix ERR-DYLIB
16
17# DYLIB:      SYMBOL TABLE:
18# DYLIB-NEXT: {{[0-9a-f]+}} g     F __TEXT,__text _main
19# DYLIB-NEXT-EMPTY:
20# ERR-DYLIB: error: undefined symbol: __mh_dylib_header
21
22## Test that in an executable, we can link against __mh_execute_header
23# RUN: llvm-mc %t/main.s -triple=x86_64-apple-macos10.15 -filetype=obj -o %t/exec.o
24# RUN: %lld -dead_strip -lSystem %t/exec.o -o %t/exec.out
25
26## But it would be an error trying to reference __mh_execute_header in a dylib
27# RUN: not %lld -o /dev/null -dylib %t/exec.o 2>&1 | FileCheck %s --check-prefix ERR-EXEC
28
29# ERR-EXEC: error: undefined symbol: __mh_execute_header
30
31#--- main.s
32.text
33.globl _main
34_main:
35 mov __mh_execute_header@GOTPCREL(%rip), %rax
36 ret
37.subsections_via_symbols
38
39#--- dylib.s
40.text
41.globl _main
42_main:
43 mov __mh_dylib_header@GOTPCREL(%rip), %rax
44 ret
45.subsections_via_symbols
46