| 1 | # This shell script emits a C file. -*- C -*-
|
|---|
| 2 | # It does some substitutions.
|
|---|
| 3 | cat >e${EMULATION_NAME}.c <<EOF
|
|---|
| 4 | /* This file is is generated by a shell script. DO NOT EDIT! */
|
|---|
| 5 |
|
|---|
| 6 | /* emulate the original gld for the given ${EMULATION_NAME}
|
|---|
| 7 | Copyright 1991, 1993, 1996, 1997, 1998, 1999, 2000, 2001, 2002, 2003
|
|---|
| 8 | Free Software Foundation, Inc.
|
|---|
| 9 | Written by Steve Chamberlain steve@cygnus.com
|
|---|
| 10 |
|
|---|
| 11 | This file is part of GLD, the Gnu Linker.
|
|---|
| 12 |
|
|---|
| 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 2 of the License, or
|
|---|
| 16 | (at your option) any later version.
|
|---|
| 17 |
|
|---|
| 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.
|
|---|
| 22 |
|
|---|
| 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., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */
|
|---|
| 26 |
|
|---|
| 27 | #define TARGET_IS_${EMULATION_NAME}
|
|---|
| 28 |
|
|---|
| 29 | #include "bfd.h"
|
|---|
| 30 | #include "sysdep.h"
|
|---|
| 31 | #include "bfdlink.h"
|
|---|
| 32 | #include "getopt.h"
|
|---|
| 33 |
|
|---|
| 34 | #include "ld.h"
|
|---|
| 35 | #include "ldmain.h"
|
|---|
| 36 | #include "ldmisc.h"
|
|---|
| 37 |
|
|---|
| 38 | #include "ldexp.h"
|
|---|
| 39 | #include "ldlang.h"
|
|---|
| 40 | #include "ldfile.h"
|
|---|
| 41 | #include "ldemul.h"
|
|---|
| 42 |
|
|---|
| 43 | static void gld${EMULATION_NAME}_before_parse PARAMS ((void));
|
|---|
| 44 | static void gld${EMULATION_NAME}_before_allocation PARAMS ((void));
|
|---|
| 45 | static char *gld${EMULATION_NAME}_get_script PARAMS ((int *isfile));
|
|---|
| 46 | static void gld${EMULATION_NAME}_add_options
|
|---|
| 47 | PARAMS ((int, char **, int, struct option **, int, struct option **));
|
|---|
| 48 | static void gld${EMULATION_NAME}_list_options PARAMS ((FILE *));
|
|---|
| 49 | static bfd_boolean gld${EMULATION_NAME}_handle_option PARAMS ((int));
|
|---|
| 50 | static void gld${EMULATION_NAME}_finish PARAMS ((void));
|
|---|
| 51 | static void gld${EMULATION_NAME}_after_open PARAMS ((void));
|
|---|
| 52 |
|
|---|
| 53 | /* If TRUE, then interworking stubs which support calls to old, non-interworking
|
|---|
| 54 | aware ARM code should be generated. */
|
|---|
| 55 |
|
|---|
| 56 | static int support_old_code = 0;
|
|---|
| 57 | static char * thumb_entry_symbol = NULL;
|
|---|
| 58 |
|
|---|
| 59 | #define OPTION_SUPPORT_OLD_CODE 300
|
|---|
| 60 | #define OPTION_THUMB_ENTRY 301
|
|---|
| 61 |
|
|---|
| 62 | static void
|
|---|
| 63 | gld${EMULATION_NAME}_add_options (ns, shortopts, nl, longopts, nrl, really_longopts)
|
|---|
| 64 | int ns ATTRIBUTE_UNUSED;
|
|---|
| 65 | char **shortopts ATTRIBUTE_UNUSED;
|
|---|
| 66 | int nl;
|
|---|
| 67 | struct option **longopts;
|
|---|
| 68 | int nrl ATTRIBUTE_UNUSED;
|
|---|
| 69 | struct option **really_longopts ATTRIBUTE_UNUSED;
|
|---|
| 70 | {
|
|---|
| 71 | static const struct option xtra_long[] = {
|
|---|
| 72 | {"support-old-code", no_argument, NULL, OPTION_SUPPORT_OLD_CODE},
|
|---|
| 73 | {"thumb-entry", required_argument, NULL, OPTION_THUMB_ENTRY},
|
|---|
| 74 | {NULL, no_argument, NULL, 0}
|
|---|
| 75 | };
|
|---|
| 76 |
|
|---|
| 77 | *longopts = (struct option *)
|
|---|
| 78 | xrealloc (*longopts, nl * sizeof (struct option) + sizeof (xtra_long));
|
|---|
| 79 | memcpy (*longopts + nl, &xtra_long, sizeof (xtra_long));
|
|---|
| 80 | }
|
|---|
| 81 |
|
|---|
| 82 | static void
|
|---|
| 83 | gld${EMULATION_NAME}_list_options (file)
|
|---|
| 84 | FILE * file;
|
|---|
| 85 | {
|
|---|
| 86 | fprintf (file, _(" --support-old-code Support interworking with old code\n"));
|
|---|
| 87 | fprintf (file, _(" --thumb-entry=<sym> Set the entry point to be Thumb symbol <sym>\n"));
|
|---|
| 88 | }
|
|---|
| 89 |
|
|---|
| 90 | static bfd_boolean
|
|---|
| 91 | gld${EMULATION_NAME}_handle_option (optc)
|
|---|
| 92 | int optc;
|
|---|
| 93 | {
|
|---|
| 94 | switch (optc)
|
|---|
| 95 | {
|
|---|
| 96 | default:
|
|---|
| 97 | return FALSE;
|
|---|
| 98 |
|
|---|
| 99 | case OPTION_SUPPORT_OLD_CODE:
|
|---|
| 100 | support_old_code = 1;
|
|---|
| 101 | break;
|
|---|
| 102 |
|
|---|
| 103 | case OPTION_THUMB_ENTRY:
|
|---|
| 104 | thumb_entry_symbol = optarg;
|
|---|
| 105 | break;
|
|---|
| 106 | }
|
|---|
| 107 |
|
|---|
| 108 | return TRUE;
|
|---|
| 109 | }
|
|---|
| 110 | |
|---|
| 111 |
|
|---|
| 112 | static void
|
|---|
| 113 | gld${EMULATION_NAME}_before_parse ()
|
|---|
| 114 | {
|
|---|
| 115 | #ifndef TARGET_ /* I.e., if not generic. */
|
|---|
| 116 | ldfile_set_output_arch ("`echo ${ARCH}`");
|
|---|
| 117 | #endif /* not TARGET_ */
|
|---|
| 118 | }
|
|---|
| 119 |
|
|---|
| 120 | /* This is called after the sections have been attached to output
|
|---|
| 121 | sections, but before any sizes or addresses have been set. */
|
|---|
| 122 |
|
|---|
| 123 | static void
|
|---|
| 124 | gld${EMULATION_NAME}_before_allocation ()
|
|---|
| 125 | {
|
|---|
| 126 | /* we should be able to set the size of the interworking stub section */
|
|---|
| 127 |
|
|---|
| 128 | /* Here we rummage through the found bfds to collect glue information */
|
|---|
| 129 | /* FIXME: should this be based on a command line option? krk@cygnus.com */
|
|---|
| 130 | {
|
|---|
| 131 | LANG_FOR_EACH_INPUT_STATEMENT (is)
|
|---|
| 132 | {
|
|---|
| 133 | if (! bfd_arm_process_before_allocation
|
|---|
| 134 | (is->the_bfd, & link_info, support_old_code))
|
|---|
| 135 | {
|
|---|
| 136 | /* xgettext:c-format */
|
|---|
| 137 | einfo (_("Errors encountered processing file %s"), is->filename);
|
|---|
| 138 | }
|
|---|
| 139 | }
|
|---|
| 140 | }
|
|---|
| 141 |
|
|---|
| 142 | /* We have seen it all. Allocate it, and carry on */
|
|---|
| 143 | bfd_arm_allocate_interworking_sections (& link_info);
|
|---|
| 144 | }
|
|---|
| 145 |
|
|---|
| 146 | static void
|
|---|
| 147 | gld${EMULATION_NAME}_after_open ()
|
|---|
| 148 | {
|
|---|
| 149 | if (strstr (bfd_get_target (output_bfd), "arm") == NULL)
|
|---|
| 150 | {
|
|---|
| 151 | /* The arm backend needs special fields in the output hash structure.
|
|---|
| 152 | These will only be created if the output format is an arm format,
|
|---|
| 153 | hence we do not support linking and changing output formats at the
|
|---|
| 154 | same time. Use a link followed by objcopy to change output formats. */
|
|---|
| 155 | einfo ("%F%X%P: error: cannot change output format whilst linking ARM binaries\n");
|
|---|
| 156 | return;
|
|---|
| 157 | }
|
|---|
| 158 |
|
|---|
| 159 | {
|
|---|
| 160 | LANG_FOR_EACH_INPUT_STATEMENT (is)
|
|---|
| 161 | {
|
|---|
| 162 | if (bfd_arm_get_bfd_for_interworking (is->the_bfd, & link_info))
|
|---|
| 163 | break;
|
|---|
| 164 | }
|
|---|
| 165 | }
|
|---|
| 166 | }
|
|---|
| 167 |
|
|---|
| 168 | static void
|
|---|
| 169 | gld${EMULATION_NAME}_finish PARAMS((void))
|
|---|
| 170 | {
|
|---|
| 171 | struct bfd_link_hash_entry * h;
|
|---|
| 172 |
|
|---|
| 173 | if (thumb_entry_symbol == NULL)
|
|---|
| 174 | return;
|
|---|
| 175 |
|
|---|
| 176 | h = bfd_link_hash_lookup (link_info.hash, thumb_entry_symbol,
|
|---|
| 177 | FALSE, FALSE, TRUE);
|
|---|
| 178 |
|
|---|
| 179 | if (h != (struct bfd_link_hash_entry *) NULL
|
|---|
| 180 | && (h->type == bfd_link_hash_defined
|
|---|
| 181 | || h->type == bfd_link_hash_defweak)
|
|---|
| 182 | && h->u.def.section->output_section != NULL)
|
|---|
| 183 | {
|
|---|
| 184 | static char buffer[32];
|
|---|
| 185 | bfd_vma val;
|
|---|
| 186 |
|
|---|
| 187 | /* Special procesing is required for a Thumb entry symbol. The
|
|---|
| 188 | bottom bit of its address must be set. */
|
|---|
| 189 | val = (h->u.def.value
|
|---|
| 190 | + bfd_get_section_vma (output_bfd,
|
|---|
| 191 | h->u.def.section->output_section)
|
|---|
| 192 | + h->u.def.section->output_offset);
|
|---|
| 193 |
|
|---|
| 194 | val |= 1;
|
|---|
| 195 |
|
|---|
| 196 | /* Now convert this value into a string and store it in entry_symbol
|
|---|
| 197 | where the lang_finish() function will pick it up. */
|
|---|
| 198 | buffer[0] = '0';
|
|---|
| 199 | buffer[1] = 'x';
|
|---|
| 200 |
|
|---|
| 201 | sprintf_vma (buffer + 2, val);
|
|---|
| 202 |
|
|---|
| 203 | if (entry_symbol.name != NULL && entry_from_cmdline)
|
|---|
| 204 | einfo (_("%P: warning: '--thumb-entry %s' is overriding '-e %s'\n"),
|
|---|
| 205 | thumb_entry_symbol, entry_symbol.name);
|
|---|
| 206 | entry_symbol.name = buffer;
|
|---|
| 207 | }
|
|---|
| 208 | else
|
|---|
| 209 | einfo (_("%P: warning: connot find thumb start symbol %s\n"), thumb_entry_symbol);
|
|---|
| 210 | }
|
|---|
| 211 |
|
|---|
| 212 | static char *
|
|---|
| 213 | gld${EMULATION_NAME}_get_script (isfile)
|
|---|
| 214 | int *isfile;
|
|---|
| 215 | EOF
|
|---|
| 216 |
|
|---|
| 217 | if test -n "$COMPILE_IN"
|
|---|
| 218 | then
|
|---|
| 219 | # Scripts compiled in.
|
|---|
| 220 |
|
|---|
| 221 | # sed commands to quote an ld script as a C string.
|
|---|
| 222 | sc="-f stringify.sed"
|
|---|
| 223 |
|
|---|
| 224 | cat >>e${EMULATION_NAME}.c <<EOF
|
|---|
| 225 | {
|
|---|
| 226 | *isfile = 0;
|
|---|
| 227 |
|
|---|
| 228 | if (link_info.relocateable && config.build_constructors)
|
|---|
| 229 | return
|
|---|
| 230 | EOF
|
|---|
| 231 | sed $sc ldscripts/${EMULATION_NAME}.xu >> e${EMULATION_NAME}.c
|
|---|
| 232 | echo ' ; else if (link_info.relocateable) return' >> e${EMULATION_NAME}.c
|
|---|
| 233 | sed $sc ldscripts/${EMULATION_NAME}.xr >> e${EMULATION_NAME}.c
|
|---|
| 234 | echo ' ; else if (!config.text_read_only) return' >> e${EMULATION_NAME}.c
|
|---|
| 235 | sed $sc ldscripts/${EMULATION_NAME}.xbn >> e${EMULATION_NAME}.c
|
|---|
| 236 | echo ' ; else if (!config.magic_demand_paged) return' >> e${EMULATION_NAME}.c
|
|---|
| 237 | sed $sc ldscripts/${EMULATION_NAME}.xn >> e${EMULATION_NAME}.c
|
|---|
| 238 | echo ' ; else return' >> e${EMULATION_NAME}.c
|
|---|
| 239 | sed $sc ldscripts/${EMULATION_NAME}.x >> e${EMULATION_NAME}.c
|
|---|
| 240 | echo '; }' >> e${EMULATION_NAME}.c
|
|---|
| 241 |
|
|---|
| 242 | else
|
|---|
| 243 | # Scripts read from the filesystem.
|
|---|
| 244 |
|
|---|
| 245 | cat >>e${EMULATION_NAME}.c <<EOF
|
|---|
| 246 | {
|
|---|
| 247 | *isfile = 1;
|
|---|
| 248 |
|
|---|
| 249 | if (link_info.relocateable && config.build_constructors)
|
|---|
| 250 | return "ldscripts/${EMULATION_NAME}.xu";
|
|---|
| 251 | else if (link_info.relocateable)
|
|---|
| 252 | return "ldscripts/${EMULATION_NAME}.xr";
|
|---|
| 253 | else if (!config.text_read_only)
|
|---|
| 254 | return "ldscripts/${EMULATION_NAME}.xbn";
|
|---|
| 255 | else if (!config.magic_demand_paged)
|
|---|
| 256 | return "ldscripts/${EMULATION_NAME}.xn";
|
|---|
| 257 | else
|
|---|
| 258 | return "ldscripts/${EMULATION_NAME}.x";
|
|---|
| 259 | }
|
|---|
| 260 | EOF
|
|---|
| 261 |
|
|---|
| 262 | fi
|
|---|
| 263 |
|
|---|
| 264 | cat >>e${EMULATION_NAME}.c <<EOF
|
|---|
| 265 |
|
|---|
| 266 | struct ld_emulation_xfer_struct ld_${EMULATION_NAME}_emulation =
|
|---|
| 267 | {
|
|---|
| 268 | gld${EMULATION_NAME}_before_parse,
|
|---|
| 269 | syslib_default,
|
|---|
| 270 | hll_default,
|
|---|
| 271 | after_parse_default,
|
|---|
| 272 | gld${EMULATION_NAME}_after_open,
|
|---|
| 273 | after_allocation_default,
|
|---|
| 274 | set_output_arch_default,
|
|---|
| 275 | ldemul_default_target,
|
|---|
| 276 | gld${EMULATION_NAME}_before_allocation,
|
|---|
| 277 | gld${EMULATION_NAME}_get_script,
|
|---|
| 278 | "${EMULATION_NAME}",
|
|---|
| 279 | "${OUTPUT_FORMAT}",
|
|---|
| 280 | gld${EMULATION_NAME}_finish,
|
|---|
| 281 | NULL, /* create output section statements */
|
|---|
| 282 | NULL, /* open dynamic archive */
|
|---|
| 283 | NULL, /* place orphan */
|
|---|
| 284 | NULL, /* set symbols */
|
|---|
| 285 | NULL, /* parse_args */
|
|---|
| 286 | gld${EMULATION_NAME}_add_options,
|
|---|
| 287 | gld${EMULATION_NAME}_handle_option,
|
|---|
| 288 | NULL, /* unrecognised file */
|
|---|
| 289 | gld${EMULATION_NAME}_list_options,
|
|---|
| 290 | NULL, /* recognized file */
|
|---|
| 291 | NULL, /* find_potential_libraries */
|
|---|
| 292 | NULL /* new_vers_pattern */
|
|---|
| 293 | };
|
|---|
| 294 | EOF
|
|---|