Skip to content
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

Support wasm64 #444

Open
wants to merge 46 commits into
base: main
Choose a base branch
from
Open

Support wasm64 #444

wants to merge 46 commits into from

Conversation

trcrsired
Copy link

I need to make changes to the "c_header.rs" file because there are numerous instances where "size_t" is mistakenly identified as "uint32_t," which is incompatible with wasm64.

@trcrsired trcrsired changed the title Add support 64 bits wasi Add support for 64 bits wasi Oct 26, 2023
@trcrsired trcrsired changed the title Add support for 64 bits wasi Support wasm64-wasi and wasm64-wasi-threads Oct 26, 2023
@trcrsired trcrsired changed the title Support wasm64-wasi and wasm64-wasi-threads Support wasm64 Oct 26, 2023
@trcrsired
Copy link
Author

@yamt Hello. Can you start the CI for me? Thank you

@yamt
Copy link
Contributor

yamt commented Oct 30, 2023

@yamt Hello. Can you start the CI for me? Thank you

i have no special permissions on this repo.
@abrown ping

@trcrsired
Copy link
Author

@abrown Hi. Could you explain why CI is not automatic but needs action from the maintainers?

@trcrsired
Copy link
Author

I have removed all signal apis from the upstream file and regenerated api.h and __wasi_realfile.c.

@trcrsired
Copy link
Author

Add CI for wasm64-wasi + wasm64-wasi-threads
Add noexcept to all apis.

Makefile Outdated
@@ -22,6 +22,8 @@ BUILD_LIBC_TOP_HALF ?= yes
# The directory where we will store intermediate artifacts.
OBJDIR ?= build/$(TARGET_TRIPLE)

BUILD_WASI64 ?= no
Copy link
Member

Choose a reason for hiding this comment

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

Maybe BUILD_WASM64 would better match the target name?

Copy link
Author

Choose a reason for hiding this comment

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

what about just WASI64?

Copy link
Member

Choose a reason for hiding this comment

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

But WASI64 is not a thing as far as I know. It doesn't mean much to me as the reader.. whereas WASM64 is the name of the llvm target.

Copy link
Author

Choose a reason for hiding this comment

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

but wasm64 is not wasi64, because you also have wasm64-emscripten.

Copy link
Author

Choose a reason for hiding this comment

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

But WASI64 is not a thing as far as I know. It doesn't mean much to me as the reader.. whereas WASM64 is the name of the llvm target.

what about just allowing users to set TRIPLE?

Copy link
Author

Choose a reason for hiding this comment

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

Changed to WASM64

libc-top-half/musl/src/thread/wasm64/wasi_thread_start.s Outdated Show resolved Hide resolved
// TODO: Encoding this in witx.
#define __WASI_DIRCOOKIE_START (UINT64_C(0))
typedef __SIZE_TYPE__ __wasi_size_t;

_Static_assert(sizeof(__wasi_size_t) == 4, "witx calculated size");
Copy link
Member

Choose a reason for hiding this comment

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

Rather than removing these lines perhaps change the 4 to something like WASM_PTR_SIZE?

Copy link
Author

Choose a reason for hiding this comment

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

Well the Rust generated script does not work here.

Also, personally, i would like to remove all these _Static_assert because C and C++ are designed in this way to ensure maximum portability. Better not assume anything.
In fact, in C and C++, intxx_t, uintxx_t, uintptr_t do not necessarily exist either, the standard wants you to use uint_leastxx_t.

Copy link
Member

Choose a reason for hiding this comment

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

You can use __SIZEOF_POINTER__ perhaps which is built into clang. Or you can use ifdef __wasm64__ to set a custom WASM_PTR_SIZE within this file.

Note that this header is specifically not designed to be flexible or portable its very much only designed to be included by a conforming version of clang and it defines as strict/inflexible ABI (which is why all those static asserts exists).

Copy link
Author

Choose a reason for hiding this comment

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

ret.push_str(&format!( "_Static_assert(sizeof(__wasi_{}_t) == {}, \"witx calculated size\");\n", ident_name(name), dest.mem_size_align().size )); ret.push_str(&format!( "_Static_assert(_Alignof(__wasi_{}_t) == {}, \"witx calculated align\");\n", ident_name(name), dest.mem_size_align().align ));

it is generated by this code, but the values are not correct for 64 bit so i have to disable all of them.


#ifdef __wasm64__
#define a_cas_p a_cas_p
static inline void *a_cas_p(volatile void *p, void *t, void *s)
Copy link
Member

Choose a reason for hiding this comment

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

Why is this needed for wasm64 but not for wasm32?

Copy link
Author

@trcrsired trcrsired Oct 31, 2023

Choose a reason for hiding this comment

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

because a_cas_p is defined by the clang front end for wasm32 but not wasm64

Copy link
Member

Choose a reason for hiding this comment

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

c_cas_p doesn't sounds like something that clang itself would ever define...

Copy link
Author

Choose a reason for hiding this comment

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

well, the problem is that musl does not need c_cas_p on 32 bit platform, but only on 64 bit platform and i am not 100% confident of the correctness here.

libc-bottom-half/sources/__wasilibc_real.c Outdated Show resolved Hide resolved
@sunfishcode
Copy link
Member

This PR would effectively create a new wasm64 preview1 ABI, as well as a new wasi-threads ABI. Those are major new interfaces, that could eventually impact a large number of tools and engines. Since this is an official WebAssembly organization project, we should discuss this in a WASI Subgroup meeting before proceeding with this PR.

trcrsired and others added 6 commits October 31, 2023 16:37
Parameters changing back to use signed integer in __wasilibc_real.c

rename libc-top-half/musl/arch/wasm32 to libc-top-half/musl/arch/wasm

rename libc-top-half/musl/src/thread/wasm32 to libc-top-half/musl/src/thread/wasm

rename wasi_thread_start.s to wasi_thread_start.S since .s does not support macros
@sunfishcode
Copy link
Member

i am thinking of duplicate apis instead of just making the 32 and 64 the same. Duplicating apis are much easier for virtual machine to implement and leaving more flexibility for programmers and not breaking existing tools.

Like __wasi_preview1_fd_write can have its __wasi_preview1_fd_write_i64 version which accepts i64 as its pointer.

Even so, it's still a major expansion in the WASI preview1 surface area, so we should get Subgroup guidance before this could be merged.

@trcrsired
Copy link
Author

changed to _wasm64 based on feedback

@TianlongLiang
Copy link

Hi, I tried your awesome wasm64 support patch with some wasi-threads samples, and have the following result:

wasm-ld: error: Global type mismatch: __stack_pointer
>>> defined as var i64 in <internal>
>>> defined as var i32 in /opt/wasi-sdk/build/wasi-sdk-21.4ga1b80857c490+m/bin/../share/wasi-sysroot/lib/wasm64-wasi-threads/libc.a(__init_tls.o)

It seems that this line of code in this directory also needs to be modified(i64 when it's wasm64). After I modify it and recompile it, it gets rid of the linking error. What do you think?

@loganek
Copy link
Contributor

loganek commented Jan 23, 2024

@trcrsired what's the status of the work? I seriously consider using wasm64 in one of my projects as that'd solve a few problems; if the work is abandoned, I'm happy to pick it up and drive further (i.e. discuss with WASI subgroup, finalize the PR).

@loganek
Copy link
Contributor

loganek commented Jan 30, 2024

Since there wasn't any progress on that PR for the last 1.5 month, I'm planning to close on the discussion and finalize the PR. I've requested a slot in the next WASI SG meeting; hopefully we can discuss all the concerns and agree on the next steps: WebAssembly/meetings#1479

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.

6 participants