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: Ada in gcc-3.4.3 on x86_64


Dean Kolosiek wrote:
I followed the build instructions at http://gcc.gnu.org/install/build.html which does not mention make -C gcc gnatlib_and_tools


That worked, and I reproduced a problem I saw in 3.3.3. When calling a C function from Ada there is no code generated to set %al to the number of xmm registers being passed. Variadic C functions use %al to compute a jump into a table of movaps instructions to save the xmm registers. The result is a jump to a random location.

In general, if the calling sequence for a variadic function is not the same as the normal calling sequence, then there is no way in GNAT to interface directly to such a function. From the GNAT RM:

In C, @code{varargs} allows a function to take a variable number of
arguments. There is no direct equivalent in this to Ada. One
approach that can be used is to create a C wrapper for each
different profile and then interface to this C wrapper. For
example, to print an @code{int} value using @code{printf},
create a C function @code{printfi} that takes two arguments, a
pointer to a string and an int, and calls @code{printf}.
Then in the Ada program, use pragma @code{Import} to
interface to printfi.

It may work on some platforms to directly interface to
a @code{varargs} function by providing a specific Ada profile
for a a particular call. However, this does not work on
all platforms, since there is no guarantee that the
calling sequence for a two argument normal C function
is the same as for calling a @code{varargs} C function with
the same two arguments.

So there is no bug here, just a case where the "may" of para 2 does not apply. So the proper approach is to create C wrappers as noted in the first quoted para.


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