===================================================================
@@ -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
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.