You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
This probably isn't an issue with this crate per-se, but I wanted to bring up this use case just in case someone more versed in rust than me has a solution.
I have noticed that when I declare and construct a distributed_slice in a dependency crate, the entries in the slice declared in the dependency crates do not appear. This is probably due to rust-lang/rust#67209, which seems to point to some kind of linker issue that causes custom sections to disappear across crate boundaries. I don't fully understand that issue and it has been open for some time. I suspect that the issue I'm providing an example for here is just a consequence of linkme's use of custom sections (via link_section) and that bug. I've done a little inspecting of the output elf when I don't have a distributed slice member in a root binary crate (so all members are declared in dependency crates) and the custom section doesn't even appear in the output.
Again, I don't really expect a solution to appear in this crate since it is probably a deeper linker issue, but I wanted to make sure this was mentioned here and possibly advocate for this caveat to be called out on the documentation until it is fixed.
Example
Cargo.toml
[workspace]
members = [
"toplevel",
"dependency",
]
use dependency::do_stuff;mod other;fnmain(){do_stuff();}#[cfg(test)]mod tests {#[test]fnit_works(){
dependency::do_stuff();}}
toplevel/src/other.rs
use linkme::distributed_slice;use dependency::TEST;#[distributed_slice(TEST)]fnroot_test(){println!("Root");}
Expected Behavior
As I have referenced the same distributed slice between crates, I would expect that running my toplevel should print:
Doing stuff
There are 2 items.
Dependency
Root
Actual Behavior
Running the toplevel gives me:
Doing stuff
There are 1 items.
Root
And running the tests gives me:
Compiling dependency v0.1.0 (/home/kcuzner/Projects/Rust/linktest/dependency)
Compiling toplevel v0.1.0 (/home/kcuzner/Projects/Rust/linktest/toplevel)
Finished test [unoptimized + debuginfo] target(s) in 0.41s
Running target/debug/deps/dependency-eafa826fb0a16142
running 1 test
Doing stuff
There are 1 items.
Dependency
test tests::it_works ... ok
test result: ok. 1 passed; 0 failed; 0 ignored; 0 measured; 0 filtered out
Running target/debug/deps/toplevel-48a62a711f6372bb
running 1 test
Doing stuff
There are 1 items.
Root
test tests::it_works ... ok
test result: ok. 1 passed; 0 failed; 0 ignored; 0 measured; 0 filtered out
Doc-tests dependency
running 0 tests
test result: ok. 0 passed; 0 failed; 0 ignored; 0 measured; 0 filtered out
The text was updated successfully, but these errors were encountered:
Dang, this was a duplicate of #31. I think my example is better, but the solution presented there (reference the module (dependency::other in my example) in some way, such as calling a function in that module) does fix the issue.
This probably isn't an issue with this crate per-se, but I wanted to bring up this use case just in case someone more versed in rust than me has a solution.
I have noticed that when I declare and construct a
distributed_slice
in a dependency crate, the entries in the slice declared in the dependency crates do not appear. This is probably due to rust-lang/rust#67209, which seems to point to some kind of linker issue that causes custom sections to disappear across crate boundaries. I don't fully understand that issue and it has been open for some time. I suspect that the issue I'm providing an example for here is just a consequence oflinkme
's use of custom sections (vialink_section
) and that bug. I've done a little inspecting of the output elf when I don't have a distributed slice member in a root binary crate (so all members are declared in dependency crates) and the custom section doesn't even appear in the output.Again, I don't really expect a solution to appear in this crate since it is probably a deeper linker issue, but I wanted to make sure this was mentioned here and possibly advocate for this caveat to be called out on the documentation until it is fixed.
Example
Expected Behavior
As I have referenced the same distributed slice between crates, I would expect that running my toplevel should print:
Actual Behavior
Running the toplevel gives me:
And running the tests gives me:
The text was updated successfully, but these errors were encountered: