phil-opp / blog_os

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

error: linking with `rust-lld` failed #1160

Closed ajadavis closed 1 year ago

ajadavis commented 1 year ago

following along edition 2, and currently finishing "minimal-rust-kernel"

getting this error when running "cargo bootimage":

"error: linking with rust-lld failed: exit status: 1:

when i run "rustc --version" i get output: "rustc 1.66.0-nightly (db0597f56 2022-10-11)"

so i think the nightly build setting is ok.

contents of ./.cargo/config.toml:

[unstable]
build-std-features = ["compiler-builtins-mem"]
build-std = ["core", "compiler_builtins"]

[build]
target = "x86_64-blog_os.json"

contents of "x86_64-blog_os.json":

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

i've got "bootloader = "0.9.8"" as a dependency in Cargo.toml (running v 10 gave issues before, but following along the blog's version now seems ok.

im on macOS Monterey v12.5 chip is an M1 max

doing some more research into rust-lld, but couldn't find anything in first pass. next step is to learn more about rust-lld from ground up. thx in advance if anyone knows the issue!

feoxide commented 1 year ago

I'm seeing the same issue. Here's the full error output:

` = note: rust-lld: error: undefined symbol: _rest_of_bootloader_start_addr

referenced by bootloader.715ae32a-cgu.1 ~/flint/target/bootimage/bootloader/x86_64-bootloader/release/deps/bootloader-d2c531ea42821f4b.bootloader.715ae32a-cgu.1.rcgu.o:(.boot-first-stage+0x60) referenced by bootloader.715ae32a-cgu.1 ~/flint/target/bootimage/bootloader/x86_64-bootloader/release/deps/bootloader-d2c531ea42821f4b.bootloader.715ae32a-cgu.1.rcgu.o:(.boot-first-stage+0x7B)

      rust-lld: error: undefined symbol: _rest_of_bootloader_end_addr
      >>> referenced by bootloader.715ae32a-cgu.1
      >>>               ~/flint/target/bootimage/bootloader/x86_64-bootloader/release/deps/bootloader-d2c531ea42821f4b.bootloader.715ae32a-cgu.1.rcgu.o:(.boot-first-stage+0x81)

      rust-lld: error: undefined symbol: _kernel_buffer
      >>> referenced by bootloader.715ae32a-cgu.1
      >>>               ~/flint/target/bootimage/bootloader/x86_64-bootloader/release/deps/bootloader-d2c531ea42821f4b.bootloader.715ae32a-cgu.1.rcgu.o:(.boot+0x59)

      rust-lld: error: undefined symbol: _memory_map
      >>> referenced by bootloader.715ae32a-cgu.1
      >>>               ~/flint/target/bootimage/bootloader/x86_64-bootloader/release/deps/bootloader-d2c531ea42821f4b.bootloader.715ae32a-cgu.1.rcgu.o:(.boot+0xCA)
      >>> referenced by main.rs:108 (src/main.rs:108)
      >>>               ~/flint/target/bootimage/bootloader/x86_64-bootloader/release/deps/bootloader-d2c531ea42821f4b.bootloader.715ae32a-cgu.1.rcgu.o:(stage_4)

      rust-lld: error: undefined symbol: __page_table_start
      >>> referenced by bootloader.715ae32a-cgu.1
      >>>               ~/flint/target/bootimage/bootloader/x86_64-bootloader/release/deps/bootloader-d2c531ea42821f4b.bootloader.715ae32a-cgu.1.rcgu.o:(.boot+0x1A1)
      >>> referenced by bootloader.715ae32a-cgu.1
      >>>               ~/flint/target/bootimage/bootloader/x86_64-bootloader/release/deps/bootloader-d2c531ea42821f4b.bootloader.715ae32a-cgu.1.rcgu.o:(.boot+0x20C)
      >>> referenced by bootloader.715ae32a-cgu.1
      >>>               ~/flint/target/bootimage/bootloader/x86_64-bootloader/release/deps/bootloader-d2c531ea42821f4b.bootloader.715ae32a-cgu.1.rcgu.o:(.boot+0x219)
      >>> referenced 2 more times

      rust-lld: error: undefined symbol: __page_table_end
      >>> referenced by bootloader.715ae32a-cgu.1
      >>>               ~/flint/target/bootimage/bootloader/x86_64-bootloader/release/deps/bootloader-d2c531ea42821f4b.bootloader.715ae32a-cgu.1.rcgu.o:(.boot+0x1A6)
      >>> referenced by main.rs:111 (src/main.rs:111)
      >>>               ~/flint/target/bootimage/bootloader/x86_64-bootloader/release/deps/bootloader-d2c531ea42821f4b.bootloader.715ae32a-cgu.1.rcgu.o:(stage_4)
      >>> referenced by main.rs:105 (src/main.rs:105)
      >>>               ~/flint/target/bootimage/bootloader/x86_64-bootloader/release/deps/bootloader-d2c531ea42821f4b.bootloader.715ae32a-cgu.1.rcgu.o:(stage_4)

      rust-lld: error: undefined symbol: _p3
      >>> referenced by bootloader.715ae32a-cgu.1
      >>>               ~/flint/target/bootimage/bootloader/x86_64-bootloader/release/deps/bootloader-d2c531ea42821f4b.bootloader.715ae32a-cgu.1.rcgu.o:(.boot+0x1B4)
      >>> referenced by bootloader.715ae32a-cgu.1
      >>>               ~/flint/target/bootimage/bootloader/x86_64-bootloader/release/deps/bootloader-d2c531ea42821f4b.bootloader.715ae32a-cgu.1.rcgu.o:(.boot+0x1C9)

      rust-lld: error: undefined symbol: _p4
      >>> referenced by bootloader.715ae32a-cgu.1
      >>>               ~/flint/target/bootimage/bootloader/x86_64-bootloader/release/deps/bootloader-d2c531ea42821f4b.bootloader.715ae32a-cgu.1.rcgu.o:(.boot+0x1BC)
      >>> referenced by bootloader.715ae32a-cgu.1
      >>>               ~/flint/target/bootimage/bootloader/x86_64-bootloader/release/deps/bootloader-d2c531ea42821f4b.bootloader.715ae32a-cgu.1.rcgu.o:(.boot+0x24C)
      >>> referenced by main.rs:114 (src/main.rs:114)
      >>>               ~/flint/target/bootimage/bootloader/x86_64-bootloader/release/deps/bootloader-d2c531ea42821f4b.bootloader.715ae32a-cgu.1.rcgu.o:(stage_4)
      >>> referenced 1 more times

      rust-lld: error: undefined symbol: _p2
      >>> referenced by bootloader.715ae32a-cgu.1
      >>>               ~/flint/target/bootimage/bootloader/x86_64-bootloader/release/deps/bootloader-d2c531ea42821f4b.bootloader.715ae32a-cgu.1.rcgu.o:(.boot+0x1C1)
      >>> referenced by bootloader.715ae32a-cgu.1
      >>>               ~/flint/target/bootimage/bootloader/x86_64-bootloader/release/deps/bootloader-d2c531ea42821f4b.bootloader.715ae32a-cgu.1.rcgu.o:(.boot+0x1D6)
      >>> referenced by bootloader.715ae32a-cgu.1
      >>>               ~/flint/target/bootimage/bootloader/x86_64-bootloader/release/deps/bootloader-d2c531ea42821f4b.bootloader.715ae32a-cgu.1.rcgu.o:(.boot+0x1FB)

      rust-lld: error: undefined symbol: _p1
      >>> referenced by bootloader.715ae32a-cgu.1
      >>>               ~/flint/target/bootimage/bootloader/x86_64-bootloader/release/deps/bootloader-d2c531ea42821f4b.bootloader.715ae32a-cgu.1.rcgu.o:(.boot+0x1CE)
      >>> referenced by bootloader.715ae32a-cgu.1
      >>>               ~/flint/target/bootimage/bootloader/x86_64-bootloader/release/deps/bootloader-d2c531ea42821f4b.bootloader.715ae32a-cgu.1.rcgu.o:(.boot+0x231)
      >>> referenced by bootloader.715ae32a-cgu.1
      >>>               ~/flint/target/bootimage/bootloader/x86_64-bootloader/release/deps/bootloader-d2c531ea42821f4b.bootloader.715ae32a-cgu.1.rcgu.o:(.boot+0x371)

      rust-lld: error: undefined symbol: __bootloader_end
      >>> referenced by bootloader.715ae32a-cgu.1
      >>>               ~/flint/target/bootimage/bootloader/x86_64-bootloader/release/deps/bootloader-d2c531ea42821f4b.bootloader.715ae32a-cgu.1.rcgu.o:(.boot+0x221)
      >>> referenced by main.rs:113 (src/main.rs:113)
      >>>               ~/flint/target/bootimage/bootloader/x86_64-bootloader/release/deps/bootloader-d2c531ea42821f4b.bootloader.715ae32a-cgu.1.rcgu.o:(stage_4)
      >>> referenced by main.rs:105 (src/main.rs:105)
      >>>               ~/flint/target/bootimage/bootloader/x86_64-bootloader/release/deps/bootloader-d2c531ea42821f4b.bootloader.715ae32a-cgu.1.rcgu.o:(stage_4)

      rust-lld: error: undefined symbol: __bootloader_start
      >>> referenced by main.rs:112 (src/main.rs:112)
      >>>               ~/flint/target/bootimage/bootloader/x86_64-bootloader/release/deps/bootloader-d2c531ea42821f4b.bootloader.715ae32a-cgu.1.rcgu.o:(stage_4)
      >>> referenced by main.rs:105 (src/main.rs:105)
      >>>               ~/flint/target/bootimage/bootloader/x86_64-bootloader/release/deps/bootloader-d2c531ea42821f4b.bootloader.715ae32a-cgu.1.rcgu.o:(stage_4)

error: could not compile "bootloader" due to previous error Error: Bootloader build failed. Stderr: `

tsatke commented 1 year ago

rust-osdev/bootloader#271 https://github.com/rust-lang/rust/pull/102836

Should already be fixed, the boot loader build is green again too, try again after upgrading to the latest nightly

ajadavis commented 1 year ago

Incredible. Working for me after upgrading to latest nightly- many thanks!