1 /* mri.c -- handle MRI style linker scripts
2 Copyright (C) 1991, 92, 93, 94, 95, 96, 1997, 1998 Free Software Foundation, Inc.
4 This file is part of GLD, the Gnu Linker.
6 GLD is free software; you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation; either version 2, or (at your option)
11 GLD is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU General Public License for more details.
16 You should have received a copy of the GNU General Public License
17 along with GLD; see the file COPYING. If not, write to the Free
18 Software Foundation, 59 Temple Place - Suite 330, Boston, MA
22 /* This bit does the tree decoration when MRI style link scripts are parsed */
25 contributed by Steve Chamberlain
38 #include "libiberty.h"
40 struct section_name_struct {
41 struct section_name_struct *next;
50 unsigned int symbol_truncate = 10000;
51 struct section_name_struct *order;
52 struct section_name_struct *only_load;
53 struct section_name_struct *address;
54 struct section_name_struct *alias;
56 struct section_name_struct *alignment;
57 struct section_name_struct *subalignment;
59 static struct section_name_struct **lookup
60 PARAMS ((const char *name, struct section_name_struct **list));
61 static void mri_add_to_list PARAMS ((struct section_name_struct **list,
62 const char *name, etree_type *vma,
63 const char *zalias, etree_type *align,
64 etree_type *subalign));
66 static struct section_name_struct **
69 struct section_name_struct **list;
72 struct section_name_struct **ptr = list;
75 if (strcmp(name, (*ptr)->name) == 0) {
76 /* If this is a match, delete it, we only keep the last instance
81 ptr = &((*ptr)->next);
85 *ptr = (struct section_name_struct *)xmalloc(sizeof(struct section_name_struct));
90 mri_add_to_list (list, name, vma, zalias, align, subalign)
91 struct section_name_struct **list;
98 struct section_name_struct **ptr = lookup(name,list);
101 (*ptr)->next = (struct section_name_struct *)NULL;
102 (*ptr)->ok_to_load = 0;
103 (*ptr)->alias = zalias;
104 (*ptr)->align = align;
105 (*ptr)->subalign = subalign;
110 mri_output_section (name, vma)
114 mri_add_to_list(&address, name, vma, 0,0,0);
117 /* if any ABSOLUTE <name> are in the script, only load those files
124 mri_add_to_list(&only_load, name, 0, 0,0,0);
135 static int done_tree = 0;
140 if (done_tree) return;
142 /* We don't bother with memory regions. */
144 /* Create the regions */
146 lang_memory_region_type *r;
147 r = lang_memory_region_lookup("long");
148 r->current = r->origin = exp_get_vma(base, (bfd_vma)0, "origin",
149 lang_first_phase_enum);
150 r->length = (bfd_size_type) exp_get_vma(0, (bfd_vma) ~((bfd_size_type)0),
151 "length", lang_first_phase_enum);
155 /* Now build the statements for the ldlang machine */
158 /* Attatch the addresses of any which have addresses, and add the
159 ones not mentioned */
160 if (address != (struct section_name_struct *)NULL) {
161 struct section_name_struct *alist;
162 struct section_name_struct *olist;
163 if (order == (struct section_name_struct *)NULL) {
167 for (alist = address;
168 alist != (struct section_name_struct*)NULL;
174 olist != (struct section_name_struct *)NULL;
177 if (strcmp(alist->name, olist->name) == 0)
179 olist->vma = alist->vma;
184 /* add this onto end of order list */
185 mri_add_to_list(&order, alist->name, alist->vma, 0,0,0);
192 /* If we're only supposed to load a subset of them in, then prune
195 if (only_load != (struct section_name_struct *)NULL)
197 struct section_name_struct *ptr1;
198 struct section_name_struct *ptr2;
199 if (order == (struct section_name_struct*)NULL)
202 /* See if this name is in the list, if it is then we can load it
204 for (ptr1 = only_load; ptr1; ptr1 = ptr1->next)
206 for (ptr2= order; ptr2; ptr2=ptr2->next)
208 if (strcmp(ptr2->name, ptr1->name)==0) {
209 ptr2->ok_to_load = 1;
216 /* No only load list, so everything is ok to load */
217 struct section_name_struct *ptr;
218 for (ptr = order; ptr; ptr=ptr->next) {
225 /* Create the order of sections to load */
226 if (order != (struct section_name_struct *)NULL)
228 /* Been told to output the sections in a certain order */
229 struct section_name_struct *p = order;
232 struct section_name_struct *aptr;
233 etree_type *align = 0;
234 etree_type *subalign = 0;
235 /* See if an alignment has been specified */
237 for (aptr = alignment; aptr; aptr= aptr->next)
239 if (strcmp(aptr->name, p->name)==0) {
244 for (aptr = subalignment; aptr; aptr= aptr->next)
246 if (strcmp(aptr->name, p->name)==0) {
247 subalign = aptr->subalign;
252 base = p->vma ? p->vma :exp_nameop(NAME, ".");
254 lang_enter_output_section_statement (p->name, base,
255 p->ok_to_load ? 0 : noload_section,
257 (etree_type *) NULL);
259 lang_add_wild (p->name, false, (char *)NULL, false, false, NULL);
260 /* If there is an alias for this section, add it too */
261 for (aptr = alias; aptr; aptr = aptr->next) {
263 if (strcmp(aptr->alias, p->name)== 0) {
264 lang_add_wild (aptr->name, false, (char *)NULL, false, false, NULL);
268 lang_leave_output_section_statement
269 (0, "*default*", (struct lang_output_section_phdr_list *) NULL,
285 lang_add_input_file(name,
286 lang_input_file_is_file_enum, (char *)NULL);
287 /* lang_leave_output_section_statement(0,"*default*");*/
295 mri_add_to_list(&order, name, 0, 0,0,0);
299 mri_alias (want, is, isn)
305 /* Some sections are digits - */
307 sprintf(buf, "%d", isn);
312 mri_add_to_list(&alias, is, 0, want,0,0);
321 lang_add_output(name, 1);
330 if (strcmp(name, "S") == 0)
332 lang_add_output_format("srec", (char *) NULL, (char *) NULL, 1);
334 else if (strcmp(name, "IEEE") == 0)
336 lang_add_output_format("ieee", (char *) NULL, (char *) NULL, 1);
338 else if (strcmp(name, "COFF") == 0)
340 lang_add_output_format("coff-m68k", (char *) NULL, (char *) NULL, 1);
343 einfo(_("%P%F: unknown format type %s\n"), name);
349 mri_public (name, exp)
353 lang_add_assignment(exp_assop('=', name, exp));
357 mri_align (name, exp)
361 mri_add_to_list(&alignment, name,0,0,exp,0);
365 mri_alignmod (name, exp)
369 mri_add_to_list(&subalignment, name,0,0,0,exp);
377 symbol_truncate = exp;