llvm-project/lld/test/ELF/aarch64-cortex-a53-843419-thunk.s
Peter Smith e47d3a3088
[LLD][AArch64] Increase alignment of AArch64AbsLongThunk to 8 (#133738)
This permits an AArch64AbsLongThunk to be used in an environment where
unaligned accesses are disabled.

The AArch64AbsLongThunk does a load of an 8-byte address. When unaligned
accesses are disabled this address must be 8-byte aligned.

The vast majority of AArch64 systems will have unaligned accesses
enabled in userspace. However, after a reset, before the MMU has been
enabled, all memory accesses are to "device" memory, which requires
aligned accesses. In systems with multi-stage boot loaders a thunk may
be required to a later stage before the MMU has been enabled.

As we only want to increase the alignment when the ldr is used we delay
the increase in thunk alignment until we know we are going to write an
ldr. We also need to account for the ThunkSection alignment increase
when this happens.

In some of the test updates, particularly those with shared CHECK lines
with position independent thunks it was easier to ensure that the thunks
started at an 8-byte aligned address in all cases.
2025-04-01 09:49:27 +01:00

58 lines
1.9 KiB
ArmAsm

// REQUIRES: aarch64
// RUN: llvm-mc -filetype=obj -triple=aarch64 %s -o %t.o
// RUN: echo "SECTIONS { \
// RUN: .text1 0x10000 : { *(.text.01) *(.text.02) *(.text.03) } \
// RUN: .text2 0x10010000 : { *(.text.04) } } " > %t.script
// RUN: ld.lld --script %t.script -fix-cortex-a53-843419 -verbose %t.o -o %t2 \
// RUN: 2>&1 | FileCheck -check-prefix=CHECK-PRINT %s
// RUN: llvm-objdump --no-print-imm-hex --no-show-raw-insn --triple=aarch64-linux-gnu -d %t2 | FileCheck %s
/// %t2 is 128 Megabytes, so delete it early.
// RUN: rm %t2
/// Test cases for Cortex-A53 Erratum 843419 that involve interactions with
/// range extension thunks. Both erratum fixes and range extension thunks need
/// precise address information and after creation alter address information.
.section .text.01, "ax", %progbits
.balign 4096
.globl _start
.type _start, %function
_start:
bl far_away
/// Thunk to far_away, size 16-bytes goes here.
.section .text.02, "ax", %progbits
.space 4096 - 32
/// Erratum sequence will only line up at address 0 modulo 0xffc when
/// Thunk is inserted.
.section .text.03, "ax", %progbits
.globl t3_ff8_ldr
.type t3_ff8_ldr, %function
t3_ff8_ldr:
adrp x0, dat
ldr x1, [x1, #0]
ldr x0, [x0, :got_lo12:dat]
ret
// CHECK-PRINT: detected cortex-a53-843419 erratum sequence starting at 10FF8 in unpatched output.
// CHECK: 0000000000010ff8 <t3_ff8_ldr>:
// CHECK-NEXT: adrp x0, 0x10010000
// CHECK-NEXT: ldr x1, [x1]
// CHECK-NEXT: b 0x11008
// CHECK-NEXT: ret
// CHECK: 0000000000011008 <__CortexA53843419_11000>:
// CHECK-NEXT: ldr x0, [x0, #8]
// CHECK-NEXT: b 0x11004
.section .text.04, "ax", %progbits
.globl far_away
.type far_away, function
far_away:
ret
.section .data
.globl dat
dat: .quad 0