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]

GNAT vs DW2/ZCX EH.


    Hello all, and ADA hackers in particular :-)


  I've been having a hard time bootstrapping GNAT 4.3.2 lately, and now I
think I've found the problem.  Or /a/ problem, but I'm not sure exactly why
it's a problem in the first place.  Let me explain:

  As mentioned in an earlier thread, you can't bootstrap GCC > 4.X (where x is
probably '1') with GCC-3.anything; the build process these days makes use of
new gnat (?gnatmake?) command-line options that the old compiler doesn't
understand.  Fair enough, no problem.

  However the main issues I've been having trouble with show up when I try and
run the testsuite.

  The first problem I ran into was total failure to throw and catch exceptions
in ADA, failing with a SEGV every time.  It wasn't enough to just set
EH_MECHANISM=-gcc in the target-specific section of gcc/ada/Makefile.in; I
found that lots of the ada runtime had been compiled without EH frame data, so
the unwinder couldn't throw through them and just blew up at runtime.

  So I added "T_ADA_CFLAGS=-fexceptions" to the target clause in Makefile.in
as well, but that seems wrong to me: surely the build system ought to do that
already?  I found a couple of lines in one of the source files that appear to
set the global variables corresponding to -fexceptions (and
-fnon-call-exceptions), but I'm not sure if they should be coming into play here.

  I also tried manually setting ZCX_By_Default to true in the
system-$target.ads, and even then I was getting similar crashes to the above,
because some of the library .o files still contained no DW2 eh_frame tables,
which blows up at runtime when you throw.

  Next problem I ran into was this:

------------------------------------<snip>------------------------------------
		=== acats support ===
Generating support files...error: "macrosub.adb" must be recompiled
("system.ads" has been modified)
error: "defs.ads" must be recompiled ("system.ads" has been modified)
error: "getsubs.adb" must be recompiled ("system.ads" has been modified)
error: "parsemac.adb" must be recompiled ("system.ads" has been modified)
error: "s-stalib.adb" and "macrosub.adb" compiled with different exception
handling mechanisms
error: "a-except.adb" and "macrosub.adb" compiled with different exception
handling mechanisms
                   [ ... snip many more ... ]
------------------------------------<snip>------------------------------------

  I think it might be that this arises because the GNAT I'm using to bootstrap
was configured for sjlj EH, and I'm trying to build one configured for ZCX.
The test script gcc/testsuite/ada/run_all.sh contains these lines:

------------------------------------<snip>------------------------------------
# These tools are used to preprocess some ACATS sources
# they need to be compiled native on the host.

host_gnatmake -q -gnatws macrosub.adb
if [ $? -ne 0 ]; then
   display "**** Failed to compile macrosub"
   exit 1
fi
./macrosub > macrosub.out 2>&1

gcc -c cd300051.c
host_gnatmake -q -gnatws widechr.adb
if [ $? -ne 0 ]; then
   display "**** Failed to compile widechr"
   exit 1
fi
./widechr > widechr.out 2>&1
------------------------------------<snip>------------------------------------

  It seems to me as if possibly that doesn't work right when host and target
gnat have different EH models.  I don't know enough about ada to know if
preprocessing is like C and there is some equivalent of a #define that's being
expanded differently, but I do know that I had to change that flag in
system.adb in order to enable ZCX, and I'm guessing that's what conflicts
between the modules compiled with the two compilers.  (One of the things that
seemed to be going on when I was trying to bootstrap with 3.x is that the
build system was using the native and newly-built compilers at different and
unexpected times.)

  However, I am guessing there, and I don't know whether it's actually the
preprocessing that causes the conflict, or if that should work fine and
there's a problem somewhere else causing it.

  And the fourth problem I had is that there are a whole load of builds in
gcc/ada/Makefile.in that didn't pick up the -fexceptions flag, so they still
didn't have eh frame data.  That turns out to be because the make rules that
build them refer to $(ADA_CFLAGS), which is generated by AC_SUBST at configure
time.  Most other compilations in the same makefile don't ue ADA_CFLAGS but
ALL_ADA_CFLAGS, which contains both ADA_CFLAGS and the cross- and target-
specific X_ADA_CFLAGS and T_ADA_CFLAGS, and I found a changelog entry by JDA
from back in 2001 which suggests that this was a new scheme that should be
used anywhere:

------------------------------------<snip>------------------------------------
2001-05-02  John David Anglin  <dave@hiauly1.hia.nrc.ca>

	* ada/Makefile.in (X_ADA_CFLAGS, T_ADA_CFLAGS): New fragment overrides.
	(ALL_ADA_CFLAGS): Define.  Replace ADA_CFLAGS with ALL_ADA_CFLAGS in
	ALL_ADAFLAGS, MOST_ADAFLAGS, and all compilations using CC.
------------------------------------<snip>------------------------------------

  And I'm guessing people just forgot when they were adding more .c files
several years later, because I had to apply the attached diffs to get the .o
files generated using the correct flags to have EH data.

  Also, I'm wondering if this was the actual cause of the problem I previously
suggested might be caused by using the host-compiler in run_all.sh, since that
problem seems to have gone away since I applied the current patch and rebuild

  But, I'm not very sure about any of this, and it looks like the ADA build
system has some historical warts in it that I don't understand, and I may have
gone and confused myself with the amount of rebuilds I've been doing in the
same $objdir (and not even configured with --enable-maintainer-mode, but I did
occasionally reset with a clean objdir), so I figured I'd try asking a few
questions:

1.  Is it supposed to work to bootstrap gnat with a compiler using a different
EH model from the one you're trying to build?
2.  Where it uses the host compiler, would it be ok to use the newly-built
target one instead if host==target, i.e. not a cross compiler?
3.  Should I have needed to add -fexceptions, and if not, why not?

  Oh, host is i686-pc-cygwin, btw.

    cheers,
      DaveK

--- .mf.i	2009-02-27 11:51:44.906250000 +0000
+++ Makefile.in	2009-02-27 11:51:58.234375000 +0000
@@ -277,7 +277,7 @@ ADA_INCLUDES_FOR_SUBDIR = -I. -I$(fsrcdi
 	$(CC) -c -x assembler $< $(OUTPUT_OPTION)
 
 .c.o:
-	$(CC) -c $(ALL_CFLAGS) $(ADA_CFLAGS) $(ALL_CPPFLAGS) $(INCLUDES) $< \
+	$(CC) -c $(ALL_CFLAGS) $(ALL_ADA_CFLAGS) $(ALL_CPPFLAGS) $(INCLUDES) $< \
 	  $(OUTPUT_OPTION)
 
 .adb.o:
@@ -2253,37 +2253,37 @@ raise.o   : raise.c raise.h
 vx_stack_info.o : vx_stack_info.c
 
 gen-soccon: gen-soccon.c gsocket.h
-	$(CC) $(ALL_CFLAGS) $(ADA_CFLAGS) $(ALL_CPPFLAGS) $(INCLUDES) \
+	$(CC) $(ALL_CFLAGS) $(ALL_ADA_CFLAGS) $(ALL_CPPFLAGS) $(INCLUDES) \
 		-UIN_GCC -DTARGET=\"$(target_alias)\" \
 		$< $(OUTPUT_OPTION)
 
 cio.o     : cio.c
-	$(CC) -c $(ALL_CFLAGS) $(ADA_CFLAGS) \
+	$(CC) -c $(ALL_CFLAGS) $(ALL_ADA_CFLAGS) \
 	         $(ALL_CPPFLAGS) $(INCLUDES) $< $(OUTPUT_OPTION)
 
 init.o    : init.c adaint.h raise.h
-	$(CC) -c $(ALL_CFLAGS) $(ADA_CFLAGS) \
+	$(CC) -c $(ALL_CFLAGS) $(ALL_ADA_CFLAGS) \
 	         $(ALL_CPPFLAGS) $(INCLUDES) $< $(OUTPUT_OPTION)
 
 initialize.o : initialize.c raise.h
-	$(CC) -c $(ALL_CFLAGS) $(ADA_CFLAGS) \
+	$(CC) -c $(ALL_CFLAGS) $(ALL_ADA_CFLAGS) \
 	         $(ALL_CPPFLAGS) $(INCLUDES) $< $(OUTPUT_OPTION)
 
 targext.o : targext.c
-	$(CC) -c $(ALL_CFLAGS) $(ADA_CFLAGS) \
+	$(CC) -c $(ALL_CFLAGS) $(ALL_ADA_CFLAGS) \
 		$(ALL_CPPFLAGS) $(INCLUDES_FOR_SUBDIR) \
 		$< $(OUTPUT_OPTION)
 
 # No optimization to compile this file as optimizations (-O1 or above) breaks
 # the SEH handling on Windows. The reasons are not clear.
 seh_init.o : seh_init.c raise.h
-	$(CC) -c $(ALL_CFLAGS) $(ADA_CFLAGS) -O0 \
+	$(CC) -c $(ALL_CFLAGS) $(ALL_ADA_CFLAGS) -O0 \
 	         $(ALL_CPPFLAGS) $(INCLUDES) $< $(OUTPUT_OPTION)
 
 # Need to keep the frame pointer in this file to pop the stack properly on
 # some targets.
 tracebak.o  : tracebak.c tb-alvms.c tb-alvxw.c tb-gcc.c
-	$(CC) -c $(ALL_CFLAGS) $(ADA_CFLAGS) $(ALL_CPPFLAGS) $(INCLUDES) \
+	$(CC) -c $(ALL_CFLAGS) $(ALL_ADA_CFLAGS) $(ALL_CPPFLAGS) $(INCLUDES) \
 	      -fno-omit-frame-pointer $< $(OUTPUT_OPTION)
 
 # In GNU Make, ignore whether `stage*' exists.

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