summaryrefslogtreecommitdiffstats
path: root/llvm/lib/MC
diff options
context:
space:
mode:
authorSam Clegg <sbc@chromium.org>2017-09-29 16:50:08 +0000
committerSam Clegg <sbc@chromium.org>2017-09-29 16:50:08 +0000
commit63ebb81386393c84d990e5e1bd52938eeb596f47 (patch)
tree95bacc2d0a9e8e1726c580decb1a2b55ccb65e8a /llvm/lib/MC
parent113708b7cb30277a89a4b65d8ae4c8370b6b1841 (diff)
downloadbcm5719-llvm-63ebb81386393c84d990e5e1bd52938eeb596f47.tar.gz
bcm5719-llvm-63ebb81386393c84d990e5e1bd52938eeb596f47.zip
[WebAssembly] Allow each data segment to specify its own alignment
Also, add a flags field as we will almost certainly be needing that soon too. Differential Revision: https://reviews.llvm.org/D38296 llvm-svn: 314534
Diffstat (limited to 'llvm/lib/MC')
-rw-r--r--llvm/lib/MC/WasmObjectWriter.cpp30
1 files changed, 15 insertions, 15 deletions
diff --git a/llvm/lib/MC/WasmObjectWriter.cpp b/llvm/lib/MC/WasmObjectWriter.cpp
index d7a9895af02..af5c1a759c7 100644
--- a/llvm/lib/MC/WasmObjectWriter.cpp
+++ b/llvm/lib/MC/WasmObjectWriter.cpp
@@ -104,6 +104,8 @@ struct WasmDataSegment {
MCSectionWasm *Section;
StringRef Name;
uint32_t Offset;
+ uint32_t Alignment;
+ uint32_t Flags;
SmallVector<char, 4> Data;
};
@@ -282,7 +284,6 @@ private:
void writeDataRelocSection();
void writeLinkingMetaDataSection(
ArrayRef<WasmDataSegment> Segments, uint32_t DataSize,
- uint32_t DataAlignment,
SmallVector<std::pair<StringRef, uint32_t>, 4> SymbolFlags,
bool HasStackPointer, uint32_t StackPointerGlobal);
@@ -499,11 +500,11 @@ WasmObjectWriter::getProvisionalValue(const WasmRelocationEntry &RelEntry) {
}
static void addData(SmallVectorImpl<char> &DataBytes,
- MCSectionWasm &DataSection, uint32_t &DataAlignment) {
- DataBytes.resize(alignTo(DataBytes.size(), DataSection.getAlignment()));
- DataAlignment = std::max(DataAlignment, DataSection.getAlignment());
+ MCSectionWasm &DataSection) {
DEBUG(errs() << "addData: " << DataSection.getSectionName() << "\n");
+ DataBytes.resize(alignTo(DataBytes.size(), DataSection.getAlignment()));
+
for (const MCFragment &Frag : DataSection) {
if (Frag.hasInstructions())
report_fatal_error("only data supported in data sections");
@@ -914,7 +915,6 @@ void WasmObjectWriter::writeDataRelocSection() {
void WasmObjectWriter::writeLinkingMetaDataSection(
ArrayRef<WasmDataSegment> Segments, uint32_t DataSize,
- uint32_t DataAlignment,
SmallVector<std::pair<StringRef, uint32_t>, 4> SymbolFlags,
bool HasStackPointer, uint32_t StackPointerGlobal) {
SectionBookkeeping Section;
@@ -941,17 +941,16 @@ void WasmObjectWriter::writeLinkingMetaDataSection(
startSection(SubSection, wasm::WASM_DATA_SIZE);
encodeULEB128(DataSize, getStream());
endSection(SubSection);
-
- startSection(SubSection, wasm::WASM_DATA_ALIGNMENT);
- encodeULEB128(DataAlignment, getStream());
- endSection(SubSection);
}
if (Segments.size()) {
- startSection(SubSection, wasm::WASM_SEGMENT_NAMES);
+ startSection(SubSection, wasm::WASM_SEGMENT_INFO);
encodeULEB128(Segments.size(), getStream());
- for (const WasmDataSegment &Segment : Segments)
+ for (const WasmDataSegment &Segment : Segments) {
writeString(Segment.Name);
+ encodeULEB128(Segment.Alignment, getStream());
+ encodeULEB128(Segment.Flags, getStream());
+ }
endSection(SubSection);
}
@@ -998,7 +997,6 @@ void WasmObjectWriter::writeObject(MCAssembler &Asm,
SmallPtrSet<const MCSymbolWasm *, 4> IsAddressTaken;
unsigned NumFuncImports = 0;
SmallVector<WasmDataSegment, 4> DataSegments;
- uint32_t DataAlignment = 1;
uint32_t StackPointerGlobal = 0;
uint32_t DataSize = 0;
bool HasStackPointer = false;
@@ -1144,7 +1142,9 @@ void WasmObjectWriter::writeObject(MCAssembler &Asm,
Segment.Name = Section.getSectionName();
Segment.Offset = DataSize;
Segment.Section = &Section;
- addData(Segment.Data, Section, DataAlignment);
+ addData(Segment.Data, Section);
+ Segment.Alignment = Section.getAlignment();
+ Segment.Flags = 0;
DataSize += Segment.Data.size();
Section.setMemoryOffset(Segment.Offset);
}
@@ -1308,8 +1308,8 @@ void WasmObjectWriter::writeObject(MCAssembler &Asm,
writeNameSection(Functions, Imports, NumFuncImports);
writeCodeRelocSection();
writeDataRelocSection();
- writeLinkingMetaDataSection(DataSegments, DataSize, DataAlignment,
- SymbolFlags, HasStackPointer, StackPointerGlobal);
+ writeLinkingMetaDataSection(DataSegments, DataSize, SymbolFlags,
+ HasStackPointer, StackPointerGlobal);
// TODO: Translate the .comment section to the output.
// TODO: Translate debug sections to the output.
OpenPOWER on IntegriCloud