Infinite loop in gcov_exit

Bug #1694644 reported by Reetesh Ranjan
12
This bug affects 2 people
Affects Status Importance Assigned to Milestone
GNU Arm Embedded Toolchain
New
Undecided
Unassigned

Bug Description

Release version: 5-2016-q3-update
Using binary package
Host: Mac OSX, Windows

All other mandatory details are available in the description below:

I was trying to do code coverage for my embedded project using 5-2016-q3-update and GNU ARM Eclipse (http://gnuarmeclipse.github.io/). I broadly followed the concept of manually breaking into 'gcov_exit' and using 'gdb dump binary' to create the gcda files, as described in https://mcuoneclipse.com/2014/12/26/code-coverage-for-embedded-target-with-eclipse-gcc-and-gcov/. However; gcov_exit hanged infinitely. For a simple project of not more than 25 source files, it would take minutes and won't return. To debug this, I made a copy of respective gcc and libgcc code and tailored it as needed and plugged it into my project so that I could see what the hang is about. It turned out that the 1st instance of these loops "for (gi_ptr = list; gi_ptr; gi_ptr = gi_ptr->next)" just won't finish. On debugging it appeared that the list was circular and not a null-terminated one. I cannot figure it out why that is as I studied gcc code, and __gcov_root.list construction through __gcov_init does not seem to create any circular lists. But it appeared to be so, because when I changed the loops to expect a circular list rather than a null-terminated singly linked list, things worked. Also, I manually debugged the functions called by gcov_exit to see that there are exactly as many gcov_info nodes in the __gcov_root.list as the number of source files covered, and the change to expect a circular list made sense. I had to end up changing 3 instances of such loops and then I was able to generated the gcda files.

The ported/tailored version of the minimum gcc/libgcc code has been made available at: https://github.com/reeteshranjan/libgcov-embedded

I saw that the toolchain is based on svn://gcc.gnu.org/svn/gcc/branches/ARM/; and I picked the code from gcc trunk. However; it seems at least from embedded-6-branch onwards that the gcov source is the same as I could see in gcc trunk that time.

I have also attached a patch I made using the embedded-6-branch which clearly shows the for loop changes made.

I also did a sample GNU ARM Eclipse project to use the above, which is available at:
https://github.com/reeteshranjan/libgcov-embedded-example

Steps to reproduce and analyze:
- Setup any embedded project using GNU ARM Eclipse. Follow the steps in https://mcuoneclipse.com/2014/12/26/code-coverage-for-embedded-target-with-eclipse-gcc-and-gcov/ to generate coverage data by breaking into gcov_exit or __gcov_flush (whichever is available). The hang in gcov_exit should be reproducible.
- Now create another project from scratch without using the stub code as described in https://mcuoneclipse.com/2014/12/26/code-coverage-for-embedded-target-with-eclipse-gcc-and-gcov/
- Plugin https://github.com/reeteshranjan/libgcov-embedded using the instructions in README.md provided in this repository into the new project.
- In the port/libgcc/libgcov-driver.c file in the above, search for the loops "for (gi_ptr = list; gi_ptr && !(gi_ptr == list && break_loop_counter); gi_ptr = gi_ptr->next, break_loop_counter++)". These are the changes to expect a circular list and not a null-terminated singly linked list. Change these lines to how they are in original gcc code which is "for (gi_ptr = list; gi_ptr; gi_ptr = gi_ptr->next)"
- Follow the README instructions on how to break in gcov-io.c to use gdb instructions to manually create gcda files. You won't hit this breakpoint because of the hang in first of these for loops in 'compute_summary' function (now reproducible as we changed the code to use the original libgcc version)
- Now revert the for loop changes back
- Now the breakpoints should hit once for each source file

Revision history for this message
Reetesh Ranjan (reeteshranjan) wrote :
description: updated
Revision history for this message
Tejas Belagod (belagod-tejas) wrote :

Hi Reetesh,

Thanks for suggesting the patch.

I suggest you post a patch against trunk to <email address hidden> and get it reviewed by GCOV maintainers upstream.

Thanks,
Tejas.

Revision history for this message
Reetesh Ranjan (reeteshranjan) wrote : Re: [Bug 1694644] Infinite loop in gcov_exit
Download full text (4.7 KiB)

Hi Tejas,

This is my first ever gcc contrib. I am not sure what you expect me to send to the patches email? Should I send the whole description to them again?

Thanks,
Reetesh

> On 31-May-2017, at 6:29 PM, Tejas Belagod <email address hidden> wrote:
>
> Hi Reetesh,
>
> Thanks for suggesting the patch.
>
> I suggest you post a patch against trunk to <email address hidden> and
> get it reviewed by GCOV maintainers upstream.
>
> Thanks,
> Tejas.
>
> --
> You received this bug notification because you are subscribed to the bug
> report.
> https://bugs.launchpad.net/bugs/1694644
>
> Title:
> Infinite loop in gcov_exit
>
> Status in GNU ARM Embedded Toolchain:
> New
>
> Bug description:
> Release version: 5-2016-q3-update
> Using binary package
> Host: Mac OSX, Windows
>
> All other mandatory details are available in the description below:
>
> I was trying to do code coverage for my embedded project using
> 5-2016-q3-update and GNU ARM Eclipse
> (http://gnuarmeclipse.github.io/). I broadly followed the concept of
> manually breaking into 'gcov_exit' and using 'gdb dump binary' to
> create the gcda files, as described in
> https://mcuoneclipse.com/2014/12/26/code-coverage-for-embedded-target-
> with-eclipse-gcc-and-gcov/. However; gcov_exit hanged infinitely. For
> a simple project of not more than 25 source files, it would take
> minutes and won't return. To debug this, I made a copy of respective
> gcc and libgcc code and tailored it as needed and plugged it into my
> project so that I could see what the hang is about. It turned out that
> the 1st instance of these loops "for (gi_ptr = list; gi_ptr; gi_ptr =
> gi_ptr->next)" just won't finish. On debugging it appeared that the
> list was circular and not a null-terminated one. I cannot figure it
> out why that is as I studied gcc code, and __gcov_root.list
> construction through __gcov_init does not seem to create any circular
> lists. But it appeared to be so, because when I changed the loops to
> expect a circular list rather than a null-terminated singly linked
> list, things worked. Also, I manually debugged the functions called by
> gcov_exit to see that there are exactly as many gcov_info nodes in the
> __gcov_root.list as the number of source files covered, and the change
> to expect a circular list made sense. I had to end up changing 3
> instances of such loops and then I was able to generated the gcda
> files.
>
> The ported/tailored version of the minimum gcc/libgcc code has been
> made available at: https://github.com/reeteshranjan/libgcov-embedded
>
> I saw that the toolchain is based on
> svn://gcc.gnu.org/svn/gcc/branches/ARM/; and I picked the code from
> gcc trunk. However; it seems at least from embedded-6-branch onwards
> that the gcov source is the same as I could see in gcc trunk that
> time.
>
> I have also attached a patch I made using the embedded-6-branch which
> clearly shows the for loop changes made.
>
> I also did a sample GNU ARM Eclipse project to use the above, which is available at:
> https://github.com/reeteshranjan/libgcov-embedded-example
>
> Steps to reproduce and analyze:
> - Setup any embedded p...

Read more...

Revision history for this message
Tejas Belagod (belagod-tejas) wrote :

Hi Reetesh,

Really appreciate your keennes to contribute.

Here is a detailed guide on how to contribute to gcc - https://gcc.gnu.org/contribute.html.

Thanks,
Tejas.

Revision history for this message
Petr Belskiy (petr.belskiy) wrote :

I have the same issue in my internal project.

Revision history for this message
eDeviser (wolle3) wrote :

Hi Tejas,

I read your comment at https://mcuoneclipse.com/2014/12/26/code-coverage-for-embedded-target-with-eclipse-gcc-and-gcov/ and your description at https://github.com/reeteshranjan/libgcov-embedded .

It seems, that it is the same problem for me. Did you had any success in posting a patch against trunk?

Revision history for this message
Tejas Belagod (belagod-tejas) wrote :

Hi eDeviser,

I think it was Reetesh Ranjan's patch (see above) - I don't know if he managed to get it submitted upstream to the gcc lists.

Thanks,
Tejas.

Revision history for this message
Reetesh Ranjan (reeteshranjan) wrote : Re: [Bug 1694644] Re: Infinite loop in gcov_exit
Download full text (5.0 KiB)

Hi,

I talked to the gcc team. The summary of the discussion is:

My patch works around the core issue of circular lists being created. It's not a fix in the sense it does not prevent the circular lists from getting formed. I was told to find the root cause of what created the circular lists and provide a patch for that.

Sadly I have not had time to spend on this new investigation.

Meanwhile, using the whole mechanism I have provided in GitHub is something we can use, if that's any help.

Thanks
Reetesh

> On 11-Sep-2017, at 6:54 PM, Tejas Belagod <email address hidden> wrote:
>
> Hi eDeviser,
>
> I think it was Reetesh Ranjan's patch (see above) - I don't know if he
> managed to get it submitted upstream to the gcc lists.
>
> Thanks,
> Tejas.
>
> --
> You received this bug notification because you are subscribed to the bug
> report.
> https://bugs.launchpad.net/bugs/1694644
>
> Title:
> Infinite loop in gcov_exit
>
> Status in GNU ARM Embedded Toolchain:
> New
>
> Bug description:
> Release version: 5-2016-q3-update
> Using binary package
> Host: Mac OSX, Windows
>
> All other mandatory details are available in the description below:
>
> I was trying to do code coverage for my embedded project using
> 5-2016-q3-update and GNU ARM Eclipse
> (http://gnuarmeclipse.github.io/). I broadly followed the concept of
> manually breaking into 'gcov_exit' and using 'gdb dump binary' to
> create the gcda files, as described in
> https://mcuoneclipse.com/2014/12/26/code-coverage-for-embedded-target-
> with-eclipse-gcc-and-gcov/. However; gcov_exit hanged infinitely. For
> a simple project of not more than 25 source files, it would take
> minutes and won't return. To debug this, I made a copy of respective
> gcc and libgcc code and tailored it as needed and plugged it into my
> project so that I could see what the hang is about. It turned out that
> the 1st instance of these loops "for (gi_ptr = list; gi_ptr; gi_ptr =
> gi_ptr->next)" just won't finish. On debugging it appeared that the
> list was circular and not a null-terminated one. I cannot figure it
> out why that is as I studied gcc code, and __gcov_root.list
> construction through __gcov_init does not seem to create any circular
> lists. But it appeared to be so, because when I changed the loops to
> expect a circular list rather than a null-terminated singly linked
> list, things worked. Also, I manually debugged the functions called by
> gcov_exit to see that there are exactly as many gcov_info nodes in the
> __gcov_root.list as the number of source files covered, and the change
> to expect a circular list made sense. I had to end up changing 3
> instances of such loops and then I was able to generated the gcda
> files.
>
> The ported/tailored version of the minimum gcc/libgcc code has been
> made available at: https://github.com/reeteshranjan/libgcov-embedded
>
> I saw that the toolchain is based on
> svn://gcc.gnu.org/svn/gcc/branches/ARM/; and I picked the code from
> gcc trunk. However; it seems at least from embedded-6-branch onwards
> that the gcov source is the same as I could see in gcc trunk that
> time.
>
> I have also attached a p...

Read more...

To post a comment you must log in.
This report contains Public information  
Everyone can see this information.

Other bug subscribers

Remote bug watches

Bug watches keep track of this bug in other bug trackers.