build.rs 988 B

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