+2001-02-02 Mark Mitchell <mark@codesourcery.com>
+
+ * gcc.c (init_gcc_specs): New function. Make -shared-libgcc
+ the default when building a shared object.
+ (init_spec): Use it.
+ * testsuite/lib/g++.exp: Include the directory where libgcc
+ is located to the LD_LIBRARY_PATH list.
+ * inovke.texi (-shared-libgcc): Document the cases in which
+ GCC defaults to using the shared libgcc.
+
2001-02-02 Alexandre Oliva <aoliva@redhat.com>
* config/fp-bit.h (MAX_USI_INT, MAX_SI_INT): Don't assume
+2001-02-02 Mark Mitchell <mark@codesourcery.com>
+
+ * Make-lang.in (g++spec.o): Add DRIVER_DEFINES to the list
+ of macros used when compiling g++spec.c.
+ * g++spec.c (lang_specific_driver): Link with the shared
+ libgcc by default.
+
2001-01-29 Joseph S. Myers <jsm28@cam.ac.uk>
* decl2.c (build_expr_from_tree), lex.c (make_pointer_declarator,
.PHONY: C++ c++
g++spec.o: $(srcdir)/cp/g++spec.c system.h $(GCC_H) $(CONFIG_H)
- $(CC) -c $(ALL_CFLAGS) $(ALL_CPPFLAGS) $(INCLUDES) $(srcdir)/cp/g++spec.c
+ $(CC) -c $(ALL_CFLAGS) $(ALL_CPPFLAGS) $(DRIVER_DEFINES) \
+ $(INCLUDES) $(srcdir)/cp/g++spec.c
$(INTL_TARGETS): $(srcdir)/cp/parse.c
/* Specific flags and argument handling of the C++ front-end.
- Copyright (C) 1996, 1997, 1998, 1999, 2000 Free Software Foundation, Inc.
+ Copyright (C) 1996, 1997, 1998, 1999, 2000, 2001 Free Software Foundation, Inc.
This file is part of GNU CC.
/* By default, we throw on the math library if we have one. */
int need_math = (MATH_LIBRARY[0] != '\0');
+ /* True if we should add -shared-libgcc to the command-line. */
+ int shared_libgcc = 1;
+
/* The total number of arguments with the new stuff. */
int argc;
library = 0;
added -= 2;
}
+ else if (strcmp (argv[i], "-static-libgcc") == 0
+ || strcmp (argv[i], "-static") == 0)
+ shared_libgcc = 0;
else
/* Pass other options through. */
continue;
return;
}
+ /* There's no point adding -shared-libgcc if we don't have a shared
+ libgcc. */
+#ifndef ENABLE_SHARED_LIBGCC
+ shared_libgcc = 0;
+#endif
+
/* Make sure to have room for the trailing NULL argument. */
- num_args = argc + added + need_math + 1;
+ num_args = argc + added + need_math + shared_libgcc + 1;
arglist = (const char **) xmalloc (num_args * sizeof (char *));
i = 0;
}
if (saw_libc)
arglist[j++] = saw_libc;
+ if (shared_libgcc)
+ arglist[j++] = "-shared-libgcc";
arglist[j] = NULL;
static void clear_args PARAMS ((void));
static void fatal_error PARAMS ((int));
static void set_input PARAMS ((const char *));
+static void init_gcc_specs PARAMS ((struct obstack *,
+ const char *,
+ const char *));
\f
/* Specs are strings containing lines, each of which (if not blank)
is made up of a program name, and arguments separated by spaces.
static struct spec_list *specs = (struct spec_list *) 0;
\f
+/* Add appropriate libgcc specs to OBSTACK, taking into account
+ various permutations of -shared-libgcc, -shared, and such. */
+
+static void
+init_gcc_specs (obstack, shared_name, static_name)
+ struct obstack *obstack;
+ const char *shared_name;
+ const char *static_name;
+{
+ char buffer[128];
+
+ /* If we see -shared-libgcc, then use the shared version. */
+ sprintf (buffer, "%%{shared-libgcc:%s}", shared_name);
+ obstack_grow (obstack, buffer, strlen (buffer));
+ /* If we see -static-libgcc, then use the shared version. */
+ sprintf (buffer, "%%{static-libgcc:%s}", static_name);
+ obstack_grow (obstack, buffer, strlen (buffer));
+ /* Otherwise, if we see -shared, then use the shared version. */
+ sprintf (buffer,
+ "%%{!shared-libgcc:%%{!static-libgcc:%%{shared:%s}}}",
+ shared_name);
+ obstack_grow (obstack, buffer, strlen (buffer));
+ /* Otherwise, use the static version. */
+ sprintf (buffer,
+ "%%{!shared-libgcc:%%{!static-libgcc:%%{!shared:%s}}}",
+ static_name);
+ obstack_grow (obstack, buffer, strlen (buffer));
+}
+
/* Initialize the specs lookup routines. */
static void
when given the proper command line arguments. */
while (*p)
{
- const char *r;
if (in_sep && *p == '-' && strncmp (p, "-lgcc", 5) == 0)
{
+ init_gcc_specs (&obstack,
#ifdef NO_SHARED_LIBGCC_MULTILIB
- r = "%{shared-libgcc:-lgcc_s}%{!shared-libgcc:-lgcc}";
+ "-lgcc_s"
#else
- r = "%{shared-libgcc:-lgcc_s%M}%{!shared-libgcc:-lgcc}";
+ "-lgcc_s%M"
#endif
- obstack_grow (&obstack, r, strlen(r));
+ ,
+ "-lgcc");
p += 5;
in_sep = 0;
}
{
/* Ug. We don't know shared library extensions. Hope that
systems that use this form don't do shared libraries. */
+ init_gcc_specs (&obstack,
#ifdef NO_SHARED_LIBGCC_MULTILIB
- r = "%{shared-libgcc:-lgcc_s}%{!shared-libgcc:libgcc.a%s}";
+ "-lgcc_s"
#else
- r = "%{shared-libgcc:-lgcc_s%M}%{!shared-libgcc:libgcc.a%s}";
+ "-lgcc_s%M"
#endif
- obstack_grow (&obstack, r, strlen(r));
+ ,
+ "libgcc.a%s");
p += 10;
in_sep = 0;
}
across different shared libraries. In that case, each of the libraries
as well as the application itself should use the shared @file{libgcc}.
-At present the GCC driver makes no attempt to recognize the situations
-in which the shared @file{libgcc} should be used, and defaults to using
-the static @file{libgcc} always. This will likely change in the future,
-at which time @samp{-static-libgcc} becomes useful as a means for
-overriding GCC's choice.
+Therefore, whenever you specify the @samp{-shared} option, the GCC
+driver automatically adds @samp{-shared-libgcc}, unless you explicitly
+specify @samp{-static-libgcc}. The G++ driver automatically adds
+@samp{-shared-libgcc} when you build a main executable as well because
+for C++ programs that is typically the right thing to do.
+(Exception-handling will not work reliably otherwise.)
+
+However, when linking a main executable written in C, you must
+explicitly say @samp{-shared-libgcc} if you want to use the shared
+@file{libgcc}.
@item -symbolic
Bind references to global symbols when building a shared object. Warn
-# Copyright (C) 1992, 1993, 1994, 1995, 1996, 1997, 2000 Free Software Foundation, Inc.
+# Copyright (C) 1992, 1993, 1994, 1995, 1996, 1997, 2000, 2001 Free Software Foundation, Inc.
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
}
proc g++_link_flags { args } {
+ global rootme
global srcdir
global ld_library_path
if [file exists "${gccpath}/librx/librx.a"] {
append flags "-L${gccpath}/librx "
}
+ append ld_library_path ":${rootme}"
} else {
global tool_root_dir;