2 # RUN: rm -rf %t; split-file %s %t
4 # RUN: llvm-mc -filetype=obj -triple=x86_64-apple-darwin %t/first.s -o %t/first.o
5 # RUN: llvm-mc -filetype=obj -triple=x86_64-apple-darwin %t/second.s -o %t/second.o
7 # RUN: %lld -lSystem -init_offsets -undefined dynamic_lookup %t/first.o %t/second.o -o %t/out
8 # RUN: llvm-otool -lv %t/out | FileCheck --check-prefix=FLAGS --implicit-check-not=__mod_init_func %s
9 # RUN: llvm-otool -l %t/out > %t/dump.txt
10 # RUN: llvm-objdump --macho --print-imm-hex --section=__TEXT,__stubs %t/out >> %t/dump.txt
11 # RUN: llvm-objdump --macho --syms %t/out >> %t/dump.txt
12 # RUN: llvm-objcopy --dump-section=__TEXT,__init_offsets=%t/section.bin %t/out
13 # RUN: echo "__TEXT,__init_offsets contents:" >> %t/dump.txt
14 # RUN: od -An -txI %t/section.bin >> %t/dump.txt
15 # RUN: FileCheck --check-prefix=CONTENT %s < %t/dump.txt
17 ## This test checks that:
18 ## - __mod_init_func is replaced by __init_offsets.
19 ## - __mod_init_func has type S_INIT_FUNC_OFFSETS.
20 ## - initializers show up in the order their parent objects are specified on the
21 ## command line, and in the order they show up within __mod_init_func.
22 ## - for undefined and dylib symbols, stubs are created, and the offsets point to those.
23 ## - offsets are relative to __TEXT's address, they aren't an absolute virtual address.
25 # FLAGS: sectname __init_offsets
26 # FLAGS-NEXT: segname __TEXT
28 # FLAGS-NEXT: size 0x0000000000000010
30 # FLAGS-NEXT: align 2^2 (4)
31 # FLAGS-NEXT: reloff 0
32 # FLAGS-NEXT: nreloc 0
33 # FLAGS-NEXT: type S_INIT_FUNC_OFFSETS
35 # CONTENT: segname __TEXT
36 # CONTENT-NEXT: 0x[[#%x, TEXT:]]
38 # CONTENT: Contents of (__TEXT,__stubs) section
39 # CONTENT-NEXT: [[#%x, ISNAN:]]: {{.*}} ## literal pool symbol address: ___isnan
40 # CONTENT-NEXT: [[#%x, UNDEF:]]: {{.*}} ## literal pool symbol address: _undefined
42 # CONTENT: SYMBOL TABLE:
43 # CONTENT: [[#%x, FIRST:]] g F __TEXT,__text _first_init
44 # CONTENT: [[#%x, SECOND:]] g F __TEXT,__text _second_init
46 # CONTENT: __TEXT,__init_offsets contents:
47 # CONTENT: [[#%.8x, FIRST - TEXT]] [[#%.8x, ISNAN - TEXT]] [[#%.8x, UNDEF - TEXT]] [[#%.8x, SECOND - TEXT]]
50 .globl _first_init, ___isnan, _main
57 .section __DATA,__mod_init_func,mod_init_funcs
61 .subsections_via_symbols
64 .globl _second_init, _undefined
69 .section __DATA,__mod_init_func,mod_init_funcs
73 .subsections_via_symbols