This is the mail archive of the libc-hacker@sourceware.cygnus.com mailing list for the glibc project.


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

initfini rewrite


So for no good reason, I did in fact get around to hacking a new way to
build crti.o/crtn.o as I suggested earlier.  This builds, but I haven't
fully tested it; I'm sure it's got problems, but there it is.  My patch
doesn't actually remove defs.awk as the log entry claims.  I used cvs diff,
so shoot me.  I'm going to bed now.


1998-06-29  Roland McGrath  <roland@baalperazim.frob.com>

	* csu/initfini.c: Rewritten with simpler magic to produce an object
	file to be postprocessed, instead of an assembly file to be
	postprocessed.
	* csu/Makefile (initfini.o and associated rules): Rewritten.
	* csu/defs.awk: Removed.
	* configure.in: Check for tools LD and OBJCOPY.
	* config.make.in (LD, OBJCOPY): New vars, substituted.


Index: csu/initfini.c
===================================================================
RCS file: /egcs/carton/cvsfiles/libc/csu/initfini.c,v
retrieving revision 1.23
diff -u -r1.23 initfini.c
--- initfini.c	1997/08/04 13:29:21	1.23
+++ initfini.c	1998/06/29 09:58:51
@@ -1,5 +1,5 @@
 /* Special .init and .fini section support.
-   Copyright (C) 1995, 1996, 1997 Free Software Foundation, Inc.
+   Copyright (C) 1995, 1996, 1997, 1998 Free Software Foundation, Inc.
    This file is part of the GNU C Library.
 
    The GNU C Library is free software; you can redistribute it
@@ -40,29 +40,9 @@
 
 /* We use embedded asm for .section unconditionally, as this makes it
    easier to insert the necessary directives into crtn.S. */
-#define SECTION(x) asm (".section " x );
+#define SECTION(x) asm (".section " x ",\"ax\",@progbits")
 
-/* Embed an #include to pull in the alignment and .end directives. */
-asm ("\n#include \"defs.h\"");
-
-/* The initial common code ends here. */
-asm ("\n/*@HEADER_ENDS*/");
-
-/* To determine whether we need .end and .align: */
-asm ("\n/*@TESTS_BEGIN*/");
-void
-dummy (void (*foo) (void))
-{
-  if (foo)
-    (*foo) ();
-}
-asm ("\n/*@TESTS_END*/");
-
-/* The beginning of _init:  */
-asm ("\n/*@_init_PROLOG_BEGINS*/");
-
-SECTION (".init")
-void
+void __attribute__((section (".init.prologue")))
 _init (void)
 {
   /* We cannot use the normal constructor mechanism in gcrt1.o because it
@@ -76,29 +56,17 @@
   if (__gmon_start__)
     __gmon_start__ ();
 
-  asm ("ALIGN");
-  asm("END_INIT");
   /* Now the epilog. */
-  asm ("\n/*@_init_PROLOG_ENDS*/");
-  asm ("\n/*@_init_EPILOG_BEGINS*/");
-  SECTION(".init");
+  SECTION(".init.epilogue");
 }
-asm ("END_INIT");
 
-/* End of the _init epilog, beginning of the _fini prolog. */
-asm ("\n/*@_init_EPILOG_ENDS*/");
-asm ("\n/*@_fini_PROLOG_BEGINS*/");
-
-SECTION (".fini")
-void
+void __attribute__((section (".fini.prologue")))
 _fini (void)
 {
 
   /* End of the _fini prolog. */
-  asm ("ALIGN");
-  asm ("END_FINI");
-  asm ("\n/*@_fini_PROLOG_ENDS*/");
 
+  SECTION (".garbage");
   {
     /* Let GCC know that _fini is not a leaf function by having a dummy
        function call here.  We arrange for this call to be omitted from
@@ -108,14 +76,7 @@
   }
 
   /* Beginning of the _fini epilog. */
-  asm ("\n/*@_fini_EPILOG_BEGINS*/");
-  SECTION (".fini");
+  SECTION (".fini.epilogue");
 }
-asm ("END_FINI");
-
-/* End of the _fini epilog.  Any further generated assembly (e.g. .ident)
-   is shared between both crt files. */
-asm ("\n/*@_fini_EPILOG_ENDS*/");
-asm ("\n/*@TRAILER_BEGINS*/");
 
 /* End of file. */
Index: csu/Makefile
===================================================================
RCS file: /egcs/carton/cvsfiles/libc/csu/Makefile,v
retrieving revision 1.34
diff -u -r1.34 Makefile
--- Makefile	1998/05/25 09:08:12	1.34
+++ Makefile	1998/06/29 09:58:52
@@ -75,35 +75,31 @@
 crtstuff = crti crtn
 
 install-lib += $(crtstuff:=.o)
-extra-objs += $(crtstuff:=.o)
-generated += $(crtstuff:=.S) initfini.s defs.h
+extra-objs += $(crtstuff:=.o) initfini.o \
+	      $(crtstuff:=.ld) $(crtstuff:=x.o) ld-r.ld
 omit-deps += $(crtstuff)
 
-# Special rules for the building of crti.o and crtn.o
-$(objpfx)crt%.o: $(objpfx)crt%.S $(objpfx)defs.h
-	$(compile.S) -g0 $(ASFLAGS-.os) -o $@
+$(objpfx)ld-r.ld: $(common-objpfx)config.make
+	$(LD) --verbose -r | sed '1,/^==*$$/d;/^==*$$/d' > $@
+$(objpfx)crti.ld: $(objpfx)ld-r.ld
+	sed -e 's/(\.init)/(.init.prologue); . = ALIGN(4);/' \
+	    -e 's/(\.fini)/(.fini.prologue); . = ALIGN(4);/' < $< > $@
+$(objpfx)crtn.ld: $(objpfx)ld-r.ld
+	sed -e 's/(\.init)/(.init.epilogue)/' \
+	    -e 's/(\.fini)/(.fini.epilogue)/' < $< > $@
+
+$(objpfx)crt%x.o: $(objpfx)crt%.ld $(objpfx)initfini.o
+	$(LD) -r --warn-section-align -T $< -o $@ $(filter-out $<,$^)
+$(objpfx)crt%.o: $(objpfx)crt%x.o
+	$(OBJCOPY) $< $@ \
+		   -R .init.$(crtxlogue) -R .fini.$(crtxlogue) -R .garbage
+crtxlogue = $(patsubst n,pro,$(patsubst i,epi,$*))logue
 
-CFLAGS-initfini.s = -g0 -fPIC -fno-inline-functions
 
-$(objpfx)initfini.s: initfini.c
-	$(compile.c) -S $(CFLAGS-initfini.s) -finhibit-size-directive \
-		$(no-exceptions) -o $@
+CFLAGS-initfini.o = -g0 -fPIC -fno-inline-functions
 
 # We only have one kind of startup code files.  Static binaries and
 # shared libraries are build using the PIC version.
-$(objpfx)crti.S: $(objpfx)initfini.s
-	sed -n -e '1,/@HEADER_ENDS/p' \
-	       -e '/@_.*_PROLOG_BEGINS/,/@_.*_PROLOG_ENDS/p' \
-	       -e '/@TRAILER_BEGINS/,$$p' $< > $@
-
-$(objpfx)crtn.S: $(objpfx)initfini.s
-	sed -n -e '1,/@HEADER_ENDS/p' \
-	       -e '/@_.*_EPILOG_BEGINS/,/@_.*_EPILOG_ENDS/p' \
-	       -e '/@TRAILER_BEGINS/,$$p' $< > $@
-
-$(objpfx)defs.h: $(objpfx)initfini.s
-	sed -n -e '/@TESTS_BEGIN/,/@TESTS_END/p' $< | \
-		$(AWK) -f defs.awk > $@
 
 endif
 
Index: configure.in
===================================================================
RCS file: /egcs/carton/cvsfiles/libc/configure.in,v
retrieving revision 1.222
diff -u -r1.222 configure.in
--- configure.in	1998/06/26 14:42:16	1.222
+++ configure.in	1998/06/29 09:58:57
@@ -487,6 +487,8 @@
 AC_CHECK_TOOL(AR, ar)
 AC_CHECK_TOOL(RANLIB, ranlib, :)
 AC_CHECK_TOOL(MIG, mig)
+AC_CHECK_TOOL(LD, ld)
+AC_CHECK_TOOL(OBJCOPY, objcopy)
 
 # if using special system headers, find out the compiler's sekrit
 # header directory and add that to the list.  NOTE: Only does the right
Index: config.make.in
===================================================================
RCS file: /egcs/carton/cvsfiles/libc/config.make.in,v
retrieving revision 1.58
diff -u -r1.58 config.make.in
--- config.make.in	1998/06/26 14:41:45	1.58
+++ config.make.in	1998/06/29 09:58:57
@@ -68,6 +68,8 @@
 MAKEINFO = @MAKEINFO@
 AS = $(CC) -c
 MIG = @MIG@
+LD = @LD@
+OBJCOPY = @OBJCOPY@
 
 # Installation tools.
 INSTALL = @INSTALL@


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