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

Section contractenvmetav0 not always emitted depending on profile #383

Closed
jonjove opened this issue Aug 1, 2022 · 5 comments · Fixed by #386 or #388
Closed

Section contractenvmetav0 not always emitted depending on profile #383

jonjove opened this issue Aug 1, 2022 · 5 comments · Fixed by #386 or #388
Assignees
Labels
bug Something isn't working

Comments

@jonjove
Copy link
Contributor

jonjove commented Aug 1, 2022

It is emitted when building target. This is unchanged if I remove the calls to wasm-opt.

@jonjove jonjove added the bug Something isn't working label Aug 1, 2022
@jonjove
Copy link
Contributor Author

jonjove commented Aug 1, 2022

I'm unsure at this point if this is a bug in the SDK, a bug in how the token uses the SDK, or something else entirely.

I was able to get this emitted by effectively duplicated the declaration of soroban_sdk::XDR into the token's lib.rs.

@leighmcculloch
Copy link
Member

I ran into this issue last week and the TL;DR of my current opinion is one of:

  • There is a bug in nightly that has just recently changed the behavior of link_section.
  • Or, there was a bug fixed that hasn't made it to stable yet and we are relying on the behavior of the bug.

In my testing I witnessed that this problem only happens if the release profile noted here is not used in conjunction with building with nightly.

If you use the following release profile the problem should be resolved for now:

[profile.release]
opt-level = "z"
overflow-checks = true
debug = 0
strip = "symbols"
debug-assertions = false
panic = "abort"
codegen-units = 1
lto = true

I ran out of time to open an issue about this on the rust repository, but I'll follow up with that today.

@leighmcculloch leighmcculloch transferred this issue from stellar-deprecated/soroban-token-contract Aug 1, 2022
@leighmcculloch leighmcculloch changed the title Section contractenvmetav0 not emitted when building target-tiny Section contractenvmetav0 not emitted when building with nightly without release profile Aug 1, 2022
@leighmcculloch leighmcculloch changed the title Section contractenvmetav0 not emitted when building with nightly without release profile Section contractenvmetav0 not always emitted depending on profile Aug 1, 2022
@leighmcculloch
Copy link
Member

leighmcculloch commented Aug 1, 2022

After reading rust-lang/rust#56639, I now believe my summary above about nightly vs stable is incorrect.

The comment here is likely the issue:

Long story short a custom section always goes into the current codegen unit, but if nothing else is referenced from the codegen unit then the custom section doesn't get included in the final output because the linker never looks at the codegen unit/object file.

Ref: rust-lang/rust#56639 (comment)

In the release profile we recommend, a single codegen unit is used:

codegen-units = 1

This means the custom section is preserved because the unit is always passed to the linker.

Given the custom section is never referenced right now, for anyone not using a single codegen unit it will be a bit random for if this issue occurs or not, because it really just depends how the Rust build system divides logic into codegen units.

There is a comment in the linked issue about in what cases the custom section will be included:

In which crate is the custom section defined? Where is the function containing the section? How is the function containing the custom section called? Is it generated?
External crate Submodule Not called No
External crate Submodule Indirectly No
External crate Submodule Directly Yes
External crate In root Not called No
External crate In root Indirectly Yes
External crate In root Directly Yes
Main crate Any Any Yes

Ref: rust-lang/rust#56639 (comment)

@jonjove
Copy link
Contributor Author

jonjove commented Aug 1, 2022

Reopening this for the moment based on #386 (comment).

@jonjove jonjove reopened this Aug 1, 2022
@leighmcculloch
Copy link
Member

@jonjove It looks like the token contract is still using an old version of soroban-sdk-macros, so it doesn't have the fix that was committed in #386. However, even with the macros crate updated in the token contract it doesn't make a difference, it is still missing.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
2 participants