2 # RUN: llvm-mc -filetype=obj -triple=aarch64 %s -o %t.o
4 # RUN: ld.lld --no-relax %t.o -o %t
5 # RUN: llvm-objdump --no-print-imm-hex -d --no-show-raw-insn %t | FileCheck %s --check-prefix=PDE
6 # RUN: llvm-readobj -r %t | FileCheck %s --check-prefix=PDE-RELOC
8 # RUN: ld.lld -pie --no-relax %t.o -o %t
9 # RUN: ld.lld -pie --no-relax --apply-dynamic-relocs %t.o -o %t.apply
10 # RUN: llvm-objdump --no-print-imm-hex -d --no-show-raw-insn %t | FileCheck %s --check-prefix=PIE
11 # RUN: llvm-readobj -r -x .got.plt %t | FileCheck %s --check-prefixes=PIE-RELOC,NO-APPLY
12 # RUN: llvm-readobj -r -x .got.plt %t.apply | FileCheck %s --check-prefixes=PIE-RELOC,APPLY
14 ## When compiling with -fno-PIE or -fPIE, if the ifunc is in the same
15 ## translation unit as the address taker, the compiler knows that ifunc is not
16 ## defined in a shared library so it can use a non GOT generating relative reference.
19 .type myfunc,@gnu_indirect_function
21 .globl myfunc_resolver
22 .type myfunc_resolver,@function
31 add x8
, x8
, :lo12
: myfunc
34 ## The address of myfunc is the address of the PLT entry for myfunc.
35 # PDE: <myfunc_resolver>:
36 # PDE-NEXT: 210170: ret
38 # PDE-NEXT: 210174: adrp x8, 0x210000
39 # PDE-NEXT: 210178: add x8, x8, #384
40 # PDE-NEXT: 21017c: ret
42 # PDE-NEXT: Disassembly of section .iplt:
45 ## page(.got.plt) - page(0x210010) = 65536
46 # PDE-NEXT: 210180: adrp x16, 0x220000
47 # PDE-NEXT: 210184: ldr x17, [x16, #400]
48 # PDE-NEXT: 210188: add x16, x16, #400
49 # PDE-NEXT: 21018c: br x17
51 ## The adrp to myfunc should generate a PLT entry and a GOT entry with an
52 ## irelative relocation.
53 # PDE-RELOC: .rela.dyn {
54 # PDE-RELOC-NEXT: 0x220190 R_AARCH64_IRELATIVE - 0x210170
57 # PIE: <myfunc_resolver>:
58 # PIE-NEXT: 10260: ret
60 # PIE-NEXT: 10264: adrp x8, 0x10000
61 # PIE-NEXT: 10268: add x8, x8, #624
62 # PIE-NEXT: 1026c: ret
64 # PIE-NEXT: Disassembly of section .iplt:
67 # PIE-NEXT: 10270: adrp x16, 0x30000
68 # PIE-NEXT: ldr x17, [x16, #832]
69 # PIE-NEXT: add x16, x16, #832
72 # PIE-RELOC: .rela.dyn {
73 # PIE-RELOC-NEXT: 0x30340 R_AARCH64_IRELATIVE - 0x10260
75 # PIE-RELOC: Hex dump of section '.got.plt':
76 # NO-APPLY: 0x00030340 00000000 00000000
77 # APPLY: 0x00030340 60020100 00000000