link.x 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102
  1. /* NOTE: Adapted from cortex-m/link.x */
  2. INCLUDE memory.x
  3. PROVIDE(_stack_start = ORIGIN(RAM) + LENGTH(RAM));
  4. PROVIDE(trap_handler = default_trap_handler);
  5. /* # Pre-initialization function */
  6. /* If the user overrides this using the `#[pre_init]` attribute or by creating a `__pre_init` function,
  7. then the function this points to will be called before the RAM is initialized. */
  8. PROVIDE(__pre_init = default_pre_init);
  9. PHDRS
  10. {
  11. flash PT_LOAD;
  12. ram_init PT_LOAD;
  13. ram PT_NULL;
  14. }
  15. SECTIONS
  16. {
  17. PROVIDE(_stext = ORIGIN(FLASH));
  18. .text ALIGN(_stext,4) :
  19. {
  20. /* Put reset handler first in .text section so it ends up as the entry */
  21. /* point of the program. */
  22. KEEP(*(.init));
  23. KEEP(*(.init.rust));
  24. . = ALIGN(4);
  25. KEEP(*(.trap));
  26. KEEP(*(.trap.rust));
  27. *(.text .text.*);
  28. } > FLASH :flash
  29. .rodata ALIGN(4) :
  30. {
  31. *(.rodata .rodata.*);
  32. } > FLASH :flash
  33. .data ALIGN(4) :
  34. {
  35. _sidata = LOADADDR(.data);
  36. _sdata = .;
  37. /* Must be called __global_pointer$ for linker relaxations to work. */
  38. PROVIDE(__global_pointer$ = . + 0x800);
  39. *(.data .data.*);
  40. . = ALIGN(4);
  41. _edata = .;
  42. } > RAM AT > FLASH :ram_init
  43. .bss :
  44. {
  45. _sbss = .;
  46. *(.bss .bss.*);
  47. . = ALIGN(4);
  48. _ebss = .;
  49. } > RAM :ram
  50. PROVIDE(_heap_size = 0);
  51. /* fictitious region that represents the memory available for the heap */
  52. .heap (INFO) :
  53. {
  54. _sheap = .;
  55. . += _heap_size;
  56. . = ALIGN(4);
  57. _eheap = .;
  58. } > RAM :ram
  59. /* fictitious region that represents the memory available for the stack */
  60. .stack (INFO) :
  61. {
  62. _estack = .;
  63. . = _stack_start;
  64. _sstack = .;
  65. } > RAM :ram
  66. /* fake output .got section */
  67. /* Dynamic relocations are unsupported. This section is only used to detect
  68. relocatable code in the input files and raise an error if relocatable code
  69. is found */
  70. .got (INFO) :
  71. {
  72. KEEP(*(.got .got.*));
  73. }
  74. /* Discard .eh_frame, we are not doing unwind on panic so it is not needed */
  75. /DISCARD/ :
  76. {
  77. *(.eh_frame);
  78. }
  79. }
  80. /* Do not exceed this mark in the error messages below | */
  81. ASSERT(SIZEOF(.got) == 0, "
  82. .got section detected in the input files. Dynamic relocations are not
  83. supported. If you are linking to C code compiled using the `gcc` crate
  84. then modify your build script to compile the C code _without_ the
  85. -fPIC flag. See the documentation of the `gcc::Config.fpic` method for
  86. details.");