diff options
Diffstat (limited to 'llvm/lib/Target/WebAssembly/MCTargetDesc')
| -rw-r--r-- | llvm/lib/Target/WebAssembly/MCTargetDesc/WebAssemblyMCTargetDesc.h | 16 | ||||
| -rw-r--r-- | llvm/lib/Target/WebAssembly/MCTargetDesc/WebAssemblyWasmObjectWriter.cpp | 35 |
2 files changed, 34 insertions, 17 deletions
diff --git a/llvm/lib/Target/WebAssembly/MCTargetDesc/WebAssemblyMCTargetDesc.h b/llvm/lib/Target/WebAssembly/MCTargetDesc/WebAssemblyMCTargetDesc.h index 69c477bbbb5..4c7114eea11 100644 --- a/llvm/lib/Target/WebAssembly/MCTargetDesc/WebAssemblyMCTargetDesc.h +++ b/llvm/lib/Target/WebAssembly/MCTargetDesc/WebAssemblyMCTargetDesc.h @@ -90,9 +90,21 @@ namespace WebAssemblyII { enum TOF { MO_NO_FLAG = 0, - // Address of data symbol via a wasm global. This adds a level of indirection - // similar to the GOT on native platforms. + // On a symbol operand this indicates that the immediate is a wasm global + // index. The value of the wasm global will be set to the symbol address at + // runtime. This adds a level of indirection similar to the GOT on native + // platforms. MO_GOT, + + // On a symbol operand this indicates that the immediate is the symbol + // address relative the __memory_base wasm global. + // Only applicable to data symbols. + MO_MEMORY_BASE_REL, + + // On a symbol operand this indicates that the immediate is the symbol + // address relative the __table_base wasm global. + // Only applicable to function symbols. + MO_TABLE_BASE_REL, }; } // end namespace WebAssemblyII diff --git a/llvm/lib/Target/WebAssembly/MCTargetDesc/WebAssemblyWasmObjectWriter.cpp b/llvm/lib/Target/WebAssembly/MCTargetDesc/WebAssemblyWasmObjectWriter.cpp index 91b356db81d..a1cc3e268e8 100644 --- a/llvm/lib/Target/WebAssembly/MCTargetDesc/WebAssemblyWasmObjectWriter.cpp +++ b/llvm/lib/Target/WebAssembly/MCTargetDesc/WebAssemblyWasmObjectWriter.cpp @@ -42,14 +42,6 @@ private: WebAssemblyWasmObjectWriter::WebAssemblyWasmObjectWriter(bool Is64Bit) : MCWasmObjectTargetWriter(Is64Bit) {} -static bool isFunctionSignatureRef(const MCSymbolRefExpr *Ref) { - return Ref->getKind() == MCSymbolRefExpr::VK_WebAssembly_TYPEINDEX; -} - -static bool isGOTRef(const MCSymbolRefExpr *Ref) { - return Ref->getKind() == MCSymbolRefExpr::VK_GOT; -} - static const MCSection *getFixupSection(const MCExpr *Expr) { if (auto SyExp = dyn_cast<MCSymbolRefExpr>(Expr)) { if (SyExp->getSymbol().isInSection()) @@ -75,6 +67,23 @@ unsigned WebAssemblyWasmObjectWriter::getRelocType(const MCValue &Target, assert(RefA); auto& SymA = cast<MCSymbolWasm>(RefA->getSymbol()); + MCSymbolRefExpr::VariantKind Modifier = Target.getAccessVariant(); + + switch (Modifier) { + case MCSymbolRefExpr::VK_GOT: + return wasm::R_WASM_GLOBAL_INDEX_LEB; + case MCSymbolRefExpr::VK_WASM_TBREL: + assert(SymA.isFunction()); + return wasm::R_WASM_TABLE_INDEX_REL_SLEB; + case MCSymbolRefExpr::VK_WASM_MBREL: + assert(SymA.isData()); + return wasm::R_WASM_MEMORY_ADDR_REL_SLEB; + case MCSymbolRefExpr::VK_WASM_TYPEINDEX: + return wasm::R_WASM_TYPE_INDEX_LEB; + default: + break; + } + switch (unsigned(Fixup.getKind())) { case WebAssembly::fixup_sleb128_i32: if (SymA.isFunction()) @@ -83,14 +92,10 @@ unsigned WebAssemblyWasmObjectWriter::getRelocType(const MCValue &Target, case WebAssembly::fixup_sleb128_i64: llvm_unreachable("fixup_sleb128_i64 not implemented yet"); case WebAssembly::fixup_uleb128_i32: - if (SymA.isGlobal() || isGOTRef(RefA)) + if (SymA.isGlobal()) return wasm::R_WASM_GLOBAL_INDEX_LEB; - if (SymA.isFunction()) { - if (isFunctionSignatureRef(RefA)) - return wasm::R_WASM_TYPE_INDEX_LEB; - else - return wasm::R_WASM_FUNCTION_INDEX_LEB; - } + if (SymA.isFunction()) + return wasm::R_WASM_FUNCTION_INDEX_LEB; if (SymA.isEvent()) return wasm::R_WASM_EVENT_INDEX_LEB; return wasm::R_WASM_MEMORY_ADDR_LEB; |

