libtool-patches
[Top][All Lists]
Advanced

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

Using getconf to set max_cmd_len


From: Steve Ellcey
Subject: Using getconf to set max_cmd_len
Date: Wed, 30 May 2007 15:58:37 -0700 (PDT)

While integrating a newer libtool into GCC, an issue arose with what
value libtool was setting max_cmd_len to.  This patch uses 'getconf
ARG_MAX' to set lt_cv_sys_max_cmd_len instead of going through a loop to
try and divine the right value, this should give a more accurate value
and should be faster too.  getconf is a Posix command that most
platforms have and we drop into the old behaviour if it doesn't exist.

I originally thought about putting the getconf call before the case
statement (thus skipping the special case handling if getconf exists),
but then I thought it would be better to put the getconf usage into the
generic case only so that people could still have special case targets
if they wanted to avoid using getconf.  If the special case targets want
to use getconf they can just delete their entry from the case statement
and fall into the generic case.

Peter O'Gorman recommended using 3/4 of the value that getconf returned,
so that is what I did.

I wasn't able to test this with the libtool test suite, I couldn't do a
bootstrap and when I just did a "configure;make;make check" with the
daily snapshot it didn't look like the new code was being used.

I did put the patch in my GCC tree and reconfigure and use it that way
and verified that it worked in that context.  Most of the change is just
indentation differences, there is really only a few new lines.

Steve Ellcey
address@hidden


2007-05-30  Steve Ellcey  <address@hidden>

        * libltdl/m4/libtool.m4 (LT_CMD_MAX_LEN): Try using getconf
        to set lt_cv_sys_max_cmd_len.


Index: libtool.m4
===================================================================
RCS file: /sources/libtool/libtool/libltdl/m4/libtool.m4,v
retrieving revision 1.103
diff -u -p -r1.103 libtool.m4
--- libtool.m4  28 May 2007 07:03:25 -0000      1.103
+++ libtool.m4  30 May 2007 22:15:56 -0000
@@ -1437,29 +1437,35 @@ AC_CACHE_VAL([lt_cv_sys_max_cmd_len], [d
     fi
     ;;
   *)
-    # Make teststring a little bigger before we do anything with it.
-    # a 1K string should be a reasonable start.
-    for i in 1 2 3 4 5 6 7 8 ; do
-      teststring=$teststring$teststring
-    done
-    SHELL=${SHELL-${CONFIG_SHELL-/bin/sh}}
-    # If test is not a shell built-in, we'll probably end up computing a
-    # maximum length that is only half of the actual maximum length, but
-    # we can't tell.
-    while { test "X"`$SHELL [$]0 --fallback-echo "X$teststring$teststring" 
2>/dev/null` \
-              = "XX$teststring$teststring"; } >/dev/null 2>&1 &&
-           test $i != 17 # 1/2 MB should be enough
-    do
-      i=`expr $i + 1`
-      teststring=$teststring$teststring
-    done
-    # Only check the string length outside the loop.
-    lt_cv_sys_max_cmd_len=`expr "X$teststring" : ".*" 2>&1`
-    teststring=
-    # Add a significant safety factor because C++ compilers can tack on massive
-    # amounts of additional arguments before passing them to the linker.
-    # It appears as though 1/2 is a usable value.
-    lt_cv_sys_max_cmd_len=`expr $lt_cv_sys_max_cmd_len \/ 2`
+    lt_cv_sys_max_cmd_len=`getconf ARG_MAX 2> /dev/null`
+    if test -n $lt_cv_sys_max_cmd_len; then
+      lt_cv_sys_max_cmd_len=`expr $lt_cv_sys_max_cmd_len \/ 4`
+      lt_cv_sys_max_cmd_len=`expr $lt_cv_sys_max_cmd_len \* 3`
+    else
+      # Make teststring a little bigger before we do anything with it.
+      # a 1K string should be a reasonable start.
+      for i in 1 2 3 4 5 6 7 8 ; do
+        teststring=$teststring$teststring
+      done
+      SHELL=${SHELL-${CONFIG_SHELL-/bin/sh}}
+      # If test is not a shell built-in, we'll probably end up computing a
+      # maximum length that is only half of the actual maximum length, but
+      # we can't tell.
+      while { test "X"`$SHELL [$]0 --fallback-echo "X$teststring$teststring" 
2>/dev/null` \
+                = "XX$teststring$teststring"; } >/dev/null 2>&1 &&
+             test $i != 17 # 1/2 MB should be enough
+      do
+        i=`expr $i + 1`
+        teststring=$teststring$teststring
+      done
+      # Only check the string length outside the loop.
+      lt_cv_sys_max_cmd_len=`expr "X$teststring" : ".*" 2>&1`
+      teststring=
+      # Add a significant safety factor because C++ compilers can tack on
+      # massive amounts of additional arguments before passing them to the
+      # linker.  It appears as though 1/2 is a usable value.
+      lt_cv_sys_max_cmd_len=`expr $lt_cv_sys_max_cmd_len \/ 2`
+    fi
     ;;
   esac
 ])




reply via email to

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