This is the mail archive of the
gcc-patches@gcc.gnu.org
mailing list for the GCC project.
Re: [PATCH] G++ static linking on AIX (PR target/26397)
- From: David Edelsohn <dje dot gcc at gmail dot com>
- To: Ian Lance Taylor <iant at google dot com>
- Cc: gcc-patches <gcc-patches at gcc dot gnu dot org>
- Date: Tue, 16 Jun 2009 11:09:45 -0400
- Subject: Re: [PATCH] G++ static linking on AIX (PR target/26397)
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++;