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