llvm-project
88 строк · 2.6 Кб
1# REQUIRES: x86
2# RUN: llvm-mc -filetype=obj -triple=x86_64-apple-darwin %s -o %t.o
3# RUN: echo _t > %t.order
4# RUN: %lld -o %t -order_file %t.order %t.o
5# RUN: llvm-objdump --section-headers --syms -D %t | FileCheck %s
6
7# CHECK-LABEL: Sections:
8# CHECK: __foo {{[0-9a-f]+}} [[#%x,FOO:]] DATA
9
10# CHECK-LABEL: SYMBOL TABLE:
11# CHECK: [[#%x,S:]] g O __DATA,__data _s
12
13# CHECK-LABEL: Disassembly of section
14# CHECK: <_main>:
15# CHECK-NEXT: movl {{.*}} ## imm =
16# CHECK-NEXT: ## 0x[[#S]]
17# CHECK-NEXT: callq {{.*}}
18# CHECK-NEXT: movl {{.*}} ## 0x[[#S + 2]]
19# CHECK-NEXT: callq {{.*}}
20# CHECK-NEXT: movb {{.*}} ## 0x[[#S]]
21# CHECK-NEXT: callq {{.*}}
22# CHECK: <__not_text>:
23# CHECK-NEXT: movl {{.*}} ## imm =
24# CHECK-NEXT: ## 0x[[#FOO + 8]]
25# CHECK-NEXT: callq {{.*}}
26# CHECK-NEXT: movl {{.*}} ## 0x[[#FOO + 8 + 2]]
27# CHECK-NEXT: callq {{.*}}
28# CHECK-NEXT: movb {{.*}} ## 0x[[#FOO + 8]]
29# CHECK-NEXT: callq {{.*}}
30
31.section __TEXT,__text
32.globl _main
33_main:
34## Symbol relocations
35movl $0x434241, _s(%rip) # X86_64_RELOC_SIGNED_4
36callq _f
37movl $0x44, _s+2(%rip) # X86_64_RELOC_SIGNED_2
38callq _f
39movb $0x45, _s(%rip) # X86_64_RELOC_SIGNED_1
40callq _f
41xorq %rax, %rax
42ret
43
44_f:
45movl $0x2000004, %eax # write() syscall
46mov $1, %rdi # stdout
47leaq _s(%rip), %rsi
48mov $3, %rdx # length
49syscall
50ret
51
52.section __TEXT,__not_text
53## Section relocations. We intentionally put them in a separate section since
54## the __text section typically starts at an address of zero in object files,
55## and so does not fully exercise the relocation logic.
56movl $0x434241, L._s(%rip) # X86_64_RELOC_SIGNED_4
57callq _f
58movl $0x44, L._s+2(%rip) # X86_64_RELOC_SIGNED_2
59callq _f
60movb $0x45, L._s(%rip) # X86_64_RELOC_SIGNED_1
61callq _f
62ret
63
64.section __DATA,__data
65.globl _s
66_s:
67.space 5
68
69## Create a new section to force the assembler to use a section relocation for
70## the private symbol L._s. Otherwise, it will instead use a nearby non-private
71## symbol to create a symbol relocation plus an addend.
72.section __DATA,__foo
73L._s:
74.space 1
75
76## This symbol exists in order to split __foo into two subsections, thereby
77## testing that our code matches the relocations with the right target
78## subsection. In particular, although L._s+2 points to an address within _t's
79## subsection, it's defined relative to L._s, and should therefore be associated
80## with L._s' subsection.
81##
82## We furthermore use an order file to rearrange these subsections so that a
83## mistake here will be obvious.
84.globl _t
85_t:
86.quad 123
87
88.subsections_via_symbols
89