Re: [PATCH] Generalize -fuse-ld= to support absolute path or arbitrary ld.linker
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
Re: [PATCH] Generalize -fuse-ld= to support absolute path or arbitrary ld.linker
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
Re: [PATCH] Generalize -fuse-ld= to support absolute path or arbitrary ld.linker
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
Re: [PATCH] Generalize -fuse-ld= to support absolute path or arbitrary ld.linker
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
Re: [PATCH] Generalize -fuse-ld= to support absolute path or arbitrary ld.linker
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 signature.asc Description: This is a digitally signed message part
Re: [PATCH] Generalize -fuse-ld= to support absolute path or arbitrary ld.linker
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
Re: [PATCH] Generalize -fuse-ld= to support absolute path or arbitrary ld.linker
Not so gentle ping :) What should happen in order for this patch to be accepted? signature.asc Description: This is a digitally signed message part
Re: [PATCH] Generalize -fuse-ld= to support absolute path or arbitrary ld.linker
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 + + 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 * 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);
Re: [PATCH] Generalize -fuse-ld= to support absolute path or arbitrary ld.linker
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 + + 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 * 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
Re: [PATCH] Generalize -fuse-ld= to support absolute path or arbitrary ld.linker
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 + + 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 * 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_l
[PING^3][PATCH] Generalize -fuse-ld= to support absolute path or arbitrary ld.linker
On 2020-02-24, Fangrui Song wrote: 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 + + 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 * 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) -
Re: [PATCH] Generalize -fuse-ld= to support absolute path or arbitrary ld.linker
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 + + 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 * 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_
Re: [PATCH] Generalize -fuse-ld= to support absolute path or arbitrary ld.linker
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 + + 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 * 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_n
[PATCH] Generalize -fuse-ld= to support absolute path or arbitrary ld.linker
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 + + 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 * 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) -