diff options
author | PiJoules <6019989+PiJoules@users.noreply.github.com> | 2024-05-29 13:28:32 -0700 |
---|---|---|
committer | GitHub <noreply@github.com> | 2024-05-29 13:28:32 -0700 |
commit | 025394fa0dd3d0c20cc755f79ed521b85e5d7943 (patch) | |
tree | 0f7dc09af465c57907800bad567c752130a7bd9b /lld/test | |
parent | 87e8ce376771f8c88a12776544cd81ec5a4993fb (diff) | |
download | llvm-025394fa0dd3d0c20cc755f79ed521b85e5d7943.zip llvm-025394fa0dd3d0c20cc755f79ed521b85e5d7943.tar.gz llvm-025394fa0dd3d0c20cc755f79ed521b85e5d7943.tar.bz2 |
Reapply "[lld] Support thumb PLTs" (#93631) (#93644)
This reverts commit 7832769d329ead264aff238c06dce086b3a74922.
This was reverted prior due to a test failure on the windows builder. I
think this was because we didn't specify the triple and assumed windows.
The other tests use the full triple specifying linux, so we follow suite
here.
---
We are using PLTs for cortex-m33 which only supports thumb. More
specifically, this is for a very restricted use case. There's no MMU so
there's no sharing of virtual addresses between two processes, but this
is fine. The MCU is used for running [chre
nanoapps](https://android.googlesource.com/platform/system/chre/+/HEAD/doc/nanoapp_overview.md)
for android. Each nanoapp is a shared library (but effectively acts as
an executable containing a test suite) that is loaded and run on the MCU
one binary at a time and there's only one process running at a time, so
we ensure that the same text segment cannot be shared by two different
running executables. GNU LD supports thumb PLTs but we want to migrate
to a clang toolchain and use LLD, so thumb PLTs are needed.
Diffstat (limited to 'lld/test')
-rw-r--r-- | lld/test/ELF/armv8-thumb-plt-reloc.s | 126 |
1 files changed, 126 insertions, 0 deletions
diff --git a/lld/test/ELF/armv8-thumb-plt-reloc.s b/lld/test/ELF/armv8-thumb-plt-reloc.s new file mode 100644 index 0000000..5b6e4b5 --- /dev/null +++ b/lld/test/ELF/armv8-thumb-plt-reloc.s @@ -0,0 +1,126 @@ +// REQUIRES: arm +// RUN: llvm-mc -filetype=obj -arm-add-build-attributes -triple=thumbv8-none-linux-gnueabi --arch=thumb --mcpu=cortex-m33 %p/Inputs/arm-plt-reloc.s -o %t1.o +// RUN: llvm-mc -filetype=obj -arm-add-build-attributes -triple=thumbv8-none-linux-gnueabi --arch=thumb --mcpu=cortex-m33 %s -o %t2.o +// RUN: ld.lld %t1.o %t2.o -o %t +// RUN: llvm-objdump --no-print-imm-hex -d %t | FileCheck %s +// RUN: ld.lld -shared %t1.o %t2.o -o %t.so +// RUN: llvm-objdump --no-print-imm-hex -d %t.so | FileCheck --check-prefix=DSO %s +// RUN: llvm-readelf -S -r %t.so | FileCheck -check-prefix=DSOREL %s + +// RUN: llvm-mc -filetype=obj -arm-add-build-attributes -triple=thumbv8-none-linux-gnueabi --arch=thumbeb --mcpu=cortex-m33 %p/Inputs/arm-plt-reloc.s -o %t1.be.o +// RUN: llvm-mc -filetype=obj -arm-add-build-attributes -triple=thumbv8-none-linux-gnueabi --arch=thumbeb --mcpu=cortex-m33 %s -o %t2.be.o +// RUN: ld.lld %t1.be.o %t2.be.o -o %t.be +// RUN: llvm-objdump --no-print-imm-hex -d %t.be | FileCheck %s +// RUN: ld.lld -shared %t1.be.o %t2.be.o -o %t.so.be +// RUN: llvm-objdump --no-print-imm-hex -d %t.so.be | FileCheck --check-prefix=DSO %s +// RUN: llvm-readelf -S -r %t.so.be | FileCheck -check-prefix=DSOREL %s + +// RUN: ld.lld --be8 %t1.be.o %t2.be.o -o %t.be +// RUN: llvm-objdump --no-print-imm-hex -d %t.be | FileCheck %s +// RUN: ld.lld --be8 -shared %t1.be.o %t2.be.o -o %t.so.be +// RUN: llvm-objdump --no-print-imm-hex -d %t.so.be | FileCheck --check-prefix=DSO %s +// RUN: llvm-readelf -S -r %t.so.be | FileCheck -check-prefix=DSOREL %s + +/// Test PLT entry generation + .text + .align 2 + .globl _start + .type _start,%function +_start: + bl func1 + bl func2 + bl func3 + b.w func1 + b.w func2 + b.w func3 + beq.w func1 + beq.w func2 + beq.w func3 + +/// Executable, expect no PLT +// CHECK: Disassembly of section .text: +// CHECK-EMPTY: +// CHECK-NEXT: <func1>: +// CHECK-NEXT: bx lr +// CHECK: <func2>: +// CHECK-NEXT: bx lr +// CHECK: <func3>: +// CHECK-NEXT: bx lr +// CHECK-NEXT: d4d4 +// CHECK: <_start>: +// CHECK-NEXT: bl {{.*}} <func1> +// CHECK-NEXT: bl {{.*}} <func2> +// CHECK-NEXT: bl {{.*}} <func3> +// CHECK-NEXT: b.w {{.*}} <func1> +// CHECK-NEXT: b.w {{.*}} <func2> +// CHECK-NEXT: b.w {{.*}} <func3> +// CHECK-NEXT: beq.w {{.*}} <func1> +// CHECK-NEXT: beq.w {{.*}} <func2> +// CHECK-NEXT: beq.w {{.*}} <func3> + +// DSO: Disassembly of section .text: +// DSO-EMPTY: +// DSO-NEXT: <func1>: +// DSO-NEXT: bx lr +// DSO: <func2>: +// DSO-NEXT: bx lr +// DSO: <func3>: +// DSO-NEXT: bx lr +// DSO-NEXT: d4d4 +// DSO: <_start>: +/// 0x10260 = PLT func1 +// DSO-NEXT: bl 0x10260 +/// 0x10270 = PLT func2 +// DSO-NEXT: bl 0x10270 +/// 0x10280 = PLT func3 +// DSO-NEXT: bl 0x10280 +/// 0x10260 = PLT func1 +// DSO-NEXT: b.w 0x10260 +/// 0x10270 = PLT func2 +// DSO-NEXT: b.w 0x10270 +/// 0x10280 = PLT func3 +// DSO-NEXT: b.w 0x10280 +/// 0x10260 = PLT func1 +// DSO-NEXT: beq.w 0x10260 +/// 0x10270 = PLT func2 +// DSO-NEXT: beq.w 0x10270 +/// 0x10280 = PLT func3 +// DSO-NEXT: beq.w 0x10280 +// DSO: Disassembly of section .plt: +// DSO-EMPTY: +// DSO-NEXT: 10240 <.plt>: +// DSO-NEXT: push {lr} +// DSO-NEXT: ldr.w lr, [pc, #8] +// DSO-NEXT: add lr, pc +// DSO-NEXT: ldr pc, [lr, #8]! +/// 0x20098 = .got.plt (0x302D8) - pc (0x10238 = .plt + 8) - 8 +// DSO-NEXT: .word 0x00020098 +// DSO-NEXT: .word 0xd4d4d4d4 +// DSO-NEXT: .word 0xd4d4d4d4 +// DSO-NEXT: .word 0xd4d4d4d4 +// DSO-NEXT: .word 0xd4d4d4d4 + +/// 136 + 2 << 16 + 0x1026c = 0x302f4 = got entry 1 +// DSO-NEXT: 10260: f240 0c88 movw r12, #136 +// DSO-NEXT: f2c0 0c02 movt r12, #2 +// DSO-NEXT: 44fc add r12, pc +// DSO-NEXT: f8dc f000 ldr.w pc, [r12] +// DSO-NEXT: e7fc b 0x1026a +/// 124 + 2 << 16 + 0x1027c = 0x302f8 = got entry 2 +// DSO-NEXT: 10270: f240 0c7c movw r12, #124 +// DSO-NEXT: f2c0 0c02 movt r12, #2 +// DSO-NEXT: 44fc add r12, pc +// DSO-NEXT: f8dc f000 ldr.w pc, [r12] +// DSO-NEXT: e7fc b 0x1027a +/// 112 + 2 << 16 + 0x1028c = 0x302fc = got entry 3 +// DSO-NEXT: 10280: f240 0c70 movw r12, #112 +// DSO-NEXT: f2c0 0c02 movt r12, #2 +// DSO-NEXT: 44fc add r12, pc +// DSO-NEXT: f8dc f000 ldr.w pc, [r12] +// DSO-NEXT: e7fc b 0x1028a + +// DSOREL: .got.plt PROGBITS 000302e8 {{.*}} 000018 00 WA 0 0 4 +// DSOREL: Relocation section '.rel.plt' +// DSOREL: 000302f4 {{.*}} R_ARM_JUMP_SLOT {{.*}} func1 +// DSOREL: 000302f8 {{.*}} R_ARM_JUMP_SLOT {{.*}} func2 +// DSOREL: 000302fc {{.*}} R_ARM_JUMP_SLOT {{.*}} func3 |