build.rs 1.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  1. use std::{env, path::PathBuf};
  2. fn main() {
  3. let out = PathBuf::from(env::var_os("OUT_DIR").unwrap());
  4. let ld = &out.join("rustsbi-test-kernel.ld");
  5. std::fs::write(ld, LINKER_SCRIPT).unwrap();
  6. println!("cargo:rustc-link-arg=-T{}", ld.display());
  7. println!("cargo:rustc-link-search={}", out.display());
  8. }
  9. const LINKER_SCRIPT: &[u8] = b"OUTPUT_ARCH(riscv)
  10. ENTRY(_start)
  11. SECTIONS {
  12. . = 0x80200000;
  13. .text : ALIGN(8) {
  14. *(.text.entry)
  15. *(.text .text.*)
  16. }
  17. .rodata : ALIGN(8) {
  18. srodata = .;
  19. *(.rodata .rodata.*)
  20. *(.srodata .srodata.*)
  21. . = ALIGN(8);
  22. erodata = .;
  23. }
  24. .data : ALIGN(8) {
  25. sdata = .;
  26. *(.data .data.*)
  27. *(.sdata .sdata.*)
  28. . = ALIGN(8);
  29. edata = .;
  30. }
  31. sidata = LOADADDR(.data);
  32. .bss (NOLOAD) : ALIGN(8) {
  33. *(.bss.uninit)
  34. sbss = .;
  35. *(.bss .bss.*)
  36. *(.sbss .sbss.*)
  37. ebss = .;
  38. }
  39. /DISCARD/ : {
  40. *(.eh_frame)
  41. }
  42. }";