build.rs 1.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  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-prototyper.ld");
  5. std::fs::write(ld, LINKER_SCRIPT).unwrap();
  6. println!("cargo:rerun-if-env-changed=RUST_LOG");
  7. println!("cargo:rustc-link-arg=-T{}", ld.display());
  8. println!("cargo:rustc-link-search={}", out.display());
  9. }
  10. const LINKER_SCRIPT: &[u8] = b"OUTPUT_ARCH(riscv)
  11. ENTRY(_start)
  12. SECTIONS {
  13. . = 0x80100000;
  14. .text : ALIGN(8) {
  15. *(.text.entry)
  16. *(.text .text.*)
  17. }
  18. .rodata : ALIGN(8) {
  19. srodata = .;
  20. *(.rodata .rodata.*)
  21. *(.srodata .srodata.*)
  22. . = ALIGN(8);
  23. erodata = .;
  24. }
  25. .data : ALIGN(8) {
  26. sdata = .;
  27. *(.data .data.*)
  28. *(.sdata .sdata.*)
  29. . = ALIGN(8);
  30. edata = .;
  31. }
  32. sidata = LOADADDR(.data);
  33. .bss (NOLOAD) : ALIGN(8) {
  34. *(.bss.uninit)
  35. sbss = .;
  36. *(.bss .bss.*)
  37. *(.sbss .sbss.*)
  38. ebss = .;
  39. }
  40. /DISCARD/ : {
  41. *(.eh_frame)
  42. }
  43. }";