From patchwork Fri Nov 13 16:47:40 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sebastian Huber X-Patchwork-Id: 1399946 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=gcc.gnu.org (client-ip=8.43.85.97; helo=sourceware.org; envelope-from=gcc-patches-bounces@gcc.gnu.org; receiver=) Authentication-Results: ozlabs.org; dmarc=none (p=none dis=none) header.from=embedded-brains.de Received: from sourceware.org (unknown [8.43.85.97]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 4CXksx5zWJz9sTK for ; Sat, 14 Nov 2020 03:47:48 +1100 (AEDT) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 7309C393C872; Fri, 13 Nov 2020 16:47:46 +0000 (GMT) X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from dedi548.your-server.de (dedi548.your-server.de [85.10.215.148]) by sourceware.org (Postfix) with ESMTPS id 68D2C393C853 for ; Fri, 13 Nov 2020 16:47:43 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.3.2 sourceware.org 68D2C393C853 Authentication-Results: sourceware.org; dmarc=none (p=none dis=none) header.from=embedded-brains.de Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=sebastian.huber@embedded-brains.de Received: from sslproxy02.your-server.de ([78.47.166.47]) by dedi548.your-server.de with esmtpsa (TLSv1.3:TLS_AES_256_GCM_SHA384:256) (Exim 4.92.3) (envelope-from ) id 1kdcEf-0002M4-9E; Fri, 13 Nov 2020 17:47:41 +0100 Received: from [82.100.198.138] (helo=mail.embedded-brains.de) by sslproxy02.your-server.de with esmtpsa (TLSv1.2:ECDHE-RSA-AES256-GCM-SHA384:256) (Exim 4.92) (envelope-from ) id 1kdcEf-0002AI-67; Fri, 13 Nov 2020 17:47:41 +0100 Received: from localhost (localhost.localhost [127.0.0.1]) by mail.embedded-brains.de (Postfix) with ESMTP id 3BF592A1610; Fri, 13 Nov 2020 17:44:48 +0100 (CET) Received: from mail.embedded-brains.de ([127.0.0.1]) by localhost (zimbra.eb.localhost [127.0.0.1]) (amavisd-new, port 10032) with ESMTP id V0v-RyfhO43G; Fri, 13 Nov 2020 17:44:47 +0100 (CET) Received: from localhost (localhost.localhost [127.0.0.1]) by mail.embedded-brains.de (Postfix) with ESMTP id B806A2A165B; Fri, 13 Nov 2020 17:44:47 +0100 (CET) X-Virus-Scanned: amavisd-new at zimbra.eb.localhost Received: from mail.embedded-brains.de ([127.0.0.1]) by localhost (zimbra.eb.localhost [127.0.0.1]) (amavisd-new, port 10026) with ESMTP id K_4cE5d6Law2; Fri, 13 Nov 2020 17:44:47 +0100 (CET) Received: from linux-diu0.suse (unknown [192.168.96.161]) by mail.embedded-brains.de (Postfix) with ESMTP id 99CE02A1610; Fri, 13 Nov 2020 17:44:47 +0100 (CET) From: Sebastian Huber To: gcc-patches@gcc.gnu.org Subject: [PATCH] gcov: Add -fprofile-info-section support Date: Fri, 13 Nov 2020 17:47:40 +0100 Message-Id: <20201113164740.4568-1-sebastian.huber@embedded-brains.de> X-Mailer: git-send-email 2.26.2 MIME-Version: 1.0 X-Authenticated-Sender: smtp-embedded@poldinet.de X-Virus-Scanned: Clear (ClamAV 0.102.4/25987/Fri Nov 13 14:19:33 2020) X-Spam-Status: No, score=-11.8 required=5.0 tests=BAYES_00, GIT_PATCH_0, KAM_DMARC_STATUS, SPF_HELO_NONE, SPF_PASS, TXREP autolearn=ham autolearn_force=no version=3.4.2 X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on server2.sourceware.org X-BeenThere: gcc-patches@gcc.gnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Gcc-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: gcc-patches-bounces@gcc.gnu.org Sender: "Gcc-patches" Register the profile information in the specified section instead of using a constructor/destructor. A pointer to the profile information generated by -fprofile-arcs or -ftest-coverage is placed in the specified section for each translation unit. This option disables the profile information registration through a constructor and it disables the profile information processing through a destructor. I am not sure how I can test this option. One approach would be to assemble a test file, then scan it and check that a .gcov_info section is present and no __gcov_init() and __gcov_exit() calls are present. Is there an example for this in the test suite? gcc/ * gcc/common.opt (fprofile-info-section): New. * gcc/coverage.c (build_gcov_info_var_registration): New. (coverage_obj_init): Evaluate profile_info_section and use build_gcov_info_var_registration(). * gcc/doc/invoke.texi (fprofile-info-section): Document. * gcc/opts.c (common_handle_option): Process fprofile-info-section option. --- gcc/common.opt | 8 ++++++++ gcc/coverage.c | 28 ++++++++++++++++++++++++++-- gcc/doc/invoke.texi | 29 +++++++++++++++++++++++++++++ gcc/opts.c | 4 ++++ 4 files changed, 67 insertions(+), 2 deletions(-) diff --git a/gcc/common.opt b/gcc/common.opt index 7d0e0d9c88a..114fe15e3c6 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 the profile information in the .gcov_info section instead of using a constructor/destructor. + +fprofile-info-section= +Common Joined RejectNegative Var(profile_info_section) +Register the profile information in the specified section instead of using a constructor/destructor. + 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..d299e48d591 100644 --- a/gcc/coverage.c +++ b/gcc/coverage.c @@ -1097,6 +1097,25 @@ build_gcov_exit_decl (void) cgraph_build_static_cdtor ('D', dtor, priority); } +/* Generate the pointer to the gcov_info_var in a dedicated section. */ + +static void +build_gcov_info_var_registration (tree gcov_info_type) +{ + tree var = build_decl (BUILTINS_LOCATION, + VAR_DECL, NULL_TREE, + build_pointer_type (gcov_info_type)); + TREE_STATIC (var) = 1; + TREE_READONLY (var) = 1; + char name_buf[32]; + ASM_GENERATE_INTERNAL_LABEL (name_buf, "LPBX", 2); + DECL_NAME (var) = get_identifier (name_buf); + get_section (profile_info_section, SECTION_UNNAMED, NULL); + set_decl_section_name (var, profile_info_section); + DECL_INITIAL (var) = build_fold_addr_expr (gcov_info_var); + varpool_node::finalize_decl (var); +} + /* Create the gcov_info types and object. Generate the constructor function to call __gcov_init. Does not generate the initializer for the object. Returns TRUE if coverage data is being emitted. */ @@ -1151,8 +1170,13 @@ 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) + build_gcov_info_var_registration (gcov_info_type); + else + { + build_init_ctor (gcov_info_type); + build_gcov_exit_decl (); + } return true; } diff --git a/gcc/doc/invoke.texi b/gcc/doc/invoke.texi index d01beb248e1..e78c3c23ad2 100644 --- a/gcc/doc/invoke.texi +++ b/gcc/doc/invoke.texi @@ -564,6 +564,7 @@ Objective-C and Objective-C++ Dialects}. @gccoptlist{-p -pg -fprofile-arcs --coverage -ftest-coverage @gol -fprofile-abs-path @gol -fprofile-dir=@var{path} -fprofile-generate -fprofile-generate=@var{path} @gol +-fprofile-info-section -fprofile-info-section=@var{name} @gol -fprofile-note=@var{path} -fprofile-prefix-path=@var{path} @gol -fprofile-update=@var{method} -fprofile-filter-files=@var{regex} @gol -fprofile-exclude-files=@var{regex} @gol @@ -14183,6 +14184,34 @@ the profile feedback data files. See @option{-fprofile-dir}. To optimize the program based on the collected profile information, use @option{-fprofile-use}. @xref{Optimize Options}, for more information. +@item -fprofile-info-section +@itemx -fprofile-info-section=@var{name} +@opindex fprofile-info-section + +Register the profile information in the specified section instead of using a +constructor/destructor. The section name is @var{name} if it is specified, +otherwise the section name defaults to @code{.gcov_info}. A pointer to the +profile information generated by @option{-fprofile-arcs} or +@option{-ftest-coverage} is placed in the specified section for each +translation unit. This option disables the profile information registration +through a constructor and it disables the profile information processing +through a destructor. This option is not intended to be used in hosted +environments such as GNU/Linux. It targets systems with limited resources +which do not support constructors and destructors. The linker could collect +the input sections in a continuous memory block and define start and end +symbols. The runtime support could dump the profiling information registered +in this linker set during program termination to a serial line for example. A +GNU linker script example which defines a linker output section follows: + +@smallexample + .gcov_info : + { + PROVIDE (__gcov_info_start = .); + KEEP (*(.gcov_info)) + PROVIDE (__gcov_info_end = .); + } +@end smallexample + @item -fprofile-note=@var{path} @opindex fprofile-note 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);