Index: include/llvm/BinaryFormat/Wasm.h =================================================================== --- include/llvm/BinaryFormat/Wasm.h +++ include/llvm/BinaryFormat/Wasm.h @@ -150,7 +150,11 @@ uint32_t ElementIndex; // For a data symbols, the address of the data relative to segment. WasmDataReference DataRef; + // For a section symbols, the code of the section (see also SectionName). + uint32_t SectionCode; }; + // Present for a section symbols, when code is a custom section. + StringRef SectionName; }; struct WasmFunctionName { @@ -247,6 +251,7 @@ WASM_SYMBOL_TYPE_FUNCTION = 0x0, WASM_SYMBOL_TYPE_DATA = 0x1, WASM_SYMBOL_TYPE_GLOBAL = 0x2, + WASM_SYMBOL_TYPE_SECTION = 0x3, }; const unsigned WASM_SYMBOL_BINDING_MASK = 0x3; Index: include/llvm/BinaryFormat/WasmRelocs.def =================================================================== --- include/llvm/BinaryFormat/WasmRelocs.def +++ include/llvm/BinaryFormat/WasmRelocs.def @@ -11,3 +11,5 @@ WASM_RELOC(R_WEBASSEMBLY_MEMORY_ADDR_I32, 5) WASM_RELOC(R_WEBASSEMBLY_TYPE_INDEX_LEB, 6) WASM_RELOC(R_WEBASSEMBLY_GLOBAL_INDEX_LEB, 7) +WASM_RELOC(R_WEBASSEMBLY_FUNCTION_OFFSET_I32, 8) +WASM_RELOC(R_WEBASSEMBLY_SECTION_OFFSET_I32, 9) Index: include/llvm/Object/Wasm.h =================================================================== --- include/llvm/Object/Wasm.h +++ include/llvm/Object/Wasm.h @@ -28,6 +28,7 @@ #include #include #include +#include namespace llvm { namespace object { @@ -53,6 +54,10 @@ return Info.Kind == wasm::WASM_SYMBOL_TYPE_GLOBAL; } + bool isTypeSection() const { + return Info.Kind == wasm::WASM_SYMBOL_TYPE_SECTION; + } + bool isDefined() const { return !isUndefined(); } bool isUndefined() const { @@ -206,6 +211,7 @@ bool isValidFunctionSymbol(uint32_t Index) const; bool isValidGlobalSymbol(uint32_t Index) const; bool isValidDataSymbol(uint32_t Index) const; + bool isValidSectionSymbol(uint32_t Index) const; wasm::WasmFunction &getDefinedFunction(uint32_t Index); wasm::WasmGlobal &getDefinedGlobal(uint32_t Index); @@ -255,6 +261,7 @@ std::vector Functions; std::vector Symbols; std::vector DebugNames; + std::unordered_set InternedNames; uint32_t StartFunction = -1; bool HasLinkingSection = false; wasm::WasmLinkingData LinkingData; Index: include/llvm/ObjectYAML/WasmYAML.h =================================================================== --- include/llvm/ObjectYAML/WasmYAML.h +++ include/llvm/ObjectYAML/WasmYAML.h @@ -138,7 +138,9 @@ union { uint32_t ElementIndex; wasm::WasmDataReference DataRef; + SectionType SectionType; }; + StringRef SectionName; // present when SectionType is a custom section }; struct InitFunction { Index: lib/MC/WasmObjectWriter.cpp =================================================================== --- lib/MC/WasmObjectWriter.cpp +++ lib/MC/WasmObjectWriter.cpp @@ -48,7 +48,9 @@ struct SectionBookkeeping { // Where the size of the section is written. uint64_t SizeOffset; - // Where the contents of the section starts (after the header). + // Where the section header ends (without custom section name). + uint64_t PayloadOffset; + // Where the contents of the section starts. uint64_t ContentsOffset; }; @@ -131,6 +133,15 @@ uint32_t Index; }; +// Information to store symbols that point to Wasm sections content offsets. +struct WasmSectionEntry { + const MCSymbolWasm *Sym; + const MCSection* Section; + + WasmSectionEntry(const MCSymbolWasm *Sym, const MCSection* Section) + : Sym(Sym), Section(Section) {} +}; + // Information about a single relocation. struct WasmRelocationEntry { uint64_t Offset; // Where is the relocation. @@ -150,6 +161,8 @@ case wasm::R_WEBASSEMBLY_MEMORY_ADDR_LEB: case wasm::R_WEBASSEMBLY_MEMORY_ADDR_SLEB: case wasm::R_WEBASSEMBLY_MEMORY_ADDR_I32: + case wasm::R_WEBASSEMBLY_FUNCTION_OFFSET_I32: + case wasm::R_WEBASSEMBLY_SECTION_OFFSET_I32: return true; default: return false; @@ -184,6 +197,9 @@ // Relocations for fixing up references in the data section. std::vector DataRelocations; + // Relocations for fixing up references in the custom sections. + StringMap< std::vector > CustomSectionsRelocations; + // Index values to use for fixing up call_indirect type indices. // Maps function symbols to the index of the type of the function DenseMap TypeIndices; @@ -196,6 +212,8 @@ DenseMap WasmIndices; // Maps data symbols to the Wasm segment and offset/size with the segment. DenseMap DataLocations; + // Maps section symbols to the section. + DenseMap CustomSections; DenseMap FunctionTypeIndices; @@ -227,11 +245,13 @@ void reset() override { CodeRelocations.clear(); DataRelocations.clear(); + CustomSectionsRelocations.clear(); TypeIndices.clear(); SymbolIndices.clear(); WasmIndices.clear(); TableIndices.clear(); DataLocations.clear(); + CustomSections.clear(); FunctionTypeIndices.clear(); FunctionTypes.clear(); Globals.clear(); @@ -273,11 +293,16 @@ void writeDataSection(); void writeCodeRelocSection(); void writeDataRelocSection(); + void writeCustomRelocSections(); void writeLinkingMetaDataSection( ArrayRef SymbolInfos, ArrayRef> InitFuncs, const std::map> &Comdats); + void writeDebugSections(const MCAssembler &Asm, + const MCAsmLayout &Layout); + void updateCustomSectionRelocations( + const SmallVector &Functions); uint32_t getProvisionalValue(const WasmRelocationEntry &RelEntry); void applyRelocations(ArrayRef Relocations, uint64_t ContentsOffset); @@ -308,20 +333,23 @@ // for any 32-bit value; we'll patch it later. encodeULEB128(UINT32_MAX, getStream()); - // The position where the section starts, for measuring its size. - Section.ContentsOffset = getStream().tell(); + // The position where the section header ends, for measuring its size. + Section.PayloadOffset = getStream().tell(); // Custom sections in wasm also have a string identifier. if (SectionId == wasm::WASM_SEC_CUSTOM) { assert(Name); writeString(StringRef(Name)); } + + // The position where the section starts. + Section.ContentsOffset = getStream().tell(); } // Now that the section is complete and we know how big it is, patch up the // section size field at the start of the section. void WasmObjectWriter::endSection(SectionBookkeeping &Section) { - uint64_t Size = getStream().tell() - Section.ContentsOffset; + uint64_t Size = getStream().tell() - Section.PayloadOffset; if (uint32_t(Size) != Size) report_fatal_error("section size does not fit in a uint32_t"); @@ -362,9 +390,13 @@ if (FixupSection.getSectionName().startswith(".init_array")) return; - // TODO(sbc): Add support for debug sections. - if (FixupSection.getKind().isMetadata()) - return; + bool IsDebugFixup = false; + // TODO: Add support for non-debug metadata sections? + if (FixupSection.getKind().isMetadata()) { + if (!FixupSection.getSectionName().startswith(".debug_")) + return; + IsDebugFixup = true; + } if (const MCSymbolRefExpr *RefB = Target.getSymB()) { assert(RefB->getKind() == MCSymbolRefExpr::VK_None && @@ -434,6 +466,27 @@ WasmRelocationEntry Rec(FixupOffset, SymA, C, Type, &FixupSection); DEBUG(dbgs() << "WasmReloc: " << Rec << "\n"); + if (IsDebugFixup) { + switch (Type) { + case wasm::R_WEBASSEMBLY_MEMORY_ADDR_I32: + case wasm::R_WEBASSEMBLY_FUNCTION_OFFSET_I32: + case wasm::R_WEBASSEMBLY_SECTION_OFFSET_I32: + break; + default: + report_fatal_error("relocation in debug section supported only for " + "R_WEBASSEMBLY_MEMORY_ADDR_I32 or _OFFSET_I32"); + } + + const auto& FixupSectionName = FixupSection.getSectionName().str(); + auto Relocs = CustomSectionsRelocations.find(FixupSectionName); + if (Relocs == CustomSectionsRelocations.end()) { + CustomSectionsRelocations[FixupSectionName] = std::vector(); + Relocs = CustomSectionsRelocations.find(FixupSectionName); + } + Relocs->second.push_back(Rec); + return; + } + // 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 @@ -511,6 +564,14 @@ report_fatal_error("symbol not found in wasm index space: " + RelEntry.Symbol->getName()); return WasmIndices[RelEntry.Symbol]; + case wasm::R_WEBASSEMBLY_FUNCTION_OFFSET_I32: { + const auto &Section = static_cast(RelEntry.Symbol->getSection()); + return Section.getSectionOffset() + RelEntry.Addend; + } + case wasm::R_WEBASSEMBLY_SECTION_OFFSET_I32: { + const auto &Section = *CustomSections.find(RelEntry.Symbol)->second; + return Section.getSectionOffset() + RelEntry.Addend; + } case wasm::R_WEBASSEMBLY_MEMORY_ADDR_LEB: case wasm::R_WEBASSEMBLY_MEMORY_ADDR_I32: case wasm::R_WEBASSEMBLY_MEMORY_ADDR_SLEB: { @@ -602,6 +663,8 @@ break; case wasm::R_WEBASSEMBLY_TABLE_INDEX_I32: case wasm::R_WEBASSEMBLY_MEMORY_ADDR_I32: + case wasm::R_WEBASSEMBLY_FUNCTION_OFFSET_I32: + case wasm::R_WEBASSEMBLY_SECTION_OFFSET_I32: WriteI32(Stream, Value, Offset); break; case wasm::R_WEBASSEMBLY_TABLE_INDEX_SLEB: @@ -861,6 +924,24 @@ endSection(Section); } +void WasmObjectWriter::writeCustomRelocSections() { + for (const auto& P: CustomSectionsRelocations) { + auto CustomSectionName = P.first(); + auto CustomSectionRelocations = P.second; + + SectionBookkeeping Section; + startSection(Section, wasm::WASM_SEC_CUSTOM, ("reloc." + CustomSectionName).str().c_str()); + + encodeULEB128(wasm::WASM_SEC_CUSTOM, getStream()); + writeString(CustomSectionName); + encodeULEB128(CustomSectionRelocations.size(), getStream()); + + writeRelocations(CustomSectionRelocations); + + endSection(Section); + } +} + void WasmObjectWriter::writeLinkingMetaDataSection( ArrayRef SymbolInfos, ArrayRef> InitFuncs, @@ -890,6 +971,11 @@ encodeULEB128(Sym.DataRef.Size, getStream()); } break; + case wasm::WASM_SYMBOL_TYPE_SECTION: + encodeULEB128(Sym.SectionCode, getStream()); + if (Sym.SectionCode == wasm::WASM_SEC_CUSTOM) + writeString(Sym.SectionName); + break; default: llvm_unreachable("unexpected kind"); } @@ -936,6 +1022,60 @@ endSection(Section); } +void WasmObjectWriter::writeDebugSections(const MCAssembler &Asm, + const MCAsmLayout &Layout) { + for (MCSection &Sec : Asm) { + auto &DebugSection = static_cast(Sec); + StringRef SectionName = DebugSection.getSectionName(); + + if (!SectionName.startswith(".debug_")) + continue; + + SectionBookkeeping Section; + startSection(Section, wasm::WASM_SEC_CUSTOM, SectionName.str().c_str()); + + DebugSection.setSectionOffset(getStream().tell() - Section.ContentsOffset); + Asm.writeSectionData(&DebugSection, Layout); + + endSection(Section); + } +} + +void WasmObjectWriter::updateCustomSectionRelocations( + const SmallVector &Functions) { + std::map SectionSymbols; + for (const auto& P: CustomSections) + SectionSymbols[P.second] = P.first; + std::map FuncSymbols; + for (const auto& FuncInfo: Functions) + FuncSymbols[&FuncInfo.Sym->getSection()] = FuncInfo.Sym; + + // Patch relocation records for R_WEBASSEMBLY_FUNCTION_OFFSET_I32 and + // R_WEBASSEMBLY_SECTION_OFFSET_I32. + for (auto& P: CustomSectionsRelocations) { + for (WasmRelocationEntry& RelEntry: P.second) { + switch (RelEntry.Type) { + case wasm::R_WEBASSEMBLY_FUNCTION_OFFSET_I32: { + assert(RelEntry.hasAddend()); + auto& Section = static_cast(RelEntry.Symbol->getSection()); + RelEntry.Symbol = FuncSymbols[&Section]; + RelEntry.Addend += Section.getSectionOffset(); + break; + } + case wasm::R_WEBASSEMBLY_SECTION_OFFSET_I32: { + assert(RelEntry.hasAddend()); + auto& Section = static_cast(RelEntry.Symbol->getSection()); + RelEntry.Symbol = SectionSymbols[&Section]; + RelEntry.Addend += Section.getSectionOffset(); + break; + } + default: + break; + } + } + } +} + uint32_t WasmObjectWriter::getFunctionType(const MCSymbolWasm& Symbol) { assert(Symbol.isFunction()); assert(TypeIndices.count(&Symbol)); @@ -1067,6 +1207,28 @@ } } + // Create symbols for debug/custom sections. + for (const MCSection &Sec : Asm) { + const auto &DebugSection = static_cast(Sec); + StringRef SectionName = DebugSection.getSectionName(); + + if (!SectionName.startswith(".debug_")) + continue; + + auto SymbolName = (".Lsection_start" + SectionName).str(); + MCSymbolWasm *SectionSym = cast(Ctx.getOrCreateSymbol(SymbolName)); + CustomSections[SectionSym] = &DebugSection; + + wasm::WasmSymbolInfo Info; + Info.Name = SectionSym->getName(); + Info.Kind = wasm::WASM_SYMBOL_TYPE_SECTION; + Info.Flags = 0; + Info.SectionCode = wasm::WASM_SEC_CUSTOM; + Info.SectionName = SectionName; + SymbolIndices[SectionSym] = SymbolInfos.size(); + SymbolInfos.emplace_back(Info); + } + // Populate WasmIndices and DataLocations for defined symbols. for (const MCSymbol &S : Asm.symbols()) { // Ignore unnamed temporary symbols, which aren't ever exported, imported, @@ -1310,12 +1472,14 @@ writeElemSection(TableElems); writeCodeSection(Asm, Layout, Functions); writeDataSection(); + writeDebugSections(Asm, Layout); + updateCustomSectionRelocations(Functions); writeLinkingMetaDataSection(SymbolInfos, InitFuncs, Comdats); writeCodeRelocSection(); writeDataRelocSection(); + writeCustomRelocSections(); // TODO: Translate the .comment section to the output. - // TODO: Translate debug sections to the output. } std::unique_ptr Index: lib/Object/WasmObjectFile.cpp =================================================================== --- lib/Object/WasmObjectFile.cpp +++ lib/Object/WasmObjectFile.cpp @@ -460,6 +460,23 @@ } break; + case wasm::WASM_SYMBOL_TYPE_SECTION: { + Info.SectionCode = readVaruint32(Ptr); + if (Info.SectionCode != wasm::WASM_SEC_CUSTOM) + return make_error("invalid section symbol target", + object_error::parse_failed); + Info.SectionName = readString(Ptr); + if (!findCustomSectionByName(Info.SectionName)) + return make_error("referred symbol section " + + Info.SectionName + " is missing", + object_error::parse_failed); + + // Generate somewhat unique name for the section symbol. + auto SymbolName = (".Lsection_start" + Info.SectionName).str(); + Info.Name = StringRef(*InternedNames.insert(SymbolName).first); + break; + } + default: return make_error("Invalid symbol type", object_error::parse_failed); @@ -591,6 +608,18 @@ object_error::parse_failed); Reloc.Addend = readVarint32(Ptr); break; + case wasm::R_WEBASSEMBLY_FUNCTION_OFFSET_I32: + if (!isValidFunctionSymbol(Reloc.Index)) + return make_error("Bad relocation function index", + object_error::parse_failed); + Reloc.Addend = readVarint32(Ptr); + break; + case wasm::R_WEBASSEMBLY_SECTION_OFFSET_I32: + if (!isValidSectionSymbol(Reloc.Index)) + return make_error("Bad relocation section index", + object_error::parse_failed); + Reloc.Addend = readVarint32(Ptr); + break; default: return make_error("Bad relocation type: " + Twine(Reloc.Type), @@ -830,6 +859,10 @@ return Index < Symbols.size() && Symbols[Index].isTypeData(); } +bool WasmObjectFile::isValidSectionSymbol(uint32_t Index) const { + return Index < Symbols.size() && Symbols[Index].isTypeSection(); +} + wasm::WasmFunction &WasmObjectFile::getDefinedFunction(uint32_t Index) { assert(isDefinedFunctionIndex(Index)); return Functions[Index - NumImportedFunctions]; @@ -1010,6 +1043,8 @@ assert(Segment.Offset.Opcode == wasm::WASM_OPCODE_I32_CONST); return Segment.Offset.Value.Int32 + Sym.Info.DataRef.Offset; } + case wasm::WASM_SYMBOL_TYPE_SECTION: + return 0; // TODO(yury): section offset from top of the object file? } llvm_unreachable("invalid symbol type"); } @@ -1039,6 +1074,12 @@ return SymbolRef::ST_Other; case wasm::WASM_SYMBOL_TYPE_DATA: return SymbolRef::ST_Data; + case wasm::WASM_SYMBOL_TYPE_SECTION: + if (Sym.Info.SectionCode == wasm::WASM_SEC_CUSTOM && + Sym.Info.SectionName.startswith(".debug_")) + return SymbolRef::ST_Debug; + // Support of non-debug custom sections is not implemented yet. + break; } llvm_unreachable("Unknown WasmSymbol::SymbolType"); @@ -1062,6 +1103,18 @@ case wasm::WASM_SYMBOL_TYPE_DATA: Ref.d.a = DataSection; break; + case wasm::WASM_SYMBOL_TYPE_SECTION: { + assert(Sym.Info.SectionCode != wasm::WASM_SEC_CUSTOM); + // Find index of the referred custom section. + auto Section = std::find_if(Sections.begin(), Sections.end(), + [&] (const WasmSection& Sec) -> bool { + return Sec.Type== wasm::WASM_SEC_CUSTOM && + Sec.Name == Sym.Info.SectionName; + }); + assert(Section != Sections.end()); + Ref.d.a = std::distance(Sections.begin(), Section); + break; + } default: llvm_unreachable("Unknown WasmSymbol::SymbolType"); } Index: lib/ObjectYAML/WasmYAML.cpp =================================================================== --- lib/ObjectYAML/WasmYAML.cpp +++ lib/ObjectYAML/WasmYAML.cpp @@ -404,6 +404,10 @@ IO.mapOptional("Offset", Info.DataRef.Offset, 0u); IO.mapRequired("Size", Info.DataRef.Size); } + } else if (Info.Kind == wasm::WASM_SYMBOL_TYPE_SECTION) { + IO.mapRequired("SectionType", Info.SectionType); + if (Info.SectionType == wasm::WASM_SEC_CUSTOM) + IO.mapRequired("SectionName", Info.SectionName); } else { llvm_unreachable("unsupported symbol kind"); } @@ -438,6 +442,7 @@ ECase(FUNCTION); ECase(DATA); ECase(GLOBAL); + ECase(SECTION); #undef ECase } Index: lib/Target/WebAssembly/MCTargetDesc/WebAssemblyWasmObjectWriter.cpp =================================================================== --- lib/Target/WebAssembly/MCTargetDesc/WebAssemblyWasmObjectWriter.cpp +++ lib/Target/WebAssembly/MCTargetDesc/WebAssemblyWasmObjectWriter.cpp @@ -21,6 +21,7 @@ #include "llvm/MC/MCFixupKindInfo.h" #include "llvm/MC/MCObjectWriter.h" #include "llvm/MC/MCSymbolWasm.h" +#include "llvm/MC/MCSectionWasm.h" #include "llvm/MC/MCWasmObjectWriter.h" #include "llvm/MC/MCValue.h" #include "llvm/Support/Casting.h" @@ -61,6 +62,22 @@ return RefA && RefA->getKind() == MCSymbolRefExpr::VK_WebAssembly_TYPEINDEX; } +static const MCSection* GetFixupSection(const MCExpr *Expr) { + if (auto SyExp = dyn_cast(Expr)) + return &SyExp->getSymbol().getSection(); + + if (auto BinOp = dyn_cast(Expr)) { + auto SectionLHS = GetFixupSection(BinOp->getLHS()); + auto SectionRHS = GetFixupSection(BinOp->getRHS()); + return SectionLHS == SectionRHS ? nullptr : SectionLHS; + } + + if (auto UnOp = dyn_cast(Expr)) + return GetFixupSection(UnOp->getSubExpr()); + + return nullptr; +} + unsigned WebAssemblyWasmObjectWriter::getRelocType(const MCValue &Target, const MCFixup &Fixup) const { @@ -86,6 +103,12 @@ case FK_Data_4: if (IsFunction) return wasm::R_WEBASSEMBLY_TABLE_INDEX_I32; + if (auto Section = static_cast(GetFixupSection(Fixup.getValue()))) { + if (Section->getKind().isText()) + return wasm::R_WEBASSEMBLY_FUNCTION_OFFSET_I32; + else if (!Section->isWasmData()) + return wasm::R_WEBASSEMBLY_SECTION_OFFSET_I32; + } return wasm::R_WEBASSEMBLY_MEMORY_ADDR_I32; case FK_Data_8: llvm_unreachable("FK_Data_8 not implemented yet"); Index: tools/llvm-readobj/WasmDumper.cpp =================================================================== --- tools/llvm-readobj/WasmDumper.cpp +++ tools/llvm-readobj/WasmDumper.cpp @@ -84,6 +84,8 @@ case wasm::R_WEBASSEMBLY_MEMORY_ADDR_LEB: case wasm::R_WEBASSEMBLY_MEMORY_ADDR_SLEB: case wasm::R_WEBASSEMBLY_MEMORY_ADDR_I32: + case wasm::R_WEBASSEMBLY_FUNCTION_OFFSET_I32: + case wasm::R_WEBASSEMBLY_SECTION_OFFSET_I32: HasAddend = true; break; default: Index: tools/obj2yaml/wasm2yaml.cpp =================================================================== --- tools/obj2yaml/wasm2yaml.cpp +++ tools/obj2yaml/wasm2yaml.cpp @@ -102,6 +102,10 @@ case wasm::WASM_SYMBOL_TYPE_GLOBAL: Info.ElementIndex = Symbol.ElementIndex; break; + case wasm::WASM_SYMBOL_TYPE_SECTION: + Info.SectionType = Symbol.SectionCode; + Info.SectionName = Symbol.SectionName; + break; } LinkingSec->SymbolTable.emplace_back(Info); } Index: tools/yaml2obj/yaml2wasm.cpp =================================================================== --- tools/yaml2obj/yaml2wasm.cpp +++ tools/yaml2obj/yaml2wasm.cpp @@ -163,6 +163,11 @@ encodeULEB128(Info.DataRef.Size, SubSection.GetStream()); } break; + case wasm::WASM_SYMBOL_TYPE_SECTION: + encodeULEB128(Info.SectionType, SubSection.GetStream()); + if (Info.SectionType == wasm::WASM_SEC_CUSTOM) + writeStringRef(Info.SectionName, SubSection.GetStream()); + break; default: llvm_unreachable("unexpected kind"); } @@ -421,21 +426,31 @@ int WasmWriter::writeRelocSection(raw_ostream &OS, WasmYAML::Section &Sec) { - StringRef Name; switch (Sec.Type) { case wasm::WASM_SEC_CODE: - Name = "reloc.CODE"; + writeStringRef("reloc.CODE", OS); break; case wasm::WASM_SEC_DATA: - Name = "reloc.DATA"; + writeStringRef("reloc.DATA", OS); break; + case wasm::WASM_SEC_CUSTOM: { + auto CustomSection = dyn_cast(&Sec); + if (!CustomSection->Name.startswith(".debug_")) { + llvm_unreachable("not yet implemented (only for debug sections)"); + return 1; + } + + writeStringRef(("reloc." + CustomSection->Name).str(), OS); + break; + } default: llvm_unreachable("not yet implemented"); return 1; } - writeStringRef(Name, OS); writeUint8(OS, Sec.Type); + if (Sec.Type == wasm::WASM_SEC_CUSTOM) + writeStringRef(dyn_cast(&Sec)->Name, OS); encodeULEB128(Sec.Relocations.size(), OS); for (auto Reloc: Sec.Relocations) { @@ -446,6 +461,8 @@ case wasm::R_WEBASSEMBLY_MEMORY_ADDR_LEB: case wasm::R_WEBASSEMBLY_MEMORY_ADDR_SLEB: case wasm::R_WEBASSEMBLY_MEMORY_ADDR_I32: + case wasm::R_WEBASSEMBLY_FUNCTION_OFFSET_I32: + case wasm::R_WEBASSEMBLY_SECTION_OFFSET_I32: encodeULEB128(Reloc.Addend, OS); } }