[Ada] Give error message if duplicate Linker_Section given

Arnaud Charlet charlet@adacore.com
Thu Nov 20 11:36:00 GMT 2014


Like other similar pragmas, we should disallow duplicate pragma or
aspect Linker_Section for non-overloadable entities (for the case
of overloading, the pragma only applies to previous entities which
do not have such a pragma).

The following should compile with the given error:

     1. package Pkg1 is
     2.    Var_Dyn : natural;
     3.    pragma Linker_Section (Var_Dyn, ".data_dyn");
     4.    pragma Linker_Section (Var_Dyn, ".data_dyn1");
                                  |
        >>> Linker_Section already specified for "Var_Dyn" at line 3

     5. end Pkg1;

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

2014-11-20  Robert Dewar  <dewar@adacore.com>

	* sem_prag.adb (Analyze_Pragma, case Linker_Section): Detect
	duplicate Linker_Section.

-------------- next part --------------
Index: sem_prag.adb
===================================================================
--- sem_prag.adb	(revision 217838)
+++ sem_prag.adb	(working copy)
@@ -16380,6 +16380,7 @@
          when Pragma_Linker_Section => Linker_Section : declare
             Arg : Node_Id;
             Ent : Entity_Id;
+            LPE : Node_Id;
 
          begin
             GNAT_Pragma;
@@ -16398,9 +16399,18 @@
             case Ekind (Ent) is
 
                --  Objects (constants and variables) and types. For these cases
-               --  all we need to do is to set the Linker_Section_pragma field.
+               --  all we need to do is to set the Linker_Section_pragma field,
+               --  checking that we do not have a duplicate.
 
                when E_Constant | E_Variable | Type_Kind =>
+                  LPE := Linker_Section_Pragma (Ent);
+
+                  if Present (LPE) then
+                     Error_Msg_Sloc := Sloc (LPE);
+                     Error_Msg_NE
+                       ("Linker_Section already specified for &#", Arg1, Ent);
+                  end if;
+
                   Set_Linker_Section_Pragma (Ent, N);
 
                --  Subprograms


More information about the Gcc-patches mailing list