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