diff --git a/clang/lib/Driver/ToolChain.cpp b/clang/lib/Driver/ToolChain.cpp --- a/clang/lib/Driver/ToolChain.cpp +++ b/clang/lib/Driver/ToolChain.cpp @@ -632,8 +632,7 @@ Triple.getArch() == llvm::Triple::armeb || Triple.getArch() == llvm::Triple::thumb || Triple.getArch() == llvm::Triple::thumbeb || - Triple.getArch() == llvm::Triple::wasm32 || - Triple.getArch() == llvm::Triple::wasm64; + Triple.isWasm(); } else if (Model == "posix") return true; @@ -1000,8 +999,7 @@ if (getTriple().getArch() == llvm::Triple::x86 || getTriple().getArch() == llvm::Triple::x86_64 || getTriple().getArch() == llvm::Triple::arm || - getTriple().getArch() == llvm::Triple::wasm32 || - getTriple().getArch() == llvm::Triple::wasm64 || getTriple().isAArch64()) + getTriple().isWasm() || getTriple().isAArch64()) Res |= SanitizerKind::CFIICall; if (getTriple().getArch() == llvm::Triple::x86_64 || getTriple().isAArch64()) Res |= SanitizerKind::ShadowCallStack; diff --git a/lld/wasm/InputFiles.cpp b/lld/wasm/InputFiles.cpp --- a/lld/wasm/InputFiles.cpp +++ b/lld/wasm/InputFiles.cpp @@ -576,10 +576,11 @@ obj = check(lto::InputFile::create(MemoryBufferRef( mb.getBuffer(), saver.save(archiveName + mb.getBufferIdentifier())))); Triple t(obj->getTargetTriple()); - if (t.getArch() != Triple::wasm32) { - error(toString(this) + ": machine type must be wasm32"); + if (!t.isWasm()) { + error(toString(this) + ": machine type must be wasm32 or wasm64"); return; } + config->is64 = t.getArch() == Triple::wasm64; std::vector keptComdats; for (StringRef s : obj->getComdatTable()) keptComdats.push_back(symtab->addComdat(s)); diff --git a/llvm/include/llvm/Object/Wasm.h b/llvm/include/llvm/Object/Wasm.h --- a/llvm/include/llvm/Object/Wasm.h +++ b/llvm/include/llvm/Object/Wasm.h @@ -282,6 +282,7 @@ bool HasLinkingSection = false; bool HasDylinkSection = false; bool SeenCodeSection = false; + bool HasMemory64 = false; wasm::WasmLinkingData LinkingData; uint32_t NumImportedGlobals = 0; uint32_t NumImportedFunctions = 0; diff --git a/llvm/lib/Object/WasmObjectFile.cpp b/llvm/lib/Object/WasmObjectFile.cpp --- a/llvm/lib/Object/WasmObjectFile.cpp +++ b/llvm/lib/Object/WasmObjectFile.cpp @@ -957,6 +957,7 @@ break; case wasm::WASM_EXTERNAL_MEMORY: Im.Memory = readLimits(Ctx); + if (Im.Memory.Flags & wasm::WASM_LIMITS_FLAG_IS_64) HasMemory64 = true; break; case wasm::WASM_EXTERNAL_TABLE: Im.Table = readTable(Ctx); @@ -1019,7 +1020,9 @@ uint32_t Count = readVaruint32(Ctx); Memories.reserve(Count); while (Count--) { - Memories.push_back(readLimits(Ctx)); + auto Limits = readLimits(Ctx); + if (Limits.Flags & wasm::WASM_LIMITS_FLAG_IS_64) HasMemory64 = true; + Memories.push_back(Limits); } if (Ctx.Ptr != Ctx.End) return make_error("Memory section ended prematurely", @@ -1576,11 +1579,15 @@ return section_iterator(SectionRef(Ref, this)); } -uint8_t WasmObjectFile::getBytesInAddress() const { return 4; } +uint8_t WasmObjectFile::getBytesInAddress() const { + return HasMemory64 ? 8 : 4; +} StringRef WasmObjectFile::getFileFormatName() const { return "WASM"; } -Triple::ArchType WasmObjectFile::getArch() const { return Triple::wasm32; } +Triple::ArchType WasmObjectFile::getArch() const { + return HasMemory64 ? Triple::wasm64 : Triple::wasm32; +} SubtargetFeatures WasmObjectFile::getFeatures() const { return SubtargetFeatures();