| 1 | # This shell script emits a C file. -*- C -*-
|
|---|
| 2 | # It does some substitutions.
|
|---|
| 3 | (echo;echo;echo;echo)>e${EMULATION_NAME}.c # there, now line numbers match ;-)
|
|---|
| 4 | cat >>e${EMULATION_NAME}.c <<EOF
|
|---|
| 5 | /* This file is part of GLD, the Gnu Linker.
|
|---|
| 6 | Copyright 1999, 2000, 2002, 2003 Free Software Foundation, Inc.
|
|---|
| 7 |
|
|---|
| 8 | This program is free software; you can redistribute it and/or modify
|
|---|
| 9 | it under the terms of the GNU General Public License as published by
|
|---|
| 10 | the Free Software Foundation; either version 2 of the License, or
|
|---|
| 11 | (at your option) any later version.
|
|---|
| 12 |
|
|---|
| 13 | This program is distributed in the hope that it will be useful,
|
|---|
| 14 | but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|---|
| 15 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|---|
| 16 | GNU General Public License for more details.
|
|---|
| 17 |
|
|---|
| 18 | You should have received a copy of the GNU General Public License
|
|---|
| 19 | along with this program; if not, write to the Free Software
|
|---|
| 20 | Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */
|
|---|
| 21 |
|
|---|
| 22 | /* For TI COFF */
|
|---|
| 23 | /* Need to determine load and run pages for output sections */
|
|---|
| 24 |
|
|---|
| 25 | #define TARGET_IS_${EMULATION_NAME}
|
|---|
| 26 |
|
|---|
| 27 | #include "bfd.h"
|
|---|
| 28 | #include "sysdep.h"
|
|---|
| 29 | #include "bfdlink.h"
|
|---|
| 30 | #include "getopt.h"
|
|---|
| 31 |
|
|---|
| 32 | #include "ld.h"
|
|---|
| 33 | #include "ldmain.h"
|
|---|
| 34 | #include "ldmisc.h"
|
|---|
| 35 | #include "ldexp.h"
|
|---|
| 36 | #include "ldlang.h"
|
|---|
| 37 | #include "ldfile.h"
|
|---|
| 38 | #include "ldemul.h"
|
|---|
| 39 |
|
|---|
| 40 | static int coff_version;
|
|---|
| 41 |
|
|---|
| 42 | static void gld_${EMULATION_NAME}_before_parse PARAMS ((void));
|
|---|
| 43 | static char *gld_${EMULATION_NAME}_get_script PARAMS ((int *));
|
|---|
| 44 | static void gld${EMULATION_NAME}_add_options
|
|---|
| 45 | PARAMS ((int, char **, int, struct option **, int, struct option **));
|
|---|
| 46 | static bfd_boolean gld${EMULATION_NAME}_handle_option PARAMS ((int));
|
|---|
| 47 | static void gld_${EMULATION_NAME}_list_options PARAMS ((FILE *));
|
|---|
| 48 |
|
|---|
| 49 | /* TI COFF extra command line options */
|
|---|
| 50 | #define OPTION_COFF_FORMAT (300 + 1)
|
|---|
| 51 |
|
|---|
| 52 | static void
|
|---|
| 53 | gld${EMULATION_NAME}_add_options (ns, shortopts, nl, longopts, nrl, really_longopts)
|
|---|
| 54 | int ns ATTRIBUTE_UNUSED;
|
|---|
| 55 | char **shortopts ATTRIBUTE_UNUSED;
|
|---|
| 56 | int nl;
|
|---|
| 57 | struct option **longopts;
|
|---|
| 58 | int nrl ATTRIBUTE_UNUSED;
|
|---|
| 59 | struct option **really_longopts ATTRIBUTE_UNUSED;
|
|---|
| 60 | {
|
|---|
| 61 | static const struct option xtra_long[] = {
|
|---|
| 62 | /* TI COFF options */
|
|---|
| 63 | {"format", required_argument, NULL, OPTION_COFF_FORMAT },
|
|---|
| 64 | {NULL, no_argument, NULL, 0}
|
|---|
| 65 | };
|
|---|
| 66 |
|
|---|
| 67 | *longopts = (struct option *)
|
|---|
| 68 | xrealloc (*longopts, nl * sizeof (struct option) + sizeof (xtra_long));
|
|---|
| 69 | memcpy (*longopts + nl, &xtra_long, sizeof (xtra_long));
|
|---|
| 70 | }
|
|---|
| 71 |
|
|---|
| 72 | static void
|
|---|
| 73 | gld_${EMULATION_NAME}_list_options (file)
|
|---|
| 74 | FILE * file;
|
|---|
| 75 | {
|
|---|
| 76 | fprintf (file, _(" --format 0|1|2 Specify which COFF version to use"));
|
|---|
| 77 | }
|
|---|
| 78 |
|
|---|
| 79 | static bfd_boolean
|
|---|
| 80 | gld${EMULATION_NAME}_handle_option (optc)
|
|---|
| 81 | int optc;
|
|---|
| 82 | {
|
|---|
| 83 | switch (optc)
|
|---|
| 84 | {
|
|---|
| 85 | default:
|
|---|
| 86 | return FALSE;
|
|---|
| 87 |
|
|---|
| 88 | case OPTION_COFF_FORMAT:
|
|---|
| 89 | if ((*optarg == '0' || *optarg == '1' || *optarg == '2')
|
|---|
| 90 | && optarg[1] == '\0')
|
|---|
| 91 | {
|
|---|
| 92 | extern void lang_add_output_format
|
|---|
| 93 | PARAMS ((const char *, const char *, const char *, int));
|
|---|
| 94 | static char buf[] = "coffX-${OUTPUT_FORMAT_TEMPLATE}";
|
|---|
| 95 | coff_version = *optarg - '0';
|
|---|
| 96 | buf[4] = *optarg;
|
|---|
| 97 | lang_add_output_format (buf, NULL, NULL, 0);
|
|---|
| 98 | }
|
|---|
| 99 | else
|
|---|
| 100 | {
|
|---|
| 101 | einfo (_("%P%F: invalid COFF format version %s\n"), optarg);
|
|---|
| 102 | }
|
|---|
| 103 | break;
|
|---|
| 104 | }
|
|---|
| 105 | return FALSE;
|
|---|
| 106 | }
|
|---|
| 107 |
|
|---|
| 108 | static void
|
|---|
| 109 | gld_${EMULATION_NAME}_before_parse()
|
|---|
| 110 | {
|
|---|
| 111 | #ifndef TARGET_ /* I.e., if not generic. */
|
|---|
| 112 | ldfile_set_output_arch ("`echo ${ARCH}`");
|
|---|
| 113 | #endif /* not TARGET_ */
|
|---|
| 114 | }
|
|---|
| 115 |
|
|---|
| 116 | static char *
|
|---|
| 117 | gld_${EMULATION_NAME}_get_script (isfile)
|
|---|
| 118 | int *isfile;
|
|---|
| 119 | EOF
|
|---|
| 120 | if test -n "$COMPILE_IN"
|
|---|
| 121 | then
|
|---|
| 122 | # Scripts compiled in.
|
|---|
| 123 |
|
|---|
| 124 | # sed commands to quote an ld script as a C string.
|
|---|
| 125 | sc='s/["\\]/\\&/g
|
|---|
| 126 | s/$/\\n\\/
|
|---|
| 127 | 1s/^/"/
|
|---|
| 128 | $s/$/n"/
|
|---|
| 129 | '
|
|---|
| 130 | cat >>e${EMULATION_NAME}.c <<EOF
|
|---|
| 131 | {
|
|---|
| 132 | *isfile = 0;
|
|---|
| 133 | if (link_info.relocateable && config.build_constructors)
|
|---|
| 134 | return `sed "$sc" ldscripts/${EMULATION_NAME}.xu`;
|
|---|
| 135 | else if (link_info.relocateable)
|
|---|
| 136 | return `sed "$sc" ldscripts/${EMULATION_NAME}.xr`;
|
|---|
| 137 | else if (!config.text_read_only)
|
|---|
| 138 | return `sed "$sc" ldscripts/${EMULATION_NAME}.xbn`;
|
|---|
| 139 | else if (!config.magic_demand_paged)
|
|---|
| 140 | return `sed "$sc" ldscripts/${EMULATION_NAME}.xn`;
|
|---|
| 141 | else
|
|---|
| 142 | return `sed "$sc" ldscripts/${EMULATION_NAME}.x`;
|
|---|
| 143 | }
|
|---|
| 144 | EOF
|
|---|
| 145 |
|
|---|
| 146 | else
|
|---|
| 147 | # Scripts read from the filesystem.
|
|---|
| 148 |
|
|---|
| 149 | cat >>e${EMULATION_NAME}.c <<EOF
|
|---|
| 150 | {
|
|---|
| 151 | *isfile = 1;
|
|---|
| 152 |
|
|---|
| 153 | if (link_info.relocateable && config.build_constructors)
|
|---|
| 154 | return "ldscripts/${EMULATION_NAME}.xu";
|
|---|
| 155 | else if (link_info.relocateable)
|
|---|
| 156 | return "ldscripts/${EMULATION_NAME}.xr";
|
|---|
| 157 | else if (!config.text_read_only)
|
|---|
| 158 | return "ldscripts/${EMULATION_NAME}.xbn";
|
|---|
| 159 | else if (!config.magic_demand_paged)
|
|---|
| 160 | return "ldscripts/${EMULATION_NAME}.xn";
|
|---|
| 161 | else
|
|---|
| 162 | return "ldscripts/${EMULATION_NAME}.x";
|
|---|
| 163 | }
|
|---|
| 164 | EOF
|
|---|
| 165 |
|
|---|
| 166 | fi
|
|---|
| 167 |
|
|---|
| 168 | cat >>e${EMULATION_NAME}.c <<EOF
|
|---|
| 169 | struct ld_emulation_xfer_struct ld_${EMULATION_NAME}_emulation =
|
|---|
| 170 | {
|
|---|
| 171 | gld_${EMULATION_NAME}_before_parse,
|
|---|
| 172 | syslib_default,
|
|---|
| 173 | hll_default,
|
|---|
| 174 | after_parse_default,
|
|---|
| 175 | after_open_default,
|
|---|
| 176 | after_allocation_default,
|
|---|
| 177 | set_output_arch_default,
|
|---|
| 178 | ldemul_default_target,
|
|---|
| 179 | before_allocation_default,
|
|---|
| 180 | gld_${EMULATION_NAME}_get_script,
|
|---|
| 181 | "${EMULATION_NAME}",
|
|---|
| 182 | "${OUTPUT_FORMAT}",
|
|---|
| 183 | NULL, /* finish */
|
|---|
| 184 | NULL, /* create output section statements */
|
|---|
| 185 | NULL, /* open dynamic archive */
|
|---|
| 186 | NULL, /* place orphan */
|
|---|
| 187 | NULL, /* set_symbols */
|
|---|
| 188 | NULL, /* parse_args */
|
|---|
| 189 | gld${EMULATION_NAME}_add_options,
|
|---|
| 190 | gld${EMULATION_NAME}_handle_option,
|
|---|
| 191 | NULL, /* unrecognized_file */
|
|---|
| 192 | gld_${EMULATION_NAME}_list_options,
|
|---|
| 193 | NULL, /* recognized file */
|
|---|
| 194 | NULL, /* find_potential_libraries */
|
|---|
| 195 | NULL /* new_vers_pattern */
|
|---|
| 196 | };
|
|---|
| 197 | EOF
|
|---|