diff options
author | Martin Liska <mliska@suse.cz> | 2021-02-05 13:11:44 +0100 |
---|---|---|
committer | Martin Liska <mliska@suse.cz> | 2021-02-08 12:31:24 +0100 |
commit | 0d701e3eb89870237669ef7bf41394d90c35ae70 (patch) | |
tree | 1b07829e072abb7fee500525bdeb3a4b11e3e022 /gcc/opts.c | |
parent | fe2034e9c039c998fc5da730ed531c61cf2e0b7d (diff) | |
download | gcc-0d701e3eb89870237669ef7bf41394d90c35ae70.zip gcc-0d701e3eb89870237669ef7bf41394d90c35ae70.tar.gz gcc-0d701e3eb89870237669ef7bf41394d90c35ae70.tar.bz2 |
opts: fix handling of -fpatchable-function-entries option
gcc/ChangeLog:
PR lto/98971
* cfgexpand.c (pass_expand::execute): Parse per-function option
flag_patchable_function_entry and use it.
* common.opt: Remove function_entry_patch_area_size and
function_entry_patch_area_start global variables.
* opts.c (parse_and_check_patch_area): New function.
(common_handle_option): Use it.
* opts.h (parse_and_check_patch_area): New function.
* toplev.c (process_options): Parse and use
function_entry_patch_area_size.
Diffstat (limited to 'gcc/opts.c')
-rw-r--r-- | gcc/opts.c | 65 |
1 files changed, 41 insertions, 24 deletions
@@ -2130,6 +2130,44 @@ check_alignment_argument (location_t loc, const char *flag, const char *name, } } +/* Parse argument of -fpatchable-function-entry option ARG and store + corresponding values to PATCH_AREA_SIZE and PATCH_AREA_START. + If REPORT_ERROR is set to true, generate error for a problematic + option arguments. */ + +void +parse_and_check_patch_area (const char *arg, bool report_error, + HOST_WIDE_INT *patch_area_size, + HOST_WIDE_INT *patch_area_start) +{ + *patch_area_size = 0; + *patch_area_start = 0; + + if (arg == NULL) + return; + + char *patch_area_arg = xstrdup (arg); + char *comma = strchr (patch_area_arg, ','); + if (comma) + { + *comma = '\0'; + *patch_area_size = integral_argument (patch_area_arg); + *patch_area_start = integral_argument (comma + 1); + } + else + *patch_area_size = integral_argument (patch_area_arg); + + if (*patch_area_size < 0 + || *patch_area_size > USHRT_MAX + || *patch_area_start < 0 + || *patch_area_start > USHRT_MAX + || *patch_area_size < *patch_area_start) + if (report_error) + error ("invalid arguments for %<-fpatchable-function-entry%>"); + + free (patch_area_arg); +} + /* Print help when OPT__help_ is set. */ void @@ -2671,30 +2709,9 @@ common_handle_option (struct gcc_options *opts, case OPT_fpatchable_function_entry_: { - char *patch_area_arg = xstrdup (arg); - char *comma = strchr (patch_area_arg, ','); - if (comma) - { - *comma = '\0'; - function_entry_patch_area_size = - integral_argument (patch_area_arg); - function_entry_patch_area_start = - integral_argument (comma + 1); - } - else - { - function_entry_patch_area_size = - integral_argument (patch_area_arg); - function_entry_patch_area_start = 0; - } - if (function_entry_patch_area_size < 0 - || function_entry_patch_area_size > USHRT_MAX - || function_entry_patch_area_start < 0 - || function_entry_patch_area_start > USHRT_MAX - || function_entry_patch_area_size - < function_entry_patch_area_start) - error ("invalid arguments for %<-fpatchable-function-entry%>"); - free (patch_area_arg); + HOST_WIDE_INT patch_area_size, patch_area_start; + parse_and_check_patch_area (arg, true, &patch_area_size, + &patch_area_start); } break; |