Skip to content

Wasm support #71

@ratmice

Description

@ratmice

wasm-ld now seems to have rudimentary .init_array support.
I posted a rustc patch here: rust-lang/rust#121533

While it does work to just add

diff --git a/src/lib.rs b/src/lib.rs
index de4cdef..599f064 100644
--- a/src/lib.rs
+++ b/src/lib.rs
@@ -451,6 +451,7 @@ macro_rules! __do_submit {
                     target_os = "netbsd",
                     target_os = "openbsd",
                     target_os = "none",
+                    target_os = "wasi",
                 ),
                 link_section = ".init_array",
             )]

This suffers from the limitation of wasm only supporting a single symbol in the link_section.
It would perhaps be nice if there was a submit_many!() macro which would

static __CTORS: [unsafe extern "C" fn(); num_submitted] = [ ... ]

I tested that this also works with .init_array at least on linux, on other platforms presumably it could just submit! for each
arg to submit_many!.

Probably not worth implementing until we see the rustc patch go in, but I figured it was worth mentioning since
wasm support has come up in the past. E.g. @matklad asked about it in #3

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions