gcc.c (init_gcc_specs): New function.

* 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

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

From-SVN: r39408
This commit is contained in:
Mark Mitchell 2001-02-02 17:42:00 +00:00 committed by Mark Mitchell
parent 483b9fd0fe
commit 049f6ec972
7 changed files with 90 additions and 16 deletions

View File

@ -1,3 +1,13 @@
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

View File

@ -1,3 +1,10 @@
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,

View File

@ -61,7 +61,8 @@ C++ c++: cc1plus$(exeext)
.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

View File

@ -1,5 +1,5 @@
/* 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.
@ -82,6 +82,9 @@ lang_specific_driver (in_argc, in_argv, in_added_libraries)
/* 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;
@ -160,6 +163,9 @@ lang_specific_driver (in_argc, in_argv, in_added_libraries)
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;
@ -197,8 +203,14 @@ lang_specific_driver (in_argc, in_argv, in_added_libraries)
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;
@ -258,6 +270,8 @@ lang_specific_driver (in_argc, in_argv, in_added_libraries)
}
if (saw_libc)
arglist[j++] = saw_libc;
if (shared_libgcc)
arglist[j++] = "-shared-libgcc";
arglist[j] = NULL;

View File

@ -268,6 +268,9 @@ static int execute PARAMS ((void));
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 *));
/* Specs are strings containing lines, each of which (if not blank)
is made up of a program name, and arguments separated by spaces.
@ -1252,6 +1255,35 @@ static struct spec_list *extra_specs = (struct spec_list *) 0;
static struct spec_list *specs = (struct spec_list *) 0;
/* 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
@ -1326,15 +1358,16 @@ init_spec ()
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;
}
@ -1342,12 +1375,14 @@ init_spec ()
{
/* 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;
}

View File

@ -3688,11 +3688,16 @@ of these is when the application wishes to throw and catch exceptions
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

View File

@ -1,4 +1,4 @@
# 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
@ -97,6 +97,7 @@ proc g++_include_flags { args } {
}
proc g++_link_flags { args } {
global rootme
global srcdir
global ld_library_path
@ -127,6 +128,7 @@ proc g++_link_flags { args } {
if [file exists "${gccpath}/librx/librx.a"] {
append flags "-L${gccpath}/librx "
}
append ld_library_path ":${rootme}"
} else {
global tool_root_dir;