summaryrefslogtreecommitdiffstats
path: root/llvm/lib/MC
diff options
context:
space:
mode:
authorSam Clegg <sbc@chromium.org>2017-09-19 23:00:57 +0000
committerSam Clegg <sbc@chromium.org>2017-09-19 23:00:57 +0000
commitb292c259665df700442f47f430d0e4b4edd818cb (patch)
tree9f1cdf736c1460806311eca8b11e7bd436192b4a /llvm/lib/MC
parent15fccf00097dd5b07710539fb4e3ff68c50f44de (diff)
downloadbcm5719-llvm-b292c259665df700442f47f430d0e4b4edd818cb.tar.gz
bcm5719-llvm-b292c259665df700442f47f430d0e4b4edd818cb.zip
[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: 313692
Diffstat (limited to 'llvm/lib/MC')
-rw-r--r--llvm/lib/MC/WasmObjectWriter.cpp19
1 files changed, 16 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.
OpenPOWER on IntegriCloud