comp.lang.ada
 help / color / mirror / Atom feed
* How do package body initializers get run in GNU Ada?
@ 2002-11-02  0:39 Van Snyder
  2002-11-02  1:23 ` Jeffrey Carter
                   ` (4 more replies)
  0 siblings, 5 replies; 9+ messages in thread
From: Van Snyder @ 2002-11-02  0:39 UTC (permalink / raw)



In GNU Ada, what mechanism is used to cause execution of package
body initializers, i.e., the code between begin and end in a
package body?

Is it done using some kind of back-patching/overlaying done
by an otherwise garden-variety ld, by special features added
to ld to support Ada, by first-time flags at the entries
to procedures, or by something else?

--
Van Snyder                    |  What fraction of Americans believe
vsnyder@math.jpl.nasa.gov     |  Wrestling is real and NASA is fake?
Any alleged opinions are my own and have not been approved or
disapproved by JPL, CalTech, NASA, Sean O'Keefe, George Bush,
the Pope, or anybody else.




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

* Re: How do package body initializers get run in GNU Ada?
  2002-11-02  0:39 How do package body initializers get run in GNU Ada? Van Snyder
@ 2002-11-02  1:23 ` Jeffrey Carter
  2002-11-02  1:28 ` sk
                   ` (3 subsequent siblings)
  4 siblings, 0 replies; 9+ messages in thread
From: Jeffrey Carter @ 2002-11-02  1:23 UTC (permalink / raw)


Van Snyder wrote:
> 
> In GNU Ada, what mechanism is used to cause execution of package
> body initializers, i.e., the code between begin and end in a
> package body?

You can find the answer to your question by reading the GNAT sources.

> 
> Is it done using some kind of back-patching/overlaying done
> by an otherwise garden-variety ld, by special features added
> to ld to support Ada, by first-time flags at the entries
> to procedures, or by something else?

You will find that the binding process (gnatbind) builds the main 
program, which makes a call or calls to execute such code before calling 
your main procedure. By reading the secret GNAT documentation you can 
find the option that keeps the source of this main program instead of 
deleting it after the executable is written. You could then look at the 
main program and see what it calls to effect elaboration.

-- 
Jeff Carter
"I fart in your general direction."
Monty Python & the Holy Grail




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

* Re: How do package body initializers get run in GNU Ada?
  2002-11-02  0:39 How do package body initializers get run in GNU Ada? Van Snyder
  2002-11-02  1:23 ` Jeffrey Carter
@ 2002-11-02  1:28 ` sk
  2002-11-04 15:20   ` Stephen Leake
  2002-11-02 16:00 ` Robert A Duff
                   ` (2 subsequent siblings)
  4 siblings, 1 reply; 9+ messages in thread
From: sk @ 2002-11-02  1:28 UTC (permalink / raw)


Hi,

Van Snyder <vsnyder@math.jpl.nasa.gov>
> <snip>

This is a quick response and off the top of my head, so
details might be bad ...

Firstly, if you mean GNAT (?) by GNU Ada, the linker is
on GNU/Linux is not an issue in the elaboration code.

To explore what happens (if you are not referring to GNAT,
sorry, this is irrelevent) build a sample dummy package ...

package dummy is

    procedure Initialize;

begin
    Initialize;
end dummy;

... and compile with the "-s" option to produce assembly
listing and review. 
... or compile normally and use "objdump" to look at the
".o" file structure.

Then build an Ada main with the above options and look at
the produced "*.s" or "*.o" files

Along with this, look closely at the GNAT users guide,
specifically the binder section which shows how an Ada
"main" is built.

Sorry for not much detail, and it can become laborious 
finding how the code interacts, but it does provide some
insight which might be useful to you.

-- 
-------------------------------------
-- Merge vertically for real address
-------------------------------------
s n p @ t . o
 k i e k c c m
-------------------------------------



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

* Re: How do package body initializers get run in GNU Ada?
  2002-11-02  0:39 How do package body initializers get run in GNU Ada? Van Snyder
  2002-11-02  1:23 ` Jeffrey Carter
  2002-11-02  1:28 ` sk
@ 2002-11-02 16:00 ` Robert A Duff
  2002-11-03  2:45 ` David Marceau
  2002-11-03 11:37 ` Romanov
  4 siblings, 0 replies; 9+ messages in thread
From: Robert A Duff @ 2002-11-02 16:00 UTC (permalink / raw)


Van Snyder <vsnyder@math.jpl.nasa.gov> writes:

> In GNU Ada, what mechanism is used to cause execution of package
> body initializers, i.e., the code between begin and end in a
> package body?
> 
> Is it done using some kind of back-patching/overlaying done
> by an otherwise garden-variety ld, by special features added
> to ld to support Ada, by first-time flags at the entries
> to procedures, or by something else?

I believe most Ada compilers do not use such features of the linker.
Instead, they provide a program called the "builder" or "prelinker".
The compiler generates a procedure for each compilation unit,
containing the elaboration code.  The builder constructs a "main" that
calls all those elaboration procedures in a correct order, and then
calls the user-defined main procedure.  The builder normally then 
invokes the system linker (e.g. 'ld'), with all that code, telling it
the automatically constructed "main" is the program's entry point (*not*
the user-defined main procedure).

Note that the elaboration code for a package body is not just the code
between "begin" and "end".  It also includes initialization code for all
kinds of declarations.  E.g., if you say "X: Integer := Func(...);", the
elaboration code must call Func and initialize X to the result.
Similarly, package specs also have elaboration code.

- Bob



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

* Re: How do package body initializers get run in GNU Ada?
  2002-11-02  0:39 How do package body initializers get run in GNU Ada? Van Snyder
                   ` (2 preceding siblings ...)
  2002-11-02 16:00 ` Robert A Duff
@ 2002-11-03  2:45 ` David Marceau
  2002-11-03 11:37 ` Romanov
  4 siblings, 0 replies; 9+ messages in thread
From: David Marceau @ 2002-11-03  2:45 UTC (permalink / raw)


Van Snyder wrote:
> 
> In GNU Ada, what mechanism is used to cause execution of package
> body initializers, i.e., the code between begin and end in a
> package body?
> 
> Is it done using some kind of back-patching/overlaying done
> by an otherwise garden-variety ld, by special features added
> to ld to support Ada, by first-time flags at the entries
> to procedures, or by something else?
> 
> --
> Van Snyder                    |  What fraction of Americans believe
> vsnyder@math.jpl.nasa.gov     |  Wrestling is real and NASA is fake?
> Any alleged opinions are my own and have not been approved or
> disapproved by JPL, CalTech, NASA, Sean O'Keefe, George Bush,
> the Pope, or anybody else.
Hi there,

If I understood correctly you have two questions:
1)how do package body initializers get run in ada?
I am going to interpret that you mean what is the sequence of execution
of your ada lines of source code.
Without actually reading any gnat docs, 
IMHO I believe it worthwhile to place tracelog statements at the
beginning of every service including the initialize service even if it
was empty(non-existant).
Some people may find this a waste of time however IMHO you will have a
better understanding of what is going on at runtime if you do this.  In
the long term it certainly makes your code easier to diagnose where a
run-time error is caused.  Keep in mind the tracelog statements should
have a few things: package name, service name, line number.
A trick that some people may not agree with is exceptions info types
actually provide all this so you might embed a "begin fake exception
where fake exception print  exception info end; " block.
Once your program is finished executing you can look in your tracelog
for the order of execution of all your statements including especially
your "initialize" service.
As an alternative to a tracelog, you can achieve what you want by
stepping through your code with gdb. And I do mean "step" and not
"next".  It's long and tedious however it will show you the order of
elaboration, execution... of all your ada source.

2)What mechanism is used to cause execution of package body intializers?
I'm going to interpret that you mean how exactly the mechanism was
designed and written to implement the running of package body
initializers.
I think Mr. Duff's summary was clear and it shows he knows what %�! he's
talking about :)
For the detailed how, if I were you I would look at the gnat sources and
along with all the config makefiles and linker script.  Warning reading
these sources for what you want to know will open a can of worms so it
requires a lot of coffee and some reference books for linkers and
loaders.
Do I really know what I'm talking about?  No.

Cheers :)



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

* Re: How do package body initializers get run in GNU Ada?
  2002-11-02  0:39 How do package body initializers get run in GNU Ada? Van Snyder
                   ` (3 preceding siblings ...)
  2002-11-03  2:45 ` David Marceau
@ 2002-11-03 11:37 ` Romanov
  2002-11-03 20:14   ` Simon Wright
  4 siblings, 1 reply; 9+ messages in thread
From: Romanov @ 2002-11-03 11:37 UTC (permalink / raw)


Van Snyder <vsnyder@math.jpl.nasa.gov> wrote in message news:<3DC31EBB.2050809@math.jpl.nasa.gov>...
> In GNU Ada, what mechanism is used to cause execution of package
> body initializers, i.e., the code between begin and end in a
> package body?
> 
> Is it done using some kind of back-patching/overlaying done
> by an otherwise garden-variety ld, by special features added
> to ld to support Ada, by first-time flags at the entries
> to procedures, or by something else?

I thought it was done when the package was being elaborated? Package
elaboration takes place when the package is instantiated. statements
like 'with text_io;' executes the body initializers.

Ada is much more precise about initialization that C/C++ is. That's
why we have 'pragma elaborate(xxx);' statements

but i use the dynamic elaboration feature in gnat. so much easier...
you only get a problem when you try to use another joker who uses
static elaboration instead...



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

* Re: How do package body initializers get run in GNU Ada?
  2002-11-03 11:37 ` Romanov
@ 2002-11-03 20:14   ` Simon Wright
  0 siblings, 0 replies; 9+ messages in thread
From: Simon Wright @ 2002-11-03 20:14 UTC (permalink / raw)


russian_power@hotmail.com (Romanov) writes:

> I thought it was done when the package was being elaborated? Package
> elaboration takes place when the package is instantiated. statements
> like 'with text_io;' executes the body initializers.

I am pretty sure that "with text_io;" will only execute the spec
elaboration -- which is why you have to be careful when your
initialization calls functions in other packages, cos the _body_ of
the other package needs to have been elaborated.

> but i use the dynamic elaboration feature in gnat. so much easier...
> you only get a problem when you try to use another joker who uses
> static elaboration instead...

This seems odd to me, it's loads easier to let GNAT do its own thing
and not have to worry. I admit that a program of ours that built fine
under 3.09 caused us a lot of grief when we tried to migrate to 3.12
-- so much so that we stayed with 3.09 until we had to port to Solaris
x86, with no possible way of building a 3.09 compiler. I can also see
that if you want portability to other compilers you might have to be
explicit ..



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

* Re: How do package body initializers get run in GNU Ada?
  2002-11-02  1:28 ` sk
@ 2002-11-04 15:20   ` Stephen Leake
  2002-11-05  1:03     ` sk
  0 siblings, 1 reply; 9+ messages in thread
From: Stephen Leake @ 2002-11-04 15:20 UTC (permalink / raw)


sk <noname@myob.com> writes:

> Firstly, if you mean GNAT (?) by GNU Ada, 

Since GNAT originally meant GNU Ada Translator, this is clear. GNAT is
by definition GNU Ada.

-- 
-- Stephe



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

* Re: How do package body initializers get run in GNU Ada?
  2002-11-04 15:20   ` Stephen Leake
@ 2002-11-05  1:03     ` sk
  0 siblings, 0 replies; 9+ messages in thread
From: sk @ 2002-11-05  1:03 UTC (permalink / raw)


Hi,

Stephen Leake <stephen.a.leake.1@gsfc.nasa.gov>
>sk <noname@myob.com> writes:
>> Firstly, if you mean GNAT (?) by GNU Ada, 
>
> Since GNAT originally meant GNU Ada Translator, this is 
> clear. GNAT is by definition GNU Ada.

There is GNAT from "ftp://cs.nyu.edu/pub/gnat/3.14p/..."
and there is the Ada part of the new GNU gcc (3.x).

Obviously the GNU gcc Ada is derived from GNAT, but is not
the same animal. Would you care to interpret to which the OP
was refering to ? 

I have not tried the gcc 3.x stuff, so I was limiting
my response to the unofficial-official GNAT release !

-- 
-------------------------------------
-- Merge vertically for real address
-------------------------------------
s n p @ t . o
 k i e k c c m
-------------------------------------



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

end of thread, other threads:[~2002-11-05  1:03 UTC | newest]

Thread overview: 9+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2002-11-02  0:39 How do package body initializers get run in GNU Ada? Van Snyder
2002-11-02  1:23 ` Jeffrey Carter
2002-11-02  1:28 ` sk
2002-11-04 15:20   ` Stephen Leake
2002-11-05  1:03     ` sk
2002-11-02 16:00 ` Robert A Duff
2002-11-03  2:45 ` David Marceau
2002-11-03 11:37 ` Romanov
2002-11-03 20:14   ` Simon Wright

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