1 /* mri.c -- handle MRI style linker scripts
2 Copyright 1991, 1992, 1993, 1994, 1996, 1997, 1998, 1999, 2000, 2001,
3 2002, 2003, 2004, 2005 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
{
38 struct section_name_struct
*next
;
47 static unsigned int symbol_truncate
= 10000;
48 static struct section_name_struct
*order
;
49 static struct section_name_struct
*only_load
;
50 static struct section_name_struct
*address
;
51 static struct section_name_struct
*alias
;
53 static struct section_name_struct
*alignment
;
54 static struct section_name_struct
*subalignment
;
56 static struct section_name_struct
**
57 lookup (const char *name
, struct section_name_struct
**list
)
59 struct section_name_struct
**ptr
= list
;
63 if (strcmp (name
, (*ptr
)->name
) == 0)
64 /* If this is a match, delete it, we only keep the last instance
68 ptr
= &((*ptr
)->next
);
71 *ptr
= xmalloc (sizeof (struct section_name_struct
));
76 mri_add_to_list (struct section_name_struct
**list
,
83 struct section_name_struct
**ptr
= lookup (name
, list
);
88 (*ptr
)->ok_to_load
= 0;
89 (*ptr
)->alias
= zalias
;
90 (*ptr
)->align
= align
;
91 (*ptr
)->subalign
= subalign
;
95 mri_output_section (const char *name
, etree_type
*vma
)
97 mri_add_to_list (&address
, name
, vma
, 0, 0, 0);
100 /* If any ABSOLUTE <name> are in the script, only load those files
104 mri_only_load (const char *name
)
106 mri_add_to_list (&only_load
, name
, 0, 0, 0, 0);
110 mri_base (etree_type
*exp
)
115 static int done_tree
= 0;
123 /* Now build the statements for the ldlang machine. */
125 /* Attach the addresses of any which have addresses,
126 and add the ones not mentioned. */
129 struct section_name_struct
*alist
;
130 struct section_name_struct
*olist
;
135 for (alist
= address
;
141 for (olist
= order
; done
== 0 && olist
!= NULL
; olist
= olist
->next
)
143 if (strcmp (alist
->name
, olist
->name
) == 0)
145 olist
->vma
= alist
->vma
;
152 /* Add this onto end of order list. */
153 mri_add_to_list (&order
, alist
->name
, alist
->vma
, 0, 0, 0);
158 /* If we're only supposed to load a subset of them in, then prune
160 if (only_load
!= NULL
)
162 struct section_name_struct
*ptr1
;
163 struct section_name_struct
*ptr2
;
168 /* See if this name is in the list, if it is then we can load it. */
169 for (ptr1
= only_load
; ptr1
; ptr1
= ptr1
->next
)
170 for (ptr2
= order
; ptr2
; ptr2
= ptr2
->next
)
171 if (strcmp (ptr2
->name
, ptr1
->name
) == 0)
172 ptr2
->ok_to_load
= 1;
176 /* No only load list, so everything is ok to load. */
177 struct section_name_struct
*ptr
;
179 for (ptr
= order
; ptr
; ptr
= ptr
->next
)
183 /* Create the order of sections to load. */
186 /* Been told to output the sections in a certain order. */
187 struct section_name_struct
*p
= order
;
191 struct section_name_struct
*aptr
;
192 etree_type
*align
= 0;
193 etree_type
*subalign
= 0;
194 struct wildcard_list
*tmp
;
196 /* See if an alignment has been specified. */
197 for (aptr
= alignment
; aptr
; aptr
= aptr
->next
)
198 if (strcmp (aptr
->name
, p
->name
) == 0)
201 for (aptr
= subalignment
; aptr
; aptr
= aptr
->next
)
202 if (strcmp (aptr
->name
, p
->name
) == 0)
203 subalign
= aptr
->subalign
;
206 base
= p
->vma
? p
->vma
: exp_nameop (NAME
, ".");
208 lang_enter_output_section_statement (p
->name
, base
,
209 p
->ok_to_load
? 0 : noload_section
,
210 align
, subalign
, NULL
, 0);
212 tmp
= xmalloc (sizeof *tmp
);
214 tmp
->spec
.name
= p
->name
;
215 tmp
->spec
.exclude_name_list
= NULL
;
216 tmp
->spec
.sorted
= none
;
217 lang_add_wild (NULL
, tmp
, FALSE
);
219 /* If there is an alias for this section, add it too. */
220 for (aptr
= alias
; aptr
; aptr
= aptr
->next
)
221 if (strcmp (aptr
->alias
, p
->name
) == 0)
223 tmp
= xmalloc (sizeof *tmp
);
225 tmp
->spec
.name
= aptr
->name
;
226 tmp
->spec
.exclude_name_list
= NULL
;
227 tmp
->spec
.sorted
= none
;
228 lang_add_wild (NULL
, tmp
, FALSE
);
231 lang_leave_output_section_statement (0, "*default*", NULL
, NULL
);
241 mri_load (const char *name
)
244 lang_add_input_file (name
, lang_input_file_is_file_enum
, NULL
);
248 mri_order (const char *name
)
250 mri_add_to_list (&order
, name
, 0, 0, 0, 0);
254 mri_alias (const char *want
, const char *is
, int isn
)
260 /* Some sections are digits. */
261 sprintf (buf
, "%d", isn
);
269 mri_add_to_list (&alias
, is
, 0, want
, 0, 0);
273 mri_name (const char *name
)
275 lang_add_output (name
, 1);
279 mri_format (const char *name
)
281 if (strcmp (name
, "S") == 0)
282 lang_add_output_format ("srec", NULL
, NULL
, 1);
284 else if (strcmp (name
, "IEEE") == 0)
285 lang_add_output_format ("ieee", NULL
, NULL
, 1);
287 else if (strcmp (name
, "COFF") == 0)
288 lang_add_output_format ("coff-m68k", NULL
, NULL
, 1);
291 einfo (_("%P%F: unknown format type %s\n"), name
);
295 mri_public (const char *name
, etree_type
*exp
)
297 lang_add_assignment (exp_assop ('=', name
, exp
));
301 mri_align (const char *name
, etree_type
*exp
)
303 mri_add_to_list (&alignment
, name
, 0, 0, exp
, 0);
307 mri_alignmod (const char *name
, etree_type
*exp
)
309 mri_add_to_list (&subalignment
, name
, 0, 0, 0, exp
);
313 mri_truncate (unsigned int exp
)
315 symbol_truncate
= exp
;