1 /* mri.c -- handle MRI style linker scripts
2 Copyright 1991, 92, 93, 94, 95, 96, 1997, 1998, 2000
3 Free Software Foundation, Inc.
5 This file is part of GLD, the Gnu Linker.
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)
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.
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
22 This bit does the tree decoration when MRI style link scripts
25 Contributed by Steve Chamberlain <sac@cygnus.com>. */
35 #include "libiberty.h"
37 struct section_name_struct
39 struct section_name_struct
*next
;
48 unsigned 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 static struct section_name_struct
**lookup
58 PARAMS ((const char *name
, struct section_name_struct
**list
));
59 static void mri_add_to_list
PARAMS ((struct section_name_struct
**list
,
60 const char *name
, etree_type
*vma
,
61 const char *zalias
, etree_type
*align
,
62 etree_type
*subalign
));
64 static struct section_name_struct
**
67 struct section_name_struct
**list
;
69 struct section_name_struct
**ptr
= list
;
73 if (strcmp (name
, (*ptr
)->name
) == 0)
74 /* If this is a match, delete it, we only keep the last instance
78 ptr
= &((*ptr
)->next
);
81 *ptr
= (struct section_name_struct
*) xmalloc (sizeof (struct section_name_struct
));
86 mri_add_to_list (list
, name
, vma
, zalias
, align
, subalign
)
87 struct section_name_struct
**list
;
94 struct section_name_struct
**ptr
= lookup (name
,list
);
98 (*ptr
)->next
= (struct section_name_struct
*) NULL
;
99 (*ptr
)->ok_to_load
= 0;
100 (*ptr
)->alias
= zalias
;
101 (*ptr
)->align
= align
;
102 (*ptr
)->subalign
= subalign
;
106 mri_output_section (name
, vma
)
110 mri_add_to_list (& address
, name
, vma
, 0,0,0);
113 /* If any ABSOLUTE <name> are in the script, only load those files
120 mri_add_to_list (&only_load
, name
, 0, 0,0,0);
130 static int done_tree
= 0;
138 #if 0 /* We don't bother with memory regions. */
139 /* Create the regions. */
141 lang_memory_region_type
*r
;
143 r
= lang_memory_region_lookup("long");
144 r
->current
= r
->origin
= exp_get_vma (base
, (bfd_vma
)0, "origin",
145 lang_first_phase_enum
);
146 r
->length
= (bfd_size_type
) exp_get_vma (0, (bfd_vma
) ~((bfd_size_type
)0),
147 "length", lang_first_phase_enum
);
151 /* Now build the statements for the ldlang machine. */
153 /* Attatch the addresses of any which have addresses,
154 and add the ones not mentioned. */
155 if (address
!= (struct section_name_struct
*)NULL
)
157 struct section_name_struct
*alist
;
158 struct section_name_struct
*olist
;
160 if (order
== (struct section_name_struct
*)NULL
)
163 for (alist
= address
;
164 alist
!= (struct section_name_struct
*)NULL
;
171 olist
!= (struct section_name_struct
*)NULL
;
174 if (strcmp (alist
->name
, olist
->name
) == 0)
176 olist
->vma
= alist
->vma
;
183 /* Add this onto end of order list. */
184 mri_add_to_list (& order
, alist
->name
, alist
->vma
, 0,0,0);
189 /* If we're only supposed to load a subset of them in, then prune
191 if (only_load
!= (struct section_name_struct
*)NULL
)
193 struct section_name_struct
*ptr1
;
194 struct section_name_struct
*ptr2
;
196 if (order
== (struct section_name_struct
*)NULL
)
199 /* See if this name is in the list, if it is then we can load it. */
200 for (ptr1
= only_load
; ptr1
; ptr1
= ptr1
->next
)
201 for (ptr2
= order
; ptr2
; ptr2
= ptr2
->next
)
202 if (strcmp (ptr2
->name
, ptr1
->name
) == 0)
203 ptr2
->ok_to_load
= 1;
207 /* No only load list, so everything is ok to load. */
208 struct section_name_struct
*ptr
;
210 for (ptr
= order
; ptr
; ptr
=ptr
->next
)
214 /* Create the order of sections to load. */
215 if (order
!= (struct section_name_struct
*)NULL
)
217 /* Been told to output the sections in a certain order. */
218 struct section_name_struct
*p
= order
;
222 struct section_name_struct
*aptr
;
223 etree_type
*align
= 0;
224 etree_type
*subalign
= 0;
226 /* See if an alignment has been specified. */
227 for (aptr
= alignment
; aptr
; aptr
= aptr
->next
)
228 if (strcmp (aptr
->name
, p
->name
) == 0)
231 for (aptr
= subalignment
; aptr
; aptr
= aptr
->next
)
232 if (strcmp (aptr
->name
, p
->name
) == 0)
233 subalign
= aptr
->subalign
;
236 base
= p
->vma
? p
->vma
:exp_nameop (NAME
, ".");
238 lang_enter_output_section_statement (p
->name
, base
,
239 p
->ok_to_load
? 0 : noload_section
,
241 (etree_type
*) NULL
);
243 lang_add_wild (p
->name
, false, (char *)NULL
, false, false, NULL
);
245 /* If there is an alias for this section, add it too. */
246 for (aptr
= alias
; aptr
; aptr
= aptr
->next
)
247 if (strcmp (aptr
->alias
, p
->name
) == 0)
248 lang_add_wild (aptr
->name
, false, (char *)NULL
, false, false, NULL
);
250 lang_leave_output_section_statement
251 (0, "*default*", (struct lang_output_section_phdr_list
*) NULL
,
266 lang_add_input_file (name
,
267 lang_input_file_is_file_enum
, (char *)NULL
);
269 lang_leave_output_section_statement (0,"*default*");
277 mri_add_to_list (& order
, name
, 0, 0,0,0);
281 mri_alias (want
, is
, isn
)
290 /* Some sections are digits. */
291 sprintf (buf
, "%d", isn
);
299 mri_add_to_list (& alias
, is
, 0, want
,0,0);
306 lang_add_output (name
, 1);
313 if (strcmp (name
, "S") == 0)
314 lang_add_output_format ("srec", (char *) NULL
, (char *) NULL
, 1);
316 else if (strcmp (name
, "IEEE") == 0)
317 lang_add_output_format ("ieee", (char *) NULL
, (char *) NULL
, 1);
319 else if (strcmp (name
, "COFF") == 0)
320 lang_add_output_format ("coff-m68k", (char *) NULL
, (char *) NULL
, 1);
323 einfo (_("%P%F: unknown format type %s\n"), name
);
327 mri_public (name
, exp
)
331 lang_add_assignment (exp_assop ('=', name
, exp
));
335 mri_align (name
, exp
)
339 mri_add_to_list (& alignment
, name
, 0, 0, exp
, 0);
343 mri_alignmod (name
, exp
)
347 mri_add_to_list (& subalignment
, name
, 0, 0, 0, exp
);
354 symbol_truncate
= exp
;