public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
From: Sebastian Huber <sebastian.huber@embedded-brains.de>
To: gcc-patches@gcc.gnu.org
Subject: [PATCH] gcov: Fix use of profile info section
Date: Wed, 14 Jul 2021 09:46:30 +0200	[thread overview]
Message-ID: <20210714074630.119391-1-sebastian.huber@embedded-brains.de> (raw)

If the -fprofile-info-section is used, then the gcov information is registered
in a linker set.  This is done by build_gcov_info_var_registration().  The
compiler generated object placed in the section was not marked as referenced,
so once optimization was enabled, this object was optimized away.  Mark it as
referenced.

gcc/
	coverage.c (build_gcov_info_var_registration): Mark the object placed
	in the linker set as referenced so that it does not get optimized away.
---
 gcc/coverage.c | 2 ++
 1 file changed, 2 insertions(+)

diff --git a/gcc/coverage.c b/gcc/coverage.c
index dfc8108d5d83..ac9a9fdad228 100644
--- a/gcc/coverage.c
+++ b/gcc/coverage.c
@@ -50,6 +50,7 @@ along with GCC; see the file COPYING3.  If not see
 #include "auto-profile.h"
 #include "profile.h"
 #include "diagnostic.h"
+#include "varasm.h"
 
 #include "gcov-io.c"
 
@@ -1121,6 +1122,7 @@ build_gcov_info_var_registration (tree gcov_info_type)
   DECL_NAME (var) = get_identifier (name_buf);
   get_section (profile_info_section, SECTION_UNNAMED, NULL);
   set_decl_section_name (var, profile_info_section);
+  mark_decl_referenced (var);
   DECL_INITIAL (var) = build_fold_addr_expr (gcov_info_var);
   varpool_node::finalize_decl (var);
 }
-- 
2.26.2


             reply	other threads:[~2021-07-14  7:46 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-07-14  7:46 Sebastian Huber [this message]
2021-07-20 22:05 ` Jeff Law

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20210714074630.119391-1-sebastian.huber@embedded-brains.de \
    --to=sebastian.huber@embedded-brains.de \
    --cc=gcc-patches@gcc.gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).