Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 4688b97

Browse files
androm3dac-rhodes
authored andcommitted
[lld][Hexagon] Fix R_HEX_TPREL_11_X relocation on duplex instructions (llvm#179860)
findMaskR11() was missing handling for duplex instructions. This caused incorrect encoding when R_HEX_TPREL_11_X relocations were applied to duplex instructions with large TLS offsets. For duplex instructions, the immediate bits are located at positions 20-25 (mask 0x03f00000), not in the standard positions used for non-duplex instructions. This fix adds the isDuplex() check to findMaskR11() to return the correct mask for duplex instruction encodings. (cherry picked from commit 62d018b)
1 parent d9cccb1 commit 4688b97

2 files changed

Lines changed: 37 additions & 1 deletion

File tree

lld/ELF/Arch/Hexagon.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -225,6 +225,8 @@ static uint32_t findMaskR8(uint32_t insn) {
225225
}
226226

227227
static uint32_t findMaskR11(uint32_t insn) {
228+
if (isDuplex(insn))
229+
return 0x03f00000;
228230
if ((0xff000000 & insn) == 0xa1000000)
229231
return 0x060020ff;
230232
return 0x06003fe0;

lld/test/ELF/hexagon-tls-ie.s

Lines changed: 35 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
# REQUIRES: hexagon
2-
# RUN: llvm-mc -filetype=obj -triple=hexagon-unknown-elf %s -o %t.o
2+
# RUN: rm -rf %t.dir && split-file %s %t.dir
3+
# RUN: llvm-mc -filetype=obj -triple=hexagon-unknown-elf %t.dir/main.s -o %t.o
34
# RUN: llvm-readobj -r %t.o | FileCheck -check-prefix=RELOC %s
45
# RUN: ld.lld %t.o -o %t
56
## shared needs -z notext because of the R_HEX_IE_16/32_X(R_GOT) static
@@ -11,6 +12,16 @@
1112
# RUN: FileCheck -check-prefix=SHARED %s
1213
# RUN: llvm-readobj -r %t.so | FileCheck -check-prefix=RELA %s
1314

15+
## Test R_HEX_TPREL_11_X on duplex instructions with large TLS offset.
16+
## TPREL relocations cannot be used with -shared, so test separately.
17+
# RUN: llvm-mc -filetype=obj -triple=hexagon-unknown-elf \
18+
# RUN: %t.dir/tprel-duplex.s -o %t-duplex.o
19+
# RUN: llvm-readobj -r %t-duplex.o | FileCheck -check-prefix=RELOC-DUPLEX %s
20+
# RUN: ld.lld %t-duplex.o -o %t-duplex
21+
# RUN: llvm-objdump -d --no-show-raw-insn --print-imm-hex %t-duplex | \
22+
# RUN: FileCheck -check-prefix=CHECK-DUPLEX %s
23+
24+
#--- main.s
1425
.globl _start
1526
.type _start, @function
1627
_start:
@@ -76,3 +87,26 @@ c:
7687
.globl d
7788
d:
7889
.word 4
90+
91+
#--- tprel-duplex.s
92+
## Test R_HEX_TPREL_11_X on duplex instructions with large TLS offset.
93+
## This exercises the isDuplex() path in findMaskR11().
94+
.globl _start
95+
.type _start, @function
96+
_start:
97+
# RELOC-DUPLEX: 0x0 R_HEX_TPREL_32_6_X e 0x0
98+
# RELOC-DUPLEX-NEXT: 0x4 R_HEX_TPREL_11_X e 0x0
99+
# CHECK-DUPLEX: { immext(#0xfffbffc0)
100+
# CHECK-DUPLEX-NEXT: r2 = add(r2,##-0x40003); memw(r3+#0x0) = #0 }
101+
{
102+
r2 = add(r2,##e@TPREL)
103+
memw(r3+#0) = #0
104+
}
105+
jumpr r31
106+
107+
.section .tbss,"awT",@nobits
108+
.p2align 2
109+
.space 0xd
110+
.globl e
111+
e:
112+
.space 0x40000

0 commit comments

Comments
 (0)