-
Notifications
You must be signed in to change notification settings - Fork 236
Clarification on i128 and u128 atomic operation linkage #316
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
Comments
Thanks for the questions! Unfortunately I probably don't have great answers for you :( In general In terms of resolving these symbols, they're typically compiled and linked as such:
So I think a lot of this boils down to kbuild/build systems/etc. It may also depend on different compilers. For example Rust code linked with gcc may not be finding the right compiler builtins. Alternatively the extraction of dealing with a staticlib may be iffy. Rust staticlibs should include all of compiler-builtins's object files, so the should be "just resolved" but it sounds like there's shenanigans which may prevent this. As for why they may not be necessary for the kernel target, it sounds like that may also be related to the build system perhaps? Do you have some build system scripts/commands I could take a look at to see if they match the expected usage of compiler-builtins? |
Interestingly enough, I went to reproduce the issue in a gist and when I tested building it, I got a warning from xargo that indicated compiler_builtins was being included implicitly.
After that, I changed back to cargo as that's what I was originally using, and I seem to have tracked down the problem thanks to your response. It appears that xargo will pull in compiler_builtins regardless of the target. cargo on the other hand requires an explicit inclusion of compiler_builtins and even then, I get these two errors at kbuild link time:
Ultimately, I think using xargo is the simple solution here, even more so because even if the above symbols were to get resolved, the kernel will fail to load the module if it's not linked with a libcore that's been compiled with a different relocation table generation strategy from what is typically used (it should use PLT instead of GOT). I'm still a little confused as to why those two symbols are not resolved in cargo with compiler_builtins and here's a link to a Makefile/Cargo.toml combination in a github gist to use with my kernel module in case you want to try to reproduce it. I'm uncertain if this is maybe an unrelated but relevant error affecting compiler_builtins. I can also imagine that this might never show up in any correctly configured situation if these symbols get optimized out based on various compilation flags that xargo sets properly, so this may also be a non-issue. Regardless, thanks for the input! I'll leave this open for now, but feel free to close it if you determine that the errors above are simply a product of the misuse of cargo here combined with kbuild. |
Move arch-specific behavior and intrinsics to a separate module
I've been working on an example kernel module in Rust for educational purposes, and I bumped into some interesting behavior at link time. The working process is codified here, but prior to this I had some problems with linking that may be of interest to you.
Current state
.a
files)x86_64-linux-kernel
target to make sure libcore doesn't have invalid relocation table entriesThis all works very nicely and there are no longer unresolved symbols even without this crate.
Previous state:
.o
file for thex86_64-unknown-linux-gnu
target using some specific flags:cargo rustc --release -- -C relocation-model=static -C code-model=kernel -Z plt=y --emit=obj=rust.o
This resolved a couple previous problems I bumped into by compiling to the kernel address space and avoiding GOT relocation entries for the .o file itself. However, I ran into a really strange issue when I tweaked this process slightly and started emitting a
.a
file so that I could link to and uselibcore
in my kernel module. I extracted the bundled.o
files, and without compiler-builtins, I got unresolved symbol errors when linking them together and attempting to insert the kernel module. After I included compiler-builtins in Cargo.toml, all of the unresolved symbol errors went away, but two new ones came up. They were both__sync_*_16
symbols which I ultimately determined were builtins for u128 and i128 atomic operations that seem to be styled after the gcc-specific builtins such as__sync_lock_test_and_set
.I ultimately have two questions:
x86_64-linux-kernel
target, I'm a little confused as to why these symbols are not getting resolved through this crate at link time. Do you have any input on why that might be? Could this problem ever pop up when using cargo to generate executables or do you think this may just be a problem with the way that I was going about the build process due to my requirements?The text was updated successfully, but these errors were encountered: