27ea6a1d53628a7345c5386f759bc99e03fbc507
[openwrt/staging/mkresin.git] / tools / libtool / patches / 150-libtool-mitigate-the-sed_quote_subst-slowdown.patch
1 From 3adadb568fbf15d952bd25a005b6a9afb7e59dc7 Mon Sep 17 00:00:00 2001
2 From: Pavel Raiskup <praiskup@redhat.com>
3 Date: Sun, 4 Oct 2015 21:55:03 +0200
4 Subject: libtool: mitigate the $sed_quote_subst slowdown
5
6 When it is reasonably possible, use shell implementation for
7 quoting.
8
9 References:
10 http://lists.gnu.org/archive/html/libtool/2015-03/msg00005.html
11 http://lists.gnu.org/archive/html/libtool/2015-02/msg00000.html
12 https://debbugs.gnu.org/cgi/bugreport.cgi?bug=20006
13
14 * gl/build-aux/funclib.sh (func_quote): New function that can be
15 used as substitution for '$SED $sed_quote_subst' call.
16 * build-aux/ltmain.in (func_emit_wrapper): Use func_quote instead
17 of '$SED $sed_quote_subst'.
18 (func_mode_link): Likewise.
19 * NEWS: Document.
20 * bootstrap: Sync with funclib.sh.
21
22 (cherry picked from commit 32f0df9835ac15ac17e04be57c368172c3ad1d19)
23 (skipping NEWS change)
24 Signed-off-by: Eneas U de Queiroz <cotequeiroz@gmail.com>
25
26 --- a/bootstrap
27 +++ b/bootstrap
28 @@ -230,7 +230,7 @@ vc_ignore=
29
30 # Source required external libraries:
31 # Set a version string for this script.
32 -scriptversion=2015-01-20.17; # UTC
33 +scriptversion=2015-10-04.22; # UTC
34
35 # General shell script boiler plate, and helper functions.
36 # Written by Gary V. Vaughan, 2004
37 @@ -1257,6 +1257,57 @@ func_relative_path ()
38 }
39
40
41 +# func_quote ARG
42 +# --------------
43 +# Aesthetically quote one ARG, store the result into $func_quote_result. Note
44 +# that we keep attention to performance here (so far O(N) complexity as long as
45 +# func_append is O(1)).
46 +func_quote ()
47 +{
48 + $debug_cmd
49 +
50 + func_quote_result=$1
51 +
52 + case $func_quote_result in
53 + *[\\\`\"\$]*)
54 + case $func_quote_result in
55 + *'*'*|*'['*)
56 + func_quote_result=`$ECHO "$func_quote_result" | $SED "$sed_quote_subst"`
57 + return 0
58 + ;;
59 + esac
60 +
61 + func_quote_old_IFS=$IFS
62 + for _G_char in '\' '`' '"' '$'
63 + do
64 + # STATE($1) PREV($2) SEPARATOR($3)
65 + set start "" ""
66 + func_quote_result=dummy"$_G_char$func_quote_result$_G_char"dummy
67 + IFS=$_G_char
68 + for _G_part in $func_quote_result
69 + do
70 + case $1 in
71 + quote)
72 + func_append func_quote_result "$3$2"
73 + set quote "$_G_part" "\\$_G_char"
74 + ;;
75 + start)
76 + set first "" ""
77 + func_quote_result=
78 + ;;
79 + first)
80 + set quote "$_G_part" ""
81 + ;;
82 + esac
83 + done
84 + IFS=$func_quote_old_IFS
85 + done
86 + ;;
87 + *) ;;
88 + esac
89 +}
90 +
91 +
92 # func_quote_for_eval ARG...
93 # --------------------------
94 # Aesthetically quote ARGs to be evaled later.
95 @@ -1273,12 +1324,8 @@ func_quote_for_eval ()
96 func_quote_for_eval_unquoted_result=
97 func_quote_for_eval_result=
98 while test 0 -lt $#; do
99 - case $1 in
100 - *[\\\`\"\$]*)
101 - _G_unquoted_arg=`printf '%s\n' "$1" |$SED "$sed_quote_subst"` ;;
102 - *)
103 - _G_unquoted_arg=$1 ;;
104 - esac
105 + func_quote "$1"
106 + _G_unquoted_arg=$func_quote_result
107 if test -n "$func_quote_for_eval_unquoted_result"; then
108 func_append func_quote_for_eval_unquoted_result " $_G_unquoted_arg"
109 else
110 --- a/build-aux/ltmain.in
111 +++ b/build-aux/ltmain.in
112 @@ -3356,7 +3356,8 @@ else
113 if test \"\$libtool_execute_magic\" != \"$magic\"; then
114 file=\"\$0\""
115
116 - qECHO=`$ECHO "$ECHO" | $SED "$sed_quote_subst"`
117 + func_quote "$ECHO"
118 + qECHO=$func_quote_result
119 $ECHO "\
120
121 # A function that is used when there is no print builtin or printf.
122 @@ -8618,8 +8619,8 @@ EOF
123 relink_command="$var=$func_quote_for_eval_result; export $var; $relink_command"
124 fi
125 done
126 - relink_command="(cd `pwd`; $relink_command)"
127 - relink_command=`$ECHO "$relink_command" | $SED "$sed_quote_subst"`
128 + func_quote "(cd `pwd`; $relink_command)"
129 + relink_command=$func_quote_result
130 fi
131
132 # Only actually do things if not in dry run mode.
133 @@ -8865,7 +8866,8 @@ EOF
134 done
135 # Quote the link command for shipping.
136 relink_command="(cd `pwd`; $SHELL \"$progpath\" $preserve_args --mode=relink $libtool_args @inst_prefix_dir@)"
137 - relink_command=`$ECHO "$relink_command" | $SED "$sed_quote_subst"`
138 + func_quote "$relink_command"
139 + relink_command=$func_quote_result
140 if test yes = "$hardcode_automatic"; then
141 relink_command=
142 fi
143 --- a/build-aux/funclib.sh
144 +++ b/build-aux/funclib.sh
145 @@ -1,5 +1,5 @@
146 # Set a version string for this script.
147 -scriptversion=2015-01-20.17; # UTC
148 +scriptversion=2015-10-04.22; # UTC
149
150 # General shell script boiler plate, and helper functions.
151 # Written by Gary V. Vaughan, 2004
152 @@ -1026,6 +1026,57 @@ func_relative_path ()
153 }
154
155
156 +# func_quote ARG
157 +# --------------
158 +# Aesthetically quote one ARG, store the result into $func_quote_result. Note
159 +# that we keep attention to performance here (so far O(N) complexity as long as
160 +# func_append is O(1)).
161 +func_quote ()
162 +{
163 + $debug_cmd
164 +
165 + func_quote_result=$1
166 +
167 + case $func_quote_result in
168 + *[\\\`\"\$]*)
169 + case $func_quote_result in
170 + *[\[\*\?]*)
171 + func_quote_result=`$ECHO "$func_quote_result" | $SED "$sed_quote_subst"`
172 + return 0
173 + ;;
174 + esac
175 +
176 + func_quote_old_IFS=$IFS
177 + for _G_char in '\' '`' '"' '$'
178 + do
179 + # STATE($1) PREV($2) SEPARATOR($3)
180 + set start "" ""
181 + func_quote_result=dummy"$_G_char$func_quote_result$_G_char"dummy
182 + IFS=$_G_char
183 + for _G_part in $func_quote_result
184 + do
185 + case $1 in
186 + quote)
187 + func_append func_quote_result "$3$2"
188 + set quote "$_G_part" "\\$_G_char"
189 + ;;
190 + start)
191 + set first "" ""
192 + func_quote_result=
193 + ;;
194 + first)
195 + set quote "$_G_part" ""
196 + ;;
197 + esac
198 + done
199 + IFS=$func_quote_old_IFS
200 + done
201 + ;;
202 + *) ;;
203 + esac
204 +}
205 +
206 +
207 # func_quote_for_eval ARG...
208 # --------------------------
209 # Aesthetically quote ARGs to be evaled later.
210 @@ -1042,12 +1093,8 @@ func_quote_for_eval ()
211 func_quote_for_eval_unquoted_result=
212 func_quote_for_eval_result=
213 while test 0 -lt $#; do
214 - case $1 in
215 - *[\\\`\"\$]*)
216 - _G_unquoted_arg=`printf '%s\n' "$1" |$SED "$sed_quote_subst"` ;;
217 - *)
218 - _G_unquoted_arg=$1 ;;
219 - esac
220 + func_quote "$1"
221 + _G_unquoted_arg=$func_quote_result
222 if test -n "$func_quote_for_eval_unquoted_result"; then
223 func_append func_quote_for_eval_unquoted_result " $_G_unquoted_arg"
224 else