users-prolog
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Prolog not fully initialized


From: Michał Bieliński
Subject: Re: Prolog not fully initialized
Date: Wed, 29 Sep 2010 18:14:59 +0200
User-agent: SquirrelMail/1.4.20

Dnia 29 Września 2010, 00:54, Śr, Daniel Diaz napisał:
>   Le 28/09/2010 22:42, "Michał Bieliński" a écrit :
>> Greetings!
>>
>> I recently managed to interface GNU Prolog with Free Pascal albeit not
>> fully. Both Prolog and Pascal units compile and link.
>>
>> Pl_Start_Prolog executes and returns. Manual states this function will
>> collect all objects and initialize them. Probably this somehow fails
>> because many standard atoms are not found by Pl_Find_Atom function. It
>> seems linking through gcc allows Prolog to find all objects but using
>> another compiler does not.
[snip]

> Hello,
>
> gprolog uses the underlying gcc mechanism to collect and initialize
> linked objects : constructors functions. Each Prolog source give rise to
> a constructor function to register it (and later to initialize it). The
> asm code is similar to what is generated by gcc when compiling a
> function declared as follows (see also src/EnginePl/obj_chain.h and .c) :

Ah, I see now. Object files need to modify a static table with pointers to
their initialization functions before Pl_Start_Prolog is called.

> /* file x.c */
> static void __attribute__((constructor)) foo(void) {
>     ...
> }
>
> use gcc -S -O2 x.c
> to see x.s

In assembly file I located "Object_Initializer" symbol. By making it
global (static modifier in C code ensures it is not visible by default) I
could call it from Pascal file and suddenly there are atoms from Prolog
example available! Doing the same with gprolog libs is not an option
though.

> I suppose you have to succeed in doing the same as gcc to initialize
> correctly the objects.

Indeed. Addresses of initializers are stored in .ctors section. gcc walks
through this table and calls these pointers. Question is how exactly is it
done. Probably code for this task is not generated but linked with some
standard gcc library. I need to get my hands on this routine.

-- 
Michal Bielinski




reply via email to

[Prev in Thread] Current Thread [Next in Thread]