Quuxplusone / LLVMBugzillaTest

0 stars 0 forks source link

ARM: Add range thunk support to avoid relocation R_ARM_THM_CALL out of range #32585

Closed Quuxplusone closed 6 years ago

Quuxplusone commented 7 years ago
Bugzilla Link PR33612
Status RESOLVED FIXED
Importance P enhancement
Reported by Peter Smith (smithp352@googlemail.com)
Reported on 2017-06-27 08:34:23 -0700
Last modified on 2017-10-27 02:57:10 -0700
Version unspecified
Hardware PC Linux
CC llvm-bugs@lists.llvm.org, rafael@espindo.la
Fixed by commit(s)
Attachments
Blocks
Blocked by
See also
The range of ARM branch instructions is limited. The ABI allows object
producers to assume that a linker can extend the range of branches via the use
of range extension thunks/stubs/veneers. These are pieces of code that are
inserted between branches that turn a range limited direct call into (usually)
an indirect call via the register r12 (ABI reserved).

lld does not currently implement range extension thunks so we can quite easily
write a program that has a relocation out of range error.

        .syntax unified
        .thumb
        .section .text.1 ,"ax", %progbits
        .global low
        .type low, %function
low:
        bl high
        bx lr
        // Thumb2 branch range is 16Mb
        .space 20 * 1024 * 1024

        .section .text.2 ,"ax", %progbits
        .global high
        .type high, %function
high:
        bl low
        bx lr

llvm-mc -triple=armv7a-linux-gnueabihf long.s -filetype=obj -o long.o
ld.lld long.o -o long.axf
error: long.o:(.text.2+0x0): relocation R_ARM_THM_CALL out of range
error: long.o:(.text.1+0x0): relocation R_ARM_THM_CALL out of range

Range thunks are currently in review, this pr is here so that if people run
into the relocation R_ARM_THM_CALL they know that work is in progress to
support it.

Initial set of upstream Reviews:
D34035 [LLD][ELF] Introduce Thunk reuse compatibility (1/11).
D34037 [LLD][ELF] Allow multiple thunks to be added for a symbol. (2/11)
D34344 [LLD][ELF] Extract allocateHeaders() from assignAddresses() (3/11)
D34345 [LLD][ELF] Reset any accumulated state before calculating addresses
(4/11)
D34688 [LLD][ELF] Add call to assignAddresses() before createThunks() [NFC]
(5/11)
D34689 [LLD][ELF] Pre-create ThunkSections at Target specific intervals (6/11)
D34690 [LLD][ELF] Introduce target specific inBranchRange() function (7/11)
D34691 [LLD][ELF] Introduce range extension thunks for ARM (8/11)
D34692 [LLD][ELF] Add support for multiple passes to createThunks() (9/11)
D31666 [LLD][ELF] Add test cases for range extension thunks using linker
scripts (10/11)
D31665 [LLD][ELF] Add test cases for range extension thunks (no linkerscripts)
(11/11)
Quuxplusone commented 6 years ago
As of r316755 all RangeThunks patches have been committed. Resolving.

https://reviews.llvm.org/D34344 r307131
https://reviews.llvm.org/D34035 r307132
https://reviews.llvm.org/D34037 r307136
307136 caused a build-bot failure on Windows, fixed on 307137
https://reviews.llvm.org/D34345 r307367
https://reviews.llvm.org/D34688 r307373
https://reviews.llvm.org/D34690 r308188
https://reviews.llvm.org/D37743 r316750
https://reviews.llvm.org/D34689 r316751
https://reviews.llvm.org/D34691 r316752
https://reviews.llvm.org/D34692 r316754
buildbot fix r316755