-
Notifications
You must be signed in to change notification settings - Fork 15.6k
[MC][WebAssembly] Fix importing tables with limits #172992
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -323,8 +323,8 @@ class WasmObjectWriter : public MCObjectWriter { | |
| void writeValueType(wasm::ValType Ty) { W->OS << static_cast<char>(Ty); } | ||
|
|
||
| void writeTypeSection(ArrayRef<wasm::WasmSignature> Signatures); | ||
| void writeImportSection(ArrayRef<wasm::WasmImport> Imports, uint64_t DataSize, | ||
| uint32_t NumElements); | ||
| void writeImportSection(ArrayRef<wasm::WasmImport> Imports, | ||
| uint64_t DataSize); | ||
| void writeFunctionSection(ArrayRef<WasmFunction> Functions); | ||
| void writeExportSection(ArrayRef<wasm::WasmExport> Exports); | ||
| void writeElemSection(const MCSymbolWasm *IndirectFunctionTable, | ||
|
|
@@ -823,8 +823,7 @@ void WasmObjectWriter::writeTypeSection( | |
| } | ||
|
|
||
| void WasmObjectWriter::writeImportSection(ArrayRef<wasm::WasmImport> Imports, | ||
| uint64_t DataSize, | ||
| uint32_t NumElements) { | ||
| uint64_t DataSize) { | ||
| if (Imports.empty()) | ||
| return; | ||
|
|
||
|
|
@@ -855,7 +854,9 @@ void WasmObjectWriter::writeImportSection(ArrayRef<wasm::WasmImport> Imports, | |
| case wasm::WASM_EXTERNAL_TABLE: | ||
| W->OS << char(Import.Table.ElemType); | ||
| encodeULEB128(Import.Table.Limits.Flags, W->OS); | ||
| encodeULEB128(NumElements, W->OS); // initial | ||
| encodeULEB128(Import.Table.Limits.Minimum, W->OS); | ||
| if (Import.Table.Limits.Flags & wasm::WASM_LIMITS_FLAG_HAS_MAX) | ||
| encodeULEB128(Import.Table.Limits.Maximum, W->OS); | ||
| break; | ||
| case wasm::WASM_EXTERNAL_TAG: | ||
| W->OS << char(0); // Reserved 'attribute' field | ||
|
|
@@ -1849,6 +1850,15 @@ uint64_t WasmObjectWriter::writeOneObject(MCAssembler &Asm, | |
| HandleReloc(RelEntry); | ||
| for (const WasmRelocationEntry &RelEntry : DataRelocations) | ||
| HandleReloc(RelEntry); | ||
|
|
||
| // Update minimum size of `__indirect_function_table` table. | ||
| auto It = llvm::find_if(Imports, [](const wasm::WasmImport &I) { | ||
| return I.Field == "__indirect_function_table"; | ||
| }); | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We already lookup this symbol in other places in this file with
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. No, because they are looking it up in a different table, not in |
||
|
|
||
| if (It != Imports.end()) { | ||
| It->Table.Limits.Minimum = TableElems.size(); | ||
| } | ||
| } | ||
|
|
||
| // Translate .init_array section contents into start functions. | ||
|
|
@@ -1901,7 +1911,7 @@ uint64_t WasmObjectWriter::writeOneObject(MCAssembler &Asm, | |
| uint32_t CodeSectionIndex, DataSectionIndex; | ||
| if (Mode != DwoMode::DwoOnly) { | ||
| writeTypeSection(Signatures); | ||
| writeImportSection(Imports, DataSize, TableElems.size()); | ||
| writeImportSection(Imports, DataSize); | ||
| writeFunctionSection(Functions); | ||
| writeTableSection(Tables); | ||
| // Skip the "memory" section; we import the memory instead. | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.