diff options
Diffstat (limited to 'llvm/lib')
| -rw-r--r-- | llvm/lib/CodeGen/TargetLoweringObjectFileImpl.cpp | 17 | ||||
| -rw-r--r-- | llvm/lib/MC/MCParser/WasmAsmParser.cpp | 46 | ||||
| -rw-r--r-- | llvm/lib/MC/MCSectionWasm.cpp | 3 | ||||
| -rw-r--r-- | llvm/lib/MC/WasmObjectWriter.cpp | 20 | ||||
| -rw-r--r-- | llvm/lib/Object/WasmObjectFile.cpp | 17 | ||||
| -rw-r--r-- | llvm/lib/ObjectYAML/WasmYAML.cpp | 14 | ||||
| -rw-r--r-- | llvm/lib/Target/WebAssembly/WebAssemblyAsmPrinter.cpp | 1 |
7 files changed, 97 insertions, 21 deletions
diff --git a/llvm/lib/CodeGen/TargetLoweringObjectFileImpl.cpp b/llvm/lib/CodeGen/TargetLoweringObjectFileImpl.cpp index a7cdcee8cd6..c50c6476ec5 100644 --- a/llvm/lib/CodeGen/TargetLoweringObjectFileImpl.cpp +++ b/llvm/lib/CodeGen/TargetLoweringObjectFileImpl.cpp @@ -1693,8 +1693,14 @@ MCSection *TargetLoweringObjectFileWasm::getExplicitSectionGlobal( Group = C->getName(); } - return getContext().getWasmSection(Name, Kind, Group, - MCContext::GenericSectionID); + MCSectionWasm* Section = + getContext().getWasmSection(Name, Kind, Group, + MCContext::GenericSectionID); + + if (TM.Options.ThreadModel != ThreadModel::Single) + Section->setPassive(); + + return Section; } static MCSectionWasm *selectWasmSectionForGlobal( @@ -1723,7 +1729,12 @@ static MCSectionWasm *selectWasmSectionForGlobal( UniqueID = *NextUniqueID; (*NextUniqueID)++; } - return Ctx.getWasmSection(Name, Kind, Group, UniqueID); + + MCSectionWasm* Section = Ctx.getWasmSection(Name, Kind, Group, UniqueID); + if (Section->isWasmData() && TM.Options.ThreadModel != ThreadModel::Single) + Section->setPassive(); + + return Section; } MCSection *TargetLoweringObjectFileWasm::SelectSectionForGlobal( diff --git a/llvm/lib/MC/MCParser/WasmAsmParser.cpp b/llvm/lib/MC/MCParser/WasmAsmParser.cpp index 17d86aa0d64..a8a48d1cd69 100644 --- a/llvm/lib/MC/MCParser/WasmAsmParser.cpp +++ b/llvm/lib/MC/MCParser/WasmAsmParser.cpp @@ -81,13 +81,53 @@ public: return false; } + bool parseSectionFlags(StringRef FlagStr, bool &Passive) { + SmallVector<StringRef, 2> Flags; + // If there are no flags, keep Flags empty + FlagStr.split(Flags, ",", -1, false); + for (auto &Flag : Flags) { + if (Flag == "passive") + Passive = true; + else + return error("Expected section flags, instead got: ", Lexer->getTok()); + } + return false; + } + bool parseSectionDirective(StringRef, SMLoc) { StringRef Name; if (Parser->parseIdentifier(Name)) return TokError("expected identifier in directive"); - // FIXME: currently requiring this very fixed format. - if (expect(AsmToken::Comma, ",") || expect(AsmToken::String, "string") || - expect(AsmToken::Comma, ",") || expect(AsmToken::At, "@") || + + if (expect(AsmToken::Comma, ",")) + return true; + + if (Lexer->isNot(AsmToken::String)) + return error("expected string in directive, instead got: ", Lexer->getTok()); + + SectionKind Kind = StringSwitch<SectionKind>(Name) + .StartsWith(".data", SectionKind::getData()) + .StartsWith(".rodata", SectionKind::getReadOnly()) + .StartsWith(".text", SectionKind::getText()) + .StartsWith(".custom_section", SectionKind::getMetadata()); + + MCSectionWasm* Section = getContext().getWasmSection(Name, Kind); + + // Update section flags if present in this .section directive + bool Passive = false; + if (parseSectionFlags(getTok().getStringContents(), Passive)) + return true; + + if (Passive) { + if (!Section->isWasmData()) + return Parser->Error(getTok().getLoc(), + "Only data sections can be passive"); + Section->setPassive(); + } + + Lex(); + + if (expect(AsmToken::Comma, ",") || expect(AsmToken::At, "@") || expect(AsmToken::EndOfStatement, "eol")) return true; // This is done automatically by the assembler for text sections currently, diff --git a/llvm/lib/MC/MCSectionWasm.cpp b/llvm/lib/MC/MCSectionWasm.cpp index 164ded9a1f8..8633c10a73f 100644 --- a/llvm/lib/MC/MCSectionWasm.cpp +++ b/llvm/lib/MC/MCSectionWasm.cpp @@ -62,7 +62,8 @@ void MCSectionWasm::PrintSwitchToSection(const MCAsmInfo &MAI, const Triple &T, printName(OS, getSectionName()); OS << ",\""; - // TODO: Print section flags. + if (IsPassive) + OS << "passive"; OS << '"'; diff --git a/llvm/lib/MC/WasmObjectWriter.cpp b/llvm/lib/MC/WasmObjectWriter.cpp index 600928c05bc..10f16ba3c8f 100644 --- a/llvm/lib/MC/WasmObjectWriter.cpp +++ b/llvm/lib/MC/WasmObjectWriter.cpp @@ -106,9 +106,10 @@ struct WasmSignatureDenseMapInfo { struct WasmDataSegment { MCSectionWasm *Section; StringRef Name; + uint32_t InitFlags; uint32_t Offset; uint32_t Alignment; - uint32_t Flags; + uint32_t LinkerFlags; SmallVector<char, 4> Data; }; @@ -899,10 +900,14 @@ void WasmObjectWriter::writeDataSection() { encodeULEB128(DataSegments.size(), W.OS); // count for (const WasmDataSegment &Segment : DataSegments) { - encodeULEB128(0, W.OS); // memory index - W.OS << char(wasm::WASM_OPCODE_I32_CONST); - encodeSLEB128(Segment.Offset, W.OS); // offset - W.OS << char(wasm::WASM_OPCODE_END); + encodeULEB128(Segment.InitFlags, W.OS); // flags + if (Segment.InitFlags & wasm::WASM_SEGMENT_HAS_MEMINDEX) + encodeULEB128(0, W.OS); // memory index + if ((Segment.InitFlags & wasm::WASM_SEGMENT_IS_PASSIVE) == 0) { + W.OS << char(wasm::WASM_OPCODE_I32_CONST); + encodeSLEB128(Segment.Offset, W.OS); // offset + W.OS << char(wasm::WASM_OPCODE_END); + } encodeULEB128(Segment.Data.size(), W.OS); // size Segment.Section->setSectionOffset(W.OS.tell() - Section.ContentsOffset); W.OS << Segment.Data; // data @@ -1013,7 +1018,7 @@ void WasmObjectWriter::writeLinkingMetaDataSection( for (const WasmDataSegment &Segment : DataSegments) { writeString(Segment.Name); encodeULEB128(Segment.Alignment, W.OS); - encodeULEB128(Segment.Flags, W.OS); + encodeULEB128(Segment.LinkerFlags, W.OS); } endSection(SubSection); } @@ -1253,11 +1258,12 @@ uint64_t WasmObjectWriter::writeObject(MCAssembler &Asm, DataSegments.emplace_back(); WasmDataSegment &Segment = DataSegments.back(); Segment.Name = SectionName; + Segment.InitFlags = Section.getPassive() ? wasm::WASM_SEGMENT_IS_PASSIVE : 0; Segment.Offset = DataSize; Segment.Section = &Section; addData(Segment.Data, Section); Segment.Alignment = Log2_32(Section.getAlignment()); - Segment.Flags = 0; + Segment.LinkerFlags = 0; DataSize += Segment.Data.size(); Section.setSegmentIndex(SegmentIndex); diff --git a/llvm/lib/Object/WasmObjectFile.cpp b/llvm/lib/Object/WasmObjectFile.cpp index e5b6a9b6e35..5a41ca3a89f 100644 --- a/llvm/lib/Object/WasmObjectFile.cpp +++ b/llvm/lib/Object/WasmObjectFile.cpp @@ -421,7 +421,7 @@ Error WasmObjectFile::parseLinkingSection(ReadContext &Ctx) { for (uint32_t I = 0; I < Count; I++) { DataSegments[I].Data.Name = readString(Ctx); DataSegments[I].Data.Alignment = readVaruint32(Ctx); - DataSegments[I].Data.Flags = readVaruint32(Ctx); + DataSegments[I].Data.LinkerFlags = readVaruint32(Ctx); } break; } @@ -1164,9 +1164,16 @@ Error WasmObjectFile::parseDataSection(ReadContext &Ctx) { DataSegments.reserve(Count); while (Count--) { WasmSegment Segment; - Segment.Data.MemoryIndex = readVaruint32(Ctx); - if (Error Err = readInitExpr(Segment.Data.Offset, Ctx)) - return Err; + Segment.Data.InitFlags = readVaruint32(Ctx); + Segment.Data.MemoryIndex = (Segment.Data.InitFlags & wasm::WASM_SEGMENT_HAS_MEMINDEX) + ? readVaruint32(Ctx) : 0; + if ((Segment.Data.InitFlags & wasm::WASM_SEGMENT_IS_PASSIVE) == 0) { + if (Error Err = readInitExpr(Segment.Data.Offset, Ctx)) + return Err; + } else { + Segment.Data.Offset.Opcode = wasm::WASM_OPCODE_I32_CONST; + Segment.Data.Offset.Value.Int32 = 0; + } uint32_t Size = readVaruint32(Ctx); if (Size > (size_t)(Ctx.End - Ctx.Ptr)) return make_error<GenericBinaryError>("Invalid segment size", @@ -1175,7 +1182,7 @@ Error WasmObjectFile::parseDataSection(ReadContext &Ctx) { // The rest of these Data fields are set later, when reading in the linking // metadata section. Segment.Data.Alignment = 0; - Segment.Data.Flags = 0; + Segment.Data.LinkerFlags = 0; Segment.Data.Comdat = UINT32_MAX; Segment.SectionOffset = Ctx.Ptr - Ctx.Start; Ctx.Ptr += Size; diff --git a/llvm/lib/ObjectYAML/WasmYAML.cpp b/llvm/lib/ObjectYAML/WasmYAML.cpp index def4d58a101..1865dcf7aa6 100644 --- a/llvm/lib/ObjectYAML/WasmYAML.cpp +++ b/llvm/lib/ObjectYAML/WasmYAML.cpp @@ -403,8 +403,18 @@ void MappingTraits<wasm::WasmInitExpr>::mapping(IO &IO, void MappingTraits<WasmYAML::DataSegment>::mapping( IO &IO, WasmYAML::DataSegment &Segment) { IO.mapOptional("SectionOffset", Segment.SectionOffset); - IO.mapRequired("MemoryIndex", Segment.MemoryIndex); - IO.mapRequired("Offset", Segment.Offset); + IO.mapRequired("InitFlags", Segment.InitFlags); + if (Segment.InitFlags & wasm::WASM_SEGMENT_HAS_MEMINDEX) { + IO.mapRequired("MemoryIndex", Segment.MemoryIndex); + } else { + Segment.MemoryIndex = 0; + } + if ((Segment.InitFlags & wasm::WASM_SEGMENT_IS_PASSIVE) == 0) { + IO.mapRequired("Offset", Segment.Offset); + } else { + Segment.Offset.Opcode = wasm::WASM_OPCODE_I32_CONST; + Segment.Offset.Value.Int32 = 0; + } IO.mapRequired("Content", Segment.Content); } diff --git a/llvm/lib/Target/WebAssembly/WebAssemblyAsmPrinter.cpp b/llvm/lib/Target/WebAssembly/WebAssemblyAsmPrinter.cpp index 563c7cc203d..18ec2c273ec 100644 --- a/llvm/lib/Target/WebAssembly/WebAssemblyAsmPrinter.cpp +++ b/llvm/lib/Target/WebAssembly/WebAssemblyAsmPrinter.cpp @@ -39,6 +39,7 @@ #include "llvm/Support/Debug.h" #include "llvm/Support/TargetRegistry.h" #include "llvm/Support/raw_ostream.h" + using namespace llvm; #define DEBUG_TYPE "asm-printer" |

