Mainline and 4.7 failed to use LTO when toolchain is installed to a path with space in it. Resulting in error message like:
xxxx/ld.exe: c:/program: error loading plugin collect2.exe: error: ld returned 1 exit status Root cause is when GCC driver process specs, it doesn't handle plugin file name properly. Here is a patch fixing it. Bootstraped and make check on x86 and aarch32, no regression. OK to trunk and 4.7? ChangeLog: PR lto/50293 * gcc.c (convert_white_space): New function. (main): Handles white space in function name. Index: gcc/gcc.c =================================================================== --- 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 * orig); /* The Specs Language @@ -6595,6 +6596,7 @@ X_OK, false); if (lto_wrapper_file) { + lto_wrapper_file = convert_white_space(lto_wrapper_file); lto_wrapper_spec = lto_wrapper_file; obstack_init (&collect_obstack); obstack_grow (&collect_obstack, "COLLECT_LTO_WRAPPER=", @@ -7005,12 +7007,13 @@ + strlen (fuse_linker_plugin), 0)) #endif { - linker_plugin_file_spec = find_a_file (&exec_prefixes, + char * temp_spec = find_a_file (&exec_prefixes, LTOPLUGINSONAME, R_OK, false); - if (!linker_plugin_file_spec) + if (!temp_spec) fatal_error ("-fuse-linker-plugin, but %s not found", LTOPLUGINSONAME); + linker_plugin_file_spec = convert_white_space(temp_spec); } #endif lto_gcc_spec = argv[0]; @@ -8506,3 +8509,30 @@ free (name); return result; } + +/* Insert back slash before spaces in a string, to avoid path + that has space in it broken into multiple arguments. */ + +static char * convert_white_space(char * orig) +{ + int len, number_of_space = 0; + char *p = orig; + if (orig == NULL) return NULL; + + for (len=0; p[len]; len++) + if (p[len] == ' ' || p[len] == '\t') number_of_space ++; + + if (number_of_space) + { + char * new_spec = (char *)xmalloc(len + number_of_space + 1); + int j,k; + for (j=0, k=0; j<=len; j++, k++) + { + if (p[j] == ' ' || p[j] == '\t') new_spec[k++]='\\'; + new_spec[k] = p[j]; + } + free(CONST_CAST(char *, orig)); + return new_spec; + } + else return orig; +}