Skip to content

[LLD][ELF][ARM] Fix resolution of R_ARM_THM_JUMP8 and R_ARM_THM_JUMP11 for big endian #126933

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

Merged
merged 5 commits into from
Feb 17, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions lld/ELF/Arch/ARM.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -663,12 +663,12 @@ void ARM::relocate(uint8_t *loc, const Relocation &rel, uint64_t val) const {
case R_ARM_THM_JUMP8:
// We do a 9 bit check because val is right-shifted by 1 bit.
checkInt(ctx, loc, val, 9, rel);
write16(ctx, loc, (read32(ctx, loc) & 0xff00) | ((val >> 1) & 0x00ff));
write16(ctx, loc, (read16(ctx, loc) & 0xff00) | ((val >> 1) & 0x00ff));
break;
case R_ARM_THM_JUMP11:
// We do a 12 bit check because val is right-shifted by 1 bit.
checkInt(ctx, loc, val, 12, rel);
write16(ctx, loc, (read32(ctx, loc) & 0xf800) | ((val >> 1) & 0x07ff));
write16(ctx, loc, (read16(ctx, loc) & 0xf800) | ((val >> 1) & 0x07ff));
break;
case R_ARM_THM_JUMP19:
// Encoding T3: Val = S:J2:J1:imm6:imm11:0
Expand Down
32 changes: 32 additions & 0 deletions lld/test/ELF/arm-thumb-jump8-11.s
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
# REQUIRES: arm
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We have arm-thumb-narrow-branch-check.s .

Another candidate name is arm-thumb-narrow-branch.s


# RUN: llvm-mc -triple thumbv6m-arm-eabi --filetype=obj %s -o %t.o
# RUN: ld.lld %t.o -o %t
# RUN: llvm-objdump -d %t --no-show-raw-insn | FileCheck %s --check-prefixes=CHECK,CHECK-LE

# RUN: llvm-mc -triple thumbebv6m-arm-eabi --filetype=obj %s -o %t.o
# RUN: ld.lld %t.o -o %t
# RUN: llvm-objdump -d %t --no-show-raw-insn | FileCheck %s --check-prefixes=CHECK,CHECK-BE

# CHECK-LE: file format elf32-littlearm
# CHECK-BE: file format elf32-bigarm

# CHECK: Disassembly of section .text:

# CHECK-LABEL: [[#%x,TARGET:]] <target>:
# CHECK-NEXT: [[#TARGET]]: bx lr

# CHECK-LABEL: <_start>:
# CHECK-NEXT: b 0x[[#TARGET]] <target>
# CHECK-NEXT: beq 0x[[#TARGET]] <target>

.thumb
.section .text.1, "ax", %progbits
target:
bx lr

.section .text.2, "ax", %progbits
.globl _start
_start:
b.n target // R_ARM_THM_JUMP11
beq.n target // R_ARM_THM_JUMP8