Skip to content
This repository has been archived by the owner on Jan 14, 2024. It is now read-only.

Targetting new kernels and new versions of Rust Nightly #5

Open
hMihaiDavid opened this issue Mar 23, 2021 · 0 comments
Open

Targetting new kernels and new versions of Rust Nightly #5

hMihaiDavid opened this issue Mar 23, 2021 · 0 comments

Comments

@hMihaiDavid
Copy link

Hi, thank you for this repository.

I am trying to write a minimal kernel driver based on this repo (without the bindgen) and I encountered some issue:

  • On recent kernel version, apparently you can't link a .a, so helloworld-objs := target/$(TARGET)/$(BUILD)/libhello_world.a does not work. I got a workaround by extracting the .o files with ar -x foo.a and linking the .o files into a single .o like this: ld -relocatable *.o -o final.o. It is this object that replaces the .a in the makefile.
  • The object files corresponding with libcore and family (all except the hello-*.o one) contain relocations of type R_X86_64_GOTPCREL. I don't know if this happened on older versions of rust, I use the most recent one as of today, which is rustc 1.53.0-nightly. These relocs end up in the .o amalgamation (final.o) and eventually in the resulting .ko module. The kernel is not able to resolve these relocations when it loads the module, failing withmodule: 8888: Unknown rela relocation: 9. 9 is the type of relocation mentioned above. I tried playing with the settings in the JSON target configuration, I tried changing the relocation model, adding -fplt to the pre-link gcc options and adding the "needs-plt": true. They seem to have no effect. The object file corresponding with the driver crate has a PLT and no GOTPCREL relocations invariantly, which is what I want, but the libcore objects contain those kind of relocations, which end up in the final module and make it unloadable by the kernel.

I would appreciate any help in this regard and it could lead eventually to make this repo work with recent versions of the kernel and rust.

Related links

fishinabarrel/linux-kernel-module-rust#173
https://users.rust-lang.org/t/how-can-i-enable-plt-in-a-custom-target/57332
https://internals.rust-lang.org/t/function-calls-plt-vs-gotpcrel/8909

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant