[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
This commit is contained in:
Sam Clegg 2018-02-16 18:06:05 +00:00
parent 91bb775087
commit b7a5469c7e
3 changed files with 34 additions and 6 deletions

View File

@ -355,6 +355,10 @@ void WasmObjectWriter::recordRelocation(MCAssembler &Asm,
if (FixupSection.getSectionName().startswith(".init_array")) if (FixupSection.getSectionName().startswith(".init_array"))
return; return;
// TODO(sbc): Add support for debug sections.
if (FixupSection.getKind().isMetadata())
return;
if (const MCSymbolRefExpr *RefB = Target.getSymB()) { if (const MCSymbolRefExpr *RefB = Target.getSymB()) {
assert(RefB->getKind() == MCSymbolRefExpr::VK_None && assert(RefB->getKind() == MCSymbolRefExpr::VK_None &&
"Should not have constructed this"); "Should not have constructed this");
@ -423,12 +427,20 @@ void WasmObjectWriter::recordRelocation(MCAssembler &Asm,
WasmRelocationEntry Rec(FixupOffset, SymA, C, Type, &FixupSection); WasmRelocationEntry Rec(FixupOffset, SymA, C, Type, &FixupSection);
DEBUG(dbgs() << "WasmReloc: " << Rec << "\n"); 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()) if (FixupSection.isWasmData())
DataRelocations.push_back(Rec); DataRelocations.push_back(Rec);
else if (FixupSection.getKind().isText()) else if (FixupSection.getKind().isText())
CodeRelocations.push_back(Rec); CodeRelocations.push_back(Rec);
else if (!FixupSection.getKind().isMetadata()) else
// TODO(sbc): Add support for debug sections.
llvm_unreachable("unexpected section type"); llvm_unreachable("unexpected section type");
} }
@ -496,6 +508,9 @@ WasmObjectWriter::getProvisionalValue(const WasmRelocationEntry &RelEntry) {
if (!Sym->isDefined()) if (!Sym->isDefined())
return 0; return 0;
if (!SymbolIndices.count(Sym))
report_fatal_error("symbol not found in function/global index space: " +
Sym->getName());
uint32_t GlobalIndex = SymbolIndices[Sym]; uint32_t GlobalIndex = SymbolIndices[Sym];
const WasmGlobal& Global = Globals[GlobalIndex - NumGlobalImports]; const WasmGlobal& Global = Globals[GlobalIndex - NumGlobalImports];
uint64_t Address = Global.InitialValue + RelEntry.Addend; uint64_t Address = Global.InitialValue + RelEntry.Addend;

View File

@ -11,7 +11,8 @@
# to wasm object files (.o). # to wasm object files (.o).
# Computed gotos are not supported (Cannot select BlockAddress/BRIND) # Computed gotos are not supported (Cannot select BlockAddress/BRIND)
20071220-1.c wasm-o,O0 20071220-1.c wasm-o
20071220-2.c wasm-o
20040302-1.c 20040302-1.c
20041214-1.c O0 20041214-1.c O0
20071210-1.c 20071210-1.c
@ -97,9 +98,6 @@ devirt-14.C # bad main signature
devirt-21.C # bad main signature devirt-21.C # bad main signature
devirt-23.C # bad main signature devirt-23.C # bad main signature
# Untriaged: Assertion failure in WasmObjectWriter::applyRelocations
20071220-2.c wasm-o,O0
# Untriaged C++ failures # Untriaged C++ failures
spec5.C spec5.C
addr1.C addr1.C

View File

@ -0,0 +1,15 @@
; TODO(sbc): Make this test pass by adding support for unnamed tempoaries
; in wasm relocations.
; RUN: not llc -filetype=obj %s
target triple = "wasm32-unknown-unknown-wasm"
@foo = internal global i8* blockaddress(@bar, %addr), align 4
define hidden i32 @bar() #0 {
entry:
br label %addr
addr:
ret i32 0
}