From: "Pekka Jääskeläinen" <pekka@parmance.com>
To: gcc-patches@gcc.gnu.org
Subject: [PATCH 1/8] [BRIGFE] fix an alloca stack underflow
Date: Fri, 04 May 2018 13:57:00 -0000 [thread overview]
Message-ID: <fe36645b-165e-4829-a60b-6581266dedf0@parmance.com> (raw)
We didn't preserve additional space for the alloca frame pointers that
are needed to be saved in the alloca space.
Fixes libgomp.c++/target-6.C execution test.
---
libhsail-rt/rt/workitems.c | 15 ++++++++++++---
1 file changed, 12 insertions(+), 3 deletions(-)
diff --git a/libhsail-rt/rt/workitems.c b/libhsail-rt/rt/workitems.c
index 39daf27..36c9169 100644
--- a/libhsail-rt/rt/workitems.c
+++ b/libhsail-rt/rt/workitems.c
@@ -63,6 +63,12 @@ static clock_t start_time;
#define FIBER_STACK_SIZE (64*1024)
#define GROUP_SEGMENT_ALIGN 256
+/* Preserve this amount of additional space in the alloca stack as we
need to
+ store the alloca frame pointer to the alloca frame, thus must preserve
+ space for it. This thus supports at most 1024 functions with allocas in
+ a call chain. */
+#define ALLOCA_OVERHEAD 1024*4
+
uint32_t __hsail_workitemabsid (uint32_t dim, PHSAWorkItem *context);
uint32_t __hsail_workitemid (uint32_t dim, PHSAWorkItem *context);
@@ -246,7 +252,7 @@ phsa_execute_wi_gang (PHSAKernelLaunchData *context,
void *group_base_ptr,
!= 0)
phsa_fatal_error (3);
- wg.alloca_stack_p = wg.private_segment_total_size;
+ wg.alloca_stack_p = wg.private_segment_total_size + ALLOCA_OVERHEAD;
wg.alloca_frame_p = wg.alloca_stack_p;
wg.initial_group_offset = group_local_offset;
@@ -446,7 +452,7 @@ phsa_execute_work_groups (PHSAKernelLaunchData
*context, void *group_base_ptr,
!= 0)
phsa_fatal_error (3);
- wg.alloca_stack_p = dp->private_segment_size * wg_size;
+ wg.alloca_stack_p = dp->private_segment_size * wg_size + ALLOCA_OVERHEAD;
wg.alloca_frame_p = wg.alloca_stack_p;
wg.private_base_ptr = private_base_ptr;
@@ -867,9 +873,12 @@ uint32_t
__hsail_alloca (uint32_t size, uint32_t align, PHSAWorkItem *wi)
{
volatile PHSAWorkGroup *wg = wi->wg;
- uint32_t new_pos = wg->alloca_stack_p - size;
+ int64_t new_pos = wg->alloca_stack_p - size;
while (new_pos % align != 0)
new_pos--;
+ if (new_pos < 0)
+ phsa_fatal_error (2);
+
wg->alloca_stack_p = new_pos;
#ifdef DEBUG_ALLOCA
--
2.7.4
next reply other threads:[~2018-05-04 13:57 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2018-05-04 13:57 Pekka Jääskeläinen [this message]
2018-05-04 16:42 ` Pekka Jääskeläinen
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=fe36645b-165e-4829-a60b-6581266dedf0@parmance.com \
--to=pekka@parmance.com \
--cc=gcc-patches@gcc.gnu.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).