link.x 2.3 KB

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