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

--profiling doesn't preserve function names #797

Open
RReverser opened this issue Feb 21, 2020 · 5 comments
Open

--profiling doesn't preserve function names #797

RReverser opened this issue Feb 21, 2020 · 5 comments

Comments

@RReverser
Copy link
Member

🐛 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.

@stefan2718
Copy link

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

@RReverser
Copy link
Member Author

@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.

@stefan2718
Copy link

@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.

@RReverser
Copy link
Member Author

@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 added a commit to RReverser/serde-wasm-bindgen that referenced this issue Jun 7, 2021
@jamesyoungman
Copy link

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`

evmar added a commit to evmar/retrowin32 that referenced this issue Oct 17, 2022
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

No branches or pull requests

3 participants