Commit | Line | Data |
---|---|---|
74459f0e TW |
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 ;-) | |
92b93329 | 4 | fragment <<EOF |
74459f0e | 5 | /* This file is part of GLD, the Gnu Linker. |
2571583a | 6 | Copyright (C) 1999-2017 Free Software Foundation, Inc. |
74459f0e | 7 | |
f96b4a7b NC |
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. */ | |
74459f0e TW |
24 | |
25 | /* For TI COFF */ | |
5e2f1575 AM |
26 | /* Need to determine load and run pages for output sections */ |
27 | ||
74459f0e TW |
28 | #define TARGET_IS_${EMULATION_NAME} |
29 | ||
74459f0e | 30 | #include "sysdep.h" |
3db64b00 | 31 | #include "bfd.h" |
74459f0e | 32 | #include "bfdlink.h" |
fcf65871 | 33 | #include "getopt.h" |
74459f0e TW |
34 | |
35 | #include "ld.h" | |
36 | #include "ldmain.h" | |
74459f0e | 37 | #include "ldmisc.h" |
b71e2778 AM |
38 | #include "ldexp.h" |
39 | #include "ldlang.h" | |
40 | #include "ldfile.h" | |
41 | #include "ldemul.h" | |
42 | ||
74459f0e TW |
43 | static int coff_version; |
44 | ||
74459f0e TW |
45 | /* TI COFF extra command line options */ |
46 | #define OPTION_COFF_FORMAT (300 + 1) | |
47 | ||
3bcf5557 | 48 | static void |
0c7a8e5a AM |
49 | gld${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) | |
74459f0e | 53 | { |
3bcf5557 AM |
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 | } | |
74459f0e TW |
64 | |
65 | static void | |
0c7a8e5a | 66 | gld_${EMULATION_NAME}_list_options (FILE * file) |
74459f0e | 67 | { |
442996ee | 68 | fprintf (file, _(" --format 0|1|2 Specify which COFF version to use\n")); |
5e2f1575 | 69 | } |
74459f0e | 70 | |
3bcf5557 | 71 | static bfd_boolean |
0c7a8e5a | 72 | gld${EMULATION_NAME}_handle_option (int optc) |
74459f0e | 73 | { |
74459f0e TW |
74 | switch (optc) |
75 | { | |
76 | default: | |
3bcf5557 | 77 | return FALSE; |
74459f0e TW |
78 | |
79 | case OPTION_COFF_FORMAT: | |
80 | if ((*optarg == '0' || *optarg == '1' || *optarg == '2') | |
6c19b93b AM |
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 | } | |
74459f0e | 88 | else |
6c19b93b | 89 | { |
74459f0e | 90 | einfo (_("%P%F: invalid COFF format version %s\n"), optarg); |
6c19b93b | 91 | } |
74459f0e TW |
92 | break; |
93 | } | |
3bcf5557 | 94 | return FALSE; |
74459f0e TW |
95 | } |
96 | ||
97 | static void | |
0c7a8e5a | 98 | gld_${EMULATION_NAME}_before_parse(void) |
74459f0e TW |
99 | { |
100 | #ifndef TARGET_ /* I.e., if not generic. */ | |
5e2f1575 | 101 | ldfile_set_output_arch ("`echo ${ARCH}`", bfd_arch_unknown); |
74459f0e TW |
102 | #endif /* not TARGET_ */ |
103 | } | |
104 | ||
105 | static char * | |
0c7a8e5a | 106 | gld_${EMULATION_NAME}_get_script (int *isfile) |
74459f0e | 107 | EOF |
7225345d | 108 | if test x"$COMPILE_IN" = xyes |
74459f0e TW |
109 | then |
110 | # Scripts compiled in. | |
111 | ||
112 | # sed commands to quote an ld script as a C string. | |
113 | sc='s/["\\]/\\&/g | |
114 | s/$/\\n\\/ | |
115 | 1s/^/"/ | |
116 | $s/$/n"/ | |
117 | ' | |
92b93329 | 118 | fragment <<EOF |
5e2f1575 | 119 | { |
74459f0e | 120 | *isfile = 0; |
0e1862bb | 121 | if (bfd_link_relocatable (&link_info) && config.build_constructors) |
74459f0e | 122 | return `sed "$sc" ldscripts/${EMULATION_NAME}.xu`; |
0e1862bb | 123 | else if (bfd_link_relocatable (&link_info)) |
74459f0e TW |
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 | } | |
132 | EOF | |
133 | ||
134 | else | |
135 | # Scripts read from the filesystem. | |
136 | ||
92b93329 | 137 | fragment <<EOF |
5e2f1575 | 138 | { |
74459f0e TW |
139 | *isfile = 1; |
140 | ||
0e1862bb | 141 | if (bfd_link_relocatable (&link_info) && config.build_constructors) |
74459f0e | 142 | return "ldscripts/${EMULATION_NAME}.xu"; |
0e1862bb | 143 | else if (bfd_link_relocatable (&link_info)) |
74459f0e TW |
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 | } | |
152 | EOF | |
153 | ||
154 | fi | |
155 | ||
92b93329 | 156 | fragment <<EOF |
5e2f1575 | 157 | struct ld_emulation_xfer_struct ld_${EMULATION_NAME}_emulation = |
74459f0e TW |
158 | { |
159 | gld_${EMULATION_NAME}_before_parse, | |
160 | syslib_default, | |
161 | hll_default, | |
162 | after_parse_default, | |
163 | after_open_default, | |
5c3261b0 | 164 | after_check_relocs_default, |
74459f0e TW |
165 | after_allocation_default, |
166 | set_output_arch_default, | |
167 | ldemul_default_target, | |
168 | before_allocation_default, | |
169 | gld_${EMULATION_NAME}_get_script, | |
170 | "${EMULATION_NAME}", | |
171 | "${OUTPUT_FORMAT}", | |
1e035701 | 172 | finish_default, |
74459f0e TW |
173 | NULL, /* create output section statements */ |
174 | NULL, /* open dynamic archive */ | |
175 | NULL, /* place orphan */ | |
176 | NULL, /* set_symbols */ | |
3bcf5557 AM |
177 | NULL, /* parse_args */ |
178 | gld${EMULATION_NAME}_add_options, | |
179 | gld${EMULATION_NAME}_handle_option, | |
74459f0e TW |
180 | NULL, /* unrecognized_file */ |
181 | gld_${EMULATION_NAME}_list_options, | |
182 | NULL, /* recognized file */ | |
fac1652d | 183 | NULL, /* find_potential_libraries */ |
7a2f2d82 DD |
184 | NULL, /* new_vers_pattern */ |
185 | NULL /* extra_map_file_text */ | |
74459f0e TW |
186 | }; |
187 | EOF |