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