Date: Fri, 21 Jun 2002 16:58:06 +0100 From: Mark Murray <mark@grondar.za> To: jdp@freebsd.org Cc: audit@freebsd.org Subject: lib/csu cleanup - review please Message-ID: <200206231830.g5NIUAa4045990@grimreaper.grondar.org>
next in thread | raw e-mail | index | archive | help
Hi John and other folks
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.
Comments? Flames? Awards? :-)
M
--
o Mark Murray
\_
O.\_ Warning: this .sig is umop ap!sdn
Index: alpha/crt1.c
===================================================================
RCS file: /home/ncvs/src/lib/csu/alpha/crt1.c,v
retrieving revision 1.12
diff -u -d -r1.12 crt1.c
--- alpha/crt1.c 13 Apr 2002 21:54:09 -0000 1.12
+++ alpha/crt1.c 20 Jun 2002 19:01:36 -0000
@@ -35,23 +35,31 @@
* THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
+#ifndef lint
+
#ifndef __GNUC__
#error "GCC is needed to compile this file"
#endif
+#ifndef __alpha__
+#error "This file only supports the alpha architecture"
+#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 int main(int, char **, char **);
+void _start(char **, void (*)(void), struct Struct_Obj_Entry *,
+ struct ps_strings *);
#ifdef GCRT
extern void _mcleanup(void);
@@ -60,6 +68,9 @@
extern int etext;
#endif
+extern int _DYNAMIC;
+#pragma weak _DYNAMIC
+
char **environ;
const char *__progname = "";
@@ -75,7 +86,7 @@
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 -r1.7 crt1.c
--- i386-elf/crt1.c 29 Mar 2002 22:43:41 -0000 1.7
+++ i386-elf/crt1.c 21 Jun 2002 06:56:31 -0000
@@ -23,20 +23,29 @@
* THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
+#ifndef lint
+
#ifndef __GNUC__
#error "GCC is needed to compile this file"
#endif
-#include <stddef.h>
+#ifndef __i386__
+#error "This file only supports the i386 architecture"
+#endif
+
+#endif /* lint */
+
#include <stdlib.h>
+
#include "libc_private.h"
#include "crtbrand.c"
typedef void (*fptr)(void);
-extern void _fini(void);
extern void _init(void);
+extern void _fini(void);
extern int main(int, char **, char **);
+void _start(char *, ...);
#ifdef GCRT
extern void _mcleanup(void);
@@ -48,51 +57,56 @@
extern int _DYNAMIC;
#pragma weak _DYNAMIC
-#ifdef __i386__
-#define get_rtld_cleanup() \
- ({ fptr __value; \
- __asm__("movl %%edx,%0" : "=rm"(__value)); \
- __value; })
-#else
-#error "This file only supports the i386 architecture"
-#endif
-
char **environ;
const char *__progname = "";
+__inline static fptr
+get_rtld_cleanup(void)
+{
+ fptr retval;
+
+ retval =
+#ifdef __GNUC__
+ ({ fptr __value; __asm__("movl %%edx,%0" : "=rm"(__value)); __value; });
+#else
+ (fptr)0;
+#endif
+ return(retval);
+}
+
void
-_start(char *arguments, ...)
+_start(char *ap, ...)
{
- fptr rtld_cleanup;
- int argc;
- char **argv;
- char **env;
- const char *s;
+ fptr rtld_cleanup;
+ int argc;
+ char **argv;
+ char **env;
+ const char *s;
- rtld_cleanup = get_rtld_cleanup();
- argv = &arguments;
- argc = * (int *) (argv - 1);
- env = argv + argc + 1;
- environ = env;
- if (argc > 0 && argv[0] != NULL) {
- __progname = argv[0];
- for (s = __progname; *s != '\0'; s++)
- if (*s == '/')
- __progname = s + 1;
- }
+ rtld_cleanup = get_rtld_cleanup();
+ argv = ≈
+ argc = *(int *)(void *)(argv - 1);
+ env = argv + argc + 1;
+ environ = env;
+ if (argc > 0 && argv[0] != NULL) {
+ __progname = argv[0];
+ for (s = __progname; *s != '\0'; s++)
+ if (*s == '/')
+ __progname = s + 1;
+ }
- if (&_DYNAMIC != NULL)
- atexit(rtld_cleanup);
+ if (&_DYNAMIC != NULL)
+ atexit(rtld_cleanup);
#ifdef GCRT
- atexit(_mcleanup);
+ atexit(_mcleanup);
#endif
- atexit(_fini);
+ atexit(_fini);
#ifdef GCRT
- monstartup(&eprol, &etext);
+ monstartup(&eprol, &etext);
#endif
- _init();
- exit( main(argc, argv, env) );
+ _init();
+ exit( main(argc, argv, env) );
}
#ifdef GCRT
Index: powerpc/crt1.c
===================================================================
RCS file: /home/ncvs/src/lib/csu/powerpc/crt1.c,v
retrieving revision 1.8
diff -u -d -r1.8 crt1.c
--- powerpc/crt1.c 29 Mar 2002 22:43:41 -0000 1.8
+++ powerpc/crt1.c 20 Jun 2002 19:11:17 -0000
@@ -38,20 +38,26 @@
* THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
+#ifndef lint
+
#ifndef __GNUC__
#error "GCC is needed to compile this file"
#endif
+#ifndef __powerpc__
+#error "This file only supports the powerpc architecture"
+#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 int main(int, char **, char **);
@@ -63,6 +69,9 @@
extern int etext;
#endif
+extern int _DYNAMIC;
+#pragma weak _DYNAMIC
+
char **environ;
const char *__progname = "";
struct ps_strings *__ps_strings;
@@ -73,17 +82,13 @@
* The last argument, ps_strings, is a BSD extension.
*/
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 struct Struct_Obj_Entry *obj,
+ 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 +111,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 -r1.8 crt1.c
--- sparc64/crt1.c 29 Apr 2002 20:25:29 -0000 1.8
+++ sparc64/crt1.c 20 Jun 2002 19:02:25 -0000
@@ -29,23 +29,31 @@
* THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
+#ifndef lint
+
#ifndef __GNUC__
#error "GCC is needed to compile this file"
#endif
+#ifndef __sparc64__
+#error "This file only supports the sparc64 architecture"
+#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 int main(int, char **, char **);
+void _start(char **, void (*)(void), struct Struct_Obj_Entry *,
+ struct ps_strings *);
extern void __sparc64_sigtramp_setup(void);
extern void __sparc64_utrap_setup(void);
@@ -55,6 +63,9 @@
extern int eprol;
extern int etext;
#endif
+
+extern int _DYNAMIC;
+#pragma weak _DYNAMIC
char **environ;
const char *__progname = "";
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?200206231830.g5NIUAa4045990>
