public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
* [patch] Tighten VXWORKS_LIBGCC_SPEC wrt libgcc_eh
@ 2022-10-10  8:28 Olivier Hainque
  0 siblings, 0 replies; only message in thread
From: Olivier Hainque @ 2022-10-10  8:28 UTC (permalink / raw)
  To: gcc-patches; +Cc: Olivier Hainque

[-- Attachment #1: Type: text/plain, Size: 1692 bytes --]

Hello,

VxWorks has a custom definition of LIBGCC_SPEC to accommodate
the variety of "modules" a user can build (dkm, sharedlib (-shared),
static rtp, or rtp depending on shared libs (-non-static))

This change reworks that spec to better support configurations with
shared libraries enabled (patch coming) and document the variations.

The change also prepares for a possible dual-eh (dwarf+sjlj) setup,
which we (AdaCore) work on proposing. The impact on this patch is really
minimal and there's no functional impact at all in the interim.

The bulk of the change consists in the introduction of a couple of local
macros that instantiate the link options needed to include libgcc_eh in
the closure, with values depending on the configuration characteristics.

A few comments are added to explain the general idea and each of the
variations. Part of the changes consist in adding -lgcc after -lgcc_eh
to accommodate configurations where libgcc_eh legitimately resort to
libgcc functions on some targets, for example cas synchronisation routines
on aarch64.


We have been using this for a while in house for gcc-11 based toolchains
targetting a range of vxworks7r2 configurations (arm, aarch64, ppc, ppc64,
x86, x86_64, with shared libraries enabled for all the 64bit variants),
as well as for vxworks6.9 on powerpc.

I have verified that gcc-12 based toolchain for arm, ppc and ppc64 behave
as expected and performed a sanity check build for powerpc64-vxworks7r2 on
mainline.

Will commit shortly.

Cheers,

Olivier

2022-10-09  Olivier Hainque  <hainque@adacore.com>

	* config/vxworks (VX_LGCC_EH_SO0, VX_LGCC_EH_SO1): New internal macros.
	(VXWORKS_LIBGCC_SPEC): Use them and document.


[-- Attachment #2: 0001-Tigthen-the-addition-of-lgcc_eh-to-vxworks_libgcc_sp.patch --]
[-- Type: application/octet-stream, Size: 3657 bytes --]

From dce5f64ff7b387ca966a19345939a8b7d0515c91 Mon Sep 17 00:00:00 2001
From: Olivier Hainque <hainque@adacore.com>
Date: Fri, 18 Feb 2022 22:44:53 +0000
Subject: [PATCH 1/2] Tigthen the addition of -lgcc_eh to vxworks_libgcc_spec

This change refines VXWORKS_LIBGCC_SPEC wrt the inclusion
of -lgcc_eh.

Unless the compiler features support for dual sjlj and
table based eh, libgcc_eh.a is available only with multilib
variants for which we build a shared lib (mrtp on VxWorks).

Rework logic to handle absence of libgcc_s
for -mrtp -mcmodel=large, using a conditional expr kind of
spec.

The gthread support in libgcc_eh might resort to libgcc
functions on some targets, e.g. cas synchronisation routines
on aarch64. Arrange to append -lgcc also after -lgcc_eh
in VXWORKS_LIBGCC_SPEC.
---
 gcc/config/vxworks.h | 48 ++++++++++++++++++++++++++++++++++++++++----
 1 file changed, 44 insertions(+), 4 deletions(-)

diff --git a/gcc/config/vxworks.h b/gcc/config/vxworks.h
index 075a45109e8..e7e5ffe9999 100644
--- a/gcc/config/vxworks.h
+++ b/gcc/config/vxworks.h
@@ -224,14 +224,54 @@ extern void vxworks_driver_init (unsigned int *, struct cl_decoded_option **);
 #undef VXWORKS_LINK_SPEC
 #define VXWORKS_LINK_SPEC VXWORKS_BASE_LINK_SPEC " " VXWORKS_EXTRA_LINK_SPEC
 
+/* Control how to include libgcc in the link closure, handling both "shared"
+   and "non-static" in addition to "static-libgcc" when shared lib support is
+   enabled.  */
+
 #undef VXWORKS_LIBGCC_SPEC
+
+/* libgcc_eh control; libgcc_eh.a is available either together with libgcc_s
+   (mrtp and mcmodel!=large when configured with --enable-shared) or when the
+   compiler is specially setup to support dual sjlj/table-based eh.  */
+
+/* VX_LGCC_EH_SO1: The "-lgcc_eh" part we need in situations where we know a
+   shared libgcc is available (ENABLE_SHARED_LIBGCC + mrtp multilib).  */
+
+#define VX_LGCC_EH_SO1 " -lgcc_eh -lgcc"
+/* Extra -lgcc to handle functions from libgcc_eh that refer to symbols
+   exposed by libgcc and not guaranteed to be dragged in before -lgcc_eh
+   appears.  */
+
+/* VX_LGCC_EH_SO0: The "-lgcc_eh" part we need in situations where we know a
+   shared libgcc is not available (!ENABLE_SHARED_LIBGCC or !mrtp multlib).  */
+
+#if !defined(CONFIG_DUAL_EXCEPTIONS)
+
+/* No shared lib && !DUAL_EH -> no libgcc_eh available at all.  */
+#define VX_LGCC_EH_SO0
+
+#else /* CONFIG_DUAL_EXCEPTIONS  */
+
+/* No shared lib but DUAL_EH -> libgcc_eh around and spec handled by the driver
+   depending on ENABLE_SHARED_LIBGCC.  If defined, the driver expects a regular
+   sequence.  Otherwise, the driver is expected to turn -lgcc into -lgcc_eh on
+   its own and just add an instance to address possible cross refs.  */
+
+#if defined(ENABLE_SHARED_LIBGCC)
+#define VX_LGCC_EH_SO0 " -lgcc_eh -lgcc"
+#else
+#define VX_LGCC_EH_SO0 " -lgcc"
+#endif
+
+#endif /* CONFIG_DUAL_EXCEPTIONS  */
+
 #if defined(ENABLE_SHARED_LIBGCC)
 #define VXWORKS_LIBGCC_SPEC                                             \
-"%{!mrtp:-lgcc -lgcc_eh}                                                \
- %{mrtp:%{!static-libgcc:%{shared|non-static:-lgcc_s;:-lgcc -lgcc_eh}}  \
-         %{static-libgcc:-lgcc -lgcc_eh}}"
+  "%{!mrtp|mcmodel=large:-lgcc" VX_LGCC_EH_SO0 ";"			\
+  " :%{!static-libgcc:%{shared|non-static:-lgcc_s;:-lgcc" VX_LGCC_EH_SO1 "}} \
+     %{static-libgcc:-lgcc" VX_LGCC_EH_SO1 "}}"
 #else
-#define VXWORKS_LIBGCC_SPEC "-lgcc"
+#define VXWORKS_LIBGCC_SPEC "-lgcc" VX_LGCC_EH_SO0
 #endif
 
 /* Setup the crtstuff begin/end we might need for dwarf EH registration
-- 
2.25.1


[-- Attachment #3: Type: text/plain, Size: 2 bytes --]




^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2022-10-10  8:28 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-10-10  8:28 [patch] Tighten VXWORKS_LIBGCC_SPEC wrt libgcc_eh Olivier Hainque

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).