1# REQUIRES: x86
2# RUN: llvm-mc -filetype=obj -triple=x86_64-apple-darwin %s -o %t.o
3# RUN: lld -flavor darwinnew -L%S/Inputs/MacOSX.sdk/usr/lib -lSystem -o %t %t.o
4# RUN: llvm-objdump --section-headers --syms -d %t | FileCheck %s
5
6# CHECK-LABEL: Sections:
7# CHECK:       __cstring {{[0-9a-z]+}} [[#%x, CSTRING_ADDR:]]
8
9# CHECK-LABEL: SYMBOL TABLE:
10# CHECK:       [[#%x, F_ADDR:]] {{.*}} _f
11
12# CHECK-LABEL: <_main>:
13## Test X86_64_RELOC_BRANCH
14# CHECK:       callq 0x[[#%x, F_ADDR]] <_f>
15## Test extern (symbol) X86_64_RELOC_SIGNED
16# CHECK:       leaq [[#%u, STR_OFF:]](%rip), %rsi
17# CHECK-NEXT:  [[#%x, CSTRING_ADDR - STR_OFF]]
18## Test non-extern (section) X86_64_RELOC_SIGNED
19# CHECK:       leaq [[#%u, LSTR_OFF:]](%rip), %rsi
20# CHECK-NEXT:  [[#%x, CSTRING_ADDR + 22 - LSTR_OFF]]
21
22# RUN: llvm-objdump --section=__const --full-contents -d %t | FileCheck %s --check-prefix=NONPCREL
23# NONPCREL:      Contents of section __const:
24# NONPCREL-NEXT: 100001000 b0030000 01000000 b0030000 01000000
25
26.section __TEXT,__text
27.globl _main, _f
28_main:
29  callq _f # X86_64_RELOC_BRANCH
30  mov $0, %rax
31  ret
32
33_f:
34  movl $0x2000004, %eax # write() syscall
35  mov $1, %rdi # stdout
36  leaq _str(%rip), %rsi # Generates a X86_64_RELOC_SIGNED pcrel symbol relocation
37  mov $21, %rdx # length of str
38  syscall
39
40  movl $0x2000004, %eax # write() syscall
41  mov $1, %rdi # stdout
42  leaq L_.str(%rip), %rsi # Generates a X86_64_RELOC_SIGNED pcrel section relocation
43  mov $15, %rdx # length of str
44  syscall
45
46  movl $0x2000004, %eax # write() syscall
47  mov $1, %rdi # stdout
48  movq L_.ptr_1_to_str(%rip), %rsi
49  mov $15, %rdx # length of str
50  syscall
51  ret
52
53.section __TEXT,__cstring
54## References to this generate a symbol relocation
55_str:
56  .asciz "Local defined symbol\n"
57## References to this generate a section relocation
58L_.str:
59  .asciz "Private symbol\n"
60
61.section __DATA,__const
62## These generate X86_64_RELOC_UNSIGNED non-pcrel section relocations
63L_.ptr_1_to_str:
64  .quad L_.str
65L_.ptr_2_to_str:
66  .quad L_.str
67