Why link C with crtstuff? [patch]

H.J. Lu hjl@lucon.org
Sun Apr 26 00:19:00 GMT 1998


> 
> Hello
> 
> There is a feature of egcs (and gcc 2.8.x) that I don't like.
> It links everything with crtbegin[S].o/crtend[S].o which in turn
> reference symbols from frame.o. 
> This is not good because
> 
> 1. The executable size increases (+5Kb on my i586-pc-linux-gnulibc1).
> crtstuff itself is small, but frame.o is large.

It should be easy to fix.

> 
> 2. It also goes to shared libraries. Imagine one has a library
> libxxx.so and builds a program with -lxxx. The linker gets crtbegin.o
> and -lxxx before -lgcc, and what is referenced by crtbegin.o is found
> in libxxx.so - frame.o is there because of crtbeginS.o!
> Now what if the library was built with an older version of egcs/gcc,
> and things has been changed since that? Even worse, the binary now
> depends on something in libxxx about which only gcc knows.
> So future versions of gcc will have to include the same stuff,
> with the same interface, into shared libs. Otherwise recompiling
> the library will break programs depending on it.
> 
> On the other hand, crtstuff is a C++ related thing
> and is not needed for pure C code (AFAIK).

That is not true. crtstuff is used by C++, but not exclusively.
> 
> So why not link it just like libstdc++, i.e. only by g++ driver?
> Let good old C live in a world untouched by dirty hands of C++!
> 
> Please look at the below patch against egcs-1.0.2
> (quick and a bit illogical, but works for me at least).
> It enables %{x...} tests in specs and uses them in linux
> startfile/endfile to get rid of crt*.o when not using c++.
> 

The patch is wrong. Please try this patch.

BTW, Jim, I cannot get__ attribute__((weak)) to work on extern.


H.J.
----
Index: crtstuff.c
===================================================================
RCS file: /home/work/cvs/gnu/egcs/gcc/crtstuff.c,v
retrieving revision 1.1.1.9
diff -u -r1.1.1.9 crtstuff.c
--- crtstuff.c	1998/04/05 19:07:15	1.1.1.9
+++ crtstuff.c	1998/04/22 15:30:00
@@ -80,6 +80,11 @@
 #endif
 #if !defined (EH_FRAME_SECTION_ASM_OP) && defined (DWARF2_UNWIND_INFO) && defined(ASM_OUTPUT_SECTION_NAME)
 #define EH_FRAME_SECTION_ASM_OP	".section\t.eh_frame,\"aw\""
+
+#ifdef HANDLE_SYSV_PRAGMA
+#pragma weak __register_frame_info
+#pragma weak __deregister_frame_info
+#endif
 #endif
 
 #ifdef OBJECT_FORMAT_ELF
@@ -142,8 +147,11 @@
     }
 
 #ifdef EH_FRAME_SECTION_ASM_OP
-  __deregister_frame_info (__EH_FRAME_BEGIN__);
+#ifdef HANDLE_SYSV_PRAGMA
+  if (__deregister_frame_info)
 #endif
+    __deregister_frame_info (__EH_FRAME_BEGIN__);
+#endif
   completed = 1;
 }
 
@@ -170,7 +178,10 @@
 frame_dummy ()
 {
   static struct object object;
-  __register_frame_info (__EH_FRAME_BEGIN__, &object);
+#ifdef HANDLE_SYSV_PRAGMA
+  if (__register_frame_info)
+#endif
+    __register_frame_info (__EH_FRAME_BEGIN__, &object);
 }
 
 static void
@@ -254,8 +265,11 @@
     (*p) ();
 
 #ifdef EH_FRAME_SECTION_ASM_OP
-  __deregister_frame_info (__EH_FRAME_BEGIN__);
+#ifdef HANDLE_SYSV_PRAGMA
+  if (__deregister_frame_info)
 #endif
+    __deregister_frame_info (__EH_FRAME_BEGIN__);
+#endif
 }
 
 #ifdef EH_FRAME_SECTION_ASM_OP
@@ -266,7 +280,10 @@
 __frame_dummy ()
 {
   static struct object object;
-  __register_frame_info (__EH_FRAME_BEGIN__, &object);
+#ifdef HANDLE_SYSV_PRAGMA
+  if (__register_frame_info)
+#endif
+    __register_frame_info (__EH_FRAME_BEGIN__, &object);
 }
 #endif
 #endif



More information about the Gcc mailing list