[OpenAFS-devel] Libtool on AIX
Benjamin Kaduk
kaduk@mit.edu
Sun, 10 Nov 2024 17:32:01 -0800
tl'dr `make dest` is not going to work on AIX at all. You should be able
to get a decent approximation by setting a PREFIX and passing some specific
paths to configure for where various things go and using a `make install`
workflow.
I did not quickly find an explicit place where I documented this but the
commit message for 87ce2a6f05e313dad43311fba93224f33b86f54f is pretty clear
that `make dest` and libtool do not go well together. It kind of works by
accident on most platforms but is doomed on AIX because libtool on AIX
fundamentally requires re-linking at install time, but `make dest` assumes
that you can "install" to a path and then move the resulting binaries
around without breaking things.
I need to do something else right now but might be able to dig up some
references and write more at some point later.
-Ben
On Sun, Nov 10, 2024 at 11:34:49PM +0000, Ben Huntsman wrote:
> Hi there!
> I'm not super familiar with libtool's inner workings, so I was wondering if someone could help point me in the right direction. On AIX, if we configure with --enable-transarc-paths (though I think this happens even without it), and after the make, run "make dest", the resulting binaries don't work.
>
> I'm currently trying this on AIX 7.1. The shared libraries should end up in rs_aix71/dest/lib. Let's say I try to run afsd:
>
> ./afsd --help
> exec(): 0509-036 Cannot load program ./afsd because of the following errors:
> 0509-150 Dependent module libafshcrypto.a(libafshcrypto.so.2) could not be loaded.
> 0509-022 Cannot load module libafshcrypto.a(libafshcrypto.so.2).
> 0509-026 System error: A file or directory in the path name does not exist.
>
> Ok, expected with shared libraries. On AIX I can set my LD_LIBRARY_PATH to /wherever/rs_aix71/dest/lib, and try again:
>
> $ ./afsd --help
> exec(): 0509-036 Cannot load program ./afsd because of the following errors:
> 0509-150 Dependent module /whereever/rs_aix71/dest/lib/libafshcrypto.a(libafshcrypto.so.2) could not be loaded.
> 0509-152 Member libafshcrypto.so.2 is not found in archive
>
> Let's see what is in that archive:
>
> $ ar t /wherever/rs_aix71/dest/lib/libafshcrypto.a
> aes.o
> camellia.o
> camellia-ntt.o
> des.o
> engine.o
> evp.o
> evp-hcrypto.o
> evp-cc.o
> hmac.o
> md2.o
> md4.o
> md5.o
> pkcs5.o
> rand-egd.o
> rand-timer.o
> rand-unix.o
> rand.o
> rc2.o
> rc4.o
> rijndael-alg-fst.o
> rnd_keys.o
> sha.o
> sha256.o
> sha512.o
> ui.o
> validate.o
> rand-fortuna.o
>
> Sure enough, that's the static archive. Let's see what exists in the build directory:
>
> $ find /wherever -name libafshcrypto.a
> /wherever/lib/libafshcrypto.a
> /wherever/rs_aix71/dest/lib/libafshcrypto.a
> /wherever/src/crypto/hcrypto/.libs/libafshcrypto.a
> /wherever/src/crypto/hcrypto/libafshcrypto.a
>
> Ok, we're interested in the contents of src/crypto/hcrypto/libafshcrypto.a and src/crypto/hcrypto/.libs/libafshcrypto.a:
>
> $ ar t /whereever/src/crypto/hcrypto/libafshcrypto.a
> aes.o
> camellia.o
> camellia-ntt.o
> des.o
> engine.o
> evp.o
> evp-hcrypto.o
> evp-cc.o
> hmac.o
> md2.o
> md4.o
> md5.o
> pkcs5.o
> rand-egd.o
> rand-timer.o
> rand-unix.o
> rand.o
> rc2.o
> rc4.o
> rijndael-alg-fst.o
> rnd_keys.o
> sha.o
> sha256.o
> sha512.o
> ui.o
> validate.o
> rand-fortuna.o
>
> ... That's the static archive...
>
> $ ar t /whereever/src/crypto/hcrypto/.libs/libafshcrypto.a
> libafshcrypto.so.2
>
> Aha, that's the shared library archive!
>
> Now, on AIX, you can have an archive file with both static and shared objects in it. So what we really want here is for the installed libafshcrypto.a to have all the .o files, and also the libafshcrypto.so.2 in it.
>
> Let's look at the "dest" make rule in src/crypto/hcrypto/Makefile:
>
> dest: $(SHARED_LIBS) libafshcrypto.a
> ${LT_INSTALL_DATA} libafshcrypto.la ${DEST}/lib/libafshcrypto.la
> ${RM} ${DEST}/lib/libafshcrypto.la
> ${INSTALL_DATA} libafshcrypto.a ${DEST}/lib/libafshcrypto.a
>
> AHA, that looks like the problem! First we install the shared library, then we overwrite it with the static library! Of course this only breaks on AIX because on AIX the names of the shared and the static libraries are the same. I thought that is what the --with-aix=soname=aix configure option is supposed to take care of, which is the default. Ideally libtool could either build the combined library in src/crypto/hcrypto so that this works as-is, or else the Makefile needs to be heavily reworked with some AIX specifics. This library is just one example out of many, all of them have the same issue on AIX with the "dest" target, as well as the "install" target.
>
> Another alternative that I might prefer, would be for the default on AIX to be to disable shared libraries altogether. This would be more similar to the original IBM AFS. Would that be possible, something everyone could agree on, and anyone know how to do that?
>
> Obviously this is a big problem, as the AIX build doesn't work unless you select only one or the other shared/static library options manually as a ./configure option.
>
> Thanks in advance for any suggestions!
>
> -Ben
>