public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
* [PATCH] Ada,Darwin: Do not link libgcc statically on Darwin [PR108202].
@ 2022-12-24 19:00 Iain Sandoe
  2022-12-30  8:55 ` [PATCH] Ada, Darwin: " Iain Sandoe
  0 siblings, 1 reply; 3+ messages in thread
From: Iain Sandoe @ 2022-12-24 19:00 UTC (permalink / raw)
  To: gcc-patches; +Cc: charlet

Tested on i686, x86-64 darwin, x86_64-linux (with a 32b multilib).
OK for trunk?
Iain

--- 8< ---

Normally, GCC executables are built with -static-libstdc++ -static-libgcc
on Darwin.  This is fine in most cases, because GCC executables typically
do not use exceptions.   However gnat1 does use exceptions and also pulls
in system libraries that are linked against the installed shared libgcc
which contains the system unwinder.  This means that gnat1 effectively has
two unwinder instances (which does not work reliably since the unwinders
have global state).

A recent change in the initialization of FDEs has made this a hard error
now on Darwin versions with libgcc installed in /usr/lib (gnat1 now hangs
when an exception is thrown).

The solution is to link libgcc dynamically, picking up the installed
system version.  To do this we strip -static-libgcc from the link flags.

	PR ada/108202

gcc/ada/ChangeLog:

	* gcc-interface/Make-lang.in (GCC_LINKERFLAGS, GCC_LDFLAGS):
	Versions of ALL_LINKERFLAGS, LDFLAGS with -Werror and
	-static-libgcc filtered out for Darwin (-Werror only for other
	hosts).
---
 gcc/ada/gcc-interface/Make-lang.in | 14 ++++++++++++--
 1 file changed, 12 insertions(+), 2 deletions(-)

diff --git a/gcc/ada/gcc-interface/Make-lang.in b/gcc/ada/gcc-interface/Make-lang.in
index 2acd195017e..64273c3bdb4 100644
--- a/gcc/ada/gcc-interface/Make-lang.in
+++ b/gcc/ada/gcc-interface/Make-lang.in
@@ -261,10 +261,20 @@ else
 endif
 
 # Strip -Werror during linking for the LTO bootstrap
+
+ifneq ($(findstring darwin,$(host)),)
+# gnat1 uses exceptions which is incompatible with statically-linked libgcc
+# on Darwin, since gnat1 also pulls in libraries linked with the system
+# unwinder.
+GCC_LINKERFLAGS = $(filter-out -Werror -static-libgcc, $(ALL_LINKERFLAGS))
+GCC_LDFLAGS = $(filter-out -static-libgcc, $(LDFLAGS))
+else
 GCC_LINKERFLAGS = $(filter-out -Werror, $(ALL_LINKERFLAGS))
+GCC_LDFLAGS = $(LDFLAGS)
+endif
 
-GCC_LINK=$(LINKER) $(GCC_LINKERFLAGS) $(LDFLAGS)
-GCC_LLINK=$(LLINKER) $(GCC_LINKERFLAGS) $(LDFLAGS)
+GCC_LINK=$(LINKER) $(GCC_LINKERFLAGS) $(GCC_LDFLAGS)
+GCC_LLINK=$(LLINKER) $(GCC_LINKERFLAGS) $(GCC_LDFLAGS)
 
 # Lists of files for various purposes.
 
-- 
2.37.1 (Apple Git-137.1)


^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [PATCH] Ada, Darwin: Do not link libgcc statically on Darwin [PR108202].
  2022-12-24 19:00 [PATCH] Ada,Darwin: Do not link libgcc statically on Darwin [PR108202] Iain Sandoe
@ 2022-12-30  8:55 ` Iain Sandoe
  2023-01-02  8:42   ` Arnaud Charlet
  0 siblings, 1 reply; 3+ messages in thread
From: Iain Sandoe @ 2022-12-30  8:55 UTC (permalink / raw)
  To: GCC Patches; +Cc: Arnaud Charlet

I would like to revise this patch to be more conservative (only applying to Darwin 8 and 9).

> On 24 Dec 2022, at 19:00, Iain Sandoe via Gcc-patches <gcc-patches@gcc.gnu.org> wrote:
> 
> Tested on i686, x86-64 darwin, x86_64-linux (with a 32b multilib).
> OK for trunk?
> Iain

revised:

[PATCH] Ada,Darwin: Do not link libgcc statically on Darwin 8 and 9  [PR108202].

Normally, GCC executables are built with -static-libstdc++ -static-libgcc
on Darwin.  This is fine in most cases, because GCC executables typically
do not use exceptions.   However gnat1 does use exceptions and also pulls
in system libraries that are linked against the installed shared libgcc
which contains the system unwinder.  This means that gnat1 effectively has
two unwinder instances (which does not work reliably since the unwinders
have global state).

A recent change in the initialization of FDEs has made this a hard error
now on Darwin versions (8 and 9) with libgcc installed in /usr/lib (gnat1
now hangs when an exception is thrown).

The solution is to link libgcc dynamically, picking up the installed
system version.  To do this we strip -static-libgcc from the link flags.

	PR ada/108202

gcc/ada/ChangeLog:

	* gcc-interface/Make-lang.in (GCC_LINKERFLAGS, GCC_LDFLAGS):
	Versions of ALL_LINKERFLAGS, LDFLAGS with -Werror and
	-static-libgcc filtered out for Darwin8 and 9 (-Werror is filtered
	out for other hosts).
---
 gcc/ada/gcc-interface/Make-lang.in | 13 +++++++++++--
 1 file changed, 11 insertions(+), 2 deletions(-)

diff --git a/gcc/ada/gcc-interface/Make-lang.in b/gcc/ada/gcc-interface/Make-lang.in
index 2acd195017e..c81daae9c4a 100644
--- a/gcc/ada/gcc-interface/Make-lang.in
+++ b/gcc/ada/gcc-interface/Make-lang.in
@@ -260,11 +260,20 @@ else
   endif
 endif
 
+ifneq ($(filter darwin9% darwin8%,$(host_os)),)
+# gnat1 uses exceptions which is incompatible with statically-linked libgcc
+# on Darwin8 and 9, since gnat1 also pulls in libraries linked with the system
+# unwinder.
+GCC_LINKERFLAGS = $(filter-out -Werror -static-libgcc, $(ALL_LINKERFLAGS))
+GCC_LDFLAGS = $(filter-out -static-libgcc, $(LDFLAGS))
+else
 # Strip -Werror during linking for the LTO bootstrap
 GCC_LINKERFLAGS = $(filter-out -Werror, $(ALL_LINKERFLAGS))
+GCC_LDFLAGS = $(LDFLAGS)
+endif
 
-GCC_LINK=$(LINKER) $(GCC_LINKERFLAGS) $(LDFLAGS)
-GCC_LLINK=$(LLINKER) $(GCC_LINKERFLAGS) $(LDFLAGS)
+GCC_LINK=$(LINKER) $(GCC_LINKERFLAGS) $(GCC_LDFLAGS)
+GCC_LLINK=$(LLINKER) $(GCC_LINKERFLAGS) $(GCC_LDFLAGS)
 
 # Lists of files for various purposes.
 
-- 
2.37.1 (Apple Git-137.1)


^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [PATCH] Ada, Darwin: Do not link libgcc statically on Darwin [PR108202].
  2022-12-30  8:55 ` [PATCH] Ada, Darwin: " Iain Sandoe
@ 2023-01-02  8:42   ` Arnaud Charlet
  0 siblings, 0 replies; 3+ messages in thread
From: Arnaud Charlet @ 2023-01-02  8:42 UTC (permalink / raw)
  To: Iain Sandoe; +Cc: GCC Patches, Arnaud Charlet

> I would like to revise this patch to be more conservative (only applying to Darwin 8 and 9).

This is OK, thanks (and Happy New Year!)

> > On 24 Dec 2022, at 19:00, Iain Sandoe via Gcc-patches <gcc-patches@gcc.gnu.org> wrote:
> > 
> > Tested on i686, x86-64 darwin, x86_64-linux (with a 32b multilib).
> > OK for trunk?
> > Iain
> 
> revised:
> 
> [PATCH] Ada,Darwin: Do not link libgcc statically on Darwin 8 and 9  [PR108202].
> 
> Normally, GCC executables are built with -static-libstdc++ -static-libgcc
> on Darwin.  This is fine in most cases, because GCC executables typically
> do not use exceptions.   However gnat1 does use exceptions and also pulls
> in system libraries that are linked against the installed shared libgcc
> which contains the system unwinder.  This means that gnat1 effectively has
> two unwinder instances (which does not work reliably since the unwinders
> have global state).
> 
> A recent change in the initialization of FDEs has made this a hard error
> now on Darwin versions (8 and 9) with libgcc installed in /usr/lib (gnat1
> now hangs when an exception is thrown).
> 
> The solution is to link libgcc dynamically, picking up the installed
> system version.  To do this we strip -static-libgcc from the link flags.
> 
> 	PR ada/108202
> 
> gcc/ada/ChangeLog:
> 
> 	* gcc-interface/Make-lang.in (GCC_LINKERFLAGS, GCC_LDFLAGS):
> 	Versions of ALL_LINKERFLAGS, LDFLAGS with -Werror and
> 	-static-libgcc filtered out for Darwin8 and 9 (-Werror is filtered
> 	out for other hosts).

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2023-01-02  8:42 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-12-24 19:00 [PATCH] Ada,Darwin: Do not link libgcc statically on Darwin [PR108202] Iain Sandoe
2022-12-30  8:55 ` [PATCH] Ada, Darwin: " Iain Sandoe
2023-01-02  8:42   ` Arnaud Charlet

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).