gdb: add target_ops::supports_displaced_step
[deliverable/binutils-gdb.git] / ld / mri.c
CommitLineData
252b5132 1/* mri.c -- handle MRI style linker scripts
b3adc24a 2 Copyright (C) 1991-2020 Free Software Foundation, Inc.
f96b4a7b 3 Contributed by Steve Chamberlain <sac@cygnus.com>.
252b5132 4
f96b4a7b 5 This file is part of the GNU Binutils.
252b5132 6
f96b4a7b
NC
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.
252b5132 11
f96b4a7b
NC
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.
252b5132 16
f96b4a7b
NC
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. */
252b5132
RH
21
22
f96b4a7b
NC
23/* This bit does the tree decoration when MRI style link scripts
24 are parsed. */
252b5132 25
5cc18311 26#include "sysdep.h"
3db64b00 27#include "bfd.h"
0b4453c7 28#include "bfdlink.h"
1ff6de03 29#include "ctf-api.h"
252b5132
RH
30#include "ld.h"
31#include "ldexp.h"
32#include "ldlang.h"
33#include "ldmisc.h"
34#include "mri.h"
df2a7313 35#include <ldgram.h>
252b5132
RH
36#include "libiberty.h"
37
e47d05ad 38struct section_name_struct {
252b5132 39 struct section_name_struct *next;
4da711b1
AM
40 const char *name;
41 const char *alias;
252b5132
RH
42 etree_type *vma;
43 etree_type *align;
44 etree_type *subalign;
45 int ok_to_load;
891fa266 46};
252b5132 47
279e75dc 48static unsigned int symbol_truncate = 10000;
0ef76c43
AM
49static etree_type *base; /* Relocation base - or null */
50
279e75dc
BE
51static struct section_name_struct *order;
52static struct section_name_struct *only_load;
53static struct section_name_struct *address;
54static struct section_name_struct *alias;
252b5132 55
279e75dc
BE
56static struct section_name_struct *alignment;
57static struct section_name_struct *subalignment;
252b5132 58
252b5132 59static struct section_name_struct **
1579bae1 60lookup (const char *name, struct section_name_struct **list)
252b5132 61{
252b5132 62 struct section_name_struct **ptr = list;
5cc18311
KH
63
64 while (*ptr)
891fa266
NC
65 {
66 if (strcmp (name, (*ptr)->name) == 0)
67 /* If this is a match, delete it, we only keep the last instance
68 of any name. */
69 *ptr = (*ptr)->next;
70 else
71 ptr = &((*ptr)->next);
252b5132 72 }
252b5132 73
1e9cc1c2
NC
74 *ptr = (struct section_name_struct *)
75 xmalloc (sizeof (struct section_name_struct));
252b5132
RH
76 return ptr;
77}
78
79static void
1579bae1
AM
80mri_add_to_list (struct section_name_struct **list,
81 const char *name,
82 etree_type *vma,
83 const char *zalias,
84 etree_type *align,
85 etree_type *subalign)
252b5132 86{
e47d05ad 87 struct section_name_struct **ptr = lookup (name, list);
5cc18311 88
252b5132
RH
89 (*ptr)->name = name;
90 (*ptr)->vma = vma;
1579bae1 91 (*ptr)->next = NULL;
252b5132
RH
92 (*ptr)->ok_to_load = 0;
93 (*ptr)->alias = zalias;
94 (*ptr)->align = align;
95 (*ptr)->subalign = subalign;
96}
97
252b5132 98void
1579bae1 99mri_output_section (const char *name, etree_type *vma)
252b5132 100{
e47d05ad 101 mri_add_to_list (&address, name, vma, 0, 0, 0);
252b5132
RH
102}
103
891fa266
NC
104/* If any ABSOLUTE <name> are in the script, only load those files
105 marked thus. */
252b5132
RH
106
107void
1579bae1 108mri_only_load (const char *name)
252b5132 109{
e47d05ad 110 mri_add_to_list (&only_load, name, 0, 0, 0, 0);
252b5132
RH
111}
112
252b5132 113void
1579bae1 114mri_base (etree_type *exp)
252b5132
RH
115{
116 base = exp;
117}
118
119static int done_tree = 0;
120
121void
1579bae1 122mri_draw_tree (void)
252b5132 123{
891fa266
NC
124 if (done_tree)
125 return;
126
891fa266 127 /* Now build the statements for the ldlang machine. */
252b5132 128
396a2467 129 /* Attach the addresses of any which have addresses,
891fa266 130 and add the ones not mentioned. */
1579bae1 131 if (address != NULL)
252b5132 132 {
891fa266
NC
133 struct section_name_struct *alist;
134 struct section_name_struct *olist;
5cc18311 135
1579bae1 136 if (order == NULL)
891fa266
NC
137 order = address;
138
139 for (alist = address;
1579bae1 140 alist != NULL;
5cc18311 141 alist = alist->next)
252b5132 142 {
891fa266 143 int done = 0;
5cc18311 144
1579bae1 145 for (olist = order; done == 0 && olist != NULL; olist = olist->next)
891fa266 146 {
5cc18311 147 if (strcmp (alist->name, olist->name) == 0)
891fa266
NC
148 {
149 olist->vma = alist->vma;
150 done = 1;
151 }
152 }
5cc18311 153
891fa266
NC
154 if (!done)
155 {
156 /* Add this onto end of order list. */
e47d05ad 157 mri_add_to_list (&order, alist->name, alist->vma, 0, 0, 0);
891fa266 158 }
252b5132 159 }
252b5132
RH
160 }
161
252b5132
RH
162 /* If we're only supposed to load a subset of them in, then prune
163 the list. */
1579bae1 164 if (only_load != NULL)
252b5132 165 {
891fa266
NC
166 struct section_name_struct *ptr1;
167 struct section_name_struct *ptr2;
5cc18311 168
1579bae1 169 if (order == NULL)
891fa266 170 order = only_load;
5cc18311 171
891fa266 172 /* See if this name is in the list, if it is then we can load it. */
5cc18311
KH
173 for (ptr1 = only_load; ptr1; ptr1 = ptr1->next)
174 for (ptr2 = order; ptr2; ptr2 = ptr2->next)
891fa266
NC
175 if (strcmp (ptr2->name, ptr1->name) == 0)
176 ptr2->ok_to_load = 1;
252b5132 177 }
5cc18311 178 else
891fa266
NC
179 {
180 /* No only load list, so everything is ok to load. */
181 struct section_name_struct *ptr;
5cc18311 182
e47d05ad 183 for (ptr = order; ptr; ptr = ptr->next)
891fa266 184 ptr->ok_to_load = 1;
e47d05ad 185 }
252b5132 186
891fa266 187 /* Create the order of sections to load. */
1579bae1 188 if (order != NULL)
252b5132 189 {
891fa266
NC
190 /* Been told to output the sections in a certain order. */
191 struct section_name_struct *p = order;
5cc18311
KH
192
193 while (p)
891fa266
NC
194 {
195 struct section_name_struct *aptr;
196 etree_type *align = 0;
197 etree_type *subalign = 0;
b6bf44ba 198 struct wildcard_list *tmp;
5cc18311 199
891fa266 200 /* See if an alignment has been specified. */
e47d05ad 201 for (aptr = alignment; aptr; aptr = aptr->next)
891fa266 202 if (strcmp (aptr->name, p->name) == 0)
e47d05ad 203 align = aptr->align;
891fa266 204
e47d05ad 205 for (aptr = subalignment; aptr; aptr = aptr->next)
891fa266 206 if (strcmp (aptr->name, p->name) == 0)
e47d05ad 207 subalign = aptr->subalign;
891fa266
NC
208
209 if (base == 0)
e47d05ad 210 base = p->vma ? p->vma : exp_nameop (NAME, ".");
891fa266
NC
211
212 lang_enter_output_section_statement (p->name, base,
1e9cc1c2 213 p->ok_to_load ? normal_section : noload_section,
1eec346e 214 align, subalign, NULL, 0, 0);
891fa266 215 base = 0;
1e9cc1c2 216 tmp = (struct wildcard_list *) xmalloc (sizeof *tmp);
b6bf44ba
AM
217 tmp->next = NULL;
218 tmp->spec.name = p->name;
219 tmp->spec.exclude_name_list = NULL;
bcaa7b3e 220 tmp->spec.sorted = none;
ae17ab41 221 tmp->spec.section_flag_list = NULL;
b34976b6 222 lang_add_wild (NULL, tmp, FALSE);
5cc18311 223
891fa266
NC
224 /* If there is an alias for this section, add it too. */
225 for (aptr = alias; aptr; aptr = aptr->next)
226 if (strcmp (aptr->alias, p->name) == 0)
b6bf44ba 227 {
1e9cc1c2 228 tmp = (struct wildcard_list *) xmalloc (sizeof *tmp);
b6bf44ba
AM
229 tmp->next = NULL;
230 tmp->spec.name = aptr->name;
231 tmp->spec.exclude_name_list = NULL;
bcaa7b3e 232 tmp->spec.sorted = none;
ae17ab41 233 tmp->spec.section_flag_list = NULL;
b34976b6 234 lang_add_wild (NULL, tmp, FALSE);
b6bf44ba 235 }
891fa266 236
1579bae1 237 lang_leave_output_section_statement (0, "*default*", NULL, NULL);
891fa266
NC
238
239 p = p->next;
252b5132 240 }
252b5132 241 }
252b5132
RH
242
243 done_tree = 1;
252b5132 244}
891fa266 245
252b5132 246void
1579bae1 247mri_load (const char *name)
252b5132
RH
248{
249 base = 0;
1579bae1 250 lang_add_input_file (name, lang_input_file_is_file_enum, NULL);
252b5132
RH
251}
252
252b5132 253void
1579bae1 254mri_order (const char *name)
252b5132 255{
e47d05ad 256 mri_add_to_list (&order, name, 0, 0, 0, 0);
252b5132
RH
257}
258
5cc18311 259void
1579bae1 260mri_alias (const char *want, const char *is, int isn)
252b5132 261{
891fa266
NC
262 if (!is)
263 {
264 char buf[20];
5cc18311 265
891fa266
NC
266 /* Some sections are digits. */
267 sprintf (buf, "%d", isn);
5cc18311 268
891fa266 269 is = xstrdup (buf);
5cc18311 270
891fa266
NC
271 if (is == NULL)
272 abort ();
273 }
5cc18311 274
e47d05ad 275 mri_add_to_list (&alias, is, 0, want, 0, 0);
252b5132
RH
276}
277
5cc18311 278void
1579bae1 279mri_name (const char *name)
252b5132 280{
891fa266 281 lang_add_output (name, 1);
252b5132
RH
282}
283
252b5132 284void
1579bae1 285mri_format (const char *name)
252b5132 286{
891fa266 287 if (strcmp (name, "S") == 0)
1579bae1 288 lang_add_output_format ("srec", NULL, NULL, 1);
5cc18311 289
891fa266 290 else
df5f2391 291 einfo (_("%F%P: unknown format type %s\n"), name);
252b5132
RH
292}
293
252b5132 294void
1579bae1 295mri_public (const char *name, etree_type *exp)
252b5132 296{
eb8476a6 297 lang_add_assignment (exp_assign (name, exp, FALSE));
252b5132
RH
298}
299
5cc18311 300void
1579bae1 301mri_align (const char *name, etree_type *exp)
252b5132 302{
e47d05ad 303 mri_add_to_list (&alignment, name, 0, 0, exp, 0);
252b5132
RH
304}
305
5cc18311 306void
1579bae1 307mri_alignmod (const char *name, etree_type *exp)
252b5132 308{
e47d05ad 309 mri_add_to_list (&subalignment, name, 0, 0, 0, exp);
252b5132
RH
310}
311
5cc18311 312void
1579bae1 313mri_truncate (unsigned int exp)
252b5132
RH
314{
315 symbol_truncate = exp;
316}
This page took 0.93779 seconds and 4 git commands to generate.