Skip to content

Linking with extern function in Wasm #63562

Closed

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.

Activity

  1. mikevoronov commented on Aug 30, 2019

    @mikevoronov
    Author

    Hi, guys! Are there any updates?

  2. added
    A-linkageArea: linking into static, shared libraries and binaries
    C-tracking-issueCategory: An issue tracking the progress of sth. like the implementation of an RFC
    T-compilerRelevant to the compiler team, which will review and decide on the PR/issue.
    and removed
    C-tracking-issueCategory: An issue tracking the progress of sth. like the implementation of an RFC
    on Sep 16, 2019
  3. added
    O-wasmTarget: WASM (WebAssembly), http://webassembly.org/
    on Dec 16, 2019
  4. added a commit that references this issue on Dec 16, 2019
    aa0ef5a
  5. added a commit that references this issue on Dec 19, 2019
    74b1902
  6. added 2 commits that reference this issue on Dec 20, 2019
    8e9f09c
    43d1532
  7. added a commit that references this issue on Jun 29, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

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