Lind-Project / lind-wasm

https://lind-project.github.io/lind-wasm-docs/
Apache License 2.0
1 stars 1 forks source link

Progress on adding syscall to lind-wasm #12

Closed robinyuan1002 closed 1 week ago

robinyuan1002 commented 2 months ago

Track the progress on adding syscalls to Lind-Wasm

robinyuan1002 commented 2 months ago

I ran all the test cases of Lind, and basically none of them could compile. Mainly due to the lack of some header files, # include <linux/errno.h>, # include <linux/falloc.h>, # include <asm/socket.h>. I'll try to find and install it.

robinyuan1002 commented 2 months ago
  1. Most of the tests can be compiled, but I encountered a problem in <asm/socket.h>.

wasm-ld: error: /tmp/uds-socketselect-63ca2b.o: undefined symbol: connect wasm-ld: error: /tmp/uds-socketselect-63ca2b.o: undefined symbol: bind wasm-ld: error: /tmp/uds-socketselect-63ca2b.o: undefined symbol: accept wasm-ld: error: /home/lind-wasm/glibc/sysroot/lib/wasm32-wasi/libc.a(nanosleep.o): undefined symbol: __clock_nanosleep_time64 clang-16: error: linker command failed with exit code 1 (use -v to see invocation)

  1. I started running these tests. Try modifying dispatch.rs or glibc/sysdeps if I encountered problems.
rennergade commented 2 months ago

Where is asm/socket.h included?

robinyuan1002 commented 2 months ago

uds-nb-select.c, uds-serverclient.c, uds-socketselect.c

rennergade commented 2 months ago

I don't see any of those declared in those programs. Are you talking about sys/socket.h?

robinyuan1002 commented 2 months ago

yes, in sys/socket.h there is a header file called bit/socket.h, and in bit/socket.h there is a header file called asm/socket.h

rennergade commented 2 months ago

Okay, so these are included within the libraries so its entirely a glibc issue. Thats good to know.

rennergade commented 2 months ago

So for NaCl, asm/socket.h is actually an include file generated by the nacl-toolchain and is platform specific. @yzhang71 are there wasm toolchain generated include files?

yzhang71 commented 2 months ago

No, we don't have asm/socket.h generated, but we have bit/socket.h generated, and there is condition to use asm/socket.h

#ifdef __USE_MISC
# include <bits/types/time_t.h>
# include <asm/socket.h>
#else
# define SO_DEBUG 1
# include <bits/socket-constants.h>
#endif
qianxichen233 commented 2 months ago

For the undefined symbol error, I just found out that it was due to bind.c in glibc failing to compile and not being successfully turned into bind.o. The error message was buried among a sea of warnings and other errors during the make process, so we did not notice it previously. I guess that's the same for connect.c and accept.c. I'll try to fix this later

rennergade commented 2 months ago

No, we don't have asm/socket.h generated, but we have bit/socket.h generated, and there is condition to use asm/socket.h

#ifdef __USE_MISC
# include <bits/types/time_t.h>
# include <asm/socket.h>
#else
# define SO_DEBUG 1
# include <bits/socket-constants.h>
#endif

IIRC bits/socket.h is a file in libc. What I'm saying is that asm/socket.h is not a libc file. It's a platform file.

For example on my system its located at /usr/x86_64-linux-gnux32/include/asm/socket.h

When we compile NaCl this file is generated, as opposed to the other files which are in the libc repo.

robinyuan1002 commented 2 months ago

Update There is no problem with open, read and close.

Problem When I was testing read.c, I encountered a problem. The isprint() function returned false no matter how much input was entered. This seemed to be a problem, but it did not affect the test very much.

rennergade commented 2 months ago

@qianxichen233 found that copying the system includes into the wasm folder ie /usr/x86_64-linux-gnux32/include/asm/socket.h fixes the builds. We need to:

  1. Audit the include folder to make sure its just defined constants and/or code we can compile.
  2. Lets ask the people on Zulip if wasm generates its own system includes as above (mention that NaCl does). If they do I'd prefer to use those.
rennergade commented 2 months ago

@yzhang71 Can you point me to the wasm generated headers you were talking about in the meeting?

yzhang71 commented 2 months ago

Hi Nick, here is the header files that we are currently using: https://github.com/Lind-Project/glibc/tree/main/include

robinyuan1002 commented 2 months ago

Hi Nick, I use glibc/target/include which is same with Dennis's link. I look for the header file I need based on the compile error, for example I created a directory called asm-generic and add a file called errno.base.h(Here is the link: https://github.com/torvalds/linux/blob/master/include/uapi/asm-generic/errno-base.h).

rennergade commented 2 months ago

Okay that sounds good. Dennis is going to check with Zulip but we can probably use these if they dont have anything. We probably want to move these out of the glibc folder since theyre not technically libc files.

robinyuan1002 commented 2 months ago

Update: There is no problem with rename(6), xstat(9), open(10), close(11), read(12), write(13), fstatfs(19), dup(24), dup2(25), getcwd(47), mkdir(131), rmdir(132), chmod(133), fchmod(134)