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]

gcc should be Sys V ABI compliant, hence implement __assert()


ABI standards, though not as important as source standards, are still
standards.

The System V ABI (available from
ftp://ftp.linux.sgi.com/pub/linux/mips/doc/ABI and elsewhere)
specifies the function __assert.

I think both glibc (in libc.a) and gcc (in libgcc) should implement
__assert.

If its existence in a standard is not a good enough reason, here is
another reason.  Implementing assert() using __assert() is "obviously"
more efficient than using _eprintf().  Using _eprintf() was a
collossal blunder, when __assert was already defined in the ABI and is
clearly the better choice.  Eventually, gcc should use __assert()
unconditionally to implement assert().  The only reason not to do so
right away is because then object code compiled with newer versions of
gcc may not link when using old versions of gcc to do the link.  On
platforms like Solaris, where you can count on having assert() in
libc, one could switch to using __assert() right away.  But that is
the subject of a different patch.  Even on Solaris, some crazy person
could port glibc to Solaris and try to build applications with that
instead of native libc.  In that case, it's good to have copies of
__assert() in libgcc (and glibc, of course) for decades of binary
compatibility.

Anyways, there is no time to lose.  The sooner __assert is added to
libgcc, the better for everyone.

assert() is not rocket science, but the foresight for binary
compatibility apparently is.

This patch is intended to be NON-experimental, unlike my previous
patch in this area.  However, I don't really understand `inhibit_libc'.

This whole effort started when static libs built using solaris native
cc worked with both gcc and cc doing the link, while static libs built
using gcc only worked with gcc doing the link.

ObLegal: I hereby place this message in the public domain.

Index: ./gcc/Makefile.in
===================================================================
RCS file: /cvs/gcc/egcs/gcc/Makefile.in,v
retrieving revision 1.476
diff -u -w -r1.476 Makefile.in
--- Makefile.in	2000/07/06 22:59:34	1.476
+++ Makefile.in	2000/07/12 11:51:10
@@ -736,7 +736,7 @@
     _fixunsdfsi _fixunssfsi _fixunsdfdi _fixdfdi _fixunssfdi _fixsfdi \
     _fixxfdi _fixunsxfdi _floatdixf _fixunsxfsi \
     _fixtfdi _fixunstfdi _floatditf \
-    __gcc_bcmp _varargs __dummy _eprintf \
+    __gcc_bcmp _varargs __dummy _eprintf __assert \
     _bb _shtab _clear_cache _trampoline __main _exit \
     _ctors _pure
 
Index: ./gcc/libgcc2.c
===================================================================
RCS file: /cvs/gcc/egcs/gcc/libgcc2.c,v
retrieving revision 1.98
diff -u -w -r1.98 libgcc2.c
--- libgcc2.c	2000/07/10 20:25:56	1.98
+++ libgcc2.c	2000/07/12 11:51:12
@@ -1310,7 +1310,19 @@
   fflush (stderr);
   abort ();
 }
+#endif
+#endif
 
+
+#ifdef L__assert
+#ifndef inhibit_libc
+void
+__assert (const char *expression, const char *filename, unsigned int line)
+{
+  fprintf (stderr, "%s:%u: failed assertion `%s'\n", filename, line, expression);
+  fflush (stderr);
+  abort ();
+}
 #endif
 #endif
 

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