diff mbox

[Ada] Elaborate Secondary_Stack early

Message ID 20140613094722.GA803@adacore.com
State New
Headers show

Commit Message

Arnaud Charlet June 13, 2014, 9:47 a.m. UTC
This patch fixes an obscure bug that causes the secondary stack to be used
before it is initialized in certain cases. This can only happen if (1) the
-gnatE switch is used to disable the static elaboration mode, (2) the -p
switch is passed to gnatbind to tell it to choose a pessimistic (worst-case)
elaboration order, and (3) gnatbind happens to choose an order in which the
body of System.Tasking.Protected_Objects is elaborated before the body of
System.Secondary_Stack.

Tested on x86_64-pc-linux-gnu, committed on trunk

2014-06-13  Bob Duff  <duff@adacore.com>

	* s-solita.adb (Get_Sec_Stack_Addr, Init_Tasking_Soft_Links):
	Add assertions requiring the secondary stack to be initialized.
	* s-solita.ads (Init_Tasking_Soft_Links): Comment.
	* s-taprob.adb, s-tarest.adb, s-tasini.adb (elab code): Make sure the
	secondary stack is initialized before calling Init_Tasking_Soft_Links,
	by adding pragmas Elaborate_Body.
diff mbox

Patch

Index: s-tasini.adb
===================================================================
--- s-tasini.adb	(revision 211609)
+++ s-tasini.adb	(working copy)
@@ -6,7 +6,7 @@ 
 --                                                                          --
 --                                  B o d y                                 --
 --                                                                          --
---         Copyright (C) 1992-2013, Free Software Foundation, Inc.          --
+--         Copyright (C) 1992-2014, Free Software Foundation, Inc.          --
 --                                                                          --
 -- GNARL 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- --
@@ -47,6 +47,11 @@ 
 with System.Tasking.Debug;
 with System.Parameters;
 
+with System.Secondary_Stack; pragma Elaborate_All (System.Secondary_Stack);
+pragma Unreferenced (System.Secondary_Stack);
+--  Make sure the body of Secondary_Stack is elaborated before calling
+--  Init_Tasking_Soft_Links.
+
 package body System.Tasking.Initialization is
 
    package STPO renames System.Task_Primitives.Operations;
Index: s-tarest.adb
===================================================================
--- s-tarest.adb	(revision 211609)
+++ s-tarest.adb	(working copy)
@@ -6,7 +6,7 @@ 
 --                                                                          --
 --                                  B o d y                                 --
 --                                                                          --
---         Copyright (C) 1999-2013, Free Software Foundation, Inc.          --
+--         Copyright (C) 1999-2014, Free Software Foundation, Inc.          --
 --                                                                          --
 -- GNARL 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- --
@@ -47,9 +47,12 @@ 
 
 with System.Task_Primitives.Operations;
 with System.Soft_Links.Tasking;
-with System.Secondary_Stack;
 with System.Storage_Elements;
 
+with System.Secondary_Stack; pragma Elaborate_All (System.Secondary_Stack);
+--  Make sure the body of Secondary_Stack is elaborated before calling
+--  Init_Tasking_Soft_Links.
+
 with System.Soft_Links;
 --  Used for the non-tasking routines (*_NT) that refer to global data. They
 --  are needed here before the tasking run time has been elaborated. used for
Index: s-taprob.adb
===================================================================
--- s-taprob.adb	(revision 211609)
+++ s-taprob.adb	(working copy)
@@ -7,7 +7,7 @@ 
 --                                  B o d y                                 --
 --                                                                          --
 --            Copyright (C) 1991-1994, Florida State University             --
---                     Copyright (C) 1995-2011, AdaCore                     --
+--                     Copyright (C) 1995-2014, AdaCore                     --
 --                                                                          --
 -- 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- --
@@ -38,6 +38,10 @@ 
 with System.Parameters;
 with System.Traces;
 with System.Soft_Links.Tasking;
+with System.Secondary_Stack; pragma Elaborate_All (System.Secondary_Stack);
+pragma Unreferenced (System.Secondary_Stack);
+--  Make sure the body of Secondary_Stack is elaborated before calling
+--  Init_Tasking_Soft_Links.
 
 package body System.Tasking.Protected_Objects is
 
Index: s-solita.adb
===================================================================
--- s-solita.adb	(revision 211609)
+++ s-solita.adb	(working copy)
@@ -6,7 +6,7 @@ 
 --                                                                          --
 --                                 B o d y                                  --
 --                                                                          --
---          Copyright (C) 2004-2013, Free Software Foundation, Inc.         --
+--          Copyright (C) 2004-2014, 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- --
@@ -95,7 +95,11 @@ 
 
    function Get_Sec_Stack_Addr return  Address is
    begin
-      return STPO.Self.Common.Compiler_Data.Sec_Stack_Addr;
+      return Result : constant Address :=
+        STPO.Self.Common.Compiler_Data.Sec_Stack_Addr
+      do
+         pragma Assert (Result /= Null_Address);
+      end return;
    end Get_Sec_Stack_Addr;
 
    function Get_Stack_Info return Stack_Checking.Stack_Access is
@@ -222,6 +226,8 @@ 
          SSL.Set_Sec_Stack_Addr     (SSL.Get_Sec_Stack_Addr_NT);
          SSL.Set_Jmpbuf_Address     (SSL.Get_Jmpbuf_Address_NT);
       end if;
+
+      pragma Assert (Get_Sec_Stack_Addr /= Null_Address);
    end Init_Tasking_Soft_Links;
 
 end System.Soft_Links.Tasking;
Index: s-solita.ads
===================================================================
--- s-solita.ads	(revision 211609)
+++ s-solita.ads	(working copy)
@@ -6,7 +6,7 @@ 
 --                                                                          --
 --                                 S p e c                                  --
 --                                                                          --
---             Copyright (C) 2009, Free Software Foundation, Inc.           --
+--          Copyright (C) 2009-2014, 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- --
@@ -38,6 +38,7 @@ 
 
    procedure Init_Tasking_Soft_Links;
    --  Set the tasking soft links that are common to the full and the
-   --  restricted run times.
+   --  restricted run times. Clients need to make sure the body of
+   --  System.Secondary_Stack is elaborated before calling this.
 
 end System.Soft_Links.Tasking;