libtool-patches
[Top][All Lists]
Advanced

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

Re: fix order of -L flags added for libtool dep libs


From: Ralf Wildenhues
Subject: Re: fix order of -L flags added for libtool dep libs
Date: Fri, 8 Apr 2005 12:27:16 +0200
User-agent: Mutt/1.4.1i

* Ralf Wildenhues wrote on Tue, Apr 05, 2005 at 09:23:46AM CEST:
> * Alexandre Oliva wrote on Mon, Apr 04, 2005 at 08:57:43PM CEST:
> > On Apr  4, 2005, Alexandre Oliva <address@hidden> wrote:
> > 
> > > The problem here is that, when we relink libA for installation, we
> > > start with tmp_libs="-lB -L/new" (it's in reverse order), and then we
> > > add prepend -lC but *append* -L/old to tmp_libs.  Later on, when we
> > > de-reverse it, we end up searching -L/old before -L/new, so we try to
> > > link with the old -lB, and fail.
> 
> > Err...  Bad patch.  This one should do better.  We have to make sure
> > we add the -L flag such that, after reordering, it shows up before the
> > dep lib.  Doh!
> 
> I have a feeling we fixed this in branch-2-0 and maybe forgot to
> backport.  In any case it would be good to have a test for this.

Here is a patch with a test and your fix.

OK to apply to branch-1-5 and forward-port?
For branch-1-5, I don't care much about cross-compile-induced test
failures, but for branch-2-0 and HEAD I'd like to avoid them.  The
extra test here is so I don't have to change so much porting.

Regards,
Ralf

2005-04-08  Alexandre Oliva  <address@hidden>,
            Ralf Wildenhues  <address@hidden>

        * ltmain.in (link mode): Add to tmp_libs paths for libtool dep
        libs in reverse order as well.
        * tests/defs: Set $build to allow to detect cross-compiles.
        * tests/Makefile.am, tests/linkorder.test: New test.

Index: ltmain.in
===================================================================
RCS file: /cvsroot/libtool/libtool/Attic/ltmain.in,v
retrieving revision 1.334.2.65
diff -u -r1.334.2.65 ltmain.in
--- ltmain.in   16 Mar 2005 17:31:02 -0000      1.334.2.65
+++ ltmain.in   8 Apr 2005 09:15:06 -0000
@@ -2867,12 +2867,12 @@
              *) continue ;;
              esac
              case " $deplibs " in
-             *" $depdepl "*) ;;
-             *) deplibs="$depdepl $deplibs" ;;
+             *" $path "*) ;;
+             *) deplibs="$path $deplibs" ;;
              esac
              case " $deplibs " in
-             *" $path "*) ;;
-             *) deplibs="$deplibs $path" ;;
+             *" $depdepl "*) ;;
+             *) deplibs="$depdepl $deplibs" ;;
              esac
            done
          fi # link_all_deplibs != no
Index: tests/Makefile.am
===================================================================
RCS file: /cvsroot/libtool/libtool/tests/Makefile.am,v
retrieving revision 1.32.2.3
diff -u -r1.32.2.3 Makefile.am
--- tests/Makefile.am   26 Jan 2005 17:53:51 -0000      1.32.2.3
+++ tests/Makefile.am   8 Apr 2005 09:15:07 -0000
@@ -46,7 +46,7 @@
        pdemo-make.test pdemo-exec.test pdemo-inst.test \
        mdemo-conf.test mdemo-make.test mdemo2-conf.test \
        mdemo2-make.test mdemo2-exec.test \
-       func_extract_archives.test 
+       func_extract_archives.test linkorder.test
 
 
 if HAVE_CXX
Index: tests/defs
===================================================================
RCS file: /cvsroot/libtool/libtool/tests/Attic/defs,v
retrieving revision 1.5.2.2
diff -u -r1.5.2.2 defs
--- tests/defs  24 Jun 2004 12:25:33 -0000      1.5.2.2
+++ tests/defs  8 Apr 2005 09:15:07 -0000
@@ -47,6 +47,9 @@
 # Extract host from the libtool configuration
 eval `$libtool --config | grep '^host='`
 
+# Extract build from the libtool configuration
+eval `$libtool --config | grep '^build='`
+
 # Disable usage of config.site for autoconf, unless DJGPP is present.
 # The DJGPP port of autoconf requires config.site, to work correctly.
 if test -z "$DJGPP"; then

--- /dev/null   2005-04-04 11:53:15.417024464 +0200
+++ tests/linkorder.test        2005-04-08 11:26:44.613200240 +0200
@@ -0,0 +1,92 @@
+#! /bin/sh
+# linkorder.test - make sure that library linking order matches
+
+# Test script header.
+need_prefix=no
+if test -z "$srcdir"; then
+  srcdir=`echo "$0" | sed 's%/[^/]*$%%'`
+  test "$srcdir" = "$0" && srcdir=.
+  test "${VERBOSE+set}" != "set" && VERBOSE=yes
+fi
+. $srcdir/defs || exit 1
+
+retcode=0
+
+rm -rf linkorder.dir
+mkdir linkorder.dir
+top_dir=`pwd`/linkorder.dir
+prefix_old=$top_dir/old
+prefix_new=$top_dir/new
+srcdir=linkorder.dir/src
+mkdir $srcdir $prefix_old $prefix_new $prefix_old/lib $prefix_new/lib
+
+cat >$srcdir/c.c <<EOF
+int c = 1;
+EOF
+
+$libtool --mode=compile $CC $CFLAGS -c $srcdir/c.c -o $srcdir/c.lo
+$libtool --mode=link $CC $CFLAGS $LDFLAGS -o $srcdir/libcee.la $srcdir/c.lo \
+    -rpath $prefix_old/lib
+$libtool --mode=install cp $srcdir/libcee.la $prefix_old/lib/libcee.la
+
+for i in old new; do
+  rm -rf $srcdir
+  mkdir $srcdir
+
+  cat >$srcdir/a_$i.c <<EOF
+extern int c;
+extern int b_$i();
+int a_$i() { return c + b_$i(); }
+EOF
+
+  cat >$srcdir/b_$i.c <<EOF
+extern int c;
+int b_$i() { return 1 + c; }
+EOF
+
+  prefix=`eval echo \\$prefix_$i`
+  $libtool --mode=compile $CC $CFLAGS -c $srcdir/a_$i.c -o $srcdir/a.lo
+  $libtool --mode=compile $CC $CFLAGS -c $srcdir/b_$i.c -o $srcdir/b.lo
+  $libtool --mode=link $CC $CFLAGS $LDFLAGS -o $srcdir/libb.la $srcdir/b.lo \
+      -L$prefix_old/lib -lcee -rpath $prefix/lib
+  $libtool --mode=link $CC $CFLAGS -o $srcdir/liba.la $srcdir/a.lo \
+      $srcdir/libb.la -L$prefix_old/lib -lcee -rpath $prefix/lib
+  $libtool --mode=install cp $srcdir/libb.la $prefix/lib/libb.la
+  $libtool --mode=install cp $srcdir/liba.la $prefix/lib/liba.la \
+      >$srcdir/stdout 2>$srcdir/stderr || retcode=1
+  cat $srcdir/stdout
+  cat $srcdir/stderr >&2
+done
+
+# Do not error if we do not relink (e.g. static-only systems)
+if $EGREP relinking $srcdir/stderr; then
+  if $EGREP ' -L.*\/new\/lib -lb -L.*\/old\/lib -lcee' $srcdir/stdout; then :; 
else
+    echo "$0: wrong link order" 1>&2
+    retcode=1
+  fi
+fi
+
+for i in old new; do
+  cat >$srcdir/main_$i.c <<EOF
+extern int a_$i();
+int main(void) { return a_$i() != 3; }
+EOF
+
+  prefix=`eval echo \\$prefix_$i`
+  $libtool --mode=compile $CC $CFLAGS -c $srcdir/main_$i.c -o 
$srcdir/main_$i.lo
+  $libtool --mode=link $CC $CFLAGS $LDFLAGS -o $srcdir/main_$i 
$srcdir/main_$i.lo \
+      -L$prefix/lib -la || retcode=1
+  if $srcdir/main_$i; then :
+  else
+    echo "$0: cannot execute $srcdir/main_$i" 1>&2
+    if test "X$host" != "X$build"; then
+      echo "This may be ok since you seem to be cross-compiling." 1>&2
+      retcode=77
+    else
+      retcode=1
+    fi
+  fi
+done
+
+rm -rf $top_dir
+exit $retcode




reply via email to

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