Hi community, I have a question. If my C project contains assembly code (i.e, .S files), can I using Clang to compile my C project into WASM? Any help will be appreciated!
Best,
you can link .S
files into Wasm binaries with lld
(and therefore I assume with clang) but the .S
file needs to be using the wasm text format, not e.g. x86 assembly
You first have to convert the .S
file to a wasm object file using an assembler. Lld doesn't directly accept assembly code.
Thanks so much for the responds! I am really appreciated. BTW, could you guys provide some links that I can take a look of the wasm assembly text format?
https://webassembly.github.io/spec/core/text/index.html is the specification of the text format
you can use wasm-tools print
and wasm-tools parse
to assemble and disassemble: github.com/bytecodealliance/wasm-tools
the official test suite has more examples of the text format (although it is in the extended .wast
format rather than .wat
, which allows defining multiple modules and assertions and such): https://github.com/WebAssembly/testsuite/
Hi guys, I'm also a newbee to WASM libcs, and I'm kind of confused by the assembly code in wasi-libc. For example, longjmp.s, I thought WASM is a architecture agnostic format, but in this part of wasi-libc, the assembly file
.global _longjmp
.global longjmp
.type _longjmp,@function
.type longjmp,@function
_longjmp:
longjmp:
mov 4(%esp),%edx
mov 8(%esp),%eax
cmp $1,%eax
adc $0, %al
mov (%edx),%ebx
mov 4(%edx),%esi
mov 8(%edx),%edi
mov 12(%edx),%ebp
mov 16(%edx),%esp
jmp *20(%edx)
is included as a part of musl. Then how is this being compiled as a part of the wasm sysroot? I'm kind of interested in this compilation.
It shouldn't be; probably that's general code in musl in an architecture-specific part (for x86) that is not included in the wasm build
(it's common for programs that require assembly bits, either for performance or for implementing low-level things, to have separate implementations per architecture and select only one during build)
If you look at the wasi-libc
Makefile, you'll see that not all the files in the source tree are included as part of the build, and I'd expect that longjmp.s is not included.
I believe the approach of importing all of musl but only using part of it is motivated by a desire to make upgrading to later musl versions easier.
Ohoh I see, so the actual source for wasi-libc shouldn't include stuff like x86 asm, or at least not necessarily needed. Yeah, their approach definitely makes upgrading for future musl versions easier, thanks!
Last updated: Nov 22 2024 at 17:03 UTC