diff options
Diffstat (limited to 'llvm/lib/MC')
-rw-r--r-- | llvm/lib/MC/WasmObjectWriter.cpp | 19 |
1 files changed, 17 insertions, 2 deletions
diff --git a/llvm/lib/MC/WasmObjectWriter.cpp b/llvm/lib/MC/WasmObjectWriter.cpp index 1ef6567555d..c47c014467a 100644 --- a/llvm/lib/MC/WasmObjectWriter.cpp +++ b/llvm/lib/MC/WasmObjectWriter.cpp @@ -355,6 +355,10 @@ void WasmObjectWriter::recordRelocation(MCAssembler &Asm, if (FixupSection.getSectionName().startswith(".init_array")) return; + // TODO(sbc): Add support for debug sections. + if (FixupSection.getKind().isMetadata()) + return; + if (const MCSymbolRefExpr *RefB = Target.getSymB()) { assert(RefB->getKind() == MCSymbolRefExpr::VK_None && "Should not have constructed this"); @@ -423,12 +427,20 @@ void WasmObjectWriter::recordRelocation(MCAssembler &Asm, WasmRelocationEntry Rec(FixupOffset, SymA, C, Type, &FixupSection); DEBUG(dbgs() << "WasmReloc: " << Rec << "\n"); + // Relocation other than R_WEBASSEMBLY_TYPE_INDEX_LEB are currently required + // to be against a named symbol. + // TODO(sbc): Add support for relocations against unnamed temporaries such + // as those generated by llvm's `blockaddress`. + // See: test/MC/WebAssembly/blockaddress.ll + if (SymA->getName().empty() && Type != wasm::R_WEBASSEMBLY_TYPE_INDEX_LEB) + report_fatal_error("relocations against un-named temporaries are not yet " + "supported by wasm"); + if (FixupSection.isWasmData()) DataRelocations.push_back(Rec); else if (FixupSection.getKind().isText()) CodeRelocations.push_back(Rec); - else if (!FixupSection.getKind().isMetadata()) - // TODO(sbc): Add support for debug sections. + else llvm_unreachable("unexpected section type"); } @@ -496,6 +508,9 @@ WasmObjectWriter::getProvisionalValue(const WasmRelocationEntry &RelEntry) { if (!Sym->isDefined()) return 0; + if (!SymbolIndices.count(Sym)) + report_fatal_error("symbol not found in function/global index space: " + + Sym->getName()); uint32_t GlobalIndex = SymbolIndices[Sym]; const WasmGlobal& Global = Globals[GlobalIndex - NumGlobalImports]; uint64_t Address = Global.InitialValue + RelEntry.Addend; |