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,18 @@ class WebAssemblyAsmBackend final : public MCAsmBackend {
48
50
const MCSubtargetInfo *STI) const override ;
49
51
};
50
52
53
+ std::optional<MCFixupKind>
54
+ WebAssemblyAsmBackend::getFixupKind (StringRef Name) const {
55
+ unsigned Type = llvm::StringSwitch<unsigned >(Name)
56
+ #define WASM_RELOC (NAME, ID ) .Case(#NAME, ID)
57
+ #include " llvm/BinaryFormat/WasmRelocs.def"
58
+ #undef WASM_RELOC
59
+ .Default (-1u );
60
+ if (Type != -1u )
61
+ return static_cast <MCFixupKind>(FirstLiteralRelocationKind + Type);
62
+ return std::nullopt;
63
+ }
64
+
51
65
MCFixupKindInfo
52
66
WebAssemblyAsmBackend::getFixupKindInfo (MCFixupKind Kind) const {
53
67
const static MCFixupKindInfo Infos[WebAssembly::NumTargetFixupKinds] = {
@@ -61,6 +75,11 @@ WebAssemblyAsmBackend::getFixupKindInfo(MCFixupKind Kind) const {
61
75
{" fixup_uleb128_i64" , 0 , 10 * 8 , 0 },
62
76
};
63
77
78
+ // Fixup kinds from raw relocation types and .reloc directives force
79
+ // relocations and do not use these fields.
80
+ if (mc::isRelocation (Kind))
81
+ return MCAsmBackend::getFixupKindInfo (FK_NONE);
82
+
64
83
if (Kind < FirstTargetFixupKind)
65
84
return MCAsmBackend::getFixupKindInfo (Kind);
66
85
0 commit comments