Reputation: 3
I have been following this tutorial for writing an OS in rust: https://os.phil-opp.com/minimal-rust-kernel/ As soon as I try to compile it with the x86_64-blog_os.json target, it throws this linker error:
error: linking with 'cc' failed: exit status: 1
|
= note: LC_ALL="C" PATH= ......
..... = note: /usr/bin/ld: /usr/lib/gcc/x86_64-linux-gnu/10/../../../x86_64-linux-gnu/Scrt1.o: unrecognized relocation (0x2a) in section '.text'
/usr/bin/ld: final link failed: Bad value
collect2: error: ld returned 1 exit status
error: could not compile 'compiler_builtins' (build script) due to previous error
When I was installing rust the first time on my machine, i accidentally stopped the installation script while it was running. I thought this was the problem so i deleted rust and reinstalled it. Unfortunately this didn't solve the issue.
x86_64-blog_os.json file:
{
"llvm-target": "x86_64-unknown-none",
"data-layout": "e-m:e-i64:64-f80:128-n8:16:32:64-S128",
"arch": "x86_64",
"target-endian": "little",
"target-pointer-width": "64",
"target-c-int-width": "32",
"os": "none",
"executables": true,
"linker-flavor": "ld.lld",
"linker": "rust-lld",
"panic-strategy": "abort",
"disable-redzone": true,
"features": "-mmx,-sse,+soft-float"
}
.cargo/config.toml file:
[unstable]
build-std = ["core", "compiler_builtins"]
Cargo.toml file:
[package]
name = "blog_os"
version = "0.1.0"
edition = "2018"
[dependencies]
Toolchain: nightly-x86_64-unknown-linux-gnu (default) rustc: 1.72.0-nightly
Edit: I just found out this happens when i try to compile anywhere, not just this target. Updating toolchain doesn't work
Edit 2.: I solved the issue. There was a problem with binutils. All i needed to do was apt purge
it and reinstall it. Closing the question.
Upvotes: 0
Views: 680
Reputation: 3
I found the answer to my question. It looks like an issue with Scrt1.o. All i needed to do is delete binutils and reinstall it.
sudo apt purge binutils
sudo apt install binutils
Upvotes: 0