diff --git a/clang/lib/CodeGen/ObjectFilePCHContainerOperations.cpp b/clang/lib/CodeGen/ObjectFilePCHContainerOperations.cpp index 15a2ab99fdac2..8935cadffcdfa 100644 --- a/clang/lib/CodeGen/ObjectFilePCHContainerOperations.cpp +++ b/clang/lib/CodeGen/ObjectFilePCHContainerOperations.cpp @@ -332,18 +332,27 @@ ObjectFilePCHContainerReader::ExtractPCH(llvm::MemoryBufferRef Buffer) const { if (OFOrErr) { auto &OF = OFOrErr.get(); bool IsCOFF = isa(*OF); - // Find the clang AST section in the container. - for (auto &Section : OF->sections()) { - StringRef Name; - Section.getName(Name); - if ((!IsCOFF && Name == "__clangast") || (IsCOFF && Name == "clangast")) { - if (Expected E = Section.getContents()) - return *E; - else { - handleAllErrors(E.takeError(), [&](const llvm::ErrorInfoBase &EIB) { - EIB.log(llvm::errs()); - }); - return ""; + StringRef SectionName = IsCOFF ? "clangast" : "__clangast"; + + if (const auto &WasmOF = llvm::unique_dyn_cast(OF)) { + for (auto &Segment : WasmOF->dataSegments()) { + if (Segment.Data.Name != SectionName) continue; + return llvm::toStringRef(Segment.Data.Content); + } + } else { + // Find the clang AST section in the container. + for (auto &Section : OF->sections()) { + StringRef Name; + Section.getName(Name); + if (Name == SectionName) { + if (Expected E = Section.getContents()) + return *E; + else { + handleAllErrors(E.takeError(), [&](const llvm::ErrorInfoBase &EIB) { + EIB.log(llvm::errs()); + }); + return ""; + } } } } diff --git a/clang/lib/Driver/ToolChains/Clang.cpp b/clang/lib/Driver/ToolChains/Clang.cpp index fcc55a756b679..e9e2b9ffbe7ba 100644 --- a/clang/lib/Driver/ToolChains/Clang.cpp +++ b/clang/lib/Driver/ToolChains/Clang.cpp @@ -448,9 +448,6 @@ static void addExceptionArgs(const ArgList &Args, types::ID InputType, // Disable C++ EH by default on XCore and PS4. bool CXXExceptionsEnabled = Triple.getArch() != llvm::Triple::xcore && !Triple.isPS4CPU(); - // WebAssembly: no exception handling on WASI - if (Triple.isOSBinFormatWasm()) - CXXExceptionsEnabled = false; Arg *ExceptionArg = Args.getLastArg( options::OPT_fcxx_exceptions, options::OPT_fno_cxx_exceptions, options::OPT_fexceptions, options::OPT_fno_exceptions); diff --git a/llvm/lib/CodeGen/TargetLoweringObjectFileImpl.cpp b/llvm/lib/CodeGen/TargetLoweringObjectFileImpl.cpp index 083776e2e4fef..338ef97dc1340 100644 --- a/llvm/lib/CodeGen/TargetLoweringObjectFileImpl.cpp +++ b/llvm/lib/CodeGen/TargetLoweringObjectFileImpl.cpp @@ -1682,10 +1682,6 @@ static SectionKind getWasmKindForNamedSection(StringRef Name, SectionKind K) { if (K.isText()) return SectionKind::getText(); - // Clang precompiled header data isn't needed at runtime; use custom section - if (Name == "__clangast") - return SectionKind::getMetadata(); - // Otherwise, ignore whatever section type the generic impl detected and use // a plain data section. return SectionKind::getData(); diff --git a/llvm/lib/MC/WasmObjectWriter.cpp b/llvm/lib/MC/WasmObjectWriter.cpp index cc6022f7ea5aa..c163c7d6ed38b 100644 --- a/llvm/lib/MC/WasmObjectWriter.cpp +++ b/llvm/lib/MC/WasmObjectWriter.cpp @@ -372,15 +372,7 @@ void WasmObjectWriter::startCustomSection(SectionBookkeeping &Section, Section.PayloadOffset = W.OS.tell(); // Custom sections in wasm also have a string identifier. - if (Name != "__clangast") { - writeString(Name); - } else { - // pad section start to nearest 4 bytes for Clang PCH - uint64_t MinLength = Section.PayloadOffset + 5ULL /* min ULEB128 length */ + Name.size(); - uint64_t RoundedUpLength = (MinLength + 3ULL) & ~3ULL; - encodeULEB128(Name.size(), W.OS, 5 + (RoundedUpLength - MinLength)); - W.OS << Name; - } + writeString(Name); // The position where the custom section starts. Section.ContentsOffset = W.OS.tell(); @@ -493,9 +485,6 @@ void WasmObjectWriter::recordRelocation(MCAssembler &Asm, if (SymA && SymA->isVariable()) { const MCExpr *Expr = SymA->getVariableValue(); - if (Expr->getKind() != MCExpr::SymbolRef) { - fprintf(stderr, "The expr type is %d\n", (int)Expr->getKind()); - } const auto *Inner = dyn_cast(Expr); if (Inner && Inner->getKind() == MCSymbolRefExpr::VK_WEAKREF) llvm_unreachable("weakref used in reloc not yet implemented"); @@ -581,7 +570,6 @@ static const MCSymbolWasm *resolveSymbol(const MCSymbolWasm &Symbol) { while (Ret->isVariable()) { const MCExpr *Expr = Ret->getVariableValue(); if (Expr->getKind() == MCExpr::Binary) { - fprintf(stderr, "The expr type is %d\n", (int)Expr->getKind()); Expr = pullSymbol(Expr); if (!Expr) { llvm_unreachable("can't find a symbol in this mess\n"); @@ -1081,16 +1069,8 @@ void WasmObjectWriter::writeCustomSection(WasmCustomSection &CustomSection, auto *Sec = CustomSection.Section; startCustomSection(Section, CustomSection.Name); - if (CustomSection.Name == "__clangast") { - // pad to nearest 4 bytes - uint64_t RoundedUp = (Section.ContentsOffset + 3ULL) & ~3ULL; - for (uint64_t Count = 0; Count < RoundedUp - Section.ContentsOffset; Count++) { - W.OS << char(0); - } - } - - Sec->setSectionOffset(W.OS.tell() - Section.ContentsOffset); - Asm.writeSectionData(W.OS, Sec, Layout); + Sec->setSectionOffset(W.OS.tell() - Section.ContentsOffset); + Asm.writeSectionData(W.OS, Sec, Layout); CustomSection.OutputContentsOffset = Section.ContentsOffset; CustomSection.OutputIndex = Section.Index; @@ -1171,29 +1151,9 @@ static bool isInSymtab(const MCSymbolWasm &Sym) { if (Sym.isSection()) return false; - // Clang's precompiled headers are in a separate custom section - if (Sym.getName() == "__clang_ast") - return false; - return true; } -// SwiftWasm: takes a MCSymbolWasm that's an alias expression of the form -// ((targetSymbol + constantA) - constantB) + constantC...) -// return the final offset from targetSymbol. -// if no offset, returns 0. -static int64_t getAliasedSymbolOffset(const MCSymbolWasm &Symbol, - const MCAsmLayout &Layout) { - if (!Symbol.isVariable()) - return 0; - const MCExpr *Expr = Symbol.getVariableValue(); - MCValue Res; - if (!Expr->evaluateAsRelocatable(Res, &Layout, nullptr)) { - report_fatal_error("Can't evaluate alias symbol expression"); - } - return Res.getConstant(); -} - uint64_t WasmObjectWriter::writeObject(MCAssembler &Asm, const MCAsmLayout &Layout) { uint64_t StartOffset = W.OS.tell(); @@ -1424,10 +1384,6 @@ uint64_t WasmObjectWriter::writeObject(MCAssembler &Asm, LLVM_DEBUG(dbgs() << " -> function index: " << Index << "\n"); } else if (WS.isData()) { - if (WS.getName() == "__clang_ast") - continue; - if (WS.isTemporary() && !WS.getSize()) - continue; if (!isInSymtab(WS)) continue; @@ -1503,9 +1459,6 @@ uint64_t WasmObjectWriter::writeObject(MCAssembler &Asm, // Find the target symbol of this weak alias and export that index const auto &WS = static_cast(S); const MCSymbolWasm *ResolvedSym = resolveSymbol(WS); - if (!ResolvedSym) { - continue; - } LLVM_DEBUG(dbgs() << WS.getName() << ": weak alias of '" << *ResolvedSym << "'\n"); @@ -1517,16 +1470,8 @@ uint64_t WasmObjectWriter::writeObject(MCAssembler &Asm, LLVM_DEBUG(dbgs() << " -> index:" << WasmIndex << "\n"); } else if (ResolvedSym->isData()) { assert(DataLocations.count(ResolvedSym) > 0); - // SwiftWasm: hack: grab the offset - // Swift has aliases of the form - // alias = ((symbol + constant) - constant) - // so we need to evaluate the constants here using MCExpr - // there's probably a proper way to do this. - int64_t Offset = getAliasedSymbolOffset(WS, Layout); - wasm::WasmDataReference Ref = + const wasm::WasmDataReference &Ref = DataLocations.find(ResolvedSym)->second; - Ref.Offset += Offset; - Ref.Size -= Offset; DataLocations[&WS] = Ref; LLVM_DEBUG(dbgs() << " -> index:" << Ref.Segment << "\n"); } else {