Mailing List Archive

WARNING: AIX and dynamic loading.
Hi everybody,

I would like to warn developers using AIX against this trap waiting
for us to fall into. (I am cross-posting this to the SWIG mailing list
although it is not strictly a SWIG problems, as SWIG users will be
doing just the kind of stuff that gets you into trouble).

SCENARIO:
You are developing a dynamically loaded C module for Python (or
possibly for other languages). You place the module in a directory on
the PYTHONPATH. That directory is NFS mounted. Or you are loading
the module directly from the directory where you compiled it, and that
directory is NFS mounted.

SYMPTOMS:
You are improving the code, but it does not seem to have any effect at
all. Eventually you realise that Python is loading the buggy version
of your module that you tried out this morning, although _all_ copies
on disk are the new improved version you just wrote !

PROBLEM:
If you copy the module to the PYTHONPATH directory using cp, the old
file gets overwritten, but keeps the same inode number. Apparently,
the AIX dynamical loader is caching the module somewhere, and does not
discover that the file has been modified. (If the directory is not NFS
mounted cp will fail with an error message saying that you cannot
overwrite a running program - although the program has stopped.)

It is _possible_ that this only occurs if the module you wrote causes
python to dump core. It certainly makes it frustrating to fix the
bug as you continue to get the version that dumps core loaded into
python, even after you fixed the bug.

SOLUTION:
You makefile should remove the old module (the .so file) before copying the
new version into the installation directory. Then the file gets a new
inode number and the loader discovers that it has been changed. If
you ever load the module directly from the development directory you
should also remove the .so file before compiling/linking, as you will
otherwise get hit by the same bug.


I just wanted to warn you all about this bug in AIX. I wasted too much time
on this last Friday :-(

Best regards,

Jakob Schiotz

--
Jakob Schiotz, CAMP and Department of Physics, Tech. Univ. of Denmark,
DK-2800 Lyngby, Denmark. http://www.fysik.dtu.dk/~schiotz/
This email address is used for newsgroups and mailing lists
(spam protection). Official email: schiotz @ fysik . dtu . dk

-----------== Posted via Deja News, The Discussion Network ==----------
http://www.dejanews.com/ Search, Read, Discuss, or Start Your Own
WARNING: AIX and dynamic loading. [ In reply to ]
In article <7g4i77$qif$1@nnrp1.dejanews.com>,
Jakob Schiotz <jschiotz@hotmail.com> wrote:
>
>
>Hi everybody,
>
>I would like to warn developers using AIX against this trap waiting
>for us to fall into. (I am cross-posting this to the SWIG mailing list
>although it is not strictly a SWIG problems, as SWIG users will be
>doing just the kind of stuff that gets you into trouble).
.
.
.
There are several issues specific to dynamic loading
under AIX that are quite independent of Python. Your
caching example is one I've never heard of before,
but the comp.lang.tcl crowd knowledgeable about the
Stubs project might be able to help you if you run
into more problems. I agree that SWIG is an apt
locus for such discussion.
--

Cameron Laird http://starbase.neosoft.com/~claird/home.html
claird@NeoSoft.com +1 281 996 8546 FAX
WARNING: AIX and dynamic loading. [ In reply to ]
Jakob Schiotz wrote:
>
> Hi everybody,
>
> I would like to warn developers using AIX against this trap waiting
> for us to fall into. (I am cross-posting this to the SWIG mailing list
> although it is not strictly a SWIG problems, as SWIG users will be
> doing just the kind of stuff that gets you into trouble).
>
> SCENARIO:
> You are developing a dynamically loaded C module for Python (or
> possibly for other languages). You place the module in a directory on
> the PYTHONPATH. That directory is NFS mounted. Or you are loading
> the module directly from the directory where you compiled it, and that
> directory is NFS mounted.
>
> SYMPTOMS:
> You are improving the code, but it does not seem to have any effect at
> all. Eventually you realise that Python is loading the buggy version
> of your module that you tried out this morning, although _all_ copies
> on disk are the new improved version you just wrote !
>
> PROBLEM:
> If you copy the module to the PYTHONPATH directory using cp, the old
> file gets overwritten, but keeps the same inode number. Apparently,
> the AIX dynamical loader is caching the module somewhere, and does not
> discover that the file has been modified. (If the directory is not NFS
> mounted cp will fail with an error message saying that you cannot
> overwrite a running program - although the program has stopped.)
>
> It is _possible_ that this only occurs if the module you wrote causes
> python to dump core. It certainly makes it frustrating to fix the
> bug as you continue to get the version that dumps core loaded into
> python, even after you fixed the bug.
>

I found this problem when developing extensions for Tcl, my solution
was to run slibclean (as root) which removes all unused modules from the
system.

> SOLUTION:
> You makefile should remove the old module (the .so file) before copying the
> new version into the installation directory. Then the file gets a new
> inode number and the loader discovers that it has been changed. If
> you ever load the module directly from the development directory you
> should also remove the .so file before compiling/linking, as you will
> otherwise get hit by the same bug.
>

That is very useful, as I had a solution I did not bother to find out
what was happening.

> I just wanted to warn you all about this bug in AIX. I wasted too much time
> on this last Friday :-(
>

AIX should definitely look at the modification date as well as the
inode.

--
Paul Duffin
DT/6000 Development Email: pduffin@hursley.ibm.com
IBM UK Laboratories Ltd., Hursley Park nr. Winchester
Internal: 7-246880 International: +44 1962-816880
WARNING: AIX and dynamic loading. [ In reply to ]
Paul Duffin <pduffin@mailserver.hursley.ibm.com> writes:

> > PROBLEM:
> > If you copy the module to the PYTHONPATH directory using cp, the old
> > file gets overwritten, but keeps the same inode number. Apparently,

On my system (running AIX 4.3.1), it is *impossible* to overwrite
a shared library that has ever been loaded; all you get is an error
message claiming that the file is being used.

> > SOLUTION:
> > You makefile should remove the old module (the .so file) before copying the
> > new version into the installation directory. Then the file gets a new

This is what I had to do as well, in order to be able to copy a new
version. With that I never had any problems.

--
-------------------------------------------------------------------------------
Konrad Hinsen | E-Mail: hinsen@cnrs-orleans.fr
Centre de Biophysique Moleculaire (CNRS) | Tel.: +33-2.38.25.55.69
Rue Charles Sadron | Fax: +33-2.38.63.15.17
45071 Orleans Cedex 2 | Deutsch/Esperanto/English/
France | Nederlands/Francais
-------------------------------------------------------------------------------
WARNING: AIX and dynamic loading. [ In reply to ]
Did you try running slibclean? That flushes out dynamic libraries
that are no longer being used from memory. This forces a reload from
disk when a library is next used.
--
Pete Forman
Western Geophysical
pete.forman@westgeo.com
WARNING: AIX and dynamic loading. [ In reply to ]
In article <m3btg9jand.fsf@chinon.cnrs-orleans.fr>,
Konrad Hinsen <hinsen@cnrs-orleans.fr> wrote:

> On my system (running AIX 4.3.1), it is *impossible* to overwrite
> a shared library that has ever been loaded; all you get is an error
> message claiming that the file is being used.

Even if the directory is NFS mounted? NFS file locking usually doesn't work -
and there may be the additional problem of another machine using the module.
It sure would be nice if it has been fixed in AIX 4.3

>
> > > SOLUTION:
> > > You makefile should remove the old module (the .so file) before copying
the
> > > new version into the installation directory. Then the file gets a new
>
> This is what I had to do as well, in order to be able to copy a new
> version. With that I never had any problems.

I guess that is the safest thing to do whenever you are installing an
executable or a shared object - somebody might be running it.


Happy programming! :-)


Jakob

--
Jakob Schiotz, CAMP and Department of Physics, Tech. Univ. of Denmark,
DK-2800 Lyngby, Denmark. http://www.fysik.dtu.dk/~schiotz/
This email address is used for newsgroups and mailing lists
(spam protection). Official email: schiotz @ fysik . dtu . dk

-----------== Posted via Deja News, The Discussion Network ==----------
http://www.dejanews.com/ Search, Read, Discuss, or Start Your Own