Hi Tristan,
the root cause for this lies in grt-stats.adb. The method used to call
the C stdarg function fprintf does not work portably.
According to "System V Application Binary Interface, AMD64 Architecture
Processor Supplement, Draft Version
0.99" (http://www.x86-64.org/documentation...), on x86_64, stdarg
functions receive a hidden parameter in %al, which counts the number of
%xmm registers used in the call. Now with the current calling method, %
al is undefined. %al however may only use values from 0 to 8. At least
my gcc version (4.4.2) uses %al at the call site to compute a jump. Any
value in %al other than 0 to 8 will cause that jump to land in arbitrary
code, not at an intended landing site, thus crashing the program.
The conclusion is that C stdarg functions cannot be called like this
portably from Ada.
The attached patch fixes the crash. I just hope Ada Integer and C int
are the same size on any supported platform.
I also filed this as bug #15015 on gna.org.
I wish you all a happy new year and may ghdl help you uncover many bugs
in your VHDL code.
Tom
--- gcc/vhdl/grt/grt-cbinding.c.orig 2009-12-30 00:24:06.000000000 +0100
+++ gcc/vhdl/grt/grt-cbinding.c 2009-12-30 00:27:36.000000000 +0100
@@ -43,6 +43,12 @@
fprintf (stream, "%g", val);
}
+void
+__ghdl_fprintf_clock (FILE *stream, int a, int b)
+{
+ fprintf (stream, "%3d.%03d", a, b);
+}
+
#if 1
void
__gnat_last_chance_handler (void)
--- gcc/vhdl/grt/grt-stats.adb.orig 2009-12-30 00:24:17.000000000 +0100
+++ gcc/vhdl/grt/grt-stats.adb 2009-12-30 00:29:20.000000000 +0100
@@ -71,10 +71,8 @@
procedure Put (Stream : FILEs; Val : Clock_T)
is
- Fmt : constant String := "%3d.%03d" & Character'Val (0);
-
- procedure fprintf (Stream : FILEs; Fmt : Address; A, B : Clock_T);
- pragma Import (C, fprintf);
+ procedure Fprintf_Clock (Stream : FILEs; A, B : Clock_T);
+ pragma Import (C, Fprintf_Clock, "__ghdl_fprintf_clock");
Sec : Clock_T;
Ms : Clock_T;
@@ -84,7 +82,7 @@
-- Avoid overflow.
Ms := ((Val mod One_Second) * 1000) / One_Second;
- fprintf (Stream, Fmt'Address, Sec, Ms);
+ Fprintf_Clock (Stream, Sec, Ms);
end Put;
procedure Put (Stream : FILEs; T : Time_Stats) is
_______________________________________________
Ghdl-discuss mailing list
[email protected]
https://mail.gna.org/listinfo/ghdl-discuss