Skip to content

Commit 47c5734

Browse files
authored
[SSP] Accessing __stack_chk_guard when using LTO (#66535)
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. It confirms issue [#64999](#64999). The intent is to update this test with the fix for the aforementioned issue.
1 parent bbe3ee0 commit 47c5734

File tree

1 file changed

+40
-0
lines changed

1 file changed

+40
-0
lines changed

llvm/test/LTO/ARM/ssp-static-reloc.ll

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
; RUN: llvm-as < %s > %t.bc
2+
; RUN: llvm-lto -O0 -relocation-model=static -o %t.o %t.bc
3+
; RUN: llvm-objdump -d -r %t.o | FileCheck %s
4+
5+
; Confirm that we do generate one too many indirections accessing the stack guard
6+
; variable, when the relocation model is static and the PIC level is not 0..
7+
; This is preparation for the fix.
8+
;
9+
target triple = "armv4t-unknown-unknown"
10+
11+
define arm_aapcscc i8 @foo() #0 {
12+
entry:
13+
%arr = alloca [200 x i8], align 1
14+
call void @llvm.memset.p0.i32(ptr align 1 %arr, i8 0, i32 200, i1 false)
15+
%arrayidx = getelementptr inbounds [200 x i8], ptr %arr, i32 0, i8 5
16+
%0 = load i8, ptr %arrayidx, align 1
17+
ret i8 %0
18+
}
19+
20+
; CHECK: <foo>:
21+
; CHECK: [[#%x,CURPC:]]:{{.*}} ldr r[[REG1:[0-9]+]], [pc, #0x[[#%x,OFFSET:]]]
22+
; CHECK-NEXT: ldr r[[REG2:[0-9]+]], [r[[REG1]]]
23+
; CHECK-NEXT: ldr r[[REG3:[0-9]+]], [r[[REG2]]]
24+
; CHECK-NEXT: str r[[REG3]],
25+
; CHECK: [[#CURPC + OFFSET + 8]]:{{.*}}.word
26+
; CHECK-NEXT: R_ARM_ABS32 __stack_chk_guard
27+
28+
declare void @llvm.memset.p0.i32(ptr nocapture writeonly, i8, i32, i1 immarg)
29+
30+
define arm_aapcscc i32 @main() {
31+
entry:
32+
%call = call arm_aapcscc i8 @foo()
33+
%conv = zext i8 %call to i32
34+
ret i32 %conv
35+
}
36+
37+
attributes #0 = { sspstrong }
38+
39+
!llvm.module.flags = !{!0}
40+
!0 = !{i32 8, !"PIC Level", i32 2}

0 commit comments

Comments
 (0)