Skip site navigation (1)Skip section navigation (2)
Date:      Sun, 30 Jun 2002 20:24:21 +0100
From:      Mark Murray <mark@grondar.za>
To:        audit@FreeBSD.ORG
Subject:   lib/csu cleanup #2 - review please (commit candidate)
Message-ID:  <200206301924.g5UJOL07070228@grimreaper.grondar.org>
In-Reply-To: <200206231830.g5NIUAa4045990@grimreaper.grondar.org> ; from Mark Murray <mark@grondar.za>  "Fri, 21 Jun 2002 16:58:06 BST."
References:  <200206231830.g5NIUAa4045990@grimreaper.grondar.org> 

next in thread | previous in thread | raw e-mail | index | archive | help
------- =_aaaaaaaaaa0
Content-Type: text/plain; charset="us-ascii"
Content-ID: <70203.1025464768.1@grimreaper.grondar.org>

I said in a previous mail:
> Please check out the following diffs to lib/csu/*/crt1.c.
> 
> I've been carrying a lot of this for nearly a year now with
> no problems at all on my laptop or SMP servers.
> 
> There are two separate reasons for the cleanup: WARNS/lint
> fixes, and diff-reduction between all of the crt1.c's.
> 
> For the i386-elf version, there are a lot of whitespace diffs
> that will be committed separately.
> 
> Also for the i386-elf one, a macro containing GCC-specific
> __asm() code has been turned into an inline function. This
> makes for neater (IMO) code, and makes it possible to lint.

In response to some useful comments from Bruce and David, I've
cleaned this up, tested it on i386-elf (on my laptop) and extended
it to the other architectures a lot more (limited testing, so
please help out!).

Here is the latest incarnaton. Review please? I did the diff
with "cvs ... diff ... -bB ... " to minimise the whitespace
diffs in i386-elf/crt1.c (Which I will commit separately; it
has 4-space indents instead of tabs, and I'd like to fix that).

M
-- 
o       Mark Murray
\_
O.\_    Warning: this .sig is umop ap!sdn

------- =_aaaaaaaaaa0
Content-Type: text/plain; charset="us-ascii"
Content-ID: <70203.1025464768.2@grimreaper.grondar.org>
Content-Description: lib/csu/*/crt1.c fixes

Index: alpha/crt1.c
===================================================================
RCS file: /home/ncvs/src/lib/csu/alpha/crt1.c,v
retrieving revision 1.13
diff -u -d -B -b -r1.13 crt1.c
--- alpha/crt1.c	25 Jun 2002 18:01:12 -0000	1.13
+++ alpha/crt1.c	30 Jun 2002 12:05:26 -0000
@@ -35,11 +35,14 @@
  * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  */
 
+#ifndef lint
 #ifndef __GNUC__
 #error "GCC is needed to compile this file"
 #endif
+#endif /* lint */
 
 #include <stdlib.h>
+
 #include "libc_private.h"
 #include "crtbrand.c"
 
@@ -43,17 +46,13 @@
 #include "libc_private.h"
 #include "crtbrand.c"
 
-struct Struct_Obj_Entry;
-struct ps_strings;
-
-#pragma weak _DYNAMIC
 extern int _DYNAMIC;
+#pragma weak _DYNAMIC
 
-extern void _init(void);
 extern void _fini(void);
+extern void _init(void);
 extern int main(int, char **, char **);
-extern void _start(char **, void (*)(void), struct Struct_Obj_Entry *,
-    struct ps_strings *);
+extern void _start(char **, void (*)(void), ...);
 
 #ifdef GCRT
 extern void _mcleanup(void);
@@ -67,17 +66,14 @@
 
 /* The entry function. */
 void
-_start(char **ap,
-	void (*cleanup)(void),			/* from shared loader */
-	struct Struct_Obj_Entry *obj __unused,	/* from shared loader */
-	struct ps_strings *ps_strings __unused)
+_start(char **ap, void (*cleanup)(void), ...)
 {
 	int argc;
 	char **argv;
 	char **env;
 	const char *s;
 
-	argc = * (long *) ap;
+	argc = *(long *)(void *)ap;
 	argv = ap + 1;
 	env  = ap + 2 + argc;
 	environ = env;
Index: i386-elf/crt1.c
===================================================================
RCS file: /home/ncvs/src/lib/csu/i386-elf/crt1.c,v
retrieving revision 1.7
diff -u -d -B -b -r1.7 crt1.c
--- i386-elf/crt1.c	29 Mar 2002 22:43:41 -0000	1.7
+++ i386-elf/crt1.c	30 Jun 2002 12:23:33 -0000
@@ -23,12 +23,14 @@
  * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  */
 
+#ifndef lint
 #ifndef __GNUC__
 #error "GCC is needed to compile this file"
 #endif
+#endif /* lint */
 
-#include <stddef.h>
 #include <stdlib.h>
+
 #include "libc_private.h"
 #include "crtbrand.c"
 
@@ -32,11 +34,15 @@
 #include "libc_private.h"
 #include "crtbrand.c"
 
+extern int _DYNAMIC;
+#pragma weak _DYNAMIC
+
 typedef void (*fptr)(void);
 
 extern void _fini(void);
 extern void _init(void);
 extern int main(int, char **, char **);
+extern void _start(char *, ...);
 
 #ifdef GCRT
 extern void _mcleanup(void);
@@ -45,33 +51,35 @@
 extern int etext;
 #endif
 
-extern int _DYNAMIC;
-#pragma weak _DYNAMIC
+char **environ;
+const char *__progname = "";
 
-#ifdef __i386__
-#define get_rtld_cleanup()				\
-    ({ fptr __value;					\
-       __asm__("movl %%edx,%0" : "=rm"(__value));	\
-       __value; })
+static __inline fptr
+get_rtld_cleanup(void)
+{
+	fptr retval;
+
+#ifdef	__GNUC__
+	__asm__("movl %%edx,%0" : "=rm"(retval));
 #else
-#error "This file only supports the i386 architecture"
+	retval = (fptr)0; /* XXXX Fix this for other compilers */
 #endif
+	return(retval);
+}
 
-char **environ;
-const char *__progname = "";
-
+/* The entry function. */
 void
-_start(char *arguments, ...)
+_start(char *ap, ...)
 {
-    fptr rtld_cleanup;
+	fptr cleanup;
     int argc;
     char **argv;
     char **env;
     const char *s;
 
-    rtld_cleanup = get_rtld_cleanup();
-    argv = &arguments;
-    argc = * (int *) (argv - 1);
+	cleanup = get_rtld_cleanup();
+	argv = &ap;
+	argc = *(long *)(void *)(argv - 1);
     env = argv + argc + 1;
     environ = env;
     if (argc > 0 && argv[0] != NULL) {
@@ -82,7 +90,7 @@
     }
 
     if (&_DYNAMIC != NULL)
-	atexit(rtld_cleanup);
+		atexit(cleanup);
 
 #ifdef GCRT
     atexit(_mcleanup);
Index: ia64/crt1.c
===================================================================
RCS file: /home/ncvs/src/lib/csu/ia64/crt1.c,v
retrieving revision 1.7
diff -u -d -B -b -r1.7 crt1.c
--- ia64/crt1.c	29 Mar 2002 22:43:41 -0000	1.7
+++ ia64/crt1.c	30 Jun 2002 19:09:00 -0000
@@ -31,23 +31,23 @@
  * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  */
 
+#ifndef lint
 #ifndef __GNUC__
 #error "GCC is needed to compile this file"
 #endif
+#endif /* lint */
 
 #include <stdlib.h>
 #include "libc_private.h"
 #include "crtbrand.c"
 
-struct Struct_Obj_Entry;
-struct ps_strings;
-
 #pragma weak _DYNAMIC
 extern int _DYNAMIC;
 
-extern void _init(void);
 extern void _fini(void);
+extern void _init(void);
 extern int main(int, char **, char **);
+extern void _start(char **, const void *, void (*)(void));
 
 #ifdef GCRT
 extern void _mcleanup(void);
@@ -59,17 +59,10 @@
 char **environ;
 const char *__progname = "";
 
-/* The entry function. */
-void
-_start(char **ap,
-       struct ps_strings *ps_strings,
-       void (*cleanup)(void))
+static __inline void
+fix_gp(void)
 {
-	int argc;
-	char **argv;
-	char **env;
-	const char *s;
-
+#ifdef __GNUC__
 	/* Calculate gp */
 	__asm __volatile(" \
 		movl gp=@gprel(1f) ; \
@@ -78,8 +71,21 @@
 		;; ; \
 		sub gp=r14,gp ; \
 		;; ");
+#endif
+}
 
-	argc = * (long *) ap;
+/* The entry function. */
+/* ARGSUSED */
+void
+_start(char **ap, const void *junk __unused, void (*cleanup)(void))
+{
+	int argc;
+	char **argv;
+	char **env;
+	const char *s;
+
+	fix_gp();
+	argc = *(long *)(void *)ap;
 	argv = ap + 1;
 	env  = ap + 2 + argc;
 	environ = env;
Index: powerpc/crt1.c
===================================================================
RCS file: /home/ncvs/src/lib/csu/powerpc/crt1.c,v
retrieving revision 1.8
diff -u -d -B -b -r1.8 crt1.c
--- powerpc/crt1.c	29 Mar 2002 22:43:41 -0000	1.8
+++ powerpc/crt1.c	30 Jun 2002 18:54:56 -0000
@@ -38,11 +38,14 @@
  * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  */
 
+#ifndef lint
 #ifndef __GNUC__
 #error "GCC is needed to compile this file"
 #endif
+#endif /* lint */
 
 #include <stdlib.h>
+
 #include "libc_private.h"
 #include "crtbrand.c"
 
@@ -46,15 +49,16 @@
 #include "libc_private.h"
 #include "crtbrand.c"
 
-struct Struct_Obj_Entry;
-struct ps_strings;
-
-#pragma weak _DYNAMIC
 extern int _DYNAMIC;
+#pragma weak _DYNAMIC
+
+struct ps_strings;
 
-extern void _init(void);
 extern void _fini(void);
+extern void _init(void);
 extern int main(int, char **, char **);
+extern void _start(int, char **, char **, const void *, void (*)(void),
+    struct ps_strings *);
 
 #ifdef GCRT
 extern void _mcleanup(void);
@@ -72,18 +76,15 @@
  * First 5 arguments are specified by the PowerPC SVR4 ABI.
  * The last argument, ps_strings, is a BSD extension.
  */
+/* ARGSUSED */
 void
-_start(argc, argv, envp, obj, cleanup, ps_strings)
-	int argc;
-	char **argv, **envp;
-	const struct Struct_Obj_Entry *obj;	/* from shared loader */
-	void (*cleanup)(void);			/* from shared loader */
-	struct ps_strings *ps_strings;		/* BSD extension */
+_start(int argc, char **argv, char **env, const void *junk __unused,
+    void (*cleanup)(void),
+    struct ps_strings *ps_strings)
 {
-	char *namep;
 	const char *s;
 
-	environ = envp;
+	environ = env;
 
 	if (argc > 0 && argv[0] != NULL) {
 		__progname = argv[0];
@@ -106,7 +107,7 @@
 	monstartup(&eprol, &etext);
 #endif
 	_init();
-	exit( main(argc, argv, envp) );
+	exit( main(argc, argv, env) );
 }
 
 #ifdef GCRT
Index: sparc64/crt1.c
===================================================================
RCS file: /home/ncvs/src/lib/csu/sparc64/crt1.c,v
retrieving revision 1.8
diff -u -d -B -b -r1.8 crt1.c
--- sparc64/crt1.c	29 Apr 2002 20:25:29 -0000	1.8
+++ sparc64/crt1.c	30 Jun 2002 19:13:04 -0000
@@ -29,11 +29,14 @@
  * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  */
 
+#ifndef lint
 #ifndef __GNUC__
 #error "GCC is needed to compile this file"
 #endif
+#endif /* lint */
 
 #include <stdlib.h>
+
 #include "libc_private.h"
 #include "crtbrand.c"
 
@@ -37,17 +40,17 @@
 #include "libc_private.h"
 #include "crtbrand.c"
 
-struct Struct_Obj_Entry;
-struct ps_strings;
-
-#pragma weak _DYNAMIC
 extern int _DYNAMIC;
+#pragma weak _DYNAMIC
+
+typedef void (*fptr)(void);
 
-extern void _init(void);
 extern void _fini(void);
+extern void _init(void);
 extern int main(int, char **, char **);
-extern void __sparc64_sigtramp_setup(void);
-extern void __sparc64_utrap_setup(void);
+extern void _start(char **, void (*)(void), ...);
+extern void __sparc_sigtramp_setup(void);
+extern void __sparc_utrap_setup(void);
 
 #ifdef GCRT
 extern void _mcleanup(void);
@@ -59,6 +62,23 @@
 char **environ;
 const char *__progname = "";
 
+static __inline fptr
+get_term(void)
+{
+	fptr retval;
+
+#if 0
+#ifdef	__GNUC__
+	__asm__ volatile("mov %%g1,%0" : "=r"(retval));
+#else
+	retval = (fptr)0; /* XXXX Fix this for other compilers */
+#endif
+#else
+	retval = (fptr)0; /* XXXX temporary */
+#endif
+	return(retval);
+}
+
 /* The entry function. */
 /*
  *
@@ -71,25 +91,20 @@
  * but for now we do not use it here.
  */
 void
-_start(char **ap,
-	void (*cleanup)(void),			/* from shared loader */
-	struct Struct_Obj_Entry *obj,		/* from shared loader */
-	struct ps_strings *ps_strings)
+_start(char **ap, void (*cleanup)(void), ...)
 {
+	void (*term)(void);	
 	int argc;
 	char **argv;
 	char **env;
 	const char *s;
-#if 0
-	void (*term)(void);	
 
 	/* Grab %g1 before it gets used for anything by the compiler. */
 	/* Sparc ELF psABI specifies a termination routine (if any) will be in
 	   %g1 */
-	__asm__ volatile("mov %%g1,%0" : "=r"(term));
-#endif
+	term = get_term();
 
-	argc = * (long *) ap;
+	argc = *(long *)(void *)ap;
 	argv = ap + 1;
 	env  = ap + 2 + argc;
 	environ = env;
@@ -102,14 +117,13 @@
 
 	__sparc_sigtramp_setup();
 	__sparc_utrap_setup();
-#if 0
+
 	/*
 	 * If the kernel or a shared library wants us to call
 	 * a termination function, arrange to do so.
 	 */
 	if (term)
 		atexit(term);
-#endif
 
 	if (&_DYNAMIC != NULL)
 		atexit(cleanup);

------- =_aaaaaaaaaa0--

To Unsubscribe: send mail to majordomo@FreeBSD.org
with "unsubscribe freebsd-audit" in the body of the message




Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?200206301924.g5UJOL07070228>