[llvm] [RISCV] Use the thread local stack protector for Android targets (PR #87672)

Paul Kirth via llvm-commits llvm-commits at lists.llvm.org
Fri May 10 13:35:22 PDT 2024


https://github.com/ilovepi updated https://github.com/llvm/llvm-project/pull/87672

>From 941ec507d2ce9627dbdefb8602b5b0606ef071c2 Mon Sep 17 00:00:00 2001
From: Paul Kirth <paulkirth at google.com>
Date: Thu, 4 Apr 2024 11:30:21 -0700
Subject: [PATCH 1/2] =?UTF-8?q?[=F0=9D=98=80=F0=9D=97=BD=F0=9D=97=BF]=20ch?=
 =?UTF-8?q?anges=20to=20main=20this=20commit=20is=20based=20on?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

Created using spr 1.3.4

[skip ci]
---
 llvm/lib/Target/RISCV/RISCVSubtarget.h | 1 +
 1 file changed, 1 insertion(+)

diff --git a/llvm/lib/Target/RISCV/RISCVSubtarget.h b/llvm/lib/Target/RISCV/RISCVSubtarget.h
index ba108912d9340..85f8f5f654fe7 100644
--- a/llvm/lib/Target/RISCV/RISCVSubtarget.h
+++ b/llvm/lib/Target/RISCV/RISCVSubtarget.h
@@ -254,6 +254,7 @@ class RISCVSubtarget : public RISCVGenSubtargetInfo {
   const LegalizerInfo *getLegalizerInfo() const override;
   const RegisterBankInfo *getRegBankInfo() const override;
 
+  bool isTargetAndroid() const { return getTargetTriple().isAndroid(); }
   bool isTargetFuchsia() const { return getTargetTriple().isOSFuchsia(); }
 
   bool useConstantPoolForLargeInts() const;

>From b7ab9896dfe0ec7c40b0f73764d06e6f9021445a Mon Sep 17 00:00:00 2001
From: Paul Kirth <paulkirth at google.com>
Date: Thu, 4 Apr 2024 11:54:08 -0700
Subject: [PATCH 2/2] =?UTF-8?q?[=F0=9D=98=80=F0=9D=97=BD=F0=9D=97=BF]=20ch?=
 =?UTF-8?q?anges=20introduced=20through=20rebase?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

Created using spr 1.3.4

[skip ci]
---
 .../CodeGen/RISCV/stack-protector-target.ll   | 44 +++++++++++++++++++
 1 file changed, 44 insertions(+)

diff --git a/llvm/test/CodeGen/RISCV/stack-protector-target.ll b/llvm/test/CodeGen/RISCV/stack-protector-target.ll
index 13abde7878f3a..50531d3849822 100644
--- a/llvm/test/CodeGen/RISCV/stack-protector-target.ll
+++ b/llvm/test/CodeGen/RISCV/stack-protector-target.ll
@@ -2,9 +2,32 @@
 
 ;; Test target-specific stack cookie location.
 ;
+; RUN: llc -mtriple=riscv64-linux < %s | FileCheck --check-prefix=LINUX-RISCV64 %s
 ; RUN: llc -mtriple=riscv64-fuchsia < %s | FileCheck --check-prefix=FUCHSIA-RISCV64 %s
+; RUN: llc -mtriple=riscv64-android < %s | FileCheck --check-prefix=ANDROID-RISCV64 %s
 
 define void @func() sspreq nounwind {
+; LINUX-RISCV64-LABEL: func:
+; LINUX-RISCV64:       # %bb.0:
+; LINUX-RISCV64-NEXT:    addi sp, sp, -32
+; LINUX-RISCV64-NEXT:    sd ra, 24(sp) # 8-byte Folded Spill
+; LINUX-RISCV64-NEXT:    sd s0, 16(sp) # 8-byte Folded Spill
+; LINUX-RISCV64-NEXT:    lui s0, %hi(__stack_chk_guard)
+; LINUX-RISCV64-NEXT:    ld a0, %lo(__stack_chk_guard)(s0)
+; LINUX-RISCV64-NEXT:    sd a0, 8(sp)
+; LINUX-RISCV64-NEXT:    addi a0, sp, 4
+; LINUX-RISCV64-NEXT:    call capture
+; LINUX-RISCV64-NEXT:    ld a0, %lo(__stack_chk_guard)(s0)
+; LINUX-RISCV64-NEXT:    ld a1, 8(sp)
+; LINUX-RISCV64-NEXT:    bne a0, a1, .LBB0_2
+; LINUX-RISCV64-NEXT:  # %bb.1:
+; LINUX-RISCV64-NEXT:    ld ra, 24(sp) # 8-byte Folded Reload
+; LINUX-RISCV64-NEXT:    ld s0, 16(sp) # 8-byte Folded Reload
+; LINUX-RISCV64-NEXT:    addi sp, sp, 32
+; LINUX-RISCV64-NEXT:    ret
+; LINUX-RISCV64-NEXT:  .LBB0_2:
+; LINUX-RISCV64-NEXT:    call __stack_chk_fail
+;
 ; FUCHSIA-RISCV64-LABEL: func:
 ; FUCHSIA-RISCV64:       # %bb.0:
 ; FUCHSIA-RISCV64-NEXT:    addi sp, sp, -32
@@ -22,6 +45,27 @@ define void @func() sspreq nounwind {
 ; FUCHSIA-RISCV64-NEXT:    ret
 ; FUCHSIA-RISCV64-NEXT:  .LBB0_2: # %CallStackCheckFailBlk
 ; FUCHSIA-RISCV64-NEXT:    call __stack_chk_fail
+;
+; ANDROID-RISCV64-LABEL: func:
+; ANDROID-RISCV64:       # %bb.0:
+; ANDROID-RISCV64-NEXT:    addi sp, sp, -32
+; ANDROID-RISCV64-NEXT:    sd ra, 24(sp) # 8-byte Folded Spill
+; ANDROID-RISCV64-NEXT:    sd s0, 16(sp) # 8-byte Folded Spill
+; ANDROID-RISCV64-NEXT:    lui s0, %hi(__stack_chk_guard)
+; ANDROID-RISCV64-NEXT:    ld a0, %lo(__stack_chk_guard)(s0)
+; ANDROID-RISCV64-NEXT:    sd a0, 8(sp)
+; ANDROID-RISCV64-NEXT:    addi a0, sp, 4
+; ANDROID-RISCV64-NEXT:    call capture
+; ANDROID-RISCV64-NEXT:    ld a0, %lo(__stack_chk_guard)(s0)
+; ANDROID-RISCV64-NEXT:    ld a1, 8(sp)
+; ANDROID-RISCV64-NEXT:    bne a0, a1, .LBB0_2
+; ANDROID-RISCV64-NEXT:  # %bb.1:
+; ANDROID-RISCV64-NEXT:    ld ra, 24(sp) # 8-byte Folded Reload
+; ANDROID-RISCV64-NEXT:    ld s0, 16(sp) # 8-byte Folded Reload
+; ANDROID-RISCV64-NEXT:    addi sp, sp, 32
+; ANDROID-RISCV64-NEXT:    ret
+; ANDROID-RISCV64-NEXT:  .LBB0_2:
+; ANDROID-RISCV64-NEXT:    call __stack_chk_fail
   %1 = alloca i32, align 4
   call void @capture(ptr %1)
   ret void



More information about the llvm-commits mailing list