1 /* Copyright (C) 1991 Free Software Foundation, Inc.
3 This file is part of GLD, the Gnu Linker.
5 GLD is free software; you can redistribute it and/or modify
6 it under the terms of the GNU General Public License as published by
7 the Free Software Foundation; either version 1, or (at your option)
10 GLD is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 GNU General Public License for more details.
15 You should have received a copy of the GNU General Public License
16 along with GLD; see the file COPYING. If not, write to
17 the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA. */
20 /* This bit does the tree decoration when MRI style link scripts are parsed */
23 contributed by Steve Chamberlain
38 struct section_name_struct {
39 struct section_name_struct *next;
48 int symbol_truncate = 10000;
49 struct section_name_struct *order;
50 struct section_name_struct *only_load;
51 struct section_name_struct *address;
52 struct section_name_struct *alias;
54 struct section_name_struct *alignment;
55 struct section_name_struct *subalignment;
57 extern char *strdup();
59 static struct section_name_struct **
62 struct section_name_struct **list;
65 struct section_name_struct **ptr = list;
68 if (strcmp(name, (*ptr)->name) == 0) {
69 /* If this is a match, delete it, we only keep the last instance
74 ptr = &((*ptr)->next);
78 *ptr = (struct section_name_struct *)ldmalloc(sizeof(struct section_name_struct));
83 mri_add_to_list (list, name, vma, alias, align, subalign)
84 struct section_name_struct **list;
91 struct section_name_struct **ptr = lookup(name,list);
94 (*ptr)->next = (struct section_name_struct *)NULL;
95 (*ptr)->ok_to_load = 0;
96 (*ptr)->alias = alias;
97 (*ptr)->align = align;
98 (*ptr)->subalign = subalign;
103 mri_output_section (name, vma)
107 mri_add_to_list(&address, name, vma, 0,0,0);
110 /* if any ABSOLUTE <name> are in the script, only load those files
117 mri_add_to_list(&only_load, name, 0, 0,0,0);
128 static int done_tree = 0;
132 if (done_tree) return;
134 /* Create the regions */
136 lang_memory_region_type *r;
137 r = lang_memory_region_lookup("long");
138 r->current = r->origin = exp_get_vma(base, (bfd_vma)0, "origin",
139 lang_first_phase_enum);
140 r->length = (bfd_size_type) exp_get_vma(0, (bfd_vma) ~((bfd_size_type)0),
141 "length", lang_first_phase_enum);
145 /* Now build the statements for the ldlang machine */
148 /* Attatch the addresses of any which have addresses, and add the
149 ones not mentioned */
150 if (address != (struct section_name_struct *)NULL) {
151 struct section_name_struct *alist;
152 struct section_name_struct *olist;
153 if (order == (struct section_name_struct *)NULL) {
157 for (alist = address;
158 alist != (struct section_name_struct*)NULL;
164 olist != (struct section_name_struct *)NULL;
167 if (strcmp(alist->name, olist->name) == 0)
169 olist->vma = alist->vma;
174 /* add this onto end of order list */
175 mri_add_to_list(&order, alist->name, alist->vma, 0,0,0);
182 /* If we're only supposed to load a subset of them in, then prune
185 if (only_load != (struct section_name_struct *)NULL)
187 struct section_name_struct *ptr1;
188 struct section_name_struct *ptr2;
189 if (order == (struct section_name_struct*)NULL)
192 /* See if this name is in the list, if it is then we can load it
194 for (ptr1 = only_load; ptr1; ptr1 = ptr1->next)
196 for (ptr2= order; ptr2; ptr2=ptr2->next)
198 if (strcmp(ptr2->name, ptr1->name)==0) {
199 ptr2->ok_to_load = 1;
206 /* No only load list, so everything is ok to load */
207 struct section_name_struct *ptr;
208 for (ptr = order; ptr; ptr=ptr->next) {
215 /* Create the order of sections to load */
216 if (order != (struct section_name_struct *)NULL)
218 /* Been told to output the sections in a certain order */
219 struct section_name_struct *p = order;
222 struct section_name_struct *aptr;
223 etree_type *align = 0;
224 etree_type *subalign = 0;
225 /* See if an alignment has been specified */
227 for (aptr = alignment; aptr; aptr= aptr->next)
229 if (strcmp(aptr->name, p->name)==0) {
234 for (aptr = subalignment; aptr; aptr= aptr->next)
236 if (strcmp(aptr->name, p->name)==0) {
237 subalign = aptr->subalign;
242 base = p->vma ? p->vma :exp_nameop(NAME, ".");
244 lang_enter_output_section_statement (p->name, base,
245 p->ok_to_load ? 0 : SEC_NEVER_LOAD,
247 (etree_type *) NULL);
249 lang_add_wild(p->name, (char *)NULL);
250 /* If there is an alias for this section, add it too */
251 for (aptr = alias; aptr; aptr = aptr->next) {
253 if (strcmp(aptr->alias, p->name)== 0) {
254 lang_add_wild(aptr->name, (char *)NULL);
258 lang_leave_output_section_statement(0, "long");
274 lang_add_input_file(name,
275 lang_input_file_is_file_enum, (char *)NULL);
276 /* lang_leave_output_section_statement(0,"*default*");*/
284 mri_add_to_list(&order, name, 0, 0,0,0);
288 mri_alias (want, is, isn)
294 /* Some sections are digits - */
296 sprintf(buf, "%d", isn);
299 mri_add_to_list(&alias, is, 0, want,0,0);
308 lang_add_output(name, 1);
317 if (strcmp(name, "S") == 0)
319 lang_add_output_format("srec", 1);
321 else if (strcmp(name, "IEEE") == 0)
323 lang_add_output_format("ieee", 1);
325 else if (strcmp(name, "COFF") == 0)
327 lang_add_output_format("coff-m68k", 1);
330 einfo("%P%F: unknown format type %s\n", name);
336 mri_public (name, exp)
340 lang_add_assignment(exp_assop('=', name, exp));
344 mri_align (name, exp)
348 mri_add_to_list(&alignment, name,0,0,exp,0);
352 mri_alignmod (name, exp)
356 mri_add_to_list(&subalignment, name,0,0,0,exp);
364 symbol_truncate = exp;