summaryrefslogtreecommitdiff
path: root/lib/Object/WasmObjectFile.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'lib/Object/WasmObjectFile.cpp')
-rw-r--r--lib/Object/WasmObjectFile.cpp40
1 files changed, 26 insertions, 14 deletions
diff --git a/lib/Object/WasmObjectFile.cpp b/lib/Object/WasmObjectFile.cpp
index fff497ba55647..7f80bf0b83a0a 100644
--- a/lib/Object/WasmObjectFile.cpp
+++ b/lib/Object/WasmObjectFile.cpp
@@ -567,20 +567,16 @@ Error WasmObjectFile::parseExportSection(const uint8_t *Ptr, const uint8_t *End)
Ex.Name = readString(Ptr);
Ex.Kind = readUint8(Ptr);
Ex.Index = readVaruint32(Ptr);
+ WasmSymbol::SymbolType ExportType;
+ bool MakeSymbol = false;
switch (Ex.Kind) {
case wasm::WASM_EXTERNAL_FUNCTION:
- SymbolMap.try_emplace(Ex.Name, Symbols.size());
- Symbols.emplace_back(Ex.Name, WasmSymbol::SymbolType::FUNCTION_EXPORT,
- Sections.size(), i);
- DEBUG(dbgs() << "Adding export: " << Symbols.back()
- << " sym index:" << Symbols.size() << "\n");
+ ExportType = WasmSymbol::SymbolType::FUNCTION_EXPORT;
+ MakeSymbol = true;
break;
case wasm::WASM_EXTERNAL_GLOBAL:
- SymbolMap.try_emplace(Ex.Name, Symbols.size());
- Symbols.emplace_back(Ex.Name, WasmSymbol::SymbolType::GLOBAL_EXPORT,
- Sections.size(), i);
- DEBUG(dbgs() << "Adding export: " << Symbols.back()
- << " sym index:" << Symbols.size() << "\n");
+ ExportType = WasmSymbol::SymbolType::GLOBAL_EXPORT;
+ MakeSymbol = true;
break;
case wasm::WASM_EXTERNAL_MEMORY:
case wasm::WASM_EXTERNAL_TABLE:
@@ -589,6 +585,20 @@ Error WasmObjectFile::parseExportSection(const uint8_t *Ptr, const uint8_t *End)
return make_error<GenericBinaryError>(
"Unexpected export kind", object_error::parse_failed);
}
+ if (MakeSymbol) {
+ auto Pair = SymbolMap.try_emplace(Ex.Name, Symbols.size());
+ if (Pair.second) {
+ Symbols.emplace_back(Ex.Name, ExportType,
+ Sections.size(), i);
+ DEBUG(dbgs() << "Adding export: " << Symbols.back()
+ << " sym index:" << Symbols.size() << "\n");
+ } else {
+ uint32_t SymIndex = Pair.first->second;
+ Symbols[SymIndex] = WasmSymbol(Ex.Name, ExportType, Sections.size(), i);
+ DEBUG(dbgs() << "Replacing existing symbol: " << Symbols[SymIndex]
+ << " sym index:" << SymIndex << "\n");
+ }
+ }
Exports.push_back(Ex);
}
if (Ptr != End)
@@ -665,15 +675,17 @@ Error WasmObjectFile::parseElemSection(const uint8_t *Ptr, const uint8_t *End) {
}
Error WasmObjectFile::parseDataSection(const uint8_t *Ptr, const uint8_t *End) {
+ const uint8_t *Start = Ptr;
uint32_t Count = readVaruint32(Ptr);
DataSegments.reserve(Count);
while (Count--) {
- wasm::WasmDataSegment Segment;
- Segment.Index = readVaruint32(Ptr);
- if (Error Err = readInitExpr(Segment.Offset, Ptr))
+ WasmSegment Segment;
+ Segment.Data.MemoryIndex = readVaruint32(Ptr);
+ if (Error Err = readInitExpr(Segment.Data.Offset, Ptr))
return Err;
uint32_t Size = readVaruint32(Ptr);
- Segment.Content = ArrayRef<uint8_t>(Ptr, Size);
+ Segment.Data.Content = ArrayRef<uint8_t>(Ptr, Size);
+ Segment.SectionOffset = Ptr - Start;
Ptr += Size;
DataSegments.push_back(Segment);
}