Index: lld/wasm/InputChunks.cpp =================================================================== --- lld/wasm/InputChunks.cpp +++ lld/wasm/InputChunks.cpp @@ -60,6 +60,7 @@ for (const WasmRelocation &rel : relocations) { uint64_t existingValue; unsigned bytesRead = 0; + unsigned padding = 0; auto offset = rel.Offset - getInputSectionOffset(); const uint8_t *loc = data().data() + offset; switch (rel.Type) { @@ -68,17 +69,25 @@ case R_WASM_GLOBAL_INDEX_LEB: case R_WASM_EVENT_INDEX_LEB: case R_WASM_MEMORY_ADDR_LEB: + existingValue = decodeULEB128(loc, &bytesRead); + padding = 5; + break; case R_WASM_MEMORY_ADDR_LEB64: existingValue = decodeULEB128(loc, &bytesRead); + padding = 10; break; case R_WASM_TABLE_INDEX_SLEB: - case R_WASM_TABLE_INDEX_SLEB64: case R_WASM_TABLE_INDEX_REL_SLEB: case R_WASM_MEMORY_ADDR_SLEB: - case R_WASM_MEMORY_ADDR_SLEB64: case R_WASM_MEMORY_ADDR_REL_SLEB: + existingValue = static_cast(decodeSLEB128(loc, &bytesRead)); + padding = 5; + break; + case R_WASM_TABLE_INDEX_SLEB64: + case R_WASM_MEMORY_ADDR_SLEB64: case R_WASM_MEMORY_ADDR_REL_SLEB64: existingValue = static_cast(decodeSLEB128(loc, &bytesRead)); + padding = 10; break; case R_WASM_TABLE_INDEX_I32: case R_WASM_MEMORY_ADDR_I32: @@ -95,8 +104,8 @@ llvm_unreachable("unknown relocation type"); } - if (bytesRead && bytesRead != 5) - warn("expected LEB at relocation site be 5-byte padded"); + if (bytesRead && bytesRead != padding) + warn("expected LEB at relocation site be 5/10-byte padded"); if (rel.Type != R_WASM_GLOBAL_INDEX_LEB && rel.Type != R_WASM_GLOBAL_INDEX_I32) { Index: lld/wasm/InputFiles.cpp =================================================================== --- lld/wasm/InputFiles.cpp +++ lld/wasm/InputFiles.cpp @@ -40,6 +40,18 @@ } namespace wasm { + +void checkArch(Triple::ArchType arch, const wasm::InputFile *file) { + bool is64 = arch == Triple::wasm64; + if (is64 && !config->is64.hasValue()) { + fatal(toString(file) + + ": must specify -mwasm64 to process wasm64 object files"); + } else if (config->is64.getValueOr(false) != is64) { + fatal(toString(file) + + ": wasm32 object file can\'t be linked in wasm64 mode"); + } +} + std::unique_ptr tar; Optional readFile(StringRef path) { @@ -286,6 +298,8 @@ bin.release(); wasmObj.reset(obj); + checkArch(obj->getArch(), this); + // Build up a map of function indices to table indices for use when // verifying the existing table index relocations uint32_t totalFunctions = @@ -583,12 +597,7 @@ error(toString(this) + ": machine type must be wasm32 or wasm64"); return; } - bool is64 = t.getArch() == Triple::wasm64; - if (config->is64.hasValue() && *config->is64 != is64) { - error(toString(this) + ": machine type for all bitcode files must match"); - return; - } - config->is64 = is64; + checkArch(t.getArch(), this); std::vector keptComdats; for (StringRef s : obj->getComdatTable()) keptComdats.push_back(symtab->addComdat(s)); Index: llvm/lib/MC/WasmObjectWriter.cpp =================================================================== --- llvm/lib/MC/WasmObjectWriter.cpp +++ llvm/lib/MC/WasmObjectWriter.cpp @@ -498,7 +498,8 @@ // Relocation other than R_WASM_TYPE_INDEX_LEB are required to be // against a named symbol. - if (Type != wasm::R_WASM_TYPE_INDEX_LEB) { + if (Type != wasm::R_WASM_TYPE_INDEX_LEB /*&& + Type != wasm::R_WASM_MEMORY_ADDR_I64*/) { if (SymA->getName().empty()) report_fatal_error("relocations against un-named temporaries are not yet " "supported by wasm");