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

Add --keep-symbols flag #302

Merged
merged 10 commits into from
Jul 20, 2021
Merged

Add --keep-symbols flag #302

merged 10 commits into from
Jul 20, 2021

Conversation

athei
Copy link
Contributor

@athei athei commented Jul 19, 2021

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
src/cmd/build.rs Outdated Show resolved Hide resolved
src/cmd/build.rs Outdated Show resolved Hide resolved
src/cmd/build.rs Outdated Show resolved Hide resolved
Co-authored-by: Michael Müller <michi@parity.io>
@Robbepop
Copy link
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
Copy link
Contributor Author

athei commented Jul 19, 2021

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
Copy link
Collaborator

cmichi commented Jul 19, 2021

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
Copy link
Contributor Author

athei commented Jul 19, 2021

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

@cmichi
Copy link
Collaborator

cmichi commented Jul 19, 2021

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
Copy link
Contributor Author

athei commented Jul 19, 2021

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
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
Copy link
Contributor

atenjin commented Jul 20, 2021

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

src/cmd/build.rs Outdated Show resolved Hide resolved
Copy link
Collaborator

@ascjones ascjones left a comment

Choose a reason for hiding this comment

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

LGTM

src/cmd/build.rs Outdated Show resolved Hide resolved
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>
Copy link
Collaborator

@cmichi cmichi left a comment

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
Copy link
Contributor Author

athei commented Jul 20, 2021

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
Copy link
Contributor Author

athei commented Jul 20, 2021

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