diff mbox

[Ada] Static intialization with pragma Linker_Section

Message ID 20170425094312.GA131280@adacore.com
State New
Headers show

Commit Message

Arnaud Charlet April 25, 2017, 9:43 a.m. UTC
This patch is an improvement that causes an array object that has a
pragma Linker_Section with a compile-time-known initial value to be
statically initialized in place in the appropriate section.

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

2017-04-25  Bob Duff  <duff@adacore.com>

	* freeze.adb (Freeze_Object_Declaration): Do
	not Remove_Side_Effects if there is a pragma Linker_Section,
	because in that case we want static initialization in the
	appropriate section.
diff mbox

Patch

Index: freeze.adb
===================================================================
--- freeze.adb	(revision 247155)
+++ freeze.adb	(working copy)
@@ -3197,12 +3197,15 @@ 
 
          --  Similar processing is needed for aspects that may affect
          --  object layout, like Alignment, if there is an initialization
-         --  expression.
+         --  expression. We don't do this if there is a pragma Linker_Section,
+         --  because it would prevent the back end from statically initializing
+         --  the object; we don't want elaboration code in that case.
 
          if Has_Delayed_Aspects (E)
            and then Expander_Active
            and then Is_Array_Type (Etype (E))
            and then Present (Expression (Parent (E)))
+           and then No (Linker_Section_Pragma (E))
          then
             declare
                Decl : constant Node_Id := Parent (E);