2021-03-22 00:29:11

by Joshua Abraham

[permalink] [raw]
Subject: drivers/char/rust_example fails to load

I am building Rust-for-Linux at commit
e9b9c0ef1e7040a3c3dc2232d5fd64999eba61a0 with "make CC=clang-11" and
the built kernel fails to load rust_example.ko with the following
error:

[ 1653.507602] module: rust_example: Unknown rela relocation: 9

Looking at elf.h shows this relocation is type GOTPCREL:
#define R_X86_64_GOTPCREL 9 /* 32 bit signed PC relative offset to GOT */

Sure enough rust_example.ko contains a few of these entries, and no
other kernel module does:
000000000a51 008800000009 R_X86_64_GOTPCREL 0000000000000000
_RNvXsb_NtCshGpAVYOtgW - 4
000000000f15 008700000009 R_X86_64_GOTPCREL 0000000000000000
_RNvXs2_NtNtNtCshGpAVY - 4
000000001307 005300000009 R_X86_64_GOTPCREL 0000000000000000
_RNvXs6_NtNtNtCshGpAVY - 4

I assume that this is an issue with my rust toolchain, however I'm
reporting it here since it might be helpful to update documentation or
(unlikely) add support for this relocation type in the kernel.

Host/environment info:
$ uname -a
Linux pop-os 5.8.0-7642-generic #47~1614007149~20.04~82fb226-Ubuntu
SMP Tue Feb 23 02:56:27 UTC
$ rustup show active-toolchain
nightly-x86_64-unknown-linux-gnu (default)
$ rustc --version
rustc 1.52.0-nightly (61edfd591 2021-03-20)
$ clang-11 --version
Ubuntu clang version 11.0.0-2~ubuntu20.04.1
Target: x86_64-pc-linux-gnu
Thread model: posix
InstalledDir: /usr/bin


--
Respectfully,
Josh Abraham


2021-03-22 01:05:22

by Miguel Ojeda

[permalink] [raw]
Subject: Re: drivers/char/rust_example fails to load

Hi Joshua,

On Mon, Mar 22, 2021 at 1:13 AM Joshua Abraham <[email protected]> wrote:
>
> $ rustc --version
> rustc 1.52.0-nightly (61edfd591 2021-03-20)

Please give a go to the nightly from a month ago, i.e. 2021-02-20.

Cheers,
Miguel

2021-03-22 02:55:33

by Joshua Abraham

[permalink] [raw]
Subject: Re: drivers/char/rust_example fails to load

Hey Miguel,

> Please give a go to the nightly from a month ago, i.e. 2021-02-20.

Cheers, using rustc 1.52.0-nightly (9b471a3f5 2021-02-19) fixed the
issue. Interesting that the newer nightly compiler creates these new
relocations for the code!

--
Respectfully,
Josh Abraham

2021-03-22 07:01:49

by Geert Stappers

[permalink] [raw]
Subject: Re: drivers/char/rust_example fails to load 2021-03-20 builds

On Sun, Mar 21, 2021 at 09:53:27PM -0500, Joshua Abraham wrote:
> Hey Miguel,
>
> > Please give a go to the nightly from a month ago, i.e. 2021-02-20.
>
> Cheers, using rustc 1.52.0-nightly (9b471a3f5 2021-02-19) fixed the issue.

How to tell "use older parts in toolchain"?
Yeah, probably a Rust newbie question, still a sincere question.
Was a older version installed? How to tell `rustup` to keep old
versions? Was done with a cargo.toml entry? Or with file
`rust-toolchain`? Please tell (Please spoon feed me ;-)


> Interesting that the newer nightly compiler creates these new
> relocations for the code!

Not each change is an improvement. Hopefully came the change with a
flag to modify the new default behaviour.



Groeten
Geert Stappers
--
Silence is hard to parse

2021-03-22 08:24:45

by Adam Bratschi-Kaye

[permalink] [raw]
Subject: Re: drivers/char/rust_example fails to load 2021-03-20 builds

> How to tell "use older parts in toolchain"?
> Yeah, probably a Rust newbie question, still a sincere question.
> Was a older version installed? How to tell `rustup` to keep old
> versions? Was done with a cargo.toml entry? Or with file
> `rust-toolchain`? Please tell (Please spoon feed me ;-)

Using `rust-toolchain.toml` should work.
Another option would be to override the default version for the given
directory with
`rustup override set nightly-2021-02-20`.

You could also set the global default `rustc` to a specific nightly release:
`rustup default nightly-2021-02-20`.

More info here: https://rust-lang.github.io/rustup/overrides.html

2021-03-22 12:23:23

by Miguel Ojeda

[permalink] [raw]
Subject: Re: drivers/char/rust_example fails to load

Hi Joshua,

On Mon, Mar 22, 2021 at 3:53 AM Joshua Abraham <[email protected]> wrote:
>
> Cheers, using rustc 1.52.0-nightly (9b471a3f5 2021-02-19) fixed the
> issue. Interesting that the newer nightly compiler creates these new
> relocations for the code!

Thanks a lot for the report and for confirming that worked for you!

I'll take a look at fixing those soon.

Cheers,
Miguel

2021-03-23 01:29:03

by Miguel Ojeda

[permalink] [raw]
Subject: Re: drivers/char/rust_example fails to load

On Mon, Mar 22, 2021 at 1:20 PM Miguel Ojeda
<[email protected]> wrote:
>
> I'll take a look at fixing those soon.

For those that may read this or run into the same issue: this started
with the LLVM 12 upgrade in rustc nightlies. Therefore, please avoid
the very latest nightlies (>= nightly-2021-03-05) until [1] is
resolved.

To automatically setup a known-to-work nightly for Rust for Linux (the
one we use the most in the CI), run:

rustup default nightly-2021-02-20

[1] https://github.com/Rust-for-Linux/linux/issues/135

Cheers,
Miguel