public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
* [PATCH] G++ static linking on AIX (PR target/26397)
@ 2008-11-05  1:44 David Edelsohn
  2008-11-05 15:47 ` Ian Lance Taylor
  0 siblings, 1 reply; 4+ messages in thread
From: David Edelsohn @ 2008-11-05  1:44 UTC (permalink / raw)
  To: GCC Patches

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

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

* Re: [PATCH] G++ static linking on AIX (PR target/26397)
  2008-11-05  1:44 [PATCH] G++ static linking on AIX (PR target/26397) David Edelsohn
@ 2008-11-05 15:47 ` Ian Lance Taylor
  0 siblings, 0 replies; 4+ messages in thread
From: Ian Lance Taylor @ 2008-11-05 15:47 UTC (permalink / raw)
  To: David Edelsohn; +Cc: GCC Patches

"David Edelsohn" <dje.gcc@gmail.com> writes:

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

This is OK.

Thanks.

Ian

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

* Re: [PATCH] G++ static linking on AIX (PR target/26397)
  2009-06-16 15:31 David Edelsohn
@ 2009-06-16 16:31 ` Ian Lance Taylor
  0 siblings, 0 replies; 4+ messages in thread
From: Ian Lance Taylor @ 2009-06-16 16:31 UTC (permalink / raw)
  To: David Edelsohn; +Cc: gcc-patches

David Edelsohn <dje.gcc@gmail.com> writes:

> cp/
>         * g++-spec.c (LIBSTDCXX_STATIC): Default to NULL.
>         (lang_specific_driver): Always allocate extra argument.
>         Add LIBSTDCXX_STATIC to arglist if defined and linking
>         statically.

This is OK.

Ian

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

* Re: [PATCH] G++ static linking on AIX (PR target/26397)
@ 2009-06-16 15:31 David Edelsohn
  2009-06-16 16:31 ` Ian Lance Taylor
  0 siblings, 1 reply; 4+ messages in thread
From: David Edelsohn @ 2009-06-16 15:31 UTC (permalink / raw)
  To: Ian Lance Taylor; +Cc: gcc-patches

My original patch for this PR incorrectly combined two commandline
arguments into a single arglist entry.

The fundamental problem this patch tries to solve is AIX requires
libsupc++ when linking libstdc++ statically.  I created the
LIBSTDCXX_STATIC macro in the previous iteration of the patch and only
the AIX target uses it.  AIX does not require a different library; it
needs an additional library.

I am not sure about the preferred way to structure this patch: provide
a default NULL value for LIBSTDCXX_STATIC, or conditionally define
LIBSTDCXX_STATIC and wrap the code in an #ifdef.  I also could change
the name to LIBSTDCXX_STATIC_EXTRA, if someone wants it to be even
more informative.

I also need to extend the arglist array unconditionally.  With an
#ifdef, I could make it exactly the right size.

Bootstrapped on powerpc-ibm-aix5.3.0.0.

Okay for mainline?

cp/
        * g++-spec.c (LIBSTDCXX_STATIC): Default to NULL.
        (lang_specific_driver): Always allocate extra argument.
        Add LIBSTDCXX_STATIC to arglist if defined and linking
        statically.

Index: cp/g++spec.c
===================================================================
--- cp/g++spec.c        (revision 148507)
+++ cp/g++spec.c        (working copy)
@@ -45,7 +45,7 @@ along with GCC; see the file COPYING3.
 #define LIBSTDCXX_PROFILE LIBSTDCXX
 #endif
 #ifndef LIBSTDCXX_STATIC
-#define LIBSTDCXX_STATIC LIBSTDCXX
+#define LIBSTDCXX_STATIC NULL
 #endif

 void
@@ -259,8 +259,9 @@ lang_specific_driver (int *in_argc, cons
   shared_libgcc = 0;
 #endif

-  /* Make sure to have room for the trailing NULL argument.  */
-  num_args = argc + added + need_math + shared_libgcc + (library > 0) + 1;
+  /* Make sure to have room for the trailing NULL argument.
+     Add one for shared_libgcc or extra static library.  */
+  num_args = argc + added + need_math + (library > 0) + 2;
   arglist = XNEWVEC (const char *, num_args);

   i = 0;
@@ -318,8 +319,15 @@ lang_specific_driver (int *in_argc, cons
   /* Add `-lstdc++' if we haven't already done so.  */
   if (library > 0)
     {
-      arglist[j] = shared_libgcc == 0 ? LIBSTDCXX_STATIC
-       : saw_profile_flag ? LIBSTDCXX_PROFILE : LIBSTDCXX;
+      arglist[j] = saw_profile_flag ? LIBSTDCXX_PROFILE : LIBSTDCXX;
+      if (arglist[j][0] != '-' || arglist[j][1] == 'l')
+       added_libraries++;
+      j++;
+    }
+  /* Add target-dependent static library, if necessary.  */
+  if (shared_libgcc == 0 && LIBSTDCXX_STATIC != NULL)
+    {
+      arglist[j] = LIBSTDCXX_STATIC;
       if (arglist[j][0] != '-' || arglist[j][1] == 'l')
        added_libraries++;
       j++;

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

end of thread, other threads:[~2009-06-16 16:26 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2008-11-05  1:44 [PATCH] G++ static linking on AIX (PR target/26397) David Edelsohn
2008-11-05 15:47 ` Ian Lance Taylor
2009-06-16 15:31 David Edelsohn
2009-06-16 16:31 ` Ian Lance Taylor

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