Rework VXWORKS_LINK_SPEC for shared objects support
authorDouglas B Rupp <rupp@adacore.com>
Thu, 8 Apr 2021 18:03:19 +0000 (11:03 -0700)
committerOlivier Hainque <hainque@adacore.com>
Mon, 13 Dec 2021 18:03:26 +0000 (18:03 +0000)
Split LINK_SPEC as BASE_LINK_SPEC + EXTRA_LINK_SPEC,
with an overridable LINK_OS component that cpu ports may
redefine.

Leverage the latter on powerpc for VxWorks 7, where we incorporate
our specific bits in the linux os configuration as the system compiler
is now very close to a standard linux one.

The split allows supporting shared objects (shared libs and
non-static rtps) on recent versions of VxWorks while retaining
compatibility with older VxWorks targets which could link with
shared libraries but not build them.

2021-12-07  Doug Rupp  <rupp@adacore.com>
    Olivier Hainque  <hainque@adacore.com>

gcc/
* config/vxworks.h (VXWORKS_LINK_OS_SPEC): New spec.
(VXWORKS_BASE_LINK_SPEC): New spec, using the former.
(VXWORKS_EXTRA_LINK_SPEC): New spec for old and new VxWorks.
(VXWORKS_LINK_SPEC): Combo of BASE and EXTRA specs.
* config/rs6000/vxworks.h (VXWORKS_LINK_OS_SPEC): Empty.
(LINK_OS_EXTRA_SPEC32): Use VXWORKS_LINK_SPEC.
(LINK_OS_EXTRA_SPEC64): Likewise.

gcc/config/rs6000/vxworks.h
gcc/config/vxworks.h

index fbe0902..d2d6585 100644 (file)
@@ -252,15 +252,18 @@ along with GCC; see the file COPYING3.  If not see
 #undef DOT_SYMBOLS
 #define DOT_SYMBOLS 0
 
-#undef LINK_OS_VXWORKS_SPEC
-#define LINK_OS_VXWORKS_SPEC \
-  " %{!mrtp:-r} %{mrtp:-q -static} %{!Xbind-lazy:-z now}"
+/* For link specs, we leverage the linux configuration bits through
+   LINK_OS_EXTRA_SPEC32/64 and need to cancel the default %(link_os)
+   expansion in VXWORKS_LINK_SPEC.  */
+
+#undef VXWORKS_LINK_OS_SPEC
+#define VXWORKS_LINK_OS_SPEC ""
 
 #undef LINK_OS_EXTRA_SPEC32
-#define LINK_OS_EXTRA_SPEC32 LINK_OS_VXWORKS_SPEC " " VXWORKS_RELAX_LINK_SPEC
+#define LINK_OS_EXTRA_SPEC32 VXWORKS_LINK_SPEC " " VXWORKS_RELAX_LINK_SPEC
 
 #undef LINK_OS_EXTRA_SPEC64
-#define LINK_OS_EXTRA_SPEC64 LINK_OS_VXWORKS_SPEC
+#define LINK_OS_EXTRA_SPEC64 VXWORKS_LINK_SPEC
 
 /* linux64.h enables this, not supported in vxWorks.  */
 #undef TARGET_FLOAT128_ENABLE_TYPE
index 52d6aa1..88bffc4 100644 (file)
@@ -132,8 +132,7 @@ along with GCC; see the file COPYING3.  If not see
 #define VXWORKS_NET_LIBS_RTP "-lnet -ldsi"
 #endif
 
-#define VXWORKS_BASE_LIBS_RTP \
-  "-lc -lgcc %{!shared:%{!non-static:-lc_internal}}"
+#define VXWORKS_BASE_LIBS_RTP "-lc -lgcc %{!shared:-lc_internal}"
 
 #define VXWORKS_EXTRA_LIBS_RTP
 
@@ -179,15 +178,23 @@ along with GCC; see the file COPYING3.  If not see
                  " TLS_SYM "                                              \
                  --start-group " VXWORKS_LIBS_RTP " --end-group}}"
 
-/* The no-op spec for "-shared" below is present because otherwise GCC
-   will treat it as an unrecognized option.  */
-#undef VXWORKS_LINK_SPEC
-#define VXWORKS_LINK_SPEC                              \
+#if TARGET_VXWORKS7
+#define VXWORKS_EXTRA_LINK_SPEC ""
+#else
+/* Older VxWorks RTPs can only link with shared libs, and
+   need special switches --force-dynamic --export-dynamic. */
+#define VXWORKS_EXTRA_LINK_SPEC                                \
+"%{mrtp:%{!shared:%{non-static:--force-dynamic --export-dynamic}}}"
+#endif
+
+/* A default link_os expansion for RTPs, that cpu ports may override.  */
+#undef VXWORKS_LINK_OS_SPEC
+#define VXWORKS_LINK_OS_SPEC "%(link_os)"
+
+/* The -B and -X switches are for DIAB based linking. */
+#undef VXWORKS_BASE_LINK_SPEC
+#define VXWORKS_BASE_LINK_SPEC                         \
 "%{!mrtp:-r}                                           \
- %{!shared:                                            \
-   %{mrtp:-q %{h*}                                     \
-          %{R*} %{!T*: %(link_start) }                 \
-          %(link_os)}}                                 \
  %{v:-V}                                               \
  %{shared:-shared}                                     \
  %{Bstatic:-Bstatic}                                   \
@@ -195,8 +202,12 @@ along with GCC; see the file COPYING3.  If not see
  %{!Xbind-lazy:-z now}                                 \
  %{Xbind-now:%{Xbind-lazy:                             \
    %e-Xbind-now and -Xbind-lazy are incompatible}}     \
- %{mrtp:%{!shared:%{!non-static:-static}               \
-                 %{non-static:--force-dynamic --export-dynamic}}}"
+ %{mrtp:-q %{!shared:%{!non-static:-static}}            \
+        %{h*} %{R*} %{!T*: %(link_start)}"              \
+        VXWORKS_LINK_OS_SPEC "}"
+
+#undef VXWORKS_LINK_SPEC
+#define VXWORKS_LINK_SPEC VXWORKS_BASE_LINK_SPEC " " VXWORKS_EXTRA_LINK_SPEC
 
 #undef VXWORKS_LIBGCC_SPEC
 #if defined(ENABLE_SHARED_LIBGCC)