ld64: Incorrect calculation of branch islands.

Originator:rolf
Number:rdar://15358055 Date Originated:31/10/2013
Status:Open Resolved:
Product:Developer Tools Product Version:Xcode Version 5.0.1 (5A2053)
Classification:Crash/Hang/Data Loss Reproducible:100%
 
Summary:
When linking certain object files, the generated branch islands will in some cases branch to random memory instead of the intended target address.

Steps to Reproduce:
Example data:

__text section size: 0x4b90850, with 7 branch island regions.

Need to branch from 0x6A774 to 0x4B77250, thumb instruction.

branch island regions are at:
1:   0x0de0860
2:   0x14bd890
3:   0x21810e0
4:   0x2bcbe60
5:   0x3996a50
6:   0x476d680
7:   0x4b90850

Since target address is after branch island region #6, branch islands should be inserted into regions 1 through 6.

Previous code would assume a constant 14MB between each branch region, which would result in the following region addresses:

1:   0x0E00000
2:   0x1C00000
3:   0x2A00000
4:   0x3800000
5:   0x4600000
6:   0x5400000
7:   0x6200000

And the code would not insert a branch island into region #6, because it would think the target address is before region 6.



Expected Results:
The final result would be that the branch from the island in region 5 to the 0x4B77250 would not fit into the thumb2 branch instruction, overflowing it so that it turned negative, and branch into random memory.

Actual Results:
Not branch into random memory.

Version:
Xcode Version 5.0.1 (5A2053)
Mavericks 13A603.


Notes:
Here is a potential fix (which works for me): https://github.com/rolfbjarne/ld64/commit/29767a478ff6d3f15ebcf0001d1c572e1c754db2 

Configuration:
At least Xcode 4.6 and 5.0

Comments

Marked as a duplicate of #14969745

By rolfbjarne at April 1, 2014, 4:10 p.m. (reply...)

Please note: Reports posted here will not necessarily be seen by Apple. All problems should be submitted at bugreport.apple.com before they are posted here. Please only post information for Radars that you have filed yourself, and please do not include Apple confidential information in your posts. Thank you!