Skip to content

Commit 0e6536f

Browse files
committed
[Hexagon] Add R_HEX_GD_PLT_B22/32_PCREL relocations
Extended versions of GD_PLT_B22_PCREL. These surface when -mlong-calls is used. Differential Revision: https://reviews.llvm.org/D79191
1 parent 86dfbc6 commit 0e6536f

File tree

3 files changed

+22
-3
lines changed

3 files changed

+22
-3
lines changed

lld/ELF/Arch/Hexagon.cpp

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -120,6 +120,8 @@ RelExpr Hexagon::getRelExpr(RelType type, const Symbol &s,
120120
case R_HEX_B22_PCREL_X:
121121
case R_HEX_B32_PCREL_X:
122122
case R_HEX_GD_PLT_B22_PCREL:
123+
case R_HEX_GD_PLT_B22_PCREL_X:
124+
case R_HEX_GD_PLT_B32_PCREL_X:
123125
return R_PLT_PC;
124126
case R_HEX_IE_32_6_X:
125127
case R_HEX_IE_16_X:
@@ -311,16 +313,18 @@ void Hexagon::relocate(uint8_t *loc, const Relocation &rel,
311313
case R_HEX_B15_PCREL_X:
312314
or32le(loc, applyMask(0x00df20fe, val & 0x3f));
313315
break;
314-
case R_HEX_GD_PLT_B22_PCREL:
315316
case R_HEX_B22_PCREL:
317+
case R_HEX_GD_PLT_B22_PCREL:
316318
case R_HEX_PLT_B22_PCREL:
317319
checkInt(loc, val, 22, rel);
318320
or32le(loc, applyMask(0x1ff3ffe, val >> 2));
319321
break;
320322
case R_HEX_B22_PCREL_X:
323+
case R_HEX_GD_PLT_B22_PCREL_X:
321324
or32le(loc, applyMask(0x1ff3ffe, val & 0x3f));
322325
break;
323326
case R_HEX_B32_PCREL_X:
327+
case R_HEX_GD_PLT_B32_PCREL_X:
324328
or32le(loc, applyMask(0x0fff3fff, val >> 6));
325329
break;
326330
case R_HEX_GOTREL_HI16:

lld/ELF/Relocations.cpp

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1344,8 +1344,11 @@ static void scanReloc(InputSectionBase &sec, OffsetGetter &getOffset, RelTy *&i,
13441344
addend &= ~0x8000;
13451345
// R_HEX_GD_PLT_B22_PCREL (call a@GDPLT) is transformed into
13461346
// call __tls_get_addr even if the symbol is non-preemptible.
1347-
if (!(config->emachine == EM_HEXAGON && type == R_HEX_GD_PLT_B22_PCREL))
1348-
expr = fromPlt(expr);
1347+
if (!(config->emachine == EM_HEXAGON &&
1348+
(type == R_HEX_GD_PLT_B22_PCREL ||
1349+
type == R_HEX_GD_PLT_B22_PCREL_X ||
1350+
type == R_HEX_GD_PLT_B32_PCREL_X)))
1351+
expr = fromPlt(expr);
13491352
}
13501353
}
13511354

lld/test/ELF/hexagon-tls-gd-nonpreemptible.s

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
# RUN: llvm-mc -filetype=obj -triple=hexagon-unknown-elf %s -o %t.o
44
# RUN: ld.lld -shared %t.o -o %t.so
55
# RUN: llvm-readobj -r %t.so | FileCheck --check-prefix=RELOC %s
6+
# RUN: llvm-readobj -r %t.o | FileCheck --check-prefix=REL %s
67
# RUN: llvm-objdump -d --no-show-raw-insn --print-imm-hex %t.so | FileCheck %s
78

89
## Prior to D77021 lld would error "relocation R_HEX_GD_PLT_B22_PCREL cannot refer to absolute symbol".
@@ -17,17 +18,28 @@
1718
# RELOC-NEXT: R_HEX_JMP_SLOT __tls_get_addr 0x0
1819
# RELOC-NEXT: }
1920

21+
# REL: R_HEX_B32_PCREL_X _GLOBAL_OFFSET_TABLE_ 0x0
22+
# REL-NEXT: R_HEX_6_PCREL_X _GLOBAL_OFFSET_TABLE_ 0x4
23+
# REL-NEXT: R_HEX_GD_GOT_32_6_X a 0x0
24+
# REL-NEXT: R_HEX_GD_GOT_16_X a 0x0
25+
# REL-NEXT: R_HEX_GD_PLT_B22_PCREL a 0x0
26+
# REL-NEXT: R_HEX_GD_PLT_B32_PCREL_X a 0x0
27+
# REL-NEXT: R_HEX_GD_PLT_B22_PCREL_X a 0x4
28+
2029
# CHECK: { immext(#{{.*}})
2130
# CHECK-NEXT: r2 = add(pc,##{{.*}}) }
2231
# CHECK-NEXT: { immext(#{{.*}})
2332
# CHECK-NEXT: r0 = add(r2,##-{{.*}}) }
2433
# CHECK-NEXT: { call {{.*}} }
34+
# CHECK-NEXT: { immext({{.*}})
35+
# CHECK-NEXT: call {{.*}} }
2536
# CHECK-NEXT: { r0 = memw(r0+#0x0) }
2637

2738
_start:
2839
r2 = add(pc,##_GLOBAL_OFFSET_TABLE_@PCREL)
2940
r0 = add(r2,##a@GDGOT)
3041
call a@GDPLT
42+
call ##a@GDPLT
3143
r0 = memw(r0+#0)
3244

3345
## a is non-preemptible due to STV_HIDDEN visibility.

0 commit comments

Comments
 (0)