You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

i386.lds 6.9KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282
  1. /* -*- sh -*- */
  2. /*
  3. * Linker script for i386 images
  4. *
  5. */
  6. OUTPUT_FORMAT ( "elf32-i386", "elf32-i386", "elf32-i386" )
  7. OUTPUT_ARCH ( i386 )
  8. ENTRY ( _entry )
  9. SECTIONS {
  10. /* All sections in the resulting file have consecutive load
  11. * addresses, but may have individual link addresses depending on
  12. * the memory model being used.
  13. *
  14. * We guarantee alignment of virtual addresses to any alignment
  15. * specified by the constituent object files (e.g. via
  16. * __attribute__((aligned(x)))). Load addresses are guaranteed
  17. * only up to _max_align. Provided that all loader and relocation
  18. * code honours _max_align, this means that physical addresses are
  19. * also guaranteed up to _max_align.
  20. *
  21. * Note that when using -DKEEP_IT_REAL, the UNDI segments are only
  22. * guaranteed to be loaded on a paragraph boundary (i.e. 16-byte
  23. * alignment). Using _max_align>16 will therefore not guarantee
  24. * >16-byte alignment of physical addresses when -DKEEP_IT_REAL is
  25. * used (though virtual addresses will still be fully aligned).
  26. *
  27. */
  28. /*
  29. * Weak symbols that need zero values if not otherwise defined
  30. */
  31. . = 0;
  32. .weak : AT ( 0 ) {
  33. *(.weak)
  34. }
  35. _assert = ASSERT ( ( . == 0 ), ".weak is non-zero length" );
  36. /*
  37. * The prefix
  38. */
  39. _prefix_link_addr = 0;
  40. . = _prefix_link_addr;
  41. _prefix = .;
  42. .prefix : AT ( _prefix_load_offset + __prefix ) {
  43. __prefix = .;
  44. _entry = .;
  45. *(.prefix)
  46. *(.prefix.*)
  47. _eprefix_progbits = .;
  48. }
  49. _eprefix = .;
  50. /*
  51. * The 16-bit sections, if present
  52. */
  53. _text16_link_addr = 0;
  54. . = _text16_link_addr;
  55. _text16 = .;
  56. . += 1; /* Prevent NULL being valid */
  57. .text16 : AT ( _text16_load_offset + __text16 ) {
  58. __text16 = .;
  59. *(.text16)
  60. *(.text16.*)
  61. _etext16_progbits = .;
  62. } = 0x9090
  63. _etext16 = .;
  64. _data16_link_addr = 0;
  65. . = _data16_link_addr;
  66. _data16 = .;
  67. . += 1; /* Prevent NULL being valid */
  68. .rodata16 : AT ( _data16_load_offset + __rodata16 ) {
  69. __rodata16 = .;
  70. *(.rodata16)
  71. *(.rodata16.*)
  72. }
  73. .data16 : AT ( _data16_load_offset + __data16 ) {
  74. __data16 = .;
  75. *(.data16)
  76. *(.data16.*)
  77. _edata16_progbits = .;
  78. }
  79. .bss16 : AT ( _data16_load_offset + __bss16 ) {
  80. __bss16 = .;
  81. _bss16 = .;
  82. *(.bss16)
  83. *(.bss16.*)
  84. _ebss16 = .;
  85. }
  86. .stack16 : AT ( _data16_load_offset + __stack16 ) {
  87. __stack16 = .;
  88. *(.stack16)
  89. *(.stack16.*)
  90. }
  91. _edata16 = .;
  92. /*
  93. * The 32-bit sections
  94. */
  95. _textdata_link_addr = 0;
  96. . = _textdata_link_addr;
  97. _textdata = .;
  98. _text = .;
  99. . += 1; /* Prevent NULL being valid */
  100. .text : AT ( _textdata_load_offset + __text ) {
  101. __text = .;
  102. *(.text.null_trap)
  103. *(.text)
  104. *(.text.*)
  105. } = 0x9090
  106. _etext = .;
  107. _data = .;
  108. .rodata : AT ( _textdata_load_offset + __rodata ) {
  109. __rodata = .;
  110. *(.rodata)
  111. *(.rodata.*)
  112. }
  113. .data : AT ( _textdata_load_offset + __data ) {
  114. __data = .;
  115. *(.data)
  116. *(.data.*)
  117. *(SORT(.tbl.*)) /* Various tables. See include/tables.h */
  118. _etextdata_progbits = .;
  119. }
  120. .bss : AT ( _textdata_load_offset + __bss ) {
  121. __bss = .;
  122. _bss = .;
  123. *(.bss)
  124. *(.bss.*)
  125. *(COMMON)
  126. _ebss = .;
  127. }
  128. .stack : AT ( _textdata_load_offset + __stack ) {
  129. __stack = .;
  130. *(.stack)
  131. *(.stack.*)
  132. }
  133. _edata = .;
  134. _etextdata = .;
  135. _end = .;
  136. /*
  137. * Compressor information block
  138. */
  139. _zinfo_link_addr = 0;
  140. . = _zinfo_link_addr;
  141. _zinfo = .;
  142. .zinfo : AT ( _zinfo_load_offset + __zinfo ) {
  143. __zinfo = .;
  144. _entry = .;
  145. *(.zinfo)
  146. *(.zinfo.*)
  147. _ezinfo_progbits = .;
  148. }
  149. _ezinfo = .;
  150. /*
  151. * Dispose of the comment and note sections to make the link map
  152. * easier to read
  153. */
  154. /DISCARD/ : {
  155. *(.comment)
  156. *(.note)
  157. }
  158. /*
  159. * Load address calculations. The slightly obscure nature of the
  160. * calculations is because ALIGN(x) can only operate on the
  161. * location counter.
  162. */
  163. _max_align = 16;
  164. _load_addr = 0;
  165. . = _load_addr;
  166. . -= _prefix_link_addr;
  167. _prefix_load_offset = ALIGN ( _max_align );
  168. _prefix_load_addr = _prefix_link_addr + _prefix_load_offset;
  169. _prefix_size = _eprefix - _prefix;
  170. _prefix_progbits_size = _eprefix_progbits - _prefix;
  171. . = _prefix_load_addr + _prefix_progbits_size;
  172. . -= _text16_link_addr;
  173. _text16_load_offset = ALIGN ( _max_align );
  174. _text16_load_addr = _text16_link_addr + _text16_load_offset;
  175. _text16_size = _etext16 - _text16;
  176. _text16_progbits_size = _etext16_progbits - _text16;
  177. . = _text16_load_addr + _text16_progbits_size;
  178. . -= _data16_link_addr;
  179. _data16_load_offset = ALIGN ( _max_align );
  180. _data16_load_addr = _data16_link_addr + _data16_load_offset;
  181. _data16_size = _edata16 - _data16;
  182. _data16_progbits_size = _edata16_progbits - _data16;
  183. . = _data16_load_addr + _data16_progbits_size;
  184. . -= _textdata_link_addr;
  185. _textdata_load_offset = ALIGN ( _max_align );
  186. _textdata_load_addr = _textdata_link_addr + _textdata_load_offset;
  187. _textdata_size = _etextdata - _textdata;
  188. _textdata_progbits_size = _etextdata_progbits - _textdata;
  189. . = _textdata_load_addr + _textdata_progbits_size;
  190. _load_size = . - _load_addr;
  191. . -= _zinfo_link_addr;
  192. _zinfo_load_offset = ALIGN ( _max_align );
  193. _zinfo_load_addr = _zinfo_link_addr + _zinfo_load_offset;
  194. _zinfo_size = _ezinfo - _zinfo;
  195. _zinfo_progbits_size = _ezinfo_progbits - _zinfo;
  196. . = _zinfo_load_addr + _zinfo_progbits_size;
  197. _payload_offset = _text16_load_offset;
  198. /*
  199. * Alignment checks. ALIGN() can only operate on the location
  200. * counter, so we set the location counter to each value we want
  201. * to check.
  202. */
  203. . = _prefix_load_addr - _prefix_link_addr;
  204. _assert = ASSERT ( ( . == ALIGN ( _max_align ) ),
  205. "_prefix is badly aligned" );
  206. . = _text16_load_addr - _text16_link_addr;
  207. _assert = ASSERT ( ( . == ALIGN ( _max_align ) ),
  208. "_text16 is badly aligned" );
  209. . = _data16_load_addr - _data16_link_addr;
  210. _assert = ASSERT ( ( . == ALIGN ( _max_align ) ),
  211. "_data16 is badly aligned" );
  212. . = _textdata_load_addr - _textdata_link_addr;
  213. _assert = ASSERT ( ( . == ALIGN ( _max_align ) ),
  214. "_text is badly aligned" );
  215. /*
  216. * Values calculated to save code from doing it
  217. */
  218. _prefix_size_pgh = ( ( _prefix_size + 15 ) / 16 );
  219. _prefix_size_sect = ( ( _prefix_size + 511 ) / 512 );
  220. _text16_size_pgh = ( ( _text16_size + 15 ) / 16 );
  221. _data16_size_pgh = ( ( _data16_size + 15 ) / 16 );
  222. /*
  223. * Load sizes in paragraphs and sectors. Note that wherever the
  224. * _load_size variables are used, there must be a corresponding
  225. * .zinfo.fixup section.
  226. */
  227. _load_size_pgh = ( ( _load_size + 15 ) / 16 );
  228. _load_size_sect = ( ( _load_size + 511 ) / 512 );
  229. }