-
Notifications
You must be signed in to change notification settings - Fork 13.2k
New issue
Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? # to your account
Building a no_std cdylib results in "syntax error in VERSION script" #63925
Comments
The closest related issue I could find was #50887, but it appears that the issue was closed without ever being directly addressed. |
Is this also random like #50887, or does it happen every time? |
It happens every time for me. I would be interested in seeing if the issue is reproducible by others using the example code posted above. |
Does not happen for me, but I link with LLD |
I installed LLD and ran |
I think the offending version script is being generated here: rust/src/librustc_codegen_ssa/back/linker.rs Lines 394 to 443 in 8b94e9e
|
What does |
I've been trying to come up with a way to grab the generated file, but it looks like the process cleans up the temp files before I can look at them. ld version:
|
I managed to set up an
This is clearly being built in the following snippet: rust/src/librustc_codegen_ssa/back/linker.rs Lines 430 to 439 in 8b94e9e
So it looks to me like some additional logic is needed to handle the case where self.info.exports[&crate_type] is empty. |
I can reproduce this when using normal binutils ld (2.32). According to
|
The fact that no symbols were being exported threw me for a loop, until I realized that I needed to add some additional code to make the symbols come out correctly. I changed the original #[no_mangle]
pub extern "C" fn foo(a: i32, b: i32) -> i32 {
a + b
} Now, after building and running
and, even better, I can now build without having to pass in So this whole thing was caused by creating a |
Yes, this should ideally just work (unless it isn't possible to link?) |
Agreed, I'll try to get a PR put together in the next day or two. |
…michaelwoerister Prevent syntax error in LD linker version script As discussed in rust-lang#63925, there is an edge case in which an invalid LD version script is generated when building a `cdylib` with no exported symbols. This PR makes a slight modification to the LD version script generation by first checking to see if any symbols need to be exported. If not, the `global` section of the linker script is simply omitted, and the syntax error is averted.
I'm trying to build a pure
no_std
cdylib
with no external library dependencies. For an initial proof of concept, I tried to create such a library using the following code:Cargo.toml
:src/lib.rs
Built using the following command:
cargo +nightly build --lib
Results in the following output:
However, if
crate-type
is changed to["dylib"]
, it builds properly.Tested using the following tool versions:
cargo 1.39.0-nightly (3f700ec43 2019-08-19)
The text was updated successfully, but these errors were encountered: