diff options
author | Sebastian Huber <sebastian.huber@embedded-brains.de> | 2020-11-13 17:47:40 +0100 |
---|---|---|
committer | Martin Liska <mliska@suse.cz> | 2020-11-16 12:52:14 +0100 |
commit | 27f7fb79d27bd4a4a7f04d4970c06e9050a6564e (patch) | |
tree | 4af8d2df27787d146b742cc8cde93ea3e668c084 /gcc/coverage.c | |
parent | d0a206abc6cbf0e992bf82bbb3584686eae05d34 (diff) | |
download | gcc-27f7fb79d27bd4a4a7f04d4970c06e9050a6564e.zip gcc-27f7fb79d27bd4a4a7f04d4970c06e9050a6564e.tar.gz gcc-27f7fb79d27bd4a4a7f04d4970c06e9050a6564e.tar.bz2 |
gcov: Add -fprofile-info-section support
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/
* common.opt (fprofile-info-section): New.
* coverage.c (build_gcov_info_var_registration): New.
(coverage_obj_init): Evaluate profile_info_section and use
build_gcov_info_var_registration().
* doc/invoke.texi (fprofile-info-section): Document.
* opts.c (common_handle_option): Process fprofile-info-section
option.
gcc/testsuite/ChangeLog:
* gcc.dg/profile-info-section.c: New test.
Diffstat (limited to 'gcc/coverage.c')
-rw-r--r-- | gcc/coverage.c | 28 |
1 files changed, 26 insertions, 2 deletions
diff --git a/gcc/coverage.c b/gcc/coverage.c index 7711412..d299e48 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; } |