diff options
| author | Dimitry Andric <dim@FreeBSD.org> | 2021-07-29 20:15:26 +0000 |
|---|---|---|
| committer | Dimitry Andric <dim@FreeBSD.org> | 2021-07-29 20:15:26 +0000 |
| commit | 344a3780b2e33f6ca763666c380202b18aab72a3 (patch) | |
| tree | f0b203ee6eb71d7fdd792373e3c81eb18d6934dd /llvm/lib/Target/WebAssembly/MCTargetDesc/WebAssemblyWasmObjectWriter.cpp | |
| parent | b60736ec1405bb0a8dd40989f67ef4c93da068ab (diff) | |
vendor/llvm-project/llvmorg-13-init-16847-g88e66fa60ae5vendor/llvm-project/llvmorg-12.0.1-rc2-0-ge7dac564cd0evendor/llvm-project/llvmorg-12.0.1-0-gfed41342a82f
Diffstat (limited to 'llvm/lib/Target/WebAssembly/MCTargetDesc/WebAssemblyWasmObjectWriter.cpp')
| -rw-r--r-- | llvm/lib/Target/WebAssembly/MCTargetDesc/WebAssemblyWasmObjectWriter.cpp | 46 |
1 files changed, 29 insertions, 17 deletions
diff --git a/llvm/lib/Target/WebAssembly/MCTargetDesc/WebAssemblyWasmObjectWriter.cpp b/llvm/lib/Target/WebAssembly/MCTargetDesc/WebAssemblyWasmObjectWriter.cpp index aa7e2311d240..f67fab946746 100644 --- a/llvm/lib/Target/WebAssembly/MCTargetDesc/WebAssemblyWasmObjectWriter.cpp +++ b/llvm/lib/Target/WebAssembly/MCTargetDesc/WebAssemblyWasmObjectWriter.cpp @@ -34,8 +34,9 @@ public: explicit WebAssemblyWasmObjectWriter(bool Is64Bit, bool IsEmscripten); private: - unsigned getRelocType(const MCValue &Target, - const MCFixup &Fixup) const override; + unsigned getRelocType(const MCValue &Target, const MCFixup &Fixup, + const MCSectionWasm &FixupSection, + bool IsLocRel) const override; }; } // end anonymous namespace @@ -43,7 +44,7 @@ WebAssemblyWasmObjectWriter::WebAssemblyWasmObjectWriter(bool Is64Bit, bool IsEmscripten) : MCWasmObjectTargetWriter(Is64Bit, IsEmscripten) {} -static const MCSection *getFixupSection(const MCExpr *Expr) { +static const MCSection *getTargetSection(const MCExpr *Expr) { if (auto SyExp = dyn_cast<MCSymbolRefExpr>(Expr)) { if (SyExp->getSymbol().isInSection()) return &SyExp->getSymbol().getSection(); @@ -51,19 +52,20 @@ static const MCSection *getFixupSection(const MCExpr *Expr) { } if (auto BinOp = dyn_cast<MCBinaryExpr>(Expr)) { - auto SectionLHS = getFixupSection(BinOp->getLHS()); - auto SectionRHS = getFixupSection(BinOp->getRHS()); + auto SectionLHS = getTargetSection(BinOp->getLHS()); + auto SectionRHS = getTargetSection(BinOp->getRHS()); return SectionLHS == SectionRHS ? nullptr : SectionLHS; } if (auto UnOp = dyn_cast<MCUnaryExpr>(Expr)) - return getFixupSection(UnOp->getSubExpr()); + return getTargetSection(UnOp->getSubExpr()); return nullptr; } -unsigned WebAssemblyWasmObjectWriter::getRelocType(const MCValue &Target, - const MCFixup &Fixup) const { +unsigned WebAssemblyWasmObjectWriter::getRelocType( + const MCValue &Target, const MCFixup &Fixup, + const MCSectionWasm &FixupSection, bool IsLocRel) const { const MCSymbolRefExpr *RefA = Target.getSymA(); assert(RefA); auto& SymA = cast<MCSymbolWasm>(RefA->getSymbol()); @@ -75,9 +77,11 @@ unsigned WebAssemblyWasmObjectWriter::getRelocType(const MCValue &Target, return wasm::R_WASM_GLOBAL_INDEX_LEB; case MCSymbolRefExpr::VK_WASM_TBREL: assert(SymA.isFunction()); - return wasm::R_WASM_TABLE_INDEX_REL_SLEB; + return is64Bit() ? wasm::R_WASM_TABLE_INDEX_REL_SLEB64 + : wasm::R_WASM_TABLE_INDEX_REL_SLEB; case MCSymbolRefExpr::VK_WASM_TLSREL: - return wasm::R_WASM_MEMORY_ADDR_TLS_SLEB; + return is64Bit() ? wasm::R_WASM_MEMORY_ADDR_TLS_SLEB64 + : wasm::R_WASM_MEMORY_ADDR_TLS_SLEB; case MCSymbolRefExpr::VK_WASM_MBREL: assert(SymA.isData()); return is64Bit() ? wasm::R_WASM_MEMORY_ADDR_REL_SLEB64 @@ -102,8 +106,8 @@ unsigned WebAssemblyWasmObjectWriter::getRelocType(const MCValue &Target, return wasm::R_WASM_GLOBAL_INDEX_LEB; if (SymA.isFunction()) return wasm::R_WASM_FUNCTION_INDEX_LEB; - if (SymA.isEvent()) - return wasm::R_WASM_EVENT_INDEX_LEB; + if (SymA.isTag()) + return wasm::R_WASM_TAG_INDEX_LEB; if (SymA.isTable()) return wasm::R_WASM_TABLE_NUMBER_LEB; return wasm::R_WASM_MEMORY_ADDR_LEB; @@ -111,25 +115,33 @@ unsigned WebAssemblyWasmObjectWriter::getRelocType(const MCValue &Target, assert(SymA.isData()); return wasm::R_WASM_MEMORY_ADDR_LEB64; case FK_Data_4: - if (SymA.isFunction()) + if (SymA.isFunction()) { + if (FixupSection.getKind().isMetadata()) + return wasm::R_WASM_FUNCTION_OFFSET_I32; + assert(FixupSection.isWasmData()); return wasm::R_WASM_TABLE_INDEX_I32; + } if (SymA.isGlobal()) return wasm::R_WASM_GLOBAL_INDEX_I32; if (auto Section = static_cast<const MCSectionWasm *>( - getFixupSection(Fixup.getValue()))) { + getTargetSection(Fixup.getValue()))) { if (Section->getKind().isText()) return wasm::R_WASM_FUNCTION_OFFSET_I32; else if (!Section->isWasmData()) return wasm::R_WASM_SECTION_OFFSET_I32; } - return wasm::R_WASM_MEMORY_ADDR_I32; + return IsLocRel ? wasm::R_WASM_MEMORY_ADDR_LOCREL_I32 + : wasm::R_WASM_MEMORY_ADDR_I32; case FK_Data_8: - if (SymA.isFunction()) + if (SymA.isFunction()) { + if (FixupSection.getKind().isMetadata()) + return wasm::R_WASM_FUNCTION_OFFSET_I64; return wasm::R_WASM_TABLE_INDEX_I64; + } if (SymA.isGlobal()) llvm_unreachable("unimplemented R_WASM_GLOBAL_INDEX_I64"); if (auto Section = static_cast<const MCSectionWasm *>( - getFixupSection(Fixup.getValue()))) { + getTargetSection(Fixup.getValue()))) { if (Section->getKind().isText()) return wasm::R_WASM_FUNCTION_OFFSET_I64; else if (!Section->isWasmData()) |
