Skip to content

Linking with extern function in Wasm #63562

Closed
@mikevoronov

Description

@mikevoronov

I am trying to use functions from an external module and importing them like that:

#[link(wasm_import_module = "sqlite")]
extern "C" {
  #[link_name="allocate"]
  pub fn allocate_external(size: usize) -> i32;
  
  #[link_name="deallocate"]
  pub fn deallocate_external(ptr: i32, size: usize);
}

But if I have exported functions with the same names in my own module, there will be linked with these local functions (in these case these functions won't be in the import section of a compiled module). Is it possible to link with functions in external module having functions with the same name in your own?

POC can be found here.

Btw, in C it could be done in this way:

#define __MODULE_IMPORT(module_name, function_name) \
    __attribute__((__import_module__(#module_name), __import_name__(#function_name)))

char *allocate_extern(int size) __MODULE_IMPORT(sqlite, allocate);
void deallocate_extern(char *ptr) __MODULE_IMPORT(sqlite, deallocate);

and works perfectly.

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-linkageArea: linking into static, shared libraries and binariesO-wasmTarget: WASM (WebAssembly), http://webassembly.org/T-compilerRelevant to the compiler team, which will review and decide on the PR/issue.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions