This is the mail archive of the
gcc-patches@gcc.gnu.org
mailing list for the GCC project.
[PATCH] G++ static linking on AIX (PR target/26397)
- From: "David Edelsohn" <dje dot gcc at gmail dot com>
- To: "GCC Patches" <gcc-patches at gcc dot gnu dot org>
- Date: Tue, 4 Nov 2008 20:43:51 -0500
- Subject: [PATCH] G++ static linking on AIX (PR target/26397)
AIX permits static linking against a shared library (without the benefits
of granularity of a normal archive of object files). When building
libstdc++, some functions are omitted from the shared object that
are included in the static archive. When linking against shared
libraries, these functions normally are provided by libgcc_s.so.
The combination of -static-libgcc and the libstdc++ shared
library encounter problems on AIX because neither provides
the missing symbols.
On AIX one needs to add libsupc++ when linking statically to
provide the additional symbols for exception handling -- specifically
to rethrow exceptions across library boundaries.
This patch adds a LIBSTDCXX_STATIC macro to cp/g++spec.c
that defaults to the normal "-lstdc++" but is overridden on AIX.
The new macro is used when G++ is invoked with -static or
-static-libgcc.
Okay?
Thanks, David
PR target/26397
* g++spec.c (LIBSTDCXX_STATIC): New.
(lang_spec_driver): Use LIBSTDCXX_STATIC when not shared_libgcc.
* config/rs6000/aix.h (LIBSTDCXX_STATIC): Define.
Index: cp/g++spec.c
===================================================================
--- cp/g++spec.c (revision 141264)
+++ cp/g++spec.c (working copy)
@@ -44,6 +44,9 @@
#ifndef LIBSTDCXX_PROFILE
#define LIBSTDCXX_PROFILE LIBSTDCXX
#endif
+#ifndef LIBSTDCXX_STATIC
+#define LIBSTDCXX_STATIC LIBSTDCXX
+#endif
void
lang_specific_driver (int *in_argc, const char *const **in_argv,
@@ -315,7 +318,8 @@
/* Add `-lstdc++' if we haven't already done so. */
if (library > 0)
{
- arglist[j] = saw_profile_flag ? LIBSTDCXX_PROFILE : LIBSTDCXX;
+ arglist[j] = shared_libgcc == 0 ? LIBSTDCXX_STATIC
+ : saw_profile_flag ? LIBSTDCXX_PROFILE : LIBSTDCXX;
if (arglist[j][0] != '-' || arglist[j][1] == 'l')
added_libraries++;
j++;
Index: config/rs6000/aix.h
===================================================================
--- config/rs6000/aix.h (revision 141264)
+++ config/rs6000/aix.h (working copy)
@@ -155,6 +155,9 @@
#define LIB_SPEC "%{pg:-L/lib/profiled -L/usr/lib/profiled}\
%{p:-L/lib/profiled -L/usr/lib/profiled} %{!shared:%{g*:-lg}} -lc"
+/* Static linking with shared libstdc++ requires libsupc++ as well. */
+#define LIBSTDCXX_STATIC "-lstdc++ -lsupc++"
+
/* This now supports a natural alignment mode. */
/* AIX word-aligns FP doubles but doubleword-aligns 64-bit ints. */
#define ADJUST_FIELD_ALIGN(FIELD, COMPUTED) \