Commit 52a35ef7 by Richard Guenther Committed by Richard Biener

re PR lto/44965 (lto option code breaks file format with each added option)

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.

	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.

From-SVN: r180827
parent fa66fc02
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>
......@@ -3137,16 +3137,6 @@ driver_wrong_lang_callback (const struct cl_decoded_option *decoded,
&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;
......@@ -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->post_handling_callback = driver_post_handling_callback;
handlers->num_handlers = 3;
handlers->handlers[0].handler = driver_handle_option;
handlers->handlers[0].mask = CL_DRIVER;
......
......@@ -882,12 +882,7 @@ extern GTY(()) VEC(tree,gc) *lto_global_var_decls;
/* 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_reissue_options (void);
void lto_clear_user_options (void);
void lto_clear_file_options (void);
/* In lto-wpa-fixup.c */
......
......@@ -45,6 +45,14 @@ along with GCC; see the file COPYING3. If not see
#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. */
......@@ -336,6 +344,78 @@ get_options_from_collect_gcc_options (const char *collect_gcc,
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. */
......@@ -351,6 +431,8 @@ run_gcc (unsigned argc, char *argv[])
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;
......@@ -368,11 +450,125 @@ run_gcc (unsigned argc, char *argv[])
&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");
/* 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];
......
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.
......
......@@ -692,8 +692,6 @@ lto_post_options (const char **pfilename ATTRIBUTE_UNUSED)
support. */
flag_excess_precision_cmdline = EXCESS_PRECISION_FAST;
lto_read_all_file_options ();
/* Initialize the compiler back end. */
return false;
}
......
......@@ -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
......@@ -2921,6 +2867,7 @@ lto_init (void)
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 ();
......
......@@ -878,9 +878,6 @@ handle_option (struct gcc_options *opts,
lang_mask, kind, loc,
handlers, dc))
return false;
else
handlers->post_handling_callback (decoded,
handlers->handlers[i].mask);
}
return true;
......
......@@ -160,19 +160,6 @@ unknown_option_callback (const struct cl_decoded_option *decoded)
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. */
......@@ -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->post_handling_callback = post_handling_callback;
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);
#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,
......
......@@ -291,10 +291,6 @@ struct cl_option_handlers
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;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment