rust-osdev / bootimage

Tool to create bootable disk images from a Rust OS kernel.
Apache License 2.0
767 stars 67 forks source link

Fails to link with `rust-lld` with an out of range error in latest Rust Nightly #73

Closed w-henderson closed 3 years ago

w-henderson commented 3 years ago

I'm trying to build a project using bootimage and it successfully builds when I run cargo build (not using bootimage to make it bootable), but fails to compile when I run cargo run on the final step of compiling bootloader with bootimage. I wasn't sure whether to make this issue here or on bootloader, but my project compiles bootloader fine so I figured it was probably an issue with bootimage (or my environment!).

I get the following errors:

rust-lld: error: bootloader.30ac1y0p-cgu.0:(.boot-first-stage+0x81): relocation R_X86_64_16 out of range: 88576 is not in [-32768, 65535]; references _rest_of_bootloader_end_addr
          rust-lld: error: bootloader.30ac1y0p-cgu.0:(.boot+0x6A): relocation R_X86_64_16 out of range: 88576 is not in [-32768, 65535]; references _kernel_start_addr
          >>> defined in C:\Rust\Pogostick\target\bootimage\bootloader\x86_64-bootloader\release\deps\libbootloader-0325a9ea9e448093.rlib(kernel_bin-pogostick.o)

          rust-lld: error: bootloader.30ac1y0p-cgu.0:(.boot+0x85): relocation R_X86_64_16 out of range: 880472 is not in [-32768, 65535]; references _kernel_size
          >>> defined in C:\Rust\Pogostick\target\bootimage\bootloader\x86_64-bootloader\release\deps\libbootloader-0325a9ea9e448093.rlib(kernel_bin-pogostick.o)

My target JSON file looks like this:

{
  "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"
}

As a side note, it tells me I can run with --verbose to get additional info, but when I do, it only applies to the original build and not to bootloader's runner. I've already tried rebooting and running cargo clean.

Any advice would be much appreciated!

w-henderson commented 3 years ago

Update: downgrading to Rust Nightly from 1st March (nightly-2021-03-01) fixed this for me

phil-opp commented 3 years ago

Thanks a lot for reporting! This is a bug in the bootloader crate which was presumably triggered by the recent update to LLVM 12 on Rust nightly. I'm already looking into it.

phil-opp commented 3 years ago

I just published bootloader version 0.9.15. You should be able to fix your errors by running cargo update -p bootloader. Please let me know if there are still problems!