This is the mail archive of the gcc@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]
Other format: [Raw text]

Re: patch for -Wno-long-long and early GNAT compilers


On Tue, Mar 19, 2002 at 05:20:02AM -0500, Richard Kenner wrote:
> 
> Or perhaps the problem might be that GCC changed the way the builtin
> setjmp/longjmp was implemented on x86 and the setjmp (in Ada code) is
> being compiled with one version while the longjmp (in C code) is being
> compiled by a different one.

This does appear to be the problem.  If I split up your test program
into two pieces, compile the setjmp half with gnatgcc and the longjmp
half with gcc-2.95, and link them together, it crashes.

Comparing assembly dumps for the longjmp half reveals the cause:

sub2-2.95:                              sub2-2.8.1:
        pushl %ebp                              pushl %ebp
        movl %esp,%ebp                          movl %esp,%ebp
        movl $buf,%eax                          movl $buf,%eax
        movl buf,%ebp                           movl buf,%ebp
        movl 8(%eax),%esp                       movl 8(%eax),%esp
                                      >         movl $__dummy,%ecx
        jmp *4(%eax)                            jmp *4(%eax)

The jump-receiving code expects ecx to point to a callable routine,
but the 2.95 code doesn't set that up properly.  Looks like this was
changed by the patch in http://gcc.gnu.org/ml/gcc/1997-11/msg00386.html.

This does not explain why I was seeing GNAT crash when the entire
thing was compiled with gnatgcc.  Since Florian doesn't see it, I
probably had stray objects floating around.

Hmm, there is only one C module which calls __builtin_longjmp.  We
could force that file to be compiled with the same compiler used for
Ada.  What do you think of this patch?  With it applied, and an
unpatched sem_eval.adb, I get no crash.

I've also clarified the installation instructions a bit; right now
they give the impression that you don't need a cc1 that matches your
gnat1 binary.

zw

===================================================================
Index: ada/Makefile.in
--- ada/Makefile.in	2002/03/13 00:36:45	1.24
+++ ada/Makefile.in	2002/03/19 16:38:52
@@ -2263,8 +2263,11 @@ init.o    : init.c ada.h types.h raise.h
 	$(CC) -c $(ALL_CFLAGS) $(ADA_CFLAGS) $(RT_FLAGS) \
 	         $(ALL_CPPFLAGS) $(INCLUDES) $< 
 
+# This file must be compiled with the same compiler back end that
+# was used for the Ada modules.  The __builtin_setjmp/longjmp
+# implementation is incompatible between 2.8.1 and 2.95.
 raise.o   : raise.c raise.h
-	$(CC) -c $(ALL_CFLAGS) $(ADA_CFLAGS) $(RT_FLAGS) \
+	$(ADAC) -c $(ALL_CFLAGS) $(ADA_CFLAGS) $(RT_FLAGS) \
 		 $(ALL_CPPFLAGS) $(INCLUDES) $< 
 
 # Need to keep the frame pointer in this file to pop the stack properly on
===================================================================
Index: ada/raise.c
--- ada/raise.c	2002/03/14 10:59:38	1.4
+++ ada/raise.c	2002/03/19 17:10:11
@@ -42,6 +42,9 @@ typedef char bool;
 # define false 0
 #else
 #include "config.h"
+/* Don't let system.h try to include stdbool.h - we may be using a
+   different compiler from the one autoconf probed.  */
+#undef HAVE_STDBOOL_H
 #include "system.h"
 #endif
 
@@ -56,6 +59,16 @@ _gnat_builtin_longjmp (ptr, flag)
      int flag ATTRIBUTE_UNUSED;
 {
    __builtin_longjmp (ptr, 1);
+}
+
+/* __builtin_longjmp may reference a routine in libgcc.a named __dummy,
+   which doesn't do anything.  This routine was removed from libgcc.a
+   in GCC 3.0.  Avoid link errors if this file is compiled by a version
+   of GCC that uses __dummy, but 3.0 or later is being used to link.  */
+extern void __dummy PARAMS ((void));
+void
+__dummy ()
+{
 }
 
 /* When an exception is raised for which no handler exists, the procedure
===================================================================
Index: doc/install.texi
--- doc/install.texi	2002/03/08 16:44:50	1.93
+++ doc/install.texi	2002/03/19 17:20:40
@@ -1033,13 +1033,14 @@ compiler, since the Ada front end is wri
 GNAT-specific extensions), and GNU make.
 
 However, you do not need a full installation of GNAT, just the GNAT
-binary @file{gnat1}, a copy of @file{gnatbind}, and a compiler driver
-which can deal with Ada input (by invoking the @file{gnat1} binary).
-You can specify this compiler driver by setting the @env{ADAC}
-environment variable at the configure step.  @command{configure} can
-detect the driver automatically if it has got a common name such as
-@command{gcc} or @command{gnatgcc}.  Of course, you still need a working
-C compiler (the compiler driver can be different or not).
+binary @file{gnat1}, the matching @file{cc1}, a copy of @file{gnatbind},
+and a compiler driver which can deal with Ada input (by invoking the
+@file{gnat1} binary).  You can specify this compiler driver by setting
+the @env{ADAC} environment variable at the configure step.
+@command{configure} can detect the driver automatically if it has got a
+common name such as @command{gcc} or @command{gnatgcc}.  Of course, you
+still need a working C compiler (the compiler driver can be different or
+not).
 
 Additional build tools (such as @command{gnatmake}) or a working GNAT
 run-time library installation are usually @emph{not} required.  However,


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