elf32cr16.sc 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182
  1. # Linker Script for National Semiconductor's CR16-ELF32.
  2. #
  3. # Copyright (C) 2014-2022 Free Software Foundation, Inc.
  4. #
  5. # Copying and distribution of this file, with or without modification,
  6. # are permitted in any medium without royalty provided the copyright
  7. # notice and this notice are preserved.
  8. # Using an empty script for ld -r is better than mashing together
  9. # sections. This hack likely leaves ld -Ur broken.
  10. test -n "${RELOCATING}" || exit 0
  11. # The next line should be uncommented if it is desired to link
  12. # without libstart.o and directly enter main.
  13. # ENTRY=_main
  14. test -z "$ENTRY" && ENTRY=_start
  15. cat <<EOF
  16. /* Example Linker Script for linking NS CR16 elf32 files.
  17. Copyright (C) 2014-2022 Free Software Foundation, Inc.
  18. Copying and distribution of this script, with or without modification,
  19. are permitted in any medium without royalty provided the copyright
  20. notice and this notice are preserved. */
  21. OUTPUT_FORMAT("${OUTPUT_FORMAT}")
  22. OUTPUT_ARCH(${ARCH})
  23. EOF
  24. test -n "${RELOCATING}" && cat <<EOF
  25. ENTRY(${ENTRY})
  26. /* Define memory regions. */
  27. MEMORY
  28. {
  29. rom : ORIGIN = 0x2, LENGTH = 3M
  30. ram : ORIGIN = 4M, LENGTH = 10M
  31. }
  32. EOF
  33. cat <<EOF
  34. /* Many sections come in three flavours. There is the 'real' section,
  35. like ".data". Then there are the per-procedure or per-variable
  36. sections, generated by -ffunction-sections and -fdata-sections in GCC,
  37. and useful for --gc-sections, which for a variable "foo" might be
  38. ".data.foo". Then there are the linkonce sections, for which the linker
  39. eliminates duplicates, which are named like ".gnu.linkonce.d.foo".
  40. The exact correspondences are:
  41. Section Linkonce section
  42. .text .gnu.linkonce.t.foo
  43. .rdata .gnu.linkonce.r.foo
  44. .data .gnu.linkonce.d.foo
  45. .bss .gnu.linkonce.b.foo
  46. .debug_info .gnu.linkonce.wi.foo */
  47. SECTIONS
  48. {
  49. .init :
  50. {
  51. __INIT_START = .;
  52. KEEP (*(SORT_NONE(.init)))
  53. __INIT_END = .;
  54. }${RELOCATING+ > rom}
  55. .fini :
  56. {
  57. __FINI_START = .;
  58. KEEP (*(SORT_NONE(.fini)))
  59. __FINI_END = .;
  60. }${RELOCATING+ > rom}
  61. .jcr :
  62. {
  63. KEEP (*(.jcr))
  64. }${RELOCATING+ > rom}
  65. .text :
  66. {
  67. __TEXT_START = .;
  68. *(.text) *(.text.*) *(.gnu.linkonce.t.*)
  69. __TEXT_END = .;
  70. }${RELOCATING+ > rom}
  71. .rdata :
  72. {
  73. __RDATA_START = .;
  74. *(.rdata_4) *(.rdata_2) *(.rdata_1) *(.rdata.*) *(.gnu.linkonce.r.*) *(.rodata*)
  75. __RDATA_END = .;
  76. }${RELOCATING+ > rom}
  77. .ctor ALIGN(4) :
  78. {
  79. __CTOR_START = .;
  80. /* The compiler uses crtbegin.o to find the start
  81. of the constructors, so we make sure it is
  82. first. Because this is a wildcard, it
  83. doesn't matter if the user does not
  84. actually link against crtbegin.o; the
  85. linker won't look for a file to match a
  86. wildcard. The wildcard also means that it
  87. doesn't matter which directory crtbegin.o
  88. is in. */
  89. KEEP (*crtbegin*.o(.ctors))
  90. /* We don't want to include the .ctor section from
  91. the crtend.o file until after the sorted ctors.
  92. The .ctor section from the crtend file contains the
  93. end of ctors marker and it must be last */
  94. KEEP (*(EXCLUDE_FILE (*crtend*.o) .ctors))
  95. KEEP (*(SORT(.ctors.*)))
  96. KEEP (*(.ctors))
  97. __CTOR_END = .;
  98. }${RELOCATING+ > rom}
  99. .dtor ALIGN(4) :
  100. {
  101. __DTOR_START = .;
  102. KEEP (*crtbegin*.o(.dtors))
  103. KEEP (*(EXCLUDE_FILE (*crtend*.o) .dtors))
  104. KEEP (*(SORT(.dtors.*)))
  105. KEEP (*(.dtors))
  106. __DTOR_END = .;
  107. }${RELOCATING+ > rom}
  108. .data :
  109. {
  110. __DATA_START = .;
  111. *(.data_4) *(.data_2) *(.data_1) *(.data) *(.data.*) *(.gnu.linkonce.d.*)
  112. __DATA_END = .;
  113. }${RELOCATING+ > ram AT > rom}
  114. .bss (NOLOAD) :
  115. {
  116. __BSS_START = .;
  117. *(.bss_4) *(.bss_2) *(.bss_1) *(.bss) *(COMMON) *(.bss.*) *(.gnu.linkonce.b.*)
  118. __BSS_END = .;
  119. }${RELOCATING+ > ram}
  120. /* You may change the sizes of the following sections to fit the actual
  121. size your program requires.
  122. The heap and stack are aligned to the bus width, as a speed optimization
  123. for accessing data located there. */
  124. .heap (NOLOAD) :
  125. {
  126. . = ALIGN(4);
  127. __HEAP_START = .;
  128. . += 0x2000; __HEAP_MAX = .;
  129. }${RELOCATING+ > ram}
  130. .stack (NOLOAD) :
  131. {
  132. . = ALIGN(4);
  133. . += 0x6000;
  134. __STACK_START = .;
  135. }${RELOCATING+ > ram}
  136. .istack (NOLOAD) :
  137. {
  138. . = ALIGN(4);
  139. . += 0x100;
  140. __ISTACK_START = .;
  141. }${RELOCATING+ > ram}
  142. .comment 0 : { *(.comment) }
  143. EOF
  144. . $srcdir/scripttempl/DWARF.sc
  145. cat <<EOF
  146. }
  147. ${RELOCATING+__DATA_IMAGE_START = LOADADDR(.data);}
  148. EOF