13
13
14
14
#include " MCTargetDesc/WebAssemblyFixupKinds.h"
15
15
#include " MCTargetDesc/WebAssemblyMCTargetDesc.h"
16
+ #include " llvm/ADT/StringSwitch.h"
16
17
#include " llvm/MC/MCAsmBackend.h"
17
18
#include " llvm/MC/MCAssembler.h"
18
19
#include " llvm/MC/MCExpr.h"
@@ -36,6 +37,7 @@ class WebAssemblyAsmBackend final : public MCAsmBackend {
36
37
: MCAsmBackend(llvm::endianness::little), Is64Bit(Is64Bit),
37
38
IsEmscripten(IsEmscripten) {}
38
39
40
+ std::optional<MCFixupKind> getFixupKind (StringRef Name) const override ;
39
41
MCFixupKindInfo getFixupKindInfo (MCFixupKind Kind) const override ;
40
42
41
43
void applyFixup (const MCFragment &, const MCFixup &, const MCValue &Target,
@@ -48,6 +50,17 @@ class WebAssemblyAsmBackend final : public MCAsmBackend {
48
50
const MCSubtargetInfo *STI) const override ;
49
51
};
50
52
53
+ std::optional<MCFixupKind> WebAssemblyAsmBackend::getFixupKind (StringRef Name) const {
54
+ unsigned Type = llvm::StringSwitch<unsigned >(Name)
55
+ #define WASM_RELOC (NAME, ID ) .Case(#NAME, ID)
56
+ #include " llvm/BinaryFormat/WasmRelocs.def"
57
+ #undef WASM_RELOC
58
+ .Default (-1u );
59
+ if (Type != -1u )
60
+ return static_cast <MCFixupKind>(FirstLiteralRelocationKind + Type);
61
+ return std::nullopt;
62
+ }
63
+
51
64
MCFixupKindInfo
52
65
WebAssemblyAsmBackend::getFixupKindInfo (MCFixupKind Kind) const {
53
66
const static MCFixupKindInfo Infos[WebAssembly::NumTargetFixupKinds] = {
@@ -61,6 +74,11 @@ WebAssemblyAsmBackend::getFixupKindInfo(MCFixupKind Kind) const {
61
74
{" fixup_uleb128_i64" , 0 , 10 * 8 , 0 },
62
75
};
63
76
77
+ // Fixup kinds from raw relocation types and .reloc directives force
78
+ // relocations and do not use these fields.
79
+ if (mc::isRelocation (Kind))
80
+ return MCAsmBackend::getFixupKindInfo (FK_NONE);
81
+
64
82
if (Kind < FirstTargetFixupKind)
65
83
return MCAsmBackend::getFixupKindInfo (Kind);
66
84
0 commit comments