blob: 31b826c8b580a87a2e2c6c3de696d65261a403ec [file] [log] [blame]
Fangrui Songbcc0bd72019-06-01 11:01:261# REQUIRES: aarch64
2# RUN: llvm-mc -filetype=obj -triple=aarch64-none-linux-gnu %s -o %t.o
3
4# RUN: ld.lld %t.o -o %t
5# RUN: llvm-objdump -d --no-show-raw-insn %t | FileCheck %s --check-prefix=PDE
6# RUN: llvm-readobj -r %t | FileCheck %s --check-prefix=PDE-RELOC
7
8# RUN: ld.lld -pie %t.o -o %t
9# RUN: llvm-objdump -d --no-show-raw-insn %t | FileCheck %s --check-prefix=PIE
10# RUN: llvm-readobj -r %t | FileCheck %s --check-prefix=PIE-RELOC
11
12## When compiling with -fno-PIE or -fPIE, if the ifunc is in the same
13## translation unit as the address taker, the compiler knows that ifunc is not
14## defined in a shared library so it can use a non GOT generating relative reference.
15.text
16.globl myfunc
17.type myfunc,@gnu_indirect_function
18myfunc:
19.globl myfunc_resolver
20.type myfunc_resolver,@function
21myfunc_resolver:
22 ret
23
24.text
25.globl main
26.type main,@function
27main:
28 adrp x8, myfunc
29 add x8, x8, :lo12: myfunc
30 ret
31
32## The address of myfunc is the address of the PLT entry for myfunc.
Fangrui Song71e2ca62020-03-05 22:18:3833# PDE: <myfunc_resolver>:
Fangrui Songf66b7672019-08-20 08:34:5634# PDE-NEXT: 210170: ret
Fangrui Song71e2ca62020-03-05 22:18:3835# PDE: <main>:
Fangrui Songf66b7672019-08-20 08:34:5636# PDE-NEXT: 210174: adrp x8, #0
37# PDE-NEXT: 210178: add x8, x8, #384
38# PDE-NEXT: 21017c: ret
Fangrui Songbcc0bd72019-06-01 11:01:2639# PDE-EMPTY:
Fangrui Song345f5962019-12-15 00:19:0340# PDE-NEXT: Disassembly of section .iplt:
Fangrui Songbcc0bd72019-06-01 11:01:2641# PDE-EMPTY:
Fangrui Song71e2ca62020-03-05 22:18:3842# PDE-NEXT: <myfunc>:
Fangrui Songbcc0bd72019-06-01 11:01:2643## page(.got.plt) - page(0x210010) = 65536
Fangrui Songf66b7672019-08-20 08:34:5644# PDE-NEXT: 210180: adrp x16, #65536
45# PDE-NEXT: 210184: ldr x17, [x16, #400]
46# PDE-NEXT: 210188: add x16, x16, #400
47# PDE-NEXT: 21018c: br x17
Fangrui Songbcc0bd72019-06-01 11:01:2648
49## The adrp to myfunc should generate a PLT entry and a GOT entry with an
50## irelative relocation.
Fangrui Song25ab1c62019-08-03 02:26:5251# PDE-RELOC: .rela.dyn {
Fangrui Songf66b7672019-08-20 08:34:5652# PDE-RELOC-NEXT: 0x220190 R_AARCH64_IRELATIVE - 0x210170
Fangrui Songbcc0bd72019-06-01 11:01:2653# PDE-RELOC-NEXT: }
54
Fangrui Song71e2ca62020-03-05 22:18:3855# PIE: <myfunc_resolver>:
Fangrui Songf66b7672019-08-20 08:34:5656# PIE-NEXT: 10260: ret
Fangrui Song71e2ca62020-03-05 22:18:3857# PIE: <main>:
Fangrui Songf66b7672019-08-20 08:34:5658# PIE-NEXT: 10264: adrp x8, #0
59# PIE-NEXT: 10268: add x8, x8, #624
60# PIE-NEXT: 1026c: ret
Fangrui Songbcc0bd72019-06-01 11:01:2661# PIE-EMPTY:
Fangrui Song345f5962019-12-15 00:19:0362# PIE-NEXT: Disassembly of section .iplt:
Fangrui Songbcc0bd72019-06-01 11:01:2663# PIE-EMPTY:
Fangrui Song71e2ca62020-03-05 22:18:3864# PIE-NEXT: <myfunc>:
Fangrui Songf66b7672019-08-20 08:34:5665# PIE-NEXT: 10270: adrp x16, #131072
66# PIE-NEXT: 10274: ldr x17, [x16, #880]
67# PIE-NEXT: 10278: add x16, x16, #880
68# PIE-NEXT: 1027c: br x17
Fangrui Songbcc0bd72019-06-01 11:01:2669
Fangrui Song25ab1c62019-08-03 02:26:5270# PIE-RELOC: .rela.dyn {
Fangrui Songf66b7672019-08-20 08:34:5671# PIE-RELOC-NEXT: 0x30370 R_AARCH64_IRELATIVE - 0x10260
Fangrui Songbcc0bd72019-06-01 11:01:2672# PIE-RELOC-NEXT: }