summaryrefslogtreecommitdiffstats
path: root/llvm/lib
diff options
context:
space:
mode:
authorSam Clegg <sbc@chromium.org>2017-12-14 21:10:03 +0000
committerSam Clegg <sbc@chromium.org>2017-12-14 21:10:03 +0000
commit4273998cf9013ce92c7bf1effafef76a65e31d0c (patch)
tree940a95fe5e68525d73669766b55dc1a7c9be7832 /llvm/lib
parentea244bf89b794802a0a5addeed74919a605f8636 (diff)
downloadbcm5719-llvm-4273998cf9013ce92c7bf1effafef76a65e31d0c.tar.gz
bcm5719-llvm-4273998cf9013ce92c7bf1effafef76a65e31d0c.zip
[WebAssembly] Add support for init functions linking metadata
Summary: This change lays the groundwork lowering of @llvm.global_ctors and @llvm.global_dtors for the wasm object format. Some parts of this patch are subset of: https://reviews.llvm.org/D40759 See https://github.com/WebAssembly/tool-conventions/issues/25 Subscribers: jfb, dschuff, jgravelle-google, aheejin, sunfish Differential Revision: https://reviews.llvm.org/D41208 llvm-svn: 320742
Diffstat (limited to 'llvm/lib')
-rw-r--r--llvm/lib/Object/WasmObjectFile.cpp21
-rw-r--r--llvm/lib/ObjectYAML/WasmYAML.cpp7
2 files changed, 27 insertions, 1 deletions
diff --git a/llvm/lib/Object/WasmObjectFile.cpp b/llvm/lib/Object/WasmObjectFile.cpp
index 8d4c15abc7f..677fccc6299 100644
--- a/llvm/lib/Object/WasmObjectFile.cpp
+++ b/llvm/lib/Object/WasmObjectFile.cpp
@@ -398,6 +398,21 @@ Error WasmObjectFile::parseLinkingSection(const uint8_t *Ptr,
}
break;
}
+ case wasm::WASM_INIT_FUNCS: {
+ uint32_t Count = readVaruint32(Ptr);
+ LinkingData.InitFunctions.reserve(Count);
+ for (uint32_t i = 0; i < Count; i++) {
+ wasm::WasmInitFunc Init;
+ Init.Priority = readVaruint32(Ptr);
+ Init.FunctionIndex = readVaruint32(Ptr);
+ if (!isValidFunctionIndex(Init.FunctionIndex))
+ return make_error<GenericBinaryError>("Invalid function index: " +
+ Twine(Init.FunctionIndex),
+ object_error::parse_failed);
+ LinkingData.InitFunctions.emplace_back(Init);
+ }
+ break;
+ }
default:
Ptr += Size;
break;
@@ -656,9 +671,13 @@ Error WasmObjectFile::parseExportSection(const uint8_t *Ptr, const uint8_t *End)
return Error::success();
}
+bool WasmObjectFile::isValidFunctionIndex(uint32_t Index) const {
+ return Index < FunctionTypes.size() + NumImportedFunctions;
+}
+
Error WasmObjectFile::parseStartSection(const uint8_t *Ptr, const uint8_t *End) {
StartFunction = readVaruint32(Ptr);
- if (StartFunction >= FunctionTypes.size())
+ if (!isValidFunctionIndex(StartFunction))
return make_error<GenericBinaryError>("Invalid start function",
object_error::parse_failed);
return Error::success();
diff --git a/llvm/lib/ObjectYAML/WasmYAML.cpp b/llvm/lib/ObjectYAML/WasmYAML.cpp
index c206a682b83..8687f22949a 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.mapOptional("SymbolInfo", Section.SymbolInfos);
IO.mapOptional("SegmentInfo", Section.SegmentInfos);
+ IO.mapOptional("InitFunctions", Section.InitFunctions);
}
static void sectionMapping(IO &IO, WasmYAML::CustomSection &Section) {
@@ -359,6 +360,12 @@ void MappingTraits<WasmYAML::DataSegment>::mapping(
IO.mapRequired("Content", Segment.Content);
}
+void MappingTraits<WasmYAML::InitFunction>::mapping(
+ IO &IO, WasmYAML::InitFunction &Init) {
+ IO.mapRequired("Priority", Init.Priority);
+ IO.mapRequired("FunctionIndex", Init.FunctionIndex);
+}
+
void MappingTraits<WasmYAML::SymbolInfo>::mapping(IO &IO,
WasmYAML::SymbolInfo &Info) {
IO.mapRequired("Name", Info.Name);
OpenPOWER on IntegriCloud