[lld] [lld] Add thunks for hexagon (PR #111217)
Fangrui Song via llvm-commits
llvm-commits at lists.llvm.org
Thu Jul 10 22:21:34 PDT 2025
================
@@ -0,0 +1,115 @@
+# REQUIRES: hexagon
+# RUN: rm -rf %t && split-file %s %t && cd %t
+# RUN: llvm-mc -filetype=obj -triple=hexagon-unknown-elf main.s -o main.o
+# RUN: ld.lld main.o -o test
+# RUN: llvm-objdump -d --no-show-raw-insn test | FileCheck %s
+
+## Test thunk range scenarios for Hexagon R_HEX_B22_PCREL relocations.
+## R_HEX_B22_PCREL has a range of +/- 8MB (0x800000 bytes).
+
+#--- main.s
+.globl _start
+.type _start, %function
+_start:
+ call target_within_range_max
+ call target_beyond_range
+ call target_within_range_min
+ call target_beyond_range_min
+ call target_multiple_calls
+ call target_multiple_calls
+ call target_close
+ jumpr r31
+
+target_close:
+ jumpr r31
+
+## Target at maximum positive range (8MB - 4 bytes from _start)
+## We need to account for the instructions above: 7 calls + 1 jumpr = 8 * 4 = 32 bytes
+.skip 0X7fffbc
+.globl target_within_range_max
+.type target_within_range_max, %function
+target_within_range_max:
+ jumpr r31
+
+## Target just beyond maximum positive range (needs thunk)
+.skip 8
+.globl target_beyond_range
+.type target_beyond_range, %function
+target_beyond_range:
+ call target_within_range_max
+ jumpr r31
+
+## Target for multiple calls test
+.skip 0x100000
+.globl target_multiple_calls
+.type target_multiple_calls, %function
+target_multiple_calls:
+ jumpr r31
+
+## Now place targets at maximum negative range
+## We'll put these before _start in memory layout
+.section .text_negative, "ax", %progbits
+
+## Target at maximum negative range (-8MB + 4 bytes from _start)
+.globl target_within_range_min
+.type target_within_range_min, %function
+target_within_range_min:
+ call target_close
+ jumpr r31
+
+.skip 0X7ffff4
+
+## Target beyond maximum negative range (needs thunk)
+.globl target_beyond_range_min
+.type target_beyond_range_min, %function
+target_beyond_range_min:
+ jumpr r31
+
+## Verify thunk generation for targets beyond B22_PCREL range
+# CHECK: 000200b4 <__hexagon_thunk_target_within_range_min_from_.text.thunk>:
----------------
MaskRay wrote:
Omit the address for the `<label>:` line and keep the address for the next instruction, but not subsequent instructions.
This ensures that we will get good FileCheck errors when things go wrong. And we do not need to change too many lines when changing an address.
https://github.com/llvm/llvm-project/pull/111217
More information about the llvm-commits
mailing list