Skip to content

Add IMPORTED_TABLE setting#26228

Open
hoodmane wants to merge 7 commits intoemscripten-core:mainfrom
hoodmane:imported-table
Open

Add IMPORTED_TABLE setting#26228
hoodmane wants to merge 7 commits intoemscripten-core:mainfrom
hoodmane:imported-table

Conversation

@hoodmane
Copy link
Collaborator

@hoodmane hoodmane commented Feb 8, 2026

Also, RELOCATABLE now implies IMPORTED_TABLE.

Fixes: #26217

and `RELOCATABLE` now implies `IMPORTED_TABLE`.
Resolves issue 26217
table_import = module.get_function_table_import()
if not table_import:
exit_with_error('IMPORTED_TABLE requires a table import in the wasm module')
settings.INITIAL_TABLE = table_import.limits.initial
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

INITIAL_TABLE is only ever used in RELOCATABLE mode so I think this part can maybe reverted? (Along with the webassembly.py file?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's used when we set IMPORTED_TABLE too so I'm pretty sure the change is necessary.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How about if IMPORTED_TABLE means "user must define the table"? Rather than "emcc defines the table in JS"? Then you could revert the libcore.js change along with this one?

Or, in your use case would you prefer if emcc itself defined the table in JS?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd prefer it if emcc defines the table itself. For instance, otherwise I'd need to implement similar logic that looks at the import section and checks how big the initial size is. I just want wasmTable to be defined during --pre-js execution like the test asserts.

$wasmTable__docs: '/** @type {WebAssembly.Table} */',
#if RELOCATABLE
// In RELOCATABLE mode we create the table in JS.
#if IMPORTED_TABLE
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm less sure about this part. Don't you want to define the table externally in the cases of IMPORTED_TABLE?

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm a little sad to make this change because I was hoping to completely remove this block of code. Since we no longer use -sRELOCTABLE for dynamic linking I was hoping to remove all support for -sRELOCATABLE.

@hoodmane
Copy link
Collaborator Author

Okay I added an IMPORTED_MEMORY test and made the other edits.

@sbc100
Copy link
Collaborator

sbc100 commented Feb 13, 2026

One thing that makes this a little different to IMPORTED_MEMORY is the most used of IMPORTED_MEMORY I believe want to be able to define their own memory.

In this case the only user who benefits is the user who wants the table to be available early (during --pre-js). That seems like a rather narrow set of possible users. I'd like to get some more context on exactly why need to add this. See my comment in #26217. If we do decide to land this I'd also like the use case to be document (I guess in settings.js).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

IMPORTED_TABLE setting to import function pointer table?

2 participants