emscripten-core / emscripten-core/emscripten

Swap executable bit between .js and .wasm files?

Open
#12,707 2 comments 0 reactions 0 assignees View on GitHub
wontfix
Dominant language
C++
Stars
27.6k
Forks
3.6k
Avg merge
1d 1h
Merged PRs (30d)
105

Description

I've noticed that when linking an executable in a mode that produces both the `.js` and `.wasm` files, the `.wasm` file has the executable bit set:

```
$ em++ -o hello.js hello.cxx
$ ls -l hello.js hello.wasm
-rw-r--r-- 1 boris boris 106336 Nov 5 11:48 hello.js
-rwxr-xr-x 1 boris boris 652 Nov 5 11:48 hello.wasm
```

I wonder what is the reason for this? I suspect it has something to do with [Standalone WebAssembly](https://github.com/emscripten-core/emscripten/wiki/WebAssembly-Standalone) where the `.wasm` file could be executed directly. However, my understanding is that in this mode (with the `.js` file), the only way to execute the `.wasm` file is via the `.js` file (since it depends on the Emscripten runtime).

On the other hand, if we were to make the `.js` file executable, then, at least on Linux, one could register, say, `nodejs` as an interpreter for `.js` files and run them like any other Linux executable. In particular, this would allow running tests without any changes to the build system.

I've just tried this on my machine and it works great:

> The `update-binfmts` helper is only available on Debian-based distributions.

```
$ sudo update-binfmts --install nodejs /usr/bin/nodejs --extension js
$ chmod ugo+x hello.js
$ ./hello.js
Hello, World!
```

So I am wondering if the executable bit should be swapped between the `.js` and `.wasm` files?

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.