aboutsummaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
Diffstat (limited to 'lib')
-rw-r--r--lib/Object/WasmObjectFile.cpp21
-rw-r--r--lib/ObjectYAML/WasmYAML.cpp7
2 files changed, 27 insertions, 1 deletions
diff --git a/lib/Object/WasmObjectFile.cpp b/lib/Object/WasmObjectFile.cpp
index 8d4c15abc7f..677fccc6299 100644
--- a/lib/Object/WasmObjectFile.cpp
+++ b/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/lib/ObjectYAML/WasmYAML.cpp b/lib/ObjectYAML/WasmYAML.cpp
index c206a682b83..8687f22949a 100644
--- a/lib/ObjectYAML/WasmYAML.cpp
+++ b/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);