public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug gcov-profile/105535] New: GCOV analysis on 16-bit target systems impossible
@ 2022-05-09 13:11 peter-helfert@t-online.de
  2022-05-09 14:19 ` [Bug gcov-profile/105535] " marxin at gcc dot gnu.org
                   ` (6 more replies)
  0 siblings, 7 replies; 8+ messages in thread
From: peter-helfert@t-online.de @ 2022-05-09 13:11 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=105535

            Bug ID: 105535
           Summary: GCOV analysis on 16-bit target systems impossible
           Product: gcc
           Version: 12.1.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: gcov-profile
          Assignee: unassigned at gcc dot gnu.org
          Reporter: peter-helfert@t-online.de
                CC: marxin at gcc dot gnu.org
  Target Milestone: ---

Created attachment 52944
  --> https://gcc.gnu.org/bugzilla/attachment.cgi?id=52944&action=edit
Proposed Patch file for libgcc/libgcov.h

Refers to 

GCC versions:

9.3.1 (oldest version I tested)

up to current release

12.1.0

GCOV analysis on 16-bit target systems impossible.

Length divergence of struct “gcov_info” member “n_functions”.

Dear GCC team,

Currently I am using GCC and its libgcov for on-target code coverage analysis
on a 16-bit target system (TI MSP-430). Unfortunately, during my GCOV test runs
I noticed an issue which breaks  code coverage analysis on 16-bit (and possibly
other) systems when using libgcov to assemble and write coverage information
directly on the target.

The issue is caused by a length divergence between the struct member
“n_functions” in the struct “gcov_info” (as declared in “libgcov.h”) and
statically allocated memory in generated object files.  The member
“n_functions” is declared as type “unsigned” in libgcov.h. The declared size
thus depends on the target system. On 32-bit systems, the “n_functions” member
declaration is 32 bits wide. However, on a 16-bit system, the size of the
“n_functions” element usually is reduced to 16 bits (sizeof(unsigned) == 2). 

This variable length, which depends on the compilation target, is not taken
into account when constructing the GCOV information stored as constant data in
the object file, generated at compile time. This information is generated and
included for every object file instrumented for GCOV analysis.  During
compilation, GCC generates an instance of the “gcov_info” struct in the
appropriate linker input section, where its member “n_functions” has a size of
(at least) 32 bits, irrespective of the compilation target. This size is not
compatible with the size declared in struct “gcov_info” on my 16-bit target, as
declared in the libgcov.h C-headers.

In gcc, during compilation of a source code file, the “n_functions” member is
generated by invoking “get_gcov_unsigned_t()” in function
“coverage_obj_init()”. The minimum size of an element generated by
get_gcov_usigned_t() is there hard-coded to 32 bits.

The size divergence of the “gcov_info” struct member “n_functions” causes a
shift of the subsequent struct member “functions" (pointer) by 2 bytes. This in
turn leads to a malfunction as soon as the pointer is accessed at runtime on
the 16-bit target. The issue generally prevents the target software from
collecting and outputting GCOV information on 16-bit systems and therefore
seems to be a quite severe problem, especially as it usually causes
unpredictable malfunction on software instrumented for GCOV analysis.

I wonder why that problem has not been reported before. Possibly, code coverage
analysis on 16-bit targets, using libgcov on target, is still not very common
these days.

Suggested solution:

In GCC source file “libgcov.h”:
In declaration of struct “gcov_info”:

Change: 

“unsigned n_functions” 

to 

“gcov_unsigned_t n_functions”

The gcov_unsigned_t is declared:

     typedef unsgined gcov_unsigned_t __attribute__ ((mode (SI)))

which ensures a 32-bit size for this type.

Other declarations in the context of libgcov and coverage, where the same
problem would otherwise appear, have been solved in the same fashion as my
proposed fix.

A proposed patch is attached to this bug report.

Thank you for considering my report.

Best regards,

Hans-Peter Helfert

^ permalink raw reply	[flat|nested] 8+ messages in thread

* [Bug gcov-profile/105535] GCOV analysis on 16-bit target systems impossible
  2022-05-09 13:11 [Bug gcov-profile/105535] New: GCOV analysis on 16-bit target systems impossible peter-helfert@t-online.de
@ 2022-05-09 14:19 ` marxin at gcc dot gnu.org
  2022-05-09 14:19 ` marxin at gcc dot gnu.org
                   ` (5 subsequent siblings)
  6 siblings, 0 replies; 8+ messages in thread
From: marxin at gcc dot gnu.org @ 2022-05-09 14:19 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=105535

Martin Liška <marxin at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
   Last reconfirmed|                            |2022-05-09
             Status|UNCONFIRMED                 |NEW
     Ever confirmed|0                           |1

--- Comment #1 from Martin Liška <marxin at gcc dot gnu.org> ---
Thank you very much for the analysis!

Do you want to send the patch to gcc-patches mailing list or should I do that
on your behalf?

^ permalink raw reply	[flat|nested] 8+ messages in thread

* [Bug gcov-profile/105535] GCOV analysis on 16-bit target systems impossible
  2022-05-09 13:11 [Bug gcov-profile/105535] New: GCOV analysis on 16-bit target systems impossible peter-helfert@t-online.de
  2022-05-09 14:19 ` [Bug gcov-profile/105535] " marxin at gcc dot gnu.org
@ 2022-05-09 14:19 ` marxin at gcc dot gnu.org
  2022-05-09 15:27 ` peter-helfert@t-online.de
                   ` (4 subsequent siblings)
  6 siblings, 0 replies; 8+ messages in thread
From: marxin at gcc dot gnu.org @ 2022-05-09 14:19 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=105535

Martin Liška <marxin at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|NEW                         |ASSIGNED
           Assignee|unassigned at gcc dot gnu.org      |marxin at gcc dot gnu.org

^ permalink raw reply	[flat|nested] 8+ messages in thread

* [Bug gcov-profile/105535] GCOV analysis on 16-bit target systems impossible
  2022-05-09 13:11 [Bug gcov-profile/105535] New: GCOV analysis on 16-bit target systems impossible peter-helfert@t-online.de
  2022-05-09 14:19 ` [Bug gcov-profile/105535] " marxin at gcc dot gnu.org
  2022-05-09 14:19 ` marxin at gcc dot gnu.org
@ 2022-05-09 15:27 ` peter-helfert@t-online.de
  2022-05-10 10:47 ` cvs-commit at gcc dot gnu.org
                   ` (3 subsequent siblings)
  6 siblings, 0 replies; 8+ messages in thread
From: peter-helfert@t-online.de @ 2022-05-09 15:27 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=105535

--- Comment #2 from Hans-Peter Helfert <peter-helfert@t-online.de> ---
Hello Martin,
Thanks for your quick response to my bug report. 
I'm not familiar with the customs on the gcc-patches mailing list. 
Would be nice if you  might put the patch on the gcc-patches mailing list 
on my behalf.

Thank you very much!

Hans-Peter



-----Ursprüngliche Nachricht-----
Von: marxin at gcc dot gnu.org <gcc-bugzilla@gcc.gnu.org> 
Gesendet: Montag, 9. Mai 2022 16:20
An: peter-helfert@t-online.de
Betreff: [Bug gcov-profile/105535] GCOV analysis on 16-bit target systems
impossible

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=105535

Martin Liška <marxin at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
   Last reconfirmed|                            |2022-05-09
             Status|UNCONFIRMED                 |NEW
     Ever confirmed|0                           |1

--- Comment #1 from Martin Liška <marxin at gcc dot gnu.org> ---
Thank you very much for the analysis!

Do you want to send the patch to gcc-patches mailing list or should I do that
on your behalf?

^ permalink raw reply	[flat|nested] 8+ messages in thread

* [Bug gcov-profile/105535] GCOV analysis on 16-bit target systems impossible
  2022-05-09 13:11 [Bug gcov-profile/105535] New: GCOV analysis on 16-bit target systems impossible peter-helfert@t-online.de
                   ` (2 preceding siblings ...)
  2022-05-09 15:27 ` peter-helfert@t-online.de
@ 2022-05-10 10:47 ` cvs-commit at gcc dot gnu.org
  2022-05-10 10:48 ` marxin at gcc dot gnu.org
                   ` (2 subsequent siblings)
  6 siblings, 0 replies; 8+ messages in thread
From: cvs-commit at gcc dot gnu.org @ 2022-05-10 10:47 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=105535

--- Comment #3 from CVS Commits <cvs-commit at gcc dot gnu.org> ---
The master branch has been updated by Martin Liska <marxin@gcc.gnu.org>:

https://gcc.gnu.org/g:1bac97ad0436afcbce24c82e6d57f11471cd8f10

commit r13-258-g1bac97ad0436afcbce24c82e6d57f11471cd8f10
Author: Martin Liska <mliska@suse.cz>
Date:   Tue May 10 10:52:19 2022 +0200

    libgcov: use proper type for n_functions

    gcov_info::n_functions type is initialized by generated
    code in build_info_type:

    /* n_functions */
    field = build_decl (BUILTINS_LOCATION, FIELD_DECL, NULL_TREE,
                        get_gcov_unsigned_t ());

    It uses gcov_unsigned_t, but the struct definition in libgcov.h uses
    unsigned type. That brings troubled on 16-bit targets.

            PR gcov-profile/105535

    libgcc/ChangeLog:

            * libgcov.h (struct gcov_info): Use gcov_unsigned_t for
            n_functions.

    Co-Authored-By: Hans-Peter Helfert <peter-helfert@t-online.de>

^ permalink raw reply	[flat|nested] 8+ messages in thread

* [Bug gcov-profile/105535] GCOV analysis on 16-bit target systems impossible
  2022-05-09 13:11 [Bug gcov-profile/105535] New: GCOV analysis on 16-bit target systems impossible peter-helfert@t-online.de
                   ` (3 preceding siblings ...)
  2022-05-10 10:47 ` cvs-commit at gcc dot gnu.org
@ 2022-05-10 10:48 ` marxin at gcc dot gnu.org
  2022-05-13 12:04 ` cvs-commit at gcc dot gnu.org
  2022-05-13 12:05 ` marxin at gcc dot gnu.org
  6 siblings, 0 replies; 8+ messages in thread
From: marxin at gcc dot gnu.org @ 2022-05-10 10:48 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=105535

Martin Liška <marxin at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
      Known to work|                            |13.0

--- Comment #4 from Martin Liška <marxin at gcc dot gnu.org> ---
Fixed on master so far.

^ permalink raw reply	[flat|nested] 8+ messages in thread

* [Bug gcov-profile/105535] GCOV analysis on 16-bit target systems impossible
  2022-05-09 13:11 [Bug gcov-profile/105535] New: GCOV analysis on 16-bit target systems impossible peter-helfert@t-online.de
                   ` (4 preceding siblings ...)
  2022-05-10 10:48 ` marxin at gcc dot gnu.org
@ 2022-05-13 12:04 ` cvs-commit at gcc dot gnu.org
  2022-05-13 12:05 ` marxin at gcc dot gnu.org
  6 siblings, 0 replies; 8+ messages in thread
From: cvs-commit at gcc dot gnu.org @ 2022-05-13 12:04 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=105535

--- Comment #5 from CVS Commits <cvs-commit at gcc dot gnu.org> ---
The releases/gcc-12 branch has been updated by Martin Liska
<marxin@gcc.gnu.org>:

https://gcc.gnu.org/g:5176d2755c6f4e348d1da00abfa4ab9f06a35ddd

commit r12-8374-g5176d2755c6f4e348d1da00abfa4ab9f06a35ddd
Author: Martin Liska <mliska@suse.cz>
Date:   Tue May 10 10:52:19 2022 +0200

    libgcov: use proper type for n_functions

    gcov_info::n_functions type is initialized by generated
    code in build_info_type:

    /* n_functions */
    field = build_decl (BUILTINS_LOCATION, FIELD_DECL, NULL_TREE,
                        get_gcov_unsigned_t ());

    It uses gcov_unsigned_t, but the struct definition in libgcov.h uses
    unsigned type. That brings troubled on 16-bit targets.

            PR gcov-profile/105535

    libgcc/ChangeLog:

            * libgcov.h (struct gcov_info): Use gcov_unsigned_t for
            n_functions.

    Co-Authored-By: Hans-Peter Helfert <peter-helfert@t-online.de>
    (cherry picked from commit eaf359ed04e7169f740dade548965c757f4c1e0a)

^ permalink raw reply	[flat|nested] 8+ messages in thread

* [Bug gcov-profile/105535] GCOV analysis on 16-bit target systems impossible
  2022-05-09 13:11 [Bug gcov-profile/105535] New: GCOV analysis on 16-bit target systems impossible peter-helfert@t-online.de
                   ` (5 preceding siblings ...)
  2022-05-13 12:04 ` cvs-commit at gcc dot gnu.org
@ 2022-05-13 12:05 ` marxin at gcc dot gnu.org
  6 siblings, 0 replies; 8+ messages in thread
From: marxin at gcc dot gnu.org @ 2022-05-13 12:05 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=105535

Martin Liška <marxin at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|ASSIGNED                    |RESOLVED
         Resolution|---                         |FIXED

--- Comment #6 from Martin Liška <marxin at gcc dot gnu.org> ---
Backported to gcc-12, closing now.

^ permalink raw reply	[flat|nested] 8+ messages in thread

end of thread, other threads:[~2022-05-13 12:05 UTC | newest]

Thread overview: 8+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-05-09 13:11 [Bug gcov-profile/105535] New: GCOV analysis on 16-bit target systems impossible peter-helfert@t-online.de
2022-05-09 14:19 ` [Bug gcov-profile/105535] " marxin at gcc dot gnu.org
2022-05-09 14:19 ` marxin at gcc dot gnu.org
2022-05-09 15:27 ` peter-helfert@t-online.de
2022-05-10 10:47 ` cvs-commit at gcc dot gnu.org
2022-05-10 10:48 ` marxin at gcc dot gnu.org
2022-05-13 12:04 ` cvs-commit at gcc dot gnu.org
2022-05-13 12:05 ` marxin at gcc dot gnu.org

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).