summaryrefslogtreecommitdiff
path: root/gcc/ada/s-secsta.adb
diff options
context:
space:
mode:
authorcharlet <charlet@138bc75d-0d04-0410-961f-82ee72b054a4>2007-06-06 10:48:07 +0000
committercharlet <charlet@138bc75d-0d04-0410-961f-82ee72b054a4>2007-06-06 10:48:07 +0000
commit6c2b4849f713dbb16030428a4d0bd7251c7de0a6 (patch)
treed7d3c341391a7ca4a07eceac77a4b346696cae45 /gcc/ada/s-secsta.adb
parent36b59c4c18f2cac5f312f1864f1320e0ddb9b680 (diff)
downloadgcc-6c2b4849f713dbb16030428a4d0bd7251c7de0a6.tar.gz
2007-04-20 Arnaud Charlet <charlet@adacore.com>
* s-secsta.adb (Chunk): Ensure this object has a static size known at compile time, to avoid dynamic memory allocation (Elaboration code): Only use dynamic memory allocation when needed. git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/trunk@125464 138bc75d-0d04-0410-961f-82ee72b054a4
Diffstat (limited to 'gcc/ada/s-secsta.adb')
-rw-r--r--gcc/ada/s-secsta.adb71
1 files changed, 49 insertions, 22 deletions
diff --git a/gcc/ada/s-secsta.adb b/gcc/ada/s-secsta.adb
index bc43eed93c0..0efa5556696 100644
--- a/gcc/ada/s-secsta.adb
+++ b/gcc/ada/s-secsta.adb
@@ -6,7 +6,7 @@
-- --
-- B o d y --
-- --
--- Copyright (C) 1992-2006, Free Software Foundation, Inc. --
+-- Copyright (C) 1992-2007, Free Software Foundation, Inc. --
-- --
-- GNAT is free software; you can redistribute it and/or modify it under --
-- terms of the GNU General Public License as published by the Free Soft- --
@@ -33,8 +33,8 @@
with System.Soft_Links;
with System.Parameters;
-with Unchecked_Conversion;
-with Unchecked_Deallocation;
+with Ada.Unchecked_Conversion;
+with Ada.Unchecked_Deallocation;
package body System.Secondary_Stack is
@@ -116,13 +116,13 @@ package body System.Secondary_Stack is
-- Pointer to record used to represent a dynamically allocated secondary
-- stack descriptor for a secondary stack chunk.
- procedure Free is new Unchecked_Deallocation (Chunk_Id, Chunk_Ptr);
+ procedure Free is new Ada.Unchecked_Deallocation (Chunk_Id, Chunk_Ptr);
-- Free a dynamically allocated chunk
function To_Stack_Ptr is new
- Unchecked_Conversion (Address, Stack_Ptr);
+ Ada.Unchecked_Conversion (Address, Stack_Ptr);
function To_Addr is new
- Unchecked_Conversion (Stack_Ptr, Address);
+ Ada.Unchecked_Conversion (Stack_Ptr, Address);
-- Convert to and from address stored in task data structures
--------------------------------------------------------------
@@ -166,7 +166,7 @@ package body System.Secondary_Stack is
-- Pointer to record used to describe statically allocated sec stack
function To_Fixed_Stack_Ptr is new
- Unchecked_Conversion (Address, Fixed_Stack_Ptr);
+ Ada.Unchecked_Conversion (Address, Fixed_Stack_Ptr);
-- Convert from address stored in task data structures
--------------
@@ -302,7 +302,8 @@ package body System.Secondary_Stack is
Stack : Stack_Ptr := To_Stack_Ptr (Stk);
Chunk : Chunk_Ptr;
- procedure Free is new Unchecked_Deallocation (Stack_Id, Stack_Ptr);
+ procedure Free is
+ new Ada.Unchecked_Deallocation (Stack_Id, Stack_Ptr);
begin
Chunk := Stack.Current_Chunk;
@@ -492,21 +493,47 @@ package body System.Secondary_Stack is
Stack : aliased Stack_Id;
for Stack'Alignment use Standard'Maximum_Alignment;
- Chunk : aliased Chunk_Id (1, SS_Ptr (Default_Secondary_Stack_Size));
- for Chunk'Alignment use Standard'Maximum_Alignment;
+ Static_Secondary_Stack_Size : constant := 10 * 1024;
+ -- Static_Secondary_Stack_Size must be static so that Chunk is allocated
+ -- statically, and not via dynamic memory allocation.
- Chunk_Address : Address;
+ Chunk : aliased Chunk_Id (1, Static_Secondary_Stack_Size);
+ for Chunk'Alignment use Standard'Maximum_Alignment;
+ -- Default chunk used, unless gnatbind -D is specified with a value
+ -- greater than Static_Secondary_Stack_Size
begin
- if SS_Ratio_Dynamic then
- Stack.Top := 1;
- Stack.Current_Chunk := Chunk'Access;
- Stack.Default_Size := SSE.Storage_Offset (Default_Secondary_Stack_Size);
- System.Soft_Links.Set_Sec_Stack_Addr_NT (Stack'Address);
-
- else
- Chunk_Address := Chunk'Address;
- SS_Init (Chunk_Address, Default_Secondary_Stack_Size);
- System.Soft_Links.Set_Sec_Stack_Addr_NT (Chunk_Address);
- end if;
+ declare
+ Chunk_Address : Address;
+ Chunk_Access : Chunk_Ptr;
+
+ begin
+ if Default_Secondary_Stack_Size <= Static_Secondary_Stack_Size then
+
+ -- Normally we allocate the secondary stack for the main program
+ -- statically, using the default secondary stack size.
+
+ Chunk_Access := Chunk'Access;
+
+ else
+ -- Default_Secondary_Stack_Size was increased via gnatbind -D, so we
+ -- need to allocate a chunk dynamically.
+
+ Chunk_Access :=
+ new Chunk_Id (1, SS_Ptr (Default_Secondary_Stack_Size));
+ end if;
+
+ if SS_Ratio_Dynamic then
+ Stack.Top := 1;
+ Stack.Current_Chunk := Chunk_Access;
+ Stack.Default_Size :=
+ SSE.Storage_Offset (Default_Secondary_Stack_Size);
+ System.Soft_Links.Set_Sec_Stack_Addr_NT (Stack'Address);
+
+ else
+ Chunk_Address := Chunk_Access.all'Address;
+ SS_Init (Chunk_Address, Default_Secondary_Stack_Size);
+ System.Soft_Links.Set_Sec_Stack_Addr_NT (Chunk_Address);
+ end if;
+ end;
end System.Secondary_Stack;