Run DCE after a LoopFlatten test to reduce spurious output [nfc]
[llvm-project.git] / lld / test / MachO / entry-symbol.s
blob36fdeb6b4422356b57ec704883bbe5b9dc22d205
1 # REQUIRES: x86
2 # RUN: rm -rf %t; split-file %s %t
3 # RUN: llvm-mc -filetype=obj -triple=x86_64-apple-darwin %t/not-main.s -o %t/not-main.o
4 # RUN: llvm-mc -filetype=obj -triple=x86_64-apple-darwin %t/libfoo.s -o %t/libfoo.o
5 # RUN: %lld -lSystem -dylib %t/libfoo.o -o %t/libfoo.dylib
7 # RUN: %lld -lSystem -o %t/not-main %t/not-main.o -e _not_main
8 # RUN: llvm-objdump --macho --all-headers --syms %t/not-main | FileCheck %s
10 # CHECK-LABEL: SYMBOL TABLE
11 # CHECK: {{0*}}[[#%x, ENTRY_ADDR:]] {{.*}} __TEXT,__text _not_main
13 # CHECK: sectname __text
14 # CHECK-NEXT: segname __TEXT
15 ## Note: the following checks assume that the entry symbol is right at the
16 ## beginning of __text.
17 # CHECK-NEXT: addr 0x{{0*}}[[#ENTRY_ADDR]]
18 # CHECK-NEXT: size
19 # CHECK-NEXT: offset [[#ENTRYOFF:]]
20 # CHECK: cmd LC_MAIN
21 # CHECK-NEXT: cmdsize 24
22 # CHECK-NEXT: entryoff [[#ENTRYOFF]]
24 # RUN: %lld -lSystem -o %t/dysym-main %t/not-main.o %t/libfoo.dylib -e _dysym_main
25 # RUN: llvm-objdump --macho --all-headers --indirect-symbols --lazy-bind %t/dysym-main | FileCheck %s --check-prefix=DYSYM -DDYLIB=libfoo
27 # RUN: %lld -lSystem -o %t/dyn-lookup %t/not-main.o -e _dysym_main -undefined dynamic_lookup
28 # RUN: llvm-objdump --macho --all-headers --indirect-symbols --lazy-bind %t/dyn-lookup | FileCheck %s --check-prefix=DYSYM -DDYLIB=flat-namespace
30 # DYSYM-LABEL: Indirect symbols for (__TEXT,__stubs) 1 entries
31 # DYSYM-NEXT: address index name
32 # DYSYM-NEXT: 0x[[#%x,DYSYM_ENTRY_ADDR:]] [[#]] _dysym_main
33 # DYSYM-LABEL: cmd LC_MAIN
34 # DYSYM-NEXT: cmdsize 24
35 # DYSYM-NEXT: entryoff [[#%u, DYSYM_ENTRY_ADDR - 0x100000000]]
36 # DYSYM-LABEL: Lazy bind table:
37 # DYSYM-NEXT: segment section address dylib symbol
38 # DYSYM-NEXT: __DATA __la_symbol_ptr {{.*}} [[DYLIB]] _dysym_main
40 # RUN: %lld -lSystem -o %t/weak-dysym-main %t/not-main.o %t/libfoo.dylib -e _weak_dysym_main
41 # RUN: llvm-objdump --macho --all-headers --indirect-symbols --bind --weak-bind %t/weak-dysym-main | FileCheck %s --check-prefix=WEAK-DYSYM
42 # WEAK-DYSYM-LABEL: Indirect symbols for (__TEXT,__stubs) 1 entries
43 # WEAK-DYSYM-NEXT: address index name
44 # WEAK-DYSYM-NEXT: 0x[[#%x,DYSYM_ENTRY_ADDR:]] [[#]] _weak_dysym_main
45 # WEAK-DYSYM: cmd LC_MAIN
46 # WEAK-DYSYM-NEXT: cmdsize 24
47 # WEAK-DYSYM-NEXT: entryoff [[#%u, DYSYM_ENTRY_ADDR - 0x100000000]]
48 # WEAK-DYSYM-LABEL: Bind table:
49 # WEAK-DYSYM-NEXT: segment section address type addend dylib symbol
50 # WEAK-DYSYM: __DATA __la_symbol_ptr {{.*}} pointer 0 libfoo _weak_dysym_main
51 # WEAK-DYSYM-LABEL: Weak bind table:
52 # WEAK-DYSYM-NEXT: segment section address type addend symbol
53 # WEAK-DYSYM-NEXT: __DATA __la_symbol_ptr {{.*}} pointer 0 _weak_dysym_main
55 # RUN: %lld -dylib -lSystem -o %t/dysym-main.dylib %t/not-main.o %t/libfoo.dylib -e _dysym_main
56 # RUN: llvm-objdump --macho --indirect-symbols --lazy-bind %t/dysym-main.dylib | FileCheck %s --check-prefix=DYLIB-NO-MAIN
57 # DYLIB-NO-MAIN-NOT: _dysym_main
59 # RUN: not %lld -o /dev/null %t/not-main.o -e _missing 2>&1 | FileCheck %s --check-prefix=UNDEFINED
60 # UNDEFINED: error: undefined symbol: _missing
61 # RUN: not %lld -o /dev/null %t/not-main.o 2>&1 | FileCheck %s --check-prefix=DEFAULT-ENTRY
62 # DEFAULT-ENTRY: error: undefined symbol: _main
63 # DEFAULT-ENTRY-NEXT: >>> referenced by the entry point
65 #--- libfoo.s
66 .text
67 .global _dysym_main, _weak_dysym_main
68 .weak_definition _weak_dysym_main
69 _dysym_main:
70 ret
72 _weak_dysym_main:
73 ret
75 #--- not-main.s
76 .text
77 .global _not_main
78 _not_main:
79 ret