From 0e21ccadb9bfd744367733ba04f2e4c955cdf7d3 Mon Sep 17 00:00:00 2001 From: Iain Sandoe Date: Fri, 6 Sep 2019 16:08:08 +0000 Subject: [PATCH] [Ada] Push -shared-libgcc where needed. MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit 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. 2019-09-06 Iain Sandoe Backport from mainline. 2019-06-30 Iain Sandoe * gnatlink.adb (Link_Step): 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. From-SVN: r275470 --- gcc/ada/ChangeLog | 10 ++++++++++ gcc/ada/gnatlink.adb | 30 +++++++++++++++++++++++++++++- 2 files changed, 39 insertions(+), 1 deletion(-) diff --git a/gcc/ada/ChangeLog b/gcc/ada/ChangeLog index cfb613d69eb6..2733483ab53d 100644 --- a/gcc/ada/ChangeLog +++ b/gcc/ada/ChangeLog @@ -1,3 +1,13 @@ +2019-09-06 Iain Sandoe + + Backport from mainline. + 2019-06-30 Iain Sandoe + + * gnatlink.adb (Link_Step): 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. + 2019-06-29 Eric Botcazou * gcc-interface/trans.c (mark_visited_r): Set TYPE_SIZES_GIMPLIFIED on diff --git a/gcc/ada/gnatlink.adb b/gcc/ada/gnatlink.adb index 073c2c953157..a2bfda806308 100644 --- a/gcc/ada/gnatlink.adb +++ b/gcc/ada/gnatlink.adb @@ -1888,6 +1888,7 @@ begin Clean_Link_Option_Set : declare J : Natural; Shared_Libgcc_Seen : Boolean := False; + Static_Libgcc_Seen : Boolean := False; begin J := Linker_Options.First; @@ -1909,7 +1910,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 @@ -1923,6 +1924,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. @@ -1954,14 +1969,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; -- 2.47.2