Skip to content

[MC][AMDGPU] Support .reloc BFD_RELOC_{NONE,32,64} #114617

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 2 commits into from
Nov 13, 2024
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
13 changes: 9 additions & 4 deletions llvm/lib/Target/AMDGPU/MCTargetDesc/AMDGPUAsmBackend.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -163,12 +163,17 @@ void AMDGPUAsmBackend::applyFixup(const MCAssembler &Asm, const MCFixup &Fixup,

std::optional<MCFixupKind>
AMDGPUAsmBackend::getFixupKind(StringRef Name) const {
return StringSwitch<std::optional<MCFixupKind>>(Name)
#define ELF_RELOC(Name, Value) \
.Case(#Name, MCFixupKind(FirstLiteralRelocationKind + Value))
auto Type = StringSwitch<unsigned>(Name)
#define ELF_RELOC(Name, Value) .Case(#Name, Value)
#include "llvm/BinaryFormat/ELFRelocs/AMDGPU.def"
#undef ELF_RELOC
.Default(std::nullopt);
.Case("BFD_RELOC_NONE", ELF::R_AMDGPU_NONE)
.Case("BFD_RELOC_32", ELF::R_AMDGPU_ABS32)
.Case("BFD_RELOC_64", ELF::R_AMDGPU_ABS64)
Copy link
Member

Choose a reason for hiding this comment

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

Why are they not added to "llvm/BinaryFormat/ELFRelocs/AMDGPU.def" ?

Copy link
Member

Choose a reason for hiding this comment

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

@arsenm This is how the other backends do it (4f7562d), would you prefer it this way or added to the .def file?

Copy link
Contributor

Choose a reason for hiding this comment

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

I have no idea why it's like this, why wouldn't these all be in the def? I guess it's fine to copy the pattern and clean them all later?

Copy link
Member

Choose a reason for hiding this comment

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

We just need to decide which way we want to do it.

.Default(-1u);
if (Type != -1u)
return static_cast<MCFixupKind>(FirstLiteralRelocationKind + Type);
return std::nullopt;
}

const MCFixupKindInfo &AMDGPUAsmBackend::getFixupKindInfo(
Expand Down
9 changes: 9 additions & 0 deletions llvm/test/MC/AMDGPU/reloc-directive.s
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,9 @@
# PRINT-NEXT: .reloc 0, R_AMDGPU_REL32_HI, .data
# PRINT-NEXT: .reloc 0, R_AMDGPU_RELATIVE64, .data
# PRINT-NEXT: .reloc 0, R_AMDGPU_REL16, .data
# PRINT-NEXT: .reloc 0, BFD_RELOC_NONE, .data
# PRINT-NEXT: .reloc 0, BFD_RELOC_32, .data
# PRINT-NEXT: .reloc 0, BFD_RELOC_64, .data

# CHECK: 0x2 R_AMDGPU_NONE .data
# CHECK-NEXT: 0x1 R_AMDGPU_NONE foo 0x4
Expand All @@ -36,6 +39,9 @@
# CHECK-NEXT: 0x0 R_AMDGPU_REL32_HI .data
# CHECK-NEXT: 0x0 R_AMDGPU_RELATIVE64 .data
# CHECK-NEXT: 0x0 R_AMDGPU_REL16 .data
# CHECK-NEXT: 0x0 R_AMDGPU_NONE .data
# CHECK-NEXT: 0x0 R_AMDGPU_ABS32 .data
# CHECK-NEXT: 0x0 R_AMDGPU_ABS64 .data

.text
s_nop 0
Expand All @@ -56,6 +62,9 @@
.reloc 0, R_AMDGPU_REL32_HI, .data
.reloc 0, R_AMDGPU_RELATIVE64, .data
.reloc 0, R_AMDGPU_REL16, .data
.reloc 0, BFD_RELOC_NONE, .data
.reloc 0, BFD_RELOC_32, .data
.reloc 0, BFD_RELOC_64, .data

.data
.globl foo
Expand Down
Loading