This is the mail archive of the gcc-patches@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

[PATCH] Fix -static linking with recent glibcs


Hi!

Latest CVS glibc use _Unwind_Resume and __gcc_personality_v0 in some libc.a
objects. Normally, gcc -static links with:
-lgcc -lgcc_eh -lc -lgcc -lgcc_eh
Now, if nothing in the program itself requires anything from libgcc_eh.a
but some object from libc.a which uses __attribute__((cleanup)) is required
(e.g. big part of libio), unwind-dw2.o etc. are added to the link
only at the last of the 5 above mentioned libraries. But unwind-dw2-glibc.o
needs dl_iterate_phdr among other things, and that comes from libc.a (and
very likely has not been included in the link), so linking fails.
This patch fixes it by using
--start-group -lgcc -lgcc_eh -lc --end-group
when linking -static
(and keeps current
-lgcc -lgcc_eh -lc -lgcc -lgcc_eh for dynamic link, as it is faster).
Bootstrapped/regtested on i386-redhat-linux.
Ok to commit?

2003-09-12  Jakub Jelinek  <jakub@redhat.com>

	* config/linux.h (LINK_GCC_C_SEQUENCE_SPEC): Define.
	* config/alpha/linux.h (LINK_GCC_C_SEQUENCE_SPEC): Define.
	* config/arm/linux-elf.h (LINK_GCC_C_SEQUENCE_SPEC): Define.
	* config/rs6000/linux.h (LINK_GCC_C_SEQUENCE_SPEC): Define.
	* config/rs6000/linux64.h (LINK_GCC_C_SEQUENCE_SPEC): Define.
	* config/sh/linux.h (LINK_GCC_C_SEQUENCE_SPEC): Define.
	* config/sparc/linux.h (LINK_GCC_C_SEQUENCE_SPEC): Define.
	* config/sparc/linux64.h (LINK_GCC_C_SEQUENCE_SPEC): Define.

--- gcc/config/linux.h.jj	2003-07-11 04:26:57.000000000 -0400
+++ gcc/config/linux.h	2003-09-11 18:46:35.000000000 -0400
@@ -1,5 +1,6 @@
 /* Definitions for Linux-based GNU systems with ELF format
-   Copyright (C) 1995, 1996, 1997, 1998, 1999, 2000 Free Software Foundation, Inc.
+   Copyright (C) 1995, 1996, 1997, 1998, 1999, 2000, 2003
+   Free Software Foundation, Inc.
    Contributed by Eric Youngdale.
    Modified for stabs-in-ELF by H.J. Lu (hjl@lucon.org).
 
@@ -103,6 +104,8 @@ Boston, MA 02111-1307, USA.  */
 /* Define this so we can compile MS code for use with WINE.  */
 #define HANDLE_PRAGMA_PACK_PUSH_POP
 
+#define LINK_GCC_C_SEQUENCE_SPEC \
+  "%{static:--start-group} %G %L %{static:--end-group}%{!static:%G}"
 
 /* Determine whether the the entire c99 runtime
    is present in the runtime library.  */
--- gcc/config/alpha/linux.h.jj	2003-07-11 04:26:58.000000000 -0400
+++ gcc/config/alpha/linux.h	2003-09-11 18:45:56.000000000 -0400
@@ -1,6 +1,6 @@
 /* Definitions of target machine for GNU compiler,
    for Alpha Linux-based GNU systems.
-   Copyright (C) 1996, 1997, 1998, 2002 Free Software Foundation, Inc.
+   Copyright (C) 1996, 1997, 1998, 2002, 2003 Free Software Foundation, Inc.
    Contributed by Richard Henderson.
 
 This file is part of GNU CC.
@@ -65,6 +65,9 @@ Boston, MA 02111-1307, USA.  */
 
 #define TARGET_HAS_F_SETLKW
 
+#define LINK_GCC_C_SEQUENCE_SPEC \
+  "%{static:--start-group} %G %L %{static:--end-group}%{!static:%G}"
+
 /* Do code reading to identify a signal frame, and set the frame
    state data appropriately.  See unwind-dw2.c for the structs.  */
 
--- gcc/config/arm/linux-elf.h.jj	2003-06-21 05:09:25.000000000 -0400
+++ gcc/config/arm/linux-elf.h	2003-09-11 18:46:03.000000000 -0400
@@ -1,5 +1,5 @@
 /* Definitions for ARM running Linux-based GNU systems using ELF
-   Copyright (C) 1993, 1994, 1997, 1998, 1999, 2000, 2001, 2002 
+   Copyright (C) 1993, 1994, 1997, 1998, 1999, 2000, 2001, 2002, 2003
    Free Software Foundation, Inc.
    Contributed by Philip Blundell <philb@gnu.org>
 
@@ -127,3 +127,6 @@
 
 #undef  CC1_SPEC
 #define CC1_SPEC "%{profile:-p}"
+
+#define LINK_GCC_C_SEQUENCE_SPEC \
+  "%{static:--start-group} %G %L %{static:--end-group}%{!static:%G}"
--- gcc/config/rs6000/linux.h.jj	2003-06-21 05:09:31.000000000 -0400
+++ gcc/config/rs6000/linux.h	2003-09-11 18:45:03.000000000 -0400
@@ -63,6 +63,9 @@
 #undef	LINK_OS_DEFAULT_SPEC
 #define LINK_OS_DEFAULT_SPEC "%(link_os_linux)"
 
+#define LINK_GCC_C_SEQUENCE_SPEC \
+  "%{static:--start-group} %G %L %{static:--end-group}%{!static:%G}"
+
 #undef  TARGET_VERSION
 #define TARGET_VERSION fprintf (stderr, " (PowerPC GNU/Linux)");
 
--- gcc/config/rs6000/linux64.h.jj	2003-07-16 07:17:33.000000000 -0400
+++ gcc/config/rs6000/linux64.h	2003-09-11 18:43:02.000000000 -0400
@@ -537,6 +537,9 @@ while (0)
 
 #define TARGET_ASM_FILE_END file_end_indicate_exec_stack
 
+#define LINK_GCC_C_SEQUENCE_SPEC \
+  "%{static:--start-group} %G %L %{static:--end-group}%{!static:%G}"
+
 /* Do code reading to identify a signal frame, and set the frame
    state data appropriately.  See unwind-dw2.c for the structs.  */
 
--- gcc/config/sh/linux.h.jj	2003-08-26 10:53:13.000000000 -0400
+++ gcc/config/sh/linux.h	2003-09-11 18:44:29.000000000 -0400
@@ -105,6 +105,9 @@ do { \
 #define ENDFILE_SPEC \
   "%{shared|pie:crtendS.o%s;:crtend.o%s} crtn.o%s"
 
+#define LINK_GCC_C_SEQUENCE_SPEC \
+  "%{static:--start-group} %G %L %{static:--end-group}%{!static:%G}"
+
 /* Output assembler code to STREAM to call the profiler.  */
 
 #undef FUNCTION_PROFILER
--- gcc/config/sparc/linux.h.jj	2003-09-08 02:55:53.000000000 -0400
+++ gcc/config/sparc/linux.h	2003-09-11 18:46:20.000000000 -0400
@@ -1,5 +1,6 @@
 /* Definitions for SPARC running Linux-based GNU systems with ELF.
-   Copyright (C) 1996, 1997, 1998, 1999, 2000, 2002 Free Software Foundation, Inc.
+   Copyright (C) 1996, 1997, 1998, 1999, 2000, 2002, 2003
+   Free Software Foundation, Inc.
    Contributed by Eddie C. Dost (ecd@skynet.be)
 
 This file is part of GCC.
@@ -248,6 +249,9 @@ do {									\
 
 #define TARGET_ASM_FILE_END file_end_indicate_exec_stack
 
+#define LINK_GCC_C_SEQUENCE_SPEC \
+  "%{static:--start-group} %G %L %{static:--end-group}%{!static:%G}"
+
 /* Do code reading to identify a signal frame, and set the frame
    state data appropriately.  See unwind-dw2.c for the structs.  */
 
--- gcc/config/sparc/linux64.h.jj	2003-09-08 02:55:53.000000000 -0400
+++ gcc/config/sparc/linux64.h	2003-09-11 18:46:28.000000000 -0400
@@ -1,5 +1,5 @@
 /* Definitions for 64-bit SPARC running Linux-based GNU systems with ELF.
-   Copyright 1996, 1997, 1998, 2000, 2002 Free Software Foundation, Inc.
+   Copyright 1996, 1997, 1998, 2000, 2002, 2003 Free Software Foundation, Inc.
    Contributed by David S. Miller (davem@caip.rutgers.edu)
 
 This file is part of GCC.
@@ -331,6 +331,9 @@ do {									\
 
 #define TARGET_ASM_FILE_END file_end_indicate_exec_stack
 
+#define LINK_GCC_C_SEQUENCE_SPEC \
+  "%{static:--start-group} %G %L %{static:--end-group}%{!static:%G}"
+
 /* Do code reading to identify a signal frame, and set the frame
    state data appropriately.  See unwind-dw2.c for the structs.  */
 

	Jakub


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]