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 7.1KB

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