phil-opp / blog_os

Writing an OS in Rust
http://os.phil-opp.com
Apache License 2.0
14.27k stars 1.01k forks source link

Got "relocation R_X86_64_16 out of range:" error in cargo bootimage #937

Closed gentlyj closed 3 years ago

gentlyj commented 3 years ago

I followed the post02 step by step, when I was running cmd : cargo bootimage I got error log:

 = note: rust-lld: error: bootloader.8xx1g5ts-cgu.1:(.boot+0x6A): relocation R_X86_64_16 out of range: 87040 is not in [-32768, 65535]; references _kernel_start_addr
          >>> defined in /home/yang/share/develop/rust/os_code/blog_os-post-02/target/bootimage/bootloader/x86_64-bootloader/release/deps/libbootloader-040dab97d2aff907.rlib(kernel_bin-blog_os.o)

          rust-lld: error: bootloader.8xx1g5ts-cgu.1:(.boot-first-stage+0x81): relocation R_X86_64_16 out of range: 87040 is not in [-32768, 65535]; references _rest_of_bootloader_end_addr

error: aborting due to previous error

error: could not compile `bootloader`

Then I clone the code from branch, got the same error, help~~~

rfrenchy commented 3 years ago

https://github.com/rust-osdev/bootimage/issues/73 i had the same issue and worked-around the same way as w-henderson by downgrading to nightly-2021-03-01

rustup override set nightly-2021-03-01
rustup component add rust-src
rustup component add llvm-tools-preview
cargo bootimage
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.

gentlyj commented 3 years ago

rustup component add llvm-tools-preview

thanks a lot! it works.

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!

EvanMu96 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!

  • Platform: ubuntu-latest (20.04)
  • rustc version: rustc 1.52.0-nightly (51748a8fc 2021-03-05)
  • LLVM version: 12.0.0
  • Version of bootloader: 0.9.15

It failed on linking.

  = note: rust-lld: error: bootloader.2nb1ae77-cgu.0:(.boot+0x87): relocation R_X86_64_16 out of range: 252624 is not in [-32768, 65535]; references _kernel_size

I am not sure why the ci of bootloader repo works fine...

phil-opp commented 3 years ago

@EvanMu96 Thanks for checking! It's probably because _kernel_size is much smaller for the test kernel used on the CI, compared to a real kernel. Give me a moment to fix it.

phil-opp commented 3 years ago

@EvanMu96 I just pushed v0.9.16. Could you try whether this fixes it?

EvanMu96 commented 3 years ago

@EvanMu96 I just pushed v0.9.16. Could you try whether this fixes it?

Fixed. Many thanks!