Skip to content

Add --keep-symbols flag#302

Merged
athei merged 10 commits into
masterfrom
at-keep-symbols
Jul 20, 2021
Merged

Add --keep-symbols flag#302
athei merged 10 commits into
masterfrom
at-keep-symbols

Conversation

@athei

@athei athei commented Jul 19, 2021

Copy link
Copy Markdown
Contributor

In order to properly analyze a contract binary we need to keep the wasm name section alive so that we can see what is going on. Using the non post processed wasm file is of no use because we are interested in the fully optimized binary when doing an analysis. To that end I added a new --keep-symbols flag to the build command which prevents wasm-opt from removing the debug section.

I needed to make some other changes to make this work, too. Most notable I removed the call to pwasm_utils::optimize which unconditionally removes all custom sections. We don't need this anyways because wasm-opt does the same optimizations and more. It sufficed to remove all exports from the module (but call and deploy) to have the same result without pwasm_utils::optimize. I argue that having one less pass involved is a good thing.

@athei athei added the enhancement New feature or request label Jul 19, 2021
@athei
athei requested review from ascjones and cmichi July 19, 2021 08:14
Comment thread src/cmd/build.rs Outdated
Comment thread src/cmd/build.rs Outdated
Comment thread src/cmd/build.rs Outdated
Co-authored-by: Michael Müller <michi@parity.io>
@Robbepop

Copy link
Copy Markdown
Contributor

How about not adding a new flag (that users have to know) but instead do all this whenever we do a normal --debug build which is the default build config?

@athei

athei commented Jul 19, 2021

Copy link
Copy Markdown
Contributor Author

There is no --debug flag and hence it cannot be the default. The default for build is to build for production. check is for development.

@cmichi

cmichi commented Jul 19, 2021

Copy link
Copy Markdown
Collaborator

There is no --debug flag and hence it cannot be the default. The default for build is to build for production. check is for development.

I think what Robin means that in a recent PR we decided against a cargo contract build --debug flag and instead now mirror cargo behavior of building for debug by default. We instead added a cargo contract build --release flag which leaves debug info out.

By debug info we currently only have the ink-debug flag, which enables printing debug statements and hence some overhead needs to be compiled into the contract to support that.

I think the misunderstanding here is that you are probably referring to the fact that we always build contracts as cargo build --release and also still run wasm-opt on them. This is required so that contracts can even be deployed.

So the distinction I think Robin wants to make is that we have a debug and a release mode for cargo-contract, whereas you are talking about cargo build for the *.rs files. So you could just leave the symbols in by default and only omit them on cargo contract build --release.

@athei

athei commented Jul 19, 2021

Copy link
Copy Markdown
Contributor Author

But nothing of those things is a reality on master, right? Because I don't see a --release flag anywhere.

@cmichi

cmichi commented Jul 19, 2021

Copy link
Copy Markdown
Collaborator

But nothing of those things is a reality on master, right? Because I don't see a --release flag anywhere.

#298

It's approved, but not yet merged because we need rc4 to be released first.

@athei

athei commented Jul 19, 2021

Copy link
Copy Markdown
Contributor Author

Thanks. I checked the PR. I disagree. --keep-symbols is orthogonal to --release. I want to analyze the optimized binary as it would be deployed on chain (that might or might not include a build without the ink! debug features). So basically I want --keep-symbols --release.

@Robbepop

Copy link
Copy Markdown
Contributor

If this is the case then please rename the flag to --keep-debug-symbols so that it is clear by name that this is for debug inspection.

@atenjin

atenjin commented Jul 20, 2021

Copy link
Copy Markdown
Contributor

we have create a pr in post #131
but we close it for no response ....
maybe --debug is a good choose for many cases, not only in this situation. we also need those information which contains debug symble in name section

Comment thread src/cmd/build.rs Outdated
Comment thread src/cmd/build.rs

@ascjones ascjones left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

LGTM

Comment thread src/cmd/build.rs Outdated
athei and others added 2 commits July 20, 2021 10:51
Co-authored-by: Andrew Jones <ascjones@gmail.com>
Co-authored-by: Michael Müller <michi@parity.io>

@cmichi cmichi left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Thanks! cargo fmt fails right now, but besides that it LGTM.

@athei

athei commented Jul 20, 2021

Copy link
Copy Markdown
Contributor Author

Thanks! cargo fmt fails right now, but besides that it LGTM.

Yeah but not because of the code. Just some intermittent CI failures. Saw this multiple times here:

Error during execution of `cargo metadata`: error: failed to download `env_logger v0.9.0`

@athei

athei commented Jul 20, 2021

Copy link
Copy Markdown
Contributor Author

Merging this. The CI is broken (some caching issue, again). I ran cargo fmt locally.

@athei
athei merged commit 9b36b62 into master Jul 20, 2021
@athei
athei deleted the at-keep-symbols branch July 20, 2021 10:15
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants