Skip to content

Implement rmdir with wasmfs - #18952

Merged
tlively merged 15 commits into
emscripten-core:mainfrom
kshitjj:implement-rmdir-with-wasmfs
Apr 3, 2023
Merged

tlively merged 15 commits into
emscripten-core:mainfrom
kshitjj:implement-rmdir-with-wasmfs

Conversation

@kshitjj

@kshitjj kshitjj commented Mar 13, 2023

Copy link
Copy Markdown
Contributor

Hi @tlively @kripken,

I've completed the implementation for rmdir on my branch and tested it locally, but when running the tests with ./test/runner.py test_fs_*, I'm getting an error(mentioned below).

I'm also working on implementing mount on another branch and encountering the same error there. I'm currently using Ubuntu 22.04.2LTS as my OS.

Here is the error I am getting

test_fs_readv_rawfs (test_core.core0) ... FAIL
error: failure to execute js library "library_wasmfs.js":
error: use -sVERBOSE to see more details
Internal compiler error in src/compiler.js!
Please create a bug report at https://github.com/emscripten-core/emscripten/issues/
with a log of the build and the input files used to run. Exception message: "In the following macro:

 cDefine('S_IRUGO') 

Error: Missing C define S_IRUGO! If you just added it to struct_info.json, you need to ./emcc --clear-cache
    at cDefine (/home/tylerthe/Desktop/gsoc/emscripten/src/modules.js:261:9)
    at eval (eval at <anonymous> (/home/tylerthe/Desktop/gsoc/emscripten/src/parseTools.js), <anonymous>:1:2)
    at eval (/home/tylerthe/Desktop/gsoc/emscripten/src/parseTools.js:25:19)
    at String.replace (<anonymous>)
    at processMacros (/home/tylerthe/Desktop/gsoc/emscripten/src/parseTools.js:23:15)
    at Object.load (/home/tylerthe/Desktop/gsoc/emscripten/src/modules.js:214:21)
    at runJSify (/home/tylerthe/Desktop/gsoc/emscripten/src/jsifier.js:74:18)
    at Object.<anonymous> (/home/tylerthe/Desktop/gsoc/emscripten/src/compiler.js:97:3)
    at Module._compile (node:internal/modules/cjs/loader:1246:14)
    at Module._extensions..js (node:internal/modules/cjs/loader:1300:10)
emcc: error: '/home/tylerthe/.nvm/versions/node/v19.5.0/bin/node /home/tylerthe/Desktop/gsoc/emscripten/src/compiler.js /tmp/emtest_k8nvqblu/tmpvo2x2_a1.json --symbols-only' failed (returned 1)
FAIL: Compilation failed!: ['/home/tylerthe/Desktop/gsoc/emscripten/emcc', '-D_GNU_SOURCE', '-o', '/tmp/tmpg6vtuanj.js', '/tmp/tmpvif704gr.c', '-O0', '-Werror', '-Wno-format', '-nostdlib', '/home/tylerthe/Desktop/gsoc/emscripten/cache/sysroot/lib/wasm32-emscripten/libcompiler_rt.a', '-sBOOTSTRAPPING_STRUCT_INFO', '-sSTRICT', '-sASSERTIONS=0', '-sSINGLE_FILE', '-Wno-error=version-check', '-Wno-deprecated']
None

Any guidance you can offer on how to debug the error would be greatly appreciated. Thank you!

@kshitjj kshitjj mentioned this pull request Mar 13, 2023
@kripken

kripken commented Mar 13, 2023 •

Copy link
Copy Markdown
Member

I think this error may be because some of my earlier instructions were not correct (edit: sorry about that!)

Instead, undo the changes to src/settings.js, and then run ./test/runner.py wasmfs.test_fs_* (note the wasmfs. prefix there).

@tlively tlively left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

The code looks good so far, but it will need a test as well. If there are existing tests that use FS.rmdir that can be run with WasmFS as well, then reusing those would be great. Otherwise we will need a new test.

Comment thread src/settings.js Resolved
@kshitjj

kshitjj commented Mar 16, 2023

Copy link
Copy Markdown
Contributor Author

I have addressed the two issues in a new commit. However, I noticed that there are currently no tests for rmdir. To add tests for rmdir, I'm wondering whether I should create a new pull request specifically for the tests or work on them within this existing pull request. What do you recommend?

@tlively

@tlively

tlively commented Mar 16, 2023

Copy link
Copy Markdown
Member

It would be best to add the tests in this PR so we can make sure all the code we merge is tested.

@kshitjj

kshitjj commented Mar 30, 2023 •

Copy link
Copy Markdown
Contributor Author

@tlively @kripken @sbc100
I can’t seem to figure out why test-wasm64 is failing, can you point me in the right direction?
Or, is it possible we can skip the test entirely using @no_wasm64, I can open an issue and put the link for the issue in the brackets?

@tlively

tlively commented Mar 30, 2023

Copy link
Copy Markdown
Member

I applied the diff locally and confirmed I was able to reproduce the error:

./emcc --clear-cache && ./test/runner wasm64l../test/runner wasm64l.test_fs_dir_wasmfs

Then I passed --verbose to test/runner to get the compile command so I could investigate deeper. After removing superfluous arguments and adding a node invocation to run the test after compiling it, I get this command:

./emcc test/fs/test_dir.c -o test_dir.js -sMEMORY64=2 --profiling-funcs -sWASMFS -sFORCE_FILESYSTEM && node test_dir.js

That gives this error:

/usr/local/google/home/tlively/code/emscripten/test_dir.js:130
      throw ex;
      ^

TypeError: Cannot convert 65488 to a BigInt
    at /usr/local/google/home/tlively/code/emscripten/test_dir.js:909:22
    at /usr/local/google/home/tlively/code/emscripten/test_dir.js:1747:18
    at withStackSave (/usr/local/google/home/tlively/code/emscripten/test_dir.js:1649:17)
    at Object.rmdir (/usr/local/google/home/tlively/code/emscripten/test_dir.js:1745:16)
    at 72792 (/usr/local/google/home/tlively/code/emscripten/test_dir.js:1197:109)
    at runEmAsmFunction (/usr/local/google/home/tlively/code/emscripten/test_dir.js:1404:31)
    at _emscripten_asm_const_int (/usr/local/google/home/tlively/code/emscripten/test_dir.js:1412:14)
    at __original_main (wasm://wasm/00099e9a:wasm-function[19]:0xa0e)
    at main (wasm://wasm/00099e9a:wasm-function[20]:0xa38)
    at /usr/local/google/home/tlively/code/emscripten/test_dir.js:1999:14

Looking at line 1747 in the test_dir.js that Emscripten produced, we can see that it is the call to __wasmfs_rmdir(buffer) that is failing. The only number getting converted to BigInt here is the buffer pointer getting passed to __wasmfs_rmdir, which expects an i64 pointer in wasm64. It must be the case that buffer is a normal number instead of being a BigInt. Other functions must have the same problem, and looking back in library_wasmfs.js, we can see that indeed mkdir and open use the {{{ to64('buffer') }}} macro to convert the number to a BigInt if necessary. So the same fix should work here!

@sbc100

sbc100 commented Mar 30, 2023

Copy link
Copy Markdown
Collaborator

If you have native exports that take pointers we currently have a hardcoded list in emscripten.py in create_wasm64_wrappers. I think you would need to add __wasmfs_rmdir there.

@tlively

tlively commented Mar 30, 2023

Copy link
Copy Markdown
Member

@sbc100 I didn't even know about that 😆. Is there some way we could use source annotations for that instead?

@sbc100

sbc100 commented Mar 30, 2023

Copy link
Copy Markdown
Collaborator

@sbc100 I didn't even know about that laughing. Is there some way we could use source annotations for that instead?

I have a TODO in that function, but I don't really have any concrete ideas on how to fix it.

I guess for functions that our part of our standard library we could do something similar to the auto-sig-generation I just landed... but that would not extend to user exports.

For the __sig generation we use the compiler to build a program once with wasm32 and once with wasm64 and we figure out which arguments are pointers by looking at how the sigs change between the two builds. Doing that for user programs seems a lot harder.

But we should at least make it easy for user to tag certain functions/arguments are being pointers so we can create these wrappers for them,

@kshitjj

kshitjj commented Apr 2, 2023

Copy link
Copy Markdown
Contributor Author

@tlively, just wanted to update you on the PR. We added test cases and fixed all the errors, and all Circle CI tests are passing, so I think it's ready to be merged.

Also, I wanted to thank you for walking me through the debugging process - it was really helpful!

@tlively tlively left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

LGTM besides those last two comments.

Comment thread test/fs/test_dir.c Resolved
Comment thread test/test_core.py Resolved
@kshitjj

kshitjj commented Apr 3, 2023

Copy link
Copy Markdown
Contributor Author

LGTM besides those last two comments.

Done.

@tlively tlively left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Great, thank you!

@tlively
tlively merged commit 94ae66a into emscripten-core:main Apr 3, 2023
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.

4 participants