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

Feature request: tunable for extern function definition ELF relocation type #57390

Closed
jbaublitz opened this issue Jan 6, 2019 · 3 comments
Closed
Labels
A-linkage Area: linking into static, shared libraries and binaries O-linux Operating system: Linux

Comments

@jbaublitz
Copy link

I have a prototype of a toy Linux kernel module written in Rust. I previously had it working until recently when I rebuilt it with a newer version of Rust and LLVM and insmod module.ko started throwing an error in dmesg logs about unknown rela relocation 9. I did a readelf and realized that all of the extern "C" functions I'd declared were generating ELF entries with the R_X86_64_GOTPCREL relocation entry type which is defined as having a value of 9. This is apparently illegal for kernel modules after looking at the allowable ELF relocation types in the kernel module infrastructure.

I have a few questions:

  1. Is this change recent?
  2. If so, was this a change on the Rust side or LLVM side?
  3. Would you be willing to work with me on either finding a linking-based solution (if possible) or a PR for tuning the resulting relocation type of extern-declared functions?

I am not sure if there's a simple linking flag I'm missing but the ones I've tested, as well as using any of the relocation strategies available through codegen options, yield the same results.

@jonas-schievink jonas-schievink added A-linkage Area: linking into static, shared libraries and binaries O-linux Operating system: Linux labels Jan 27, 2019
@jason-ni
Copy link

jason-ni commented Mar 27, 2019

Another rust linux kernel module project is also blocking on this issue. fishinabarrel/linux-kernel-module-rust#67 .

We can use "needs-plt": true to avoid R_X86_64_GOTPCREL.

@jbaublitz
Copy link
Author

@jason-ni Let me try that and see if this resolves it. Thanks for pointing me in that direction.

@jbaublitz
Copy link
Author

Hey @jason-ni, thank you so much for your help! I was able to resolve this with the following options on newer Rust compilers: --crate-type=staticlib -C relocation-model=static -C code-model=kernel -Z plt=y. I'm gonna close this out.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-linkage Area: linking into static, shared libraries and binaries O-linux Operating system: Linux
Projects
None yet
Development

No branches or pull requests

3 participants