Skip to content

Commit 9e4923c

Browse files
committed
[RISCV][NFC] Refactor Vendor Relocs
This change makes it much easier for external projects to opt-in to supporting relocations from specific vendors (or with specific tags), rather than having to support all of them at once.
1 parent c37b254 commit 9e4923c

File tree

3 files changed

+32
-21
lines changed

3 files changed

+32
-21
lines changed

llvm/include/llvm/BinaryFormat/ELF.h

+2-2
Original file line numberDiff line numberDiff line change
@@ -700,9 +700,9 @@ enum : unsigned {
700700
// ELF Relocation types for RISC-V
701701
enum {
702702
#include "ELFRelocs/RISCV.def"
703-
#define ELF_RISCV_NONSTANDARD_RELOC(_vendor, name, value) name = value,
703+
#define ELF_RISCV_NONSTANDARD_RELOC_ALL(name, value) name = value,
704704
#include "ELFRelocs/RISCV_nonstandard.def"
705-
#undef ELF_RISCV_NONSTANDARD_RELOC
705+
#undef ELF_RISCV_NONSTANDARD_RELOC_ALL
706706
};
707707

708708
enum {

llvm/include/llvm/BinaryFormat/ELFRelocs/RISCV_nonstandard.def

+28-17
Original file line numberDiff line numberDiff line change
@@ -6,23 +6,34 @@
66
//
77
//===----------------------------------------------------------------------===//
88

9-
#ifndef ELF_RISCV_NONSTANDARD_RELOC
10-
#error "ELF_RISCV_NONSTANDARD_RELOC must be defined"
9+
// This file defines information about RISC-V's nonstandard relocation codes.
10+
// This can be used when parsing relocations, or when printing them, to provide
11+
// better information.
12+
//
13+
// Unlike the mappings provided in RISCV.def via `ELF_RELOC`, these are not
14+
// expected to be 1:1 mappings - multiple vendors may reuse relocation IDs.
15+
16+
// For ease of use, `ELF_RISCV_NONSTANDARD_RELOC_ALL` invokes the macros for
17+
// each vendor.
18+
19+
#ifdef ELF_RISCV_NONSTANDARD_RELOC_ALL
20+
#define ELF_RISCV_NONSTANDARD_RELOC_QUALCOMM(NAME, ID) ELF_RISCV_NONSTANDARD_RELOC_ALL(NAME, ID)
1121
#endif
1222

13-
// ELF_RISCV_NONSTANDARD_RELOC(VENDOR, NAME, ID) defines information about
14-
// nonstandard relocation codes. This can be used when parsing relocations, or
15-
// when printing them, to provide better information.
16-
//
17-
// VENDOR should be the symbol name expected in the associated `R_RISCV_VENDOR`
18-
// relocation. NAME and ID work like `ELF_RELOC` but the mapping is not expected
19-
// to be 1:1.
20-
//
21-
// The mapping in RISCV.def is 1:1, and should be used when the only information
22-
// available is the relocation enum value.
23+
// For each Vendor identifier, VENDOR, as associated with an `R_RISCV_VENDOR`,
24+
// the `ELF_RISCV_NONSTANDARD_RELOC_<VENDOR>(NAME, ID)` macro defines the
25+
// relocations available for that vendor identifier.
2326

24-
// Qualcomm Nonstandard Relocations
25-
ELF_RISCV_NONSTANDARD_RELOC(QUALCOMM, R_RISCV_QC_ABS20_U, 192)
26-
ELF_RISCV_NONSTANDARD_RELOC(QUALCOMM, R_RISCV_QC_E_BRANCH, 193)
27-
ELF_RISCV_NONSTANDARD_RELOC(QUALCOMM, R_RISCV_QC_E_32, 194)
28-
ELF_RISCV_NONSTANDARD_RELOC(QUALCOMM, R_RISCV_QC_E_JUMP_PLT, 195)
27+
// QUALCOMM Nonstandard Relocations
28+
#ifndef ELF_RISCV_NONSTANDARD_RELOC_QUALCOMM
29+
#define ELF_RISCV_NONSTANDARD_RELOC_QUALCOMM(_NAME, _ID)
30+
#endif
31+
32+
ELF_RISCV_NONSTANDARD_RELOC_QUALCOMM(R_RISCV_QC_ABS20_U, 192)
33+
ELF_RISCV_NONSTANDARD_RELOC_QUALCOMM(R_RISCV_QC_E_BRANCH, 193)
34+
ELF_RISCV_NONSTANDARD_RELOC_QUALCOMM(R_RISCV_QC_E_32, 194)
35+
ELF_RISCV_NONSTANDARD_RELOC_QUALCOMM(R_RISCV_QC_E_JUMP_PLT, 195)
36+
37+
#ifdef ELF_RISCV_NONSTANDARD_RELOC_ALL
38+
#undef ELF_RISCV_NONSTANDARD_RELOC_QUALCOMM
39+
#endif

llvm/lib/Target/RISCV/MCTargetDesc/RISCVAsmBackend.cpp

+2-2
Original file line numberDiff line numberDiff line change
@@ -48,9 +48,9 @@ std::optional<MCFixupKind> RISCVAsmBackend::getFixupKind(StringRef Name) const {
4848
#define ELF_RELOC(NAME, ID) .Case(#NAME, ID)
4949
#include "llvm/BinaryFormat/ELFRelocs/RISCV.def"
5050
#undef ELF_RELOC
51-
#define ELF_RISCV_NONSTANDARD_RELOC(_VENDOR, NAME, ID) .Case(#NAME, ID)
51+
#define ELF_RISCV_NONSTANDARD_RELOC_ALL(NAME, ID) .Case(#NAME, ID)
5252
#include "llvm/BinaryFormat/ELFRelocs/RISCV_nonstandard.def"
53-
#undef ELF_RISCV_NONSTANDARD_RELOC
53+
#undef ELF_RISCV_NONSTANDARD_RELOC_ALL
5454
.Case("BFD_RELOC_NONE", ELF::R_RISCV_NONE)
5555
.Case("BFD_RELOC_32", ELF::R_RISCV_32)
5656
.Case("BFD_RELOC_64", ELF::R_RISCV_64)

0 commit comments

Comments
 (0)