On Wed, Aug 22, 2018 at 2:51 PM Iain Sandoe <i...@sandoe.co.uk> wrote: > > > > On 20 Aug 2018, at 11:01, Richard Biener <richard.guent...@gmail.com> wrote: > > > > On Sat, Aug 18, 2018 at 9:00 PM Iain Sandoe <i...@sandoe.co.uk> wrote: > > >> While working on the Darwin LTO issues I noticed that collect2 looks for > >> "-flto-partition=none” in its command line option, but it doesn’t get > >> passed. > >> > >> So - is the attached patch the right idea, or should collect2 be looking > >> in the COLLECT_GCC_OPTIONS as the lto-wrapper does? > > > > Looking at COLLECT_GCC_OPTIONS is probably better. > > So I bootstrapped and tested the following on Darwin and Linux (both with a > 32b multilib) > > It’s kinda odd that we really have to look in two places for the union of the > options to be handled, although the reasoning is clear enough. > > Comments?
OK. Richard. > thanks > Iain > > gcc/ > > * collect2.c (main): Combine flags from both the command line and > COLLECT_GCC_OPTIONS to determine the set in force. > > --- > gcc/collect2.c | 55 +++++++++++++++++++++++++++++--------------------- > 1 file changed, 32 insertions(+), 23 deletions(-) > > diff --git a/gcc/collect2.c b/gcc/collect2.c > index a96af137a4..9ead5a6a1d 100644 > --- a/gcc/collect2.c > +++ b/gcc/collect2.c > @@ -979,13 +979,14 @@ main (int argc, char **argv) > object = CONST_CAST2 (const char **, char **, object_lst); > > #ifdef DEBUG > - debug = 1; > + debug = true; > #endif > > - /* Parse command line early for instances of -debug. This allows > - the debug flag to be set before functions like find_a_file() > - are called. We also look for the -flto or -flto-partition=none flag to > know > - what LTO mode we are in. */ > + save_temps = false; > + verbose = false; > + /* Parse command line / environment for flags we want early. > + This allows the debug flag to be set before functions like find_a_file() > + are called. */ > { > bool no_partition = false; > > @@ -993,8 +994,6 @@ main (int argc, char **argv) > { > if (! strcmp (argv[i], "-debug")) > debug = true; > - else if (! strcmp (argv[i], "-flto-partition=none")) > - no_partition = true; > else if (!strncmp (argv[i], "-fno-lto", 8)) > lto_mode = LTO_MODE_NONE; > else if (! strcmp (argv[i], "-plugin")) > @@ -1027,13 +1026,6 @@ main (int argc, char **argv) > aixlazy_flag = 1; > #endif > } > - verbose = debug; > - find_file_set_debug (debug); > - if (use_plugin) > - lto_mode = LTO_MODE_NONE; > - if (no_partition && lto_mode == LTO_MODE_WHOPR) > - lto_mode = LTO_MODE_LTO; > - } > > #ifndef DEFAULT_A_OUT_NAME > output_file = "a.out"; > @@ -1041,20 +1033,37 @@ main (int argc, char **argv) > output_file = DEFAULT_A_OUT_NAME; > #endif > > - obstack_begin (&temporary_obstack, 0); > - temporary_firstobj = (char *) obstack_alloc (&temporary_obstack, 0); > + obstack_begin (&temporary_obstack, 0); > + temporary_firstobj = (char *) obstack_alloc (&temporary_obstack, 0); > > #ifndef HAVE_LD_DEMANGLE > current_demangling_style = auto_demangling; > #endif > - p = getenv ("COLLECT_GCC_OPTIONS"); > - while (p && *p) > - { > - const char *q = extract_string (&p); > - if (*q == '-' && (q[1] == 'm' || q[1] == 'f')) > - num_c_args++; > + > + /* Now pick up any flags we want early from COLLECT_GCC_OPTIONS > + The LTO options are passed here as are other options that might > + be unsuitable for ld (e.g. -save-temps). */ > + p = getenv ("COLLECT_GCC_OPTIONS"); > + while (p && *p) > + { > + const char *q = extract_string (&p); > + if (*q == '-' && (q[1] == 'm' || q[1] == 'f')) > + num_c_args++; > + if (strncmp (q, "-flto-partition=none", 20) == 0) > + no_partition = true; > + else if (strncmp (q, "-fno-lto", 8) == 0) > + lto_mode = LTO_MODE_NONE; > } > - obstack_free (&temporary_obstack, temporary_firstobj); > + obstack_free (&temporary_obstack, temporary_firstobj); > + > + verbose |= debug; > + save_temps |= debug; > + find_file_set_debug (debug); > + if (use_plugin) > + lto_mode = LTO_MODE_NONE; > + if (no_partition && lto_mode == LTO_MODE_WHOPR) > + lto_mode = LTO_MODE_LTO; > + } > > /* -fno-profile-arcs -fno-test-coverage -fno-branch-probabilities > -fno-exceptions -w -fno-whole-program */ > -- > 2.17.1 > >