xref: /openbsd-src/gnu/usr.bin/binutils/ld/scripttempl/ppcpe.sc (revision 6a4c786fd1d49fc30ce2d67fbe51c505ff9e8345)
12159047fSniklas# A PE linker script for PowerPC.
22159047fSniklas# Loosely based on Steve Chamberlain's pe.sc.
32159047fSniklas# All new mistakes should be credited to Kim Knuttila (krk@cygnus.com)
42159047fSniklas#
52159047fSniklas# These are substituted in as variables in order to get '}' in a shell
62159047fSniklas# conditional expansion.
72159047fSniklasINIT='.init : { *(.init) }'
82159047fSniklasFINI='.fini : { *(.fini) }'
92159047fSniklascat <<EOF
102159047fSniklasOUTPUT_FORMAT(${OUTPUT_FORMAT})
112159047fSniklas${LIB_SEARCH_DIRS}
122159047fSniklas
132159047fSniklas/* Much of this layout was determined by delving into .exe files for
142159047fSniklas   the box generated by other compilers/linkers/etc. This means that
152159047fSniklas   if a particular feature did not happen to appear in one of the
162159047fSniklas   subject files, then it may not be yet supported.
172159047fSniklas*/
182159047fSniklas
192159047fSniklas/* It's "mainCRTStartup", not "_mainCRTStartup", and it's located in
202159047fSniklas   one of the two .lib files (libc.lib and kernel32.lib) that currently
212159047fSniklas   must be present on the link line. This means that you must use
222159047fSniklas   "-u mainCRTStartup" to make sure it gets included in the link.
232159047fSniklas*/
242159047fSniklas
252159047fSniklasENTRY(mainCRTStartup)
262159047fSniklas
272159047fSniklasSECTIONS
282159047fSniklas{
292159047fSniklas
302159047fSniklas  /* text - the usual meaning */
312159047fSniklas  .text ${RELOCATING+ __image_base__ + __section_alignment__ } :
322159047fSniklas	{
332159047fSniklas	    ${RELOCATING+ *(.init);}
342159047fSniklas	    *(.text)
35*6a4c786fSespie	    *(.gcc_except_table)
362159047fSniklas	    ${CONSTRUCTING+ ___CTOR_LIST__ = .; __CTOR_LIST__ = . ;
372159047fSniklas		        LONG (-1); *(.ctors); *(.ctor); LONG (0); }
382159047fSniklas            ${CONSTRUCTING+ ___DTOR_LIST__ = .; __DTOR_LIST__ = . ;
392159047fSniklas			LONG (-1); *(.dtors); *(.dtor);  LONG (0); }
402159047fSniklas	    ${RELOCATING+ *(.fini);}
412159047fSniklas	    ${RELOCATING+ etext  =  .};
422159047fSniklas	}
432159047fSniklas
442159047fSniklas  /* rdata - Read Only Runtime Data
452159047fSniklas     CTR sections: All of the CRT (read only C runtime data) sections
462159047fSniklas	appear at the start of the .rdata (read only runtime data)
472159047fSniklas	section, in the following order. Don't know if it matters or not.
482159047fSniklas	Not all sections are always present either.
492159047fSniklas     .rdata: compiler generated read only data
502159047fSniklas     .xdata: compiler generated exception handling table. (Most docs
512159047fSniklas	seem to suggest that this section is now deprecated infavor
522159047fSniklas	of the ydata section)
532159047fSniklas     .edata: The exported names table.
542159047fSniklas  */
552159047fSniklas  .rdata BLOCK(__section_alignment__) :
562159047fSniklas	{
572159047fSniklas	    *(.CRT\$XCA);
582159047fSniklas	    *(.CRT\$XCC);
592159047fSniklas	    *(.CRT\$XCZ);
602159047fSniklas	    *(.CRT\$XIA);
612159047fSniklas	    *(.CRT\$XIC);
622159047fSniklas	    *(.CRT\$XIZ);
632159047fSniklas	    *(.CRT\$XLA);
642159047fSniklas	    *(.CRT\$XLZ);
652159047fSniklas	    *(.CRT\$XPA);
662159047fSniklas	    *(.CRT\$XPX);
672159047fSniklas	    *(.CRT\$XPZ);
682159047fSniklas	    *(.CRT\$XTA);
692159047fSniklas	    *(.CRT\$XTZ);
702159047fSniklas	    *(.rdata);
712159047fSniklas	    *(.xdata);
72191aa565Sniklas	}
73191aa565Sniklas
74191aa565Sniklas  .edata BLOCK(__section_alignment__) :
75191aa565Sniklas	{
762159047fSniklas    	    *(.edata);
772159047fSniklas	}
782159047fSniklas
792159047fSniklas  /* data - initialized data
802159047fSniklas     .ydata: exception handling information.
812159047fSniklas     .data: the usual meaning.
822159047fSniklas     .data2: more of the same.
832159047fSniklas     .bss: For some reason, bss appears to be included in the data
842159047fSniklas	section, as opposed to being given a section of it's own.
852159047fSniklas     COMMON:
862159047fSniklas  */
872159047fSniklas  .data BLOCK(__section_alignment__) :
882159047fSniklas	{
892159047fSniklas	    __data_start__ = . ;
902159047fSniklas	    *(.ydata);
912159047fSniklas	    *(.data);
922159047fSniklas	    *(.data2);
932159047fSniklas	    __bss_start__ = . ;
942159047fSniklas	    *(.bss) ;
952159047fSniklas	    *(COMMON);
962159047fSniklas	    __bss_end__ = . ;
972159047fSniklas	    ${RELOCATING+ end =  .};
982159047fSniklas 	    __data_end__ = . ;
992159047fSniklas	}
1002159047fSniklas
1012159047fSniklas  /* The exception handling table. A sequence of 5 word entries. Section
1022159047fSniklas     address and extent are placed in the DataDirectory.
1032159047fSniklas  */
1042159047fSniklas  .pdata BLOCK(__section_alignment__) :
1052159047fSniklas	{
1062159047fSniklas	    *(.pdata)
1072159047fSniklas 	    ;
1082159047fSniklas	}
1092159047fSniklas
1102159047fSniklas  /* The idata section is chock full of magic bits.
1112159047fSniklas	1. Boundaries around various idata parts are used to initialize
1122159047fSniklas	   some of the fields of the DataDirectory. In particular, the
1132159047fSniklas	   magic for 2, 4 and 5 are known to be used. Some compilers
1142159047fSniklas	   appear to generate magic section symbols for this purpose.
1152159047fSniklas	   Where we can, we catch such symbols and use our own. This of
1162159047fSniklas	   course is something less than a perfect strategy.
1172159047fSniklas	2. The table of contents is placed immediately after idata4.
1182159047fSniklas	   The ".private.toc" sections are generated by the ppc bfd. The
1192159047fSniklas	   .toc variable is generated by gas, and resolved here. It is
1202159047fSniklas	   used to initialized function descriptors (and anyone else who
1212159047fSniklas	   needs the address of the module's toc). The only thing
1222159047fSniklas	   interesting about it at all? Most ppc instructions using it
1232159047fSniklas	   have a 16bit displacement field. The convention for addressing
1242159047fSniklas	   is to initialize the .toc value to 32K past the start of the
1252159047fSniklas	   actual toc, and subtract 32K from all references, thus using
1262159047fSniklas	   the entire 64K range. Naturally, the reloc code must agree
1272159047fSniklas	   on this number or you get pretty stupid results.
1282159047fSniklas  */
1292159047fSniklas  .idata BLOCK(__section_alignment__) :
1302159047fSniklas	{
1312159047fSniklas	    __idata2_magic__ = .;
1322159047fSniklas	    *(.idata\$2);
1332159047fSniklas	    __idata3_magic__ = .;
1342159047fSniklas	    *(.idata\$3);
1352159047fSniklas	    __idata4_magic__ = .;
1362159047fSniklas	    *(.idata\$4);
137191aa565Sniklas	    . = ALIGN(4);
1382159047fSniklas	    .toc = . + 32768;
1392159047fSniklas	    *(.private.toc);
1402159047fSniklas	    __idata5_magic__ = .;
1412159047fSniklas	    *(.idata\$5);
1422159047fSniklas	    __idata6_magic__ = .;
1432159047fSniklas	    *(.idata\$6);
1442159047fSniklas	    __idata7_magic__ = .;
1452159047fSniklas	    *(.idata\$7);
1462159047fSniklas	    ;
1472159047fSniklas	}
1482159047fSniklas
1492159047fSniklas  /* reldata -- data that requires relocation
1502159047fSniklas  */
1512159047fSniklas  .reldata BLOCK(__section_alignment__) :
1522159047fSniklas	{
1532159047fSniklas	    *(.reldata)
1542159047fSniklas 	    ;
1552159047fSniklas	}
1562159047fSniklas
1572159047fSniklas
1582159047fSniklas  /* Resources */
1592159047fSniklas  .rsrc BLOCK(__section_alignment__) :
1602159047fSniklas	{
1612159047fSniklas	    *(.rsrc\$01)
1622159047fSniklas	    *(.rsrc\$02)
1632159047fSniklas	    ;
1642159047fSniklas	}
1652159047fSniklas
166191aa565Sniklas  .stab BLOCK(__section_alignment__)  ${RELOCATING+(NOLOAD)} :
167191aa565Sniklas  {
168191aa565Sniklas    [ .stab ]
169191aa565Sniklas  }
170191aa565Sniklas
171191aa565Sniklas  .stabstr BLOCK(__section_alignment__) ${RELOCATING+(NOLOAD)} :
172191aa565Sniklas  {
173191aa565Sniklas    [ .stabstr ]
174191aa565Sniklas  }
175191aa565Sniklas
1762159047fSniklas  /* The .reloc section is currently generated by the dlltool from Steve
1772159047fSniklas     Chamberlain in a second pass of linking. Section address and extent
1782159047fSniklas     are placed in the DataDirectory.
1792159047fSniklas  */
1802159047fSniklas  .reloc BLOCK(__section_alignment__) :
1812159047fSniklas	{
1822159047fSniklas	    *(.reloc)
1832159047fSniklas	    ;
1842159047fSniklas	}
1852159047fSniklas
186191aa565Sniklas  /* We don't do anything useful with codeview debugger support or the
187191aa565Sniklas     directive section (yet). Hopefully, we junk them correctly.
188191aa565Sniklas  */
189191aa565Sniklas  /DISCARD/ BLOCK(__section_alignment__) :
1902159047fSniklas	{
191191aa565Sniklas    	    *(.debug\$S)
192191aa565Sniklas    	    *(.debug\$T)
193191aa565Sniklas    	    *(.debug\$F)
194191aa565Sniklas    	    *(.drectve)
195191aa565Sniklas    	    ;
1962159047fSniklas   	}
1972159047fSniklas}
1982159047fSniklasEOF
199