link.x 2.5 KB

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