Use 16 byte stack alignment for NaCl on ARM
NaCl's ARM ABI uses 16 byte stack alignment, so set that in
ARMSubtarget.cpp.
Using 16 byte alignment exposes an issue in code generation in which a
varargs function leaves a 4 byte gap between the values of r1-r3 saved
to the stack and the following arguments that were passed on the
stack. (Previously, this code only needed to support 4 byte and 8
byte alignment.)
With this issue, llc generated:
varargs_func:
sub sp, sp, #16
push {lr}
sub sp, sp, #12
add r0, sp, #16 // Should be 20
stm r0, {r1, r2, r3}
ldr r0, .LCPI0_0 // Address of va_list
add r1, sp, #16
str r1, [r0]
bl external_func
Fix the bug by checking for "Align > 4". Also simplify the code by
using OffsetToAlignment(), and update comments.
Differential Revision: http://llvm-reviews.chandlerc.com/D2677
llvm-svn: 201497
2014-02-17 02:59:48 +08:00
|
|
|
; RUN: llc < %s -mtriple=arm-nacl-gnueabi | FileCheck %s
|
|
|
|
|
|
|
|
declare void @llvm.va_start(i8*)
|
|
|
|
declare void @external_func(i8*)
|
|
|
|
|
|
|
|
@va_list = external global i8*
|
|
|
|
|
|
|
|
; On ARM, varargs arguments are passed in r0-r3 with the rest on the
|
|
|
|
; stack. A varargs function must therefore spill rN-r3 just below the
|
|
|
|
; function's initial stack pointer.
|
|
|
|
;
|
|
|
|
; This test checks for a bug in which a gap was left between the spill
|
|
|
|
; area and varargs arguments on the stack when using 16 byte stack
|
|
|
|
; alignment.
|
|
|
|
|
|
|
|
define void @varargs_func(i32 %arg1, ...) {
|
|
|
|
call void @llvm.va_start(i8* bitcast (i8** @va_list to i8*))
|
|
|
|
call void @external_func(i8* bitcast (i8** @va_list to i8*))
|
|
|
|
ret void
|
|
|
|
}
|
|
|
|
; CHECK-LABEL: varargs_func:
|
|
|
|
; Reserve space for the varargs save area. This currently reserves
|
|
|
|
; more than enough (16 bytes rather than the 12 bytes needed).
|
2015-03-12 02:54:22 +08:00
|
|
|
; CHECK: sub sp, sp, #12
|
2014-11-05 08:27:20 +08:00
|
|
|
; CHECK: push {r11, lr}
|
Use 16 byte stack alignment for NaCl on ARM
NaCl's ARM ABI uses 16 byte stack alignment, so set that in
ARMSubtarget.cpp.
Using 16 byte alignment exposes an issue in code generation in which a
varargs function leaves a 4 byte gap between the values of r1-r3 saved
to the stack and the following arguments that were passed on the
stack. (Previously, this code only needed to support 4 byte and 8
byte alignment.)
With this issue, llc generated:
varargs_func:
sub sp, sp, #16
push {lr}
sub sp, sp, #12
add r0, sp, #16 // Should be 20
stm r0, {r1, r2, r3}
ldr r0, .LCPI0_0 // Address of va_list
add r1, sp, #16
str r1, [r0]
bl external_func
Fix the bug by checking for "Align > 4". Also simplify the code by
using OffsetToAlignment(), and update comments.
Differential Revision: http://llvm-reviews.chandlerc.com/D2677
llvm-svn: 201497
2014-02-17 02:59:48 +08:00
|
|
|
; Align the stack pointer to a multiple of 16.
|
2015-03-12 02:54:22 +08:00
|
|
|
; CHECK: sub sp, sp, #12
|
Use 16 byte stack alignment for NaCl on ARM
NaCl's ARM ABI uses 16 byte stack alignment, so set that in
ARMSubtarget.cpp.
Using 16 byte alignment exposes an issue in code generation in which a
varargs function leaves a 4 byte gap between the values of r1-r3 saved
to the stack and the following arguments that were passed on the
stack. (Previously, this code only needed to support 4 byte and 8
byte alignment.)
With this issue, llc generated:
varargs_func:
sub sp, sp, #16
push {lr}
sub sp, sp, #12
add r0, sp, #16 // Should be 20
stm r0, {r1, r2, r3}
ldr r0, .LCPI0_0 // Address of va_list
add r1, sp, #16
str r1, [r0]
bl external_func
Fix the bug by checking for "Align > 4". Also simplify the code by
using OffsetToAlignment(), and update comments.
Differential Revision: http://llvm-reviews.chandlerc.com/D2677
llvm-svn: 201497
2014-02-17 02:59:48 +08:00
|
|
|
; Calculate the address of the varargs save area and save varargs
|
|
|
|
; arguments into it.
|
|
|
|
; CHECK-NEXT: add r0, sp, #20
|
|
|
|
; CHECK-NEXT: stm r0, {r1, r2, r3}
|