1 # This shell script emits a C file. -*- C -*-
2 # It does some substitutions.
4 /* This file is is generated by a shell script. DO NOT EDIT! */
6 /* Emulate the original gld for the given ${EMULATION_NAME}
7 Copyright (C) 2014-2016 Free Software Foundation, Inc.
8 Written by Steve Chamberlain steve@cygnus.com
9 Extended for the MSP430 by Nick Clifton nickc@redhat.com
11 This file is part of the GNU Binutils.
13 This program is free software; you can redistribute it and/or modify
14 it under the terms of the GNU General Public License as published by
15 the Free Software Foundation; either version 3 of the License, or
16 (at your option) any later version.
18 This program is distributed in the hope that it will be useful,
19 but WITHOUT ANY WARRANTY; without even the implied warranty of
20 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 GNU General Public License for more details.
23 You should have received a copy of the GNU General Public License
24 along with this program; if not, write to the Free Software
25 Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston,
26 MA 02110-1301, USA. */
28 #define TARGET_IS_${EMULATION_NAME}
41 #include "libiberty.h"
45 # Import any needed special functions and/or overrides.
47 if test -n "$EXTRA_EM_FILE" ; then
48 source_em ${srcdir}/emultempl/${EXTRA_EM_FILE}.em
51 if test x"$LDEMUL_BEFORE_PARSE" != xgld"$EMULATION_NAME"_before_parse; then
55 gld${EMULATION_NAME}_before_parse (void)
57 #ifndef TARGET_ /* I.e., if not generic. */
58 ldfile_set_output_arch ("`echo ${ARCH}`", bfd_arch_unknown);
59 #endif /* not TARGET_ */
61 /* The MSP430 port *needs* linker relaxtion in order to cope with large
62 functions where conditional branches do not fit into a +/- 1024 byte range. */
63 if (!bfd_link_relocatable (&link_info))
64 TARGET_ENABLE_RELAXATION;
70 if test x"$LDEMUL_GET_SCRIPT" != xgld"$EMULATION_NAME"_get_script; then
74 gld${EMULATION_NAME}_get_script (int *isfile)
77 if test x"$COMPILE_IN" = xyes
79 # Scripts compiled in.
81 # sed commands to quote an ld script as a C string.
88 if (bfd_link_relocatable (&link_info) && config.build_constructors)
91 sed $sc ldscripts/${EMULATION_NAME}.xu >> e${EMULATION_NAME}.c
92 echo ' ; else if (bfd_link_relocatable (&link_info)) return' >> e${EMULATION_NAME}.c
93 sed $sc ldscripts/${EMULATION_NAME}.xr >> e${EMULATION_NAME}.c
94 echo ' ; else if (!config.text_read_only) return' >> e${EMULATION_NAME}.c
95 sed $sc ldscripts/${EMULATION_NAME}.xbn >> e${EMULATION_NAME}.c
96 echo ' ; else if (!config.magic_demand_paged) return' >> e${EMULATION_NAME}.c
97 sed $sc ldscripts/${EMULATION_NAME}.xn >> e${EMULATION_NAME}.c
98 echo ' ; else return' >> e${EMULATION_NAME}.c
99 sed $sc ldscripts/${EMULATION_NAME}.x >> e${EMULATION_NAME}.c
100 echo '; }' >> e${EMULATION_NAME}.c
103 # Scripts read from the filesystem.
109 if (bfd_link_relocatable (&link_info) && config.build_constructors)
110 return "ldscripts/${EMULATION_NAME}.xu";
111 else if (bfd_link_relocatable (&link_info))
112 return "ldscripts/${EMULATION_NAME}.xr";
113 else if (!config.text_read_only)
114 return "ldscripts/${EMULATION_NAME}.xbn";
115 else if (!config.magic_demand_paged)
116 return "ldscripts/${EMULATION_NAME}.xn";
118 return "ldscripts/${EMULATION_NAME}.x";
124 if test x"$LDEMUL_PLACE_ORPHAN" != xgld"$EMULATION_NAME"_place_orphan; then
127 /* Helper function for place_orphan that computes the size
128 of sections already mapped to the given statement. */
131 scan_children (lang_statement_union_type * l)
133 bfd_size_type amount = 0;
137 switch (l->header.type)
139 case lang_input_section_enum:
140 if (l->input_section.section->flags & SEC_ALLOC)
141 amount += l->input_section.section->size;
144 case lang_constructors_statement_enum:
145 case lang_assignment_statement_enum:
148 case lang_wild_statement_enum:
149 amount += scan_children (l->wild_statement.children.head);
153 fprintf (stderr, "msp430 orphan placer: unhandled lang type %d\n", l->header.type);
163 /* Place an orphan section. We use this to put .either sections
164 into either their lower or their upper equivalents. */
166 static lang_output_section_statement_type *
167 gld${EMULATION_NAME}_place_orphan (asection * s,
168 const char * secname,
174 lang_output_section_statement_type * lower;
175 lang_output_section_statement_type * upper;
176 lang_output_section_statement_type * os;
178 if ((s->flags & SEC_ALLOC) == 0)
181 if (bfd_link_relocatable (&link_info))
184 /* If constraints are involved let the linker handle the placement normally. */
188 /* We only need special handling for .either sections. */
189 if (strncmp (secname, ".either.", 8) != 0)
192 /* Skip the .either prefix. */
195 /* Compute the names of the corresponding upper and lower
196 sections. If the input section name contains another period,
197 only use the part of the name before the second dot. */
198 if (strchr (secname + 1, '.') != NULL)
200 name = ACONCAT ((secname, NULL));
202 * strchr (name + 1, '.') = 0;
205 name = (char *) secname;
207 lower_name = ACONCAT ((".lower", name, NULL));
208 upper_name = ACONCAT ((".upper", name, NULL));
210 /* Find the corresponding lower and upper sections. */
211 lower = lang_output_section_find (lower_name);
212 upper = lang_output_section_find (upper_name);
213 /* If the upper section does not exist, try again without the suffix. */
215 upper = lang_output_section_find (name);
222 einfo ("%P: error: no section named %s or %s in linker script\n", lower_name, upper_name);
226 else if (upper == NULL)
228 else if (lower->region == NULL)
230 /* If the section is too big for the region containing
231 the lower section then do not even try to use it. */
232 else if (lower->region->length < s->size)
236 bfd_size_type amount = 0;
237 struct lang_output_section_statement_struct * p;
239 amount += scan_children (lower->children.head);
241 /* Also check forwards for other statements assigned to the same region. */
242 for (p = lower->next; p != NULL; p = p->next)
243 if (p->region == lower->region)
244 amount += scan_children (p->children.head);
246 /* Scan backwards as well. */
247 for (p = lower->prev; p != NULL; p = p->prev)
248 if (p->region == lower->region)
249 amount += scan_children (p->children.head);
251 if (amount + s->size >= lower->region->length)
257 lang_add_section (& os->children, s, NULL, os);
265 struct ld_emulation_xfer_struct ld_${EMULATION_NAME}_emulation =
267 ${LDEMUL_BEFORE_PARSE-gld${EMULATION_NAME}_before_parse},
268 ${LDEMUL_SYSLIB-syslib_default},
269 ${LDEMUL_HLL-hll_default},
270 ${LDEMUL_AFTER_PARSE-after_parse_default},
271 ${LDEMUL_AFTER_OPEN-after_open_default},
272 ${LDEMUL_AFTER_ALLOCATION-after_allocation_default},
273 ${LDEMUL_SET_OUTPUT_ARCH-set_output_arch_default},
274 ${LDEMUL_CHOOSE_TARGET-ldemul_default_target},
275 ${LDEMUL_BEFORE_ALLOCATION-before_allocation_default},
276 ${LDEMUL_GET_SCRIPT-gld${EMULATION_NAME}_get_script},
279 ${LDEMUL_FINISH-finish_default},
280 ${LDEMUL_CREATE_OUTPUT_SECTION_STATEMENTS-NULL},
281 ${LDEMUL_OPEN_DYNAMIC_ARCHIVE-NULL},
282 ${LDEMUL_PLACE_ORPHAN-gld${EMULATION_NAME}_place_orphan},
283 ${LDEMUL_SET_SYMBOLS-NULL},
284 ${LDEMUL_PARSE_ARGS-NULL},
285 ${LDEMUL_ADD_OPTIONS-NULL},
286 ${LDEMUL_HANDLE_OPTION-NULL},
287 ${LDEMUL_UNRECOGNIZED_FILE-NULL},
288 ${LDEMUL_LIST_OPTIONS-NULL},
289 ${LDEMUL_RECOGNIZED_FILE-NULL},
290 ${LDEMUL_FIND_POTENTIAL_LIBRARIES-NULL},
291 ${LDEMUL_NEW_VERS_PATTERN-NULL},
292 ${LDEMUL_EXTRA_MAP_FILE_TEXT-NULL}