xref: /llvm-project/bolt/test/AArch64/constant_island_pie_update.s (revision e237d8aac8a90f4cb25604801d2b544e1d148d88)
1// This test checks that the constant island offset and value is updated if
2// it has dynamic relocation. The tests checks both .rela.dyn and relr.dyn
3// dynamic relocations.
4// Also check that we don't duplicate CI if it has dynamic relocations.
5
6# RUN: llvm-mc -filetype=obj -triple aarch64-unknown-unknown %s -o %t.o
7// .rela.dyn
8# RUN: %clang %cflags -fPIC -pie %t.o -o %t.rela.exe -nostdlib \
9# RUN:   -Wl,-q -Wl,-z,notext
10# RUN: llvm-bolt %t.rela.exe -o %t.rela.bolt --use-old-text=0 --lite=0
11# RUN: llvm-objdump -j .text -d -z --show-all-symbols %t.rela.bolt | FileCheck %s
12# RUN: llvm-readelf -rsW %t.rela.bolt | FileCheck --check-prefix=ELFCHECK %s
13// .relr.dyn
14# RUN: %clang %cflags -fPIC -pie %t.o -o %t.relr.exe -nostdlib \
15# RUN:   -Wl,-q -Wl,-z,notext -Wl,--pack-dyn-relocs=relr
16# RUN: llvm-objcopy --remove-section .rela.mytext %t.relr.exe
17# RUN: llvm-bolt %t.relr.exe -o %t.relr.bolt --use-old-text=0 --lite=0
18# RUN: llvm-objdump -j .text -d -z --show-all-symbols %t.relr.bolt | FileCheck %s
19# RUN: llvm-objdump -j .text -d -z %t.relr.bolt | \
20# RUN:   FileCheck %s --check-prefix=ADDENDCHECK
21# RUN: llvm-readelf -rsW %t.relr.bolt | FileCheck --check-prefix=RELRELFCHECK %s
22# RUN: llvm-readelf -SW %t.relr.bolt | FileCheck --check-prefix=RELRSZCHECK %s
23
24// Check that the CI value was updated
25# CHECK: [[#%x,ADDR:]] <exitLocal>:
26# CHECK: {{.*}} <$d>:
27# CHECK-NEXT: {{.*}} .word 0x{{[0]+}}[[#ADDR]]
28# CHECK-NEXT: {{.*}} .word 0x00000000
29# CHECK-NEXT: {{.*}} .word 0x{{[0]+}}[[#ADDR]]
30# CHECK-NEXT: {{.*}} .word 0x00000000
31# CHECK-NEXT: {{.*}} .word 0x00000000
32# CHECK-NEXT: {{.*}} .word 0x00000000
33# CHECK-NEXT: {{.*}} .word 0x{{[0]+}}[[#ADDR]]
34# CHECK-NEXT: {{.*}} .word 0x00000000
35
36// Check that addend was properly patched in mytextP with stripped relocations
37# ADDENDCHECK: [[#%x,ADDR:]] <exitLocal>:
38# ADDENDCHECK: {{.*}} <mytextP>:
39# ADDENDCHECK-NEXT: {{.*}} .word 0x{{[0]+}}[[#ADDR]]
40# ADDENDCHECK-NEXT: {{.*}} .word 0x00000000
41
42// Check that we've relaxed adr to adrp + add to refer external CI
43# CHECK: <addressDynCi>:
44# CHECK-NEXT: adrp
45# CHECK-NEXT: add
46
47// Check that relocation offsets were updated
48# ELFCHECK: [[#%x,OFF:]] [[#%x,INFO_DYN:]] R_AARCH64_RELATIVE
49# ELFCHECK-NEXT: [[#OFF + 8]] {{0*}}[[#INFO_DYN]] R_AARCH64_RELATIVE
50# ELFCHECK-NEXT: [[#OFF + 24]] {{0*}}[[#INFO_DYN]] R_AARCH64_RELATIVE
51# ELFCHECK-NEXT: {{.*}} R_AARCH64_RELATIVE
52# ELFCHECK: {{.*}}[[#OFF]] {{.*}} $d
53
54# RELRELFCHECK:       $d{{$}}
55# RELRELFCHECK-NEXT:  $d + 0x8{{$}}
56# RELRELFCHECK-NEXT:  $d + 0x18{{$}}
57# RELRELFCHECK-NEXT:  mytextP
58# RELRELFCHECK-EMPTY:
59
60// Check that .relr.dyn size is 2 bytes to ensure that last 3 relocations were
61// encoded as a bitmap so the total section size for 3 relocations is 2 bytes.
62# RELRSZCHECK: .relr.dyn RELR [[#%x,ADDR:]] [[#%x,OFF:]] {{0*}}10
63
64  .text
65  .align 4
66  .local exitLocal
67  .type exitLocal, %function
68exitLocal:
69  add x1, x1, #1
70  add x1, x1, #1
71  nop
72  nop
73  ret
74  .size exitLocal, .-exitLocal
75
76  .global _start
77  .type _start, %function
78_start:
79  mov x0, #0
80  adr x1, .Lci
81  ldr x1, [x1]
82  blr x1
83  mov x0, #1
84  bl exitLocal
85  nop
86.Lci:
87  .xword exitLocal
88  .xword exitLocal
89  .xword 0
90  .xword exitLocal
91  .size _start, .-_start
92
93  .global addressDynCi
94  .type addressDynCi, %function
95addressDynCi:
96  adr x1, .Lci
97  bl _start
98.size addressDynCi, .-addressDynCi
99
100  .section ".mytext", "ax"
101  .balign 8
102  .global dummy
103  .type dummy, %function
104dummy:
105  nop
106  .word 0
107  .size dummy, .-dummy
108
109  .global mytextP
110mytextP:
111  .xword exitLocal
112  .size mytextP, .-mytextP
113