This repository has been archived by the owner on Feb 5, 2019. It is now read-only.
forked from luqmana/llvm
-
Notifications
You must be signed in to change notification settings - Fork 63
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add stack overflow check for ARM Thumb instruction set.
Besides the mechanincal changes between the ARM and Thumb functions, because of the different instruction sets, there is difference in how the stack limit is located. The ARM version uses hardware which isn't available on the lower-end Thumb processors (namely system co-processor and MMU) therefore the stack limit is placed at a predefined location in memory - STACK_LIMIT. It is the responsibility of the wrapping runtime to manage this location with the correct value. It can vary from a simple constant defined by the linker to actively managed variable by a RTOS implementation.
- Loading branch information
1 parent
ed0d140
commit fd8a627
Showing
4 changed files
with
365 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
; RUN: llc < %s -mcpu=generic -mtriple=thumb-linux-android -segmented-stacks -verify-machineinstrs | FileCheck %s -check-prefix=Thumb-Linux-Android | ||
; RUN: llc < %s -mcpu=generic -mtriple=thumb-linux-android -segmented-stacks -filetype=obj | ||
|
||
; Just to prevent the alloca from being optimized away | ||
declare void @dummy_use(i32*, i32) | ||
|
||
define i32 @test_basic(i32 %l) { | ||
%mem = alloca i32, i32 %l | ||
call void @dummy_use (i32* %mem, i32 %l) | ||
%terminate = icmp eq i32 %l, 0 | ||
br i1 %terminate, label %true, label %false | ||
|
||
true: | ||
ret i32 0 | ||
|
||
false: | ||
%newlen = sub i32 %l, 1 | ||
%retvalue = call i32 @test_basic(i32 %newlen) | ||
ret i32 %retvalue | ||
|
||
; Thumb-Linux-Android: test_basic: | ||
|
||
; Thumb-Linux-Android: push {r4, r5} | ||
; Thumb-Linux-Android-NEXT: mov r5, sp | ||
; Thumb-Linux-Android-NEXT: ldr r4, .LCPI0_0 | ||
; Thumb-Linux-Android-NEXT: ldr r4, [r4] | ||
; Thumb-Linux-Android-NEXT: cmp r4, r5 | ||
; Thumb-Linux-Android-NEXT: blo .LBB0_2 | ||
|
||
; Thumb-Linux-Android: mov r4, #16 | ||
; Thumb-Linux-Android-NEXT: mov r5, #0 | ||
; Thumb-Linux-Android-NEXT: push {lr} | ||
; Thumb-Linux-Android-NEXT: bl __morestack | ||
; Thumb-Linux-Android-NEXT: pop {r4} | ||
; Thumb-Linux-Android-NEXT: mov lr, r4 | ||
; Thumb-Linux-Android-NEXT: pop {r4, r5} | ||
; Thumb-Linux-Android-NEXT: mov pc, lr | ||
|
||
; Thumb-Linux-Android: pop {r4, r5} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,145 @@ | ||
; RUN: llc < %s -mcpu=generic -mtriple=thumb-linux-android -segmented-stacks -verify-machineinstrs | FileCheck %s -check-prefix=Thumb-Linux-Android | ||
|
||
; We used to crash with filetype=obj | ||
; RUN: llc < %s -mcpu=generic -mtriple=thumb-linux-android -segmented-stacks -filetype=obj | ||
|
||
|
||
; Just to prevent the alloca from being optimized away | ||
declare void @dummy_use(i32*, i32) | ||
|
||
define void @test_basic() { | ||
%mem = alloca i32, i32 10 | ||
call void @dummy_use (i32* %mem, i32 10) | ||
ret void | ||
|
||
; Thumb-Linux-Android: test_basic: | ||
|
||
; Thumb-Linux-Android: push {r4, r5} | ||
; Thumb-Linux-Android-NEXT: mov r5, sp | ||
; Thumb-Linux-Android-NEXT: ldr r4, .LCPI0_0 | ||
; Thumb-Linux-Android-NEXT: ldr r4, [r4] | ||
; Thumb-Linux-Android-NEXT: cmp r4, r5 | ||
; Thumb-Linux-Android-NEXT: blo .LBB0_2 | ||
|
||
; Thumb-Linux-Android: mov r4, #48 | ||
; Thumb-Linux-Android-NEXT: mov r5, #0 | ||
; Thumb-Linux-Android-NEXT: push {lr} | ||
; Thumb-Linux-Android-NEXT: bl __morestack | ||
; Thumb-Linux-Android-NEXT: pop {r4} | ||
; Thumb-Linux-Android-NEXT: mov lr, r4 | ||
; Thumb-Linux-Android-NEXT: pop {r4, r5} | ||
; Thumb-Linux-Android-NEXT: mov pc, lr | ||
|
||
; Thumb-Linux-Android: pop {r4, r5} | ||
|
||
} | ||
|
||
define i32 @test_nested(i32 * nest %closure, i32 %other) { | ||
%addend = load i32 * %closure | ||
%result = add i32 %other, %addend | ||
ret i32 %result | ||
|
||
; Thumb-Linux-Android: test_nested: | ||
|
||
; Thumb-Linux-Android: push {r4, r5} | ||
; Thumb-Linux-Android-NEXT: mov r5, sp | ||
; Thumb-Linux-Android-NEXT: ldr r4, .LCPI1_0 | ||
; Thumb-Linux-Android-NEXT: ldr r4, [r4] | ||
; Thumb-Linux-Android-NEXT: cmp r4, r5 | ||
; Thumb-Linux-Android-NEXT: blo .LBB1_2 | ||
|
||
; Thumb-Linux-Android: mov r4, #0 | ||
; Thumb-Linux-Android-NEXT: mov r5, #0 | ||
; Thumb-Linux-Android-NEXT: push {lr} | ||
; Thumb-Linux-Android-NEXT: bl __morestack | ||
; Thumb-Linux-Android-NEXT: pop {r4} | ||
; Thumb-Linux-Android-NEXT: mov lr, r4 | ||
; Thumb-Linux-Android-NEXT: pop {r4, r5} | ||
; Thumb-Linux-Android-NEXT: mov pc, lr | ||
|
||
; Thumb-Linux-Android: pop {r4, r5} | ||
|
||
} | ||
|
||
define void @test_large() { | ||
%mem = alloca i32, i32 10000 | ||
call void @dummy_use (i32* %mem, i32 0) | ||
ret void | ||
|
||
; Thumb-Linux-Android: test_large: | ||
|
||
; Thumb-Linux-Android: push {r4, r5} | ||
; Thumb-Linux-Android-NEXT: mov r5, sp | ||
; Thumb-Linux-Android-NEXT: sub r5, #40192 | ||
; Thumb-Linux-Android-NEXT: ldr r4, .LCPI2_2 | ||
; Thumb-Linux-Android-NEXT: ldr r4, [r4] | ||
; Thumb-Linux-Android-NEXT: cmp r4, r5 | ||
; Thumb-Linux-Android-NEXT: blo .LBB2_2 | ||
|
||
; Thumb-Linux-Android: mov r4, #40192 | ||
; Thumb-Linux-Android-NEXT: mov r5, #0 | ||
; Thumb-Linux-Android-NEXT: push {lr} | ||
; Thumb-Linux-Android-NEXT: bl __morestack | ||
; Thumb-Linux-Android-NEXT: pop {r4} | ||
; Thumb-Linux-Android-NEXT: mov lr, r4 | ||
; Thumb-Linux-Android-NEXT: pop {r4, r5} | ||
; Thumb-Linux-Android-NEXT: mov pc, lr | ||
|
||
; Thumb-Linux-Android: pop {r4, r5} | ||
|
||
} | ||
|
||
define fastcc void @test_fastcc() { | ||
%mem = alloca i32, i32 10 | ||
call void @dummy_use (i32* %mem, i32 10) | ||
ret void | ||
|
||
; Thumb-Linux-Android: test_fastcc: | ||
|
||
; Thumb-Linux-Android: push {r4, r5} | ||
; Thumb-Linux-Android-NEXT: mov r5, sp | ||
; Thumb-Linux-Android-NEXT: ldr r4, .LCPI3_0 | ||
; Thumb-Linux-Android-NEXT: ldr r4, [r4] | ||
; Thumb-Linux-Android-NEXT: cmp r4, r5 | ||
; Thumb-Linux-Android-NEXT: blo .LBB3_2 | ||
|
||
; Thumb-Linux-Android: mov r4, #48 | ||
; Thumb-Linux-Android-NEXT: mov r5, #0 | ||
; Thumb-Linux-Android-NEXT: push {lr} | ||
; Thumb-Linux-Android-NEXT: bl __morestack | ||
; Thumb-Linux-Android-NEXT: pop {r4} | ||
; Thumb-Linux-Android-NEXT: mov lr, r4 | ||
; Thumb-Linux-Android-NEXT: pop {r4, r5} | ||
; Thumb-Linux-Android-NEXT: mov pc, lr | ||
|
||
; Thumb-Linux-Android: pop {r4, r5} | ||
|
||
} | ||
|
||
define fastcc void @test_fastcc_large() { | ||
%mem = alloca i32, i32 10000 | ||
call void @dummy_use (i32* %mem, i32 0) | ||
ret void | ||
|
||
; Thumb-Linux-Android: test_fastcc_large: | ||
|
||
; Thumb-Linux-Android: push {r4, r5} | ||
; Thumb-Linux-Android-NEXT: mov r5, sp | ||
; Thumb-Linux-Android-NEXT: sub r5, #40192 | ||
; Thumb-Linux-Android-NEXT: ldr r4, .LCPI4_2 | ||
; Thumb-Linux-Android-NEXT: ldr r4, [r4] | ||
; Thumb-Linux-Android-NEXT: cmp r4, r5 | ||
; Thumb-Linux-Android-NEXT: blo .LBB4_2 | ||
|
||
; Thumb-Linux-Android: mov r4, #40192 | ||
; Thumb-Linux-Android-NEXT: mov r5, #0 | ||
; Thumb-Linux-Android-NEXT: push {lr} | ||
; Thumb-Linux-Android-NEXT: bl __morestack | ||
; Thumb-Linux-Android-NEXT: pop {r4} | ||
; Thumb-Linux-Android-NEXT: mov lr, r4 | ||
; Thumb-Linux-Android-NEXT: pop {r4, r5} | ||
; Thumb-Linux-Android-NEXT: mov pc, lr | ||
|
||
; Thumb-Linux-Android: pop {r4, r5} | ||
|
||
} |