]>
Commit | Line | Data |
---|---|---|
252b5132 | 1 | /* mri.c -- handle MRI style linker scripts |
4da711b1 | 2 | Copyright 1991, 1992, 1993, 1994, 1996, 1997, 1998, 1999, 2000, 2002 |
891fa266 | 3 | Free Software Foundation, Inc. |
252b5132 RH |
4 | |
5 | This file is part of GLD, the Gnu Linker. | |
6 | ||
7 | GLD is free software; you can redistribute it and/or modify | |
8 | it under the terms of the GNU General Public License as published by | |
9 | the Free Software Foundation; either version 2, or (at your option) | |
10 | any later version. | |
11 | ||
12 | GLD is distributed in the hope that it will be useful, | |
13 | but WITHOUT ANY WARRANTY; without even the implied warranty of | |
14 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
15 | GNU General Public License for more details. | |
16 | ||
17 | You should have received a copy of the GNU General Public License | |
18 | along with GLD; see the file COPYING. If not, write to the Free | |
19 | Software Foundation, 59 Temple Place - Suite 330, Boston, MA | |
891fa266 | 20 | 02111-1307, USA. |
252b5132 | 21 | |
891fa266 NC |
22 | This bit does the tree decoration when MRI style link scripts |
23 | are parsed. | |
252b5132 | 24 | |
891fa266 | 25 | Contributed by Steve Chamberlain <[email protected]>. */ |
252b5132 RH |
26 | |
27 | #include "bfd.h" | |
5cc18311 | 28 | #include "sysdep.h" |
252b5132 RH |
29 | #include "ld.h" |
30 | #include "ldexp.h" | |
31 | #include "ldlang.h" | |
32 | #include "ldmisc.h" | |
33 | #include "mri.h" | |
df2a7313 | 34 | #include <ldgram.h> |
252b5132 RH |
35 | #include "libiberty.h" |
36 | ||
e47d05ad | 37 | struct section_name_struct { |
252b5132 | 38 | struct section_name_struct *next; |
4da711b1 AM |
39 | const char *name; |
40 | const char *alias; | |
252b5132 RH |
41 | etree_type *vma; |
42 | etree_type *align; | |
43 | etree_type *subalign; | |
44 | int ok_to_load; | |
891fa266 | 45 | }; |
252b5132 RH |
46 | |
47 | unsigned int symbol_truncate = 10000; | |
48 | struct section_name_struct *order; | |
49 | struct section_name_struct *only_load; | |
50 | struct section_name_struct *address; | |
51 | struct section_name_struct *alias; | |
52 | ||
53 | struct section_name_struct *alignment; | |
54 | struct section_name_struct *subalignment; | |
55 | ||
56 | static struct section_name_struct **lookup | |
57 | PARAMS ((const char *name, struct section_name_struct **list)); | |
58 | static void mri_add_to_list PARAMS ((struct section_name_struct **list, | |
59 | const char *name, etree_type *vma, | |
60 | const char *zalias, etree_type *align, | |
61 | etree_type *subalign)); | |
62 | ||
63 | static struct section_name_struct ** | |
64 | lookup (name, list) | |
4da711b1 | 65 | const char *name; |
252b5132 RH |
66 | struct section_name_struct **list; |
67 | { | |
252b5132 | 68 | struct section_name_struct **ptr = list; |
5cc18311 KH |
69 | |
70 | while (*ptr) | |
891fa266 NC |
71 | { |
72 | if (strcmp (name, (*ptr)->name) == 0) | |
73 | /* If this is a match, delete it, we only keep the last instance | |
74 | of any name. */ | |
75 | *ptr = (*ptr)->next; | |
76 | else | |
77 | ptr = &((*ptr)->next); | |
252b5132 | 78 | } |
252b5132 | 79 | |
891fa266 | 80 | *ptr = (struct section_name_struct *) xmalloc (sizeof (struct section_name_struct)); |
252b5132 RH |
81 | return ptr; |
82 | } | |
83 | ||
84 | static void | |
85 | mri_add_to_list (list, name, vma, zalias, align, subalign) | |
86 | struct section_name_struct **list; | |
4da711b1 | 87 | const char *name; |
252b5132 | 88 | etree_type *vma; |
4da711b1 | 89 | const char *zalias; |
252b5132 RH |
90 | etree_type *align; |
91 | etree_type *subalign; | |
92 | { | |
e47d05ad | 93 | struct section_name_struct **ptr = lookup (name, list); |
5cc18311 | 94 | |
252b5132 RH |
95 | (*ptr)->name = name; |
96 | (*ptr)->vma = vma; | |
891fa266 | 97 | (*ptr)->next = (struct section_name_struct *) NULL; |
252b5132 RH |
98 | (*ptr)->ok_to_load = 0; |
99 | (*ptr)->alias = zalias; | |
100 | (*ptr)->align = align; | |
101 | (*ptr)->subalign = subalign; | |
102 | } | |
103 | ||
252b5132 RH |
104 | void |
105 | mri_output_section (name, vma) | |
4da711b1 | 106 | const char *name; |
252b5132 RH |
107 | etree_type *vma; |
108 | { | |
e47d05ad | 109 | mri_add_to_list (&address, name, vma, 0, 0, 0); |
252b5132 RH |
110 | } |
111 | ||
891fa266 NC |
112 | /* If any ABSOLUTE <name> are in the script, only load those files |
113 | marked thus. */ | |
252b5132 RH |
114 | |
115 | void | |
116 | mri_only_load (name) | |
4da711b1 | 117 | const char *name; |
252b5132 | 118 | { |
e47d05ad | 119 | mri_add_to_list (&only_load, name, 0, 0, 0, 0); |
252b5132 RH |
120 | } |
121 | ||
252b5132 RH |
122 | void |
123 | mri_base (exp) | |
124 | etree_type *exp; | |
125 | { | |
126 | base = exp; | |
127 | } | |
128 | ||
129 | static int done_tree = 0; | |
130 | ||
131 | void | |
132 | mri_draw_tree () | |
133 | { | |
891fa266 NC |
134 | if (done_tree) |
135 | return; | |
136 | ||
137 | #if 0 /* We don't bother with memory regions. */ | |
138 | /* Create the regions. */ | |
139 | { | |
140 | lang_memory_region_type *r; | |
5cc18311 | 141 | |
891fa266 NC |
142 | r = lang_memory_region_lookup("long"); |
143 | r->current = r->origin = exp_get_vma (base, (bfd_vma)0, "origin", | |
144 | lang_first_phase_enum); | |
145 | r->length = (bfd_size_type) exp_get_vma (0, (bfd_vma) ~((bfd_size_type)0), | |
146 | "length", lang_first_phase_enum); | |
147 | } | |
252b5132 | 148 | #endif |
5cc18311 | 149 | |
891fa266 | 150 | /* Now build the statements for the ldlang machine. */ |
252b5132 | 151 | |
891fa266 NC |
152 | /* Attatch the addresses of any which have addresses, |
153 | and add the ones not mentioned. */ | |
e47d05ad | 154 | if (address != (struct section_name_struct *) NULL) |
252b5132 | 155 | { |
891fa266 NC |
156 | struct section_name_struct *alist; |
157 | struct section_name_struct *olist; | |
5cc18311 | 158 | |
e47d05ad | 159 | if (order == (struct section_name_struct *) NULL) |
891fa266 NC |
160 | order = address; |
161 | ||
162 | for (alist = address; | |
e47d05ad | 163 | alist != (struct section_name_struct *) NULL; |
5cc18311 | 164 | alist = alist->next) |
252b5132 | 165 | { |
891fa266 | 166 | int done = 0; |
5cc18311 | 167 | |
891fa266 | 168 | for (olist = order; |
e47d05ad | 169 | done == 0 && olist != (struct section_name_struct *) NULL; |
5cc18311 | 170 | olist = olist->next) |
891fa266 | 171 | { |
5cc18311 | 172 | if (strcmp (alist->name, olist->name) == 0) |
891fa266 NC |
173 | { |
174 | olist->vma = alist->vma; | |
175 | done = 1; | |
176 | } | |
177 | } | |
5cc18311 | 178 | |
891fa266 NC |
179 | if (!done) |
180 | { | |
181 | /* Add this onto end of order list. */ | |
e47d05ad | 182 | mri_add_to_list (&order, alist->name, alist->vma, 0, 0, 0); |
891fa266 | 183 | } |
252b5132 | 184 | } |
252b5132 RH |
185 | } |
186 | ||
252b5132 RH |
187 | /* If we're only supposed to load a subset of them in, then prune |
188 | the list. */ | |
e47d05ad | 189 | if (only_load != (struct section_name_struct *) NULL) |
252b5132 | 190 | { |
891fa266 NC |
191 | struct section_name_struct *ptr1; |
192 | struct section_name_struct *ptr2; | |
5cc18311 | 193 | |
e47d05ad | 194 | if (order == (struct section_name_struct *) NULL) |
891fa266 | 195 | order = only_load; |
5cc18311 | 196 | |
891fa266 | 197 | /* See if this name is in the list, if it is then we can load it. */ |
5cc18311 KH |
198 | for (ptr1 = only_load; ptr1; ptr1 = ptr1->next) |
199 | for (ptr2 = order; ptr2; ptr2 = ptr2->next) | |
891fa266 NC |
200 | if (strcmp (ptr2->name, ptr1->name) == 0) |
201 | ptr2->ok_to_load = 1; | |
252b5132 | 202 | } |
5cc18311 | 203 | else |
891fa266 NC |
204 | { |
205 | /* No only load list, so everything is ok to load. */ | |
206 | struct section_name_struct *ptr; | |
5cc18311 | 207 | |
e47d05ad | 208 | for (ptr = order; ptr; ptr = ptr->next) |
891fa266 | 209 | ptr->ok_to_load = 1; |
e47d05ad | 210 | } |
252b5132 | 211 | |
891fa266 | 212 | /* Create the order of sections to load. */ |
e47d05ad | 213 | if (order != (struct section_name_struct *) NULL) |
252b5132 | 214 | { |
891fa266 NC |
215 | /* Been told to output the sections in a certain order. */ |
216 | struct section_name_struct *p = order; | |
5cc18311 KH |
217 | |
218 | while (p) | |
891fa266 NC |
219 | { |
220 | struct section_name_struct *aptr; | |
221 | etree_type *align = 0; | |
222 | etree_type *subalign = 0; | |
b6bf44ba | 223 | struct wildcard_list *tmp; |
5cc18311 | 224 | |
891fa266 | 225 | /* See if an alignment has been specified. */ |
e47d05ad | 226 | for (aptr = alignment; aptr; aptr = aptr->next) |
891fa266 | 227 | if (strcmp (aptr->name, p->name) == 0) |
e47d05ad | 228 | align = aptr->align; |
891fa266 | 229 | |
e47d05ad | 230 | for (aptr = subalignment; aptr; aptr = aptr->next) |
891fa266 | 231 | if (strcmp (aptr->name, p->name) == 0) |
e47d05ad | 232 | subalign = aptr->subalign; |
891fa266 NC |
233 | |
234 | if (base == 0) | |
e47d05ad | 235 | base = p->vma ? p->vma : exp_nameop (NAME, "."); |
891fa266 NC |
236 | |
237 | lang_enter_output_section_statement (p->name, base, | |
238 | p->ok_to_load ? 0 : noload_section, | |
239 | 1, align, subalign, | |
240 | (etree_type *) NULL); | |
241 | base = 0; | |
b6bf44ba AM |
242 | tmp = (struct wildcard_list *) xmalloc (sizeof *tmp); |
243 | tmp->next = NULL; | |
244 | tmp->spec.name = p->name; | |
245 | tmp->spec.exclude_name_list = NULL; | |
b34976b6 AM |
246 | tmp->spec.sorted = FALSE; |
247 | lang_add_wild (NULL, tmp, FALSE); | |
5cc18311 | 248 | |
891fa266 NC |
249 | /* If there is an alias for this section, add it too. */ |
250 | for (aptr = alias; aptr; aptr = aptr->next) | |
251 | if (strcmp (aptr->alias, p->name) == 0) | |
b6bf44ba AM |
252 | { |
253 | tmp = (struct wildcard_list *) xmalloc (sizeof *tmp); | |
254 | tmp->next = NULL; | |
255 | tmp->spec.name = aptr->name; | |
256 | tmp->spec.exclude_name_list = NULL; | |
b34976b6 AM |
257 | tmp->spec.sorted = FALSE; |
258 | lang_add_wild (NULL, tmp, FALSE); | |
b6bf44ba | 259 | } |
891fa266 NC |
260 | |
261 | lang_leave_output_section_statement | |
5cc18311 | 262 | (0, "*default*", (struct lang_output_section_phdr_list *) NULL, |
ee3cc2e2 | 263 | NULL); |
891fa266 NC |
264 | |
265 | p = p->next; | |
252b5132 | 266 | } |
252b5132 | 267 | } |
252b5132 RH |
268 | |
269 | done_tree = 1; | |
252b5132 | 270 | } |
891fa266 | 271 | |
252b5132 RH |
272 | void |
273 | mri_load (name) | |
4da711b1 | 274 | const char *name; |
252b5132 RH |
275 | { |
276 | base = 0; | |
891fa266 | 277 | lang_add_input_file (name, |
e47d05ad | 278 | lang_input_file_is_file_enum, (char *) NULL); |
5cc18311 | 279 | #if 0 |
e47d05ad | 280 | lang_leave_output_section_statement (0, "*default*"); |
891fa266 | 281 | #endif |
252b5132 RH |
282 | } |
283 | ||
252b5132 RH |
284 | void |
285 | mri_order (name) | |
4da711b1 | 286 | const char *name; |
252b5132 | 287 | { |
e47d05ad | 288 | mri_add_to_list (&order, name, 0, 0, 0, 0); |
252b5132 RH |
289 | } |
290 | ||
5cc18311 | 291 | void |
252b5132 | 292 | mri_alias (want, is, isn) |
4da711b1 AM |
293 | const char *want; |
294 | const char *is; | |
252b5132 RH |
295 | int isn; |
296 | { | |
891fa266 NC |
297 | if (!is) |
298 | { | |
299 | char buf[20]; | |
5cc18311 | 300 | |
891fa266 NC |
301 | /* Some sections are digits. */ |
302 | sprintf (buf, "%d", isn); | |
5cc18311 | 303 | |
891fa266 | 304 | is = xstrdup (buf); |
5cc18311 | 305 | |
891fa266 NC |
306 | if (is == NULL) |
307 | abort (); | |
308 | } | |
5cc18311 | 309 | |
e47d05ad | 310 | mri_add_to_list (&alias, is, 0, want, 0, 0); |
252b5132 RH |
311 | } |
312 | ||
5cc18311 | 313 | void |
252b5132 | 314 | mri_name (name) |
4da711b1 | 315 | const char *name; |
252b5132 | 316 | { |
891fa266 | 317 | lang_add_output (name, 1); |
252b5132 RH |
318 | } |
319 | ||
252b5132 RH |
320 | void |
321 | mri_format (name) | |
4da711b1 | 322 | const char *name; |
252b5132 | 323 | { |
891fa266 NC |
324 | if (strcmp (name, "S") == 0) |
325 | lang_add_output_format ("srec", (char *) NULL, (char *) NULL, 1); | |
5cc18311 | 326 | |
891fa266 NC |
327 | else if (strcmp (name, "IEEE") == 0) |
328 | lang_add_output_format ("ieee", (char *) NULL, (char *) NULL, 1); | |
5cc18311 | 329 | |
891fa266 NC |
330 | else if (strcmp (name, "COFF") == 0) |
331 | lang_add_output_format ("coff-m68k", (char *) NULL, (char *) NULL, 1); | |
5cc18311 | 332 | |
891fa266 NC |
333 | else |
334 | einfo (_("%P%F: unknown format type %s\n"), name); | |
252b5132 RH |
335 | } |
336 | ||
252b5132 RH |
337 | void |
338 | mri_public (name, exp) | |
4da711b1 | 339 | const char *name; |
252b5132 RH |
340 | etree_type *exp; |
341 | { | |
891fa266 | 342 | lang_add_assignment (exp_assop ('=', name, exp)); |
252b5132 RH |
343 | } |
344 | ||
5cc18311 | 345 | void |
252b5132 | 346 | mri_align (name, exp) |
4da711b1 | 347 | const char *name; |
252b5132 RH |
348 | etree_type *exp; |
349 | { | |
e47d05ad | 350 | mri_add_to_list (&alignment, name, 0, 0, exp, 0); |
252b5132 RH |
351 | } |
352 | ||
5cc18311 | 353 | void |
252b5132 | 354 | mri_alignmod (name, exp) |
4da711b1 | 355 | const char *name; |
252b5132 RH |
356 | etree_type *exp; |
357 | { | |
e47d05ad | 358 | mri_add_to_list (&subalignment, name, 0, 0, 0, exp); |
252b5132 RH |
359 | } |
360 | ||
5cc18311 | 361 | void |
252b5132 RH |
362 | mri_truncate (exp) |
363 | unsigned int exp; | |
364 | { | |
365 | symbol_truncate = exp; | |
366 | } |