diff options
author | Thomas Lively <tlively@google.com> | 2019-01-16 23:46:14 +0000 |
---|---|---|
committer | Thomas Lively <tlively@google.com> | 2019-01-16 23:46:14 +0000 |
commit | a56c23c5ba561126f64488fbda0566fc92c26e58 (patch) | |
tree | 33176c5c495f6c9e88bdd6c4dd68bae8dac3d080 /llvm/lib/MC/WasmObjectWriter.cpp | |
parent | c7700127ae79dec3b6fe0c1773824da56352e194 (diff) | |
download | bcm5719-llvm-a56c23c5ba561126f64488fbda0566fc92c26e58.tar.gz bcm5719-llvm-a56c23c5ba561126f64488fbda0566fc92c26e58.zip |
[WebAssembly] Parse llvm.ident into producers section
Summary:
Everything before the word "version" is the tool, and everything after
the word "version" is the version.
Reviewers: aheejin, dschuff
Subscribers: sbc100, jgravelle-google, sunfish, llvm-commits
Differential Revision: https://reviews.llvm.org/D56742
llvm-svn: 351399
Diffstat (limited to 'llvm/lib/MC/WasmObjectWriter.cpp')
-rw-r--r-- | llvm/lib/MC/WasmObjectWriter.cpp | 47 |
1 files changed, 30 insertions, 17 deletions
diff --git a/llvm/lib/MC/WasmObjectWriter.cpp b/llvm/lib/MC/WasmObjectWriter.cpp index 0cca3757be9..8e45b2f3e0c 100644 --- a/llvm/lib/MC/WasmObjectWriter.cpp +++ b/llvm/lib/MC/WasmObjectWriter.cpp @@ -224,6 +224,7 @@ class WasmObjectWriter : public MCObjectWriter { // Stores output data (index, relocations, content offset) for custom // section. std::vector<WasmCustomSection> CustomSections; + std::unique_ptr<WasmCustomSection> ProducersSection; // Relocations for fixing up references in the custom sections. DenseMap<const MCSectionWasm *, std::vector<WasmRelocationEntry>> CustomSectionsRelocations; @@ -265,6 +266,8 @@ private: WasmIndices.clear(); TableIndices.clear(); DataLocations.clear(); + CustomSections.clear(); + ProducersSection.reset(); CustomSectionsRelocations.clear(); SignatureIndices.clear(); Signatures.clear(); @@ -311,7 +314,8 @@ private: ArrayRef<wasm::WasmSymbolInfo> SymbolInfos, ArrayRef<std::pair<uint16_t, uint32_t>> InitFuncs, const std::map<StringRef, std::vector<WasmComdatEntry>> &Comdats); - void writeCustomSections(const MCAssembler &Asm, const MCAsmLayout &Layout); + void writeCustomSection(WasmCustomSection &CustomSection, + const MCAssembler &Asm, const MCAsmLayout &Layout); void writeCustomRelocSections(); void updateCustomSectionRelocations(const SmallVector<WasmFunction, 4> &Functions, @@ -1045,25 +1049,24 @@ void WasmObjectWriter::writeLinkingMetaDataSection( endSection(Section); } -void WasmObjectWriter::writeCustomSections(const MCAssembler &Asm, - const MCAsmLayout &Layout) { - for (auto &CustomSection : CustomSections) { - SectionBookkeeping Section; - auto *Sec = CustomSection.Section; - startCustomSection(Section, CustomSection.Name); +void WasmObjectWriter::writeCustomSection(WasmCustomSection &CustomSection, + const MCAssembler &Asm, + const MCAsmLayout &Layout) { + SectionBookkeeping Section; + auto *Sec = CustomSection.Section; + startCustomSection(Section, CustomSection.Name); - 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; + CustomSection.OutputContentsOffset = Section.ContentsOffset; + CustomSection.OutputIndex = Section.Index; - endSection(Section); + endSection(Section); - // Apply fixups. - auto &Relocations = CustomSectionsRelocations[CustomSection.Section]; - applyRelocations(Relocations, CustomSection.OutputContentsOffset); - } + // Apply fixups. + auto &Relocations = CustomSectionsRelocations[CustomSection.Section]; + applyRelocations(Relocations, CustomSection.OutputContentsOffset); } uint32_t WasmObjectWriter::getFunctionType(const MCSymbolWasm &Symbol) { @@ -1282,6 +1285,13 @@ uint64_t WasmObjectWriter::writeObject(MCAssembler &Asm, report_fatal_error("section name and begin symbol should match: " + Twine(SectionName)); } + + // Separate out the producers section + if (Name == "producers") { + ProducersSection = llvm::make_unique<WasmCustomSection>(Name, &Section); + continue; + } + CustomSections.emplace_back(Name, &Section); } } @@ -1570,11 +1580,14 @@ uint64_t WasmObjectWriter::writeObject(MCAssembler &Asm, writeElemSection(TableElems); writeCodeSection(Asm, Layout, Functions); writeDataSection(); - writeCustomSections(Asm, Layout); + for (auto &CustomSection : CustomSections) + writeCustomSection(CustomSection, Asm, Layout); writeLinkingMetaDataSection(SymbolInfos, InitFuncs, Comdats); writeRelocSection(CodeSectionIndex, "CODE", CodeRelocations); writeRelocSection(DataSectionIndex, "DATA", DataRelocations); writeCustomRelocSections(); + if (ProducersSection) + writeCustomSection(*ProducersSection, Asm, Layout); // TODO: Translate the .comment section to the output. return W.OS.tell() - StartOffset; |