public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
* Re: [PATCH] Generalize -fuse-ld= to support absolute path or arbitrary ld.linker
@ 2021-06-26 14:44 Artur Sinila
  2021-06-28 12:08 ` Martin Liška
  0 siblings, 1 reply; 13+ messages in thread
From: Artur Sinila @ 2021-06-26 14:44 UTC (permalink / raw)
  To: gcc-patches; +Cc: H.J. Lu, Jan Hubicka, Martin Liska

[-- Attachment #1: Type: text/plain, Size: 83 bytes --]

Not so gentle ping :)
What should happen in order for this patch to be accepted?

[-- Attachment #2: This is a digitally signed message part --]
[-- Type: application/pgp-signature, Size: 269 bytes --]

^ permalink raw reply	[flat|nested] 13+ messages in thread

* Re: [PATCH] Generalize -fuse-ld= to support absolute path or arbitrary ld.linker
  2021-06-26 14:44 [PATCH] Generalize -fuse-ld= to support absolute path or arbitrary ld.linker Artur Sinila
@ 2021-06-28 12:08 ` Martin Liška
  2021-06-28 12:24   ` Artur Sinila
  0 siblings, 1 reply; 13+ messages in thread
From: Martin Liška @ 2021-06-28 12:08 UTC (permalink / raw)
  To: freesoftware, gcc-patches; +Cc: H.J. Lu, Jan Hubicka

On 6/26/21 4:44 PM, Artur Sinila wrote:
> Not so gentle ping :)
> What should happen in order for this patch to be accepted?
> 

Hello.

We came up to conclusion that one can use the currently supported option
-fuse-ld={bfd,gold,lld} with -B that can point to an arbitrary path
the such linker is expected.

Cheers,
Martin

^ permalink raw reply	[flat|nested] 13+ messages in thread

* Re: [PATCH] Generalize -fuse-ld= to support absolute path or arbitrary ld.linker
  2021-06-28 12:08 ` Martin Liška
@ 2021-06-28 12:24   ` Artur Sinila
  2021-06-28 13:26     ` Martin Liška
  0 siblings, 1 reply; 13+ messages in thread
From: Artur Sinila @ 2021-06-28 12:24 UTC (permalink / raw)
  To: Martin Liška, gcc-patches; +Cc: H.J. Lu, Jan Hubicka

[-- Attachment #1: Type: text/plain, Size: 1035 bytes --]

On Mon, 2021-06-28 at 14:08 +0200, Martin Liška wrote:
> On 6/26/21 4:44 PM, Artur Sinila wrote:
> > Not so gentle ping :)
> > What should happen in order for this patch to be accepted?
> > 
> 
> Hello.
> 
> We came up to conclusion that one can use the currently supported
> option
> -fuse-ld={bfd,gold,lld} with -B that can point to an arbitrary path
> the such linker is expected.
> 
> Cheers,
> Martin

Hello.

Thank you for the reply. I'd like to use mold linker with gcc:
https://github.com/rui314/mold. So your solution doesn't help.

There are 2 options:
1. Add mold to -fuse-ld option
2. Implement --ld-path

The 2nd option is much more future-proof: you won't need to add new
-fuse-ld variant each time new linker comes up. To provide some
context: clang had been supporting passing path to -fuse-ld, but since
clang 12 this is deprecated in favor of new --ld-path option. I think
we should take an example from clang and implement this useful feature
in gcc as well.

Cheers,
Artur Sinila

[-- Attachment #2: This is a digitally signed message part --]
[-- Type: application/pgp-signature, Size: 269 bytes --]

^ permalink raw reply	[flat|nested] 13+ messages in thread

* Re: [PATCH] Generalize -fuse-ld= to support absolute path or arbitrary ld.linker
  2021-06-28 12:24   ` Artur Sinila
@ 2021-06-28 13:26     ` Martin Liška
  2021-06-28 13:41       ` Artur Sinila
  2021-06-28 13:46       ` Jakub Jelinek
  0 siblings, 2 replies; 13+ messages in thread
From: Martin Liška @ 2021-06-28 13:26 UTC (permalink / raw)
  To: freesoftware, gcc-patches; +Cc: H.J. Lu, Jan Hubicka, Jakub Jelinek

On 6/28/21 2:24 PM, Artur Sinila wrote:
> On Mon, 2021-06-28 at 14:08 +0200, Martin Liška wrote:
>> On 6/26/21 4:44 PM, Artur Sinila wrote:
>>> Not so gentle ping :)
>>> What should happen in order for this patch to be accepted?
>>>
>>
>> Hello.
>>
>> We came up to conclusion that one can use the currently supported
>> option
>> -fuse-ld={bfd,gold,lld} with -B that can point to an arbitrary path
>> the such linker is expected.
>>
>> Cheers,
>> Martin
> 
> Hello.
> 
> Thank you for the reply. I'd like to use mold linker with gcc:
> https://github.com/rui314/mold. So your solution doesn't help.

Well, kind of works. You only need to create a symlink called
ld which will point to your linker (plus using -B argument as mentioned).

> 
> There are 2 options:
> 1. Add mold to -fuse-ld option
> 2. Implement --ld-path
> 
> The 2nd option is much more future-proof: you won't need to add new
> -fuse-ld variant each time new linker comes up. To provide some
> context: clang had been supporting passing path to -fuse-ld, but since
> clang 12 this is deprecated in favor of new --ld-path option. I think
> we should take an example from clang and implement this useful feature
> in gcc as well.

Can you please provide a pointer for the deprecation.
I'm adding Jakub who recommended using the -B argument.

Martin

> 
> Cheers,
> Artur Sinila
> 


^ permalink raw reply	[flat|nested] 13+ messages in thread

* Re: [PATCH] Generalize -fuse-ld= to support absolute path or arbitrary ld.linker
  2021-06-28 13:26     ` Martin Liška
@ 2021-06-28 13:41       ` Artur Sinila
  2021-06-28 13:49         ` Jakub Jelinek
  2021-06-28 13:46       ` Jakub Jelinek
  1 sibling, 1 reply; 13+ messages in thread
From: Artur Sinila @ 2021-06-28 13:41 UTC (permalink / raw)
  To: Martin Liška, gcc-patches; +Cc: H.J. Lu, Jan Hubicka, Jakub Jelinek

On Mon, 2021-06-28 at 15:26 +0200, Martin Liška wrote:
> On 6/28/21 2:24 PM, Artur Sinila wrote:
> > On Mon, 2021-06-28 at 14:08 +0200, Martin Liška wrote:
> > > On 6/26/21 4:44 PM, Artur Sinila wrote:
> > > > Not so gentle ping :)
> > > > What should happen in order for this patch to be accepted?
> > > > 
> > > 
> > > Hello.
> > > 
> > > We came up to conclusion that one can use the currently supported
> > > option
> > > -fuse-ld={bfd,gold,lld} with -B that can point to an arbitrary
> > > path
> > > the such linker is expected.
> > > 
> > > Cheers,
> > > Martin
> > 
> > Hello.
> > 
> > Thank you for the reply. I'd like to use mold linker with gcc:
> > https://github.com/rui314/mold. So your solution doesn't help.
> 
> Well, kind of works. You only need to create a symlink called
> ld which will point to your linker (plus using -B argument as
> mentioned).
> 
> > 
> > There are 2 options:
> > 1. Add mold to -fuse-ld option
> > 2. Implement --ld-path
> > 
> > The 2nd option is much more future-proof: you won't need to add new
> > -fuse-ld variant each time new linker comes up. To provide some
> > context: clang had been supporting passing path to -fuse-ld, but
> > since
> > clang 12 this is deprecated in favor of new --ld-path option. I
> > think
> > we should take an example from clang and implement this useful
> > feature
> > in gcc as well.
> 
> Can you please provide a pointer for the deprecation.
> I'm adding Jakub who recommended using the -B argument.
> 
> Martin
> 
> > 
> > Cheers,
> > Artur Sinila
> > 
> 

See https://reviews.llvm.org/D83015. Speaking about -B option, AFAIK it
will make gcc to search for collect2, cc and other tools in specified
directory, so apart from creating a symlink to mold, I'll also need to
create symlinks to all those tools. Didn't try it in practice though.

Best regards,
Artur Sinila


^ permalink raw reply	[flat|nested] 13+ messages in thread

* Re: [PATCH] Generalize -fuse-ld= to support absolute path or arbitrary ld.linker
  2021-06-28 13:26     ` Martin Liška
  2021-06-28 13:41       ` Artur Sinila
@ 2021-06-28 13:46       ` Jakub Jelinek
  1 sibling, 0 replies; 13+ messages in thread
From: Jakub Jelinek @ 2021-06-28 13:46 UTC (permalink / raw)
  To: Martin Liška; +Cc: freesoftware, gcc-patches, H.J. Lu, Jan Hubicka

On Mon, Jun 28, 2021 at 03:26:21PM +0200, Martin Liška wrote:
> > There are 2 options:
> > 1. Add mold to -fuse-ld option
> > 2. Implement --ld-path
> > 
> > The 2nd option is much more future-proof: you won't need to add new
> > -fuse-ld variant each time new linker comes up. To provide some
> > context: clang had been supporting passing path to -fuse-ld, but since
> > clang 12 this is deprecated in favor of new --ld-path option. I think
> > we should take an example from clang and implement this useful feature
> > in gcc as well.
> 
> Can you please provide a pointer for the deprecation.
> I'm adding Jakub who recommended using the -B argument.

-B will work with any gcc version, at least from the past 3+ decades,
just mkdir /whatever/dir/ and put the linker or symlink (with ld basename)
to it there, then -B /whatever/dir/

--ld-path= is a bad idea, it doesn't follow use any usual option naming
conventions.

Note, all these extra linkers (lld, mold) will not really work properly,
gcc during configuration detects various assembler and linker properties
on which it then relies on and I'm sure neither lld nor mold supports
those features.

HAVE_LD_ALIGNED_SHF_MERGE
HAVE_LD_AS_NEEDED
HAVE_LD_AVR_AVRXMEGA3_RODATA_IN_FLASH
HAVE_LD_BNDPLT_SUPPORT
HAVE_LD_BROKEN_PE_DWARF5
HAVE_LD_BUILDID
HAVE_LD_CLEARCAP
HAVE_LD_COMPRESS_DEBUG
HAVE_LD_DEMANGLE
HAVE_LD_EH_FRAME_CIEV3
HAVE_LD_EH_FRAME_HDR
HAVE_LD_EH_GC_SECTIONS
HAVE_LD_EH_GC_SECTIONS_BUG
HAVE_LD_LARGE_TOC
HAVE_LD_NO_DOT_SYMS
HAVE_LD_PERSONALITY_RELAXATION
HAVE_LD_PIE
HAVE_LD_PIE_COPYRELOC
HAVE_LD_PPC_GNU_ATTR_LONG_DOUBLE
HAVE_LD_PUSHPOPSTATE_SUPPORT
HAVE_LD_RO_RW_SECTION_MIXING
HAVE_LD_SOL2_EMULATION
HAVE_LD_STATIC_DYNAMIC
HAVE_LD_SYSROOT

is what is currently tested (not all of these for all targets).

	Jakub


^ permalink raw reply	[flat|nested] 13+ messages in thread

* Re: [PATCH] Generalize -fuse-ld= to support absolute path or arbitrary ld.linker
  2021-06-28 13:41       ` Artur Sinila
@ 2021-06-28 13:49         ` Jakub Jelinek
  0 siblings, 0 replies; 13+ messages in thread
From: Jakub Jelinek @ 2021-06-28 13:49 UTC (permalink / raw)
  To: freesoftware; +Cc: Martin Liška, gcc-patches, H.J. Lu, Jan Hubicka

On Mon, Jun 28, 2021 at 04:41:06PM +0300, Artur Sinila wrote:
> See https://reviews.llvm.org/D83015. Speaking about -B option, AFAIK it
> will make gcc to search for collect2, cc and other tools in specified
> directory, so apart from creating a symlink to mold, I'll also need to
> create symlinks to all those tools. Didn't try it in practice though.

You don't.  -B adds a path to the list of paths searched for the various
tools etc.  If the tool is not found in any of those directories, the
search continues in the standard paths etc. as described in the
documentation.

	Jakub


^ permalink raw reply	[flat|nested] 13+ messages in thread

* Re: [PATCH] Generalize -fuse-ld= to support absolute path or arbitrary ld.linker
  2020-04-05 22:32   ` Fangrui Song
@ 2020-04-06  7:18     ` Martin Liška
  0 siblings, 0 replies; 13+ messages in thread
From: Martin Liška @ 2020-04-06  7:18 UTC (permalink / raw)
  To: Fangrui Song; +Cc: gcc-patches

On 4/6/20 12:32 AM, Fangrui Song wrote:
> On 2020-03-11, Martin Liška wrote:
>> On 2/10/20 1:02 AM, Fangrui Song via gcc-patches wrote:
>>
>> Hello.
>>
>> Thank you for the patch. You haven't received a review because we are right now
>> in stage4 of the development cycle:
>> https://gcc.gnu.org/develop.html#stage4
> 
> Thanks for the review!
> According to https://gcc.gnu.org/pipermail/gcc-patches/2020-April/543028.html "GCC 10.0 Status Report (2020-04-01)",
> I guess GCC is not open for a new development cycle yet.

Yes, it's not opened, but I expect to be opened in 3 weeks from now.

> I will just answer a few questions instead of uploading a new patch.

Sure, but don't hesitate to send a patch. It can sit here and wait for next stage1 ;)

> 
>> Anyway, I'm going to provide a review (even though I'm not maintainer of that).
>>
>> Can you please describe your test-case why you need such option? When using
>> a different ld, I typically export PATH=/path/to/binutils and then run configure
>> and make.
> 
> I would hope -fuse-ld=ld.bfd and -fuse-ld=ld.gold were used instead of
> -fuse-ld=bfd and -fuse-ld=gold, then it would be more natural to have
> -fuse-ld=/abs/path/to/ld . https://gcc.gnu.org/bugzilla/show_bug.cgi?id=55470

Well, problem with that is that the option values are used and we want to preserve
backward compatibility of options (if possible). I mean we can't just rename
-fuse-ld=bfd to -fuse-ld=ld.bfd.

> 
> -fuse-ld=bfd, -fuse-ld=gold and -fuse-ld=lld are hard-coded in numerous
> places. It is too late to change that.
> 
> One idea is to make
> 
> -fuse-ld=bfd
> -fuse-ld=gold
> -fuse-ld=lld
> 
> special. For any other value, e.g. -fuse-ld=foo or -fuse-ld=/abs/path, just searches the
> executable named "foo" (instead of "ld.foo") or /abs/path .

Yes, that seems feasible to me.

> 
> Does the scheme sound good? If it is agreed, I can make a similar change to clang.

Yes, please send a patch and we can make another round of review process.

Thanks,
Martin

> 
>> I noticed not ideal error message:
>>
>> $ gcc -fuse-ld=pes /tmp/foo.c
>> collect2: fatal error: cannot find ‘ld’
>> compilation terminated.
>>
>> while clang prints:
>>
>> $clang -fuse-ld=pes /tmp/foo.c
>> clang-9.0: error: invalid linker name in argument '-fuse-ld=pes'
>>
>> The rest of the patch is comment inline...
> 
> Thanks for all the comments.
> 
>>>     PR driver/93645
>>>     * common.opt (-fuse-ld=): Delete -fuse-ld=[bfd|gold|lld]. Add -fuse-ld=.
>>>     * opts.c (common_handle_option): Handle OPT_fuse_ld_.
>>>     * gcc.c (driver_handle_option): Likewise.
>>>     * collect2.c (main): Likewise.
>>> ---
>>>  gcc/ChangeLog       |  8 ++++++
>>>  gcc/collect2.c      | 67 ++++++++++++++++++++++++---------------------
>>>  gcc/common.opt      | 14 ++--------
>>>  gcc/doc/invoke.texi | 15 +++-------
>>>  gcc/gcc.c           | 14 ++++------
>>>  gcc/opts.c          |  4 +--
>>>  6 files changed, 57 insertions(+), 65 deletions(-)
>>>
>>> diff --git a/gcc/ChangeLog b/gcc/ChangeLog
>>> index feb2d066d0b..6bcec12d841 100644
>>> --- a/gcc/ChangeLog
>>> +++ b/gcc/ChangeLog
>>> @@ -1,3 +1,11 @@
>>> +2020-02-09  Fangrui Song  <maskray@google.com>
>>> +
>>> +    PR driver/93645
>>> +    * common.opt (-fuse-ld=): Delete -fuse-ld=[bfd|gold|lld]. Add -fuse-ld=.
>>> +    * opts.c (common_handle_option): Handle OPT_fuse_ld_.
>>> +    * gcc.c (driver_handle_option): Likewise.
>>> +    * collect2.c (main): Likewise.
>>> +
>>>  2020-02-09  Uroš Bizjak  <ubizjak@gmail.com>
>>>      * recog.c: Move pass_split_before_sched2 code in front of
>>> diff --git a/gcc/collect2.c b/gcc/collect2.c
>>> index 502d629141c..a3ef525a93b 100644
>>> --- a/gcc/collect2.c
>>> +++ b/gcc/collect2.c
>>> @@ -859,18 +859,12 @@ main (int argc, char **argv)
>>>      {
>>>        USE_DEFAULT_LD,
>>>        USE_PLUGIN_LD,
>>> -      USE_GOLD_LD,
>>> -      USE_BFD_LD,
>>> -      USE_LLD_LD,
>>> -      USE_LD_MAX
>>> +      USE_LD
>>>      } selected_linker = USE_DEFAULT_LD;
>>> -  static const char *const ld_suffixes[USE_LD_MAX] =
>>> +  static const char *const ld_suffixes[USE_LD] =
>>>      {
>>>        "ld",
>>> -      PLUGIN_LD_SUFFIX,
>>> -      "ld.gold",
>>> -      "ld.bfd",
>>> -      "ld.lld"
>>> +      PLUGIN_LD_SUFFIX
>>>      };
>>>    static const char *const real_ld_suffix = "real-ld";
>>>    static const char *const collect_ld_suffix = "collect-ld";
>>> @@ -882,7 +876,7 @@ main (int argc, char **argv)
>>>    static const char *const strip_suffix = "strip";
>>>    static const char *const gstrip_suffix = "gstrip";
>>> -  const char *full_ld_suffixes[USE_LD_MAX];
>>> +  const char *full_ld_suffixes[USE_LD];
>>>  #ifdef CROSS_DIRECTORY_STRUCTURE
>>>    /* If we look for a program in the compiler directories, we just use
>>>       the short name, since these directories are already system-specific.
>>> @@ -924,6 +918,7 @@ main (int argc, char **argv)
>>>    const char **ld1;
>>>    bool use_plugin = false;
>>>    bool use_collect_ld = false;
>>> +  const char *use_ld = NULL;
>>>    /* The kinds of symbols we will have to consider when scanning the
>>>       outcome of a first pass link.  This is ALL to start with, then might
>>> @@ -948,7 +943,7 @@ main (int argc, char **argv)
>>>  #endif
>>>    int i;
>>> -  for (i = 0; i < USE_LD_MAX; i++)
>>> +  for (i = 0; i < USE_LD; i++)
>>>      full_ld_suffixes[i]
>>>  #ifdef CROSS_DIRECTORY_STRUCTURE
>>>        = concat (target_machine, "-", ld_suffixes[i], NULL);
>>> @@ -1041,12 +1036,11 @@ main (int argc, char **argv)
>>>          if (selected_linker == USE_DEFAULT_LD)
>>>            selected_linker = USE_PLUGIN_LD;
>>>        }
>>> -    else if (strcmp (argv[i], "-fuse-ld=bfd") == 0)
>>> -      selected_linker = USE_BFD_LD;
>>> -    else if (strcmp (argv[i], "-fuse-ld=gold") == 0)
>>> -      selected_linker = USE_GOLD_LD;
>>> -    else if (strcmp (argv[i], "-fuse-ld=lld") == 0)
>>> -      selected_linker = USE_LLD_LD;
>>> +    else if (!strncmp (argv[i], "-fuse-ld=", 9))
>>> +      {
>>> +        use_ld = argv[i] + 9;
>>> +        selected_linker = USE_LD;
>>> +      }
>>>      else if (strncmp (argv[i], "-o", 2) == 0)
>>>        {
>>>          /* Parse the output filename if it's given so that we can make
>>> @@ -1152,8 +1146,7 @@ main (int argc, char **argv)
>>>    /* Maybe we know the right file to use (if not cross).  */
>>>    ld_file_name = 0;
>>>  #ifdef DEFAULT_LINKER
>>> -  if (selected_linker == USE_BFD_LD || selected_linker == USE_GOLD_LD ||
>>> -      selected_linker == USE_LLD_LD)
>>> +  if (!ld_file_name && selected_linker == USE_LD)
>>>      {
>>>        char *linker_name;
>>>  # ifdef HOST_EXECUTABLE_SUFFIX
>>> @@ -1168,15 +1161,13 @@ main (int argc, char **argv)
>>>        if (! strcmp (&default_linker[len], HOST_EXECUTABLE_SUFFIX))
>>>          {
>>>            default_linker[len] = '\0';
>>> -          linker_name = concat (default_linker,
>>> -                    &ld_suffixes[selected_linker][2],
>>> +          linker_name = concat (default_linker, ".", use_ld,
>>>                      HOST_EXECUTABLE_SUFFIX, NULL);
>>>          }
>>>      }
>>>        if (linker_name == NULL)
>>>  # endif
>>> -      linker_name = concat (DEFAULT_LINKER,
>>> -                &ld_suffixes[selected_linker][2],
>>> +      linker_name = concat (DEFAULT_LINKER, ".", use_ld,
>>>                  NULL);
>>>        if (access (linker_name, X_OK) == 0)
>>>      ld_file_name = linker_name;
>>> @@ -1197,14 +1188,28 @@ main (int argc, char **argv)
>>>        ld_file_name = find_a_file (&cpath, collect_ld_suffix, X_OK);
>>>        use_collect_ld = ld_file_name != 0;
>>>      }
>>> -  /* Search the compiler directories for `ld'.  We have protection against
>>> -     recursive calls in find_a_file.  */
>>> -  if (ld_file_name == 0)
>>> -    ld_file_name = find_a_file (&cpath, ld_suffixes[selected_linker], X_OK);
>>> -  /* Search the ordinary system bin directories
>>> -     for `ld' (if native linking) or `TARGET-ld' (if cross).  */
>>> -  if (ld_file_name == 0)
>>> -    ld_file_name = find_a_file (&path, full_ld_suffixes[selected_linker], X_OK);
>>> +  if (selected_linker != USE_LD) {
>>> +    /* Search the compiler directories for `ld'.  We have protection against
>>> +       recursive calls in find_a_file.  */
>>> +    if (!ld_file_name)
>>> +      ld_file_name = find_a_file(&cpath, ld_suffixes[selected_linker], X_OK);
>>> +    /* Search the ordinary system bin directories
>>> +       for `ld' (if native linking) or `TARGET-ld' (if cross).  */
>>> +    if (!ld_file_name)
>>> +      ld_file_name = find_a_file(&path, full_ld_suffixes[selected_linker], X_OK);
>>> +  } else if (IS_ABSOLUTE_PATH(use_ld) && access(use_ld, X_OK) == 0) {
>>> +    ld_file_name = use_ld;
>>> +  } else {
>>> +    const char *linker_name = concat("ld.", use_ld, NULL);
>>
>> This leads to strange searches like:
>>
>> $ strace -f -s512 gcc -fuse-ld=/x/y/z/pes /tmp/foo.c 2>&1 | grep pes
>> ...
>> [pid 24295] stat("/home/marxin/bin/ld./x/y/z/pes", 0x7fffffffd1f0) = -1 ENOENT (No such file or directory)
>> [pid 24295] stat("/usr/local/bin/ld./x/y/z/pes", 0x7fffffffd1f0) = -1 ENOENT (No such file or directory)
>>
>> Moreover, before the patch we only searched for suffixes 'ld.bfd', 'ld.gold' and 'ld.gold'. Now it
>> searches also for:
>>
>> $ strace ... gcc -fuse-ld=xyz
>> ...
>> [pid 24893] stat("/home/marxin/bin/ld.xyz", 0x7fffffffd200) = -1 ENOENT (No such file or directory)
>>
>>> +    if (!ld_file_name)
>>> +      ld_file_name = find_a_file(&cpath, linker_name, X_OK);
>>> +    if (!ld_file_name) {
>>> +#ifdef CROSS_DIRECTORY_STRUCTURE
>>> +    linker_name = concat(target_machine, "-", linker_name, NULL);
>>> +#endif
>>> +    ld_file_name = find_a_file(&path, linker_name, X_OK);
>>> +    }
>>> +  }
>>>  #ifdef REAL_NM_FILE_NAME
>>>    nm_file_name = find_a_file (&path, REAL_NM_FILE_NAME, X_OK);
>>> diff --git a/gcc/common.opt b/gcc/common.opt
>>> index 5692cd04374..a76ed6434bb 100644
>>> --- a/gcc/common.opt
>>> +++ b/gcc/common.opt
>>> @@ -2859,17 +2859,9 @@ funwind-tables
>>>  Common Report Var(flag_unwind_tables) Optimization
>>>  Just generate unwind tables for exception handling.
>>> -fuse-ld=bfd
>>> -Common Driver Negative(fuse-ld=gold)
>>> -Use the bfd linker instead of the default linker.
>>> -
>>> -fuse-ld=gold
>>> -Common Driver Negative(fuse-ld=bfd)
>>> -Use the gold linker instead of the default linker.
>>> -
>>> -fuse-ld=lld
>>> -Common Driver Negative(fuse-ld=lld)
>>> -Use the lld LLVM linker instead of the default linker.
>>> +fuse-ld=
>>> +Common Driver Joined
>>> +-fuse-ld=[bfd|gold|lld|<absolute path>]    Use the specified linker.
>>>  fuse-linker-plugin
>>>  Common Undocumented Var(flag_use_linker_plugin)
>>> diff --git a/gcc/doc/invoke.texi b/gcc/doc/invoke.texi
>>> index 35b341e759f..c2dd410c88f 100644
>>> --- a/gcc/doc/invoke.texi
>>> +++ b/gcc/doc/invoke.texi
>>> @@ -14128,17 +14128,10 @@ uses @samp{nolto-rel}. To maintain whole program optimization, it is
>>>  recommended to link such objects into static library instead. Alternatively it
>>>  is possible to use H.J. Lu's binutils with support for mixed objects.
>>> -@item -fuse-ld=bfd
>>> -@opindex fuse-ld=bfd
>>> -Use the @command{bfd} linker instead of the default linker.
>>> -
>>> -@item -fuse-ld=gold
>>> -@opindex fuse-ld=gold
>>> -Use the @command{gold} linker instead of the default linker.
>>> -
>>> -@item -fuse-ld=lld
>>> -@opindex fuse-ld=lld
>>> -Use the LLVM @command{lld} linker instead of the default linker.
>>> +@item -fuse-ld=@var{linker}
>>> +@opindex fuse-ld=linker
>>> +If @var{linker} is an absolute path, use it instead of the default linker;
>>> +otherwise use @command{ld.@var{linker}}.
>>
>> You should somehow mention the special values bfd,gold and ldd.
>>>  @cindex Libraries
>>>  @item -l@var{library}
>>> diff --git a/gcc/gcc.c b/gcc/gcc.c
>>> index effc384f3ef..f9a6f10502d 100644
>>> --- a/gcc/gcc.c
>>> +++ b/gcc/gcc.c
>>> @@ -3989,12 +3989,8 @@ driver_handle_option (struct gcc_options *opts,
>>>        do_save = false;
>>>        break;
>>> -    case OPT_fuse_ld_bfd:
>>> -       use_ld = ".bfd";
>>> -       break;
>>> -
>>> -    case OPT_fuse_ld_gold:
>>> -       use_ld = ".gold";
>>> +    case OPT_fuse_ld_:
>>> +       use_ld = arg;
>>>         break;
>>>      case OPT_fcompare_debug_second:
>>> @@ -7903,20 +7899,20 @@ driver::maybe_print_and_exit () const
>>>            if (! strcmp (&default_linker[len], HOST_EXECUTABLE_SUFFIX))
>>>          {
>>>            default_linker[len] = '\0';
>>> -          ld = concat (default_linker, use_ld,
>>> +          ld = concat (default_linker, ".", use_ld,
>>>                     HOST_EXECUTABLE_SUFFIX, NULL);
>>>          }
>>>          }
>>>        if (ld == NULL)
>>>  # endif
>>> -      ld = concat (DEFAULT_LINKER, use_ld, NULL);
>>> +      ld = concat (DEFAULT_LINKER, ".", use_ld, NULL);
>>>        if (access (ld, X_OK) == 0)
>>>          {
>>>            printf ("%s\n", ld);
>>>            return (0);
>>>          }
>>>  #endif
>>> -      print_prog_name = concat (print_prog_name, use_ld, NULL);
>>> +      print_prog_name = concat (print_prog_name, ".", use_ld, NULL);
>>
>> In gcc.c you will probably have similar issues.
>>
>>>      }
>>>        char *newname = find_a_file (&exec_prefixes, print_prog_name, X_OK, 0);
>>>        printf ("%s\n", (newname ? newname : print_prog_name));
>>> diff --git a/gcc/opts.c b/gcc/opts.c
>>> index 7affeb41a96..f50d365d517 100644
>>> --- a/gcc/opts.c
>>> +++ b/gcc/opts.c
>>> @@ -2763,9 +2763,7 @@ common_handle_option (struct gcc_options *opts,
>>>        dc->max_errors = value;
>>>        break;
>>> -    case OPT_fuse_ld_bfd:
>>> -    case OPT_fuse_ld_gold:
>>> -    case OPT_fuse_ld_lld:
>>> +    case OPT_fuse_ld_:
>>>      case OPT_fuse_linker_plugin:
>>>        /* No-op. Used by the driver and passed to us because it starts with f.*/
>>>        break;
>>>
>>


^ permalink raw reply	[flat|nested] 13+ messages in thread

* Re: [PATCH] Generalize -fuse-ld= to support absolute path or arbitrary ld.linker
  2020-03-11 12:55 ` Martin Liška
@ 2020-04-05 22:32   ` Fangrui Song
  2020-04-06  7:18     ` Martin Liška
  0 siblings, 1 reply; 13+ messages in thread
From: Fangrui Song @ 2020-04-05 22:32 UTC (permalink / raw)
  To: Martin Liška; +Cc: gcc-patches

On 2020-03-11, Martin Liška wrote:
>On 2/10/20 1:02 AM, Fangrui Song via gcc-patches wrote:
>
>Hello.
>
>Thank you for the patch. You haven't received a review because we are right now
>in stage4 of the development cycle:
>https://gcc.gnu.org/develop.html#stage4

Thanks for the review!
According to https://gcc.gnu.org/pipermail/gcc-patches/2020-April/543028.html "GCC 10.0 Status Report (2020-04-01)",
I guess GCC is not open for a new development cycle yet.
I will just answer a few questions instead of uploading a new patch.

>Anyway, I'm going to provide a review (even though I'm not maintainer of that).
>
>Can you please describe your test-case why you need such option? When using
>a different ld, I typically export PATH=/path/to/binutils and then run configure
>and make.

I would hope -fuse-ld=ld.bfd and -fuse-ld=ld.gold were used instead of
-fuse-ld=bfd and -fuse-ld=gold, then it would be more natural to have
-fuse-ld=/abs/path/to/ld . https://gcc.gnu.org/bugzilla/show_bug.cgi?id=55470

-fuse-ld=bfd, -fuse-ld=gold and -fuse-ld=lld are hard-coded in numerous
places. It is too late to change that.

One idea is to make

-fuse-ld=bfd
-fuse-ld=gold
-fuse-ld=lld

special. For any other value, e.g. -fuse-ld=foo or -fuse-ld=/abs/path, just searches the
executable named "foo" (instead of "ld.foo") or /abs/path .

Does the scheme sound good? If it is agreed, I can make a similar change to clang.

>I noticed not ideal error message:
>
>$ gcc -fuse-ld=pes /tmp/foo.c
>collect2: fatal error: cannot find ‘ld’
>compilation terminated.
>
>while clang prints:
>
>$clang -fuse-ld=pes /tmp/foo.c
>clang-9.0: error: invalid linker name in argument '-fuse-ld=pes'
>
>The rest of the patch is comment inline...

Thanks for all the comments.

>>	PR driver/93645
>>	* common.opt (-fuse-ld=): Delete -fuse-ld=[bfd|gold|lld]. Add -fuse-ld=.
>>	* opts.c (common_handle_option): Handle OPT_fuse_ld_.
>>	* gcc.c (driver_handle_option): Likewise.
>>	* collect2.c (main): Likewise.
>>---
>>  gcc/ChangeLog       |  8 ++++++
>>  gcc/collect2.c      | 67 ++++++++++++++++++++++++---------------------
>>  gcc/common.opt      | 14 ++--------
>>  gcc/doc/invoke.texi | 15 +++-------
>>  gcc/gcc.c           | 14 ++++------
>>  gcc/opts.c          |  4 +--
>>  6 files changed, 57 insertions(+), 65 deletions(-)
>>
>>diff --git a/gcc/ChangeLog b/gcc/ChangeLog
>>index feb2d066d0b..6bcec12d841 100644
>>--- a/gcc/ChangeLog
>>+++ b/gcc/ChangeLog
>>@@ -1,3 +1,11 @@
>>+2020-02-09  Fangrui Song  <maskray@google.com>
>>+
>>+	PR driver/93645
>>+	* common.opt (-fuse-ld=): Delete -fuse-ld=[bfd|gold|lld]. Add -fuse-ld=.
>>+	* opts.c (common_handle_option): Handle OPT_fuse_ld_.
>>+	* gcc.c (driver_handle_option): Likewise.
>>+	* collect2.c (main): Likewise.
>>+
>>  2020-02-09  Uroš Bizjak  <ubizjak@gmail.com>
>>  	* recog.c: Move pass_split_before_sched2 code in front of
>>diff --git a/gcc/collect2.c b/gcc/collect2.c
>>index 502d629141c..a3ef525a93b 100644
>>--- a/gcc/collect2.c
>>+++ b/gcc/collect2.c
>>@@ -859,18 +859,12 @@ main (int argc, char **argv)
>>      {
>>        USE_DEFAULT_LD,
>>        USE_PLUGIN_LD,
>>-      USE_GOLD_LD,
>>-      USE_BFD_LD,
>>-      USE_LLD_LD,
>>-      USE_LD_MAX
>>+      USE_LD
>>      } selected_linker = USE_DEFAULT_LD;
>>-  static const char *const ld_suffixes[USE_LD_MAX] =
>>+  static const char *const ld_suffixes[USE_LD] =
>>      {
>>        "ld",
>>-      PLUGIN_LD_SUFFIX,
>>-      "ld.gold",
>>-      "ld.bfd",
>>-      "ld.lld"
>>+      PLUGIN_LD_SUFFIX
>>      };
>>    static const char *const real_ld_suffix = "real-ld";
>>    static const char *const collect_ld_suffix = "collect-ld";
>>@@ -882,7 +876,7 @@ main (int argc, char **argv)
>>    static const char *const strip_suffix = "strip";
>>    static const char *const gstrip_suffix = "gstrip";
>>-  const char *full_ld_suffixes[USE_LD_MAX];
>>+  const char *full_ld_suffixes[USE_LD];
>>  #ifdef CROSS_DIRECTORY_STRUCTURE
>>    /* If we look for a program in the compiler directories, we just use
>>       the short name, since these directories are already system-specific.
>>@@ -924,6 +918,7 @@ main (int argc, char **argv)
>>    const char **ld1;
>>    bool use_plugin = false;
>>    bool use_collect_ld = false;
>>+  const char *use_ld = NULL;
>>    /* The kinds of symbols we will have to consider when scanning the
>>       outcome of a first pass link.  This is ALL to start with, then might
>>@@ -948,7 +943,7 @@ main (int argc, char **argv)
>>  #endif
>>    int i;
>>-  for (i = 0; i < USE_LD_MAX; i++)
>>+  for (i = 0; i < USE_LD; i++)
>>      full_ld_suffixes[i]
>>  #ifdef CROSS_DIRECTORY_STRUCTURE
>>        = concat (target_machine, "-", ld_suffixes[i], NULL);
>>@@ -1041,12 +1036,11 @@ main (int argc, char **argv)
>>  	    if (selected_linker == USE_DEFAULT_LD)
>>  	      selected_linker = USE_PLUGIN_LD;
>>  	  }
>>-	else if (strcmp (argv[i], "-fuse-ld=bfd") == 0)
>>-	  selected_linker = USE_BFD_LD;
>>-	else if (strcmp (argv[i], "-fuse-ld=gold") == 0)
>>-	  selected_linker = USE_GOLD_LD;
>>-	else if (strcmp (argv[i], "-fuse-ld=lld") == 0)
>>-	  selected_linker = USE_LLD_LD;
>>+	else if (!strncmp (argv[i], "-fuse-ld=", 9))
>>+	  {
>>+	    use_ld = argv[i] + 9;
>>+	    selected_linker = USE_LD;
>>+	  }
>>  	else if (strncmp (argv[i], "-o", 2) == 0)
>>  	  {
>>  	    /* Parse the output filename if it's given so that we can make
>>@@ -1152,8 +1146,7 @@ main (int argc, char **argv)
>>    /* Maybe we know the right file to use (if not cross).  */
>>    ld_file_name = 0;
>>  #ifdef DEFAULT_LINKER
>>-  if (selected_linker == USE_BFD_LD || selected_linker == USE_GOLD_LD ||
>>-      selected_linker == USE_LLD_LD)
>>+  if (!ld_file_name && selected_linker == USE_LD)
>>      {
>>        char *linker_name;
>>  # ifdef HOST_EXECUTABLE_SUFFIX
>>@@ -1168,15 +1161,13 @@ main (int argc, char **argv)
>>  	  if (! strcmp (&default_linker[len], HOST_EXECUTABLE_SUFFIX))
>>  	    {
>>  	      default_linker[len] = '\0';
>>-	      linker_name = concat (default_linker,
>>-				    &ld_suffixes[selected_linker][2],
>>+	      linker_name = concat (default_linker, ".", use_ld,
>>  				    HOST_EXECUTABLE_SUFFIX, NULL);
>>  	    }
>>  	}
>>        if (linker_name == NULL)
>>  # endif
>>-      linker_name = concat (DEFAULT_LINKER,
>>-			    &ld_suffixes[selected_linker][2],
>>+      linker_name = concat (DEFAULT_LINKER, ".", use_ld,
>>  			    NULL);
>>        if (access (linker_name, X_OK) == 0)
>>  	ld_file_name = linker_name;
>>@@ -1197,14 +1188,28 @@ main (int argc, char **argv)
>>        ld_file_name = find_a_file (&cpath, collect_ld_suffix, X_OK);
>>        use_collect_ld = ld_file_name != 0;
>>      }
>>-  /* Search the compiler directories for `ld'.  We have protection against
>>-     recursive calls in find_a_file.  */
>>-  if (ld_file_name == 0)
>>-    ld_file_name = find_a_file (&cpath, ld_suffixes[selected_linker], X_OK);
>>-  /* Search the ordinary system bin directories
>>-     for `ld' (if native linking) or `TARGET-ld' (if cross).  */
>>-  if (ld_file_name == 0)
>>-    ld_file_name = find_a_file (&path, full_ld_suffixes[selected_linker], X_OK);
>>+  if (selected_linker != USE_LD) {
>>+    /* Search the compiler directories for `ld'.  We have protection against
>>+       recursive calls in find_a_file.  */
>>+    if (!ld_file_name)
>>+      ld_file_name = find_a_file(&cpath, ld_suffixes[selected_linker], X_OK);
>>+    /* Search the ordinary system bin directories
>>+       for `ld' (if native linking) or `TARGET-ld' (if cross).  */
>>+    if (!ld_file_name)
>>+      ld_file_name = find_a_file(&path, full_ld_suffixes[selected_linker], X_OK);
>>+  } else if (IS_ABSOLUTE_PATH(use_ld) && access(use_ld, X_OK) == 0) {
>>+    ld_file_name = use_ld;
>>+  } else {
>>+    const char *linker_name = concat("ld.", use_ld, NULL);
>
>This leads to strange searches like:
>
>$ strace -f -s512 gcc -fuse-ld=/x/y/z/pes /tmp/foo.c 2>&1 | grep pes
>...
>[pid 24295] stat("/home/marxin/bin/ld./x/y/z/pes", 0x7fffffffd1f0) = -1 ENOENT (No such file or directory)
>[pid 24295] stat("/usr/local/bin/ld./x/y/z/pes", 0x7fffffffd1f0) = -1 ENOENT (No such file or directory)
>
>Moreover, before the patch we only searched for suffixes 'ld.bfd', 'ld.gold' and 'ld.gold'. Now it
>searches also for:
>
>$ strace ... gcc -fuse-ld=xyz
>...
>[pid 24893] stat("/home/marxin/bin/ld.xyz", 0x7fffffffd200) = -1 ENOENT (No such file or directory)
>
>>+    if (!ld_file_name)
>>+      ld_file_name = find_a_file(&cpath, linker_name, X_OK);
>>+    if (!ld_file_name) {
>>+#ifdef CROSS_DIRECTORY_STRUCTURE
>>+	linker_name = concat(target_machine, "-", linker_name, NULL);
>>+#endif
>>+	ld_file_name = find_a_file(&path, linker_name, X_OK);
>>+    }
>>+  }
>>  #ifdef REAL_NM_FILE_NAME
>>    nm_file_name = find_a_file (&path, REAL_NM_FILE_NAME, X_OK);
>>diff --git a/gcc/common.opt b/gcc/common.opt
>>index 5692cd04374..a76ed6434bb 100644
>>--- a/gcc/common.opt
>>+++ b/gcc/common.opt
>>@@ -2859,17 +2859,9 @@ funwind-tables
>>  Common Report Var(flag_unwind_tables) Optimization
>>  Just generate unwind tables for exception handling.
>>-fuse-ld=bfd
>>-Common Driver Negative(fuse-ld=gold)
>>-Use the bfd linker instead of the default linker.
>>-
>>-fuse-ld=gold
>>-Common Driver Negative(fuse-ld=bfd)
>>-Use the gold linker instead of the default linker.
>>-
>>-fuse-ld=lld
>>-Common Driver Negative(fuse-ld=lld)
>>-Use the lld LLVM linker instead of the default linker.
>>+fuse-ld=
>>+Common Driver Joined
>>+-fuse-ld=[bfd|gold|lld|<absolute path>]	Use the specified linker.
>>  fuse-linker-plugin
>>  Common Undocumented Var(flag_use_linker_plugin)
>>diff --git a/gcc/doc/invoke.texi b/gcc/doc/invoke.texi
>>index 35b341e759f..c2dd410c88f 100644
>>--- a/gcc/doc/invoke.texi
>>+++ b/gcc/doc/invoke.texi
>>@@ -14128,17 +14128,10 @@ uses @samp{nolto-rel}. To maintain whole program optimization, it is
>>  recommended to link such objects into static library instead. Alternatively it
>>  is possible to use H.J. Lu's binutils with support for mixed objects.
>>-@item -fuse-ld=bfd
>>-@opindex fuse-ld=bfd
>>-Use the @command{bfd} linker instead of the default linker.
>>-
>>-@item -fuse-ld=gold
>>-@opindex fuse-ld=gold
>>-Use the @command{gold} linker instead of the default linker.
>>-
>>-@item -fuse-ld=lld
>>-@opindex fuse-ld=lld
>>-Use the LLVM @command{lld} linker instead of the default linker.
>>+@item -fuse-ld=@var{linker}
>>+@opindex fuse-ld=linker
>>+If @var{linker} is an absolute path, use it instead of the default linker;
>>+otherwise use @command{ld.@var{linker}}.
>
>You should somehow mention the special values bfd,gold and ldd.
>>  @cindex Libraries
>>  @item -l@var{library}
>>diff --git a/gcc/gcc.c b/gcc/gcc.c
>>index effc384f3ef..f9a6f10502d 100644
>>--- a/gcc/gcc.c
>>+++ b/gcc/gcc.c
>>@@ -3989,12 +3989,8 @@ driver_handle_option (struct gcc_options *opts,
>>        do_save = false;
>>        break;
>>-    case OPT_fuse_ld_bfd:
>>-       use_ld = ".bfd";
>>-       break;
>>-
>>-    case OPT_fuse_ld_gold:
>>-       use_ld = ".gold";
>>+    case OPT_fuse_ld_:
>>+       use_ld = arg;
>>         break;
>>      case OPT_fcompare_debug_second:
>>@@ -7903,20 +7899,20 @@ driver::maybe_print_and_exit () const
>>  	      if (! strcmp (&default_linker[len], HOST_EXECUTABLE_SUFFIX))
>>  		{
>>  		  default_linker[len] = '\0';
>>-		  ld = concat (default_linker, use_ld,
>>+		  ld = concat (default_linker, ".", use_ld,
>>  			       HOST_EXECUTABLE_SUFFIX, NULL);
>>  		}
>>  	    }
>>  	  if (ld == NULL)
>>  # endif
>>-	  ld = concat (DEFAULT_LINKER, use_ld, NULL);
>>+	  ld = concat (DEFAULT_LINKER, ".", use_ld, NULL);
>>  	  if (access (ld, X_OK) == 0)
>>  	    {
>>  	      printf ("%s\n", ld);
>>  	      return (0);
>>  	    }
>>  #endif
>>-	  print_prog_name = concat (print_prog_name, use_ld, NULL);
>>+	  print_prog_name = concat (print_prog_name, ".", use_ld, NULL);
>
>In gcc.c you will probably have similar issues.
>
>>  	}
>>        char *newname = find_a_file (&exec_prefixes, print_prog_name, X_OK, 0);
>>        printf ("%s\n", (newname ? newname : print_prog_name));
>>diff --git a/gcc/opts.c b/gcc/opts.c
>>index 7affeb41a96..f50d365d517 100644
>>--- a/gcc/opts.c
>>+++ b/gcc/opts.c
>>@@ -2763,9 +2763,7 @@ common_handle_option (struct gcc_options *opts,
>>        dc->max_errors = value;
>>        break;
>>-    case OPT_fuse_ld_bfd:
>>-    case OPT_fuse_ld_gold:
>>-    case OPT_fuse_ld_lld:
>>+    case OPT_fuse_ld_:
>>      case OPT_fuse_linker_plugin:
>>        /* No-op. Used by the driver and passed to us because it starts with f.*/
>>        break;
>>
>

^ permalink raw reply	[flat|nested] 13+ messages in thread

* Re: [PATCH] Generalize -fuse-ld= to support absolute path or arbitrary ld.linker
  2020-02-10  0:02 Fangrui Song via gcc-patches
  2020-02-13 17:59 ` Fangrui Song via gcc-patches
@ 2020-03-11 12:55 ` Martin Liška
  2020-04-05 22:32   ` Fangrui Song
  1 sibling, 1 reply; 13+ messages in thread
From: Martin Liška @ 2020-03-11 12:55 UTC (permalink / raw)
  To: Fangrui Song, gcc-patches

On 2/10/20 1:02 AM, Fangrui Song via gcc-patches wrote:

Hello.

Thank you for the patch. You haven't received a review because we are right now
in stage4 of the development cycle:
https://gcc.gnu.org/develop.html#stage4

Anyway, I'm going to provide a review (even though I'm not maintainer of that).

Can you please describe your test-case why you need such option? When using
a different ld, I typically export PATH=/path/to/binutils and then run configure
and make.

I noticed not ideal error message:

$ gcc -fuse-ld=pes /tmp/foo.c
collect2: fatal error: cannot find ‘ld’
compilation terminated.

while clang prints:

$clang -fuse-ld=pes /tmp/foo.c
clang-9.0: error: invalid linker name in argument '-fuse-ld=pes'

The rest of the patch is comment inline...

> 	PR driver/93645
> 	* common.opt (-fuse-ld=): Delete -fuse-ld=[bfd|gold|lld]. Add -fuse-ld=.
> 	* opts.c (common_handle_option): Handle OPT_fuse_ld_.
> 	* gcc.c (driver_handle_option): Likewise.
> 	* collect2.c (main): Likewise.
> ---
>   gcc/ChangeLog       |  8 ++++++
>   gcc/collect2.c      | 67 ++++++++++++++++++++++++---------------------
>   gcc/common.opt      | 14 ++--------
>   gcc/doc/invoke.texi | 15 +++-------
>   gcc/gcc.c           | 14 ++++------
>   gcc/opts.c          |  4 +--
>   6 files changed, 57 insertions(+), 65 deletions(-)
> 
> diff --git a/gcc/ChangeLog b/gcc/ChangeLog
> index feb2d066d0b..6bcec12d841 100644
> --- a/gcc/ChangeLog
> +++ b/gcc/ChangeLog
> @@ -1,3 +1,11 @@
> +2020-02-09  Fangrui Song  <maskray@google.com>
> +
> +	PR driver/93645
> +	* common.opt (-fuse-ld=): Delete -fuse-ld=[bfd|gold|lld]. Add -fuse-ld=.
> +	* opts.c (common_handle_option): Handle OPT_fuse_ld_.
> +	* gcc.c (driver_handle_option): Likewise.
> +	* collect2.c (main): Likewise.
> +
>   2020-02-09  Uroš Bizjak  <ubizjak@gmail.com>
>   
>   	* recog.c: Move pass_split_before_sched2 code in front of
> diff --git a/gcc/collect2.c b/gcc/collect2.c
> index 502d629141c..a3ef525a93b 100644
> --- a/gcc/collect2.c
> +++ b/gcc/collect2.c
> @@ -859,18 +859,12 @@ main (int argc, char **argv)
>       {
>         USE_DEFAULT_LD,
>         USE_PLUGIN_LD,
> -      USE_GOLD_LD,
> -      USE_BFD_LD,
> -      USE_LLD_LD,
> -      USE_LD_MAX
> +      USE_LD
>       } selected_linker = USE_DEFAULT_LD;
> -  static const char *const ld_suffixes[USE_LD_MAX] =
> +  static const char *const ld_suffixes[USE_LD] =
>       {
>         "ld",
> -      PLUGIN_LD_SUFFIX,
> -      "ld.gold",
> -      "ld.bfd",
> -      "ld.lld"
> +      PLUGIN_LD_SUFFIX
>       };
>     static const char *const real_ld_suffix = "real-ld";
>     static const char *const collect_ld_suffix = "collect-ld";
> @@ -882,7 +876,7 @@ main (int argc, char **argv)
>     static const char *const strip_suffix = "strip";
>     static const char *const gstrip_suffix = "gstrip";
>   
> -  const char *full_ld_suffixes[USE_LD_MAX];
> +  const char *full_ld_suffixes[USE_LD];
>   #ifdef CROSS_DIRECTORY_STRUCTURE
>     /* If we look for a program in the compiler directories, we just use
>        the short name, since these directories are already system-specific.
> @@ -924,6 +918,7 @@ main (int argc, char **argv)
>     const char **ld1;
>     bool use_plugin = false;
>     bool use_collect_ld = false;
> +  const char *use_ld = NULL;
>   
>     /* The kinds of symbols we will have to consider when scanning the
>        outcome of a first pass link.  This is ALL to start with, then might
> @@ -948,7 +943,7 @@ main (int argc, char **argv)
>   #endif
>     int i;
>   
> -  for (i = 0; i < USE_LD_MAX; i++)
> +  for (i = 0; i < USE_LD; i++)
>       full_ld_suffixes[i]
>   #ifdef CROSS_DIRECTORY_STRUCTURE
>         = concat (target_machine, "-", ld_suffixes[i], NULL);
> @@ -1041,12 +1036,11 @@ main (int argc, char **argv)
>   	    if (selected_linker == USE_DEFAULT_LD)
>   	      selected_linker = USE_PLUGIN_LD;
>   	  }
> -	else if (strcmp (argv[i], "-fuse-ld=bfd") == 0)
> -	  selected_linker = USE_BFD_LD;
> -	else if (strcmp (argv[i], "-fuse-ld=gold") == 0)
> -	  selected_linker = USE_GOLD_LD;
> -	else if (strcmp (argv[i], "-fuse-ld=lld") == 0)
> -	  selected_linker = USE_LLD_LD;
> +	else if (!strncmp (argv[i], "-fuse-ld=", 9))
> +	  {
> +	    use_ld = argv[i] + 9;
> +	    selected_linker = USE_LD;
> +	  }
>   	else if (strncmp (argv[i], "-o", 2) == 0)
>   	  {
>   	    /* Parse the output filename if it's given so that we can make
> @@ -1152,8 +1146,7 @@ main (int argc, char **argv)
>     /* Maybe we know the right file to use (if not cross).  */
>     ld_file_name = 0;
>   #ifdef DEFAULT_LINKER
> -  if (selected_linker == USE_BFD_LD || selected_linker == USE_GOLD_LD ||
> -      selected_linker == USE_LLD_LD)
> +  if (!ld_file_name && selected_linker == USE_LD)
>       {
>         char *linker_name;
>   # ifdef HOST_EXECUTABLE_SUFFIX
> @@ -1168,15 +1161,13 @@ main (int argc, char **argv)
>   	  if (! strcmp (&default_linker[len], HOST_EXECUTABLE_SUFFIX))
>   	    {
>   	      default_linker[len] = '\0';
> -	      linker_name = concat (default_linker,
> -				    &ld_suffixes[selected_linker][2],
> +	      linker_name = concat (default_linker, ".", use_ld,
>   				    HOST_EXECUTABLE_SUFFIX, NULL);
>   	    }
>   	}
>         if (linker_name == NULL)
>   # endif
> -      linker_name = concat (DEFAULT_LINKER,
> -			    &ld_suffixes[selected_linker][2],
> +      linker_name = concat (DEFAULT_LINKER, ".", use_ld,
>   			    NULL);
>         if (access (linker_name, X_OK) == 0)
>   	ld_file_name = linker_name;
> @@ -1197,14 +1188,28 @@ main (int argc, char **argv)
>         ld_file_name = find_a_file (&cpath, collect_ld_suffix, X_OK);
>         use_collect_ld = ld_file_name != 0;
>       }
> -  /* Search the compiler directories for `ld'.  We have protection against
> -     recursive calls in find_a_file.  */
> -  if (ld_file_name == 0)
> -    ld_file_name = find_a_file (&cpath, ld_suffixes[selected_linker], X_OK);
> -  /* Search the ordinary system bin directories
> -     for `ld' (if native linking) or `TARGET-ld' (if cross).  */
> -  if (ld_file_name == 0)
> -    ld_file_name = find_a_file (&path, full_ld_suffixes[selected_linker], X_OK);
> +  if (selected_linker != USE_LD) {
> +    /* Search the compiler directories for `ld'.  We have protection against
> +       recursive calls in find_a_file.  */
> +    if (!ld_file_name)
> +      ld_file_name = find_a_file(&cpath, ld_suffixes[selected_linker], X_OK);
> +    /* Search the ordinary system bin directories
> +       for `ld' (if native linking) or `TARGET-ld' (if cross).  */
> +    if (!ld_file_name)
> +      ld_file_name = find_a_file(&path, full_ld_suffixes[selected_linker], X_OK);
> +  } else if (IS_ABSOLUTE_PATH(use_ld) && access(use_ld, X_OK) == 0) {
> +    ld_file_name = use_ld;
> +  } else {
> +    const char *linker_name = concat("ld.", use_ld, NULL);

This leads to strange searches like:

$ strace -f -s512 gcc -fuse-ld=/x/y/z/pes /tmp/foo.c 2>&1 | grep pes
...
[pid 24295] stat("/home/marxin/bin/ld./x/y/z/pes", 0x7fffffffd1f0) = -1 ENOENT (No such file or directory)
[pid 24295] stat("/usr/local/bin/ld./x/y/z/pes", 0x7fffffffd1f0) = -1 ENOENT (No such file or directory)

Moreover, before the patch we only searched for suffixes 'ld.bfd', 'ld.gold' and 'ld.gold'. Now it
searches also for:

$ strace ... gcc -fuse-ld=xyz
...
[pid 24893] stat("/home/marxin/bin/ld.xyz", 0x7fffffffd200) = -1 ENOENT (No such file or directory)

> +    if (!ld_file_name)
> +      ld_file_name = find_a_file(&cpath, linker_name, X_OK);
> +    if (!ld_file_name) {
> +#ifdef CROSS_DIRECTORY_STRUCTURE
> +	linker_name = concat(target_machine, "-", linker_name, NULL);
> +#endif
> +	ld_file_name = find_a_file(&path, linker_name, X_OK);
> +    }
> +  }
>   
>   #ifdef REAL_NM_FILE_NAME
>     nm_file_name = find_a_file (&path, REAL_NM_FILE_NAME, X_OK);
> diff --git a/gcc/common.opt b/gcc/common.opt
> index 5692cd04374..a76ed6434bb 100644
> --- a/gcc/common.opt
> +++ b/gcc/common.opt
> @@ -2859,17 +2859,9 @@ funwind-tables
>   Common Report Var(flag_unwind_tables) Optimization
>   Just generate unwind tables for exception handling.
>   
> -fuse-ld=bfd
> -Common Driver Negative(fuse-ld=gold)
> -Use the bfd linker instead of the default linker.
> -
> -fuse-ld=gold
> -Common Driver Negative(fuse-ld=bfd)
> -Use the gold linker instead of the default linker.
> -
> -fuse-ld=lld
> -Common Driver Negative(fuse-ld=lld)
> -Use the lld LLVM linker instead of the default linker.
> +fuse-ld=
> +Common Driver Joined
> +-fuse-ld=[bfd|gold|lld|<absolute path>]	Use the specified linker.
>   
>   fuse-linker-plugin
>   Common Undocumented Var(flag_use_linker_plugin)
> diff --git a/gcc/doc/invoke.texi b/gcc/doc/invoke.texi
> index 35b341e759f..c2dd410c88f 100644
> --- a/gcc/doc/invoke.texi
> +++ b/gcc/doc/invoke.texi
> @@ -14128,17 +14128,10 @@ uses @samp{nolto-rel}. To maintain whole program optimization, it is
>   recommended to link such objects into static library instead. Alternatively it
>   is possible to use H.J. Lu's binutils with support for mixed objects.
>   
> -@item -fuse-ld=bfd
> -@opindex fuse-ld=bfd
> -Use the @command{bfd} linker instead of the default linker.
> -
> -@item -fuse-ld=gold
> -@opindex fuse-ld=gold
> -Use the @command{gold} linker instead of the default linker.
> -
> -@item -fuse-ld=lld
> -@opindex fuse-ld=lld
> -Use the LLVM @command{lld} linker instead of the default linker.
> +@item -fuse-ld=@var{linker}
> +@opindex fuse-ld=linker
> +If @var{linker} is an absolute path, use it instead of the default linker;
> +otherwise use @command{ld.@var{linker}}.

You should somehow mention the special values bfd,gold and ldd.

>   
>   @cindex Libraries
>   @item -l@var{library}
> diff --git a/gcc/gcc.c b/gcc/gcc.c
> index effc384f3ef..f9a6f10502d 100644
> --- a/gcc/gcc.c
> +++ b/gcc/gcc.c
> @@ -3989,12 +3989,8 @@ driver_handle_option (struct gcc_options *opts,
>         do_save = false;
>         break;
>   
> -    case OPT_fuse_ld_bfd:
> -       use_ld = ".bfd";
> -       break;
> -
> -    case OPT_fuse_ld_gold:
> -       use_ld = ".gold";
> +    case OPT_fuse_ld_:
> +       use_ld = arg;
>          break;
>   
>       case OPT_fcompare_debug_second:
> @@ -7903,20 +7899,20 @@ driver::maybe_print_and_exit () const
>   	      if (! strcmp (&default_linker[len], HOST_EXECUTABLE_SUFFIX))
>   		{
>   		  default_linker[len] = '\0';
> -		  ld = concat (default_linker, use_ld,
> +		  ld = concat (default_linker, ".", use_ld,
>   			       HOST_EXECUTABLE_SUFFIX, NULL);
>   		}
>   	    }
>   	  if (ld == NULL)
>   # endif
> -	  ld = concat (DEFAULT_LINKER, use_ld, NULL);
> +	  ld = concat (DEFAULT_LINKER, ".", use_ld, NULL);
>   	  if (access (ld, X_OK) == 0)
>   	    {
>   	      printf ("%s\n", ld);
>   	      return (0);
>   	    }
>   #endif
> -	  print_prog_name = concat (print_prog_name, use_ld, NULL);
> +	  print_prog_name = concat (print_prog_name, ".", use_ld, NULL);

In gcc.c you will probably have similar issues.

>   	}
>         char *newname = find_a_file (&exec_prefixes, print_prog_name, X_OK, 0);
>         printf ("%s\n", (newname ? newname : print_prog_name));
> diff --git a/gcc/opts.c b/gcc/opts.c
> index 7affeb41a96..f50d365d517 100644
> --- a/gcc/opts.c
> +++ b/gcc/opts.c
> @@ -2763,9 +2763,7 @@ common_handle_option (struct gcc_options *opts,
>         dc->max_errors = value;
>         break;
>   
> -    case OPT_fuse_ld_bfd:
> -    case OPT_fuse_ld_gold:
> -    case OPT_fuse_ld_lld:
> +    case OPT_fuse_ld_:
>       case OPT_fuse_linker_plugin:
>         /* No-op. Used by the driver and passed to us because it starts with f.*/
>         break;
> 


^ permalink raw reply	[flat|nested] 13+ messages in thread

* Re: [PATCH] Generalize -fuse-ld= to support absolute path or arbitrary ld.linker
  2020-02-13 17:59 ` Fangrui Song via gcc-patches
@ 2020-02-24 23:02   ` Fangrui Song via gcc-patches
  0 siblings, 0 replies; 13+ messages in thread
From: Fangrui Song via gcc-patches @ 2020-02-24 23:02 UTC (permalink / raw)
  To: gcc-patches; +Cc: H.J. Lu, Jan Hubicka, Martin Liska

On 2020-02-13, Fangrui Song wrote:
>On 2020-02-09, Fangrui Song wrote:
>>	PR driver/93645
>>	* common.opt (-fuse-ld=): Delete -fuse-ld=[bfd|gold|lld]. Add -fuse-ld=.
>>	* opts.c (common_handle_option): Handle OPT_fuse_ld_.
>>	* gcc.c (driver_handle_option): Likewise.
>>	* collect2.c (main): Likewise.
>>---
>>gcc/ChangeLog       |  8 ++++++
>>gcc/collect2.c      | 67 ++++++++++++++++++++++++---------------------
>>gcc/common.opt      | 14 ++--------
>>gcc/doc/invoke.texi | 15 +++-------
>>gcc/gcc.c           | 14 ++++------
>>gcc/opts.c          |  4 +--
>>6 files changed, 57 insertions(+), 65 deletions(-)
>>
>>diff --git a/gcc/ChangeLog b/gcc/ChangeLog
>>index feb2d066d0b..6bcec12d841 100644
>>--- a/gcc/ChangeLog
>>+++ b/gcc/ChangeLog
>>@@ -1,3 +1,11 @@
>>+2020-02-09  Fangrui Song  <maskray@google.com>
>>+
>>+	PR driver/93645
>>+	* common.opt (-fuse-ld=): Delete -fuse-ld=[bfd|gold|lld]. Add -fuse-ld=.
>>+	* opts.c (common_handle_option): Handle OPT_fuse_ld_.
>>+	* gcc.c (driver_handle_option): Likewise.
>>+	* collect2.c (main): Likewise.
>>+
>>2020-02-09  Uroš Bizjak  <ubizjak@gmail.com>
>>
>>	* recog.c: Move pass_split_before_sched2 code in front of
>>diff --git a/gcc/collect2.c b/gcc/collect2.c
>>index 502d629141c..a3ef525a93b 100644
>>--- a/gcc/collect2.c
>>+++ b/gcc/collect2.c
>>@@ -859,18 +859,12 @@ main (int argc, char **argv)
>>    {
>>      USE_DEFAULT_LD,
>>      USE_PLUGIN_LD,
>>-      USE_GOLD_LD,
>>-      USE_BFD_LD,
>>-      USE_LLD_LD,
>>-      USE_LD_MAX
>>+      USE_LD
>>    } selected_linker = USE_DEFAULT_LD;
>>-  static const char *const ld_suffixes[USE_LD_MAX] =
>>+  static const char *const ld_suffixes[USE_LD] =
>>    {
>>      "ld",
>>-      PLUGIN_LD_SUFFIX,
>>-      "ld.gold",
>>-      "ld.bfd",
>>-      "ld.lld"
>>+      PLUGIN_LD_SUFFIX
>>    };
>>  static const char *const real_ld_suffix = "real-ld";
>>  static const char *const collect_ld_suffix = "collect-ld";
>>@@ -882,7 +876,7 @@ main (int argc, char **argv)
>>  static const char *const strip_suffix = "strip";
>>  static const char *const gstrip_suffix = "gstrip";
>>
>>-  const char *full_ld_suffixes[USE_LD_MAX];
>>+  const char *full_ld_suffixes[USE_LD];
>>#ifdef CROSS_DIRECTORY_STRUCTURE
>>  /* If we look for a program in the compiler directories, we just use
>>     the short name, since these directories are already system-specific.
>>@@ -924,6 +918,7 @@ main (int argc, char **argv)
>>  const char **ld1;
>>  bool use_plugin = false;
>>  bool use_collect_ld = false;
>>+  const char *use_ld = NULL;
>>
>>  /* The kinds of symbols we will have to consider when scanning the
>>     outcome of a first pass link.  This is ALL to start with, then might
>>@@ -948,7 +943,7 @@ main (int argc, char **argv)
>>#endif
>>  int i;
>>
>>-  for (i = 0; i < USE_LD_MAX; i++)
>>+  for (i = 0; i < USE_LD; i++)
>>    full_ld_suffixes[i]
>>#ifdef CROSS_DIRECTORY_STRUCTURE
>>      = concat (target_machine, "-", ld_suffixes[i], NULL);
>>@@ -1041,12 +1036,11 @@ main (int argc, char **argv)
>>	    if (selected_linker == USE_DEFAULT_LD)
>>	      selected_linker = USE_PLUGIN_LD;
>>	  }
>>-	else if (strcmp (argv[i], "-fuse-ld=bfd") == 0)
>>-	  selected_linker = USE_BFD_LD;
>>-	else if (strcmp (argv[i], "-fuse-ld=gold") == 0)
>>-	  selected_linker = USE_GOLD_LD;
>>-	else if (strcmp (argv[i], "-fuse-ld=lld") == 0)
>>-	  selected_linker = USE_LLD_LD;
>>+	else if (!strncmp (argv[i], "-fuse-ld=", 9))
>>+	  {
>>+	    use_ld = argv[i] + 9;
>>+	    selected_linker = USE_LD;
>>+	  }
>>	else if (strncmp (argv[i], "-o", 2) == 0)
>>	  {
>>	    /* Parse the output filename if it's given so that we can make
>>@@ -1152,8 +1146,7 @@ main (int argc, char **argv)
>>  /* Maybe we know the right file to use (if not cross).  */
>>  ld_file_name = 0;
>>#ifdef DEFAULT_LINKER
>>-  if (selected_linker == USE_BFD_LD || selected_linker == USE_GOLD_LD ||
>>-      selected_linker == USE_LLD_LD)
>>+  if (!ld_file_name && selected_linker == USE_LD)
>>    {
>>      char *linker_name;
>># ifdef HOST_EXECUTABLE_SUFFIX
>>@@ -1168,15 +1161,13 @@ main (int argc, char **argv)
>>	  if (! strcmp (&default_linker[len], HOST_EXECUTABLE_SUFFIX))
>>	    {
>>	      default_linker[len] = '\0';
>>-	      linker_name = concat (default_linker,
>>-				    &ld_suffixes[selected_linker][2],
>>+	      linker_name = concat (default_linker, ".", use_ld,
>>				    HOST_EXECUTABLE_SUFFIX, NULL);
>>	    }
>>	}
>>      if (linker_name == NULL)
>># endif
>>-      linker_name = concat (DEFAULT_LINKER,
>>-			    &ld_suffixes[selected_linker][2],
>>+      linker_name = concat (DEFAULT_LINKER, ".", use_ld,
>>			    NULL);
>>      if (access (linker_name, X_OK) == 0)
>>	ld_file_name = linker_name;
>>@@ -1197,14 +1188,28 @@ main (int argc, char **argv)
>>      ld_file_name = find_a_file (&cpath, collect_ld_suffix, X_OK);
>>      use_collect_ld = ld_file_name != 0;
>>    }
>>-  /* Search the compiler directories for `ld'.  We have protection against
>>-     recursive calls in find_a_file.  */
>>-  if (ld_file_name == 0)
>>-    ld_file_name = find_a_file (&cpath, ld_suffixes[selected_linker], X_OK);
>>-  /* Search the ordinary system bin directories
>>-     for `ld' (if native linking) or `TARGET-ld' (if cross).  */
>>-  if (ld_file_name == 0)
>>-    ld_file_name = find_a_file (&path, full_ld_suffixes[selected_linker], X_OK);
>>+  if (selected_linker != USE_LD) {
>>+    /* Search the compiler directories for `ld'.  We have protection against
>>+       recursive calls in find_a_file.  */
>>+    if (!ld_file_name)
>>+      ld_file_name = find_a_file(&cpath, ld_suffixes[selected_linker], X_OK);
>>+    /* Search the ordinary system bin directories
>>+       for `ld' (if native linking) or `TARGET-ld' (if cross).  */
>>+    if (!ld_file_name)
>>+      ld_file_name = find_a_file(&path, full_ld_suffixes[selected_linker], X_OK);
>>+  } else if (IS_ABSOLUTE_PATH(use_ld) && access(use_ld, X_OK) == 0) {
>>+    ld_file_name = use_ld;
>>+  } else {
>>+    const char *linker_name = concat("ld.", use_ld, NULL);
>>+    if (!ld_file_name)
>>+      ld_file_name = find_a_file(&cpath, linker_name, X_OK);
>>+    if (!ld_file_name) {
>>+#ifdef CROSS_DIRECTORY_STRUCTURE
>>+	linker_name = concat(target_machine, "-", linker_name, NULL);
>>+#endif
>>+	ld_file_name = find_a_file(&path, linker_name, X_OK);
>>+    }
>>+  }
>>
>>#ifdef REAL_NM_FILE_NAME
>>  nm_file_name = find_a_file (&path, REAL_NM_FILE_NAME, X_OK);
>>diff --git a/gcc/common.opt b/gcc/common.opt
>>index 5692cd04374..a76ed6434bb 100644
>>--- a/gcc/common.opt
>>+++ b/gcc/common.opt
>>@@ -2859,17 +2859,9 @@ funwind-tables
>>Common Report Var(flag_unwind_tables) Optimization
>>Just generate unwind tables for exception handling.
>>
>>-fuse-ld=bfd
>>-Common Driver Negative(fuse-ld=gold)
>>-Use the bfd linker instead of the default linker.
>>-
>>-fuse-ld=gold
>>-Common Driver Negative(fuse-ld=bfd)
>>-Use the gold linker instead of the default linker.
>>-
>>-fuse-ld=lld
>>-Common Driver Negative(fuse-ld=lld)
>>-Use the lld LLVM linker instead of the default linker.
>>+fuse-ld=
>>+Common Driver Joined
>>+-fuse-ld=[bfd|gold|lld|<absolute path>]	Use the specified linker.
>>
>>fuse-linker-plugin
>>Common Undocumented Var(flag_use_linker_plugin)
>>diff --git a/gcc/doc/invoke.texi b/gcc/doc/invoke.texi
>>index 35b341e759f..c2dd410c88f 100644
>>--- a/gcc/doc/invoke.texi
>>+++ b/gcc/doc/invoke.texi
>>@@ -14128,17 +14128,10 @@ uses @samp{nolto-rel}. To maintain whole program optimization, it is
>>recommended to link such objects into static library instead. Alternatively it
>>is possible to use H.J. Lu's binutils with support for mixed objects.
>>
>>-@item -fuse-ld=bfd
>>-@opindex fuse-ld=bfd
>>-Use the @command{bfd} linker instead of the default linker.
>>-
>>-@item -fuse-ld=gold
>>-@opindex fuse-ld=gold
>>-Use the @command{gold} linker instead of the default linker.
>>-
>>-@item -fuse-ld=lld
>>-@opindex fuse-ld=lld
>>-Use the LLVM @command{lld} linker instead of the default linker.
>>+@item -fuse-ld=@var{linker}
>>+@opindex fuse-ld=linker
>>+If @var{linker} is an absolute path, use it instead of the default linker;
>>+otherwise use @command{ld.@var{linker}}.
>>
>>@cindex Libraries
>>@item -l@var{library}
>>diff --git a/gcc/gcc.c b/gcc/gcc.c
>>index effc384f3ef..f9a6f10502d 100644
>>--- a/gcc/gcc.c
>>+++ b/gcc/gcc.c
>>@@ -3989,12 +3989,8 @@ driver_handle_option (struct gcc_options *opts,
>>      do_save = false;
>>      break;
>>
>>-    case OPT_fuse_ld_bfd:
>>-       use_ld = ".bfd";
>>-       break;
>>-
>>-    case OPT_fuse_ld_gold:
>>-       use_ld = ".gold";
>>+    case OPT_fuse_ld_:
>>+       use_ld = arg;
>>       break;
>>
>>    case OPT_fcompare_debug_second:
>>@@ -7903,20 +7899,20 @@ driver::maybe_print_and_exit () const
>>	      if (! strcmp (&default_linker[len], HOST_EXECUTABLE_SUFFIX))
>>		{
>>		  default_linker[len] = '\0';
>>-		  ld = concat (default_linker, use_ld,
>>+		  ld = concat (default_linker, ".", use_ld,
>>			       HOST_EXECUTABLE_SUFFIX, NULL);
>>		}
>>	    }
>>	  if (ld == NULL)
>># endif
>>-	  ld = concat (DEFAULT_LINKER, use_ld, NULL);
>>+	  ld = concat (DEFAULT_LINKER, ".", use_ld, NULL);
>>	  if (access (ld, X_OK) == 0)
>>	    {
>>	      printf ("%s\n", ld);
>>	      return (0);
>>	    }
>>#endif
>>-	  print_prog_name = concat (print_prog_name, use_ld, NULL);
>>+	  print_prog_name = concat (print_prog_name, ".", use_ld, NULL);
>>	}
>>      char *newname = find_a_file (&exec_prefixes, print_prog_name, X_OK, 0);
>>      printf ("%s\n", (newname ? newname : print_prog_name));
>>diff --git a/gcc/opts.c b/gcc/opts.c
>>index 7affeb41a96..f50d365d517 100644
>>--- a/gcc/opts.c
>>+++ b/gcc/opts.c
>>@@ -2763,9 +2763,7 @@ common_handle_option (struct gcc_options *opts,
>>      dc->max_errors = value;
>>      break;
>>
>>-    case OPT_fuse_ld_bfd:
>>-    case OPT_fuse_ld_gold:
>>-    case OPT_fuse_ld_lld:
>>+    case OPT_fuse_ld_:
>>    case OPT_fuse_linker_plugin:
>>      /* No-op. Used by the driver and passed to us because it starts with f.*/
>>      break;
>>-- 
>>2.25.0
>
>Friendly ping:)

Patch ping https://gcc.gnu.org/ml/gcc-patches/2020-02/msg00510.html

^ permalink raw reply	[flat|nested] 13+ messages in thread

* Re: [PATCH] Generalize -fuse-ld= to support absolute path or arbitrary ld.linker
  2020-02-10  0:02 Fangrui Song via gcc-patches
@ 2020-02-13 17:59 ` Fangrui Song via gcc-patches
  2020-02-24 23:02   ` Fangrui Song via gcc-patches
  2020-03-11 12:55 ` Martin Liška
  1 sibling, 1 reply; 13+ messages in thread
From: Fangrui Song via gcc-patches @ 2020-02-13 17:59 UTC (permalink / raw)
  To: gcc-patches; +Cc: H.J. Lu

On 2020-02-09, Fangrui Song wrote:
>	PR driver/93645
>	* common.opt (-fuse-ld=): Delete -fuse-ld=[bfd|gold|lld]. Add -fuse-ld=.
>	* opts.c (common_handle_option): Handle OPT_fuse_ld_.
>	* gcc.c (driver_handle_option): Likewise.
>	* collect2.c (main): Likewise.
>---
> gcc/ChangeLog       |  8 ++++++
> gcc/collect2.c      | 67 ++++++++++++++++++++++++---------------------
> gcc/common.opt      | 14 ++--------
> gcc/doc/invoke.texi | 15 +++-------
> gcc/gcc.c           | 14 ++++------
> gcc/opts.c          |  4 +--
> 6 files changed, 57 insertions(+), 65 deletions(-)
>
>diff --git a/gcc/ChangeLog b/gcc/ChangeLog
>index feb2d066d0b..6bcec12d841 100644
>--- a/gcc/ChangeLog
>+++ b/gcc/ChangeLog
>@@ -1,3 +1,11 @@
>+2020-02-09  Fangrui Song  <maskray@google.com>
>+
>+	PR driver/93645
>+	* common.opt (-fuse-ld=): Delete -fuse-ld=[bfd|gold|lld]. Add -fuse-ld=.
>+	* opts.c (common_handle_option): Handle OPT_fuse_ld_.
>+	* gcc.c (driver_handle_option): Likewise.
>+	* collect2.c (main): Likewise.
>+
> 2020-02-09  Uroš Bizjak  <ubizjak@gmail.com>
>
> 	* recog.c: Move pass_split_before_sched2 code in front of
>diff --git a/gcc/collect2.c b/gcc/collect2.c
>index 502d629141c..a3ef525a93b 100644
>--- a/gcc/collect2.c
>+++ b/gcc/collect2.c
>@@ -859,18 +859,12 @@ main (int argc, char **argv)
>     {
>       USE_DEFAULT_LD,
>       USE_PLUGIN_LD,
>-      USE_GOLD_LD,
>-      USE_BFD_LD,
>-      USE_LLD_LD,
>-      USE_LD_MAX
>+      USE_LD
>     } selected_linker = USE_DEFAULT_LD;
>-  static const char *const ld_suffixes[USE_LD_MAX] =
>+  static const char *const ld_suffixes[USE_LD] =
>     {
>       "ld",
>-      PLUGIN_LD_SUFFIX,
>-      "ld.gold",
>-      "ld.bfd",
>-      "ld.lld"
>+      PLUGIN_LD_SUFFIX
>     };
>   static const char *const real_ld_suffix = "real-ld";
>   static const char *const collect_ld_suffix = "collect-ld";
>@@ -882,7 +876,7 @@ main (int argc, char **argv)
>   static const char *const strip_suffix = "strip";
>   static const char *const gstrip_suffix = "gstrip";
>
>-  const char *full_ld_suffixes[USE_LD_MAX];
>+  const char *full_ld_suffixes[USE_LD];
> #ifdef CROSS_DIRECTORY_STRUCTURE
>   /* If we look for a program in the compiler directories, we just use
>      the short name, since these directories are already system-specific.
>@@ -924,6 +918,7 @@ main (int argc, char **argv)
>   const char **ld1;
>   bool use_plugin = false;
>   bool use_collect_ld = false;
>+  const char *use_ld = NULL;
>
>   /* The kinds of symbols we will have to consider when scanning the
>      outcome of a first pass link.  This is ALL to start with, then might
>@@ -948,7 +943,7 @@ main (int argc, char **argv)
> #endif
>   int i;
>
>-  for (i = 0; i < USE_LD_MAX; i++)
>+  for (i = 0; i < USE_LD; i++)
>     full_ld_suffixes[i]
> #ifdef CROSS_DIRECTORY_STRUCTURE
>       = concat (target_machine, "-", ld_suffixes[i], NULL);
>@@ -1041,12 +1036,11 @@ main (int argc, char **argv)
> 	    if (selected_linker == USE_DEFAULT_LD)
> 	      selected_linker = USE_PLUGIN_LD;
> 	  }
>-	else if (strcmp (argv[i], "-fuse-ld=bfd") == 0)
>-	  selected_linker = USE_BFD_LD;
>-	else if (strcmp (argv[i], "-fuse-ld=gold") == 0)
>-	  selected_linker = USE_GOLD_LD;
>-	else if (strcmp (argv[i], "-fuse-ld=lld") == 0)
>-	  selected_linker = USE_LLD_LD;
>+	else if (!strncmp (argv[i], "-fuse-ld=", 9))
>+	  {
>+	    use_ld = argv[i] + 9;
>+	    selected_linker = USE_LD;
>+	  }
> 	else if (strncmp (argv[i], "-o", 2) == 0)
> 	  {
> 	    /* Parse the output filename if it's given so that we can make
>@@ -1152,8 +1146,7 @@ main (int argc, char **argv)
>   /* Maybe we know the right file to use (if not cross).  */
>   ld_file_name = 0;
> #ifdef DEFAULT_LINKER
>-  if (selected_linker == USE_BFD_LD || selected_linker == USE_GOLD_LD ||
>-      selected_linker == USE_LLD_LD)
>+  if (!ld_file_name && selected_linker == USE_LD)
>     {
>       char *linker_name;
> # ifdef HOST_EXECUTABLE_SUFFIX
>@@ -1168,15 +1161,13 @@ main (int argc, char **argv)
> 	  if (! strcmp (&default_linker[len], HOST_EXECUTABLE_SUFFIX))
> 	    {
> 	      default_linker[len] = '\0';
>-	      linker_name = concat (default_linker,
>-				    &ld_suffixes[selected_linker][2],
>+	      linker_name = concat (default_linker, ".", use_ld,
> 				    HOST_EXECUTABLE_SUFFIX, NULL);
> 	    }
> 	}
>       if (linker_name == NULL)
> # endif
>-      linker_name = concat (DEFAULT_LINKER,
>-			    &ld_suffixes[selected_linker][2],
>+      linker_name = concat (DEFAULT_LINKER, ".", use_ld,
> 			    NULL);
>       if (access (linker_name, X_OK) == 0)
> 	ld_file_name = linker_name;
>@@ -1197,14 +1188,28 @@ main (int argc, char **argv)
>       ld_file_name = find_a_file (&cpath, collect_ld_suffix, X_OK);
>       use_collect_ld = ld_file_name != 0;
>     }
>-  /* Search the compiler directories for `ld'.  We have protection against
>-     recursive calls in find_a_file.  */
>-  if (ld_file_name == 0)
>-    ld_file_name = find_a_file (&cpath, ld_suffixes[selected_linker], X_OK);
>-  /* Search the ordinary system bin directories
>-     for `ld' (if native linking) or `TARGET-ld' (if cross).  */
>-  if (ld_file_name == 0)
>-    ld_file_name = find_a_file (&path, full_ld_suffixes[selected_linker], X_OK);
>+  if (selected_linker != USE_LD) {
>+    /* Search the compiler directories for `ld'.  We have protection against
>+       recursive calls in find_a_file.  */
>+    if (!ld_file_name)
>+      ld_file_name = find_a_file(&cpath, ld_suffixes[selected_linker], X_OK);
>+    /* Search the ordinary system bin directories
>+       for `ld' (if native linking) or `TARGET-ld' (if cross).  */
>+    if (!ld_file_name)
>+      ld_file_name = find_a_file(&path, full_ld_suffixes[selected_linker], X_OK);
>+  } else if (IS_ABSOLUTE_PATH(use_ld) && access(use_ld, X_OK) == 0) {
>+    ld_file_name = use_ld;
>+  } else {
>+    const char *linker_name = concat("ld.", use_ld, NULL);
>+    if (!ld_file_name)
>+      ld_file_name = find_a_file(&cpath, linker_name, X_OK);
>+    if (!ld_file_name) {
>+#ifdef CROSS_DIRECTORY_STRUCTURE
>+	linker_name = concat(target_machine, "-", linker_name, NULL);
>+#endif
>+	ld_file_name = find_a_file(&path, linker_name, X_OK);
>+    }
>+  }
>
> #ifdef REAL_NM_FILE_NAME
>   nm_file_name = find_a_file (&path, REAL_NM_FILE_NAME, X_OK);
>diff --git a/gcc/common.opt b/gcc/common.opt
>index 5692cd04374..a76ed6434bb 100644
>--- a/gcc/common.opt
>+++ b/gcc/common.opt
>@@ -2859,17 +2859,9 @@ funwind-tables
> Common Report Var(flag_unwind_tables) Optimization
> Just generate unwind tables for exception handling.
>
>-fuse-ld=bfd
>-Common Driver Negative(fuse-ld=gold)
>-Use the bfd linker instead of the default linker.
>-
>-fuse-ld=gold
>-Common Driver Negative(fuse-ld=bfd)
>-Use the gold linker instead of the default linker.
>-
>-fuse-ld=lld
>-Common Driver Negative(fuse-ld=lld)
>-Use the lld LLVM linker instead of the default linker.
>+fuse-ld=
>+Common Driver Joined
>+-fuse-ld=[bfd|gold|lld|<absolute path>]	Use the specified linker.
>
> fuse-linker-plugin
> Common Undocumented Var(flag_use_linker_plugin)
>diff --git a/gcc/doc/invoke.texi b/gcc/doc/invoke.texi
>index 35b341e759f..c2dd410c88f 100644
>--- a/gcc/doc/invoke.texi
>+++ b/gcc/doc/invoke.texi
>@@ -14128,17 +14128,10 @@ uses @samp{nolto-rel}. To maintain whole program optimization, it is
> recommended to link such objects into static library instead. Alternatively it
> is possible to use H.J. Lu's binutils with support for mixed objects.
>
>-@item -fuse-ld=bfd
>-@opindex fuse-ld=bfd
>-Use the @command{bfd} linker instead of the default linker.
>-
>-@item -fuse-ld=gold
>-@opindex fuse-ld=gold
>-Use the @command{gold} linker instead of the default linker.
>-
>-@item -fuse-ld=lld
>-@opindex fuse-ld=lld
>-Use the LLVM @command{lld} linker instead of the default linker.
>+@item -fuse-ld=@var{linker}
>+@opindex fuse-ld=linker
>+If @var{linker} is an absolute path, use it instead of the default linker;
>+otherwise use @command{ld.@var{linker}}.
>
> @cindex Libraries
> @item -l@var{library}
>diff --git a/gcc/gcc.c b/gcc/gcc.c
>index effc384f3ef..f9a6f10502d 100644
>--- a/gcc/gcc.c
>+++ b/gcc/gcc.c
>@@ -3989,12 +3989,8 @@ driver_handle_option (struct gcc_options *opts,
>       do_save = false;
>       break;
>
>-    case OPT_fuse_ld_bfd:
>-       use_ld = ".bfd";
>-       break;
>-
>-    case OPT_fuse_ld_gold:
>-       use_ld = ".gold";
>+    case OPT_fuse_ld_:
>+       use_ld = arg;
>        break;
>
>     case OPT_fcompare_debug_second:
>@@ -7903,20 +7899,20 @@ driver::maybe_print_and_exit () const
> 	      if (! strcmp (&default_linker[len], HOST_EXECUTABLE_SUFFIX))
> 		{
> 		  default_linker[len] = '\0';
>-		  ld = concat (default_linker, use_ld,
>+		  ld = concat (default_linker, ".", use_ld,
> 			       HOST_EXECUTABLE_SUFFIX, NULL);
> 		}
> 	    }
> 	  if (ld == NULL)
> # endif
>-	  ld = concat (DEFAULT_LINKER, use_ld, NULL);
>+	  ld = concat (DEFAULT_LINKER, ".", use_ld, NULL);
> 	  if (access (ld, X_OK) == 0)
> 	    {
> 	      printf ("%s\n", ld);
> 	      return (0);
> 	    }
> #endif
>-	  print_prog_name = concat (print_prog_name, use_ld, NULL);
>+	  print_prog_name = concat (print_prog_name, ".", use_ld, NULL);
> 	}
>       char *newname = find_a_file (&exec_prefixes, print_prog_name, X_OK, 0);
>       printf ("%s\n", (newname ? newname : print_prog_name));
>diff --git a/gcc/opts.c b/gcc/opts.c
>index 7affeb41a96..f50d365d517 100644
>--- a/gcc/opts.c
>+++ b/gcc/opts.c
>@@ -2763,9 +2763,7 @@ common_handle_option (struct gcc_options *opts,
>       dc->max_errors = value;
>       break;
>
>-    case OPT_fuse_ld_bfd:
>-    case OPT_fuse_ld_gold:
>-    case OPT_fuse_ld_lld:
>+    case OPT_fuse_ld_:
>     case OPT_fuse_linker_plugin:
>       /* No-op. Used by the driver and passed to us because it starts with f.*/
>       break;
>-- 
>2.25.0

Friendly ping:)

^ permalink raw reply	[flat|nested] 13+ messages in thread

* [PATCH] Generalize -fuse-ld= to support absolute path or arbitrary ld.linker
@ 2020-02-10  0:02 Fangrui Song via gcc-patches
  2020-02-13 17:59 ` Fangrui Song via gcc-patches
  2020-03-11 12:55 ` Martin Liška
  0 siblings, 2 replies; 13+ messages in thread
From: Fangrui Song via gcc-patches @ 2020-02-10  0:02 UTC (permalink / raw)
  To: gcc-patches

	PR driver/93645
	* common.opt (-fuse-ld=): Delete -fuse-ld=[bfd|gold|lld]. Add -fuse-ld=.
	* opts.c (common_handle_option): Handle OPT_fuse_ld_.
	* gcc.c (driver_handle_option): Likewise.
	* collect2.c (main): Likewise.
---
 gcc/ChangeLog       |  8 ++++++
 gcc/collect2.c      | 67 ++++++++++++++++++++++++---------------------
 gcc/common.opt      | 14 ++--------
 gcc/doc/invoke.texi | 15 +++-------
 gcc/gcc.c           | 14 ++++------
 gcc/opts.c          |  4 +--
 6 files changed, 57 insertions(+), 65 deletions(-)

diff --git a/gcc/ChangeLog b/gcc/ChangeLog
index feb2d066d0b..6bcec12d841 100644
--- a/gcc/ChangeLog
+++ b/gcc/ChangeLog
@@ -1,3 +1,11 @@
+2020-02-09  Fangrui Song  <maskray@google.com>
+
+	PR driver/93645
+	* common.opt (-fuse-ld=): Delete -fuse-ld=[bfd|gold|lld]. Add -fuse-ld=.
+	* opts.c (common_handle_option): Handle OPT_fuse_ld_.
+	* gcc.c (driver_handle_option): Likewise.
+	* collect2.c (main): Likewise.
+
 2020-02-09  Uroš Bizjak  <ubizjak@gmail.com>
 
 	* recog.c: Move pass_split_before_sched2 code in front of
diff --git a/gcc/collect2.c b/gcc/collect2.c
index 502d629141c..a3ef525a93b 100644
--- a/gcc/collect2.c
+++ b/gcc/collect2.c
@@ -859,18 +859,12 @@ main (int argc, char **argv)
     {
       USE_DEFAULT_LD,
       USE_PLUGIN_LD,
-      USE_GOLD_LD,
-      USE_BFD_LD,
-      USE_LLD_LD,
-      USE_LD_MAX
+      USE_LD
     } selected_linker = USE_DEFAULT_LD;
-  static const char *const ld_suffixes[USE_LD_MAX] =
+  static const char *const ld_suffixes[USE_LD] =
     {
       "ld",
-      PLUGIN_LD_SUFFIX,
-      "ld.gold",
-      "ld.bfd",
-      "ld.lld"
+      PLUGIN_LD_SUFFIX
     };
   static const char *const real_ld_suffix = "real-ld";
   static const char *const collect_ld_suffix = "collect-ld";
@@ -882,7 +876,7 @@ main (int argc, char **argv)
   static const char *const strip_suffix = "strip";
   static const char *const gstrip_suffix = "gstrip";
 
-  const char *full_ld_suffixes[USE_LD_MAX];
+  const char *full_ld_suffixes[USE_LD];
 #ifdef CROSS_DIRECTORY_STRUCTURE
   /* If we look for a program in the compiler directories, we just use
      the short name, since these directories are already system-specific.
@@ -924,6 +918,7 @@ main (int argc, char **argv)
   const char **ld1;
   bool use_plugin = false;
   bool use_collect_ld = false;
+  const char *use_ld = NULL;
 
   /* The kinds of symbols we will have to consider when scanning the
      outcome of a first pass link.  This is ALL to start with, then might
@@ -948,7 +943,7 @@ main (int argc, char **argv)
 #endif
   int i;
 
-  for (i = 0; i < USE_LD_MAX; i++)
+  for (i = 0; i < USE_LD; i++)
     full_ld_suffixes[i]
 #ifdef CROSS_DIRECTORY_STRUCTURE
       = concat (target_machine, "-", ld_suffixes[i], NULL);
@@ -1041,12 +1036,11 @@ main (int argc, char **argv)
 	    if (selected_linker == USE_DEFAULT_LD)
 	      selected_linker = USE_PLUGIN_LD;
 	  }
-	else if (strcmp (argv[i], "-fuse-ld=bfd") == 0)
-	  selected_linker = USE_BFD_LD;
-	else if (strcmp (argv[i], "-fuse-ld=gold") == 0)
-	  selected_linker = USE_GOLD_LD;
-	else if (strcmp (argv[i], "-fuse-ld=lld") == 0)
-	  selected_linker = USE_LLD_LD;
+	else if (!strncmp (argv[i], "-fuse-ld=", 9))
+	  {
+	    use_ld = argv[i] + 9;
+	    selected_linker = USE_LD;
+	  }
 	else if (strncmp (argv[i], "-o", 2) == 0)
 	  {
 	    /* Parse the output filename if it's given so that we can make
@@ -1152,8 +1146,7 @@ main (int argc, char **argv)
   /* Maybe we know the right file to use (if not cross).  */
   ld_file_name = 0;
 #ifdef DEFAULT_LINKER
-  if (selected_linker == USE_BFD_LD || selected_linker == USE_GOLD_LD ||
-      selected_linker == USE_LLD_LD)
+  if (!ld_file_name && selected_linker == USE_LD)
     {
       char *linker_name;
 # ifdef HOST_EXECUTABLE_SUFFIX
@@ -1168,15 +1161,13 @@ main (int argc, char **argv)
 	  if (! strcmp (&default_linker[len], HOST_EXECUTABLE_SUFFIX))
 	    {
 	      default_linker[len] = '\0';
-	      linker_name = concat (default_linker,
-				    &ld_suffixes[selected_linker][2],
+	      linker_name = concat (default_linker, ".", use_ld,
 				    HOST_EXECUTABLE_SUFFIX, NULL);
 	    }
 	}
       if (linker_name == NULL)
 # endif
-      linker_name = concat (DEFAULT_LINKER,
-			    &ld_suffixes[selected_linker][2],
+      linker_name = concat (DEFAULT_LINKER, ".", use_ld,
 			    NULL);
       if (access (linker_name, X_OK) == 0)
 	ld_file_name = linker_name;
@@ -1197,14 +1188,28 @@ main (int argc, char **argv)
       ld_file_name = find_a_file (&cpath, collect_ld_suffix, X_OK);
       use_collect_ld = ld_file_name != 0;
     }
-  /* Search the compiler directories for `ld'.  We have protection against
-     recursive calls in find_a_file.  */
-  if (ld_file_name == 0)
-    ld_file_name = find_a_file (&cpath, ld_suffixes[selected_linker], X_OK);
-  /* Search the ordinary system bin directories
-     for `ld' (if native linking) or `TARGET-ld' (if cross).  */
-  if (ld_file_name == 0)
-    ld_file_name = find_a_file (&path, full_ld_suffixes[selected_linker], X_OK);
+  if (selected_linker != USE_LD) {
+    /* Search the compiler directories for `ld'.  We have protection against
+       recursive calls in find_a_file.  */
+    if (!ld_file_name)
+      ld_file_name = find_a_file(&cpath, ld_suffixes[selected_linker], X_OK);
+    /* Search the ordinary system bin directories
+       for `ld' (if native linking) or `TARGET-ld' (if cross).  */
+    if (!ld_file_name)
+      ld_file_name = find_a_file(&path, full_ld_suffixes[selected_linker], X_OK);
+  } else if (IS_ABSOLUTE_PATH(use_ld) && access(use_ld, X_OK) == 0) {
+    ld_file_name = use_ld;
+  } else {
+    const char *linker_name = concat("ld.", use_ld, NULL);
+    if (!ld_file_name)
+      ld_file_name = find_a_file(&cpath, linker_name, X_OK);
+    if (!ld_file_name) {
+#ifdef CROSS_DIRECTORY_STRUCTURE
+	linker_name = concat(target_machine, "-", linker_name, NULL);
+#endif
+	ld_file_name = find_a_file(&path, linker_name, X_OK);
+    }
+  }
 
 #ifdef REAL_NM_FILE_NAME
   nm_file_name = find_a_file (&path, REAL_NM_FILE_NAME, X_OK);
diff --git a/gcc/common.opt b/gcc/common.opt
index 5692cd04374..a76ed6434bb 100644
--- a/gcc/common.opt
+++ b/gcc/common.opt
@@ -2859,17 +2859,9 @@ funwind-tables
 Common Report Var(flag_unwind_tables) Optimization
 Just generate unwind tables for exception handling.
 
-fuse-ld=bfd
-Common Driver Negative(fuse-ld=gold)
-Use the bfd linker instead of the default linker.
-
-fuse-ld=gold
-Common Driver Negative(fuse-ld=bfd)
-Use the gold linker instead of the default linker.
-
-fuse-ld=lld
-Common Driver Negative(fuse-ld=lld)
-Use the lld LLVM linker instead of the default linker.
+fuse-ld=
+Common Driver Joined
+-fuse-ld=[bfd|gold|lld|<absolute path>]	Use the specified linker.
 
 fuse-linker-plugin
 Common Undocumented Var(flag_use_linker_plugin)
diff --git a/gcc/doc/invoke.texi b/gcc/doc/invoke.texi
index 35b341e759f..c2dd410c88f 100644
--- a/gcc/doc/invoke.texi
+++ b/gcc/doc/invoke.texi
@@ -14128,17 +14128,10 @@ uses @samp{nolto-rel}. To maintain whole program optimization, it is
 recommended to link such objects into static library instead. Alternatively it
 is possible to use H.J. Lu's binutils with support for mixed objects.
 
-@item -fuse-ld=bfd
-@opindex fuse-ld=bfd
-Use the @command{bfd} linker instead of the default linker.
-
-@item -fuse-ld=gold
-@opindex fuse-ld=gold
-Use the @command{gold} linker instead of the default linker.
-
-@item -fuse-ld=lld
-@opindex fuse-ld=lld
-Use the LLVM @command{lld} linker instead of the default linker.
+@item -fuse-ld=@var{linker}
+@opindex fuse-ld=linker
+If @var{linker} is an absolute path, use it instead of the default linker;
+otherwise use @command{ld.@var{linker}}.
 
 @cindex Libraries
 @item -l@var{library}
diff --git a/gcc/gcc.c b/gcc/gcc.c
index effc384f3ef..f9a6f10502d 100644
--- a/gcc/gcc.c
+++ b/gcc/gcc.c
@@ -3989,12 +3989,8 @@ driver_handle_option (struct gcc_options *opts,
       do_save = false;
       break;
 
-    case OPT_fuse_ld_bfd:
-       use_ld = ".bfd";
-       break;
-
-    case OPT_fuse_ld_gold:
-       use_ld = ".gold";
+    case OPT_fuse_ld_:
+       use_ld = arg;
        break;
 
     case OPT_fcompare_debug_second:
@@ -7903,20 +7899,20 @@ driver::maybe_print_and_exit () const
 	      if (! strcmp (&default_linker[len], HOST_EXECUTABLE_SUFFIX))
 		{
 		  default_linker[len] = '\0';
-		  ld = concat (default_linker, use_ld,
+		  ld = concat (default_linker, ".", use_ld,
 			       HOST_EXECUTABLE_SUFFIX, NULL);
 		}
 	    }
 	  if (ld == NULL)
 # endif
-	  ld = concat (DEFAULT_LINKER, use_ld, NULL);
+	  ld = concat (DEFAULT_LINKER, ".", use_ld, NULL);
 	  if (access (ld, X_OK) == 0)
 	    {
 	      printf ("%s\n", ld);
 	      return (0);
 	    }
 #endif
-	  print_prog_name = concat (print_prog_name, use_ld, NULL);
+	  print_prog_name = concat (print_prog_name, ".", use_ld, NULL);
 	}
       char *newname = find_a_file (&exec_prefixes, print_prog_name, X_OK, 0);
       printf ("%s\n", (newname ? newname : print_prog_name));
diff --git a/gcc/opts.c b/gcc/opts.c
index 7affeb41a96..f50d365d517 100644
--- a/gcc/opts.c
+++ b/gcc/opts.c
@@ -2763,9 +2763,7 @@ common_handle_option (struct gcc_options *opts,
       dc->max_errors = value;
       break;
 
-    case OPT_fuse_ld_bfd:
-    case OPT_fuse_ld_gold:
-    case OPT_fuse_ld_lld:
+    case OPT_fuse_ld_:
     case OPT_fuse_linker_plugin:
       /* No-op. Used by the driver and passed to us because it starts with f.*/
       break;
-- 
2.25.0

^ permalink raw reply	[flat|nested] 13+ messages in thread

end of thread, other threads:[~2021-06-28 13:49 UTC | newest]

Thread overview: 13+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-06-26 14:44 [PATCH] Generalize -fuse-ld= to support absolute path or arbitrary ld.linker Artur Sinila
2021-06-28 12:08 ` Martin Liška
2021-06-28 12:24   ` Artur Sinila
2021-06-28 13:26     ` Martin Liška
2021-06-28 13:41       ` Artur Sinila
2021-06-28 13:49         ` Jakub Jelinek
2021-06-28 13:46       ` Jakub Jelinek
  -- strict thread matches above, loose matches on Subject: below --
2020-02-10  0:02 Fangrui Song via gcc-patches
2020-02-13 17:59 ` Fangrui Song via gcc-patches
2020-02-24 23:02   ` Fangrui Song via gcc-patches
2020-03-11 12:55 ` Martin Liška
2020-04-05 22:32   ` Fangrui Song
2020-04-06  7:18     ` Martin Liška

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).