1 # RUN: rm -rf %t && mkdir -p %t
2 # RUN: llvm-mc -triple=x86_64-unknown-linux -position-independent -filetype=obj \
3 # RUN: -o %t/elf_sm_pic_reloc.o %s
4 # RUN: llvm-jitlink -noexec -slab-allocate 100Kb -slab-address 0xfff00000 \
5 # RUN: -define-abs external_data=0x1 \
6 # RUN: -define-abs extern_out_of_range32=0x7fff00000000 \
7 # RUN: -check %s %t/elf_sm_pic_reloc.o
9 # Test ELF small/PIC relocations.
14 # Empty main entry point.
23 # Test PCRel32 / R_X86_64_PC32 handling.
24 # jitlink-check: decode_operand(test_pcrel32, 4) = named_data - next_pc(test_pcrel32)
27 .type test_pcrel32,@function
29 movl named_data
(%rip
), %eax
31 .size test_pcrel32, .-test_pcrel32
35 .type named_func,@function
39 .size named_func, .-named_func
41 # Check R_X86_64_PLT32 handling with a call to a local function. This produces a
42 # Branch32 edge that is resolved like a regular PCRel32 (no PLT entry created).
44 # jitlink-check: decode_operand(test_call_local, 0) = named_func - next_pc(test_call_local)
45 .globl test_call_local
47 .type test_call_local,@function
51 .size test_call_local, .-test_call_local
53 # Check R_X86_64_PLT32 handling with a call to an external via PLT. This
54 # produces a Branch32ToStub edge, because externals are not defined locally.
55 # As the target is out-of-range from the callsite, the edge keeps using its PLT
58 # jitlink-check: decode_operand(test_call_extern_plt, 0) = \
59 # jitlink-check: stub_addr(elf_sm_pic_reloc.o, extern_out_of_range32) - \
60 # jitlink-check: next_pc(test_call_extern_plt)
61 # jitlink-check: *{8}(got_addr(elf_sm_pic_reloc.o, extern_out_of_range32)) = \
62 # jitlink-check: extern_out_of_range32
63 .globl test_call_extern_plt
65 .type test_call_extern_plt,@function
67 callq extern_out_of_range32@plt
69 .size test_call_extern_plt, .-test_call_extern_plt
71 # Test GOTPCREL handling. We want to check both the offset to the GOT entry and its
72 # contents. "movl" will be optimized to "leal" and a non-got access if the pc relative
73 # offset to named_data is in range of 32 bits signed immediate. So use "leal" here to
74 # suppress optimization
75 # jitlink-check: decode_operand(test_gotpcrel, 4) = \
76 # jitlink-check: got_addr(elf_sm_pic_reloc.o, named_data) - next_pc(test_gotpcrel)
77 # jitlink-check: *{8}(got_addr(elf_sm_pic_reloc.o, named_data)) = named_data
81 .type test_gotpcrel,@function
83 leal named_data@GOTPCREL
(%rip
), %eax
85 .size test_gotpcrel, .-test_gotpcrel
87 # Test REX_GOTPCRELX handling. We want to check both the offset to the GOT entry and its
89 # jitlink-check: decode_operand(test_rex_gotpcrelx, 4) = \
90 # jitlink-check: got_addr(elf_sm_pic_reloc.o, external_data) - next_pc(test_rex_gotpcrelx)
92 .globl test_rex_gotpcrelx
94 .type test_rex_gotpcrelx,@function
96 movq external_data@GOTPCREL
(%rip
), %rax
98 .size test_rex_gotpcrelx, .-test_rex_gotpcrelx
100 # Test GOTOFF64 handling.
101 # jitlink-check: decode_operand(test_gotoff64, 1) = named_func - _GLOBAL_OFFSET_TABLE_
104 .type test_gotoff64,@function
106 movabsq $named_func@GOTOFF
, %rax
108 .size test_gotoff64, .-test_gotoff64
110 # Test that relocations to anonymous constant pool entries work.
111 .globl test_anchor_LCPI
113 .type test_anchor_LCPI,@function
115 movq
.LCPI0_0(%rip), %rax
117 .size test_anchor_LCPI, .-test_anchor_LCPI
121 .type named_data,@object
127 # Test BSS / zero-fill section handling.
128 # llvm-jitlink: *{4}bss_variable = 0
130 .type bss_variable,@object
136 .size bss_variable, 4
138 # Constant pool entry with type STT_NOTYPE.
139 .section .rodata.cst8,"aM",@progbits,8
142 .quad 0x400921fb54442d18
144 .ident "clang version 10.0.0-4ubuntu1 "
145 .section ".note.GNU-stack","",@progbits