From 7d3887b1b24901eca69614e601b6e8f36e5c86eb Mon Sep 17 00:00:00 2001 From: marxin Date: Fri, 9 Nov 2018 16:28:07 +0100 Subject: [PATCH] Come up with -flive-patching master option. gcc/ChangeLog: 2018-11-09 Martin Liska * common.opt: Add -flive-patching option. * opts.c (disable_live_patching_related_optimizations): New function where we disable all optimizations that are potentially dangerous for live patching. (common_handle_option): Call the function. --- gcc/common.opt | 4 ++++ gcc/opts.c | 31 +++++++++++++++++++++++++++++++ 2 files changed, 35 insertions(+) diff --git a/gcc/common.opt b/gcc/common.opt index 98e8eb03ef3..475b667f26b 100644 --- a/gcc/common.opt +++ b/gcc/common.opt @@ -2156,6 +2156,10 @@ flive-range-shrinkage Common Report Var(flag_live_range_shrinkage) Init(0) Optimization Relief of register pressure through live range shrinkage. +flive-patching +Common Report Var(flag_live_patching) Init(0) Optimization +Perform only safe IPA transformations for live patching. + frename-registers Common Report Var(flag_rename_registers) Init(2) Optimization Perform a register renaming optimization pass. diff --git a/gcc/opts.c b/gcc/opts.c index e21967ba84d..dd0c24ac2f9 100644 --- a/gcc/opts.c +++ b/gcc/opts.c @@ -1548,6 +1548,33 @@ enable_fdo_optimizations (struct gcc_options *opts, opts->x_flag_tree_loop_distribute_patterns = value; } +/* Disable IPA optimization that are not safe for live patching. */ + +static void +disable_live_patching_related_optimizations (gcc_options *opts, + gcc_options *opts_set) +{ + if (!opts_set->x_flag_ipa_icf_functions) + opts->x_flag_ipa_icf_functions = 0; + + if (!opts_set->x_flag_ipa_icf) + opts->x_flag_ipa_icf = 0; + if (!opts_set->x_flag_ipa_icf_variables) + opts->x_flag_ipa_icf_variables = 0; + if (!opts_set->x_flag_ipa_pure_const) + opts->x_flag_ipa_pure_const = 0; + if (!opts_set->x_flag_ipa_pta) + opts->x_flag_ipa_pta = 0; + if (!opts_set->x_flag_ipa_reference) + opts->x_flag_ipa_reference = 0; + if (!opts_set->x_flag_ipa_reference_addressable) + opts->x_flag_ipa_reference_addressable = 0; + if (!opts_set->x_flag_ipa_stack_alignment) + opts->x_flag_ipa_stack_alignment = 0; + if (!opts_set->x_flag_ipa_ra) + opts->x_flag_ipa_ra = 0; +} + /* -f{,no-}sanitize{,-recover}= suboptions. */ const struct sanitizer_opts_s sanitizer_opts[] = { @@ -2266,6 +2293,10 @@ common_handle_option (struct gcc_options *opts, (&opts->x_flag_instrument_functions_exclude_files, arg); break; + case OPT_flive_patching: + if (value) + disable_live_patching_related_optimizations (opts, opts_set); + case OPT_fmessage_length_: pp_set_line_maximum_length (dc->printer, value); diagnostic_set_caret_max_width (dc, value); -- 2.19.1