-
Notifications
You must be signed in to change notification settings - Fork 12.9k
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
Handle .init_array link_section specially on wasm #121533
Conversation
if attrs | ||
.link_section | ||
.map(|link_section| !link_section.as_str().starts_with(".init_array")) | ||
.unwrap_or(true) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I guess this could just be unwrap() because of the early return on line 158-159
Does |
No, neither helps, nor does passing |
And adding |
Doesn't appear to help either. I should probably mention if it helps I'm using the wasi-root for the current download version of wasi-sdk. |
r? compiler |
// show up, reject it here. | ||
// For the wasm32 target statics with `#[link_section]` other than `.init_array` | ||
// are placed into custom sections of the final output file, but this isn't link | ||
// custom sections of other executable formats. Namely we can only embed a list |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pre-existing, but might as well fix it: "this isn't link custom sections..." is nonsensical phrasing. I'm not sure what the correct words would be.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe s/link/like?
I'm not really sure any of the things discussed are worth putting into a comment, in particular they are limitations of the wasm-ld linker, and could change easily without notice. I had considered putting it into a comment. But it really feels like something which is just bound to become stale and out of date if at some point in the future if the linker is ever fixed. It does feel like that stuff could/should be documented somewhere, but perhaps the best place for it to be documented is by linker itself? |
What about a comment like this: "the wasm-ld linker currently has $LIMITATION, so we work around it by doing $X. If this limitation is lifted in the future we can instead do $Y"? I can imagine somebody in the future finding that comment extremely useful, in a Chesterton's Fence kind of way. |
I tried to fix up most of the review comments, and added a new comment like you asked. |
✌️ @ratmice, you can now approve this pull request! If @nnethercote told you to " |
Forgot about this one for a bit, so it has been a bit longer than a week. |
…ethercote Handle .init_array link_section specially on wasm Given that wasm-ld now has support for [.init_array](https://github.com/llvm/llvm-project/blob/8f2bd8ae68883592a333f4bdbed9798d66e68630/llvm/lib/MC/WasmObjectWriter.cpp#L1852), it appears we can easily implement that section by falling through to the normal path rather than taking the typical custom_section path for wasm. The wasm-ld appears to have a bunch of limitations. Only one static with the `link_section` in a crate or else you hit the fatal error in the link above "only one .init_array section fragment supported". They do not get merged. You can still call multiple constructors by setting it to an array. ``` unsafe extern "C" fn ctor() { println!("foo"); } #[used] #[link_section = ".init_array"] static FOO: [unsafe extern "C" fn(); 2] = [ctor, ctor]; ``` Another issue appears to be that if crate *A* depends on crate *B*, but *A* doesn't call any symbols from *B* and *B* doesn't `#[export_name = ...]` any symbols, then crate *B*'s constructor will not be called. The workaround to this is to provide an exported symbol in crate *B*.
…llaumeGomez Rollup of 5 pull requests Successful merges: - rust-lang#121533 (Handle .init_array link_section specially on wasm) - rust-lang#123196 (Add Process support for UEFI) - rust-lang#127621 (Rewrite and rename `issue-22131` and `issue-26006` `run-make` tests to rmake) - rust-lang#127928 (Migrate `lto-smoke-c` and `link-path-order` `run-make` tests to rmake) - rust-lang#127935 (Change `binary_asm_labels` to only fire on x86 and x86_64) r? `@ghost` `@rustbot` modify labels: rollup
…llaumeGomez Rollup of 5 pull requests Successful merges: - rust-lang#121533 (Handle .init_array link_section specially on wasm) - rust-lang#123196 (Add Process support for UEFI) - rust-lang#127621 (Rewrite and rename `issue-22131` and `issue-26006` `run-make` tests to rmake) - rust-lang#127928 (Migrate `lto-smoke-c` and `link-path-order` `run-make` tests to rmake) - rust-lang#127935 (Change `binary_asm_labels` to only fire on x86 and x86_64) r? `@ghost` `@rustbot` modify labels: rollup
Rollup of 7 pull requests Successful merges: - rust-lang#121533 (Handle .init_array link_section specially on wasm) - rust-lang#127825 (Migrate `macos-fat-archive`, `manual-link` and `archive-duplicate-names` `run-make` tests to rmake) - rust-lang#127891 (Tweak suggestions when using incorrect type of enum literal) - rust-lang#127902 (`collect_tokens_trailing_token` cleanups) - rust-lang#127928 (Migrate `lto-smoke-c` and `link-path-order` `run-make` tests to rmake) - rust-lang#127935 (Change `binary_asm_labels` to only fire on x86 and x86_64) - rust-lang#127953 ([compiletest] Search *.a when getting dynamic libraries on AIX) r? `@ghost` `@rustbot` modify labels: rollup
Rollup merge of rust-lang#121533 - ratmice:wasm_init_fini_array, r=nnethercote Handle .init_array link_section specially on wasm Given that wasm-ld now has support for [.init_array](https://github.com/llvm/llvm-project/blob/8f2bd8ae68883592a333f4bdbed9798d66e68630/llvm/lib/MC/WasmObjectWriter.cpp#L1852), it appears we can easily implement that section by falling through to the normal path rather than taking the typical custom_section path for wasm. The wasm-ld appears to have a bunch of limitations. Only one static with the `link_section` in a crate or else you hit the fatal error in the link above "only one .init_array section fragment supported". They do not get merged. You can still call multiple constructors by setting it to an array. ``` unsafe extern "C" fn ctor() { println!("foo"); } #[used] #[link_section = ".init_array"] static FOO: [unsafe extern "C" fn(); 2] = [ctor, ctor]; ``` Another issue appears to be that if crate *A* depends on crate *B*, but *A* doesn't call any symbols from *B* and *B* doesn't `#[export_name = ...]` any symbols, then crate *B*'s constructor will not be called. The workaround to this is to provide an exported symbol in crate *B*.
Given that wasm-ld now has support for .init_array, it appears we can easily implement that section by falling through to the normal path rather than taking the typical custom_section path for wasm.
The wasm-ld appears to have a bunch of limitations. Only one static with the
link_section
in a crate or else you hit the fatal error in the link above "only one .init_array section fragment supported". They do not get merged.You can still call multiple constructors by setting it to an array.
Another issue appears to be that if crate A depends on crate B, but A doesn't call any symbols from B and B doesn't
#[export_name = ...]
any symbols, then crate B's constructor will not be called. The workaround to this is to provide an exported symbol in crate B.