ppcpe.sc 6.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214
  1. # A PE linker script for PowerPC.
  2. # Loosely based on Steve Chamberlain's pe.sc.
  3. # All new mistakes should be credited to Kim Knuttila (krk@cygnus.com)
  4. #
  5. # Copyright (C) 2014-2015 Free Software Foundation, Inc.
  6. #
  7. # Copying and distribution of this file, with or without modification,
  8. # are permitted in any medium without royalty provided the copyright
  9. # notice and this notice are preserved.
  10. #
  11. # These are substituted in as variables in order to get '}' in a shell
  12. # conditional expansion.
  13. INIT='.init : { *(.init) }'
  14. FINI='.fini : { *(.fini) }'
  15. cat <<EOF
  16. /* Copyright (C) 2014-2015 Free Software Foundation, Inc.
  17. Copying and distribution of this script, with or without modification,
  18. are permitted in any medium without royalty provided the copyright
  19. notice and this notice are preserved. */
  20. OUTPUT_FORMAT(${OUTPUT_FORMAT})
  21. ${LIB_SEARCH_DIRS}
  22. /* Much of this layout was determined by delving into .exe files for
  23. the box generated by other compilers/linkers/etc. This means that
  24. if a particular feature did not happen to appear in one of the
  25. subject files, then it may not be yet supported.
  26. */
  27. /* It's "mainCRTStartup", not "_mainCRTStartup", and it's located in
  28. one of the two .lib files (libc.lib and kernel32.lib) that currently
  29. must be present on the link line. This means that you must use
  30. "-u mainCRTStartup" to make sure it gets included in the link.
  31. */
  32. ${RELOCATING+ENTRY (mainCRTStartup)}
  33. SECTIONS
  34. {
  35. /* text - the usual meaning */
  36. .text ${RELOCATING+ __image_base__ + __section_alignment__ } :
  37. {
  38. ${RELOCATING+ *(.init);}
  39. *(.text)
  40. ${RELOCATING+ *(.text.*)}
  41. *(.gcc_except_table)
  42. ${CONSTRUCTING+ ___CTOR_LIST__ = .; __CTOR_LIST__ = . ;
  43. LONG (-1); *(.ctors); *(.ctor); LONG (0); }
  44. ${CONSTRUCTING+ ___DTOR_LIST__ = .; __DTOR_LIST__ = . ;
  45. LONG (-1); *(.dtors); *(.dtor); LONG (0); }
  46. ${RELOCATING+ *(.fini);}
  47. ${RELOCATING+ etext = .};
  48. }
  49. /* rdata - Read Only Runtime Data
  50. CTR sections: All of the CRT (read only C runtime data) sections
  51. appear at the start of the .rdata (read only runtime data)
  52. section, in the following order. Don't know if it matters or not.
  53. Not all sections are always present either.
  54. .rdata: compiler generated read only data
  55. .xdata: compiler generated exception handling table. (Most docs
  56. seem to suggest that this section is now deprecated infavor
  57. of the ydata section)
  58. .edata: The exported names table.
  59. */
  60. .rdata BLOCK(__section_alignment__) :
  61. {
  62. *(.CRT\$XCA);
  63. *(.CRT\$XCC);
  64. *(.CRT\$XCZ);
  65. *(.CRT\$XIA);
  66. *(.CRT\$XIC);
  67. *(.CRT\$XIZ);
  68. *(.CRT\$XLA);
  69. *(.CRT\$XLZ);
  70. *(.CRT\$XPA);
  71. *(.CRT\$XPX);
  72. *(.CRT\$XPZ);
  73. *(.CRT\$XTA);
  74. *(.CRT\$XTZ);
  75. *(.rdata);
  76. *(.xdata);
  77. }
  78. .edata BLOCK(__section_alignment__) :
  79. {
  80. *(.edata);
  81. }
  82. /* data - initialized data
  83. .ydata: exception handling information.
  84. .data: the usual meaning.
  85. .data2: more of the same.
  86. .bss: For some reason, bss appears to be included in the data
  87. section, as opposed to being given a section of it's own.
  88. COMMON:
  89. */
  90. .data BLOCK(__section_alignment__) :
  91. {
  92. __data_start__ = . ;
  93. *(.ydata);
  94. *(.data);
  95. *(.data2);
  96. __bss_start__ = . ;
  97. *(.bss) ;
  98. *(COMMON);
  99. __bss_end__ = . ;
  100. ${RELOCATING+ end = .};
  101. __data_end__ = . ;
  102. }
  103. /* The exception handling table. A sequence of 5 word entries. Section
  104. address and extent are placed in the DataDirectory.
  105. */
  106. .pdata BLOCK(__section_alignment__) :
  107. {
  108. *(.pdata)
  109. ;
  110. }
  111. /* The idata section is chock full of magic bits.
  112. 1. Boundaries around various idata parts are used to initialize
  113. some of the fields of the DataDirectory. In particular, the
  114. magic for 2, 4 and 5 are known to be used. Some compilers
  115. appear to generate magic section symbols for this purpose.
  116. Where we can, we catch such symbols and use our own. This of
  117. course is something less than a perfect strategy.
  118. 2. The table of contents is placed immediately after idata4.
  119. The ".private.toc" sections are generated by the ppc bfd. The
  120. .toc variable is generated by gas, and resolved here. It is
  121. used to initialized function descriptors (and anyone else who
  122. needs the address of the module's toc). The only thing
  123. interesting about it at all? Most ppc instructions using it
  124. have a 16bit displacement field. The convention for addressing
  125. is to initialize the .toc value to 32K past the start of the
  126. actual toc, and subtract 32K from all references, thus using
  127. the entire 64K range. Naturally, the reloc code must agree
  128. on this number or you get pretty stupid results.
  129. */
  130. .idata BLOCK(__section_alignment__) :
  131. {
  132. __idata2_magic__ = .;
  133. *(.idata\$2);
  134. __idata3_magic__ = .;
  135. *(.idata\$3);
  136. __idata4_magic__ = .;
  137. *(.idata\$4);
  138. . = ALIGN(4);
  139. .toc = . + 32768;
  140. *(.private.toc);
  141. __idata5_magic__ = .;
  142. *(.idata\$5);
  143. __idata6_magic__ = .;
  144. *(.idata\$6);
  145. __idata7_magic__ = .;
  146. *(.idata\$7);
  147. ;
  148. }
  149. /* reldata -- data that requires relocation
  150. */
  151. .reldata BLOCK(__section_alignment__) :
  152. {
  153. *(.reldata)
  154. ;
  155. }
  156. /* Resources */
  157. .rsrc BLOCK(__section_alignment__) :
  158. {
  159. *(.rsrc\$01)
  160. *(.rsrc\$02)
  161. ;
  162. }
  163. .stab BLOCK(__section_alignment__) ${RELOCATING+(NOLOAD)} :
  164. {
  165. [ .stab ]
  166. }
  167. .stabstr BLOCK(__section_alignment__) ${RELOCATING+(NOLOAD)} :
  168. {
  169. [ .stabstr ]
  170. }
  171. /* The .reloc section is currently generated by the dlltool from Steve
  172. Chamberlain in a second pass of linking. Section address and extent
  173. are placed in the DataDirectory.
  174. */
  175. .reloc BLOCK(__section_alignment__) :
  176. {
  177. *(.reloc)
  178. ;
  179. }
  180. /* We don't do anything useful with codeview debugger support or the
  181. directive section (yet). Hopefully, we junk them correctly.
  182. */
  183. /DISCARD/ BLOCK(__section_alignment__) :
  184. {
  185. *(.debug\$S)
  186. *(.debug\$T)
  187. *(.debug\$F)
  188. *(.drectve)
  189. ;
  190. }
  191. }
  192. EOF