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

Module doesn't install on rustc 1.53.0-nightly #11

Closed
ChoKyuWon opened this issue Mar 22, 2021 · 5 comments
Closed

Module doesn't install on rustc 1.53.0-nightly #11

ChoKyuWon opened this issue Mar 22, 2021 · 5 comments

Comments

@ChoKyuWon
Copy link

Hello. I try to build this repo, but I meet this error:

$make V=1
xargo rustc --release --target=x86_64-linux-kernel
error: failed to run `rustc` to learn about target-specific information

Caused by:
  process didn't exit successfully: `rustc - --crate-name ___ --print=file-names --target x86_64-linux-kernel --crate-type bin --crate-type rlib --crate-type dylib --crate-type cdylib --crate-type staticlib --crate-type proc-macro --print=sysroot --print=cfg` (exit code: 1)
  --- stderr
  error: Error loading target specification: Could not find specification for target "x86_64-linux-kernel". Use `--print target-list` for a list of built-in targets

make: *** [Makefile:21: src/rust.o] Error 101

so I change x86_64-linux-kernel to x86_64-unknown-none-linuxkernel on Makefile and then it build without error.
However, when I try to install the module, follow error is occur.

$sudo insmod parrot.ko
insmod: ERROR: could not insert module parrot.ko: Invalid module format

My toolchain and kernel version is here:

$rustc --version
rustc 1.53.0-nightly (f82664191 2021-03-21)

$uname -a
Linux kyuwon-systemproductname 5.4.80-2-MANJARO #1 SMP PREEMPT Sat Nov 28 09:58:18 UTC 2020 x86_64 GNU/Linux

and module info is here:

$modinfo parrot.ko
filename:       /home/kyuwon/knock-out/parrot.ko
license:        GPL v2
depends:        
retpoline:      Y
name:           parrot
vermagic:       5.4.80-2-MANJARO SMP preempt mod_unload modversions 
@jbaublitz jbaublitz reopened this Mar 27, 2021
@jbaublitz
Copy link
Owner

I'll look into this, but this seems like a bug somewhere in the Rust build system or compiler. I bumped into this early on in my crate where Rust was emitting relocation symbols unacceptable in the kernel. I just checked, and it's doing it again. See this issue for a deeper dive. I may not be able to fix this on my end.

@jbaublitz
Copy link
Owner

Feel free to use the information in my issue linked above and the output of objdump -r parrot.ko (the bad symbols you're looking for are R_X86_64_GOTPCREL) to file an issue upstream if you'd like this resolved.

@joroec
Copy link

joroec commented Apr 21, 2021

Since I looked into this, I just append my insights here. Maybe they are helpful for further analysis.
A new toolchain rustc 1.53.0-nightly (6df26f897 2021-04-20) is available by now.

Unfortunately, the following illegal relocations are generated:

$ objdump -r parrot.ko | grep R_X86_64_GOTPCREL
0000000000000036 R_X86_64_GOTPCREL  _ZN4core3num7flt2dec8strategy5grisu12CACHED_POW1017h03fcb65baeeb9113E-0x0000000000000004
00000000000001bf R_X86_64_GOTPCREL  _ZN4core3num7flt2dec8strategy5grisu12CACHED_POW1017h03fcb65baeeb9113E-0x0000000000000004
0000000000000126 R_X86_64_GOTPCREL  _ZN4core3num7flt2dec8strategy5grisu12CACHED_POW1017h03fcb65baeeb9113E-0x0000000000000004

It is interesting that the R_X86_64_GOTPCREL relocation is only generated for those tree relocations to the flt2dec function. The rest of the core does not seem to be affected.
I cant look into this in more depth by now. However, filing an issue upstream seems to be a good idea, indeed ;-)

@Mic92
Copy link

Mic92 commented May 11, 2021

I also see it being used for memcpy/memset. It can be reproduced when using core::ptr::copy

@jbaublitz
Copy link
Owner

jbaublitz commented Oct 2, 2021

I switched from xargo to build-std in commit 7bd8f6c and this appears to resolve the 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

4 participants