aboutsummaryrefslogtreecommitdiff
path: root/gcc
diff options
context:
space:
mode:
authorAlexandre Oliva <aoliva@redhat.com>2002-02-25 13:25:11 +0000
committerAlexandre Oliva <aoliva@gcc.gnu.org>2002-02-25 13:25:11 +0000
commit5c1817565f2c0f669634fab893d03cc83c215a4f (patch)
tree29cb77e79aa665ff931f60954f69d12aa92ba88f /gcc
parentf36bcb2d6bfa52ba2db71bfdff8f247086945fc2 (diff)
downloadgcc-5c1817565f2c0f669634fab893d03cc83c215a4f.zip
gcc-5c1817565f2c0f669634fab893d03cc83c215a4f.tar.gz
gcc-5c1817565f2c0f669634fab893d03cc83c215a4f.tar.bz2
gcc.c (init_gcc_specs): Get -shared-libgcc along with -shared to link with shared_name only.
* gcc.c (init_gcc_specs): Get -shared-libgcc along with -shared to link with shared_name only. * doc/invoke.texi (Link Options): Document new behavior. From-SVN: r50025
Diffstat (limited to 'gcc')
-rw-r--r--gcc/ChangeLog6
-rw-r--r--gcc/doc/invoke.texi29
-rw-r--r--gcc/gcc.c34
3 files changed, 39 insertions, 30 deletions
diff --git a/gcc/ChangeLog b/gcc/ChangeLog
index 2f01984..385826c 100644
--- a/gcc/ChangeLog
+++ b/gcc/ChangeLog
@@ -1,3 +1,9 @@
+2002-02-25 Alexandre Oliva <aoliva@redhat.com>
+
+ * gcc.c (init_gcc_specs): Get -shared-libgcc along with -shared to
+ link with shared_name only.
+ * doc/invoke.texi (Link Options): Document new behavior.
+
2002-02-25 Aldy Hernandez <aldyh@redhat.com>
* c-typeck.c (push_init_level): Handle vectors.
diff --git a/gcc/doc/invoke.texi b/gcc/doc/invoke.texi
index fbc74f4..760c195 100644
--- a/gcc/doc/invoke.texi
+++ b/gcc/doc/invoke.texi
@@ -4428,15 +4428,26 @@ 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}.
-Therefore, whenever you specify the @option{-shared} option, the GCC
-driver automatically adds @option{-shared-libgcc}, unless you explicitly
-specify @option{-static-libgcc}. The G++ driver automatically adds
-@option{-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 @option{-shared-libgcc} if you want to use the shared
+Therefore, the G++ and GCJ drivers automatically add
+@option{-shared-libgcc} whenever you build a shared library or a main
+executable, because C++ and Java programs typically use exceptions, so
+this is the right thing to do.
+
+If, instead, you use the GCC driver to create shared libraries, you may
+find that they will not always be linked with the shared @file{libgcc}.
+If GCC finds, at its configuration time, that you have a GNU linker that
+does not support option @option{--eh-frame-hdr}, it will link the shared
+version of @file{libgcc} into shared libraries by default. Otherwise,
+it will take advantage of the linker and optimize away the linking with
+the shared version of @file{libgcc}, linking with the static version of
+libgcc by default. This allows exceptions to propagate through such
+shared libraries, without incurring relocation costs at library load
+time.
+
+However, if a library or main executable is supposed to throw or catch
+exceptions, you must link it using the G++ or GCJ driver, as appropriate
+for the languages used in the program, or using the option
+@option{-shared-libgcc}, such that it is linked with the shared
@file{libgcc}.
@item -symbolic
diff --git a/gcc/gcc.c b/gcc/gcc.c
index 1fcd8f3..267bfa3 100644
--- a/gcc/gcc.c
+++ b/gcc/gcc.c
@@ -1414,31 +1414,23 @@ init_gcc_specs (obstack, shared_name, static_name, eh_name)
const char *static_name;
const char *eh_name;
{
- char buffer[128];
- const char *p;
+ char *buf;
- /* If we see -shared-libgcc, then use the shared version. */
- sprintf (buffer, "%%{shared-libgcc:%s %s}", shared_name, static_name);
- obstack_grow (obstack, buffer, strlen (buffer));
- /* If we see -static-libgcc, then use the static version. */
- sprintf (buffer, "%%{static-libgcc:%s %s}", static_name, eh_name);
- obstack_grow (obstack, buffer, strlen (buffer));
- /* Otherwise, if we see -shared, then use the shared version
- if using EH registration routines or static version without
- exception handling routines otherwise. */
- p = "%{!shared-libgcc:%{!static-libgcc:%{shared:";
- obstack_grow (obstack, p, strlen (p));
+ buf = concat ("%{!shared:%{!shared-libgcc:", static_name, " ",
+ eh_name, "}%{shared-libgcc:", shared_name, " ",
+ static_name, "}}",
+ "%{shared:%{static-libgcc:", static_name, " ",
+ eh_name, "}%{!static-libgcc:",
#ifdef LINK_EH_SPEC
- sprintf (buffer, "%s}}}", static_name);
+ "%{shared-libgcc:", shared_name,
+ "}%{!shared-libgcc:", static_name, "}",
#else
- sprintf (buffer, "%s}}}", shared_name);
+ shared_name,
#endif
- obstack_grow (obstack, buffer, strlen (buffer));
- /* Otherwise, use the static version. */
- sprintf (buffer,
- "%%{!shared-libgcc:%%{!static-libgcc:%%{!shared:%s %s}}}",
- static_name, eh_name);
- obstack_grow (obstack, buffer, strlen (buffer));
+ "}}", NULL);
+
+ obstack_grow (obstack, buf, strlen (buf));
+ free (buf);
}
#endif /* ENABLE_SHARED_LIBGCC */