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