libtool-patches
[Top][All Lists]
Advanced

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

[PATCH] Fix command line configuration options when used with tags


From: Scott James Remnant
Subject: [PATCH] Fix command line configuration options when used with tags
Date: Sat, 15 Nov 2003 20:39:03 +0000

In both compile and link mode libtool reads the tagged configuration
block after it has parsed the command line options.  The problem is that
some of the options, such as -shared and -static, change the values of
variables that are defined in the tagged configuration.

The easiest way to see this bug is to attempt to use -static when
linking a C++ library:

----8<--------8<--------8<--------8<--------8<--------8<--------8<--------8<----
$ ./libtool_unpatched --mode=link g++ -static -o libcpptest.la cpptest.lo 
-rpath /usr/local/lib
rm -fr  .libs/libcpptest.a .libs/libcpptest.la .libs/libcpptest.lai 
.libs/libcpptest.so .libs/libcpptest.so.0 .libs/libcpptest.so.0.0.0
g++ -shared -nostdlib /usr/lib/gcc-lib/i486-linux/3.3.2/../../../crti.o 
/usr/lib/gcc-lib/i486-linux/3.3.2/crtbeginS.o  .libs/cpptest.o  
-L/usr/lib/gcc-lib/i486-linux/3.3.2 
-L/usr/lib/gcc-lib/i486-linux/3.3.2/../../.. -lstdc++ -lm -lc -lgcc_s 
/usr/lib/gcc-lib/i486-linux/3.3.2/crtendS.o 
/usr/lib/gcc-lib/i486-linux/3.3.2/../../../crtn.o  -Wl,-soname 
-Wl,libcpptest.so.0 -o .libs/libcpptest.so.0.0.0
(cd .libs && rm -f libcpptest.so.0 && ln -s libcpptest.so.0.0.0 
libcpptest.so.0)(cd .libs && rm -f libcpptest.so && ln -s libcpptest.so.0.0.0 
libcpptest.so)
ar cru .libs/libcpptest.a  cpptest.o
ranlib .libs/libcpptest.a
creating libcpptest.la
(cd .libs && rm -f libcpptest.la && ln -s ../libcpptest.la libcpptest.la)

$ ./libtool_patched --mode=link g++ -static -o libcpptest.la cpptest.lo -rpath
elite lt_cmdline% vi libtool elite lt_cmdline% ./libtool --mode=link g++ 
-static -o libcpptest.la cpptest.lo -rpath /usr/local/lib
rm -fr  .libs/libcpptest.a .libs/libcpptest.la .libs/libcpptest.lai 
.libs/libcpptest.so .libs/libcpptest.so.0 .libs/libcpptest.so.0.0.0
ar cru .libs/libcpptest.a  cpptest.o
ranlib .libs/libcpptest.a
creating libcpptest.la
(cd .libs && rm -f libcpptest.la && ln -s ../libcpptest.la libcpptest.la)
---->8-------->8-------->8-------->8-------->8-------->8-------->8-------->8----

For link mode, the patch simply moves the tagged configuration block
above the argument parsing.  The only effect is that $base_compile will
only contain the compiler/linker name (from $nonopt) and no following
arguments or spaces, this doesn't matter fortunately.  Note that we add
a space to $base_compile to keep the rest of the code the same as the
other block (for easy bugfixing purposes later down the line).

Compile mode is a bit trickier (because of -Xcompiler) we need to parse
the command line arguments before we can know which tagged configuration
to use.  So instead we catch those arguments we know change things and
store them in the $later variable, and once we've loaded the tagged
configuration go through this variable to actually do the job we did
above it before.

Scott
-- 
Have you ever, ever felt like this?
Had strange things happen?  Are you going round the twist?

diff -ruNp libtool-CVS~/ChangeLog libtool-CVS/ChangeLog
--- libtool-CVS~/ChangeLog      2003-11-14 12:40:17.000000000 +0000
+++ libtool-CVS/ChangeLog       2003-11-15 10:59:21.000000000 +0000
@@ -0,0 +1,8 @@
+2003-11-15  Scott James Remnant  <address@hidden>
+
+       * ltmain.in: In compile mode, delay parsing of -shared, -static,
+       -prefer-pic and -prefer-non-pic until after tagged configuration
+       has been read.  In link mode, read tagged configuration before
+       parsing any arguments.  These arguments will now work when using
+       a non-C compiler.
+
diff -ruNp libtool-CVS~/ltmain.in libtool-CVS/ltmain.in
--- libtool-CVS~/ltmain.in      2003-11-10 21:07:24.000000000 +0000
+++ libtool-CVS/ltmain.in       2003-11-15 10:56:56.000000000 +0000
@@ -365,6 +365,7 @@ exec_cmd=
     suppress_output=
     arg_mode=normal
     libobj=
+    later=
 
     for arg
     do
@@ -393,29 +394,8 @@ exec_cmd=
          continue
          ;;
 
-       -shared)
-         if test "$build_libtool_libs" != yes; then
-           $echo "$modename: can not build a shared library" 1>&2
-           $echo "Fatal configuration error." 1>&2
-           exit 1
-         fi
-         build_old_libs=no
-         continue
-         ;;
-
-       -static)
-         build_libtool_libs=no
-         build_old_libs=yes
-         continue
-         ;;
-
-       -prefer-pic)
-         pic_mode=yes
-         continue
-         ;;
-
-       -prefer-non-pic)
-         pic_mode=no
+       -shared | -static | -prefer-pic | -prefer-non-pic)
+         later="$later $arg"
          continue
          ;;
 
@@ -565,6 +545,36 @@ exec_cmd=
       esac
     fi
 
+    for arg in $later; do
+      case $arg in
+      -shared)
+       if test "$build_libtool_libs" != yes; then
+         $echo "$modename: can not build a shared library" 1>&2
+         $echo "Fatal configuration error." 1>&2
+         exit 1
+       fi
+       build_old_libs=no
+       continue
+       ;;
+
+      -static)
+       build_libtool_libs=no
+       build_old_libs=yes
+       continue
+       ;;
+
+      -prefer-pic)
+       pic_mode=yes
+       continue
+       ;;
+
+      -prefer-non-pic)
+       pic_mode=no
+       continue
+       ;;
+      esac
+    done
+
     objname=`$echo "X$obj" | $Xsed -e 's%^.*/%%'`
     xdir=`$echo "X$obj" | $Xsed -e 's%/[^/]*$%%'`
     if test "X$xdir" = "X$obj"; then
@@ -891,6 +901,47 @@ EOF
     vinfo=
     vinfo_number=no
 
+    # Infer tagged configuration to use if any are available and
+    # if one wasn't chosen via the "--tag" command line option.
+    # Only attempt this if the compiler in the base link
+    # command doesn't match the default compiler.
+    if test -n "$available_tags" && test -z "$tagname"; then
+      case "$base_compile " in
+      # Blanks in the command may have been stripped by the calling shell,
+      # but not from the CC environment variable when configure was run.
+      "$CC "* | " $CC "* | "`$echo $CC` "* | " `$echo $CC` "*) ;;
+      # Blanks at the start of $base_compile will cause this to fail
+      # if we don't check for them as well.
+      *)
+       for z in $available_tags; do
+         if grep "^# ### BEGIN LIBTOOL TAG CONFIG: $z$" < "$0" > /dev/null; 
then
+           # Evaluate the configuration.
+           eval "`${SED} -n -e '/^# ### BEGIN LIBTOOL TAG CONFIG: '$z'$/,/^# 
### END LIBTOOL TAG CONFIG: '$z'$/p' < $0`"
+           case "$base_compile " in
+           "$CC "* | " $CC "* | "`$echo $CC` "* | " `$echo $CC` "*)
+             # The compiler in $compile_command matches
+             # the one in the tagged configuration.
+             # Assume this is the tagged configuration we want.
+             tagname=$z
+             break
+             ;;
+           esac
+         fi
+       done
+       # If $tagname still isn't set, then no tagged configuration
+       # was found and let the user know that the "--tag" command
+       # line option must be used.
+       if test -z "$tagname"; then
+         $echo "$modename: unable to infer tagged configuration"
+         $echo "$modename: specify a tag with \`--tag'" 1>&2
+         exit 1
+#       else
+#         $echo "$modename: using $tagname tagged configuration"
+       fi
+       ;;
+      esac
+    fi
+
     # We need to know -static, to get the right output filenames.
     for arg
     do
@@ -1667,47 +1718,6 @@ EOF
       exit 1
     fi
 
-    # Infer tagged configuration to use if any are available and
-    # if one wasn't chosen via the "--tag" command line option.
-    # Only attempt this if the compiler in the base link
-    # command doesn't match the default compiler.
-    if test -n "$available_tags" && test -z "$tagname"; then
-      case $base_compile in
-      # Blanks in the command may have been stripped by the calling shell,
-      # but not from the CC environment variable when configure was run.
-      "$CC "* | " $CC "* | "`$echo $CC` "* | " `$echo $CC` "*) ;;
-      # Blanks at the start of $base_compile will cause this to fail
-      # if we don't check for them as well.
-      *)
-       for z in $available_tags; do
-         if grep "^# ### BEGIN LIBTOOL TAG CONFIG: $z$" < "$0" > /dev/null; 
then
-           # Evaluate the configuration.
-           eval "`${SED} -n -e '/^# ### BEGIN LIBTOOL TAG CONFIG: '$z'$/,/^# 
### END LIBTOOL TAG CONFIG: '$z'$/p' < $0`"
-           case $base_compile in
-           "$CC "* | " $CC "* | "`$echo $CC` "* | " `$echo $CC` "*)
-             # The compiler in $compile_command matches
-             # the one in the tagged configuration.
-             # Assume this is the tagged configuration we want.
-             tagname=$z
-             break
-             ;;
-           esac
-         fi
-       done
-       # If $tagname still isn't set, then no tagged configuration
-       # was found and let the user know that the "--tag" command
-       # line option must be used.
-       if test -z "$tagname"; then
-         $echo "$modename: unable to infer tagged configuration"
-         $echo "$modename: specify a tag with \`--tag'" 1>&2
-         exit 1
-#       else
-#         $echo "$modename: using $tagname tagged configuration"
-       fi
-       ;;
-      esac
-    fi
-
     if test "$export_dynamic" = yes && test -n "$export_dynamic_flag_spec"; 
then
       eval arg=\"$export_dynamic_flag_spec\"
       compile_command="$compile_command $arg"

Attachment: signature.asc
Description: This is a digitally signed message part


reply via email to

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