diff options
| author | Ard Biesheuvel <ardb@kernel.org> | 2024-10-09 18:34:17 +0200 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2024-10-09 09:34:17 -0700 |
| commit | 2e47b93fd29ad6ef13a4134f3b0be3c42e91180c (patch) | |
| tree | 4c0690c3f862d60374a3e5fb18c42397a69a845a | |
| parent | 18952bdcd6f987620e6396261c2bb444e428e07e (diff) | |
| download | llvm-2e47b93fd29ad6ef13a4134f3b0be3c42e91180c.zip llvm-2e47b93fd29ad6ef13a4134f3b0be3c42e91180c.tar.gz llvm-2e47b93fd29ad6ef13a4134f3b0be3c42e91180c.tar.bz2 | |
[ARM] Honour -mno-movt in stack protector handling (#109022)
When -mno-movt is passed to Clang, the ARM codegen correctly avoids
movt/movw pairs to take the address of __stack_chk_guard in the stack
protector code emitted into the function pro- and epilogues. However,
the Thumb2 codegen fails to do so, and happily emits movw/movt pairs
unless it is generating an ELF binary and the symbol might be in a
different DSO. Let's incorporate a check for useMovt() in the logic
here, so movt/movw are never emitted when -mno-movt is specified.
Suggestions welcome for how/where to add a test case for this.
Signed-off-by: Ard Biesheuvel <ardb@kernel.org>
| -rw-r--r-- | llvm/lib/Target/ARM/Thumb2InstrInfo.cpp | 5 | ||||
| -rw-r--r-- | llvm/test/CodeGen/ARM/stack-guard-nomovt.ll | 32 |
2 files changed, 36 insertions, 1 deletions
diff --git a/llvm/lib/Target/ARM/Thumb2InstrInfo.cpp b/llvm/lib/Target/ARM/Thumb2InstrInfo.cpp index d1e07b6..27f8638 100644 --- a/llvm/lib/Target/ARM/Thumb2InstrInfo.cpp +++ b/llvm/lib/Target/ARM/Thumb2InstrInfo.cpp @@ -264,8 +264,11 @@ void Thumb2InstrInfo::expandLoadStackGuard( } const auto *GV = cast<GlobalValue>((*MI->memoperands_begin())->getValue()); - if (MF.getSubtarget<ARMSubtarget>().isTargetELF() && !GV->isDSOLocal()) + const ARMSubtarget &Subtarget = MF.getSubtarget<ARMSubtarget>(); + if (Subtarget.isTargetELF() && !GV->isDSOLocal()) expandLoadStackGuardBase(MI, ARM::t2LDRLIT_ga_pcrel, ARM::t2LDRi12); + else if (!Subtarget.useMovt()) + expandLoadStackGuardBase(MI, ARM::tLDRLIT_ga_abs, ARM::t2LDRi12); else if (MF.getTarget().isPositionIndependent()) expandLoadStackGuardBase(MI, ARM::t2MOV_ga_pcrel, ARM::t2LDRi12); else diff --git a/llvm/test/CodeGen/ARM/stack-guard-nomovt.ll b/llvm/test/CodeGen/ARM/stack-guard-nomovt.ll new file mode 100644 index 0000000..6802dab --- /dev/null +++ b/llvm/test/CodeGen/ARM/stack-guard-nomovt.ll @@ -0,0 +1,32 @@ +; RUN: llc -relocation-model=static -mattr=+no-movt < %s | FileCheck %s + +target triple = "thumbv7a-linux-gnueabi" + +define i32 @test1() #0 { +; CHECK-LABEL: test1: +; CHECK: @ %bb.0: +; CHECK-NEXT: push {r7, lr} +; CHECK-NEXT: sub.w sp, sp, #1032 +; CHECK-NEXT: ldr r0, .LCPI0_0 +; CHECK-NEXT: ldr r0, [r0] +; CHECK-NEXT: str.w r0, [sp, #1028] +; CHECK-NEXT: add r0, sp, #4 +; CHECK-NEXT: bl foo +; CHECK-NEXT: ldr.w r0, [sp, #1028] +; CHECK-NEXT: ldr r1, .LCPI0_0 +; CHECK-NEXT: ldr r1, [r1] +; CHECK-NEXT: cmp r1, r0 +; CHECK-NEXT: ittt eq +; CHECK-NEXT: moveq r0, #0 +; CHECK-NEXT: addeq.w sp, sp, #1032 +; CHECK-NEXT: popeq {r7, pc} +; CHECK-NEXT: .LBB0_1: +; CHECK-NEXT: bl __stack_chk_fail + %a1 = alloca [256 x i32], align 4 + call void @foo(ptr %a1) #3 + ret i32 0 +} + +declare void @foo(ptr) + +attributes #0 = { nounwind sspstrong } |
