1# Linker script for PE.
2#
3# Copyright (C) 2014-2016 Free Software Foundation, Inc.
4#
5# Copying and distribution of this file, with or without modification,
6# are permitted in any medium without royalty provided the copyright
7# notice and this notice are preserved.
8
9if test -z "${RELOCATEABLE_OUTPUT_FORMAT}"; then
10  RELOCATEABLE_OUTPUT_FORMAT=${OUTPUT_FORMAT}
11fi
12
13# We can't easily and portably get an unquoted $ in a shell
14# substitution, so we do this instead.
15# Sorting of the .foo$* sections is required by the definition of
16# grouped sections in PE.
17# Sorting of the file names in R_IDATA is required by the
18# current implementation of dlltool (this could probably be changed to
19# use grouped sections instead).
20if test "${RELOCATING}"; then
21  R_TEXT='*(SORT(.text$*))'
22  R_DATA='*(SORT(.data$*))'
23  R_RDATA='*(SORT(.rdata$*))'
24  R_IDATA='
25    SORT(*)(.idata$2)
26    SORT(*)(.idata$3)
27    /* These zeroes mark the end of the import list.  */
28    LONG (0); LONG (0); LONG (0); LONG (0); LONG (0);
29    SORT(*)(.idata$4)
30    SORT(*)(.idata$5)
31    SORT(*)(.idata$6)
32    SORT(*)(.idata$7)'
33  R_CRT='*(SORT(.CRT$*))'
34  R_RSRC='*(SORT(.rsrc$*))'
35else
36  R_TEXT=
37  R_DATA=
38  R_RDATA=
39  R_IDATA=
40  R_CRT=
41  R_RSRC=
42fi
43
44cat <<EOF
45/* Copyright (C) 2014-2016 Free Software Foundation, Inc.
46
47   Copying and distribution of this script, with or without modification,
48   are permitted in any medium without royalty provided the copyright
49   notice and this notice are preserved.  */
50
51${RELOCATING+OUTPUT_FORMAT(${OUTPUT_FORMAT})}
52${RELOCATING-OUTPUT_FORMAT(${RELOCATEABLE_OUTPUT_FORMAT})}
53
54${LIB_SEARCH_DIRS}
55
56${RELOCATING+ENTRY (_mainCRTStartup)}
57
58SECTIONS
59{
60  .text ${RELOCATING+ __image_base__ + __section_alignment__ } :
61  {
62    ${RELOCATING+ *(.init)}
63    *(.text)
64    ${R_TEXT}
65    *(.glue_7t)
66    *(.glue_7)
67    ${RELOCATING+ *(.text.*)}
68    ${CONSTRUCTING+ ___CTOR_LIST__ = .; __CTOR_LIST__ = . ;
69			LONG (-1); *(.ctors); *(.ctor); LONG (0); }
70    ${CONSTRUCTING+ ___DTOR_LIST__ = .; __DTOR_LIST__ = . ;
71			LONG (-1); *(.dtors); *(.dtor);  LONG (0); }
72    ${RELOCATING+ *(.fini)}
73    /* ??? Why is .gcc_exc here?  */
74    ${RELOCATING+ *(.gcc_exc)}
75    ${RELOCATING+ etext = .;}
76    *(.gcc_except_table)
77
78    /* For EPOC the read only data is located at the end of the .text
79    section */
80    *(.rdata)
81    ${R_RDATA}
82    *(.eh_frame)
83  }
84
85  /* The Cygwin32 library uses a section to avoid copying certain data
86     on fork.  This used to be named ".data$nocopy".  The linker used
87     to include this between __data_start__ and __data_end__, but that
88     breaks building the cygwin32 dll.  Instead, we name the section
89     ".data_cygwin_nocopy" and explicitly include it after __data_end__. */
90
91  .data ${RELOCATING+BLOCK(__section_alignment__)} :
92  {
93    ${RELOCATING+__data_start__ = . ;}
94    *(.data)
95    *(.data2)
96    ${R_DATA}
97    ${RELOCATING+__data_end__ = . ;}
98    ${RELOCATING+*(.data_cygwin_nocopy)}
99  }
100
101  .bss ${RELOCATING+BLOCK(__section_alignment__)} :
102  {
103    ${RELOCATING+__bss_start__ = . ;}
104    *(.bss)
105    *(COMMON)
106    ${RELOCATING+__bss_end__ = . ;}
107  }
108
109  .edata ${RELOCATING+BLOCK(__section_alignment__)} :
110  {
111    *(.edata)
112  }
113
114  /DISCARD/ :
115  {
116    *(.debug\$S)
117    *(.debug\$T)
118    *(.debug\$F)
119    *(.drectve)
120  }
121
122  .idata ${RELOCATING+BLOCK(__section_alignment__)} :
123  {
124    /* This cannot currently be handled with grouped sections.
125	See pe.em:sort_sections.  */
126    ${R_IDATA}
127  }
128
129  .CRT ${RELOCATING+BLOCK(__section_alignment__)} :
130  {
131    ${R_CRT}
132  }
133
134  .endjunk ${RELOCATING+BLOCK(__section_alignment__)} :
135  {
136    /* end is deprecated, don't use it */
137    ${RELOCATING+ end = .;}
138    ${RELOCATING+ _end = .;}
139    ${RELOCATING+ __end__ = .;}
140  }
141
142  .reloc ${RELOCATING+BLOCK(__section_alignment__)} :
143  {
144    *(.reloc)
145  }
146
147  .rsrc ${RELOCATING+BLOCK(__section_alignment__)} :
148  {
149    *(.rsrc)
150    ${R_RSRC}
151  }
152
153  .stab ${RELOCATING+BLOCK(__section_alignment__)} ${RELOCATING+(NOLOAD)} :
154  {
155    [ .stab ]
156  }
157
158  .stabstr ${RELOCATING+BLOCK(__section_alignment__)} ${RELOCATING+(NOLOAD)} :
159  {
160    [ .stabstr ]
161  }
162
163}
164EOF
165