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

feat(wasm) add support for detailed backtraces #259

Closed
wants to merge 8 commits into from

Conversation

hishamhm
Copy link
Contributor

@hishamhm hishamhm commented Apr 6, 2023

Previously to this PR, this was the state of backtrace support on panics for our supported VMs:

  • Wasmtime: outputs backtraces with function names
  • Wasmer: no backtraces
  • V8: no backtraces

This adds a new configuration directive, backtraces on, which adds support for more detailed backtraces:

  • Wasmtime: outputs backtraces with function names,
    filenames and line numbers
  • Wasmer: outputs backtraces with function names
  • V8: outputs backtraces with function names

The default is backtraces off, which is the same as the old behavior (incurring in no additional initialization time for parsing the function name table for Wasmer and V8).

We also replace the "semi-external dependency" cwabt (a library whose source lives in the ngx_wasm_module repository but which was not built as part of the ngx_wasm_module build process) with a properly "vendored-in" dependency ngx-wasm-rs, which implements the same functionality as a more general Rust library for ngx_wasm_module, which will allow us to add more Rust functionality over time with little deployment overhead.

The Rust library dependency is currently optional for Wasmer and mandatory for V8 (as cwabt was) — it could be made optional as well at the expense of .wat files not working.

Draft status:

  • detailed backtraces for Wasmtime
  • detailed backtraces for Wasmer
  • detailed backtraces for V8
  • fix remaining memory leaks (see Valgrind CI runs)
  • address PR feedback
  • tests
  • document directive

@thibaultcha
Copy link
Member

main -> feat/gateway merge just done; rebasing this branch will significantly improve CI runs

@hishamhm hishamhm force-pushed the feat/backtraces branch 10 times, most recently from b0aae44 to 54a0c1c Compare April 8, 2023 16:56
.github/workflows/ci.yml Outdated Show resolved Hide resolved
auto/cargo Outdated Show resolved Hide resolved
auto/cargo Show resolved Hide resolved
config Outdated Show resolved Hide resolved
config Outdated Show resolved Hide resolved
auto/cargo Show resolved Hide resolved
src/wasm/vm/ngx_wavm.c Show resolved Hide resolved
src/wasm/ngx_wasm_core_module.c Show resolved Hide resolved
src/wasm/wrt/ngx_wrt_wasmtime.c Outdated Show resolved Hide resolved
src/wasm/vm/ngx_wavm.c Show resolved Hide resolved
@hishamhm
Copy link
Contributor Author

@thibaultcha thanks for the first round of reviews! I left a bunch of replies, merged the trivial changes and will continue applying the other changes I marked with ":+1:" tomorrow

@hishamhm hishamhm force-pushed the feat/backtraces branch 8 times, most recently from a316b59 to 7e593fe Compare April 12, 2023 18:24
@hishamhm
Copy link
Contributor Author

Update:

  • Addressed all PR feedback — the Wasmer situation is the last remaining bit; do we leave it as-is given this scenario?
  • Fixed the memory leaks — Valgrind runs are happy now!

I will resume writing new tests for the backtraces directive (with specific tests checking the backtrace output for each VM).

hishamhm added a commit that referenced this pull request Apr 13, 2023
There's a tricky thing going on. Since Wasmer itself is written in Rust and we
build using a precompiled libwasmer.a generated with a different Rust version,
if we link both libwasmer.a and libngx_wasm_rs.a, we get a link failure with
some duplicated incompatible symbols [1][2].

For this reason, when we enable ngx_wasm_rs with Wasmer, we build
it as a .so file rather than a statically-linked .a file.

With this commit, we can install cdylibs under nginx's `--prefix` at `/lib`
(e.g. `/usr/local/nginx/lib`, next to `/usr/local/nginx/sbin/nginx`) and
ensure that the `nginx` binary can find it.

See here for more info:

[1] https://users.rust-lang.org/t/linking-more-than-one-rustc-compiled-static-libraries-in-a-c-project/89778/2
[2] #259 (comment)
Replace "semi-external dependency" cwabt (a library whose source
lives in the ngx_wasm_module repository but which was not built
as part of the ngx_wasm_module build process) with a properly
"vendored-in" dependency ngx-wasm-rs, which implements the same
functionality as a more general Rust library for ngx_wasm_module,
which will allow us to add more Rust functionality over time with
little deployment overhead.
hishamhm added a commit that referenced this pull request Apr 13, 2023
There's a tricky thing going on. Since Wasmer itself is written in Rust and we
build using a precompiled libwasmer.a generated with a different Rust version,
if we link both libwasmer.a and libngx_wasm_rs.a, we get a link failure with
some duplicated incompatible symbols [1][2].

For this reason, when we enable ngx_wasm_rs with Wasmer, we build
it as a .so file rather than a statically-linked .a file.

With this commit, we can install cdylibs under nginx's `--prefix` at `/lib`
(e.g. `/usr/local/nginx/lib`, next to `/usr/local/nginx/sbin/nginx`) and
ensure that the `nginx` binary can find it.

See here for more info:

[1] https://users.rust-lang.org/t/linking-more-than-one-rustc-compiled-static-libraries-in-a-c-project/89778/2
[2] #259 (comment)
hishamhm added a commit that referenced this pull request Apr 13, 2023
There's a tricky thing going on. Since Wasmer itself is written in Rust and we
build using a precompiled libwasmer.a generated with a different Rust version,
if we link both libwasmer.a and libngx_wasm_rs.a, we get a link failure with
some duplicated incompatible symbols [1][2].

For this reason, when we enable ngx_wasm_rs with Wasmer, we build
it as a .so file rather than a statically-linked .a file.

With this commit, we can install cdylibs under nginx's `--prefix` at `/lib`
(e.g. `/usr/local/nginx/lib`, next to `/usr/local/nginx/sbin/nginx`) and
ensure that the `nginx` binary can find it.

See here for more info:

[1] https://users.rust-lang.org/t/linking-more-than-one-rustc-compiled-static-libraries-in-a-c-project/89778/2
[2] #259 (comment)
@hishamhm hishamhm force-pushed the feat/backtraces branch 2 times, most recently from 318a792 to deb3933 Compare April 13, 2023 16:00
hishamhm added a commit that referenced this pull request Apr 13, 2023
There's a tricky thing going on. Since Wasmer itself is written in Rust and we
build using a precompiled libwasmer.a generated with a different Rust version,
if we link both libwasmer.a and libngx_wasm_rs.a, we get a link failure with
some duplicated incompatible symbols [1][2].

For this reason, when we enable ngx_wasm_rs with Wasmer, we build
it as a .so file rather than a statically-linked .a file.

With this commit, we can install cdylibs under nginx's `--prefix` at `/lib`
(e.g. `/usr/local/nginx/lib`, next to `/usr/local/nginx/sbin/nginx`) and
ensure that the `nginx` binary can find it.

See here for more info:

[1] https://users.rust-lang.org/t/linking-more-than-one-rustc-compiled-static-libraries-in-a-c-project/89778/2
[2] #259 (comment)
@thibaultcha
Copy link
Member

thibaultcha commented Apr 14, 2023 via email

There's a tricky thing going on. Since Wasmer itself is written in Rust and we
build using a precompiled libwasmer.a generated with a different Rust version,
if we link both libwasmer.a and libngx_wasm_rs.a, we get a link failure with
some duplicated incompatible symbols [1][2].

For this reason, when we enable ngx_wasm_rs with Wasmer, we build
it as a .so file rather than a statically-linked .a file.

With this commit, we can install cdylibs under nginx's `--prefix` at `/lib`
(e.g. `/usr/local/nginx/lib`, next to `/usr/local/nginx/sbin/nginx`) and
ensure that the `nginx` binary can find it.

See here for more info:

[1] https://users.rust-lang.org/t/linking-more-than-one-rustc-compiled-static-libraries-in-a-c-project/89778/2
[2] #259 (comment)
This refactor is needed because Wasmtime needs to:

1. read the ngx_wavm_conf_t configuration
2. set up the environment variable
3. create the wasm_config_t object

...in that order. With this small API change, we give
the wrt backends the extra flexibility to be able to
do that.
@hishamhm hishamhm force-pushed the feat/backtraces branch 2 times, most recently from fcb43bb to 24de344 Compare April 14, 2023 19:33
Attempt enabling 'llvm', 'cranelift' or 'singlepass', based on
compiler availability, in that order.
Previously to this commit, this was the state of backtrace
support on panics for our supported VMs:

* Wasmtime: outputs backtraces with filenames
* Wasmer: no backtraces
* V8: no backtraces

This adds a new configuration directive, `backtraces on`,
which adds support for more detailed backtraces:

* Wasmtime: outputs backtraces with function names,
  filenames and line numbers
* Wasmer: outputs backtraces with function names
* V8: outputs backtraces with function names

The default is `backtraces off`, which is the same as the
old behavior (incurring in no additional initialization time
for parsing the function name table for Wasmer and V8).
@hishamhm hishamhm force-pushed the feat/backtraces branch 2 times, most recently from 47a7937 to 4226eb5 Compare April 14, 2023 20:29
@hishamhm hishamhm marked this pull request as ready for review April 14, 2023 21:19
@thibaultcha
Copy link
Member

thibaultcha commented Apr 17, 2023

@hishamhm Are you ready for a merge on this one? I see everything is ticked and tests seem to be ready! If there's nothing for you to add I'll go ahead; any minor edits I can do myself.

@hishamhm
Copy link
Contributor Author

hishamhm commented Apr 18, 2023

@thibaultcha yes, it's ready IMO!

thibaultcha pushed a commit that referenced this pull request Apr 18, 2023
There's a tricky thing going on. Since Wasmer itself is written in Rust and we
build using a precompiled libwasmer.a generated with a different Rust version,
if we link both libwasmer.a and libngx_wasm_rs.a, we get a link failure with
some duplicated incompatible symbols [1][2].

For this reason, when we enable ngx_wasm_rs with Wasmer, we build
it as a .so file rather than a statically-linked .a file.

With this commit, we can install cdylibs under nginx's `--prefix` at `/lib`
(e.g. `/usr/local/nginx/lib`, next to `/usr/local/nginx/sbin/nginx`) and
ensure that the `nginx` binary can find it.

See here for more info:

[1] https://users.rust-lang.org/t/linking-more-than-one-rustc-compiled-static-libraries-in-a-c-project/89778/2
[2] #259 (comment)
thibaultcha pushed a commit that referenced this pull request Apr 18, 2023
There's a tricky thing going on. Since Wasmer itself is written in Rust and we
build using a precompiled libwasmer.a generated with a different Rust version,
if we link both libwasmer.a and libngx_wasm_rs.a, we get a link failure with
some duplicated incompatible symbols [1][2].

For this reason, when we enable ngx_wasm_rs with Wasmer, we build
it as a .so file rather than a statically-linked .a file.

With this commit, we can install cdylibs under nginx's `--prefix` at `/lib`
(e.g. `/usr/local/nginx/lib`, next to `/usr/local/nginx/sbin/nginx`) and
ensure that the `nginx` binary can find it.

See here for more info:

[1] https://users.rust-lang.org/t/linking-more-than-one-rustc-compiled-static-libraries-in-a-c-project/89778/2
[2] #259 (comment)
thibaultcha pushed a commit that referenced this pull request Apr 19, 2023
There's a tricky thing going on. Since Wasmer itself is written in Rust and we
build using a precompiled libwasmer.a generated with a different Rust version,
if we link both libwasmer.a and libngx_wasm_rs.a, we get a link failure with
some duplicated incompatible symbols [1][2].

For this reason, when we enable ngx_wasm_rs with Wasmer, we build
it as a .so file rather than a statically-linked .a file.

With this commit, we can install cdylibs under nginx's `--prefix` at `/lib`
(e.g. `/usr/local/nginx/lib`, next to `/usr/local/nginx/sbin/nginx`) and
ensure that the `nginx` binary can find it.

See here for more info:

[1] https://users.rust-lang.org/t/linking-more-than-one-rustc-compiled-static-libraries-in-a-c-project/89778/2
[2] #259 (comment)
thibaultcha pushed a commit that referenced this pull request Apr 19, 2023
There's a tricky thing going on. Since Wasmer itself is written in Rust and we
build using a precompiled libwasmer.a generated with a different Rust version,
if we link both libwasmer.a and libngx_wasm_rs.a, we get a link failure with
some duplicated incompatible symbols [1][2].

For this reason, when we enable ngx_wasm_rs with Wasmer, we build
it as a .so file rather than a statically-linked .a file.

With this commit, we can install cdylibs under nginx's `--prefix` at `/lib`
(e.g. `/usr/local/nginx/lib`, next to `/usr/local/nginx/sbin/nginx`) and
ensure that the `nginx` binary can find it.

See here for more info:

[1] https://users.rust-lang.org/t/linking-more-than-one-rustc-compiled-static-libraries-in-a-c-project/89778/2
[2] #259 (comment)
@thibaultcha
Copy link
Member

Merged in feat/gateway.

@thibaultcha thibaultcha deleted the feat/backtraces branch April 19, 2023 04:15
thibaultcha pushed a commit that referenced this pull request Apr 19, 2023
There's a tricky thing going on. Since Wasmer itself is written in Rust and we
build using a precompiled libwasmer.a generated with a different Rust version,
if we link both libwasmer.a and libngx_wasm_rs.a, we get a link failure with
some duplicated incompatible symbols [1][2].

For this reason, when we enable ngx_wasm_rs with Wasmer, we build
it as a .so file rather than a statically-linked .a file.

With this commit, we can install cdylibs under nginx's `--prefix` at `/lib`
(e.g. `/usr/local/nginx/lib`, next to `/usr/local/nginx/sbin/nginx`) and
ensure that the `nginx` binary can find it.

See here for more info:

[1] https://users.rust-lang.org/t/linking-more-than-one-rustc-compiled-static-libraries-in-a-c-project/89778/2
[2] #259 (comment)
thibaultcha pushed a commit that referenced this pull request Apr 19, 2023
There's a tricky thing going on. Since Wasmer itself is written in Rust and we
build using a precompiled libwasmer.a generated with a different Rust version,
if we link both libwasmer.a and libngx_wasm_rs.a, we get a link failure with
some duplicated incompatible symbols [1][2].

For this reason, when we enable ngx_wasm_rs with Wasmer, we build
it as a .so file rather than a statically-linked .a file.

With this commit, we can install cdylibs under nginx's `--prefix` at `/lib`
(e.g. `/usr/local/nginx/lib`, next to `/usr/local/nginx/sbin/nginx`) and
ensure that the `nginx` binary can find it.

See here for more info:

[1] https://users.rust-lang.org/t/linking-more-than-one-rustc-compiled-static-libraries-in-a-c-project/89778/2
[2] #259 (comment)
thibaultcha pushed a commit that referenced this pull request Apr 20, 2023
There's a tricky thing going on. Since Wasmer itself is written in Rust and we
build using a precompiled libwasmer.a generated with a different Rust version,
if we link both libwasmer.a and libngx_wasm_rs.a, we get a link failure with
some duplicated incompatible symbols [1][2].

For this reason, when we enable ngx_wasm_rs with Wasmer, we build
it as a .so file rather than a statically-linked .a file.

With this commit, we can install cdylibs under nginx's `--prefix` at `/lib`
(e.g. `/usr/local/nginx/lib`, next to `/usr/local/nginx/sbin/nginx`) and
ensure that the `nginx` binary can find it.

See here for more info:

[1] https://users.rust-lang.org/t/linking-more-than-one-rustc-compiled-static-libraries-in-a-c-project/89778/2
[2] #259 (comment)
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.

2 participants