Skip to content

Fix building with new rust-nightly.#561

Draft
jarovo wants to merge 4 commits intorust-osdev:mainfrom
jarovo:main
Draft

Fix building with new rust-nightly.#561
jarovo wants to merge 4 commits intorust-osdev:mainfrom
jarovo:main

Conversation

@jarovo
Copy link
Copy Markdown

@jarovo jarovo commented May 9, 2026

  • Fixes to enable compiling with new rust.
    after bumping the tempfile to use new deps, there was this linker issue to be fixed:
 = note: rust-lld: error: /home/jhenner/projects/bootloader/target/i386-code16-stage-2/stage-2/deps/bootloader_x86_64_bios_stage_2-2a60fabcbb129033.bootloader_x86_64_bios_stage_2.3f4927ae6a5f4601-cgu.0.rcgu.o:(function bootloader_x86_64_bios_stage_2::start: .text._RNvCs5qRQZAVXUQf_30bootloader_x86_64_bios_stage_25start+0x251): relocation R_386_16 out of range: 73531 is not in [-32768, 65535]; references section '.bss._RNvNvXNtCs5qRQZAVXUQf_30bootloader_x86_64_bios_stage_24diskNtB4_10DiskAccessNtB4_4Read10read_exact7TMP_BUF'

To address this I made disk_buffer a stack variable instead of static variable because the now large .text region pushed the .bss so much that it didn't fit to the 16bit address range ( the .text precedes the .bss in the stage-2-link.ld file). Another advantage is that this allowed me to remove the unsafe block. I think I was getting some memory corruption when dealing with the references to the static mem region.

  • Enlarge the stack.
    IIRC After moving the disk_buffer to the stack the some of the tests BIOS boot and then nothing was happening. After changing the ESP to 0x00080000 all the tests are passing. Only the large_ramdisk test sometimes fails. It seems to be flaky - many times it passes.

@Freax13
Copy link
Copy Markdown
Member

Freax13 commented May 10, 2026

  • Fixes to enable compiling with new rust.
    after bumping the tempfile to use new deps, there was this linker issue to be fixed:
 = note: rust-lld: error: /home/jhenner/projects/bootloader/target/i386-code16-stage-2/stage-2/deps/bootloader_x86_64_bios_stage_2-2a60fabcbb129033.bootloader_x86_64_bios_stage_2.3f4927ae6a5f4601-cgu.0.rcgu.o:(function bootloader_x86_64_bios_stage_2::start: .text._RNvCs5qRQZAVXUQf_30bootloader_x86_64_bios_stage_25start+0x251): relocation R_386_16 out of range: 73531 is not in [-32768, 65535]; references section '.bss._RNvNvXNtCs5qRQZAVXUQf_30bootloader_x86_64_bios_stage_24diskNtB4_10DiskAccessNtB4_4Read10read_exact7TMP_BUF'

To address this I made disk_buffer a stack variable instead of static variable because the now large .text region pushed the .bss so much that it didn't fit to the 16bit address range ( the .text precedes the .bss in the stage-2-link.ld file). Another advantage is that this allowed me to remove the unsafe block. I think I was getting some stack corruption when dealing with the references to the static mem region.

This was possibly already fixed by #521/#522.

@jarovo jarovo force-pushed the main branch 3 times, most recently from 951729a to fc8b4cc Compare May 10, 2026 14:13
jarovo added 3 commits May 10, 2026 20:55
This workarounds a problem with clippy:
```
Error:   --> tests/test_kernels/stack_address/src/bin/basic_boot.rs:27:1
   |
27 | / fn panic(info: &core::panic::PanicInfo) -> ! {
28 | |     use core::fmt::Write;
29 | |
30 | |     let _ = writeln!(test_kernel_stack_address::serial(), "PANIC: {info}");
31 | |     exit_qemu(QemuExitCode::Failed);
32 | | }
   | |_^
   |
   = note: the lang item is first defined in crate `std` (which `bitflags` depends on)
   = note: first definition in `std` loaded from /home/runner/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/rustlib/x86_64-unknown-linux-gnu/lib/libstd-dd28cbf307893515.rmeta
   = note: second definition in the local crate (`basic_boot`)
```
@jarovo
Copy link
Copy Markdown
Author

jarovo commented May 10, 2026

  • Fixes to enable compiling with new rust.
    after bumping the tempfile to use new deps, there was this linker issue to be fixed:
 = note: rust-lld: error: /home/jhenner/projects/bootloader/target/i386-code16-stage-2/stage-2/deps/bootloader_x86_64_bios_stage_2-2a60fabcbb129033.bootloader_x86_64_bios_stage_2.3f4927ae6a5f4601-cgu.0.rcgu.o:(function bootloader_x86_64_bios_stage_2::start: .text._RNvCs5qRQZAVXUQf_30bootloader_x86_64_bios_stage_25start+0x251): relocation R_386_16 out of range: 73531 is not in [-32768, 65535]; references section '.bss._RNvNvXNtCs5qRQZAVXUQf_30bootloader_x86_64_bios_stage_24diskNtB4_10DiskAccessNtB4_4Read10read_exact7TMP_BUF'

To address this I made disk_buffer a stack variable instead of static variable because the now large .text region pushed the .bss so much that it didn't fit to the 16bit address range ( the .text precedes the .bss in the stage-2-link.ld file). Another advantage is that this allowed me to remove the unsafe block. I think I was getting some stack corruption when dealing with the references to the static mem region.

This was possibly already fixed by #521/#522.

Yes, it seems like got fixed before me noticing it.

May I ask you to leave a comment on the idea of making the disk_buffer on stack in stage-2 and setting the base of the stack to 0x00080000 in stage-3 to make it fit the kernel while removing the unsafe section? Perhaps I am missing something, but I think we don't need to preserve the stack between the stages. It is something I would like to check before I un-mark this as Draft.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants