Subject: Problem when linking non-libNAMEd modules on AIX 6.1

From: Thomas Jahns <[email-masked]>
Date: Mon, 21 Oct 2013 18:13:52 +0200

Hello,

I was investigating a problem with libtool on AIX which occured as part of the
testcase libtool7.sh of automake 1.14.

The test project tries to link via -dlpreopen a module named mod2.la.

libtool then goes on to replace, as can be seen below, mod2.la with -L.libs -lmod2

$ make
/client/bin/bash ./libtool  --tag=CC   --mode=link xlc_r  -q32 -qmaxmem=-1 -O
-o prg prg.o -dlopen libmod1.la -dlpreopen mod2.la
libtool: link: rm -f .libs/prg.nm .libs/prg.nmS .libs/prg.nmT
libtool: link: (cd .libs && xlc_r -q32 -qmaxmem=-1 -O -c "prgS.c")
libtool: link: rm -f ".libs/prgS.c" ".libs/prg.nm" ".libs/prg.nmS" ".libs/prg.nmT"
libtool: link: xlc_r -q32 -qmaxmem=-1 -O -o .libs/prg prg.o .libs/prgS.o
-L./.libs -lmod2
-Wl,-blibpath:/sw/src/autotools/automake-1.14-build/t/libtool7.dir/_inst/lib:/sw/ibm/xlc/11.1.0.8/usr/lib:/sw/ibm/xlc/11.1.0.8/usr/vac/lib:/usr/lib:/lib
ld: 0706-006 Cannot find or open library file: -l mod2
        ld:open(): No such file or directory
make: *** [prg] Error 255

When I make the change to the resolution of dlpreopen modules to libtool (see
attached patch), the problem goes away:

$ make
/client/bin/bash ./libtool  --tag=CC   --mode=link xlc_r  -q32 -qmaxmem=-1 -O
-o prg prg.o -dlopen libmod1.la -dlpreopen mod2.la
libtool: link: rm -f .libs/prg.nm .libs/prg.nmS .libs/prg.nmT
libtool: link: (cd .libs && xlc_r -q32 -qmaxmem=-1 -O -c "prgS.c")
libtool: link: rm -f ".libs/prgS.c" ".libs/prg.nm" ".libs/prg.nmS" ".libs/prg.nmT"
libtool: link: xlc_r -q32 -qmaxmem=-1 -O -o .libs/prg prg.o .libs/prgS.o
-bstatic ./.libs/mod2.a -bdynamic
-Wl,-blibpath:/sw/src/autotools/automake-1.14-build/t/libtool7.dir/_inst/lib:/sw/ibm/xlc/11.1.0.8/usr/lib:/sw/ibm/xlc/11.1.0.8/usr/vac/lib:/usr/lib:/lib

I'm sure my patch is imperfect in that it shouldn't simply switch back to
dynamic mode but instead infer from other flags what the current state of the
link editor was before switching to -bstatic but I don't know how to make that
happern. At least it's working for the moment. Because shared object can be
linked statically on AIX, it would probably also be preferrable to link the
mod2.so file.

Regards, Thomas

host-triplet: powerpc-ibm-aix6.1.0.0
shell: GNU bash 4.0.10(1)-release (powerpc-ibm-aix5.3.0.0
compiler: xlc_r 13.1.0.8
compiler flags: -q32 -qmaxmem=-1 -O
linker: /usr/bin/ld ld: LD 1.65.5.1 (1/10/12)
libtool: 2.4.2
automake 1.14
autoconf 2.69

-- 
Thomas Jahns
DKRZ GmbH, Department: Application software

Deutsches Klimarechenzentrum
Bundesstraße 45a
D-20146 Hamburg

Phone: +49-40-460094-151
Fax: +49-40-460094-270
Email: Thomas Jahns <[email-masked]>
--- b/libtool	2013-10-21 13:20:11.000000000 +0200
+++ a/libtool	2013-10-21 17:37:48.000000000 +0200
@@ -7248,10 +7248,10 @@
 		esac
 	      elif test "$hardcode_minus_L" = no; then
 		case $host in
-		*-*-sunos*) add_shlibpath="$dir" ;;
+		*-*-sunos*) add_shlibpath="$dir" ; add_dir="-L$dir" ; add="-l$name" ;;
+                *-*-aix*) add="-bdynamic $dir/$linklib -bstatic" ;;
+                *) add_dir="-L$dir" ; add="-l$name" ;;
 		esac
-		add_dir="-L$dir"
-		add="-l$name"
 	      elif test "$hardcode_shlibpath_var" = no; then
 		add_shlibpath="$dir"
 		add="-l$name"