diff options
author | Sam Clegg <sbc@chromium.org> | 2017-06-27 20:27:59 +0000 |
---|---|---|
committer | Sam Clegg <sbc@chromium.org> | 2017-06-27 20:27:59 +0000 |
commit | 9e1ade93a83635da90ff93586a1b9f503be8b8e8 (patch) | |
tree | 8a86cabda57202d4c2b23d83c210a54ad02fcec9 /llvm/lib | |
parent | 25173e4cbab59cb1256ca42c7133e6a973ce358a (diff) | |
download | bcm5719-llvm-9e1ade93a83635da90ff93586a1b9f503be8b8e8.tar.gz bcm5719-llvm-9e1ade93a83635da90ff93586a1b9f503be8b8e8.zip |
[WebAssembly] Add data size and alignement to linking section
The overal size of the data section (including BSS)
is otherwise not included in the wasm binary.
Differential Revision: https://reviews.llvm.org/D34657
llvm-svn: 306459
Diffstat (limited to 'llvm/lib')
-rw-r--r-- | llvm/lib/MC/WasmObjectWriter.cpp | 24 | ||||
-rw-r--r-- | llvm/lib/Object/WasmObjectFile.cpp | 11 | ||||
-rw-r--r-- | llvm/lib/ObjectYAML/WasmYAML.cpp | 2 |
3 files changed, 29 insertions, 8 deletions
diff --git a/llvm/lib/MC/WasmObjectWriter.cpp b/llvm/lib/MC/WasmObjectWriter.cpp index 45534ba1821..82352cb50c7 100644 --- a/llvm/lib/MC/WasmObjectWriter.cpp +++ b/llvm/lib/MC/WasmObjectWriter.cpp @@ -265,7 +265,8 @@ private: uint32_t NumFuncImports); void writeCodeRelocSection(); void writeDataRelocSection(uint64_t DataSectionHeaderSize); - void writeLinkingMetaDataSection(ArrayRef<StringRef> WeakSymbols, + void writeLinkingMetaDataSection(uint32_t DataSize, uint32_t DataAlignment, + ArrayRef<StringRef> WeakSymbols, bool HasStackPointer, uint32_t StackPointerGlobal); @@ -877,11 +878,8 @@ void WasmObjectWriter::writeDataRelocSection(uint64_t DataSectionHeaderSize) { } void WasmObjectWriter::writeLinkingMetaDataSection( - ArrayRef<StringRef> WeakSymbols, bool HasStackPointer, - uint32_t StackPointerGlobal) { - if (!HasStackPointer && WeakSymbols.empty()) - return; - + uint32_t DataSize, uint32_t DataAlignment, ArrayRef<StringRef> WeakSymbols, + bool HasStackPointer, uint32_t StackPointerGlobal) { SectionBookkeeping Section; startSection(Section, wasm::WASM_SEC_CUSTOM, "linking"); SectionBookkeeping SubSection; @@ -902,6 +900,16 @@ void WasmObjectWriter::writeLinkingMetaDataSection( endSection(SubSection); } + if (DataSize > 0) { + startSection(SubSection, wasm::WASM_DATA_SIZE); + encodeULEB128(DataSize, getStream()); + endSection(SubSection); + + startSection(SubSection, wasm::WASM_DATA_ALIGNMENT); + encodeULEB128(DataAlignment, getStream()); + endSection(SubSection); + } + endSection(Section); } @@ -923,6 +931,7 @@ void WasmObjectWriter::writeObject(MCAssembler &Asm, unsigned NumFuncImports = 0; unsigned NumGlobalImports = 0; SmallVector<char, 0> DataBytes; + uint32_t DataAlignment = 1; uint32_t StackPointerGlobal = 0; bool HasStackPointer = false; @@ -1157,6 +1166,7 @@ void WasmObjectWriter::writeObject(MCAssembler &Asm, report_fatal_error("data sections must contain at most one variable"); DataBytes.resize(alignTo(DataBytes.size(), DataSection.getAlignment())); + DataAlignment = std::max(DataAlignment, DataSection.getAlignment()); DataSection.setSectionOffset(DataBytes.size()); @@ -1272,7 +1282,7 @@ void WasmObjectWriter::writeObject(MCAssembler &Asm, writeNameSection(Functions, Imports, NumFuncImports); writeCodeRelocSection(); writeDataRelocSection(DataSectionHeaderSize); - writeLinkingMetaDataSection(WeakSymbols, HasStackPointer, StackPointerGlobal); + writeLinkingMetaDataSection(DataBytes.size(), 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 d15860674ae..e87dd48cb01 100644 --- a/llvm/lib/Object/WasmObjectFile.cpp +++ b/llvm/lib/Object/WasmObjectFile.cpp @@ -193,6 +193,9 @@ static Error readSection(WasmSection &Section, const uint8_t *&Ptr, WasmObjectFile::WasmObjectFile(MemoryBufferRef Buffer, Error &Err) : ObjectFile(Binary::ID_Wasm, Buffer) { + LinkingData.DataAlignment = 0; + LinkingData.DataSize = 0; + ErrorAsOutParameter ErrAsOutParam(&Err); Header.Magic = getData().substr(0, 4); if (Header.Magic != StringRef("\0asm", 4)) { @@ -305,7 +308,7 @@ Error WasmObjectFile::parseLinkingSection(const uint8_t *Ptr, auto iter = SymbolMap.find(Symbol); if (iter == SymbolMap.end()) { return make_error<GenericBinaryError>( - "Invalid symbol name in linking section", + "Invalid symbol name in linking section: " + Symbol, object_error::parse_failed); } uint32_t SymIndex = iter->second; @@ -318,6 +321,12 @@ Error WasmObjectFile::parseLinkingSection(const uint8_t *Ptr, } break; } + case wasm::WASM_DATA_SIZE: + LinkingData.DataSize = readVaruint32(Ptr); + break; + case wasm::WASM_DATA_ALIGNMENT: + LinkingData.DataAlignment = readVaruint32(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 65703c6cf68..11999559d65 100644 --- a/llvm/lib/ObjectYAML/WasmYAML.cpp +++ b/llvm/lib/ObjectYAML/WasmYAML.cpp @@ -56,6 +56,8 @@ static void sectionMapping(IO &IO, WasmYAML::NameSection &Section) { static void sectionMapping(IO &IO, WasmYAML::LinkingSection &Section) { commonSectionMapping(IO, Section); IO.mapRequired("Name", Section.Name); + IO.mapRequired("DataSize", Section.DataSize); + IO.mapRequired("DataAlignment", Section.DataAlignment); IO.mapRequired("SymbolInfo", Section.SymbolInfos); } |