This is the mail archive of the gcc-patches@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: [Patch] Do not call the linker if we are creating precompiled header files


Ping.

Steve Ellcey
sellcey@cavium.com


On Wed, 2018-05-02 at 12:47 -0700, Steve Ellcey wrote:
> This is a new version of a patch I sent out last year to stop gcc from
> trying to do a link when creating precompiled headers and a linker
> flag is also given.
> 
> When I build and test GCC I also build glibc and then I run the GCC tests
> with -Wl,-rpath and -Wl,--dynamic-linker so that I don't have to install
> glibc and the compiler in the default locations.  When I do this some
> precompiled header tests fail because the existance of the linker flags
> causes the compiler to try and call the linker when we really just want to
> create pch files.
> 
> I tracked this down to driver::maybe_run_linker where it sees the linker
> flags and increments num_linker_inputs, this causes the routine to call
> the linker.   This patch checks to see if we are creating precompiled
> header files and avoids calling the linker in that case.
> 
> I tested this with the GCC testsuite and got no regressions, OK to
> checkin?
> 
> Steve Ellcey
> sellcey@cavium.com
> 
> 
> 2018-05-02  Steve Ellcey  <sellcey@cavium.com>
> 
> 	* gcc.c (create_pch_flag): New variable.
> 	(driver::prepare_infiles): Set create_pch_flag
> 	when we are 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 a716f70..ca986cf 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"
>  
> @@ -8095,8 +8098,15 @@ driver::prepare_infiles ()
>  						   strlen (name),
>  						   infiles[i].langua
> ge);
>  
> -      if (compiler && !(compiler->combinable))
> -	combine_inputs = false;
> +      if (compiler)
> +	{
> +	  if (!(compiler->combinable))
> +	    combine_inputs = false;
> +
> +	  if ((strcmp(compiler->suffix, "@c-header") == 0)
> +	      || (strcmp(compiler->suffix, "@c++-header") == 0))
> +	    create_pch_flag = true;
> +	}
>  
>        if (lang_n_infiles > 0 && compiler != input_file_compiler
>  	  && infiles[i].language && infiles[i].language[0] != '*')
> @@ -8282,6 +8292,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++)
> @@ -10052,6 +10066,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;


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]