[Date Prev] [Date Next] [Thread Prev] [Thread Next] Date Index Thread Index Search archive:
Date:Mon Jun 29 18:21:26 2003 
Subject:Re: 'errno' problem for poplog in redhat 9: Partial progress 
From:Aaron Sloman 
Volume-ID:1030629.01 


I had some useful comments from Joe Wood and Waldek Hebisch for which
many thanks.

Joe wrote:

> After some digging, the error message is generated by lib/ld-linux.XXX

Yes: found that

    strings /lib/ld-linux.so.2 | grep errno

printed out this:

    Incorrectly built binary which accesses errno, h_errno
        or _res directly. Needs to be fixed.

which is the warning message mentioned previously.

> A possible (quick and dirty) workaround to satisfy the linker and
> others...
>
> 1/ in external/lib put pop-11 errno, with suitable get and set routines
> to read a thread local errno.
> 2/ Modify the macro(s) in unixdefs to invoke the get/set as needed to
> read errno from where ever the thread local copy was.

A similar, more detailed, suggestion came from Waldek Hebisch
[AS]
> ....
> : So it looks as if the problem likes in $popsrc/devio.p

[WH]
> Not exactly, I see the following in unixdefs.ph :
>
> lconstant macro _ERRNO = [_extern errno:data!(int)];
>
> I think this macro references errno directly
>
> <snip>
> ...
>
> Since errno is not an ordinary variable one really need
> a get and (possibly) update functions:
>
> #include <errno.h>
>
> int get_libc_errno(void)
> {
>   return errno;
> }
>
> void set_libc_errno(int x)
> {
>   errno = x;
> }
>
> The _ERRNO macro in unixdefs.ph have to be updated to call
> the C functions above.

That was very helpful. I looked at invocations of the _ERRNO
macro. They can occur on either side of an assignment,
so
   _ERRNO -> _x

would translate to

    _extern errno:data!(int) -> _x

and
   _x -> _ERRNO

would translate to

    _x -> _extern errno:data!(int)

The syntax word _extern is used by pgcomp, and defined in
    $popsrc/syscomp/syspop.p

However, I don't know enough about external calls in pop-11 to
understand exactly what it is doing.

Nevertheless I guessed that the following three steps could replace the
above definition of the macro _ERRNO, using an active variable.

Step 1:
Put Waldek's two C procedures in
    $popexternlib/c_core.c

     int get_libc_errno(void)
     {
             return errno;
     }

     void set_libc_errno(int x)
     {
             errno = x;
     }

and run mklibpop to compile them and build the library
    $popexternlib/libpop.a

Step 2:
Put an active variable definition in $popsrc/errors.p to
invoke those two C programs.

 define active DO_ERRNO_VAL() -> _x;
     _extern get_libc_errno() -> _x
 enddefine;


 define updaterof active DO_ERRNO_VAL(_x);
     _extern set_libc_errno(_x)
 enddefine;

Also make sure that this is declared in
    $popsrc/declare.ph

So that it is available for all system sources:

 global constant
     active
                 DO_ERRNO_VAL
     ;


    NOTE: I have no idea whether I need to add something to play
    the role of :data!(int) in the original definition of the
    macro. Nothing I have tried in those procedures works,
    and all the examples of _extern followed by a procedure call
    in the system sources have nothing like :data!(int)

    Note that in the pop11 system dialect underscore variables
    are regarded as not holding pop11 values, so the garbage
    collector does not look at them.


Step 3: Alter the definition of the macro in
    $popsrc/unixdefs.ph
to invoke the active variable

    lconstant macro _ERRNO = [DO_ERRNO_VAL];

(note that the _extern has moved to inside the procedure definitions
and is not needed here.)

Finally: recompile all the system sources and relink

    In $popsrc

        pgcomp *.p
        pglibr -r ../obj/src.wlb *.w
        rm *.w *.o

    In $usepop/pop/ved/src

        pgcomp *.p
        pglibr -r ../obj/vedsrc.wlb *.w
        rm *.w *.o

    In $usepop/pop/x/src

        pgcomp *.p
        pglibr -r ../obj/xsrc.wlb *.w
        rm *.w *.o

Then in some temporary directory:

    pglink

That creates a bunch of poplink* files (including the poplink_cmnd
that does the linking) and creates from them an executable
    newpop11

Try it:

Amazing: no more warning message about errno
./newpop11

Sussex Poplog (Version 15.53 Sun Jun 29 18:37:05 BST 2003)
Copyright (c) 1982-1999 University of Sussex. All rights reserved.

Setpop
:

Many things work as expected except the mishap message
: sqrt(99*1) =>
 ** 9.94987
: sqrt(100) =>
 ** 10.0
: sqrt(99+1) =>
 ** 10.0
: sqrt(-1) =>
 ** 0.0_+:1.0
: 'the cat ' >< [sat on the mat] =>
 ** the cat [sat on the mat]
: 3 + "two" =>

;;; MISHAP - NUMBER(S) NEEDED
;;; INVOLVING:  two <SYSTEM_OBJECT 401A4048>
;;; DOING    :  + pop_setpop_compiler

Setpop
:

That suggests I am not converting something properly.

Also I cannot compile libraries.

I have the impression it is close!

More later.
Aaron
====
Aaron Sloman, ( http://www.cs.bham.ac.uk/~axs/ )
School of Computer Science, The University of Birmingham, B15 2TT, UK
EMAIL A.Sloman AT cs.bham.ac.uk   (ReadATas@please !)
PAPERS: http://www.cs.bham.ac.uk/research/cogaff/ (And free book on Philosophy of AI)
FREE TOOLS: http://www.cs.bham.ac.uk/research/poplog/freepoplog.html