Skip to content

Commit e8c07f7

Browse files
[MC][AMDGPU] Support .reloc BFD_RELOC_{NONE,32,64} (#114617)
Emitting BFD_RELOC_* reloc directives can cause internal errors on AMDGPU.
1 parent 9778fc7 commit e8c07f7

File tree

2 files changed

+18
-4
lines changed

2 files changed

+18
-4
lines changed

llvm/lib/Target/AMDGPU/MCTargetDesc/AMDGPUAsmBackend.cpp

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -163,12 +163,17 @@ void AMDGPUAsmBackend::applyFixup(const MCAssembler &Asm, const MCFixup &Fixup,
163163

164164
std::optional<MCFixupKind>
165165
AMDGPUAsmBackend::getFixupKind(StringRef Name) const {
166-
return StringSwitch<std::optional<MCFixupKind>>(Name)
167-
#define ELF_RELOC(Name, Value) \
168-
.Case(#Name, MCFixupKind(FirstLiteralRelocationKind + Value))
166+
auto Type = StringSwitch<unsigned>(Name)
167+
#define ELF_RELOC(Name, Value) .Case(#Name, Value)
169168
#include "llvm/BinaryFormat/ELFRelocs/AMDGPU.def"
170169
#undef ELF_RELOC
171-
.Default(std::nullopt);
170+
.Case("BFD_RELOC_NONE", ELF::R_AMDGPU_NONE)
171+
.Case("BFD_RELOC_32", ELF::R_AMDGPU_ABS32)
172+
.Case("BFD_RELOC_64", ELF::R_AMDGPU_ABS64)
173+
.Default(-1u);
174+
if (Type != -1u)
175+
return static_cast<MCFixupKind>(FirstLiteralRelocationKind + Type);
176+
return std::nullopt;
172177
}
173178

174179
const MCFixupKindInfo &AMDGPUAsmBackend::getFixupKindInfo(

llvm/test/MC/AMDGPU/reloc-directive.s

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,9 @@
1919
# PRINT-NEXT: .reloc 0, R_AMDGPU_REL32_HI, .data
2020
# PRINT-NEXT: .reloc 0, R_AMDGPU_RELATIVE64, .data
2121
# PRINT-NEXT: .reloc 0, R_AMDGPU_REL16, .data
22+
# PRINT-NEXT: .reloc 0, BFD_RELOC_NONE, .data
23+
# PRINT-NEXT: .reloc 0, BFD_RELOC_32, .data
24+
# PRINT-NEXT: .reloc 0, BFD_RELOC_64, .data
2225

2326
# CHECK: 0x2 R_AMDGPU_NONE .data
2427
# CHECK-NEXT: 0x1 R_AMDGPU_NONE foo 0x4
@@ -36,6 +39,9 @@
3639
# CHECK-NEXT: 0x0 R_AMDGPU_REL32_HI .data
3740
# CHECK-NEXT: 0x0 R_AMDGPU_RELATIVE64 .data
3841
# CHECK-NEXT: 0x0 R_AMDGPU_REL16 .data
42+
# CHECK-NEXT: 0x0 R_AMDGPU_NONE .data
43+
# CHECK-NEXT: 0x0 R_AMDGPU_ABS32 .data
44+
# CHECK-NEXT: 0x0 R_AMDGPU_ABS64 .data
3945

4046
.text
4147
s_nop 0
@@ -56,6 +62,9 @@
5662
.reloc 0, R_AMDGPU_REL32_HI, .data
5763
.reloc 0, R_AMDGPU_RELATIVE64, .data
5864
.reloc 0, R_AMDGPU_REL16, .data
65+
.reloc 0, BFD_RELOC_NONE, .data
66+
.reloc 0, BFD_RELOC_32, .data
67+
.reloc 0, BFD_RELOC_64, .data
5968

6069
.data
6170
.globl foo

0 commit comments

Comments
 (0)