Skip to content

[ARM] Honour -mno-movt in stack protector handling #109022

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Oct 9, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion llvm/lib/Target/ARM/Thumb2InstrInfo.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
32 changes: 32 additions & 0 deletions llvm/test/CodeGen/ARM/stack-guard-nomovt.ll
Original file line number Diff line number Diff line change
@@ -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 }
Loading