Subject: Re: bug#13472: [PATCH] libtool: speed up by pre-cutting sed's input by dd

From: Peter Rosin <[email-masked]>
Date: Thu, 13 Feb 2014 20:52:59 +0100

On 2014-02-13 18:57, Peter Rosin wrote:
> On 2014-02-12 16:22, Nick Bowler wrote:
>> On 2/11/14, Peter Rosin <[email-masked]> wrote:
>>> Ok Pavel, first of all, sorry for the "smallish" delay in handling
>>> your request, and Nick, are you able to test this patch?
>> [...]
>>> Does my version work? The testsuite behaves OK for me, but other than
>>> that I haven't tested.
>>
>> Patch seems to work!
> 
> Ok, everybody seems happy. But not me, not 100% anyway. This introduces
> an extra fork, and AFAICT, the "extra protection" is only needed when
> func_lalib_p is called from func_ltwrapper_script_p. Should we perhaps
> have a separate implementation in func_ltwrapper_script_p instead of
> simply calling func_lalib_p?
> 
> Maybe we could also lose the "sed -e 4q" part when dd limits the size?

*snip* outline, real patch attached instead...

Now, which patch should I push?

The old [1]:
libtool: speed up lalib detection in execute mode

or the new?
libtool: speed up ltwrapper_script detection in execute mode

I like the latter better and will push that soonish. Unless...

Cheers,
Peter

[1] http://lists.gnu.org/archive/html/bug-libtool/2014-02/msg00005.html
>From d93a003e6189c0c8f9f91ef6e48b3a65063979da Mon Sep 17 00:00:00 2001
From: Peter Rosin <[email-masked]>
Date: Thu, 13 Feb 2014 20:22:42 +0100
Subject: [PATCH] libtool: speed up ltwrapper_script detection in execute mode

Execute mode is slow and might even DOS the computer in extreme
cases when a parameter is a big binary file without newlines.
Work around this with different truncation if a suitable dd
utility is found.

Fixes bug#13472 and bug#16662.

Reported by Pavel Raiskup and Nick Bowler.

* m4/libtool.m4 (_LT_CMD_TRUNCATE): New macro, for finding out
how to truncate binary pipes (fallback to the old sed truncation
if no suitable dd is found).
(_LT_SETUP): Require _LT_CMD_TRUNCATE.
* build_aux/ltmain.in (func_ltwrapper_script_p): Truncate the
pipe according to _LT_CMD_TRUNCATE.
* THANKS: Update.

Signed-off-by: Peter Rosin <[email-masked]>
---
 THANKS              |    2 ++
 build-aux/ltmain.in |    4 +++-
 m4/libtool.m4       |   22 ++++++++++++++++++++++
 3 files changed, 27 insertions(+), 1 deletions(-)

diff --git a/THANKS b/THANKS
index e895aee..85c5150 100644
--- a/THANKS
+++ b/THANKS
@@ -150,6 +150,7 @@
   Mike Gorchak			[email-masked]
   Mike Frysinger		[email-masked]
   Mike Miller			[email-masked]
+  Nick Bowler			[email-masked]
   Nix				[email-masked]
   Olaf Lenz			[email-masked]
   Olly Betts			[email-masked]
@@ -161,6 +162,7 @@
   Paul Eggert			[email-masked]
   Paul Laight			[email-masked]
   Paul Seidler			[email-masked]
+  Pavel Raiskup			[email-masked]
   Paweł Daniluk			[email-masked]
   Peter Eisentraut		[email-masked]
   Peter Fritzsche		[email-masked]
diff --git a/build-aux/ltmain.in b/build-aux/ltmain.in
index f8e0f5f..b013688 100644
--- a/build-aux/ltmain.in
+++ b/build-aux/ltmain.in
@@ -610,7 +610,9 @@ func_lalib_unsafe_p ()
 # determined imposters.
 func_ltwrapper_script_p ()
 {
-    func_lalib_p "$1"
+    test -f "$1" &&
+      $lt_truncate_bin < "$1" 2>/dev/null \
+        | $GREP "^# Generated by .*$PACKAGE" > /dev/null 2>&1
 }
 
 # func_ltwrapper_executable_p file
diff --git a/m4/libtool.m4 b/m4/libtool.m4
index ce58f31..b9ac7f8 100644
--- a/m4/libtool.m4
+++ b/m4/libtool.m4
@@ -169,6 +169,7 @@ m4_require([_LT_CHECK_SHAREDLIB_FROM_LINKLIB])dnl
 m4_require([_LT_CMD_OLD_ARCHIVE])dnl
 m4_require([_LT_CMD_GLOBAL_SYMBOLS])dnl
 m4_require([_LT_WITH_SYSROOT])dnl
+m4_require([_LT_CMD_TRUNCATE])dnl
 
 _LT_CONFIG_LIBTOOL_INIT([
 # See if we are running on zsh, and set the options that allow our
@@ -3216,6 +3217,27 @@ _LT_TAGDECL([], [reload_cmds], [2])dnl
 ])# _LT_CMD_RELOAD

+# _LT_CMD_TRUNCATE
+# ----------------
+# find command to truncate a binary pipe
+m4_defun([_LT_CMD_TRUNCATE],
+[AC_PATH_PROG([DD], [dd])
+test -z "$DD" && DD=dd
+
+AC_CACHE_CHECK([how to truncate binary pipes], [lt_cv_truncate_bin],
+[lt_cv_truncate_bin="$SED -e 4q"
+printf 0123456789abcdef0123456789abcdef >conftest.i
+cat conftest.i conftest.i >conftest2.i
+if "$DD" bs=32 count=1 <conftest2.i >conftest.out 2>/dev/null; then
+  cmp -s conftest.i conftest.out && lt_cv_truncate_bin="$DD bs=4096 count=1"
+fi
+rm -f conftest.i conftest2.i conftest.out])
+
+_LT_DECL([lt_truncate_bin], [lt_cv_truncate_bin], [1],
+  [Command to truncate a binary pipe])
+])# _LT_CMD_TRUNCATE
+
+
 # _LT_CHECK_MAGIC_METHOD
 # ----------------------
 # how to check for library dependencies
-- 
1.7.9