* ldgram.y (DATA_SEGMENT_RELRO_END): Add one argument.
[deliverable/binutils-gdb.git] / ld / mri.c
CommitLineData
252b5132 1/* mri.c -- handle MRI style linker scripts
e5caa5e0
AM
2 Copyright 1991, 1992, 1993, 1994, 1996, 1997, 1998, 1999, 2000, 2002,
3 2003, 2004 Free Software Foundation, Inc.
252b5132
RH
4
5This file is part of GLD, the Gnu Linker.
6
7GLD is free software; you can redistribute it and/or modify
8it under the terms of the GNU General Public License as published by
9the Free Software Foundation; either version 2, or (at your option)
10any later version.
11
12GLD is distributed in the hope that it will be useful,
13but WITHOUT ANY WARRANTY; without even the implied warranty of
14MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15GNU General Public License for more details.
16
17You should have received a copy of the GNU General Public License
18along with GLD; see the file COPYING. If not, write to the Free
19Software Foundation, 59 Temple Place - Suite 330, Boston, MA
891fa266 2002111-1307, USA.
252b5132 21
891fa266
NC
22 This bit does the tree decoration when MRI style link scripts
23 are parsed.
252b5132 24
891fa266 25 Contributed by Steve Chamberlain <sac@cygnus.com>. */
252b5132
RH
26
27#include "bfd.h"
5cc18311 28#include "sysdep.h"
252b5132
RH
29#include "ld.h"
30#include "ldexp.h"
31#include "ldlang.h"
32#include "ldmisc.h"
33#include "mri.h"
df2a7313 34#include <ldgram.h>
252b5132
RH
35#include "libiberty.h"
36
e47d05ad 37struct section_name_struct {
252b5132 38 struct section_name_struct *next;
4da711b1
AM
39 const char *name;
40 const char *alias;
252b5132
RH
41 etree_type *vma;
42 etree_type *align;
43 etree_type *subalign;
44 int ok_to_load;
891fa266 45};
252b5132
RH
46
47unsigned int symbol_truncate = 10000;
48struct section_name_struct *order;
49struct section_name_struct *only_load;
50struct section_name_struct *address;
51struct section_name_struct *alias;
52
53struct section_name_struct *alignment;
54struct section_name_struct *subalignment;
55
252b5132 56static struct section_name_struct **
1579bae1 57lookup (const char *name, struct section_name_struct **list)
252b5132 58{
252b5132 59 struct section_name_struct **ptr = list;
5cc18311
KH
60
61 while (*ptr)
891fa266
NC
62 {
63 if (strcmp (name, (*ptr)->name) == 0)
64 /* If this is a match, delete it, we only keep the last instance
65 of any name. */
66 *ptr = (*ptr)->next;
67 else
68 ptr = &((*ptr)->next);
252b5132 69 }
252b5132 70
1579bae1 71 *ptr = xmalloc (sizeof (struct section_name_struct));
252b5132
RH
72 return ptr;
73}
74
75static void
1579bae1
AM
76mri_add_to_list (struct section_name_struct **list,
77 const char *name,
78 etree_type *vma,
79 const char *zalias,
80 etree_type *align,
81 etree_type *subalign)
252b5132 82{
e47d05ad 83 struct section_name_struct **ptr = lookup (name, list);
5cc18311 84
252b5132
RH
85 (*ptr)->name = name;
86 (*ptr)->vma = vma;
1579bae1 87 (*ptr)->next = NULL;
252b5132
RH
88 (*ptr)->ok_to_load = 0;
89 (*ptr)->alias = zalias;
90 (*ptr)->align = align;
91 (*ptr)->subalign = subalign;
92}
93
252b5132 94void
1579bae1 95mri_output_section (const char *name, etree_type *vma)
252b5132 96{
e47d05ad 97 mri_add_to_list (&address, name, vma, 0, 0, 0);
252b5132
RH
98}
99
891fa266
NC
100/* If any ABSOLUTE <name> are in the script, only load those files
101 marked thus. */
252b5132
RH
102
103void
1579bae1 104mri_only_load (const char *name)
252b5132 105{
e47d05ad 106 mri_add_to_list (&only_load, name, 0, 0, 0, 0);
252b5132
RH
107}
108
252b5132 109void
1579bae1 110mri_base (etree_type *exp)
252b5132
RH
111{
112 base = exp;
113}
114
115static int done_tree = 0;
116
117void
1579bae1 118mri_draw_tree (void)
252b5132 119{
891fa266
NC
120 if (done_tree)
121 return;
122
123#if 0 /* We don't bother with memory regions. */
124 /* Create the regions. */
125 {
126 lang_memory_region_type *r;
5cc18311 127
891fa266
NC
128 r = lang_memory_region_lookup("long");
129 r->current = r->origin = exp_get_vma (base, (bfd_vma)0, "origin",
130 lang_first_phase_enum);
1579bae1
AM
131 r->length = (bfd_size_type) exp_get_vma (0, ~(bfd_vma) 0, "length",
132 lang_first_phase_enum);
891fa266 133 }
252b5132 134#endif
5cc18311 135
891fa266 136 /* Now build the statements for the ldlang machine. */
252b5132 137
396a2467 138 /* Attach the addresses of any which have addresses,
891fa266 139 and add the ones not mentioned. */
1579bae1 140 if (address != NULL)
252b5132 141 {
891fa266
NC
142 struct section_name_struct *alist;
143 struct section_name_struct *olist;
5cc18311 144
1579bae1 145 if (order == NULL)
891fa266
NC
146 order = address;
147
148 for (alist = address;
1579bae1 149 alist != NULL;
5cc18311 150 alist = alist->next)
252b5132 151 {
891fa266 152 int done = 0;
5cc18311 153
1579bae1 154 for (olist = order; done == 0 && olist != NULL; olist = olist->next)
891fa266 155 {
5cc18311 156 if (strcmp (alist->name, olist->name) == 0)
891fa266
NC
157 {
158 olist->vma = alist->vma;
159 done = 1;
160 }
161 }
5cc18311 162
891fa266
NC
163 if (!done)
164 {
165 /* Add this onto end of order list. */
e47d05ad 166 mri_add_to_list (&order, alist->name, alist->vma, 0, 0, 0);
891fa266 167 }
252b5132 168 }
252b5132
RH
169 }
170
252b5132
RH
171 /* If we're only supposed to load a subset of them in, then prune
172 the list. */
1579bae1 173 if (only_load != NULL)
252b5132 174 {
891fa266
NC
175 struct section_name_struct *ptr1;
176 struct section_name_struct *ptr2;
5cc18311 177
1579bae1 178 if (order == NULL)
891fa266 179 order = only_load;
5cc18311 180
891fa266 181 /* See if this name is in the list, if it is then we can load it. */
5cc18311
KH
182 for (ptr1 = only_load; ptr1; ptr1 = ptr1->next)
183 for (ptr2 = order; ptr2; ptr2 = ptr2->next)
891fa266
NC
184 if (strcmp (ptr2->name, ptr1->name) == 0)
185 ptr2->ok_to_load = 1;
252b5132 186 }
5cc18311 187 else
891fa266
NC
188 {
189 /* No only load list, so everything is ok to load. */
190 struct section_name_struct *ptr;
5cc18311 191
e47d05ad 192 for (ptr = order; ptr; ptr = ptr->next)
891fa266 193 ptr->ok_to_load = 1;
e47d05ad 194 }
252b5132 195
891fa266 196 /* Create the order of sections to load. */
1579bae1 197 if (order != NULL)
252b5132 198 {
891fa266
NC
199 /* Been told to output the sections in a certain order. */
200 struct section_name_struct *p = order;
5cc18311
KH
201
202 while (p)
891fa266
NC
203 {
204 struct section_name_struct *aptr;
205 etree_type *align = 0;
206 etree_type *subalign = 0;
b6bf44ba 207 struct wildcard_list *tmp;
5cc18311 208
891fa266 209 /* See if an alignment has been specified. */
e47d05ad 210 for (aptr = alignment; aptr; aptr = aptr->next)
891fa266 211 if (strcmp (aptr->name, p->name) == 0)
e47d05ad 212 align = aptr->align;
891fa266 213
e47d05ad 214 for (aptr = subalignment; aptr; aptr = aptr->next)
891fa266 215 if (strcmp (aptr->name, p->name) == 0)
e47d05ad 216 subalign = aptr->subalign;
891fa266
NC
217
218 if (base == 0)
e47d05ad 219 base = p->vma ? p->vma : exp_nameop (NAME, ".");
891fa266
NC
220
221 lang_enter_output_section_statement (p->name, base,
222 p->ok_to_load ? 0 : noload_section,
0841712e 223 align, subalign, NULL, 0);
891fa266 224 base = 0;
1579bae1 225 tmp = xmalloc (sizeof *tmp);
b6bf44ba
AM
226 tmp->next = NULL;
227 tmp->spec.name = p->name;
228 tmp->spec.exclude_name_list = NULL;
b34976b6
AM
229 tmp->spec.sorted = FALSE;
230 lang_add_wild (NULL, tmp, FALSE);
5cc18311 231
891fa266
NC
232 /* If there is an alias for this section, add it too. */
233 for (aptr = alias; aptr; aptr = aptr->next)
234 if (strcmp (aptr->alias, p->name) == 0)
b6bf44ba 235 {
1579bae1 236 tmp = xmalloc (sizeof *tmp);
b6bf44ba
AM
237 tmp->next = NULL;
238 tmp->spec.name = aptr->name;
239 tmp->spec.exclude_name_list = NULL;
b34976b6
AM
240 tmp->spec.sorted = FALSE;
241 lang_add_wild (NULL, tmp, FALSE);
b6bf44ba 242 }
891fa266 243
1579bae1 244 lang_leave_output_section_statement (0, "*default*", NULL, NULL);
891fa266
NC
245
246 p = p->next;
252b5132 247 }
252b5132 248 }
252b5132
RH
249
250 done_tree = 1;
252b5132 251}
891fa266 252
252b5132 253void
1579bae1 254mri_load (const char *name)
252b5132
RH
255{
256 base = 0;
1579bae1 257 lang_add_input_file (name, lang_input_file_is_file_enum, NULL);
5cc18311 258#if 0
e47d05ad 259 lang_leave_output_section_statement (0, "*default*");
891fa266 260#endif
252b5132
RH
261}
262
252b5132 263void
1579bae1 264mri_order (const char *name)
252b5132 265{
e47d05ad 266 mri_add_to_list (&order, name, 0, 0, 0, 0);
252b5132
RH
267}
268
5cc18311 269void
1579bae1 270mri_alias (const char *want, const char *is, int isn)
252b5132 271{
891fa266
NC
272 if (!is)
273 {
274 char buf[20];
5cc18311 275
891fa266
NC
276 /* Some sections are digits. */
277 sprintf (buf, "%d", isn);
5cc18311 278
891fa266 279 is = xstrdup (buf);
5cc18311 280
891fa266
NC
281 if (is == NULL)
282 abort ();
283 }
5cc18311 284
e47d05ad 285 mri_add_to_list (&alias, is, 0, want, 0, 0);
252b5132
RH
286}
287
5cc18311 288void
1579bae1 289mri_name (const char *name)
252b5132 290{
891fa266 291 lang_add_output (name, 1);
252b5132
RH
292}
293
252b5132 294void
1579bae1 295mri_format (const char *name)
252b5132 296{
891fa266 297 if (strcmp (name, "S") == 0)
1579bae1 298 lang_add_output_format ("srec", NULL, NULL, 1);
5cc18311 299
891fa266 300 else if (strcmp (name, "IEEE") == 0)
1579bae1 301 lang_add_output_format ("ieee", NULL, NULL, 1);
5cc18311 302
891fa266 303 else if (strcmp (name, "COFF") == 0)
1579bae1 304 lang_add_output_format ("coff-m68k", NULL, NULL, 1);
5cc18311 305
891fa266
NC
306 else
307 einfo (_("%P%F: unknown format type %s\n"), name);
252b5132
RH
308}
309
252b5132 310void
1579bae1 311mri_public (const char *name, etree_type *exp)
252b5132 312{
891fa266 313 lang_add_assignment (exp_assop ('=', name, exp));
252b5132
RH
314}
315
5cc18311 316void
1579bae1 317mri_align (const char *name, etree_type *exp)
252b5132 318{
e47d05ad 319 mri_add_to_list (&alignment, name, 0, 0, exp, 0);
252b5132
RH
320}
321
5cc18311 322void
1579bae1 323mri_alignmod (const char *name, etree_type *exp)
252b5132 324{
e47d05ad 325 mri_add_to_list (&subalignment, name, 0, 0, 0, exp);
252b5132
RH
326}
327
5cc18311 328void
1579bae1 329mri_truncate (unsigned int exp)
252b5132
RH
330{
331 symbol_truncate = exp;
332}
This page took 0.244924 seconds and 4 git commands to generate.