link.x 2.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283
  1. /* NOTE: Adapted from cortex-m/link.x */
  2. INCLUDE memory.x
  3. PROVIDE(_stack_start = ORIGIN(RAM) + LENGTH(RAM));
  4. SECTIONS
  5. {
  6. PROVIDE(_stext = ORIGIN(FLASH));
  7. .text _stext : ALIGN(4)
  8. {
  9. /* Put reset handler first in .text section so it ends up as the entry */
  10. /* point of the program. */
  11. KEEP(*(.init));
  12. KEEP(*(.init.rust));
  13. KEEP(*(.trap));
  14. KEEP(*(.trap.rust));
  15. *(.text .text.*);
  16. } > FLASH
  17. .rodata : ALIGN(4)
  18. {
  19. *(.rodata .rodata.*);
  20. . = ALIGN(4);
  21. } > FLASH
  22. .bss : ALIGN(4)
  23. {
  24. _sbss = .;
  25. *(.bss .bss.*);
  26. . = ALIGN(4);
  27. _ebss = .;
  28. } > RAM
  29. .data : ALIGN(4)
  30. {
  31. _sidata = LOADADDR(.data);
  32. _sdata = .;
  33. /* Must be called __global_pointer$ for linker relaxations to work. */
  34. PROVIDE(__global_pointer$ = . + 0x800);
  35. *(.data .data.*);
  36. . = ALIGN(4);
  37. _edata = .;
  38. } > RAM AT > FLASH /* LLD fails on AT > FLASH */
  39. /* fake output .got section */
  40. /* Dynamic relocations are unsupported. This section is only used to detect
  41. relocatable code in the input files and raise an error if relocatable code
  42. is found */
  43. .got :
  44. {
  45. _sgot = .;
  46. KEEP(*(.got .got.*));
  47. _egot = .;
  48. } > RAM AT > FLASH /* LLD fails on AT > FLASH */
  49. /* The heap starts right after the .bss + .data section ends */
  50. _sheap = _edata;
  51. /* Due to an unfortunate combination of legacy concerns,
  52. toolchain drawbacks, and insufficient attention to detail,
  53. rustc has no choice but to mark .debug_gdb_scripts as allocatable.
  54. We really do not want to upload it to our target, so we
  55. remove the allocatable bit. Unfortunately, it appears
  56. that the only way to do this in a linker script is
  57. the extremely obscure "INFO" output section type specifier. */
  58. /* a rustc hack will force the program to read the first byte of this section,
  59. so we'll set the (fake) start address of this section to something we're
  60. sure can be read at runtime: the start of the .text section */
  61. /* LLD fails to parse _stext (INFO) */
  62. .debug_gdb_scripts _stext (INFO) : {
  63. KEEP(*(.debug_gdb_scripts))
  64. }
  65. }
  66. /* Do not exceed this mark in the error messages below | */
  67. ASSERT(_sgot == _egot, "
  68. .got section detected in the input files. Dynamic relocations are not
  69. supported. If you are linking to C code compiled using the `gcc` crate
  70. then modify your build script to compile the C code _without_ the
  71. -fPIC flag. See the documentation of the `gcc::Config.fpic` method for
  72. details.");