This is the mail archive of the
gcc-patches@gcc.gnu.org
mailing list for the GCC project.
Re: [Patch] Don't call linker when creating pre-compiled header just because you saw a linker option
- From: Steve Ellcey <sellcey at cavium dot com>
- To: Richard Biener <richard dot guenther at gmail dot com>, gcc-patches <gcc-patches at gcc dot gnu dot org>
- Date: Tue, 14 Nov 2017 14:51:46 -0800
- Subject: Re: [Patch] Don't call linker when creating pre-compiled header just because you saw a linker option
- Authentication-results: sourceware.org; auth=none
- Authentication-results: spf=none (sender IP is ) smtp.mailfrom=Steve dot Ellcey at cavium dot com;
- References: <1510685958.4087.4.camel@cavium.com> <B011EBAE-3EF0-43AD-8C08-BBF967D54BE6@gmail.com>
- Reply-to: sellcey at cavium dot com
- Spamdiagnosticmetadata: NSPM
- Spamdiagnosticoutput: 1:99
On Tue, 2017-11-14 at 20:04 +0100, Richard Biener wrote:
>
> I think the intent is to link even for just - lfoo while it makes
> sense to ignore -L/path - Wl,... Certainly counts as possible input.
>
> It seems you even break - lfoo.
>
> Richard.
Good point. I guess I need to take a different approach to determining
if I am creating a PCH or an executable. Here is a new patch that also
passes the testsuite with no regressions. Originally in this patch I
was setting create_pch_flag whenever I saw a '@-cheader' compiler being
called but that broke on things like 'gcc foo.h main.c' so now I only
skip the link phase when creating pch's is the only thing being done.
Steve Ellcey
sellcey@cavium.com
2017-11-14 Steve Ellcey <sellcey@cavium.com>
* gcc.c (create_pch_flag): New variable.
(driver::prepare_infiles): Set create_pch_flag
when we are only creating precompiled headers.
(driver::maybe_run_linker): Do not link if
create_pch_flag is set.
(driver::finalize): Reset create_pch_flag.
diff --git a/gcc/gcc.c b/gcc/gcc.c
index 43e6d59..9df32e3 100644
--- a/gcc/gcc.c
+++ b/gcc/gcc.c
@@ -208,6 +208,9 @@ int is_cpp_driver;
/* Flag set to nonzero if an @file argument has been supplied to gcc. */
static bool at_file_supplied;
+/* Flag set to nonzero if we are generating a precompiled header. */
+static bool create_pch_flag;
+
/* Definition of string containing the arguments given to configure. */
#include "configargs.h"
@@ -8074,6 +8077,8 @@ driver::prepare_infiles ()
{
size_t i;
int lang_n_infiles = 0;
+ bool found_pch_input_file = false;
+ bool found_non_pch_input_file = false;
if (n_infiles == added_libraries)
fatal_error (input_location, "no input files");
@@ -8102,8 +8107,16 @@ driver::prepare_infiles ()
strlen (name),
infiles[i].language);
- if (compiler && !(compiler->combinable))
- combine_inputs = false;
+ if (compiler)
+ {
+ if (!(compiler->combinable))
+ combine_inputs = false;
+
+ if (strcmp(compiler->suffix, "@c-header") == 0)
+ found_pch_input_file = true;
+ else
+ found_non_pch_input_file = true;
+ }
if (lang_n_infiles > 0 && compiler != input_file_compiler
&& infiles[i].language && infiles[i].language[0] != '*')
@@ -8129,6 +8142,9 @@ driver::prepare_infiles ()
fatal_error (input_location,
"cannot specify -o with -c, -S or -E with multiple files");
+ if (found_pch_input_file && !found_non_pch_input_file)
+ create_pch_flag = true;
+
/* No early exit needed from main; we can continue. */
return false;
}
@@ -8289,6 +8305,10 @@ driver::maybe_run_linker (const char *argv0) const
int linker_was_run = 0;
int num_linker_inputs;
+ /* If we are creating a precompiled header, do not run the linker. */
+ if (create_pch_flag)
+ return;
+
/* Determine if there are any linker input files. */
num_linker_inputs = 0;
for (i = 0; (int) i < n_infiles; i++)
@@ -10059,6 +10079,7 @@ driver::finalize ()
is_cpp_driver = 0;
at_file_supplied = 0;
+ create_pch_flag = 0;
print_help_list = 0;
print_version = 0;
verbose_only_flag = 0;