wasm-pack icon indicating copy to clipboard operation
wasm-pack copied to clipboard

--profiling doesn't preserve function names

Open RReverser opened this issue 5 years ago • 5 comments
trafficstars

🐛 Bug description

profiling mode is essentially equivalent to release and doesn't preserve debug info as documented (not even function names necessary for profiling or basic debugging).

🤔 Expected Behavior

The generated .wasm contains a custom "names" section that is subsequently used by engines for function names in error stacks and profiling traces.

👟 Steps to reproduce

Compile any package with wasm-pack --profiling.

Run an example app in a browser profiler or a debugger and observe that all functions are shown as just wasm-function[...], just like in a release mode.

Alternatively, check the generated .wasm with wasm-objdump -h for presence of "names" section (it's absent).

🌍 Your environment

Include the relevant details of your environment. wasm-pack version: 0.9.1 rustc version: 1.41.0


Extra info

This seems to be caused by wasm-pack running wasm-opt without a -g flag, which is necessary to preserve function names information.

RReverser avatar Feb 21 '20 15:02 RReverser

For others struggling with this like me, I've been able to work around this by setting the -g flag manually in my cargo.toml like this:

[package.metadata.wasm-pack.profile.release]
# previously had just ['-O4']
wasm-opt = ['-O4', '-g']

Which I got from this doc: https://rustwasm.github.io/docs/wasm-pack/cargo-toml-configuration.html

stefan2718 avatar Apr 26 '20 15:04 stefan2718

@stefan2718 Oh yeah, sorry, should've probably mentioned this as a workaround.

I'm using the same one, except with .profiling instead of .release as I don't want regular release builds to be affected.

RReverser avatar Apr 26 '20 20:04 RReverser

@RReverser Do I need to be building with nightly to use the --profiling flag? When I've tried before it just uses the release profile, which doesn't add debuginfo unless I add debug = true to the release profile.

stefan2718 avatar Apr 26 '20 20:04 stefan2718

@stefan2718 No, it works for me as-is.

But note that my original issue is about preserving names (in the "names" subsection), while you seem to be talking about DWARF debuginfo instead? That one is controlled by separate flags, and doesn't work with wasm-bindgen for different reasons.

RReverser avatar Apr 29 '20 17:04 RReverser

AIUI this doesn't work for crates within a workspace:

horizon:~/source/TX-2/TX-2-simulator$ cat Cargo.toml 
[workspace]
members = [
	"base",
	"cpu",
	"cli",
	"assembler",
	"tx2-web",
]

[profile.wasm-release]
inherits = "release"
lto = true
debug=true

[profile.release]
debug=true

[profile.wasm-release.build-override]
# Tell `rustc` to optimize for small code size.
opt-level = "s"
debug=true

[package.metadata.wasm-pack.profile.release]
# Retain debug information in release builds (for profiling).
# This section seems to have no effect at crate level but
# not be allowed at workspace level.
wasm-opt = ["-O4 --debuginfo"]
horizon:~/source/TX-2/TX-2-simulator$ cargo metadata
error: failed to parse manifest at `/home/james/source/TX-2/TX-2-simulator/Cargo.toml`

Caused by:
  missing field `name` for key `package`

jamesyoungman avatar Jun 18 '22 08:06 jamesyoungman