From 305eb4066742418d3b14ee6e8bec76bfb2835a99 Mon Sep 17 00:00:00 2001 From: Sebastian Huber Date: Tue, 10 Nov 2020 16:21:07 +0100 Subject: [PATCH] Add -fprofile-info-section support --- gcc/common.opt | 8 ++++++++ gcc/coverage.c | 19 +++++++++++++++++-- gcc/opts.c | 4 ++++ 3 files changed, 29 insertions(+), 2 deletions(-) diff --git a/gcc/common.opt b/gcc/common.opt index 7d0e0d9c88a..1b69da681e3 100644 --- a/gcc/common.opt +++ b/gcc/common.opt @@ -2268,6 +2268,14 @@ fprofile-generate= Common Joined RejectNegative Enable common options for generating profile info for profile feedback directed optimizations, and set -fprofile-dir=. +fprofile-info-section +Common RejectNegative +Register a pointer to the profile information in the .gcov_info section. + +fprofile-info-section= +Common Joined RejectNegative Var(profile_info_section) +Register a pointer to the profile information in the named section. + fprofile-partial-training Common Report Var(flag_profile_partial_training) Optimization Do not assume that functions never executed during the train run are cold. diff --git a/gcc/coverage.c b/gcc/coverage.c index 7711412c3be..ec1c5d3d125 100644 --- a/gcc/coverage.c +++ b/gcc/coverage.c @@ -1151,8 +1151,23 @@ coverage_obj_init (void) ASM_GENERATE_INTERNAL_LABEL (name_buf, "LPBX", 0); DECL_NAME (gcov_info_var) = get_identifier (name_buf); - build_init_ctor (gcov_info_type); - build_gcov_exit_decl (); + if (profile_info_section) + { + tree var = build_decl (BUILTINS_LOCATION, + VAR_DECL, NULL_TREE, + build_pointer_type (gcov_info_type)); + TREE_STATIC (var) = 1; + ASM_GENERATE_INTERNAL_LABEL (name_buf, "LPBX", 2); + DECL_NAME (var) = get_identifier (name_buf); + set_decl_section_name (var, profile_info_section); + DECL_INITIAL (var) = build_fold_addr_expr (gcov_info_var); + varpool_node::finalize_decl (var); + } + else + { + build_init_ctor (gcov_info_type); + build_gcov_exit_decl (); + } return true; } diff --git a/gcc/opts.c b/gcc/opts.c index 96291e89a49..fd6e669471e 100644 --- a/gcc/opts.c +++ b/gcc/opts.c @@ -2602,6 +2602,10 @@ common_handle_option (struct gcc_options *opts, SET_OPTION_IF_UNSET (opts, opts_set, flag_ipa_bit_cp, value); break; + case OPT_fprofile_info_section: + opts->x_profile_info_section = ".gcov_info"; + break; + case OPT_fpatchable_function_entry_: { char *patch_area_arg = xstrdup (arg); -- 2.26.2