OSDN Git Service

2011-11-03 Richard Guenther <rguenther@suse.de>
authorrguenth <rguenth@138bc75d-0d04-0410-961f-82ee72b054a4>
Thu, 3 Nov 2011 14:46:26 +0000 (14:46 +0000)
committerrguenth <rguenth@138bc75d-0d04-0410-961f-82ee72b054a4>
Thu, 3 Nov 2011 14:46:26 +0000 (14:46 +0000)
PR lto/44965
* lto-opts.c: Re-implement.
* lto-streamer.h (lto_register_user_option): Remove.
(lto_read_file_options): Likewise.
(lto_reissue_options): Likewise.
(lto_clear_user_options): Likewise.
(lto_clear_file_options): Likewise.
* opts-global.c (post_handling_callback): Remove.
(set_default_handlers): Do not set post_handling_callback.
(decode_options): Remove LTO specific code.
* lto-wrapper.c (merge_and_complain): New function.
(run_gcc): Read all input file options and
prepend a merged set before the linker driver options.
* gcc.c (driver_post_handling_callback): Remove.
(set_option_handlers): Do not set post_handling_callback.
* opts-common.c (handle_option): Do not call post_handling_callback.
* opts.h (struct cl_option_handlers): Remove post_handling_callback.

lto/
* lto-lang.c (lto_post_options): Do not read file options.
* lto.c (lto_read_all_file_options): Remove.
(lto_init): Call lto_set_in_hooks here.

git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/trunk@180827 138bc75d-0d04-0410-961f-82ee72b054a4

gcc/ChangeLog
gcc/gcc.c
gcc/lto-opts.c
gcc/lto-streamer.h
gcc/lto-wrapper.c
gcc/lto/ChangeLog
gcc/lto/lto-lang.c
gcc/lto/lto.c
gcc/opts-common.c
gcc/opts-global.c
gcc/opts.h

index 8da2816..5516c2f 100644 (file)
@@ -1,5 +1,25 @@
 2011-11-03  Richard Guenther  <rguenther@suse.de>
 
 2011-11-03  Richard Guenther  <rguenther@suse.de>
 
+       PR lto/44965
+       * lto-opts.c: Re-implement.
+       * lto-streamer.h (lto_register_user_option): Remove.
+       (lto_read_file_options): Likewise.
+       (lto_reissue_options): Likewise.
+       (lto_clear_user_options): Likewise.
+       (lto_clear_file_options): Likewise.
+       * opts-global.c (post_handling_callback): Remove.
+       (set_default_handlers): Do not set post_handling_callback.
+       (decode_options): Remove LTO specific code.
+       * lto-wrapper.c (merge_and_complain): New function.
+       (run_gcc): Read all input file options and
+       prepend a merged set before the linker driver options.
+       * gcc.c (driver_post_handling_callback): Remove.
+       (set_option_handlers): Do not set post_handling_callback.
+       * opts-common.c (handle_option): Do not call post_handling_callback.
+       * opts.h (struct cl_option_handlers): Remove post_handling_callback.
+
+2011-11-03  Richard Guenther  <rguenther@suse.de>
+
        * collect2.c (main): Guard object_nbr variable with TARGET_AIX_VERSION.
 
 2011-11-03  Martin Jambor  <mjambor@suse.cz>
        * collect2.c (main): Guard object_nbr variable with TARGET_AIX_VERSION.
 
 2011-11-03  Martin Jambor  <mjambor@suse.cz>
index 0fd4edd..46130dc 100644 (file)
--- a/gcc/gcc.c
+++ b/gcc/gcc.c
@@ -3137,16 +3137,6 @@ driver_wrong_lang_callback (const struct cl_decoded_option *decoded,
                 &decoded->canonical_option[1], false);
 }
 
                 &decoded->canonical_option[1], false);
 }
 
-/* Note that an option (index OPT_INDEX, argument ARG, value VALUE)
-   has been successfully handled with a handler for mask MASK.  */
-
-static void
-driver_post_handling_callback (const struct cl_decoded_option *decoded ATTRIBUTE_UNUSED,
-                              unsigned int mask ATTRIBUTE_UNUSED)
-{
-  /* Nothing to do here.  */
-}
-
 static const char *spec_lang = 0;
 static int last_language_n_infiles;
 
 static const char *spec_lang = 0;
 static int last_language_n_infiles;
 
@@ -3533,7 +3523,6 @@ set_option_handlers (struct cl_option_handlers *handlers)
 {
   handlers->unknown_option_callback = driver_unknown_option_callback;
   handlers->wrong_lang_callback = driver_wrong_lang_callback;
 {
   handlers->unknown_option_callback = driver_unknown_option_callback;
   handlers->wrong_lang_callback = driver_wrong_lang_callback;
-  handlers->post_handling_callback = driver_post_handling_callback;
   handlers->num_handlers = 3;
   handlers->handlers[0].handler = driver_handle_option;
   handlers->handlers[0].mask = CL_DRIVER;
   handlers->num_handlers = 3;
   handlers->handlers[0].handler = driver_handle_option;
   handlers->handlers[0].mask = CL_DRIVER;
index 296739e..47f73aa 100644 (file)
@@ -1,6 +1,6 @@
 /* LTO IL options.
 
 /* LTO IL options.
 
-   Copyright 2009, 2010, 2011 Free Software Foundation, Inc.
+   Copyright 2009, 2010, 2011, 2012 Free Software Foundation, Inc.
    Contributed by Simon Baldwin <simonb@google.com>
 
 This file is part of GCC.
    Contributed by Simon Baldwin <simonb@google.com>
 
 This file is part of GCC.
@@ -33,390 +33,89 @@ along with GCC; see the file COPYING3.  If not see
 #include "common/common-target.h"
 #include "diagnostic.h"
 #include "lto-streamer.h"
 #include "common/common-target.h"
 #include "diagnostic.h"
 #include "lto-streamer.h"
-
-/* When a file is initially compiled, the options used when generating
-   the IL are not necessarily the same as those used when linking the
-   objects into the final executable.  In general, most build systems
-   will proceed with something along the lines of:
-
-       $ gcc <cc-flags> -flto -c f1.c -o f1.o
-       $ gcc <cc-flags> -flto -c f2.c -o f2.o
-       ...
-       $ gcc <cc-flags> -flto -c fN.c -o fN.o
-
-   And the final link may or may not include the same <cc-flags> used
-   to generate the initial object files:
-
-       $ gcc <ld-flags> -flto -o prog f1.o ... fN.o
-
-   Since we will be generating final code during the link step, some
-   of the flags used during the compile step need to be re-applied
-   during the link step.  For instance, flags in the -m family.
-
-   The idea is to save a selected set of <cc-flags> in a special
-   section of the initial object files.  This section is then read
-   during linking and the options re-applied.
-
-   FIXME lto.  Currently the scheme is limited in that only the
-   options saved on the first object file (f1.o) are read back during
-   the link step.  This means that the options used to compile f1.o
-   will be applied to ALL the object files in the final link step.
-   More work needs to be done to implement a merging and validation
-   mechanism, as this will not be enough for all cases.  */
-
-/* Saved options hold the type of the option (currently CL_TARGET or
-   CL_COMMON), and the code, argument, and value.  */
-
-typedef struct GTY(()) opt_d
-{
-  unsigned int type;
-  size_t code;
-  char *arg;
-  int value;
-} opt_t;
-
-DEF_VEC_O (opt_t);
-DEF_VEC_ALLOC_O (opt_t, heap);
-
-
-/* Options are held in two vectors, one for those registered by
-   command line handling code, and the other for those read in from
-   any LTO IL input.  */
-static VEC(opt_t, heap) *user_options = NULL;
-static VEC(opt_t, heap) *file_options = NULL;
-
-/* Iterate FROM in reverse, writing option codes not yet in CODES into *TO.
-   Mark each new option code encountered in CODES.  */
-
-static void
-reverse_iterate_options (VEC(opt_t, heap) *from, VEC(opt_t, heap) **to,
-                        bitmap codes)
-{
-  int i;
-
-  for (i = VEC_length (opt_t, from); i > 0; i--)
-    {
-      const opt_t *const o = VEC_index (opt_t, from, i - 1);
-
-      if (bitmap_set_bit (codes, o->code))
-       VEC_safe_push (opt_t, heap, *to, o);
-    }
-}
-
-/* Concatenate options vectors FIRST and SECOND, rationalize so that only the
-   final of any given option remains, and return the result.  */
-
-static VEC(opt_t, heap) *
-concatenate_options (VEC(opt_t, heap) *first, VEC(opt_t, heap) *second)
-{
-  VEC(opt_t, heap) *results = NULL;
-  bitmap codes = lto_bitmap_alloc ();
-
-  reverse_iterate_options (second, &results, codes);
-  reverse_iterate_options (first, &results, codes);
-
-  lto_bitmap_free (codes);
-  return results;
-}
-
-/* Clear the options vector in *OPTS_P and set it to NULL.  */
-
-static void
-clear_options (VEC(opt_t, heap) **opts_p)
-{
-  int i;
-  opt_t *o;
-
-  FOR_EACH_VEC_ELT (opt_t, *opts_p, i, o)
-    free (o->arg);
-
-  VEC_free (opt_t, heap, *opts_p);
-}
-
-/* Write LENGTH bytes from ADDR to STREAM.  */
-
-static void
-output_data_stream (struct lto_output_stream *stream,
-                    const void *addr, size_t length)
-{
-  lto_output_data_stream (stream, addr, length);
-}
-
-/* Write string STRING to STREAM.  */
-
-static void
-output_string_stream (struct lto_output_stream *stream, const char *string)
-{
-  bool flag = false;
-
-  if (string != NULL)
-    {
-      const size_t length = strlen (string);
-
-      flag = true;
-      output_data_stream (stream, &flag, sizeof (flag));
-      output_data_stream (stream, &length, sizeof (length));
-      output_data_stream (stream, string, length);
-    }
-  else
-    output_data_stream (stream, &flag, sizeof (flag));
-}
-
-/* Return a string from IB.  The string is allocated, and the caller is
-   responsible for freeing it.  */
-
-static char *
-input_string_block (struct lto_input_block *ib)
-{
-  bool flag;
-
-  lto_input_data_block (ib, &flag, sizeof (flag));
-  if (flag)
-    {
-      size_t length;
-      char *string;
-
-      lto_input_data_block (ib, &length, sizeof (length));
-      string = (char *) xcalloc (1, length + 1);
-      lto_input_data_block (ib, string, length);
-
-      return string;
-    }
-  else
-    return NULL;
-}
-
-/* Return true if this option is one we need to save in LTO output files.
-   At present, we pass along all target options, and common options that
-   involve position independent code.
-
-   TODO This list of options requires expansion and rationalization.
-   Among others, optimization options may well be appropriate here.  */
-
-static bool
-register_user_option_p (size_t code, unsigned int type)
-{
-  if (type == CL_TARGET)
-    return true;
-  else if (type == CL_COMMON)
-    {
-      return (code == OPT_fPIC
-             || code == OPT_fpic
-             || code == OPT_fPIE
-             || code == OPT_fpie
-             || code == OPT_fcommon
-             || code == OPT_fexceptions);
-    }
-
-  return false;
-}
-
-/* Note command line option with the given TYPE and CODE, ARG, and VALUE.
-   If relevant to LTO, save it in the user options vector.  */
-
-void
-lto_register_user_option (size_t code, const char *arg, int value,
-                         unsigned int type)
-{
-  if (register_user_option_p (code, type))
-    {
-      opt_t o;
-
-      o.type = type;
-      o.code = code;
-      if (arg != NULL)
-       {
-         o.arg = (char *) xmalloc (strlen (arg) + 1);
-         strcpy (o.arg, arg);
-       }
-      else
-       o.arg = NULL;
-      o.value = value;
-      VEC_safe_push (opt_t, heap, user_options, &o);
-    }
-}
-
-/* Empty the saved user options vector.  */
-
-void
-lto_clear_user_options (void)
-{
-  clear_options (&user_options);
-}
-
-/* Empty the saved file options vector.  */
-
-void
-lto_clear_file_options (void)
-{
-  clear_options (&file_options);
-}
-
-/* Concatenate the user options and any file options read from an LTO IL
-   file, and serialize them to STREAM.  File options precede user options
-   so that the latter override the former when reissued.  */
-
-static void
-output_options (struct lto_output_stream *stream)
-{
-  VEC(opt_t, heap) *opts = concatenate_options (file_options, user_options);
-  const size_t length = VEC_length (opt_t, opts);
-  int i;
-  opt_t *o;
-
-  output_data_stream (stream, &length, sizeof (length));
-
-  FOR_EACH_VEC_ELT (opt_t, opts, i, o)
-    {
-      output_data_stream (stream, &o->type, sizeof (o->type));
-      output_data_stream (stream, &o->code, sizeof (o->code));
-      output_string_stream (stream, o->arg);
-      output_data_stream (stream, &o->value, sizeof (o->value));
-    }
-
-  VEC_free (opt_t, heap, opts);
-}
+#include "toplev.h"
 
 /* Write currently held options to an LTO IL section.  */
 
 void
 lto_write_options (void)
 {
 
 /* Write currently held options to an LTO IL section.  */
 
 void
 lto_write_options (void)
 {
-  char *const section_name = lto_get_section_name (LTO_section_opts, NULL, NULL);
   struct lto_output_stream stream;
   struct lto_output_stream stream;
-  struct lto_simple_header header;
-  struct lto_output_stream *header_stream;
-
-  /* Targets and languages can provide defaults for -fexceptions but
-     we only process user options from the command-line.  Until we
-     serialize out a white list of options from the new global state
-     explicitly append important options as user options here.  */
-  if (flag_exceptions)
-    lto_register_user_option (OPT_fexceptions, NULL, 1, CL_COMMON);
-
-  lto_begin_section (section_name, !flag_wpa);
-  free (section_name);
+  char *section_name;
+  struct obstack temporary_obstack;
+  unsigned int i, j;
+  char *args;
 
 
+  section_name = lto_get_section_name (LTO_section_opts, NULL, NULL);
+  lto_begin_section (section_name, false);
   memset (&stream, 0, sizeof (stream));
   memset (&stream, 0, sizeof (stream));
-  output_options (&stream);
 
 
-  memset (&header, 0, sizeof (header));
-  header.lto_header.major_version = LTO_major_version;
-  header.lto_header.minor_version = LTO_minor_version;
-  header.lto_header.section_type = LTO_section_opts;
-
-  header.compressed_size = 0;
-  header.main_size = stream.total_size;
-
-  header_stream = ((struct lto_output_stream *)
-                  xcalloc (1, sizeof (*header_stream)));
-  lto_output_data_stream (header_stream, &header, sizeof (header));
-  lto_write_stream (header_stream);
-  free (header_stream);
-
-  lto_write_stream (&stream);
-  lto_end_section ();
-}
-
-/* Unserialize an options vector from IB, and append to file_options.  */
-
-static void
-input_options (struct lto_input_block *ib)
-{
-  size_t length, i;
-
-  lto_input_data_block (ib, &length, sizeof (length));
-
-  for (i = 0; i < length; i++)
+  obstack_init (&temporary_obstack);
+  for (i = 1; i < save_decoded_options_count; ++i)
     {
     {
-      opt_t o;
-
-      lto_input_data_block (ib, &o.type, sizeof (o.type));
-      lto_input_data_block (ib, &o.code, sizeof (o.code));
-      o.arg = input_string_block (ib);
-      lto_input_data_block (ib, &o.value, sizeof (o.value));
-      VEC_safe_push (opt_t, heap, file_options, &o);
-    }
-}
-
-/* Read options from an LTO IL section.  */
-
-void
-lto_read_file_options (struct lto_file_decl_data *file_data)
-{
-  size_t len, l, skip;
-  const char *data, *p;
-  const struct lto_simple_header *header;
-  int32_t opts_offset;
-  struct lto_input_block ib;
-
-  data = lto_get_section_data (file_data, LTO_section_opts, NULL, &len);
-  if (!data)
-         return;
-
-  /* Option could be multiple sections merged (through ld -r) 
-     Keep reading all options.  This is ok right now because
-     the options just get mashed together anyways.
-     This will have to be done differently once lto-opts knows
-     how to associate options with different files. */
-  l = len;
-  p = data;
-  do 
-    { 
-      header = (const struct lto_simple_header *) p;
-      opts_offset = sizeof (*header);
-
-      lto_check_version (header->lto_header.major_version,
-                        header->lto_header.minor_version);
-      
-      LTO_INIT_INPUT_BLOCK (ib, p + opts_offset, 0, header->main_size);
-      input_options (&ib);
-      
-      skip = header->main_size + opts_offset;
-      l -= skip;
-      p += skip;
-    } 
-  while (l > 0);
-
-  lto_free_section_data (file_data, LTO_section_opts, 0, data, len);
-}
-
-/* Concatenate the user options and any file options read from an LTO IL
-   file, and reissue them as if all had just been read in from the command
-   line.  As with serialization, file options precede user options.  */
-
-void
-lto_reissue_options (void)
-{
-  VEC(opt_t, heap) *opts = concatenate_options (file_options, user_options);
-  int i;
-  opt_t *o;
+      struct cl_decoded_option *option = &save_decoded_options[i];
+      const char *q, *p;
+
+      /* Skip frontend and driver specific options here.  */
+      if (!(cl_options[option->opt_index].flags & (CL_COMMON|CL_TARGET|CL_LTO)))
+       continue;
+
+      /* Drop options created from the gcc driver that will be rejected
+        when passed on to the driver again.  */
+      if (cl_options[option->opt_index].cl_reject_driver)
+       continue;
+
+      /* Also drop all options that are handled by the driver as well,
+         which includes things like -o and -v or -fhelp for example.
+        We do not need those.  Also drop all diagnostic options.  */
+      if (cl_options[option->opt_index].flags & (CL_DRIVER|CL_WARNING))
+       continue;
+
+      /* Skip explicitly some common options that we do not need.  */
+      switch (option->opt_index)
+       {
+       case OPT_dumpbase:
+       case OPT_SPECIAL_input_file:
+         continue;
 
 
-  FOR_EACH_VEC_ELT (opt_t, opts, i, o)
-    {
-      void *flag_var = option_flag_var (o->code, &global_options);
+       default:
+         break;
+       }
 
 
-      if (flag_var)
-       set_option (&global_options, &global_options_set,
-                   o->code, o->value, o->arg,
-                   DK_UNSPECIFIED, UNKNOWN_LOCATION, global_dc);
+      if (i != 1)
+       obstack_grow (&temporary_obstack, " ", 1);
+      obstack_grow (&temporary_obstack, "'", 1);
+      q = option->canonical_option[0];
+      while ((p = strchr (q, '\'')))
+       {
+         obstack_grow (&temporary_obstack, q, p - q);
+         obstack_grow (&temporary_obstack, "'\\''", 4);
+         q = ++p;
+       }
+      obstack_grow (&temporary_obstack, q, strlen (q));
+      obstack_grow (&temporary_obstack, "'", 1);
 
 
-      if (o->type == CL_TARGET)
+      for (j = 1; j < option->canonical_option_num_elements; ++j)
        {
        {
-         struct cl_decoded_option decoded;
-         generate_option (o->code, o->arg, o->value, CL_TARGET, &decoded);
-         targetm_common.handle_option (&global_options, &global_options_set,
-                                       &decoded, UNKNOWN_LOCATION);
+         obstack_grow (&temporary_obstack, " '", 2);
+         q = option->canonical_option[j];
+         while ((p = strchr (q, '\'')))
+           {
+             obstack_grow (&temporary_obstack, q, p - q);
+             obstack_grow (&temporary_obstack, "'\\''", 4);
+             q = ++p;
+           }
+         obstack_grow (&temporary_obstack, q, strlen (q));
+         obstack_grow (&temporary_obstack, "'", 1);
        }
        }
-      else if (o->type == CL_COMMON)
-       gcc_assert (flag_var);
-      else
-       gcc_unreachable ();
     }
     }
+  obstack_grow (&temporary_obstack, "\0", 1);
+  args = XOBFINISH (&temporary_obstack, char *);
+  lto_output_data_stream (&stream, args, strlen (args) + 1);
 
 
-  /* Flag_shlib is usually set by finish_options, but we are issuing flag_pic
-     too late.  */
-  if (flag_pic && !flag_pie)
-    flag_shlib = 1;
-  VEC_free (opt_t, heap, opts);
+  lto_write_stream (&stream);
+  lto_end_section ();
+
+  obstack_free (&temporary_obstack, NULL);
+  free (section_name);
 }
 }
index f3c9368..58d4874 100644 (file)
@@ -882,12 +882,7 @@ extern GTY(()) VEC(tree,gc) *lto_global_var_decls;
 
 
 /* In lto-opts.c.  */
 
 
 /* In lto-opts.c.  */
-extern void lto_register_user_option (size_t, const char *, int, unsigned int);
-extern void lto_read_file_options (struct lto_file_decl_data *);
 extern void lto_write_options (void);
 extern void lto_write_options (void);
-extern void lto_reissue_options (void);
-void lto_clear_user_options (void);
-void lto_clear_file_options (void);
 
 
 /* In lto-wpa-fixup.c  */
 
 
 /* In lto-wpa-fixup.c  */
index c1480f9..5fb3762 100644 (file)
@@ -45,6 +45,14 @@ along with GCC; see the file COPYING3.  If not see
 #include "obstack.h"
 #include "opts.h"
 #include "options.h"
 #include "obstack.h"
 #include "opts.h"
 #include "options.h"
+#include "simple-object.h"
+
+/* From lto-streamer.h which we cannot include with -fkeep-inline-functions.
+   ???  Split out a lto-streamer-core.h.  */
+
+#define LTO_SECTION_NAME_PREFIX         ".gnu.lto_"
+
+/* End of lto-streamer.h copy.  */
 
 int debug;                             /* true if -save-temps.  */
 int verbose;                           /* true if -v.  */
 
 int debug;                             /* true if -save-temps.  */
 int verbose;                           /* true if -v.  */
@@ -336,6 +344,78 @@ get_options_from_collect_gcc_options (const char *collect_gcc,
   obstack_free (&argv_obstack, NULL);
 }
 
   obstack_free (&argv_obstack, NULL);
 }
 
+/* Append OPTION to the options array DECODED_OPTIONS with size
+   DECODED_OPTIONS_COUNT.  */
+
+static void
+append_option (struct cl_decoded_option **decoded_options,
+              unsigned int *decoded_options_count,
+              struct cl_decoded_option *option)
+{
+  ++*decoded_options_count;
+  *decoded_options
+    = (struct cl_decoded_option *)
+       xrealloc (*decoded_options,
+                 (*decoded_options_count
+                  * sizeof (struct cl_decoded_option)));
+  memcpy (&(*decoded_options)[*decoded_options_count - 1], option,
+         sizeof (struct cl_decoded_option));
+}
+
+/* Try to merge and complain about options FDECODED_OPTIONS when applied
+   ontop of DECODED_OPTIONS.  */
+
+static void
+merge_and_complain (struct cl_decoded_option **decoded_options,
+                   unsigned int *decoded_options_count,
+                   struct cl_decoded_option *fdecoded_options,
+                   unsigned int fdecoded_options_count)
+{
+  unsigned int i, j;
+
+  /* ???  Merge options from files.  Most cases can be
+     handled by either unioning or intersecting
+     (for example -fwrapv is a case for unioning,
+     -ffast-math is for intersection).  Most complaints
+     about real conflicts between different options can
+     be deferred to the compiler proper.  Options that
+     we can neither safely handle by intersection nor
+     unioning would need to be complained about here.
+     Ideally we'd have a flag in the opt files that
+     tells whether to union or intersect or reject.
+     In absence of that it's unclear what a good default is.
+     It's also difficult to get positional handling correct.  */
+
+  /* The following does what the old LTO option code did,
+     union all target and a selected set of common options.  */
+  for (i = 0; i < fdecoded_options_count; ++i)
+    {
+      struct cl_decoded_option *foption = &fdecoded_options[i];
+      switch (foption->opt_index)
+       {
+       default:
+         if (!(cl_options[foption->opt_index].flags & CL_TARGET))
+           break;
+
+         /* Fallthru.  */
+       case OPT_fPIC:
+       case OPT_fpic:
+       case OPT_fpie:
+       case OPT_fcommon:
+       case OPT_fexceptions:
+         /* Do what the old LTO code did - collect exactly one option
+            setting per OPT code, we pick the first we encounter.
+            ???  This doesn't make too much sense, but when it doesn't
+            then we should complain.  */
+         for (j = 0; j < *decoded_options_count; ++j)
+           if ((*decoded_options)[j].opt_index == foption->opt_index)
+             break;
+         if (j == *decoded_options_count)
+           append_option (decoded_options, decoded_options_count, foption);
+         break;
+       }
+    }
+}
 
 /* Execute gcc. ARGC is the number of arguments. ARGV contains the arguments. */
 
 
 /* Execute gcc. ARGC is the number of arguments. ARGV contains the arguments. */
 
@@ -351,6 +431,8 @@ run_gcc (unsigned argc, char *argv[])
   int parallel = 0;
   int jobserver = 0;
   bool no_partition = false;
   int parallel = 0;
   int jobserver = 0;
   bool no_partition = false;
+  struct cl_decoded_option *fdecoded_options = NULL;
+  unsigned int fdecoded_options_count = 0;
   struct cl_decoded_option *decoded_options;
   unsigned int decoded_options_count;
   struct obstack argv_obstack;
   struct cl_decoded_option *decoded_options;
   unsigned int decoded_options_count;
   struct obstack argv_obstack;
@@ -368,11 +450,125 @@ run_gcc (unsigned argc, char *argv[])
                                        &decoded_options,
                                        &decoded_options_count);
 
                                        &decoded_options,
                                        &decoded_options_count);
 
+  /* Look at saved options in the IL files.  */
+  for (i = 1; i < argc; ++i)
+    {
+      char *data, *p;
+      char *fopts;
+      int fd;
+      const char *errmsg;
+      int err;
+      off_t file_offset = 0, offset, length;
+      long loffset;
+      simple_object_read *sobj;
+      int consumed;
+      struct cl_decoded_option *f2decoded_options;
+      unsigned int f2decoded_options_count;
+      char *filename = argv[i];
+      if ((p = strrchr (argv[i], '@'))
+         && p != argv[i] 
+         && sscanf (p, "@%li%n", &loffset, &consumed) >= 1
+         && strlen (p) == (unsigned int) consumed)
+       {
+         filename = XNEWVEC (char, p - argv[i] + 1);
+         memcpy (filename, argv[i], p - argv[i]);
+         filename[p - argv[i]] = '\0';
+         file_offset = (off_t) loffset;
+       }
+      fd = open (argv[i], O_RDONLY);
+      if (fd == -1)
+       continue;
+      sobj = simple_object_start_read (fd, file_offset, NULL, &errmsg, &err);
+      if (!sobj)
+       {
+         close (fd);
+         continue;
+       }
+      if (!simple_object_find_section (sobj, LTO_SECTION_NAME_PREFIX "." "opts",
+                                      &offset, &length, &errmsg, &err))
+       {
+         simple_object_release_read (sobj);
+         close (fd);
+         continue;
+       }
+      lseek (fd, file_offset + offset, SEEK_SET);
+      data = (char *)xmalloc (length);
+      read (fd, data, length);
+      fopts = data;
+      do
+       {
+         get_options_from_collect_gcc_options (collect_gcc,
+                                               fopts, CL_LANG_ALL,
+                                               &f2decoded_options,
+                                               &f2decoded_options_count);
+         if (!fdecoded_options)
+           {
+             fdecoded_options = f2decoded_options;
+             fdecoded_options_count = f2decoded_options_count;
+           }
+         else
+           merge_and_complain (&fdecoded_options,
+                               &fdecoded_options_count,
+                               f2decoded_options, f2decoded_options_count);
+
+         fopts += strlen (fopts) + 1;
+       }
+      while (fopts - data < length);
+
+      free (data);
+      simple_object_release_read (sobj);
+      close (fd);
+    }
+
   /* Initalize the common arguments for the driver.  */
   obstack_init (&argv_obstack);
   obstack_ptr_grow (&argv_obstack, collect_gcc);
   obstack_ptr_grow (&argv_obstack, "-xlto");
   obstack_ptr_grow (&argv_obstack, "-c");
   /* Initalize the common arguments for the driver.  */
   obstack_init (&argv_obstack);
   obstack_ptr_grow (&argv_obstack, collect_gcc);
   obstack_ptr_grow (&argv_obstack, "-xlto");
   obstack_ptr_grow (&argv_obstack, "-c");
+
+  /* Append compiler driver arguments as far as they were merged.  */
+  for (j = 1; j < fdecoded_options_count; ++j)
+    {
+      struct cl_decoded_option *option = &fdecoded_options[j];
+
+      /* File options have been properly filtered by lto-opts.c.  */
+      switch (option->opt_index)
+       {
+         /* Drop arguments that we want to take from the link line.  */
+         case OPT_flto_:
+         case OPT_flto:
+         case OPT_flto_partition_none:
+         case OPT_flto_partition_1to1:
+         case OPT_flto_partition_balanced:
+             continue;
+
+         default:
+             break;
+       }
+
+      /* For now do what the original LTO option code was doing - pass
+        on any CL_TARGET flag and a few selected others.  */
+      switch (option->opt_index)
+       {
+       case OPT_fPIC:
+       case OPT_fpic:
+       case OPT_fpie:
+       case OPT_fcommon:
+       case OPT_fexceptions:
+         break;
+
+       default:
+         if (!(cl_options[option->opt_index].flags & CL_TARGET))
+           continue;
+       }
+
+      /* Pass the option on.  */
+      for (i = 0; i < option->canonical_option_num_elements; ++i)
+       obstack_ptr_grow (&argv_obstack, option->canonical_option[i]);
+    }
+
+  /* Append linker driver arguments.  Compiler options from the linker
+     driver arguments will override / merge with those from the compiler.  */
   for (j = 1; j < decoded_options_count; ++j)
     {
       struct cl_decoded_option *option = &decoded_options[j];
   for (j = 1; j < decoded_options_count; ++j)
     {
       struct cl_decoded_option *option = &decoded_options[j];
index 5de85dd..d8bbd9c 100644 (file)
@@ -1,3 +1,10 @@
+2011-11-03  Richard Guenther  <rguenther@suse.de>
+
+       PR lto/44965
+       * lto-lang.c (lto_post_options): Do not read file options.
+       * lto.c (lto_read_all_file_options): Remove.
+       (lto_init): Call lto_set_in_hooks here.
+
 2011-10-09  Jan Hubicka  <jh@suse.cz>
 
        * lto.c (node_cmp, varpool_node_cmp): New functions.
 2011-10-09  Jan Hubicka  <jh@suse.cz>
 
        * lto.c (node_cmp, varpool_node_cmp): New functions.
index 4a5f6fe..c702b9a 100644 (file)
@@ -692,8 +692,6 @@ lto_post_options (const char **pfilename ATTRIBUTE_UNUSED)
      support.  */
   flag_excess_precision_cmdline = EXCESS_PRECISION_FAST;
 
      support.  */
   flag_excess_precision_cmdline = EXCESS_PRECISION_FAST;
 
-  lto_read_all_file_options ();
-
   /* Initialize the compiler back end.  */
   return false;
 }
   /* Initialize the compiler back end.  */
   return false;
 }
index c50a97e..3b35604 100644 (file)
@@ -2494,60 +2494,6 @@ lto_fixup_decls (struct lto_file_decl_data **files)
     }
 }
 
     }
 }
 
-/* Read the options saved from each file in the command line.  Called
-   from lang_hooks.post_options which is called by process_options
-   right before all the options are used to initialize the compiler.
-   This assumes that decode_options has already run, so the
-   num_in_fnames and in_fnames are properly set.
-
-   Note that this assumes that all the files had been compiled with
-   the same options, which is not a good assumption.  In general,
-   options ought to be read from all the files in the set and merged.
-   However, it is still unclear what the merge rules should be.  */
-
-void
-lto_read_all_file_options (void)
-{
-  size_t i;
-
-  /* Clear any file options currently saved.  */
-  lto_clear_file_options ();
-
-  /* Set the hooks to read ELF sections.  */
-  lto_set_in_hooks (NULL, get_section_data, free_section_data);
-  if (!quiet_flag)
-    fprintf (stderr, "Reading command line options:");
-
-  for (i = 0; i < num_in_fnames; i++)
-    {
-      struct lto_file_decl_data *file_data;
-      lto_file *file = lto_obj_file_open (in_fnames[i], false);
-      if (!file)
-       break;
-      if (!quiet_flag)
-       {
-         fprintf (stderr, " %s", in_fnames[i]);
-         fflush (stderr);
-       }
-
-      file_data = XCNEW (struct lto_file_decl_data);
-      file_data->file_name = file->filename;
-      file_data->section_hash_table = lto_obj_build_section_table (file, NULL);
-
-      lto_read_file_options (file_data);
-
-      lto_obj_file_close (file);
-      htab_delete (file_data->section_hash_table);
-      free (file_data);
-    }
-
-  if (!quiet_flag)
-    fprintf (stderr, "\n");
-
-  /* Apply globally the options read from all the files.  */
-  lto_reissue_options ();
-}
-
 static GTY((length ("lto_stats.num_input_files + 1"))) struct lto_file_decl_data **all_file_decl_data;
 
 /* Turn file datas for sub files into a single array, so that they look
 static GTY((length ("lto_stats.num_input_files + 1"))) struct lto_file_decl_data **all_file_decl_data;
 
 /* Turn file datas for sub files into a single array, so that they look
@@ -2921,6 +2867,7 @@ lto_init (void)
   lto_process_name ();
   lto_streamer_hooks_init ();
   lto_reader_init ();
   lto_process_name ();
   lto_streamer_hooks_init ();
   lto_reader_init ();
+  lto_set_in_hooks (NULL, get_section_data, free_section_data);
   memset (&lto_stats, 0, sizeof (lto_stats));
   bitmap_obstack_initialize (NULL);
   gimple_register_cfg_hooks ();
   memset (&lto_stats, 0, sizeof (lto_stats));
   bitmap_obstack_initialize (NULL);
   gimple_register_cfg_hooks ();
index 0b86764..00edbe6 100644 (file)
@@ -878,9 +878,6 @@ handle_option (struct gcc_options *opts,
                                            lang_mask, kind, loc,
                                            handlers, dc))
          return false;
                                            lang_mask, kind, loc,
                                            handlers, dc))
          return false;
-       else
-         handlers->post_handling_callback (decoded,
-                                           handlers->handlers[i].mask);
       }
   
   return true;
       }
   
   return true;
index 6fdc951..b93d56f 100644 (file)
@@ -160,19 +160,6 @@ unknown_option_callback (const struct cl_decoded_option *decoded)
     return true;
 }
 
     return true;
 }
 
-/* Note that an option DECODED has been successfully handled with a
-   handler for mask MASK.  */
-
-static void
-post_handling_callback (const struct cl_decoded_option *decoded ATTRIBUTE_UNUSED,
-                       unsigned int mask ATTRIBUTE_UNUSED)
-{
-#ifdef ENABLE_LTO
-  lto_register_user_option (decoded->opt_index, decoded->arg,
-                           decoded->value, mask);
-#endif
-}
-
 /* Handle a front-end option; arguments and return value as for
    handle_option.  */
 
 /* Handle a front-end option; arguments and return value as for
    handle_option.  */
 
@@ -282,7 +269,6 @@ set_default_handlers (struct cl_option_handlers *handlers)
 {
   handlers->unknown_option_callback = unknown_option_callback;
   handlers->wrong_lang_callback = complain_wrong_lang;
 {
   handlers->unknown_option_callback = unknown_option_callback;
   handlers->wrong_lang_callback = complain_wrong_lang;
-  handlers->post_handling_callback = post_handling_callback;
   handlers->num_handlers = 3;
   handlers->handlers[0].handler = lang_handle_option;
   handlers->handlers[0].mask = initial_lang_mask;
   handlers->num_handlers = 3;
   handlers->handlers[0].handler = lang_handle_option;
   handlers->handlers[0].mask = initial_lang_mask;
@@ -314,11 +300,6 @@ decode_options (struct gcc_options *opts, struct gcc_options *opts_set,
                                decoded_options, decoded_options_count,
                                loc, lang_mask, &handlers, dc);
 
                                decoded_options, decoded_options_count,
                                loc, lang_mask, &handlers, dc);
 
-#ifdef ENABLE_LTO
-  /* Clear any options currently held for LTO.  */
-  lto_clear_user_options ();
-#endif
-
   read_cmdline_options (opts, opts_set,
                        decoded_options, decoded_options_count,
                        loc, lang_mask,
   read_cmdline_options (opts, opts_set,
                        decoded_options, decoded_options_count,
                        loc, lang_mask,
index 621cdea..dbefc64 100644 (file)
@@ -291,10 +291,6 @@ struct cl_option_handlers
   void (*wrong_lang_callback) (const struct cl_decoded_option *decoded,
                               unsigned int lang_mask);
 
   void (*wrong_lang_callback) (const struct cl_decoded_option *decoded,
                               unsigned int lang_mask);
 
-  /* Callback to call after the successful handling of any option.  */
-  void (*post_handling_callback) (const struct cl_decoded_option *decoded,
-                                 unsigned int mask);
-
   /* The number of individual handlers.  */
   size_t num_handlers;
 
   /* The number of individual handlers.  */
   size_t num_handlers;