]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
gcov: Fix use of profile info section
authorSebastian Huber <sebastian.huber@embedded-brains.de>
Wed, 14 Jul 2021 07:40:11 +0000 (09:40 +0200)
committerSebastian Huber <sebastian.huber@embedded-brains.de>
Wed, 21 Jul 2021 09:39:30 +0000 (11:39 +0200)
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

index dfc8108d5d835c7ef05b31b82f4fe044e01285bf..ac9a9fdad228271f121b3068519f7662bbd7e323 100644 (file)
@@ -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);
 }