Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix for veneers generated by linker for interworking #123

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

nikarh
Copy link
Contributor

@nikarh nikarh commented May 31, 2023

Force-enables -Wl,--pic-veneer linker flag.

A compiler can do tail-call optimizations, emitting R_ARM_JUMP24 relocation instead of a normal call.

If this call has interworking (was from an arm function to a thumb function or vice versa), binutils produces a veneer, because it needs to do a switch. By default, these veneers do jump to an absolute address. This patch forces ld to produce veneers for position-independent binaries.

tldr; no need for --no-optimize-sibling-calls anymore, sibling calls will ✨ just work ✨

An example of veneer before this patch:

81000010 <__func_thumb_from_arm>:
81000010: e51ff004      ldr     pc, [pc, #-4]           @ 0x81000014 <$d>

81000014 <$d>:
81000014: 01 00 00 81   .word   0x81000001

and after:

81000010 <__func_thumb_from_arm>:
81000010: e59fc004      ldr     r12, [pc, #4]           @ 0x8100001c <$d>
81000014: e08fc00c      add     r12, pc, r12
81000018: e12fff1c      bx      r12

8100001c <$d>:
8100001c: e5 ff ff ff   .word   0xffffffe5

@nikarh nikarh force-pushed the fixed-interworking-veneers branch 4 times, most recently from 2c28624 to bbf1c99 Compare June 1, 2023 10:05
A compiler can do tail call optimizations, emitting
R_ARM_JUMP24 relocation instead of a normal call.

If this call has interworking (was from arm function to a thumb function
or vice versa), binutils produces a veneer, because it needs to do a
switch. By default these veneers do jumps to an absolute address. This
patch forces ld to produce veneers for position independent binaries.

tldr; no need for `--no-optimize-sibling-calls` anymore, sibling calls
will ✨ work ✨

An example of veneer before this patch:

```
81000010 <__func_thumb_from_arm>:
81000010: e51ff004      ldr     pc, [pc, #-4]           @ 0x81000014 <$d>

81000014 <$d>:
81000014: 01 00 00 81   .word   0x81000001
```

and after:

```
81000010 <__func_thumb_from_arm>:
81000010: e59fc004      ldr     r12, [pc, vitasdk#4]           @ 0x8100001c <$d>
81000014: e08fc00c      add     r12, pc, r12
81000018: e12fff1c      bx      r12

8100001c <$d>:
8100001c: e5 ff ff ff   .word   0xffffffe5

```
@nikarh nikarh force-pushed the fixed-interworking-veneers branch from bbf1c99 to 692cd11 Compare June 1, 2023 10:05
@nikarh nikarh changed the title Fixed for veneers generated by linker for interworking Fix for veneers generated by linker for interworking Jun 13, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

1 participant