Bug 20529 - Gold [powerpc] - relaxing loop never ends
Summary: Gold [powerpc] - relaxing loop never ends
Status: RESOLVED FIXED
Alias: None
Product: binutils
Classification: Unclassified
Component: gold (show other bugs)
Version: 2.28
: P2 normal
Target Milestone: ---
Assignee: Cary Coutant
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2016-08-26 21:57 UTC by Han Shen
Modified: 2024-02-29 21:47 UTC (History)
1 user (show)

See Also:
Host:
Target:
Build:
Last reconfirmed:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Han Shen 2016-08-26 21:57:36 UTC
Here is one particular case that causes gold PPC linker trapped in a endless relaxing loop. (I do not provide a reproducible case because the objects involved are proprietary).

Here is the case - 

--------------
|            |
| 0x1b9446f0 |
|	     | <- stub_table
|   ...      |
|------------|
|	     |
|	     |
|------------|
| 0x1c71e3d0 |-----
|------------|    |
|	     |	  |
|	     |	  |
|	     |	  |  jump delta = 0x2000000
|	     |	  | (>= max_branch_offset, which is 0x2000000)
|	     |	  |
|	     |	  |
|------------|	  |
| 0x1e71e3d0 | <--|
|----------- |
|	     |
|	     |

So a long branch stub is added, which is 16-byte, and this pushes the section forward, thus get to the following:

--------------
|            |
| 0x1b9446f0 |
|	     | <- stub_table
| a new stub |
|   ...      |
|------------|
|	     |
|	     |
|------------|
| 0x1c71e3e0 |-----
|------------|    |
|	     |	  |
|	     |	  |
|	     |	  |  jump delta < 0x2000000
|	     |	  |    no stub needed
|	     |	  |
|	     |	  |
|------------|	  |
| 0x1e71e3d0 | <--|  (the jump target is *NOT* pushed forward? why?)
|----------- |
|	     |
|	     |

Now for this particular branch_info, we do not add a branch stub. So stub table shrinks by 16 bytes, and we get back to the first graph. Thus causes the indefinite loop.

The solution is to only allow growth of stub tables after a few relax iterations.
Comment 1 Sourceware Commits 2016-08-28 21:19:23 UTC
The master branch has been updated by Han Shen <shenhan@sourceware.org>:

https://sourceware.org/git/gitweb.cgi?p=binutils-gdb.git;h=6395d38b7ffd231a3b7b5a67b47e1bda947089ee

commit 6395d38b7ffd231a3b7b5a67b47e1bda947089ee
Author: Han Shen <shenhan@google.com>
Date:   Fri Aug 26 15:50:15 2016 -0700

    PR gold/20529 - relaxing loop never ends.
    
    gold/ChangeLog
    
    2016-08-26  Han Shen  <shenhan@google.com>
    
    	* powerpc.cc (Stub_table::min_size_threshold_): New member to
    	limit size.
    	(Stub_table::set_min_size_threshold): New member function.
    	(Stub_table::set_address_and_size): Add code to only allow size
    	increase.
    	(Target_powerpc::do_relax): Add code to record last size.
Comment 2 Sourceware Commits 2017-02-21 23:32:24 UTC
The binutils-2_27-branch branch has been updated by Alan Modra <amodra@sourceware.org>:

https://sourceware.org/git/gitweb.cgi?p=binutils-gdb.git;h=cd54b50e7b5ac662ca52d636c01dfaa506cdb07b

commit cd54b50e7b5ac662ca52d636c01dfaa506cdb07b
Author: Han Shen <shenhan@google.com>
Date:   Fri Aug 26 15:50:15 2016 -0700

    PR gold/20529 - relaxing loop never ends.
    
    	* powerpc.cc (Stub_table::min_size_threshold_): New member to
    	limit size.
    	(Stub_table::set_min_size_threshold): New member function.
    	(Stub_table::set_address_and_size): Add code to only allow size
    	increase.
    	(Target_powerpc::do_relax): Add code to record last size.
Comment 3 Alan Modra 2024-02-29 21:47:45 UTC
patch applied