comp.lang.ada
 help / color / mirror / Atom feed
* Strange error in mixed language program (incompatible libraries?)
@ 2004-08-09 18:37 James Alan Farrell
  2004-08-10  6:40 ` Simon Wright
                   ` (3 more replies)
  0 siblings, 4 replies; 8+ messages in thread
From: James Alan Farrell @ 2004-08-09 18:37 UTC (permalink / raw)


Hello, all,
I'm working on a program that is partly in C and partly in Ada.  The
main program is in C, and links to several libraries whose source is
C, and one library whose source is Ada.

When the C libraries are actually linked, I get an error 
raised STORAGE_ERROR : stack overflow (or erroneous memory access)

This error is raised by one of the Ada routines BEFORE any of the C
library routines are called.

When the C library is not linked and the C calls are commented out the
Ada routines run correctly.  Unfortunately the program does not do
anything this way.  (Actually that's a good thing.  The unfortunate
thing is the specs say it HAS to so something ;)

The Ada code is compiled with gnat version 3.15

The C code is compiled with gcc version 2.8.1


This shows how the Ada code is typically compiled, so you can see what
flags, etc. we are using:

gcc -c -Wall -g -gnatf -I/usr/local/lib/stk/include -DAPICALL=
example.adb
gnatmake -c example.adb -cargs -Wall -g -gnatf
-I/usr/local/lib/stk/include -DAPICALL= 

where example.adb is a made up file name containing a package body
with a set of functions to be  loaded into the Ada library.  There is
a matching companion .ads file.  The each library function is declared
in the .ads file, and is accompanied with a pragma like

   pragma Export
     (C, My_Ada_Function_Name, "my_c_function_name");



The library is created with:

ar rs libada_interface.a b~ada_interface.o ada_interface.o example.o
... (a dozen or so files)

I've tried simple things like recompiling all Ada and C code, raising
the stack limit then recompiling everything, etc.  

Anyone know what might cause this and how it might be fixed?

Many thanks,
James Alan Farrell
GrammaTech.com



^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: Strange error in mixed language program (incompatible libraries?)
  2004-08-09 18:37 Strange error in mixed language program (incompatible libraries?) James Alan Farrell
@ 2004-08-10  6:40 ` Simon Wright
  2004-08-10  7:04 ` Jerry van Dijk
                   ` (2 subsequent siblings)
  3 siblings, 0 replies; 8+ messages in thread
From: Simon Wright @ 2004-08-10  6:40 UTC (permalink / raw)


> I'm working on a program that is partly in C and partly in Ada.  The
> main program is in C, and links to several libraries whose source is
> C, and one library whose source is Ada.

Perhaps this is appropriate?
http://gcc.gnu.org/onlinedocs/gnat_ugn_unw/Binding-with-Non_002dAda-Main-Programs.html#Binding-with-Non_002dAda-Main-Programs

There is stuff in the same set of pages about building libraries with
GNAT, but I suspect that won't work with 3.15.

-- 
Simon Wright                               100% Ada, no bugs.



^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: Strange error in mixed language program (incompatible libraries?)
  2004-08-09 18:37 Strange error in mixed language program (incompatible libraries?) James Alan Farrell
  2004-08-10  6:40 ` Simon Wright
@ 2004-08-10  7:04 ` Jerry van Dijk
  2004-08-10 13:01   ` Marc A. Criley
  2004-08-10 15:31 ` James Alan Farrell
  2004-08-11  8:58 ` Pascal Obry
  3 siblings, 1 reply; 8+ messages in thread
From: Jerry van Dijk @ 2004-08-10  7:04 UTC (permalink / raw)


James Alan Farrell <anonymous@anonymous.com> writes:

> This error is raised by one of the Ada routines BEFORE any of the C
> library routines are called.

Most likely you forgot that the Ada code needs elaboration. see the chapter
on using Ada libraries in the GNAT user guide for how to do this.

-- 
--  Jerry van Dijk
--  Leiden, Holland



^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: Strange error in mixed language program (incompatible libraries?)
  2004-08-10  7:04 ` Jerry van Dijk
@ 2004-08-10 13:01   ` Marc A. Criley
  0 siblings, 0 replies; 8+ messages in thread
From: Marc A. Criley @ 2004-08-10 13:01 UTC (permalink / raw)


"Jerry van Dijk" <jerry@jvdsys.demon.nl> wrote:

> Most likely you forgot that the Ada code needs elaboration. see the
chapter
> on using Ada libraries in the GNAT user guide for how to do this.

Specifically, adainit and adafinal.

Marc A. Criley
McKae Technologies
www.mckae.com





^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: Strange error in mixed language program (incompatible libraries?)
  2004-08-09 18:37 Strange error in mixed language program (incompatible libraries?) James Alan Farrell
  2004-08-10  6:40 ` Simon Wright
  2004-08-10  7:04 ` Jerry van Dijk
@ 2004-08-10 15:31 ` James Alan Farrell
  2004-08-10 21:36   ` James Alan Farrell
  2004-08-14 15:29   ` Simon Wright
  2004-08-11  8:58 ` Pascal Obry
  3 siblings, 2 replies; 8+ messages in thread
From: James Alan Farrell @ 2004-08-10 15:31 UTC (permalink / raw)


Thanx for the help.

I am calling adainit.  I was missing the call to adafinal (my bad) but
that did not solve the problem (did not expect it too - that comes at
the end of the program and should not effect the previous execution.)

I have found the following in the make file (set up by someone else
before I joined the project):

b~ada_interface.o: ada_interface.o 
	gnatbind -n ada_interface.ali
	gnatmake -c b~ada_interface.adb


Ada_interface has a number of children
(ie, ada_interface-this.ad[bs] and ada_interface-that.ad[bs])

Do their .ali files need to be explicitly listed in the above bind
command?

Also, just to make mention of it, another program creates a .so that
links to this library plus a different C library, and that seems to
work fine.

James



^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: Strange error in mixed language program (incompatible libraries?)
  2004-08-10 15:31 ` James Alan Farrell
@ 2004-08-10 21:36   ` James Alan Farrell
  2004-08-14 15:29   ` Simon Wright
  1 sibling, 0 replies; 8+ messages in thread
From: James Alan Farrell @ 2004-08-10 21:36 UTC (permalink / raw)


Just some further info:

I tried have tried providing all the .o files from all the children of
ada_interface to gnatbind.  I am still getting the same error.

I also attempted to turn the library into a shared dynamic library,
and I am still getting the same error.  Perhaps I was incorrect when I
said that is working on another program - that other program does not
link the same C files.

Is there anything special I have to do to build the C files I link to
the ada files?


I compiled b~ada_interface with the -g option, then  stepped through
the program with gdb.  I found the crash is occuring at 

      if not E045 then
=>    System.Exception_Table'Elab_Body;
         E045 := True;
      end if;

We looked at what this is doing, and it appears that it registers the
standard Ada errors, but we cannot be sure which particular error is
doing it.  However, at least to me this is not shedding any light.
Why would this crash when C libraries are linked in, but not
otherwise?

thanks,
James


On Tue, 10 Aug 2004 11:31:31 -0400, James Alan Farrell
<anonymous@anonymous.com> wrote:

>Thanx for the help.
>
>I am calling adainit.  I was missing the call to adafinal (my bad) but
>that did not solve the problem (did not expect it too - that comes at
>the end of the program and should not effect the previous execution.)
>
>I have found the following in the make file (set up by someone else
>before I joined the project):
>
>b~ada_interface.o: ada_interface.o 
>	gnatbind -n ada_interface.ali
>	gnatmake -c b~ada_interface.adb
>
>
>Ada_interface has a number of children
>(ie, ada_interface-this.ad[bs] and ada_interface-that.ad[bs])
>
>Do their .ali files need to be explicitly listed in the above bind
>command?
>
>Also, just to make mention of it, another program creates a .so that
>links to this library plus a different C library, and that seems to
>work fine.
>
>James





^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: Strange error in mixed language program (incompatible libraries?)
  2004-08-09 18:37 Strange error in mixed language program (incompatible libraries?) James Alan Farrell
                   ` (2 preceding siblings ...)
  2004-08-10 15:31 ` James Alan Farrell
@ 2004-08-11  8:58 ` Pascal Obry
  3 siblings, 0 replies; 8+ messages in thread
From: Pascal Obry @ 2004-08-11  8:58 UTC (permalink / raw)



James Alan Farrell <anonymous@anonymous.com> writes:

> Anyone know what might cause this and how it might be fixed?

Looks like an elaboration issue. Sinci the main is in C, do you elaborate
properly the Ada part ? See GNAT User's Guide about mixed languages
programming.

Pascal.

-- 

--|------------------------------------------------------
--| Pascal Obry                           Team-Ada Member
--| 45, rue Gabriel Peri - 78114 Magny Les Hameaux FRANCE
--|------------------------------------------------------
--|              http://www.obry.org
--| "The best way to travel is by means of imagination"
--|
--| gpg --keyserver wwwkeys.pgp.net --recv-key C1082595



^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: Strange error in mixed language program (incompatible libraries?)
  2004-08-10 15:31 ` James Alan Farrell
  2004-08-10 21:36   ` James Alan Farrell
@ 2004-08-14 15:29   ` Simon Wright
  1 sibling, 0 replies; 8+ messages in thread
From: Simon Wright @ 2004-08-14 15:29 UTC (permalink / raw)


James Alan Farrell <anonymous@anonymous.com> writes:

> I have found the following in the make file (set up by someone else
> before I joined the project):
> 
> b~ada_interface.o: ada_interface.o 
> 	gnatbind -n ada_interface.ali
> 	gnatmake -c b~ada_interface.adb
> 
> 
> Ada_interface has a number of children
> (ie, ada_interface-this.ad[bs] and ada_interface-that.ad[bs])
> 
> Do their .ali files need to be explicitly listed in the above bind
> command?

No, provided that they are in the closure ..

The last time I set this up I used Imake, so the rules are a tad
obscure, and I had adabind output in C instead of Ada, but the gist
was .. the b~ada_interface.adb file contains a set of comments which
list all the linker commands (mainly .o files) needed. So I extracted
these comments into a "response file" and catted the file as part of
the linker commands.

Looking at one of my scratch builds, in b~main.adb I have

--  BEGIN Object file/option list
   --   ./tasks.o
   --   ./main.o
   --   -L./
   --   -L/opt/3.16a1/lib/gcc-lib/i686-pc-linux-gnu/2.8.1/adalib/
   --   -L/opt/3.16a1/lib/gcc-lib/i686-pc-linux-gnu/2.8.1/adalib/
   --   -static
   --   -lgnarl
   --   -lgnat
   --   -lpthread
--  END Object file/option list   

so I need to extract the lines between BEGIN and END and remove the
leading --. Something like

  sed -n -e "/BEGIN/,/END/p" <b~main.adb \
     | egrep -v "BEGIN|END" \
     | sed -e "s/--//" > b~main.r

(I'm sure there's a better way to do that!)


All this is done automatically by gnatlink, but I don't think that
works if the main program isn't in Ada.


-- 
Simon Wright                               100% Ada, no bugs.



^ permalink raw reply	[flat|nested] 8+ messages in thread

end of thread, other threads:[~2004-08-14 15:29 UTC | newest]

Thread overview: 8+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2004-08-09 18:37 Strange error in mixed language program (incompatible libraries?) James Alan Farrell
2004-08-10  6:40 ` Simon Wright
2004-08-10  7:04 ` Jerry van Dijk
2004-08-10 13:01   ` Marc A. Criley
2004-08-10 15:31 ` James Alan Farrell
2004-08-10 21:36   ` James Alan Farrell
2004-08-14 15:29   ` Simon Wright
2004-08-11  8:58 ` Pascal Obry

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox