link.x 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107
  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.dummy ORIGIN(FLASH) :
  19. {
  20. /* This section is intended to make _stext address work */
  21. } > FLASH :ram
  22. .text ALIGN(_stext,4) :
  23. {
  24. /* Put reset handler first in .text section so it ends up as the entry */
  25. /* point of the program. */
  26. KEEP(*(.init));
  27. KEEP(*(.init.rust));
  28. . = ALIGN(4);
  29. KEEP(*(.trap));
  30. KEEP(*(.trap.rust));
  31. *(.text .text.*);
  32. } > FLASH :flash
  33. .rodata ALIGN(4) :
  34. {
  35. *(.rodata .rodata.*);
  36. } > FLASH :flash
  37. .data ALIGN(4) :
  38. {
  39. _sidata = LOADADDR(.data);
  40. _sdata = .;
  41. /* Must be called __global_pointer$ for linker relaxations to work. */
  42. PROVIDE(__global_pointer$ = . + 0x800);
  43. *(.data .data.*);
  44. . = ALIGN(4);
  45. _edata = .;
  46. } > RAM AT > FLASH :ram_init
  47. .bss :
  48. {
  49. _sbss = .;
  50. *(.bss .bss.*);
  51. . = ALIGN(4);
  52. _ebss = .;
  53. } > RAM :ram
  54. PROVIDE(_heap_size = 0);
  55. /* fictitious region that represents the memory available for the heap */
  56. .heap (INFO) :
  57. {
  58. _sheap = .;
  59. . += _heap_size;
  60. . = ALIGN(4);
  61. _eheap = .;
  62. } > RAM :ram
  63. /* fictitious region that represents the memory available for the stack */
  64. .stack (INFO) :
  65. {
  66. _estack = .;
  67. . = _stack_start;
  68. _sstack = .;
  69. } > RAM :ram
  70. /* fake output .got section */
  71. /* Dynamic relocations are unsupported. This section is only used to detect
  72. relocatable code in the input files and raise an error if relocatable code
  73. is found */
  74. .got (INFO) :
  75. {
  76. KEEP(*(.got .got.*));
  77. }
  78. /* Discard .eh_frame, we are not doing unwind on panic so it is not needed */
  79. /DISCARD/ :
  80. {
  81. *(.eh_frame);
  82. }
  83. }
  84. /* Do not exceed this mark in the error messages below | */
  85. ASSERT(SIZEOF(.got) == 0, "
  86. .got section detected in the input files. Dynamic relocations are not
  87. supported. If you are linking to C code compiled using the `gcc` crate
  88. then modify your build script to compile the C code _without_ the
  89. -fPIC flag. See the documentation of the `gcc::Config.fpic` method for
  90. details.");