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

Fix contractenvmetav0 not being emitted (again) #388

Merged
merged 2 commits into from
Aug 1, 2022
Merged

Conversation

leighmcculloch
Copy link
Member

@leighmcculloch leighmcculloch commented Aug 1, 2022

What

Move the link section for contractenvmetav0 into an exported function that is exported in every contract.

Why

In Rust's build system sections only get included into the final build if the object file containing those sections are processed by the linker, but as an optimization step if no code is called in an object file it is discarded. This has the unfortunate effect of causing anything else in those object files, such as link sections, to be discarded. Placing anything that must be included in the build inside an exported function ensures the object files won't be discarded.

wasm-bindgen does a similar thing to this, and so this seems to be a reasonably accepted way to work around this limitation in the build system. (Some more details about their approach here: koute/cargo-web#92 (comment).)

This has an unfortunate side-effect that all contracts will have a function in the resulting WASM named _, however this function won't be rendered in the contract specification. The overhead of this is very minimal on file size. Total overhead is still only 12 bytes on the token contract, and the XDR being embedded is also 12 bytes, so I'm not even sure how that happens, it's as if its free!

This is the second attempted fix to this problem. The first fix was #386. If this fix doesn't stick, I will suggest we simply tell people to always use codegen-units = 1 as I don't think it is worth us to expend more time on working around the compiler.

Close #383

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

Successfully merging this pull request may close these issues.

Section contractenvmetav0 not always emitted depending on profile
1 participant