From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 11017 invoked by alias); 4 Mar 2013 08:11:30 -0000 Received: (qmail 11007 invoked by uid 22791); 4 Mar 2013 08:11:28 -0000 X-SWARE-Spam-Status: No, hits=-0.5 required=5.0 tests=AWL,BAYES_50,KHOP_RCVD_UNTRUST,KHOP_SPAMHAUS_DROP,KHOP_THREADED,MSGID_MULTIPLE_AT,RCVD_IN_DNSWL_LOW X-Spam-Check-By: sourceware.org Received: from service87.mimecast.com (HELO service87.mimecast.com) (91.220.42.44) by sourceware.org (qpsmtpd/0.43rc1) with ESMTP; Mon, 04 Mar 2013 08:11:21 +0000 Received: from cam-owa1.Emea.Arm.com (fw-tnat.cambridge.arm.com [217.140.96.21]) by service87.mimecast.com; Mon, 04 Mar 2013 08:11:19 +0000 Received: from E103005 ([10.1.255.212]) by cam-owa1.Emea.Arm.com with Microsoft SMTPSVC(6.0.3790.0); Mon, 4 Mar 2013 08:11:16 +0000 From: "Joey Ye" To: "'Joseph Myers'" Cc: References: <000001ce0cb4$6b491000$41db3000$@ye@arm.com> <000101ce0d88$7febdb80$7fc39280$@ye@arm.com> In-Reply-To: Subject: RE: [PATCH] Fix PR50293 - LTO plugin with space in path Date: Mon, 04 Mar 2013 08:11:00 -0000 Message-ID: <000101ce18af$c9e89750$5db9c5f0$@ye@arm.com> MIME-Version: 1.0 X-MC-Unique: 113030408111903201 Content-Type: multipart/mixed; boundary="----=_NextPart_000_0002_01CE18F2.D80BD750" Mailing-List: contact gcc-patches-help@gcc.gnu.org; run by ezmlm Precedence: bulk List-Id: List-Archive: List-Post: List-Help: Sender: gcc-patches-owner@gcc.gnu.org X-SW-Source: 2013-03/txt/msg00089.txt.bz2 This is a multi-part message in MIME format. ------=_NextPart_000_0002_01CE18F2.D80BD750 Content-Type: text/plain; charset=WINDOWS-1252 Content-Transfer-Encoding: quoted-printable Content-length: 6257 > -----Original Message----- > From: Joseph Myers [mailto:joseph@codesourcery.com] > Sent: Monday, March 04, 2013 00:49 > To: Joey Ye > Cc: gcc-patches@gcc.gnu.org > Subject: RE: [PATCH] Fix PR50293 - LTO plugin with space in path >=20 > On Mon, 18 Feb 2013, Joey Ye wrote: >=20 > > +static char * convert_white_space (char *); >=20 > No space after "*". Fixed >=20 > > - linker_plugin_file_spec =3D find_a_file (&exec_prefixes, > > + char * temp_spec =3D find_a_file (&exec_prefixes, > > LTOPLUGINSONAME, R_OK, > > false); >=20 > The indentation of the following lines looks odd after this patch; > unless > that's just an effect of TABs plus quoting, make sure they are > reindented > to line up with the new position of the opening '('. They was unchanged. But since the line with '(' changed, it need changing too. Fixed >=20 > > +/* Insert back slash before spaces in orig (usually a file path), to >=20 > Capitalize variable names when referring to the value of the variable, > so > ORIG; likewise elsewhere in this comment. Single work "backslash". >=20 > > + the filename should be treated as a single argument rather than > being >=20 > "file name" should be two words, according to the GNU Coding Standards. >=20 > > + This function converts and only converts all occurrance of ' ' >=20 > "occurrence" >=20 > > + Return: orig if no conversion needed. orig if conversion needed > but no > > + sufficient memory for a new string. Otherwise a newly allocated > string >=20 > Returning wrong results on insufficient memory doesn't make sense. > Anyway, xmalloc always exits the program if there is insufficient memory, > so you don't need any code to allow for that case. Fixed. Though it is conflicting with secure coding practice. >=20 > > +static char * convert_white_space (char *orig) >=20 > Newline, not space, between return type and function name, so that the > function name comes at the start of the line. Fixed. >=20 > > + if (orig =3D=3D NULL) return orig; >=20 > The comment didn't mention NULL as a valid argument, and it doesn't > appear > NULL can actually be passed to this function. So don't include code to > handle that case. Fixed. >=20 > > + for (len=3D0; orig[len]; len++) >=20 > Spaces around "=3D". Fixed. >=20 > > + if (orig[len] =3D=3D ' ' || orig[len] =3D=3D '\t') number_of_space= ++; >=20 > No space before "++", but put the body of the "if" on a separate line. Fixed. >=20 > > + char * new_spec =3D (char *)xmalloc (len + number_of_space + 1); >=20 > No space after "*". Space in the cast after "(char *)". Fixed. >=20 > > + int j,k; >=20 > Space after ",". Fixed. >=20 > > + if (new_spec =3D=3D NULL) return orig; >=20 > As discussed above, not needed. Removed. >=20 > > + for (j=3D0, k=3D0; j<=3Dlen; j++, k++) >=20 > Spaces around "=3D" and "<=3D". Fixed. >=20 > > + if (orig[j] =3D=3D ' ' || orig[j] =3D=3D '\t') new_spec[k++] =3D '\= \'; >=20 > Put the "if" both on a separate line. Fixed. >=20 > > + else return orig; >=20 > Put the "else" body on a separate line. Fixed. >=20 > -- > Joseph S. Myers > joseph@codesourcery.com Index: gcc/gcc.c =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D --- gcc/gcc.c (revision 195189) +++ gcc/gcc.c (working copy) @@ -265,6 +265,7 @@ static const char *compare_debug_auxbase_opt_spec_function (int, const char **); static const char *pass_through_libs_spec_func (int, const char **); static const char *replace_extension_spec_func (int, const char **); +static char *convert_white_space (char *); =20 /* The Specs Language =20 @@ -6595,6 +6596,7 @@ X_OK, false); if (lto_wrapper_file) { + lto_wrapper_file =3D convert_white_space (lto_wrapper_file); lto_wrapper_spec =3D lto_wrapper_file; obstack_init (&collect_obstack); obstack_grow (&collect_obstack, "COLLECT_LTO_WRAPPER=3D", @@ -7005,12 +7007,13 @@ + strlen (fuse_linker_plugin), 0)) #endif { - linker_plugin_file_spec =3D find_a_file (&exec_prefixes, - LTOPLUGINSONAME, R_OK, - false); - if (!linker_plugin_file_spec) + char *temp_spec =3D find_a_file (&exec_prefixes, + LTOPLUGINSONAME, R_OK, + false); + if (!temp_spec) fatal_error ("-fuse-linker-plugin, but %s not found", LTOPLUGINSONAME); + linker_plugin_file_spec =3D convert_white_space (temp_spec); } #endif lto_gcc_spec =3D argv[0]; @@ -8506,3 +8509,51 @@ free (name); return result; } + +/* Insert backslash before spaces in ORIG (usually a file path), to=20 + avoid being broken by spec parser. + + This function is needed as do_spec_1 treats white space (' ' and '\t') + as the end of an argument. But in case of -plugin /usr/gcc install/xxx.so, + the file name should be treated as a single argument rather than being + broken into multiple. Solution is to insert '\\' before the space in a= =20 + file name. +=20=20=20 + This function converts and only converts all occurrence of ' '=20 + to '\\' + ' ' and '\t' to '\\' + '\t'. For example: + "a b" -> "a\\ b" + "a b" -> "a\\ \\ b" + "a\tb" -> "a\\\tb" + "a\\ b" -> "a\\\\ b" + + orig: input null-terminating string that was allocated by xalloc. The + memory it points to might be freed in this function. Behavior undefined + if ORIG wasn't xalloced or was freed already at entry. + + Return: ORIG if no conversion needed. Otherwise a newly allocated string + that was converted from ORIG. */ + +static char * +convert_white_space (char *orig) +{ + int len, number_of_space =3D 0; + + for (len =3D 0; orig[len]; len++) + if (orig[len] =3D=3D ' ' || orig[len] =3D=3D '\t') number_of_space++; + + if (number_of_space) + { + char *new_spec =3D (char *)xmalloc (len + number_of_space + 1); + int j, k; + for (j =3D 0, k =3D 0; j <=3D len; j++, k++) + { + if (orig[j] =3D=3D ' ' || orig[j] =3D=3D '\t') + new_spec[k++] =3D '\\'; + new_spec[k] =3D orig[j]; + } + free (orig); + return new_spec; + } + else + return orig; +}= ------=_NextPart_000_0002_01CE18F2.D80BD750 Content-Type: text/plain; name=space_in_plugin_spec-20130304.patch.txt Content-Transfer-Encoding: quoted-printable Content-Disposition: attachment; filename="space_in_plugin_spec-20130304.patch.txt" Content-length: 3110 Index: gcc/gcc.c =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D --- gcc/gcc.c (revision 195189) +++ gcc/gcc.c (working copy) @@ -265,6 +265,7 @@ static const char *compare_debug_auxbase_opt_spec_function (int, const cha= r **); static const char *pass_through_libs_spec_func (int, const char **); static const char *replace_extension_spec_func (int, const char **); +static char *convert_white_space (char *); =0C /* The Specs Language =20 @@ -6595,6 +6596,7 @@ X_OK, false); if (lto_wrapper_file) { + lto_wrapper_file =3D convert_white_space (lto_wrapper_file); lto_wrapper_spec =3D lto_wrapper_file; obstack_init (&collect_obstack); obstack_grow (&collect_obstack, "COLLECT_LTO_WRAPPER=3D", @@ -7005,12 +7007,13 @@ + strlen (fuse_linker_plugin), 0)) #endif { - linker_plugin_file_spec =3D find_a_file (&exec_prefixes, - LTOPLUGINSONAME, R_OK, - false); - if (!linker_plugin_file_spec) + char *temp_spec =3D find_a_file (&exec_prefixes, + LTOPLUGINSONAME, R_OK, + false); + if (!temp_spec) fatal_error ("-fuse-linker-plugin, but %s not found", LTOPLUGINSONAME); + linker_plugin_file_spec =3D convert_white_space (temp_spec); } #endif lto_gcc_spec =3D argv[0]; @@ -8506,3 +8509,51 @@ free (name); return result; } + +/* Insert backslash before spaces in ORIG (usually a file path), to=20 + avoid being broken by spec parser. + + This function is needed as do_spec_1 treats white space (' ' and '\t') + as the end of an argument. But in case of -plugin /usr/gcc install/xxx.= so, + the file name should be treated as a single argument rather than being + broken into multiple. Solution is to insert '\\' before the space in a= =20 + file name. +=20=20=20 + This function converts and only converts all occurrence of ' '=20 + to '\\' + ' ' and '\t' to '\\' + '\t'. For example: + "a b" -> "a\\ b" + "a b" -> "a\\ \\ b" + "a\tb" -> "a\\\tb" + "a\\ b" -> "a\\\\ b" + + orig: input null-terminating string that was allocated by xalloc. The + memory it points to might be freed in this function. Behavior undefined + if ORIG wasn't xalloced or was freed already at entry. + + Return: ORIG if no conversion needed. Otherwise a newly allocated string + that was converted from ORIG. */ + +static char * +convert_white_space (char *orig) +{ + int len, number_of_space =3D 0; + + for (len =3D 0; orig[len]; len++) + if (orig[len] =3D=3D ' ' || orig[len] =3D=3D '\t') number_of_space++; + + if (number_of_space) + { + char *new_spec =3D (char *)xmalloc (len + number_of_space + 1); + int j, k; + for (j =3D 0, k =3D 0; j <=3D len; j++, k++) + { + if (orig[j] =3D=3D ' ' || orig[j] =3D=3D '\t') + new_spec[k++] =3D '\\'; + new_spec[k] =3D orig[j]; + } + free (orig); + return new_spec; + } + else + return orig; +} ------=_NextPart_000_0002_01CE18F2.D80BD750--