On Tue, 19 Jun 2018, Steve Ellcey wrote:

> The problem with this is that num_linker_inputs isn't getting
> incremented when it sees a file to be turned into a precompiled header
> it gets incremented when it sees a linker flag like '-rpath'.
> 
> The comments in driver::prepare_infiles make it seem like we are just
> processing a list of file names but when I use something like -Wl,-
> rpath=/foo, the -rpath flag shows up in the list of 'files' that this
> function is processing and that is what causes the routine to set
> explicit_link_files and trigger the link.

In that case this has nothing to do with precompiled headers at all.

What should plain

  gcc -Wl,-rpath=/foo

do?  Whatever it should do regarding trying to link or not trying to link, 
it should do the same if you also name a header on the command line to be 
compiled to a precompiled header.  So if you don't want it to try to link 
when building a precompiled header, you presumably want it to say "gcc: 
fatal error: no input files" just like if you pass some compilation option 
to GCC, rather than trying to run the linker.

So the basic question is: is it valid to link a program (or shared 
library) using *only* -Wl, / -Xlinker to provide input files?  Given that 
those are documented as being for passing options rather than input files 
I think it's reasonable to say it's not valid - so when -Wl, / -Xlinker 
are used, their arguments, stored alongside actual linker input files (any 
non-option that doesn't have a file extension known to be a language 
compiled by GCC), should be marked in some way to indicate that they are 
options not input files and so should not by themselves cause linking to 
be done.

Then there's the question of whether -l<library> counts as an input file 
or an option for this purpose.  Using it as an input file is a bit less 
contrived than using -Wl, options for that purpose - for example, it's 
valid to define main in a shared library (there's a glibc test for this), 
and then you can link a program using just -l<library> without naming any 
object files to link - so I'd be inclined to keep it as an input file, not 
an option.

-- 
Joseph S. Myers
jos...@codesourcery.com

Reply via email to