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

Undefined reference in libcore str::str.StrPrelude::bytes::h835a605f8fa9b9b7hWs. #20016

Closed
ckkashyap opened this issue Dec 19, 2014 · 15 comments
Closed

Comments

@ckkashyap
Copy link

Hi,
I am using libcore for my kernel - https://github.com/ckkashyap/unix

I've been using the latest nightly builds. The nightly builds from a few days ago started having an undefined reference to str::str.StrPrelude::bytes::h835a605f8fa9b9b7hWs.

Looks like this is a regression.

Regards,
Kashyap

@ckkashyap
Copy link
Author

This problem was introduced sometime after 10th December

@alexcrichton
Copy link
Member

You actually need to modify how you link to rust code in your kernel. Your build process uses --emit=obj, but that does not include dependencies such as libcore. You'll want to build your kernel as a staticlib (--crate-type=staticlib) and then link the generated archive via ld instead of dealing with object files directly.

Thanks for the issue though!

@ckkashyap
Copy link
Author

Thanks Alex ... sorry I am new to Rust - I'd appreciate it very much if you could provide more details.
I thought crate-type was being set to staticlib already by the directive in kernel.rs.

Are you suggesting that I just need to remove the emit-obj from the command line?

@alexcrichton
Copy link
Member

Yeah you should be fine just deleting that, and then you'll pass libkernel.a instead of kernel.o to the linker.

@ckkashyap
Copy link
Author

After removing the --emit=obj I get
error: could not find native static library compiler-rt, perhaps an -L flag is missing?

@alexcrichton
Copy link
Member

That indicates that libcompiler-rt.a (normally shipped with the standard distribution) was not found by your target. You can disable linking to it through the flexible target specification I believe.

@ckkashyap
Copy link
Author

Thanks Alex ... I'll try it out and post back ... on the move right now

@ckkashyap
Copy link
Author

Awesome .. it worked .... I had to implement a bunch of libc functions though.

A couple of questions bother me though -

  1. How come things worked before the December 10th rust build?
  2. Is it safe to link with compiler-rt for a kernel? How can I find out about what are the capabilities/limitations that comes in with compiler-rt?

I'd appreciate your inputs very much.

Thanks,
Kashyap

@ckkashyap
Copy link
Author

Plus I did not build libcompiler-rt.a - instead I just used the -L to point to it. How can I build libcompiler-rt myself (using my target spec)....It does not seem as straight forward as libcore.

@alexcrichton
Copy link
Member

Linkers often work just by chance if something's not actually supposed to work, so you may have just been getting lucky before the 10th. Currently you'd have to check out compiler-rt from LLVM itself to cross-compile it, there's sadly not a great way to compile it otherwise.

@ckkashyap
Copy link
Author

Oh ... I did not realize that libcompiler-rt.a is part of LLVM ... in that case, I presume, there's no harm in linking with the one that gets built as part of Rust.

Thanks Alex.

@ckkashyap
Copy link
Author

Hey Alex ... happy new year (year of Rust 1.0) ...

Just got back from a break and tried to build my kernel code with the latest RUST and found uart.rs:26:5: 26:26 error: unresolved import core::str::StrPrelude. There is no StrPrelude in core::str

Not sure, what changed .... could you please advice how I can use the bytes function of &str?

Regards,
Kashyap

@alexcrichton
Copy link
Member

The StrPrelude trait has been renamed to StrExt

@ckkashyap
Copy link
Author

Thanks Alex.
Regards,
Kashyap

@nistvan86
Copy link

You can disable linking to it through the flexible target specification I believe.

How exactly did you achieve this @ckkashyap? I'd appreciate it if you could give me some hints. I'm compiling Rust code to Raspberry Pi bare metal and facing the same issue.

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

No branches or pull requests

3 participants