diff options
author | Sam Clegg <sbc@chromium.org> | 2017-09-20 19:03:35 +0000 |
---|---|---|
committer | Sam Clegg <sbc@chromium.org> | 2017-09-20 19:03:35 +0000 |
commit | d95ed959d8ab270808aeec8b31f06140e68834ea (patch) | |
tree | 989216a22660bb777d0fcff71cbc4540067b80ed /llvm/lib | |
parent | 01a409520b39946bd4c7e86f83bc2d01d8c839d4 (diff) | |
download | bcm5719-llvm-d95ed959d8ab270808aeec8b31f06140e68834ea.tar.gz bcm5719-llvm-d95ed959d8ab270808aeec8b31f06140e68834ea.zip |
Reland "[WebAssembly] Add support for naming wasm data segments"
Add adds support for naming data segments. This is useful
useful linkers so that they can merge similar sections.
Differential Revision: https://reviews.llvm.org/D37886
llvm-svn: 313795
Diffstat (limited to 'llvm/lib')
-rw-r--r-- | llvm/lib/MC/WasmObjectWriter.cpp | 19 | ||||
-rw-r--r-- | llvm/lib/Object/WasmObjectFile.cpp | 9 | ||||
-rw-r--r-- | llvm/lib/ObjectYAML/WasmYAML.cpp | 1 |
3 files changed, 26 insertions, 3 deletions
diff --git a/llvm/lib/MC/WasmObjectWriter.cpp b/llvm/lib/MC/WasmObjectWriter.cpp index 7ed20d32fd2..6ec93246c06 100644 --- a/llvm/lib/MC/WasmObjectWriter.cpp +++ b/llvm/lib/MC/WasmObjectWriter.cpp @@ -102,6 +102,7 @@ struct WasmFunctionTypeDenseMapInfo { // wasm data segment. struct WasmDataSegment { MCSectionWasm *Section; + StringRef Name; uint32_t Offset; SmallVector<char, 4> Data; }; @@ -279,7 +280,8 @@ private: uint32_t NumFuncImports); void writeCodeRelocSection(); void writeDataRelocSection(); - void writeLinkingMetaDataSection(uint32_t DataSize, uint32_t DataAlignment, + void writeLinkingMetaDataSection(ArrayRef<WasmDataSegment> Segments, + uint32_t DataSize, uint32_t DataAlignment, ArrayRef<StringRef> WeakSymbols, bool HasStackPointer, uint32_t StackPointerGlobal); @@ -911,7 +913,8 @@ void WasmObjectWriter::writeDataRelocSection() { } void WasmObjectWriter::writeLinkingMetaDataSection( - uint32_t DataSize, uint32_t DataAlignment, ArrayRef<StringRef> WeakSymbols, + ArrayRef<WasmDataSegment> Segments, uint32_t DataSize, + uint32_t DataAlignment, ArrayRef<StringRef> WeakSymbols, bool HasStackPointer, uint32_t StackPointerGlobal) { SectionBookkeeping Section; startSection(Section, wasm::WASM_SEC_CUSTOM, "linking"); @@ -943,6 +946,14 @@ void WasmObjectWriter::writeLinkingMetaDataSection( endSection(SubSection); } + if (Segments.size()) { + startSection(SubSection, wasm::WASM_SEGMENT_NAMES); + encodeULEB128(Segments.size(), getStream()); + for (const WasmDataSegment &Segment : Segments) + writeString(Segment.Name); + endSection(SubSection); + } + endSection(Section); } @@ -1129,6 +1140,7 @@ void WasmObjectWriter::writeObject(MCAssembler &Asm, DataSize = alignTo(DataSize, Section.getAlignment()); DataSegments.emplace_back(); WasmDataSegment &Segment = DataSegments.back(); + Segment.Name = Section.getSectionName(); Segment.Offset = DataSize; Segment.Section = &Section; addData(Segment.Data, Section, DataAlignment); @@ -1288,7 +1300,8 @@ void WasmObjectWriter::writeObject(MCAssembler &Asm, writeNameSection(Functions, Imports, NumFuncImports); writeCodeRelocSection(); writeDataRelocSection(); - writeLinkingMetaDataSection(DataSize, DataAlignment, WeakSymbols, HasStackPointer, StackPointerGlobal); + writeLinkingMetaDataSection(DataSegments, DataSize, DataAlignment, + WeakSymbols, HasStackPointer, StackPointerGlobal); // TODO: Translate the .comment section to the output. // TODO: Translate debug sections to the output. diff --git a/llvm/lib/Object/WasmObjectFile.cpp b/llvm/lib/Object/WasmObjectFile.cpp index bd51fbdac0b..d2d3aba0396 100644 --- a/llvm/lib/Object/WasmObjectFile.cpp +++ b/llvm/lib/Object/WasmObjectFile.cpp @@ -396,6 +396,15 @@ Error WasmObjectFile::parseLinkingSection(const uint8_t *Ptr, case wasm::WASM_DATA_ALIGNMENT: LinkingData.DataAlignment = readVaruint32(Ptr); break; + case wasm::WASM_SEGMENT_NAMES: { + uint32_t Count = readVaruint32(Ptr); + if (Count > DataSegments.size()) + return make_error<GenericBinaryError>("Too many segment names", + object_error::parse_failed); + for (uint32_t i = 0; i < Count; i++) + DataSegments[i].Data.Name = readString(Ptr); + break; + } case wasm::WASM_STACK_POINTER: default: Ptr += Size; diff --git a/llvm/lib/ObjectYAML/WasmYAML.cpp b/llvm/lib/ObjectYAML/WasmYAML.cpp index 8aea8cfb4bc..a5c1d13598c 100644 --- a/llvm/lib/ObjectYAML/WasmYAML.cpp +++ b/llvm/lib/ObjectYAML/WasmYAML.cpp @@ -60,6 +60,7 @@ static void sectionMapping(IO &IO, WasmYAML::LinkingSection &Section) { IO.mapRequired("DataSize", Section.DataSize); IO.mapRequired("DataAlignment", Section.DataAlignment); IO.mapOptional("SymbolInfo", Section.SymbolInfos); + IO.mapOptional("SegmentNames", Section.SegmentNames); } static void sectionMapping(IO &IO, WasmYAML::CustomSection &Section) { |