1 /* mri.c -- handle MRI style linker scripts
2 Copyright (C) 1991-2019 Free Software Foundation, Inc.
3 Contributed by Steve Chamberlain <sac@cygnus.com>.
5 This file is part of the GNU Binutils.
7 This program 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 3 of the License, or
10 (at your option) any later version.
12 This program 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 this program; if not, write to the Free Software
19 Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston,
20 MA 02110-1301, USA. */
23 /* This bit does the tree decoration when MRI style link scripts
35 #include "libiberty.h"
37 struct section_name_struct
{
38 struct section_name_struct
*next
;
47 static unsigned int symbol_truncate
= 10000;
48 static etree_type
*base
; /* Relocation base - or null */
50 static struct section_name_struct
*order
;
51 static struct section_name_struct
*only_load
;
52 static struct section_name_struct
*address
;
53 static struct section_name_struct
*alias
;
55 static struct section_name_struct
*alignment
;
56 static struct section_name_struct
*subalignment
;
58 static struct section_name_struct
**
59 lookup (const char *name
, struct section_name_struct
**list
)
61 struct section_name_struct
**ptr
= list
;
65 if (strcmp (name
, (*ptr
)->name
) == 0)
66 /* If this is a match, delete it, we only keep the last instance
70 ptr
= &((*ptr
)->next
);
73 *ptr
= (struct section_name_struct
*)
74 xmalloc (sizeof (struct section_name_struct
));
79 mri_add_to_list (struct section_name_struct
**list
,
86 struct section_name_struct
**ptr
= lookup (name
, list
);
91 (*ptr
)->ok_to_load
= 0;
92 (*ptr
)->alias
= zalias
;
93 (*ptr
)->align
= align
;
94 (*ptr
)->subalign
= subalign
;
98 mri_output_section (const char *name
, etree_type
*vma
)
100 mri_add_to_list (&address
, name
, vma
, 0, 0, 0);
103 /* If any ABSOLUTE <name> are in the script, only load those files
107 mri_only_load (const char *name
)
109 mri_add_to_list (&only_load
, name
, 0, 0, 0, 0);
113 mri_base (etree_type
*exp
)
118 static int done_tree
= 0;
126 /* Now build the statements for the ldlang machine. */
128 /* Attach the addresses of any which have addresses,
129 and add the ones not mentioned. */
132 struct section_name_struct
*alist
;
133 struct section_name_struct
*olist
;
138 for (alist
= address
;
144 for (olist
= order
; done
== 0 && olist
!= NULL
; olist
= olist
->next
)
146 if (strcmp (alist
->name
, olist
->name
) == 0)
148 olist
->vma
= alist
->vma
;
155 /* Add this onto end of order list. */
156 mri_add_to_list (&order
, alist
->name
, alist
->vma
, 0, 0, 0);
161 /* If we're only supposed to load a subset of them in, then prune
163 if (only_load
!= NULL
)
165 struct section_name_struct
*ptr1
;
166 struct section_name_struct
*ptr2
;
171 /* See if this name is in the list, if it is then we can load it. */
172 for (ptr1
= only_load
; ptr1
; ptr1
= ptr1
->next
)
173 for (ptr2
= order
; ptr2
; ptr2
= ptr2
->next
)
174 if (strcmp (ptr2
->name
, ptr1
->name
) == 0)
175 ptr2
->ok_to_load
= 1;
179 /* No only load list, so everything is ok to load. */
180 struct section_name_struct
*ptr
;
182 for (ptr
= order
; ptr
; ptr
= ptr
->next
)
186 /* Create the order of sections to load. */
189 /* Been told to output the sections in a certain order. */
190 struct section_name_struct
*p
= order
;
194 struct section_name_struct
*aptr
;
195 etree_type
*align
= 0;
196 etree_type
*subalign
= 0;
197 struct wildcard_list
*tmp
;
199 /* See if an alignment has been specified. */
200 for (aptr
= alignment
; aptr
; aptr
= aptr
->next
)
201 if (strcmp (aptr
->name
, p
->name
) == 0)
204 for (aptr
= subalignment
; aptr
; aptr
= aptr
->next
)
205 if (strcmp (aptr
->name
, p
->name
) == 0)
206 subalign
= aptr
->subalign
;
209 base
= p
->vma
? p
->vma
: exp_nameop (NAME
, ".");
211 lang_enter_output_section_statement (p
->name
, base
,
212 p
->ok_to_load
? normal_section
: noload_section
,
213 align
, subalign
, NULL
, 0, 0);
215 tmp
= (struct wildcard_list
*) xmalloc (sizeof *tmp
);
217 tmp
->spec
.name
= p
->name
;
218 tmp
->spec
.exclude_name_list
= NULL
;
219 tmp
->spec
.sorted
= none
;
220 tmp
->spec
.section_flag_list
= NULL
;
221 lang_add_wild (NULL
, tmp
, FALSE
);
223 /* If there is an alias for this section, add it too. */
224 for (aptr
= alias
; aptr
; aptr
= aptr
->next
)
225 if (strcmp (aptr
->alias
, p
->name
) == 0)
227 tmp
= (struct wildcard_list
*) xmalloc (sizeof *tmp
);
229 tmp
->spec
.name
= aptr
->name
;
230 tmp
->spec
.exclude_name_list
= NULL
;
231 tmp
->spec
.sorted
= none
;
232 tmp
->spec
.section_flag_list
= NULL
;
233 lang_add_wild (NULL
, tmp
, FALSE
);
236 lang_leave_output_section_statement (0, "*default*", NULL
, NULL
);
246 mri_load (const char *name
)
249 lang_add_input_file (name
, lang_input_file_is_file_enum
, NULL
);
253 mri_order (const char *name
)
255 mri_add_to_list (&order
, name
, 0, 0, 0, 0);
259 mri_alias (const char *want
, const char *is
, int isn
)
265 /* Some sections are digits. */
266 sprintf (buf
, "%d", isn
);
274 mri_add_to_list (&alias
, is
, 0, want
, 0, 0);
278 mri_name (const char *name
)
280 lang_add_output (name
, 1);
284 mri_format (const char *name
)
286 if (strcmp (name
, "S") == 0)
287 lang_add_output_format ("srec", NULL
, NULL
, 1);
290 einfo (_("%F%P: unknown format type %s\n"), name
);
294 mri_public (const char *name
, etree_type
*exp
)
296 lang_add_assignment (exp_assign (name
, exp
, FALSE
));
300 mri_align (const char *name
, etree_type
*exp
)
302 mri_add_to_list (&alignment
, name
, 0, 0, exp
, 0);
306 mri_alignmod (const char *name
, etree_type
*exp
)
308 mri_add_to_list (&subalignment
, name
, 0, 0, 0, exp
);
312 mri_truncate (unsigned int exp
)
314 symbol_truncate
= exp
;