diff options
| author | Sam Clegg <sbc@chromium.org> | 2018-02-16 18:06:05 +0000 |
|---|---|---|
| committer | Sam Clegg <sbc@chromium.org> | 2018-02-16 18:06:05 +0000 |
| commit | b7a5469c7eb9980ba22b6f43459b8fb42a7ba6e3 (patch) | |
| tree | 0f4519eeb7b3340ad83fdc6e03b341e4781819ab /llvm/lib/MC/WasmObjectWriter.cpp | |
| parent | 91bb7750870147c863145c7241c984b3d3505b74 (diff) | |
| download | bcm5719-llvm-b7a5469c7eb9980ba22b6f43459b8fb42a7ba6e3.tar.gz bcm5719-llvm-b7a5469c7eb9980ba22b6f43459b8fb42a7ba6e3.zip | |
[WebAssembly] MC: Make explicit our current lack of support for relocations against unnamed temporary symbols.
Add an explicit check before looking up symbol in SymbolIndices.
This was previously silently succeeding and returning zero for such
unnamed temporaries.
Differential Revision: https://reviews.llvm.org/D43365
llvm-svn: 325367
Diffstat (limited to 'llvm/lib/MC/WasmObjectWriter.cpp')
| -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; |

