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,
175 lang_output_section_statement_type * lower;
176 lang_output_section_statement_type * upper;
177 lang_output_section_statement_type * os;
179 if ((s->flags & SEC_ALLOC) == 0)
182 if (bfd_link_relocatable (&link_info))
185 /* If constraints are involved let the linker handle the placement normally. */
189 /* We only need special handling for .either sections. */
190 if (strncmp (secname, ".either.", 8) != 0)
193 /* Skip the .either prefix. */
196 /* Compute the names of the corresponding upper and lower
197 sections. If the input section name contains another period,
198 only use the part of the name before the second dot. */
199 if (strchr (secname + 1, '.') != NULL)
201 buf = name = xstrdup (secname);
203 * strchr (name + 1, '.') = 0;
206 name = (char *) secname;
208 lower_name = concat (".lower", name, NULL);
209 upper_name = concat (".upper", name, NULL);
211 /* Find the corresponding lower and upper sections. */
212 lower = lang_output_section_find (lower_name);
213 upper = lang_output_section_find (upper_name);
214 /* If the upper section does not exist, try again without the suffix. */
216 upper = lang_output_section_find (name);
223 einfo ("%P: error: no section named %s or %s in linker script\n", lower_name, upper_name);
227 else if (upper == NULL)
229 else if (lower->region == NULL)
231 /* If the section is too big for the region containing
232 the lower section then do not even try to use it. */
233 else if (lower->region->length < s->size)
237 bfd_size_type amount = 0;
238 struct lang_output_section_statement_struct * p;
240 amount += scan_children (lower->children.head);
242 /* Also check forwards for other statements assigned to the same region. */
243 for (p = lower->next; p != NULL; p = p->next)
244 if (p->region == lower->region)
245 amount += scan_children (p->children.head);
247 /* Scan backwards as well. */
248 for (p = lower->prev; p != NULL; p = p->prev)
249 if (p->region == lower->region)
250 amount += scan_children (p->children.head);
252 if (amount + s->size >= lower->region->length)
258 lang_add_section (& os->children, s, NULL, os);
271 struct ld_emulation_xfer_struct ld_${EMULATION_NAME}_emulation =
273 ${LDEMUL_BEFORE_PARSE-gld${EMULATION_NAME}_before_parse},
274 ${LDEMUL_SYSLIB-syslib_default},
275 ${LDEMUL_HLL-hll_default},
276 ${LDEMUL_AFTER_PARSE-after_parse_default},
277 ${LDEMUL_AFTER_OPEN-after_open_default},
278 ${LDEMUL_AFTER_ALLOCATION-after_allocation_default},
279 ${LDEMUL_SET_OUTPUT_ARCH-set_output_arch_default},
280 ${LDEMUL_CHOOSE_TARGET-ldemul_default_target},
281 ${LDEMUL_BEFORE_ALLOCATION-before_allocation_default},
282 ${LDEMUL_GET_SCRIPT-gld${EMULATION_NAME}_get_script},
285 ${LDEMUL_FINISH-finish_default},
286 ${LDEMUL_CREATE_OUTPUT_SECTION_STATEMENTS-NULL},
287 ${LDEMUL_OPEN_DYNAMIC_ARCHIVE-NULL},
288 ${LDEMUL_PLACE_ORPHAN-gld${EMULATION_NAME}_place_orphan},
289 ${LDEMUL_SET_SYMBOLS-NULL},
290 ${LDEMUL_PARSE_ARGS-NULL},
291 ${LDEMUL_ADD_OPTIONS-NULL},
292 ${LDEMUL_HANDLE_OPTION-NULL},
293 ${LDEMUL_UNRECOGNIZED_FILE-NULL},
294 ${LDEMUL_LIST_OPTIONS-NULL},
295 ${LDEMUL_RECOGNIZED_FILE-NULL},
296 ${LDEMUL_FIND_POTENTIAL_LIBRARIES-NULL},
297 ${LDEMUL_NEW_VERS_PATTERN-NULL},
298 ${LDEMUL_EXTRA_MAP_FILE_TEXT-NULL}