diff mbox series

[Ada] Push -shared-libgcc where needed.

Message ID 00921F60-CCC4-451A-BF8F-830F21747EE4@sandoe.co.uk
State New
Headers show
Series [Ada] Push -shared-libgcc where needed. | expand

Commit Message

Iain Sandoe June 30, 2019, 9:22 a.m. UTC
Hi Eric,

Gnatlink has code that checks for duplicate '-shared-libgcc’ switches (but not
duplicate ‘static-libgcc’) and also pushes ’static-libgcc' onto the link line for
targets that default to static linking, provided '-shared-libgcc' is not present.

For targets that should use a shared libgcc we need the same process to be
applied (in inverse), in the event that they do not default to providing the
shared flag implicitly***.

So this adds the complementary set of tests for the shared case and pushes
the shared flag as needed.  As a minor tidy-up there’s no need push duplicates
of the libgcc switch onto the link line when one has already been seen (given by
the user).

The patch does not alter any of the platform defaults for static/shared libgcc,
but it ensures that the intent of the link is explicit.

OK for trunk?
thanks
Iain

*** I have patches in progress to resolve the long-standing unwinder issues
on Darwin, and one consequence of those will be to make the libgcc linkage
default to "static" unless -f{,objc-}exceptions is present (or it is overidden with
the shared flag).  Once that tidy-up is complete, then it will be possible to switch
all Darwin >= 10 (10.6) to the same defaults as Linux (since the unwinder is in
libSystem not libgcc_s). 

===

gcc/ada/

2019-06-30  Iain Sandoe  <iain@sandoe.co.uk>

	* gnatlink.adb (Link_Step): Remove duplicate -static-libgcc switches.
	Push -shared-libgcc explicitly, when it is the target default (unless overidden
	by the static flag).
	When the user has put an instance of shared/static-libgcc do not push
	a duplicate of this.

Comments

Eric Botcazou June 30, 2019, 9:54 a.m. UTC | #1
> 2019-06-30  Iain Sandoe  <iain@sandoe.co.uk>
> 
> 	* gnatlink.adb (Link_Step): Remove duplicate -static-libgcc switches.
> 	Push -shared-libgcc explicitly, when it is the target default (unless
> overidden by the static flag).
> 	When the user has put an instance of shared/static-libgcc do not push
> 	a duplicate of this.

OK for mainline, thanks.
Iain Sandoe Aug. 4, 2019, 8:59 a.m. UTC | #2
Hi Eric,

> On 30 Jun 2019, at 10:54, Eric Botcazou <ebotcazou@adacore.com> wrote:
> 
>> 2019-06-30  Iain Sandoe  <iain@sandoe.co.uk>
>> 
>> 	* gnatlink.adb (Link_Step): Remove duplicate -static-libgcc switches.
>> 	Push -shared-libgcc explicitly, when it is the target default (unless
>> overidden by the static flag).
>> 	When the user has put an instance of shared/static-libgcc do not push
>> 	a duplicate of this.
> 
> OK for mainline, thanks.

This patch has now been on mainline for some time without any apparent issue,
the problem is also present on the open branches, may I backport it?

thanks
Iain
Eric Botcazou Aug. 4, 2019, 8:42 p.m. UTC | #3
> This patch has now been on mainline for some time without any apparent
> issue, the problem is also present on the open branches, may I backport it?

OK, thanks.
Iain Sandoe Aug. 5, 2019, 8:14 a.m. UTC | #4
> On 4 Aug 2019, at 21:42, Eric Botcazou <ebotcazou@adacore.com> wrote:
> 
>> This patch has now been on mainline for some time without any apparent
>> issue, the problem is also present on the open branches, may I backport it?
> 
> OK, thanks.

Done for 9.2.
Iain
diff mbox series

Patch

diff --git a/gcc/ada/gnatlink.adb b/gcc/ada/gnatlink.adb
index e8a1b92..5e5ede0 100644
--- a/gcc/ada/gnatlink.adb
+++ b/gcc/ada/gnatlink.adb
@@ -1884,6 +1884,7 @@  begin
       Clean_Link_Option_Set : declare
          J                  : Natural;
          Shared_Libgcc_Seen : Boolean := False;
+         Static_Libgcc_Seen : Boolean := False;
 
       begin
          J := Linker_Options.First;
@@ -1905,7 +1906,7 @@  begin
                end if;
             end if;
 
-            --  Remove duplicate -shared-libgcc switch
+            --  Remove duplicate -shared-libgcc switches
 
             if Linker_Options.Table (J).all = Shared_Libgcc_String then
                if Shared_Libgcc_Seen then
@@ -1919,6 +1920,20 @@  begin
                end if;
             end if;
 
+            --  Remove duplicate -static-libgcc switches
+
+            if Linker_Options.Table (J).all = Static_Libgcc_String then
+               if Static_Libgcc_Seen then
+                  Linker_Options.Table (J .. Linker_Options.Last - 1) :=
+                    Linker_Options.Table (J + 1 .. Linker_Options.Last);
+                  Linker_Options.Decrement_Last;
+                  Num_Args := Num_Args - 1;
+
+               else
+                  Static_Libgcc_Seen := True;
+               end if;
+            end if;
+
             --  Here we just check for a canonical form that matches the
             --  pragma Linker_Options set in the NT runtime.
 
@@ -1950,14 +1965,27 @@  begin
             --  libgcc, if gcc is not called with -shared-libgcc, call it
             --  with -static-libgcc, as there are some platforms where one
             --  of these two switches is compulsory to link.
+            --  Don't push extra switches if we already saw one.
 
             if Shared_Libgcc_Default = 'T'
               and then not Shared_Libgcc_Seen
+              and then not Static_Libgcc_Seen
             then
                Linker_Options.Increment_Last;
                Linker_Options.Table (Linker_Options.Last) := Static_Libgcc;
                Num_Args := Num_Args + 1;
             end if;
+
+            --  Likewise, the reverse.
+
+            if Shared_Libgcc_Default = 'H'
+              and then not Static_Libgcc_Seen
+              and then not Shared_Libgcc_Seen
+            then
+               Linker_Options.Increment_Last;
+               Linker_Options.Table (Linker_Options.Last) := Shared_Libgcc;
+               Num_Args := Num_Args + 1;
+            end if;
          end if;
       end Clean_Link_Option_Set;