diff options
Diffstat (limited to 'gcc/lto-wrapper.c')
-rw-r--r-- | gcc/lto-wrapper.c | 154 |
1 files changed, 88 insertions, 66 deletions
diff --git a/gcc/lto-wrapper.c b/gcc/lto-wrapper.c index 4b86f939ca2..5e75a4fa48c 100644 --- a/gcc/lto-wrapper.c +++ b/gcc/lto-wrapper.c @@ -192,6 +192,20 @@ append_option (struct cl_decoded_option **decoded_options, sizeof (struct cl_decoded_option)); } +/* Remove option number INDEX from DECODED_OPTIONS, update + DECODED_OPTIONS_COUNT. */ + +static void +remove_option (struct cl_decoded_option **decoded_options, + int index, unsigned int *decoded_options_count) +{ + --*decoded_options_count; + memmove (&(*decoded_options)[index + 1], + &(*decoded_options)[index], + sizeof (struct cl_decoded_option) + * (*decoded_options_count - index)); +} + /* Try to merge and complain about options FDECODED_OPTIONS when applied ontop of DECODED_OPTIONS. */ @@ -202,6 +216,8 @@ merge_and_complain (struct cl_decoded_option **decoded_options, unsigned int fdecoded_options_count) { unsigned int i, j; + struct cl_decoded_option *pic_option = NULL; + struct cl_decoded_option *pie_option = NULL; /* ??? Merge options from files. Most cases can be handled by either unioning or intersecting @@ -238,13 +254,7 @@ merge_and_complain (struct cl_decoded_option **decoded_options, case OPT_fdiagnostics_show_option: case OPT_fdiagnostics_show_location_: case OPT_fshow_column: - case OPT_fPIC: - case OPT_fpic: - case OPT_fPIE: - case OPT_fpie: case OPT_fcommon: - case OPT_fexceptions: - case OPT_fnon_call_exceptions: case OPT_fgnu_tm: /* Do what the old LTO code did - collect exactly one option setting per OPT code, we pick the first we encounter. @@ -257,25 +267,16 @@ merge_and_complain (struct cl_decoded_option **decoded_options, append_option (decoded_options, decoded_options_count, foption); break; - case OPT_ftrapv: - case OPT_ffp_contract_: - /* For selected options we can merge conservatively. */ - 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); - /* FP_CONTRACT_OFF < FP_CONTRACT_ON < FP_CONTRACT_FAST, - -fno-trapv < -ftrapv, - -fno-strict-overflow < -fstrict-overflow */ - else if (foption->value < (*decoded_options)[j].value) - (*decoded_options)[j] = *foption; + /* Figure out what PIC/PIE level wins and merge the results. */ + case OPT_fPIC: + case OPT_fpic: + pic_option = foption; + break; + case OPT_fPIE: + case OPT_fpie: + pie_option = foption; break; - case OPT_fmath_errno: - case OPT_fsigned_zeros: - case OPT_ftrapping_math: - case OPT_fwrapv: case OPT_fopenmp: case OPT_fopenacc: case OPT_fcilkplus: @@ -286,10 +287,10 @@ merge_and_complain (struct cl_decoded_option **decoded_options, break; if (j == *decoded_options_count) append_option (decoded_options, decoded_options_count, foption); - /* -fmath-errno > -fno-math-errno, - -fsigned-zeros > -fno-signed-zeros, - -ftrapping-math > -fno-trapping-math, - -fwrapv > -fno-wrapv. */ + /* -fopenmp > -fno-openmp, + -fopenacc > -fno-openacc, + -fcilkplus > -fno-cilkplus, + -fcheck_pointer_bounds > -fcheck_pointer_bounds */ else if (foption->value > (*decoded_options)[j].value) (*decoded_options)[j] = *foption; break; @@ -307,29 +308,6 @@ merge_and_complain (struct cl_decoded_option **decoded_options, foption->orig_option_with_args_text); break; - case OPT_freg_struct_return: - case OPT_fpcc_struct_return: - for (j = 0; j < *decoded_options_count; ++j) - if ((*decoded_options)[j].opt_index == foption->opt_index) - break; - if (j == *decoded_options_count) - fatal_error (input_location, - "Option %s not used consistently in all LTO input" - " files", foption->orig_option_with_args_text); - break; - - case OPT_foffload_abi_: - 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); - else if (foption->value != (*decoded_options)[j].value) - fatal_error (input_location, - "Option %s not used consistently in all LTO input" - " files", foption->orig_option_with_args_text); - break; - case OPT_O: case OPT_Ofast: case OPT_Og: @@ -400,12 +378,70 @@ merge_and_complain (struct cl_decoded_option **decoded_options, (*decoded_options)[j].value = 1; } break; + + + case OPT_foffload_abi_: + 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); + else if (foption->value != (*decoded_options)[j].value) + fatal_error (input_location, + "Option %s not used consistently in all LTO input" + " files", foption->orig_option_with_args_text); + break; + case OPT_foffload_: append_option (decoded_options, decoded_options_count, foption); break; } } + + /* Merge PIC options: + -fPIC + -fpic = -fpic + -fPIC + -fno-pic = -fno-pic + -fpic/-fPIC + nothin = nothing. + It is a common mistake to mix few -fPIC compiled objects into otherwise + non-PIC code. We do not want to build everything with PIC then. + + It would be good to warn on mismatches, but it is bit hard to do as + we do not know what nothing translates to. */ + + for (unsigned int j = 0; j < *decoded_options_count;) + if ((*decoded_options)[j].opt_index == OPT_fPIC + || (*decoded_options)[j].opt_index == OPT_fpic) + { + if (!pic_option + || (pic_option->value > 0) != ((*decoded_options)[j].value > 0)) + remove_option (decoded_options, j, decoded_options_count); + else if (pic_option->opt_index == OPT_fPIC + && (*decoded_options)[j].opt_index == OPT_fpic) + { + (*decoded_options)[j] = *pic_option; + j++; + } + else + j++; + } + else if ((*decoded_options)[j].opt_index == OPT_fPIE + || (*decoded_options)[j].opt_index == OPT_fpie) + { + if (!pie_option + || pie_option->value != (*decoded_options)[j].value) + remove_option (decoded_options, j, decoded_options_count); + else if (pie_option->opt_index == OPT_fPIE + && (*decoded_options)[j].opt_index == OPT_fpie) + { + (*decoded_options)[j] = *pie_option; + j++; + } + else + j++; + } + else + j++; } /* Auxiliary function that frees elements of PTR and PTR itself. @@ -506,21 +542,11 @@ append_compiler_options (obstack *argv_obstack, struct cl_decoded_option *opts, case OPT_fPIE: case OPT_fpie: case OPT_fcommon: - case OPT_fexceptions: - case OPT_fnon_call_exceptions: case OPT_fgnu_tm: - case OPT_freg_struct_return: - case OPT_fpcc_struct_return: - case OPT_ffp_contract_: - case OPT_fmath_errno: - case OPT_fsigned_zeros: - case OPT_ftrapping_math: - case OPT_fwrapv: case OPT_fopenmp: case OPT_fopenacc: case OPT_fopenacc_dim_: case OPT_fcilkplus: - case OPT_ftrapv: case OPT_foffload_abi_: case OPT_O: case OPT_Ofast: @@ -595,12 +621,6 @@ append_linker_options (obstack *argv_obstack, struct cl_decoded_option *opts, /* We've handled these LTO options, do not pass them on. */ continue; - case OPT_freg_struct_return: - case OPT_fpcc_struct_return: - /* Ignore these, they are determined by the input files. - ??? We fail to diagnose a possible mismatch here. */ - continue; - case OPT_fopenmp: case OPT_fopenacc: case OPT_fcilkplus: @@ -838,6 +858,8 @@ copy_file (const char *dest, const char *src) fatal_error (input_location, "writing output file"); } } + fclose (d); + fclose (s); } /* Find the crtoffloadtable.o file in LIBRARY_PATH, make copy and pass name of |