libtool-patches
[Top][All Lists]
Advanced

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

Patch for Libtool : partial linking of .lo objects


From: Marc Alff
Subject: Patch for Libtool : partial linking of .lo objects
Date: Fri, 07 Apr 2006 04:27:22 -0700
User-agent: Mozilla Thunderbird 1.0.7 (X11/20060327)


Hi Ralf and all

From a previous discussion on automake :

RW> If you want to get libtool-for-shared-libraries into play, then the
RW> sensible thing IMHO would be to have libtool objects named .lo which
RW> themselves are created by two partial links: the non-PIC *.o go into
RW> output.o, the PIC ones [._]libs/*.o go into [._]libs/output.o.

RW> Yes, Libtool does not do this ATM.  This is a bug.  I don't mind
RW> breaking compatibility here, as that hasn't worked well for a long time.

RW> Marc, to make this very clear to you: At the moment, this:

RW>   $LIBTOOL --mode=link -o glued.lo input.lo

RW> translates to
RW>   ld -r -o glued.lo .libs/input.o

RW> but that is not consistent, and comes from a very old libtool age when
RW> the PIC objects were named object.lo and not .libs/object.o!  And it
RW> will cause subsequent links using glued.lo to fail.  What should happen
RW> instead is this:
RW>   ld -r -o .libs/glued.o .libs/input.o
RW>   ld -r -o glued.o input.o
RW>   creating libtool objects glued.lo

RW> and then "glued.lo" will be a short script just as input.lo is
RW> (with the obvious skipping of steps when either PIC or non-PIC
RW> objects are disabled).

Well, I tried to see how to change libtool to address that, and I eventually found what code to fix,
so here is a proposed patch :

See the attached file.

The patch is based on Libtool-1.5.23a (CVS)

With this change :

   $LIBTOOL --mode=link $CC -o all.o a.o b.o

results in something like :

   /usr/x86_64-pc-linux-gnu/bin/ld -m elf_x86_64 -r -o all.o a.o b.o

and

   $LIBTOOL --mode=link $CC -o all.lo a.lo b.lo

results in something like :

   /usr/x86_64-pc-linux-gnu/bin/ld -m elf_x86_64 -r -o all.o  a.o b.o
/usr/x86_64-pc-linux-gnu/bin/ld -m elf_x86_64 -r -o .libs/all.o .libs/a.o .libs/b.o
   creating libtool object all.lo

As I am totally new to the Libtool code base (and the file ltmain.in),
so this patch needs review of course.

Please let me know what you think of it, if any code needs to be adjusted,
or if you need more things from me (paperwork for Libtool ?).

The patch includes a test also :)

Cheers,
Marc Alff.


diff -Naur libtool/ChangeLog libtool-reloc/ChangeLog
--- libtool/ChangeLog   2006-03-28 18:12:50.000000000 +0000
+++ libtool-reloc/ChangeLog     2006-04-07 10:55:44.000000000 +0000
@@ -1,3 +1,12 @@
+2006-04-07 Marc Alff <address@hidden>
+
+       * ltmain.in (link mode) <reload_cmds>: Fixed generated commands
+       when performing partial link against libtool objects (*.lo).
+       * tests/link-reload.test: new test.
+       * tests/Makefile.am: adjust.
+       Bug reported by Ralf Wildenhues  <address@hidden>,
+       patch by Marc Alff <address@hidden>.
+
 2006-03-28  Ralf Wildenhues  <address@hidden>
 
        * libtool.m4 (AC_LIBTOOL_SYS_DYNAMIC_LINKER) [ linux ]:
diff -Naur libtool/ltmain.in libtool-reloc/ltmain.in
--- libtool/ltmain.in   2006-04-07 10:17:59.000000000 +0000
+++ libtool-reloc/ltmain.in     2006-04-07 10:55:44.000000000 +0000
@@ -4292,7 +4292,7 @@
       fi
 
       # Create the old-style object.
-      reload_objs="$objs$old_deplibs "`$echo "X$libobjs" | $SP2NL | $Xsed -e 
'/\.'${libext}$'/d' -e '/\.lib$/d' -e "$lo2o" | $NL2SP`" $reload_conv_objs" ### 
testsuite: skip nested quoting test
+      reload_objs="$objs$old_deplibs "`$echo "X$non_pic_objects" | $SP2NL | 
$Xsed -e '/\.'${libext}$'/d' -e '/\.lib$/d' -e "$lo2o" | $NL2SP`" 
$reload_conv_objs" ### testsuite: skip nested quoting test
 
       output="$obj"
       cmds=$reload_cmds
@@ -4331,7 +4331,7 @@
       if test -n "$pic_flag" || test "$pic_mode" != default; then
        # Only do commands if we really have different PIC objects.
        reload_objs="$libobjs $reload_conv_objs"
-       output="$libobj"
+       output="$objdir/$obj"
        cmds=$reload_cmds
        save_ifs="$IFS"; IFS='~'
        for cmd in $cmds; do
@@ -4343,6 +4343,26 @@
        IFS="$save_ifs"
       fi
 
+    $run $rm "$libobj"
+
+    $show "creating libtool object $libobj"
+
+    # Create a libtool object file (analogous to a ".la" file),
+    # but don't create it if we're doing a dry run.
+    test -z "$run" && cat > ${libobj} <<EOF
+# $libobj - a libtool object file
+# Generated by $PROGRAM - GNU $PACKAGE $VERSION$TIMESTAMP
+#
+# Please DO NOT delete this file!
+# It is necessary for linking the library.
+
+# Name of the PIC object.
+pic_object='$objdir/$obj'
+
+# Name of the non-PIC object.
+non_pic_object='$obj'
+EOF
+
       if test -n "$gentop"; then
        $show "${rm}r $gentop"
        $run ${rm}r $gentop
diff -Naur libtool/tests/Makefile.am libtool-reloc/tests/Makefile.am
--- libtool/tests/Makefile.am   2006-04-07 10:18:50.000000000 +0000
+++ libtool-reloc/tests/Makefile.am     2006-04-07 10:55:44.000000000 +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 \
-       duplicate_members.test link-order.test
+       duplicate_members.test link-order.test link-reload.test
 
 if HAVE_CXX
 if HAVE_F77
diff -Naur libtool/tests/link-reload.test libtool-reloc/tests/link-reload.test
--- libtool/tests/link-reload.test      1970-01-01 00:00:00.000000000 +0000
+++ libtool-reloc/tests/link-reload.test        2006-04-07 10:55:44.000000000 
+0000
@@ -0,0 +1,71 @@
+#! /bin/sh
+# Copyright (C) 2006  Free Software Foundation, Inc.
+#
+# This file is part of GNU Libtool.
+#
+# GNU Libtool is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2, or (at your option)
+# any later version.
+#
+# GNU Libtool is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with Libtool; see the file COPYING.  If not, write to
+# the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
+# Boston, MA 02110-1301, USA.
+
+# link-reload.test - make sure that linking reloadable objects works.
+# Written by Marc Alff
+
+# 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
+
+set -e
+
+. $srcdir/defs
+
+# Expected linker
+$libtool --config | grep "^LD=" | sed -e "s/^LD=\"//g" -e "s/\"$//g" > 
expected_ld
+export expected_ld=`cat expected_ld`
+
+# Expected linker flag
+$libtool --config | grep "^reload_flag=" | sed -e "s/^reload_flag=\"//g" -e 
"s/\"$//g" > expected_ld_flag
+export expected_ld_flag=`cat expected_ld_flag`
+
+# Try a sample link command with non PIC objects
+echo "Test 1"
+$libtool -n --mode=link $CC -o all.o a.o b.o > linkresult
+test $? -eq 0
+
+echo "Actual result"
+cat linkresult
+echo "Expected result"
+grep "$expected_ld$expected_ld_flag -o all\.o a\.o b\.o" linkresult
+
+# Try a sample link command with PIC objects
+echo "Test 2"
+$libtool -n --mode=link $CC -o all.lo a.lo b.lo > linkresult
+test $? -eq 0
+
+echo "Actual result"
+cat linkresult
+echo "Expected result"
+## FIXME : annoying extra space
+grep "$expected_ld$expected_ld_flag -o all\.o  a\.o b\.o" linkresult
+grep "$expected_ld$expected_ld_flag -o \.libs/all\.o \.libs/a\.o \.libs/b\.o" 
linkresult
+grep "creating libtool object all\.lo" linkresult
+
+rm -f linkresult
+rm -f expected_ld
+rm -f expected_ld_flag
+
+exit 0

reply via email to

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