public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug gcov-profile/97069] New: Zero valued #line directive results in excessively large blocks of memory being allocated
@ 2020-09-16 12:42 martin.ogden at arm dot com
  2020-09-16 13:44 ` [Bug gcov-profile/97069] " jakub at gcc dot gnu.org
                   ` (7 more replies)
  0 siblings, 8 replies; 9+ messages in thread
From: martin.ogden at arm dot com @ 2020-09-16 12:42 UTC (permalink / raw)
  To: gcc-bugs

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

            Bug ID: 97069
           Summary: Zero valued #line directive results in excessively
                    large blocks of memory being allocated
           Product: gcc
           Version: 11.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: gcov-profile
          Assignee: unassigned at gcc dot gnu.org
          Reporter: martin.ogden at arm dot com
                CC: marxin at gcc dot gnu.org
  Target Milestone: ---

Created attachment 49225
  --> https://gcc.gnu.org/bugzilla/attachment.cgi?id=49225&action=edit
Associated main.i file

Adding a #line directive with a line number of 0 causes gcov to attempt to
allocate large (~2G) blocks of memory. To reproduce, consider main.c:

    int main()
    {
    }

    #line 0 "main.c"
    void zero_line_directive()
    {
    }

Compile and attempt to run gcov:

    $ gcc main.c -Wall -Werror --coverage
    $ ./a.out
    $ gcov main.c # gcov a-main.c for gcc-11
    terminate called after throwing an instance of 'std::bad_alloc'
    what():  std::bad_alloc

The bad allocation is made in gcc/gcc/gcov.c at line 1346:

    s->lines.resize(last_line + 1);

A line number of 0 causes `last_line` to be large (often 0x100000, sometimes
larger ~10^8).


System details
--------------

Fault occurs on Ubuntu 16.04.6 with with gcc-{5,7,8,9,11} and gcov-{5,7,8,9,11}
(not tested with v{<=4,6,10}).

    $ lsb_release -a
    ...
    Distributor ID: Ubuntu
    Description:    Ubuntu 16.04.6 LTS
    Release:        16.04
    Codename:       xenial

    $ gcc -v
    gcc version 11.0.0 20200902 (experimental) (GCC)

    $ gcc-9 -v
    gcc-9 (Ubuntu 9.3.0-10ubuntu2~16.04) 9.3.0

    $ gcc-8
    gcc-8 (Ubuntu 8.1.0-9ubuntu1~16.04.york1) 8.1.0

    $ gcc-7 -v
    gcc-7 (Ubuntu 7.3.0-23ubuntu2~16.04.york0) 7.3.0

    $ gcc-5 -v
    gcc-5 (Ubuntu 5.5.0-12ubuntu1~16.04) 5.5.0 20171010

It also occurs on macOS 10.15.6 with gcc-{7,8,9} (not tested with
v{<=5,6,10,11}).

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

* [Bug gcov-profile/97069] Zero valued #line directive results in excessively large blocks of memory being allocated
  2020-09-16 12:42 [Bug gcov-profile/97069] New: Zero valued #line directive results in excessively large blocks of memory being allocated martin.ogden at arm dot com
@ 2020-09-16 13:44 ` jakub at gcc dot gnu.org
  2020-09-16 14:30 ` martin.ogden at arm dot com
                   ` (6 subsequent siblings)
  7 siblings, 0 replies; 9+ messages in thread
From: jakub at gcc dot gnu.org @ 2020-09-16 13:44 UTC (permalink / raw)
  To: gcc-bugs

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

Jakub Jelinek <jakub at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |jakub at gcc dot gnu.org

--- Comment #1 from Jakub Jelinek <jakub at gcc dot gnu.org> ---
Any reason why you want #line 0 ?  Files don't really have line number 0...

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

* [Bug gcov-profile/97069] Zero valued #line directive results in excessively large blocks of memory being allocated
  2020-09-16 12:42 [Bug gcov-profile/97069] New: Zero valued #line directive results in excessively large blocks of memory being allocated martin.ogden at arm dot com
  2020-09-16 13:44 ` [Bug gcov-profile/97069] " jakub at gcc dot gnu.org
@ 2020-09-16 14:30 ` martin.ogden at arm dot com
  2020-09-21  8:38 ` marxin at gcc dot gnu.org
                   ` (5 subsequent siblings)
  7 siblings, 0 replies; 9+ messages in thread
From: martin.ogden at arm dot com @ 2020-09-16 14:30 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #2 from Martin Ogden <martin.ogden at arm dot com> ---
I appreciate `#line 0 "main.c"` doesn't make much sense, but according to
https://gcc.gnu.org/onlinedocs/cpp/Line-Control.html, 0 is a valid input.

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

* [Bug gcov-profile/97069] Zero valued #line directive results in excessively large blocks of memory being allocated
  2020-09-16 12:42 [Bug gcov-profile/97069] New: Zero valued #line directive results in excessively large blocks of memory being allocated martin.ogden at arm dot com
  2020-09-16 13:44 ` [Bug gcov-profile/97069] " jakub at gcc dot gnu.org
  2020-09-16 14:30 ` martin.ogden at arm dot com
@ 2020-09-21  8:38 ` marxin at gcc dot gnu.org
  2020-09-23  8:05 ` cvs-commit at gcc dot gnu.org
                   ` (4 subsequent siblings)
  7 siblings, 0 replies; 9+ messages in thread
From: marxin at gcc dot gnu.org @ 2020-09-21  8:38 UTC (permalink / raw)
  To: gcc-bugs

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

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

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|UNCONFIRMED                 |ASSIGNED
   Last reconfirmed|                            |2020-09-21
           Assignee|unassigned at gcc dot gnu.org      |marxin at gcc dot gnu.org
     Ever confirmed|0                           |1

--- Comment #3 from Martin Liška <marxin at gcc dot gnu.org> ---
Let me take it.

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

* [Bug gcov-profile/97069] Zero valued #line directive results in excessively large blocks of memory being allocated
  2020-09-16 12:42 [Bug gcov-profile/97069] New: Zero valued #line directive results in excessively large blocks of memory being allocated martin.ogden at arm dot com
                   ` (2 preceding siblings ...)
  2020-09-21  8:38 ` marxin at gcc dot gnu.org
@ 2020-09-23  8:05 ` cvs-commit at gcc dot gnu.org
  2020-09-23  8:05 ` marxin at gcc dot gnu.org
                   ` (3 subsequent siblings)
  7 siblings, 0 replies; 9+ messages in thread
From: cvs-commit at gcc dot gnu.org @ 2020-09-23  8:05 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #4 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:6b4e8bf88f1172ce8561f57b12fb81063b21a78f

commit r11-3384-g6b4e8bf88f1172ce8561f57b12fb81063b21a78f
Author: Martin Liska <mliska@suse.cz>
Date:   Mon Sep 21 16:26:10 2020 +0200

    gcov: fix streaming corruption

    gcc/ChangeLog:

            PR gcov-profile/97069
            * profile.c (branch_prob): Line number must be at least 1.

    gcc/testsuite/ChangeLog:

            PR gcov-profile/97069
            * g++.dg/gcov/pr97069.C: New test.

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

* [Bug gcov-profile/97069] Zero valued #line directive results in excessively large blocks of memory being allocated
  2020-09-16 12:42 [Bug gcov-profile/97069] New: Zero valued #line directive results in excessively large blocks of memory being allocated martin.ogden at arm dot com
                   ` (3 preceding siblings ...)
  2020-09-23  8:05 ` cvs-commit at gcc dot gnu.org
@ 2020-09-23  8:05 ` marxin at gcc dot gnu.org
  2020-10-01 19:19 ` cvs-commit at gcc dot gnu.org
                   ` (2 subsequent siblings)
  7 siblings, 0 replies; 9+ messages in thread
From: marxin at gcc dot gnu.org @ 2020-09-23  8:05 UTC (permalink / raw)
  To: gcc-bugs

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

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

           What    |Removed                     |Added
----------------------------------------------------------------------------
      Known to work|                            |11.0
      Known to fail|                            |10.2.0

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

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

* [Bug gcov-profile/97069] Zero valued #line directive results in excessively large blocks of memory being allocated
  2020-09-16 12:42 [Bug gcov-profile/97069] New: Zero valued #line directive results in excessively large blocks of memory being allocated martin.ogden at arm dot com
                   ` (4 preceding siblings ...)
  2020-09-23  8:05 ` marxin at gcc dot gnu.org
@ 2020-10-01 19:19 ` cvs-commit at gcc dot gnu.org
  2020-10-02 10:06 ` cvs-commit at gcc dot gnu.org
  2020-10-02 10:07 ` marxin at gcc dot gnu.org
  7 siblings, 0 replies; 9+ messages in thread
From: cvs-commit at gcc dot gnu.org @ 2020-10-01 19:19 UTC (permalink / raw)
  To: gcc-bugs

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

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

https://gcc.gnu.org/g:bc3914f307211c42f31af7e64d2e6cc8a69837cb

commit r10-8838-gbc3914f307211c42f31af7e64d2e6cc8a69837cb
Author: Martin Liska <mliska@suse.cz>
Date:   Mon Sep 21 16:26:10 2020 +0200

    gcov: fix streaming corruption

    gcc/ChangeLog:

            PR gcov-profile/97069
            * profile.c (branch_prob): Line number must be at least 1.

    gcc/testsuite/ChangeLog:

            PR gcov-profile/97069
            * g++.dg/gcov/pr97069.C: New test.

    (cherry picked from commit 6b4e8bf88f1172ce8561f57b12fb81063b21a78f)

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

* [Bug gcov-profile/97069] Zero valued #line directive results in excessively large blocks of memory being allocated
  2020-09-16 12:42 [Bug gcov-profile/97069] New: Zero valued #line directive results in excessively large blocks of memory being allocated martin.ogden at arm dot com
                   ` (5 preceding siblings ...)
  2020-10-01 19:19 ` cvs-commit at gcc dot gnu.org
@ 2020-10-02 10:06 ` cvs-commit at gcc dot gnu.org
  2020-10-02 10:07 ` marxin at gcc dot gnu.org
  7 siblings, 0 replies; 9+ messages in thread
From: cvs-commit at gcc dot gnu.org @ 2020-10-02 10:06 UTC (permalink / raw)
  To: gcc-bugs

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

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

https://gcc.gnu.org/g:20f699a44492f2f43351d19849873d1112ffc7e0

commit r9-8967-g20f699a44492f2f43351d19849873d1112ffc7e0
Author: Martin Liska <mliska@suse.cz>
Date:   Mon Sep 21 16:26:10 2020 +0200

    gcov: fix streaming corruption

    gcc/ChangeLog:

            PR gcov-profile/97069
            * profile.c (branch_prob): Line number must be at least 1.

    gcc/testsuite/ChangeLog:

            PR gcov-profile/97069
            * g++.dg/gcov/pr97069.C: New test.

    (cherry picked from commit 6b4e8bf88f1172ce8561f57b12fb81063b21a78f)

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

* [Bug gcov-profile/97069] Zero valued #line directive results in excessively large blocks of memory being allocated
  2020-09-16 12:42 [Bug gcov-profile/97069] New: Zero valued #line directive results in excessively large blocks of memory being allocated martin.ogden at arm dot com
                   ` (6 preceding siblings ...)
  2020-10-02 10:06 ` cvs-commit at gcc dot gnu.org
@ 2020-10-02 10:07 ` marxin at gcc dot gnu.org
  7 siblings, 0 replies; 9+ messages in thread
From: marxin at gcc dot gnu.org @ 2020-10-02 10:07 UTC (permalink / raw)
  To: gcc-bugs

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

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

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

--- Comment #8 from Martin Liška <marxin at gcc dot gnu.org> ---
Resolved.

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

end of thread, other threads:[~2020-10-02 10:07 UTC | newest]

Thread overview: 9+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-09-16 12:42 [Bug gcov-profile/97069] New: Zero valued #line directive results in excessively large blocks of memory being allocated martin.ogden at arm dot com
2020-09-16 13:44 ` [Bug gcov-profile/97069] " jakub at gcc dot gnu.org
2020-09-16 14:30 ` martin.ogden at arm dot com
2020-09-21  8:38 ` marxin at gcc dot gnu.org
2020-09-23  8:05 ` cvs-commit at gcc dot gnu.org
2020-09-23  8:05 ` marxin at gcc dot gnu.org
2020-10-01 19:19 ` cvs-commit at gcc dot gnu.org
2020-10-02 10:06 ` cvs-commit at gcc dot gnu.org
2020-10-02 10:07 ` 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).