[PATCH] gcov: Add -fprofile-info-section support

Sebastian Huber sebastian.huber@embedded-brains.de
Mon Nov 16 11:02:30 GMT 2020

Hello Martin,

On 16/11/2020 11:26, Martin Liška wrote:
> Sorry for slow response.
>> 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.
> The patch is fine.
thanks for having a look at it.
>> 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?
> I'm going to add a test for it. I'm going to test your patch and will 
> install
> it after it finishes the tests.
> Thanks for working on that. What will be your next steps in order to 
> support
> profiling of your embedded target? Something I can help with? 

I sent a proposal for a simple function to convert a gcov info to a gcda 
byte stream:


It could be used for something like this:

#include <gcov.h>
#include <stdio.h>

extern const struct gcov_info *__gcov_info_start[];
extern const struct gcov_info *__gcov_info_end[];

static void
filename(const char *f, void *arg)
     printf("filename: %s\n", f);

static void
dump(const void *d, unsigned n, void *arg)
     const unsigned char *c;
     unsigned i;

     c = d;

     for (i = 0; i < n; ++i) {
         printf("%02x", c[i]);

static void dump_all(void)
     const struct gcov_info **info;
     const struct gcov_info **end;

     info = __gcov_info_start;
     end = __gcov_info_end;

     /* Obfuscate variable to prevent compiler optimizations */
     __asm__("" : "+r" (end));

     while (info != end) {
         __gcov_info_to_gcda(*info, filename, dump, NULL);

int main()
     return 0;

In the linker command file you need these directives in a read-only 
memory area:

PROVIDE (__gcov_info_start = .);
KEEP (*(.gcov_info))
PROVIDE (__gcov_info_end = .);

embedded brains GmbH
Sebastian HUBER
Dornierstr. 4
82178 Puchheim
email: sebastian.huber@embedded-brains.de
Phone: +49-89-18 94 741 - 16
Fax:   +49-89-18 94 741 - 08
PGP: Public key available on request.

embedded brains GmbH
Registergericht: Amtsgericht München
Registernummer: HRB 157899
Vertretungsberechtigte Geschäftsführer: Peter Rasmussen, Thomas Dörfler
Unsere Datenschutzerklärung finden Sie hier: https://embedded-brains.de/datenschutzerklaerung/

More information about the Gcc-patches mailing list