[llvm] [SSP] Accessing __stack_chk_guard when using LTO (PR #66535)

Wolfgang Pieb via llvm-commits llvm-commits at lists.llvm.org
Mon Sep 18 16:11:13 PDT 2023


https://github.com/wolfy1961 updated https://github.com/llvm/llvm-project/pull/66535

>From 5e39ea493d04fb7fe635b338350862c9ebba9857 Mon Sep 17 00:00:00 2001
From: wpieb <Wolfgang.Pieb at sony.com>
Date: Fri, 15 Sep 2023 09:47:30 -0700
Subject: [PATCH 1/2] [SSP] Accessing __stack_chk_guard when using LTO This is
 a pre-commit test of accessing the variable __stack_chk_guard when the static
 relocation model is imposed on a module compiled with pic enabled.

---
 llvm/test/LTO/ARM/ssp-static-reloc.ll | 40 +++++++++++++++++++++++++++
 1 file changed, 40 insertions(+)
 create mode 100644 llvm/test/LTO/ARM/ssp-static-reloc.ll

diff --git a/llvm/test/LTO/ARM/ssp-static-reloc.ll b/llvm/test/LTO/ARM/ssp-static-reloc.ll
new file mode 100644
index 000000000000000..ca32505996b8656
--- /dev/null
+++ b/llvm/test/LTO/ARM/ssp-static-reloc.ll
@@ -0,0 +1,40 @@
+; Confirm that we do generate one too many indirections accessing the stack guard
+; variable, when the relocation model is static.
+; This is preparation for the fix. 
+;
+; RUN: llvm-as < %s > %t.bc
+; RUN: llvm-lto -O0 -relocation-model=static -o %t.o %t.bc
+; RUN: llvm-objdump -d -r %t.o | FileCheck %s
+
+target triple = "armv4t-unknown-unknown"
+
+define arm_aapcscc i8 @foo() #0 {
+entry:
+  %arr = alloca [200 x i8], align 1
+  call void @llvm.memset.p0.i32(ptr align 1 %arr, i8 0, i32 200, i1 false)
+  %arrayidx = getelementptr inbounds [200 x i8], ptr %arr, i32 0, i8 5
+  %0 = load i8, ptr %arrayidx, align 1
+  ret i8 %0
+}
+
+; CHECK:      <foo>:
+; CHECK:      [[#%x,CURPC:]]:{{.*}} ldr r[[REG1:[0-9]+]], [pc, #0x[[#%x,OFFSET:]]]
+; CHECK-NEXT: ldr r[[REG2:[0-9]+]], [r[[REG1]]]
+; CHECK-NEXT: ldr r[[REG3:[0-9]+]], [r[[REG2]]]
+; CHECK-NEXT: str r[[REG3]],
+; CHECK:      [[#CURPC + OFFSET + 8]]:{{.*}}.word
+; CHECK-NEXT: R_ARM_ABS32 __stack_chk_guard
+
+declare void @llvm.memset.p0.i32(ptr nocapture writeonly, i8, i32, i1 immarg)
+
+define arm_aapcscc i32 @main() {
+entry:
+  %call = call arm_aapcscc i8 @foo()
+  %conv = zext i8 %call to i32
+  ret i32 %conv
+}
+
+attributes #0 = { noinline nounwind optnone sspstrong }
+
+!llvm.module.flags = !{!0}
+!0 = !{i32 8, !"PIC Level", i32 2}

>From 1ebee38732dd3c463e5c7d5120d443b86f497f51 Mon Sep 17 00:00:00 2001
From: wpieb <Wolfgang.Pieb at sony.com>
Date: Mon, 18 Sep 2023 16:10:28 -0700
Subject: [PATCH 2/2] Moved RUN lines to the top and removed some function
 attributes.

---
 llvm/test/LTO/ARM/ssp-static-reloc.ll | 10 +++++-----
 1 file changed, 5 insertions(+), 5 deletions(-)

diff --git a/llvm/test/LTO/ARM/ssp-static-reloc.ll b/llvm/test/LTO/ARM/ssp-static-reloc.ll
index ca32505996b8656..c8825c2aae0fbb6 100644
--- a/llvm/test/LTO/ARM/ssp-static-reloc.ll
+++ b/llvm/test/LTO/ARM/ssp-static-reloc.ll
@@ -1,11 +1,11 @@
-; Confirm that we do generate one too many indirections accessing the stack guard
-; variable, when the relocation model is static.
-; This is preparation for the fix. 
-;
 ; RUN: llvm-as < %s > %t.bc
 ; RUN: llvm-lto -O0 -relocation-model=static -o %t.o %t.bc
 ; RUN: llvm-objdump -d -r %t.o | FileCheck %s
 
+; Confirm that we do generate one too many indirections accessing the stack guard
+; variable, when the relocation model is static and the PIC level is not 0..
+; This is preparation for the fix.
+;
 target triple = "armv4t-unknown-unknown"
 
 define arm_aapcscc i8 @foo() #0 {
@@ -34,7 +34,7 @@ entry:
   ret i32 %conv
 }
 
-attributes #0 = { noinline nounwind optnone sspstrong }
+attributes #0 = { sspstrong }
 
 !llvm.module.flags = !{!0}
 !0 = !{i32 8, !"PIC Level", i32 2}



More information about the llvm-commits mailing list