[Ada] Pragma Linker_Section in subprogram instantiations in CCG

Message ID 20191213095501.GA14031@adacore.com
State New
Headers show
Series
  • [Ada] Pragma Linker_Section in subprogram instantiations in CCG
Related show

Commit Message

Pierre-Marie de Rodat Dec. 13, 2019, 9:55 a.m.
Propagate attribute Linker_Section_Pragma to the ultimate aliased entity
to facilitate processing it in instantantiations of generic subprograms
in the C backend.

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

2019-12-13  Javier Miranda  <miranda@adacore.com>

gcc/ada/

	* sem_prag.adb (Analyze_Pragma): Propagate the
	Linker_Section_Attribute to the ultimate alias of the subprogram
	to facilitate the C backend processing this attribute.

Patch

--- gcc/ada/sem_prag.adb
+++ gcc/ada/sem_prag.adb
@@ -19188,6 +19188,17 @@  package body Sem_Prag is
                      Set_Linker_Section_Pragma
                        (Entity (Corresponding_Aspect (N)), N);
 
+                     --  Propagate it to its ultimate aliased entity to
+                     --  facilitate the backend processing this attribute
+                     --  in instantiations of generic subprograms.
+
+                     if Present (Alias (Entity (Corresponding_Aspect (N))))
+                     then
+                        Set_Linker_Section_Pragma
+                          (Ultimate_Alias
+                            (Entity (Corresponding_Aspect (N))), N);
+                     end if;
+
                   --  Pragma case, we must climb the homonym chain, but skip
                   --  any for which the linker section is already set.
 
@@ -19196,6 +19207,15 @@  package body Sem_Prag is
                         if No (Linker_Section_Pragma (Ent)) then
                            Set_Linker_Section_Pragma (Ent, N);
 
+                           --  Propagate it to its ultimate aliased entity to
+                           --  facilitate the backend processing this attribute
+                           --  in instantiations of generic subprograms.
+
+                           if Present (Alias (Ent)) then
+                              Set_Linker_Section_Pragma
+                                (Ultimate_Alias (Ent), N);
+                           end if;
+
                            --  A pragma that applies to a Ghost entity becomes
                            --  Ghost for the purposes of legality checks and
                            --  removal of ignored Ghost code.