Initial revision
[deliverable/binutils-gdb.git] / ld / ldlang.c
CommitLineData
2fa0b342
DHW
1/* Copyright (C) 1991 Free Software Foundation, Inc.
2
3This file is part of GLD, the Gnu Linker.
4
5GLD is free software; you can redistribute it and/or modify
6it under the terms of the GNU General Public License as published by
7the Free Software Foundation; either version 1, or (at your option)
8any later version.
9
10GLD is distributed in the hope that it will be useful,
11but WITHOUT ANY WARRANTY; without even the implied warranty of
12MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13GNU General Public License for more details.
14
15You should have received a copy of the GNU General Public License
16along with GLD; see the file COPYING. If not, write to
17the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA. */
18
19/* $Id$
20 *
2fa0b342
DHW
21*/
22
23
24
25#include "sysdep.h"
26#include "bfd.h"
27
28#include "ld.h"
29#include "ldmain.h"
30#include "ldsym.h"
7bc4a0d7 31#include "ldgram.h"
3f8d46e7 32
2fa0b342
DHW
33#include "ldlang.h"
34#include "ldexp.h"
8c514453 35#include "ldemul.h"
2fa0b342 36#include "ldlex.h"
3f8d46e7 37#include "ldmisc.h"
2fa0b342
DHW
38/* FORWARDS */
39PROTO(static void, print_statements,(void));
40PROTO(static void, print_statement,(lang_statement_union_type *,
41 lang_output_section_statement_type *));
42
43
d4c02e29
SC
44/* LOCALS */
45static CONST char *startup_file;
46static lang_statement_list_type input_file_chain;
47static boolean placed_commons = false;
48static lang_output_section_statement_type *default_common_section;
49static boolean map_option_f;
50static bfd_vma print_dot;
51static lang_input_statement_type *first_file;
52static lang_statement_list_type lang_output_section_statement;
53static CONST char *current_target;
54static CONST char *output_target;
55static size_t longest_section_name = 8;
56static asection common_section;
57static section_userdata_type common_section_userdata;
58static lang_statement_list_type statement_list;
2fa0b342 59/* EXPORTS */
2fa0b342 60
d4c02e29
SC
61lang_statement_list_type *stat_ptr = &statement_list;
62lang_input_statement_type *script_file = 0;
63boolean option_longmap = false;
64lang_statement_list_type file_chain = {0};
65CONST char *entry_symbol = 0;
3f8d46e7 66bfd_size_type largest_section = 0;
d4c02e29
SC
67boolean lang_has_input_file = false;
68lang_output_section_statement_type *create_object_symbols = 0;
69boolean had_output_filename = false;
70boolean lang_float_flag = false;
71/* IMPORTS */
72extern char *default_target;
2fa0b342 73
d4c02e29
SC
74extern unsigned int undefined_global_sym_count;
75extern char *current_file;
2fa0b342 76extern bfd *output_bfd;
2fa0b342
DHW
77extern enum bfd_architecture ldfile_output_architecture;
78extern unsigned long ldfile_output_machine;
79extern char *ldfile_output_machine_name;
2fa0b342 80extern ldsym_type *symbol_head;
d4c02e29 81extern unsigned int commons_pending;
2fa0b342
DHW
82extern args_type command_line;
83extern ld_config_type config;
2fa0b342 84extern boolean had_script;
2fa0b342
DHW
85extern boolean write_map;
86
87
2fa0b342
DHW
88#ifdef __STDC__
89#define cat(a,b) a##b
90#else
91#define cat(a,b) a/**/b
92#endif
93
94#define new_stat(x,y) (cat(x,_type)*) new_statement(cat(x,_enum), sizeof(cat(x,_type)),y)
95
96#define outside_section_address(q) ( (q)->output_offset + (q)->output_section->vma)
97
98#define outside_symbol_address(q) ((q)->value + outside_section_address(q->section))
99
3f8d46e7
JG
100static void
101DEFUN(print_size,(value),
102 size_t value)
103{
104 printf("%5x", (unsigned)value);
105}
106static void
107DEFUN(print_alignment,(value),
108 unsigned int value)
109{
48491e2e 110 printf("2**%1u",value);
3f8d46e7
JG
111}
112static void
113DEFUN(print_fill,(value),
114 fill_type value)
115{
116 printf("%04x",(unsigned)value);
117}
118
d4c02e29 119
3f8d46e7
JG
120static void
121DEFUN(print_section,(name),
122 CONST char *CONST name)
123{
124 printf("%*s", -longest_section_name, name);
125}
2fa0b342 126
1418c83b
SC
127/*----------------------------------------------------------------------
128 lang_for_each_statement walks the parse tree and calls the provided
129 function for each node
130*/
131
132static void
133DEFUN(lang_for_each_statement_worker,(func, s),
134 void (*func)() AND
135 lang_statement_union_type *s)
136{
137 for (; s != (lang_statement_union_type *)NULL ; s = s->next)
138 {
139 func(s);
140
141 switch (s->header.type) {
142 case lang_output_section_statement_enum:
143 lang_for_each_statement_worker
144 (func,
145 s->output_section_statement.children.head);
146 break;
147 case lang_wild_statement_enum:
148 lang_for_each_statement_worker
149 (func,
150 s->wild_statement.children.head);
151 break;
152 case lang_data_statement_enum:
153 case lang_object_symbols_statement_enum:
154 case lang_output_statement_enum:
155 case lang_target_statement_enum:
156 case lang_input_section_enum:
157 case lang_input_statement_enum:
158 case lang_fill_statement_enum:
159 case lang_assignment_statement_enum:
160 case lang_padding_statement_enum:
161 case lang_address_statement_enum:
162 break;
163 default:
164 FAIL();
165 break;
166 }
167 }
168}
169
170void
171DEFUN(lang_for_each_statement,(func),
172 void (*func)())
173{
174 lang_for_each_statement_worker(func,
175 statement_list.head);
176}
177/*----------------------------------------------------------------------*/
178static void
179DEFUN(lang_list_init,(list),
180 lang_statement_list_type *list)
2fa0b342
DHW
181{
182list->head = (lang_statement_union_type *)NULL;
183list->tail = &list->head;
184}
185
2fa0b342 186
1418c83b
SC
187/*----------------------------------------------------------------------
188
189 build a new statement node for the parse tree
190
191 */
2fa0b342
DHW
192
193static
1418c83b
SC
194lang_statement_union_type*
195DEFUN(new_statement,(type, size, list),
196 enum statement_enum type AND
3f8d46e7 197 bfd_size_type size AND
1418c83b 198 lang_statement_list_type *list)
2fa0b342
DHW
199{
200 lang_statement_union_type *new = (lang_statement_union_type *)
201 ldmalloc(size);
202 new->header.type = type;
203 new->header.next = (lang_statement_union_type *)NULL;
1418c83b 204 lang_statement_append(list, new, &new->header.next);
2fa0b342
DHW
205 return new;
206}
207
1418c83b
SC
208/*
209 Build a new input file node for the language. There are several ways
210 in which we treat an input file, eg, we only look at symbols, or
211 prefix it with a -l etc.
212
213 We can be supplied with requests for input files more than once;
214 they may, for example be split over serveral lines like foo.o(.text)
215 foo.o(.data) etc, so when asked for a file we check that we havn't
216 got it already so we don't duplicate the bfd.
217
218 */
2fa0b342 219static lang_input_statement_type *
1418c83b
SC
220DEFUN(new_afile, (name, file_type, target),
221 CONST char *CONST name AND
222 CONST lang_input_file_enum_type file_type AND
223 CONST char *CONST target)
2fa0b342
DHW
224{
225 lang_input_statement_type *p = new_stat(lang_input_statement,
226 stat_ptr);
227 lang_has_input_file = true;
228 p->target = target;
229 switch (file_type) {
230 case lang_input_file_is_symbols_only_enum:
231 p->filename = name;
232 p->is_archive =false;
233 p->real = true;
234 p->local_sym_name= name;
235 p->just_syms_flag = true;
236 p->search_dirs_flag = false;
237 break;
238 case lang_input_file_is_fake_enum:
239 p->filename = name;
240 p->is_archive =false;
241 p->real = false;
242 p->local_sym_name= name;
243 p->just_syms_flag = false;
244 p->search_dirs_flag =false;
2fa0b342
DHW
245 break;
246 case lang_input_file_is_l_enum:
247 p->is_archive = true;
248 p->filename = name;
249 p->real = true;
250 p->local_sym_name = concat("-l",name,"");
251 p->just_syms_flag = false;
252 p->search_dirs_flag = true;
253 break;
2fa0b342
DHW
254 case lang_input_file_is_search_file_enum:
255 case lang_input_file_is_marker_enum:
256 p->filename = name;
257 p->is_archive =false;
258 p->real = true;
259 p->local_sym_name= name;
260 p->just_syms_flag = false;
261 p->search_dirs_flag =true;
262 break;
2fa0b342
DHW
263 case lang_input_file_is_file_enum:
264 p->filename = name;
265 p->is_archive =false;
266 p->real = true;
267 p->local_sym_name= name;
268 p->just_syms_flag = false;
269 p->search_dirs_flag =false;
270 break;
2fa0b342
DHW
271 default:
272 FAIL();
273 }
274 p->asymbols = (asymbol **)NULL;
275 p->superfile = (lang_input_statement_type *)NULL;
2fa0b342
DHW
276 p->next_real_file = (lang_statement_union_type*)NULL;
277 p->next = (lang_statement_union_type*)NULL;
278 p->symbol_count = 0;
279 p->common_output_section = (asection *)NULL;
2fa0b342
DHW
280 lang_statement_append(&input_file_chain,
281 (lang_statement_union_type *)p,
282 &p->next_real_file);
283 return p;
284}
285
1418c83b
SC
286
287
2fa0b342 288lang_input_statement_type *
1418c83b
SC
289DEFUN(lang_add_input_file,(name, file_type, target),
290 char *name AND
291 lang_input_file_enum_type file_type AND
292 char *target)
2fa0b342
DHW
293{
294 /* Look it up or build a new one */
1418c83b
SC
295 lang_has_input_file = true;
296#if 0
2fa0b342
DHW
297 lang_input_statement_type *p;
298
299 for (p = (lang_input_statement_type *)input_file_chain.head;
300 p != (lang_input_statement_type *)NULL;
301 p = (lang_input_statement_type *)(p->next_real_file))
1418c83b
SC
302 {
303 /* Sometimes we have incomplete entries in here */
304 if (p->filename != (char *)NULL) {
305 if(strcmp(name,p->filename) == 0) return p;
306 }
307
308 }
309#endif
2fa0b342
DHW
310 return new_afile(name, file_type, target);
311}
312
313
1418c83b 314/* Build enough state so that the parser can build its tree */
2fa0b342 315void
1418c83b 316DEFUN_VOID(lang_init)
2fa0b342
DHW
317{
318
319 stat_ptr= &statement_list;
320 lang_list_init(stat_ptr);
321
322 lang_list_init(&input_file_chain);
323 lang_list_init(&lang_output_section_statement);
324 lang_list_init(&file_chain);
325 first_file = lang_add_input_file((char *)NULL,
326 lang_input_file_is_marker_enum,
327 (char *)NULL);
2fa0b342
DHW
328}
329
2fa0b342 330
1418c83b
SC
331/*----------------------------------------------------------------------
332 A region is an area of memory declared with the
333 MEMORY { name:org=exp, len=exp ... }
334 syntax.
2fa0b342 335
1418c83b 336 We maintain a list of all the regions here
2fa0b342 337
1418c83b
SC
338 If no regions are specified in the script, then the default is used
339 which is created when looked up to be the entire data space
2fa0b342
DHW
340*/
341
342static lang_memory_region_type *lang_memory_region_list;
343static lang_memory_region_type **lang_memory_region_list_tail = &lang_memory_region_list;
344
345lang_memory_region_type *
1418c83b
SC
346DEFUN(lang_memory_region_lookup,(name),
347 CONST char *CONST name)
2fa0b342
DHW
348{
349
1418c83b
SC
350 lang_memory_region_type *p = lang_memory_region_list;
351 for (p = lang_memory_region_list;
352 p != ( lang_memory_region_type *)NULL;
353 p = p->next) {
354 if (strcmp(p->name, name) == 0) {
355 return p;
2fa0b342 356 }
1418c83b
SC
357 }
358 if (strcmp(name,"*default*")==0) {
359 /* This is the default region, dig out first one on the list */
360 if (lang_memory_region_list != (lang_memory_region_type*)NULL){
361 return lang_memory_region_list;
2fa0b342 362 }
1418c83b 363 }
2fa0b342 364 {
1418c83b 365 lang_memory_region_type *new =
3f8d46e7 366 (lang_memory_region_type *)ldmalloc((bfd_size_type)(sizeof(lang_memory_region_type)));
1418c83b
SC
367 new->name = buystring(name);
368 new->next = (lang_memory_region_type *)NULL;
369
370 *lang_memory_region_list_tail = new;
371 lang_memory_region_list_tail = &new->next;
372 new->origin = 0;
373 new->length = ~0;
374 new->current = 0;
375 return new;
2fa0b342
DHW
376 }
377}
378
379
2fa0b342 380lang_output_section_statement_type *
1418c83b
SC
381DEFUN(lang_output_section_find,(name),
382 CONST char * CONST name)
2fa0b342
DHW
383{
384 lang_statement_union_type *u;
385 lang_output_section_statement_type *lookup;
386
387 for (u = lang_output_section_statement.head;
388 u != (lang_statement_union_type *)NULL;
389 u = lookup->next)
1418c83b
SC
390 {
391 lookup = &u->output_section_statement;
392 if (strcmp(name, lookup->name)==0) {
393 return lookup;
394 }
2fa0b342 395 }
2fa0b342
DHW
396 return (lang_output_section_statement_type *)NULL;
397}
398
399lang_output_section_statement_type *
1418c83b
SC
400DEFUN(lang_output_section_statement_lookup,(name),
401 CONST char * CONST name)
2fa0b342
DHW
402{
403 lang_output_section_statement_type *lookup;
404 lookup =lang_output_section_find(name);
405 if (lookup == (lang_output_section_statement_type *)NULL) {
406
407 lookup =(lang_output_section_statement_type *)
408 new_stat(lang_output_section_statement, stat_ptr);
409 lookup->region = (lang_memory_region_type *)NULL;
410 lookup->fill = 0;
411 lookup->block_value = 1;
412 lookup->name = name;
413
414 lookup->next = (lang_statement_union_type*)NULL;
415 lookup->bfd_section = (asection *)NULL;
416 lookup->processed = false;
417 lookup->addr_tree = (etree_type *)NULL;
418 lang_list_init(&lookup->children);
419
420 lang_statement_append(&lang_output_section_statement,
421 (lang_statement_union_type *)lookup,
422 &lookup->next);
423 }
424 return lookup;
425}
426
427
428
429
430
431static void
1418c83b
SC
432DEFUN(print_flags, (outfile, ignore_flags),
433 FILE *outfile AND
7bc4a0d7 434 int *ignore_flags)
2fa0b342
DHW
435{
436 fprintf(outfile,"(");
437#if 0
438 if (flags->flag_read) fprintf(outfile,"R");
439 if (flags->flag_write) fprintf(outfile,"W");
440 if (flags->flag_executable) fprintf(outfile,"X");
441 if (flags->flag_loadable) fprintf(outfile,"L");
442#endif
443 fprintf(outfile,")");
444}
445
446void
1418c83b
SC
447DEFUN(lang_map,(outfile),
448 FILE *outfile)
2fa0b342
DHW
449{
450 lang_memory_region_type *m;
451 fprintf(outfile,"**MEMORY CONFIGURATION**\n\n");
48491e2e 452#ifdef HOST_64_BIT
2fa0b342 453 fprintf(outfile,"name\t\torigin\t\tlength\t\tattributes\n");
48491e2e
SC
454#else
455 fprintf(outfile,"name\t\torigin length\t\tattributes\n");
456#endif
2fa0b342
DHW
457 for (m = lang_memory_region_list;
458 m != (lang_memory_region_type *)NULL;
459 m = m->next)
460 {
461 fprintf(outfile,"%-16s", m->name);
3f8d46e7
JG
462 print_address(m->origin);
463 print_space();
464 print_address(m->length);
465 print_space();
2fa0b342
DHW
466 print_flags(outfile, &m->flags);
467 fprintf(outfile,"\n");
468 }
469 fprintf(outfile,"\n\n**LINK EDITOR MEMORY MAP**\n\n");
48491e2e
SC
470 fprintf(outfile,"output input virtual\n");
471 fprintf(outfile,"section section address tsize\n\n");
2fa0b342
DHW
472
473 print_statements();
474
475}
476
477/*
478 *
479 */
1418c83b
SC
480static void
481DEFUN(init_os,(s),
482 lang_output_section_statement_type *s)
2fa0b342
DHW
483{
484 section_userdata_type *new =
485 (section_userdata_type *)
3f8d46e7 486 ldmalloc((bfd_size_type)(sizeof(section_userdata_type)));
2fa0b342
DHW
487
488 s->bfd_section = bfd_make_section(output_bfd, s->name);
357a1f38
SC
489 if (s->bfd_section == (asection *)NULL) {
490 info("%P%F output format %s cannot represent section called %s\n",
491 output_bfd->xvec->name,
492 s->name);
493 }
2fa0b342 494 s->bfd_section->output_section = s->bfd_section;
7bc4a0d7
SC
495/* s->bfd_section->flags = s->flags;*/
496
2fa0b342
DHW
497 /* We initialize an output sections output offset to minus its own */
498 /* vma to allow us to output a section through itself */
499 s->bfd_section->output_offset = 0;
a0ad3035 500 get_userdata( s->bfd_section) = (PTR)new;
2fa0b342
DHW
501}
502
1418c83b
SC
503/***********************************************************************
504 The wild routines.
505
506 These expand statements like *(.text) and foo.o to a list of
507 explicit actions, like foo.o(.text), bar.o(.text) and
508 foo.o(.text,.data) .
509
510 The toplevel routine, wild, takes a statement, section, file and
511 target. If either the section or file is null it is taken to be the
512 wildcard. Seperate lang_input_section statements are created for
513 each part of the expanstion, and placed after the statement provided.
514
515*/
516
2fa0b342 517static void
1418c83b
SC
518DEFUN(wild_doit,(ptr, section, output, file),
519 lang_statement_list_type *ptr AND
520 asection *section AND
521 lang_output_section_statement_type *output AND
522 lang_input_statement_type *file)
2fa0b342
DHW
523{
524 if(output->bfd_section == (asection *)NULL)
525 {
526 init_os(output);
527 }
528
529 if (section != (asection *)NULL
530 && section->output_section == (asection *)NULL) {
531 /* Add a section reference to the list */
532 lang_input_section_type *new = new_stat(lang_input_section, ptr);
533
534 new->section = section;
535 new->ifile = file;
536 section->output_section = output->bfd_section;
537 section->output_section->flags |= section->flags;
538 if (section->alignment_power > output->bfd_section->alignment_power) {
539 output->bfd_section->alignment_power = section->alignment_power;
540 }
2fa0b342
DHW
541 }
542}
543
544static asection *
1418c83b
SC
545DEFUN(our_bfd_get_section_by_name,(abfd, section),
546bfd *abfd AND
547CONST char *section)
2fa0b342
DHW
548{
549 return bfd_get_section_by_name(abfd, section);
2fa0b342 550}
1418c83b 551
2fa0b342 552static void
1418c83b
SC
553DEFUN(wild_section,(ptr, section, file , output),
554 lang_wild_statement_type *ptr AND
555 CONST char *section AND
556 lang_input_statement_type *file AND
557 lang_output_section_statement_type *output)
2fa0b342
DHW
558{
559 asection *s;
1418c83b
SC
560 if (file->just_syms_flag == false) {
561 if (section == (char *)NULL) {
562 /* Do the creation to all sections in the file */
563 for (s = file->the_bfd->sections; s != (asection *)NULL; s=s->next) {
564 wild_doit(&ptr->children, s, output, file);
565 }
566 }
567 else {
568 /* Do the creation to the named section only */
569 wild_doit(&ptr->children,
570 our_bfd_get_section_by_name(file->the_bfd, section),
571 output, file);
2fa0b342
DHW
572 }
573 }
2fa0b342
DHW
574}
575
576
1418c83b
SC
577/* passed a file name (which must have been seen already and added to
578 the statement tree. We will see if it has been opened already and
579 had its symbols read. If not then we'll read it.
2fa0b342 580
1418c83b
SC
581 Archives are pecuilar here. We may open them once, but if they do
582 not define anything we need at the time, they won't have all their
583 symbols read. If we need them later, we'll have to redo it.
584 */
2fa0b342 585static
1418c83b
SC
586lang_input_statement_type *
587DEFUN(lookup_name,(name),
588 CONST char * CONST name)
2fa0b342
DHW
589{
590 lang_input_statement_type *search;
591 for(search = (lang_input_statement_type *)input_file_chain.head;
592 search != (lang_input_statement_type *)NULL;
593 search = (lang_input_statement_type *)search->next_real_file)
1418c83b
SC
594 {
595 if (search->filename == (char *)NULL && name == (char *)NULL) {
2fa0b342
DHW
596 return search;
597 }
1418c83b
SC
598 if (search->filename != (char *)NULL && name != (char *)NULL) {
599 if (strcmp(search->filename, name) == 0) {
600 ldmain_open_file_read_symbol(search);
601 return search;
602 }
603 }
2fa0b342 604 }
2fa0b342 605
1418c83b
SC
606 /* There isn't an afile entry for this file yet, this must be
607 because the name has only appeared inside a load script and not
608 on the command line */
609 search = new_afile(name, lang_input_file_is_file_enum, default_target);
610 ldmain_open_file_read_symbol(search);
2fa0b342 611 return search;
1418c83b
SC
612
613
2fa0b342
DHW
614}
615
616static void
1418c83b
SC
617DEFUN(wild,(s, section, file, target, output),
618 lang_wild_statement_type *s AND
619 CONST char *CONST section AND
620 CONST char *CONST file AND
621 CONST char *CONST target AND
622 lang_output_section_statement_type *output)
2fa0b342
DHW
623{
624 lang_input_statement_type *f;
625 if (file == (char *)NULL) {
626 /* Perform the iteration over all files in the list */
627 for (f = (lang_input_statement_type *)file_chain.head;
628 f != (lang_input_statement_type *)NULL;
629 f = (lang_input_statement_type *)f->next) {
630 wild_section(s, section, f, output);
631 }
632 }
633 else {
634 /* Perform the iteration over a single file */
1418c83b 635 wild_section( s, section, lookup_name(file), output);
2fa0b342 636 }
b0f36869
SC
637 if (section != (char *)NULL
638 && strcmp(section,"COMMON") == 0
1418c83b
SC
639 && default_common_section == (lang_output_section_statement_type*)NULL)
640 {
641 /* Remember the section that common is going to incase we later
642 get something which doesn't know where to put it */
643 default_common_section = output;
644 }
2fa0b342
DHW
645}
646
647/*
648 read in all the files
649 */
650static bfd *
097879bc
SC
651DEFUN(open_output,(name),
652 CONST char *CONST name)
2fa0b342 653{
1418c83b 654 extern CONST char *output_filename;
097879bc
SC
655 bfd *output;
656 if (output_target == (char *)NULL) {
657 if (current_target != (char *)NULL)
658 output_target = current_target;
659 else
660 output_target = default_target;
661 }
662 output = bfd_openw(name, output_target);
2fa0b342 663 output_filename = name;
097879bc 664
2fa0b342 665 if (output == (bfd *)NULL)
1418c83b
SC
666 {
667 if (bfd_error == invalid_target) {
097879bc 668 info("%P%F target %s not found\n", output_target);
1418c83b
SC
669 }
670 info("%P%F problem opening output file %s, %E", name);
2fa0b342 671 }
2fa0b342
DHW
672
673 output->flags |= D_PAGED;
674 bfd_set_format(output, bfd_object);
675 return output;
676}
1418c83b
SC
677
678
097879bc 679
1418c83b 680
2fa0b342 681static void
1418c83b
SC
682DEFUN(ldlang_open_output,(statement),
683 lang_statement_union_type *statement)
2fa0b342 684{
1418c83b
SC
685 switch (statement->header.type)
686 {
687 case lang_output_statement_enum:
097879bc 688 output_bfd = open_output(statement->output_statement.name);
2fa0b342 689 ldemul_set_output_arch();
2fa0b342 690 break;
1418c83b 691
2fa0b342 692 case lang_target_statement_enum:
1418c83b 693 current_target = statement->target_statement.target;
2fa0b342 694 break;
1418c83b 695 default:
2fa0b342 696 break;
1418c83b
SC
697 }
698}
2fa0b342 699
1418c83b
SC
700static void
701DEFUN(open_input_bfds,(statement),
702 lang_statement_union_type *statement)
703{
704 switch (statement->header.type)
705 {
706 case lang_target_statement_enum:
707 current_target = statement->target_statement.target;
2fa0b342 708 break;
1418c83b
SC
709 case lang_wild_statement_enum:
710 /* Maybe we should load the file's symbols */
711 if (statement->wild_statement.filename)
712 {
713 (void) lookup_name(statement->wild_statement.filename);
714 }
2fa0b342 715 break;
1418c83b
SC
716 case lang_input_statement_enum:
717 if (statement->input_statement.real == true)
718 {
719 statement->input_statement.target = current_target;
720 lookup_name(statement->input_statement.filename);
721 }
2fa0b342 722 break;
1418c83b 723 default:
2fa0b342
DHW
724 break;
725 }
2fa0b342 726}
2fa0b342
DHW
727/* If there are [COMMONS] statements, put a wild one into the bss section */
728
729static void
730lang_reasonable_defaults()
731{
1418c83b 732#if 0
8cb5eb31
SC
733 lang_output_section_statement_lookup(".text");
734 lang_output_section_statement_lookup(".data");
735
2fa0b342
DHW
736 default_common_section =
737 lang_output_section_statement_lookup(".bss");
8cb5eb31 738
1418c83b 739
2fa0b342
DHW
740 if (placed_commons == false) {
741 lang_wild_statement_type *new =
742 new_stat(lang_wild_statement,
743 &default_common_section->children);
744 new->section_name = "COMMON";
745 new->filename = (char *)NULL;
746 lang_list_init(&new->children);
747 }
1418c83b 748#endif
8cb5eb31 749
2fa0b342
DHW
750}
751
1418c83b
SC
752/*
753 Add the supplied name to the symbol table as an undefined reference.
754 Remove items from the chain as we open input bfds
755 */
756typedef struct ldlang_undef_chain_list_struct {
757 struct ldlang_undef_chain_list_struct *next;
758 char *name;
759} ldlang_undef_chain_list_type;
760
761static ldlang_undef_chain_list_type *ldlang_undef_chain_list_head;
762
763void
764DEFUN(ldlang_add_undef,(name),
765 CONST char *CONST name)
2fa0b342 766{
1418c83b
SC
767 ldlang_undef_chain_list_type *new =
768 (ldlang_undef_chain_list_type
3f8d46e7 769 *)ldmalloc((bfd_size_type)(sizeof(ldlang_undef_chain_list_type)));
1418c83b
SC
770
771 new->next = ldlang_undef_chain_list_head;
772 ldlang_undef_chain_list_head = new;
773
774 new->name = buystring(name);
775}
776/* Run through the list of undefineds created above and place them
777 into the linker hash table as undefined symbols belonging to the
778 script file.
779*/
780static void
781DEFUN_VOID(lang_place_undefineds)
782{
783 ldlang_undef_chain_list_type *ptr = ldlang_undef_chain_list_head;
784 while (ptr != (ldlang_undef_chain_list_type*)NULL) {
785 ldsym_type *sy = ldsym_get(ptr->name);
786 asymbol *def;
3f8d46e7 787 asymbol **def_ptr = (asymbol **)ldmalloc((bfd_size_type)(sizeof(asymbol **)));
1418c83b
SC
788 def = (asymbol *)bfd_make_empty_symbol(script_file->the_bfd);
789 *def_ptr= def;
790 def->name = ptr->name;
791 def->flags = BSF_UNDEFINED;
792 def->section = (asection *)NULL;
793 Q_enter_global_ref(def_ptr);
794 ptr = ptr->next;
2fa0b342 795 }
1418c83b 796}
2fa0b342 797
1418c83b
SC
798
799
800/* Copy important data from out internal form to the bfd way. Also
801 create a section for the dummy file
802 */
803
804static void
805DEFUN_VOID(lang_create_output_section_statements)
806{
807 lang_statement_union_type*os;
808 for (os = lang_output_section_statement.head;
809 os != (lang_statement_union_type*)NULL;
810 os = os->output_section_statement.next) {
811 lang_output_section_statement_type *s =
812 &os->output_section_statement;
813 init_os(s);
814 }
815
816}
817
818static void
819DEFUN_VOID(lang_init_script_file)
820{
821 script_file = lang_add_input_file("script file",
822 lang_input_file_is_fake_enum,
823 (char *)NULL);
824 script_file->the_bfd = bfd_create("script file", output_bfd);
825 script_file->symbol_count = 0;
826 script_file->the_bfd->sections = output_bfd->sections;
2fa0b342
DHW
827}
828
829
1418c83b
SC
830
831
2fa0b342
DHW
832/* Open input files and attatch to output sections */
833static void
1418c83b
SC
834DEFUN(map_input_to_output_sections,(s, target, output_section_statement),
835 lang_statement_union_type *s AND
836 CONST char *target AND
837 lang_output_section_statement_type *output_section_statement)
2fa0b342
DHW
838{
839 for (; s != (lang_statement_union_type *)NULL ; s = s->next)
840 {
841 switch (s->header.type) {
842 case lang_wild_statement_enum:
843 wild(&s->wild_statement, s->wild_statement.section_name,
844 s->wild_statement.filename, target,
845 output_section_statement);
846
847 break;
848
849 case lang_output_section_statement_enum:
1418c83b 850 map_input_to_output_sections(s->output_section_statement.children.head,
2fa0b342
DHW
851 target,
852 &s->output_section_statement);
853 break;
854 case lang_output_statement_enum:
855 break;
856 case lang_target_statement_enum:
857 target = s->target_statement.target;
858 break;
2fa0b342
DHW
859 case lang_fill_statement_enum:
860 case lang_input_section_enum:
861 case lang_object_symbols_statement_enum:
862 case lang_data_statement_enum:
1418c83b
SC
863 case lang_assignment_statement_enum:
864 case lang_padding_statement_enum:
2fa0b342
DHW
865 break;
866 case lang_afile_asection_pair_statement_enum:
867 FAIL();
868 break;
2fa0b342
DHW
869 case lang_address_statement_enum:
870 /* Mark the specified section with the supplied address */
871 {
872 lang_output_section_statement_type *os =
873 lang_output_section_statement_lookup
874 (s->address_statement.section_name);
875 os->addr_tree = s->address_statement.address;
48491e2e
SC
876 if (os->bfd_section == (asection *)NULL) {
877 info("%P%F can't set the address of undefined section %s\n",
878 s->address_statement.section_name);
879 }
2fa0b342
DHW
880 }
881 break;
882 case lang_input_statement_enum:
883 /* A standard input statement, has no wildcards */
1418c83b 884 /* ldmain_open_file_read_symbol(&s->input_statement);*/
2fa0b342
DHW
885 break;
886 }
887 }
888}
889
890
891
892
893
894static void
1418c83b
SC
895DEFUN(print_output_section_statement,(output_section_statement),
896 lang_output_section_statement_type *output_section_statement)
2fa0b342
DHW
897{
898 asection *section = output_section_statement->bfd_section;
899 print_nl();
900 print_section(output_section_statement->name);
901
902 if (section) {
903 print_dot = section->vma;
904 print_space();
905 print_section("");
906 print_space();
907 print_address(section->vma);
908 print_space();
909 print_size(section->size);
910 print_space();
911 print_alignment(section->alignment_power);
912 print_space();
913#if 0
914 printf("%s flags", output_section_statement->region->name);
915 print_flags(stdout, &output_section_statement->flags);
916#endif
7bc4a0d7
SC
917 if (section->flags & SEC_LOAD)
918 printf("load ");
919 if (section->flags & SEC_ALLOC)
920 printf("alloc ");
921 if (section->flags & SEC_RELOC)
922 printf("reloc ");
923 if (section->flags & SEC_HAS_CONTENTS)
924 printf("contents ");
2fa0b342
DHW
925
926 }
927 else {
928 printf("No attached output section");
929 }
930 print_nl();
931 print_statement(output_section_statement->children.head,
932 output_section_statement);
933
934}
935
936static void
1418c83b
SC
937DEFUN(print_assignment,(assignment, output_section),
938 lang_assignment_statement_type *assignment AND
939 lang_output_section_statement_type *output_section)
2fa0b342
DHW
940{
941 etree_value_type result;
942 print_section("");
943 print_space();
944 print_section("");
945 print_space();
946 print_address(print_dot);
947 print_space();
948 result = exp_fold_tree(assignment->exp->assign.src,
949 output_section,
950 lang_final_phase_enum,
951 print_dot,
952 &print_dot);
953
954 if (result.valid) {
955 print_address(result.value);
956 }
957 else
1418c83b
SC
958 {
959 printf("*undefined*");
960 }
2fa0b342
DHW
961 print_space();
962 exp_print_tree(stdout, assignment->exp);
963 printf("\n");
964}
965
966static void
1418c83b
SC
967DEFUN(print_input_statement,(statm),
968 lang_input_statement_type *statm)
2fa0b342 969{
070aa819
SC
970 if (statm->filename != (char *)NULL) {
971 printf("LOAD %s\n",statm->filename);
972 }
2fa0b342
DHW
973}
974
1418c83b
SC
975static void
976DEFUN(print_symbol,(q),
977 asymbol *q)
2fa0b342
DHW
978{
979 print_section("");
980 printf(" ");
981 print_section("");
982 printf(" ");
983 print_address(outside_symbol_address(q));
984 printf(" %s", q->name ? q->name : " ");
985 print_nl();
986}
1418c83b 987
2fa0b342 988static void
1418c83b
SC
989DEFUN(print_input_section,(in),
990 lang_input_section_type *in)
2fa0b342
DHW
991{
992 asection *i = in->section;
993
994 if(i->size != 0) {
995 print_section("");
996 printf(" ");
997 print_section(i->name);
998 printf(" ");
999 if (i->output_section) {
1000 print_address(i->output_section->vma + i->output_offset);
1001 printf(" ");
1002 print_size(i->size);
1003 printf(" ");
1004 print_alignment(i->alignment_power);
1005 printf(" ");
1006 if (in->ifile) {
1418c83b 1007
2fa0b342 1008 bfd *abfd = in->ifile->the_bfd;
1418c83b
SC
1009 if (in->ifile->just_syms_flag == true) {
1010 printf("symbols only ");
1011 }
1012
2fa0b342
DHW
1013 printf(" %s ",abfd->xvec->name);
1014 if(abfd->my_archive != (bfd *)NULL) {
1015 printf("[%s]%s", abfd->my_archive->filename,
1016 abfd->filename);
1017 }
1018 else {
1019 printf("%s", abfd->filename);
1020 }
48491e2e 1021 printf("(overhead %d bytes)", (int)bfd_alloc_size(abfd));
2fa0b342
DHW
1022 print_nl();
1023
1024 /* Find all the symbols in this file defined in this section */
1418c83b
SC
1025 {
1026 asymbol **p;
1027 for (p = in->ifile->asymbols; *p; p++) {
1028 asymbol *q = *p;
2fa0b342 1029
1418c83b
SC
1030 if (bfd_get_section(q) == i && q->flags & BSF_GLOBAL) {
1031 print_symbol(q);
1032 }
2fa0b342
DHW
1033 }
1034 }
2fa0b342
DHW
1035 }
1036 else {
1037 print_nl();
1038 }
1039
1040
1041 print_dot = outside_section_address(i) + i->size;
1042 }
1043 else {
1044 printf("No output section allocated\n");
1045 }
1046 }
1047}
2fa0b342 1048
2fa0b342 1049static void
1418c83b
SC
1050DEFUN(print_fill_statement,(fill),
1051 lang_fill_statement_type *fill)
2fa0b342
DHW
1052{
1053 printf("FILL mask ");
1054 print_fill( fill->fill);
1055}
1056
1057static void
1418c83b
SC
1058DEFUN(print_data_statement,(data),
1059 lang_data_statement_type *data)
2fa0b342
DHW
1060{
1061/* bfd_vma value; */
1062 print_section("");
1063 print_space();
1064 print_section("");
1065 print_space();
65c552e3 1066/* ASSERT(print_dot == data->output_vma);*/
2fa0b342
DHW
1067
1068 print_address(data->output_vma);
1069 print_space();
1070 print_address(data->value);
1071 print_space();
1072 switch (data->type) {
1073 case BYTE :
1074 printf("BYTE ");
1075 print_dot += BYTE_SIZE;
1076 break;
1077 case SHORT:
1078 printf("SHORT ");
1079 print_dot += SHORT_SIZE;
1080 break;
1081 case LONG:
1082 printf("LONG ");
1083 print_dot += LONG_SIZE;
1084 break;
1085 }
1086
1087 exp_print_tree(stdout, data->exp);
1088
1089 printf("\n");
1090}
1091
1092
1093static void
1418c83b
SC
1094DEFUN(print_padding_statement,(s),
1095 lang_padding_statement_type *s)
2fa0b342
DHW
1096{
1097 print_section("");
1098 print_space();
1099 print_section("*fill*");
1100 print_space();
1101 print_address(s->output_offset + s->output_section->vma);
1102 print_space();
1103 print_size(s->size);
1104 print_space();
1105 print_fill(s->fill);
1106 print_nl();
1107}
1108
1418c83b
SC
1109static void
1110DEFUN(print_wild_statement,(w,os),
1111 lang_wild_statement_type *w AND
1112 lang_output_section_statement_type *os)
2fa0b342 1113{
48491e2e 1114 printf(" from ");
2fa0b342
DHW
1115 if (w->filename != (char *)NULL) {
1116 printf("%s",w->filename);
1117 }
1118 else {
1119 printf("*");
1120 }
1121 if (w->section_name != (char *)NULL) {
1122 printf("(%s)",w->section_name);
1123 }
1124 else {
1125 printf("(*)");
1126 }
1127 print_nl();
1128 print_statement(w->children.head, os);
1129
1130}
1131static void
1418c83b
SC
1132DEFUN(print_statement,(s, os),
1133 lang_statement_union_type *s AND
1134 lang_output_section_statement_type *os)
2fa0b342
DHW
1135{
1136 while (s) {
1137 switch (s->header.type) {
1138 case lang_wild_statement_enum:
1418c83b
SC
1139 print_wild_statement(&s->wild_statement, os);
1140 break;
2fa0b342 1141 default:
1418c83b 1142 printf("Fail with %d\n",s->header.type);
2fa0b342
DHW
1143 FAIL();
1144 break;
1418c83b
SC
1145 case lang_address_statement_enum:
1146 printf("address\n");
1147 break;
2fa0b342
DHW
1148 break;
1149 case lang_object_symbols_statement_enum:
1150 printf("object symbols\n");
1151 break;
1152 case lang_fill_statement_enum:
1153 print_fill_statement(&s->fill_statement);
1154 break;
1155 case lang_data_statement_enum:
1156 print_data_statement(&s->data_statement);
1157 break;
2fa0b342
DHW
1158 case lang_input_section_enum:
1159 print_input_section(&s->input_section);
1160 break;
1161 case lang_padding_statement_enum:
1162 print_padding_statement(&s->padding_statement);
1163 break;
1164 case lang_output_section_statement_enum:
1165 print_output_section_statement(&s->output_section_statement);
1166 break;
1167 case lang_assignment_statement_enum:
1168 print_assignment(&s->assignment_statement,
1418c83b 1169 os);
2fa0b342
DHW
1170 break;
1171
1172
1173 case lang_target_statement_enum:
1174 printf("TARGET(%s)\n", s->target_statement.target);
1175 break;
1176 case lang_output_statement_enum:
097879bc
SC
1177 printf("OUTPUT(%s %s)\n",
1178 s->output_statement.name,
1179 output_target);
2fa0b342
DHW
1180 break;
1181 case lang_input_statement_enum:
1182 print_input_statement(&s->input_statement);
1183 break;
1184 case lang_afile_asection_pair_statement_enum:
1185 FAIL();
1186 break;
1187 }
1188 s = s->next;
1189 }
1190}
1191
1192
1193static void
1418c83b 1194DEFUN_VOID(print_statements)
2fa0b342
DHW
1195{
1196 print_statement(statement_list.head,
1197 (lang_output_section_statement_type *)NULL);
1198}
1199
1200static bfd_vma
1418c83b
SC
1201DEFUN(insert_pad,(this_ptr, fill, power, output_section_statement, dot),
1202 lang_statement_union_type **this_ptr AND
1203 fill_type fill AND
1204 unsigned int power AND
1205 asection * output_section_statement AND
1206 bfd_vma dot)
2fa0b342
DHW
1207{
1208 /* Align this section first to the
1209 input sections requirement, then
1210 to the output section's requirement.
1211 If this alignment is > than any seen before,
1212 then record it too. Perform the alignment by
1213 inserting a magic 'padding' statement.
1214 */
1215
1216 unsigned int alignment_needed = align_power(dot, power) - dot;
1217
1218 if (alignment_needed != 0)
1219 {
1220 lang_statement_union_type *new =
1221 (lang_statement_union_type *)
3f8d46e7 1222 ldmalloc((bfd_size_type)(sizeof(lang_padding_statement_type)));
2fa0b342
DHW
1223 /* Link into existing chain */
1224 new->header.next = *this_ptr;
1225 *this_ptr = new;
1226 new->header.type = lang_padding_statement_enum;
1227 new->padding_statement.output_section = output_section_statement;
1228 new->padding_statement.output_offset =
1229 dot - output_section_statement->vma;
1230 new->padding_statement.fill = fill;
1231 new->padding_statement.size = alignment_needed;
1232 }
1233
1234
1235 /* Remember the most restrictive alignment */
1236 if (power > output_section_statement->alignment_power) {
1237 output_section_statement->alignment_power = power;
1238 }
1239 output_section_statement->size += alignment_needed;
1240 return alignment_needed + dot;
1241
1242}
1243
1418c83b 1244/* Work out how much this section will move the dot point */
2fa0b342 1245static bfd_vma
1418c83b
SC
1246DEFUN(size_input_section, (this_ptr, output_section_statement, fill, dot),
1247 lang_statement_union_type **this_ptr AND
1248 lang_output_section_statement_type*output_section_statement AND
1249 unsigned short fill AND
1250 bfd_vma dot)
2fa0b342
DHW
1251{
1252 lang_input_section_type *is = &((*this_ptr)->input_section);
1253 asection *i = is->section;
1418c83b
SC
1254
1255 if (is->ifile->just_syms_flag == false) {
ac004870
SC
1256 dot = insert_pad(this_ptr, fill, i->alignment_power,
1257 output_section_statement->bfd_section, dot);
2fa0b342 1258
7bc4a0d7
SC
1259 /* remember the largest size so we can malloc the largest area
1260 needed for the output stage. Only remember the size of sections
1261 which we will actually allocate */
1262 if (((i->flags &
1263 (SEC_HAS_CONTENTS | SEC_LOAD)) == (SEC_HAS_CONTENTS | SEC_LOAD))
1264 && (i->size > largest_section)) {
ac004870
SC
1265 largest_section = i->size;
1266 }
2fa0b342 1267
ac004870 1268 /* Remember where in the output section this input section goes */
2fa0b342 1269
ac004870
SC
1270 i->output_offset = dot - output_section_statement->bfd_section->vma;
1271
1272 /* Mark how big the output section must be to contain this now */
1273 dot += i->size;
1274 output_section_statement->bfd_section->size =
1275 dot - output_section_statement->bfd_section->vma;
1276 }
1277 else
1278 {
1279 i->output_offset = i->vma - output_section_statement->bfd_section->vma;
1280 }
2fa0b342
DHW
1281
1282 return dot ;
1283}
1284
1285
1286/* Work out the size of the output sections
1287 from the sizes of the input sections */
1288static bfd_vma
1418c83b
SC
1289DEFUN(lang_size_sections,(s, output_section_statement, prev, fill, dot),
1290 lang_statement_union_type *s AND
1291 lang_output_section_statement_type * output_section_statement AND
1292 lang_statement_union_type **prev AND
1293 unsigned short fill AND
1294 bfd_vma dot)
2fa0b342
DHW
1295{
1296 /* Size up the sections from their constituent parts */
1297 for (; s != (lang_statement_union_type *)NULL ; s = s->next)
1418c83b
SC
1298 {
1299 switch (s->header.type) {
1300 case lang_output_section_statement_enum:
1301 {
1302 bfd_vma after;
1303 lang_output_section_statement_type *os =
1304 &(s->output_section_statement);
1305 /* The start of a section */
2fa0b342 1306
1418c83b
SC
1307 if (os->addr_tree == (etree_type *)NULL) {
1308 /* No address specified for this section, get one
1309 from the region specification
1310 */
1311 if (os->region == (lang_memory_region_type *)NULL) {
2fa0b342 1312 os->region = lang_memory_region_lookup("*default*");
1418c83b
SC
1313 }
1314 dot = os->region->current;
2fa0b342 1315 }
1418c83b
SC
1316 else {
1317 etree_value_type r ;
1318 r = exp_fold_tree(os->addr_tree,
1319 (lang_output_section_statement_type *)NULL,
1320 lang_allocating_phase_enum,
1321 dot, &dot);
1322 if (r.valid == false) {
1323 info("%F%S: non constant address expression for section %s\n",
1324 os->name);
1325 }
1326 dot = r.value;
1327 }
1328 /* The section starts here */
1329 /* First, align to what the section needs */
2fa0b342 1330
1418c83b
SC
1331 dot = align_power(dot, os->bfd_section->alignment_power);
1332 os->bfd_section->vma = dot;
1333 os->bfd_section->output_offset = 0;
2fa0b342 1334
1418c83b
SC
1335 (void) lang_size_sections(os->children.head, os, &os->children.head,
1336 os->fill, dot);
1337 /* Ignore the size of the input sections, use the vma and size to */
1338 /* align against */
2fa0b342
DHW
1339
1340
1418c83b
SC
1341 after = ALIGN(os->bfd_section->vma +
1342 os->bfd_section->size,
1343 os->block_value) ;
2fa0b342
DHW
1344
1345
1418c83b
SC
1346 os->bfd_section->size = after - os->bfd_section->vma;
1347 dot = os->bfd_section->vma + os->bfd_section->size;
1348 os->processed = true;
2fa0b342 1349
1418c83b
SC
1350 /* Replace into region ? */
1351 if (os->addr_tree == (etree_type *)NULL
1352 && os->region !=(lang_memory_region_type*)NULL ) {
1353 os->region->current = dot;
1354 }
1355 }
2fa0b342 1356
1418c83b 1357 break;
2fa0b342 1358
1418c83b
SC
1359 case lang_data_statement_enum:
1360 {
1361 unsigned int size;
65c552e3 1362 s->data_statement.output_vma = dot - output_section_statement->bfd_section->vma;
1418c83b
SC
1363 s->data_statement.output_section =
1364 output_section_statement->bfd_section;
2fa0b342 1365
1418c83b
SC
1366 switch (s->data_statement.type) {
1367 case LONG:
1368 size = LONG_SIZE;
1369 break;
1370 case SHORT:
1371 size = SHORT_SIZE;
1372 break;
1373 case BYTE:
1374 size = BYTE_SIZE;
1375 break;
2fa0b342 1376
1418c83b
SC
1377 }
1378 dot += size;
1379 output_section_statement->bfd_section->size += size;
1380 }
1381 break;
2fa0b342 1382
1418c83b 1383 case lang_wild_statement_enum:
2fa0b342 1384
1418c83b 1385 dot = lang_size_sections(s->wild_statement.children.head,
2fa0b342
DHW
1386 output_section_statement,
1387 &s->wild_statement.children.head,
1388
1389 fill, dot);
1390
1418c83b 1391 break;
2fa0b342 1392
1418c83b
SC
1393 case lang_object_symbols_statement_enum:
1394 create_object_symbols = output_section_statement;
1395 break;
1396 case lang_output_statement_enum:
1397 case lang_target_statement_enum:
1398 break;
1399 case lang_input_section_enum:
1400 dot = size_input_section(prev,
2fa0b342
DHW
1401 output_section_statement,
1402 output_section_statement->fill, dot);
1418c83b
SC
1403 break;
1404 case lang_input_statement_enum:
1405 break;
1406 case lang_fill_statement_enum:
1407 fill = s->fill_statement.fill;
1408 break;
1409 case lang_assignment_statement_enum:
2fa0b342 1410 {
1418c83b
SC
1411 bfd_vma newdot = dot;
1412 exp_fold_tree(s->assignment_statement.exp,
1413 output_section_statement,
1414 lang_allocating_phase_enum,
1415 dot,
1416 &newdot);
1417
1418 if (newdot != dot)
1419 /* We've been moved ! so insert a pad */
1420 {
1421 lang_statement_union_type *new =
1422 (lang_statement_union_type *)
3f8d46e7 1423 ldmalloc((bfd_size_type)(sizeof(lang_padding_statement_type)));
1418c83b
SC
1424 /* Link into existing chain */
1425 new->header.next = *prev;
1426 *prev = new;
1427 new->header.type = lang_padding_statement_enum;
1428 new->padding_statement.output_section =
1429 output_section_statement->bfd_section;
1430 new->padding_statement.output_offset =
1431 dot - output_section_statement->bfd_section->vma;
1432 new->padding_statement.fill = fill;
1433 new->padding_statement.size = newdot - dot;
1434 output_section_statement->bfd_section->size +=
1435 new->padding_statement.size;
1436 dot = newdot;
1437 }
2fa0b342 1438 }
2fa0b342 1439
1418c83b
SC
1440 break;
1441 case lang_padding_statement_enum:
1442 FAIL();
1443 break;
1444 default:
1445 FAIL();
1446 break;
1447 case lang_address_statement_enum:
1448 break;
1449 }
1450 prev = &s->header.next;
2fa0b342 1451 }
2fa0b342
DHW
1452 return dot;
1453}
1454
1455
1456static bfd_vma
1418c83b
SC
1457DEFUN(lang_do_assignments,(s, output_section_statement, fill, dot),
1458 lang_statement_union_type *s AND
1459 lang_output_section_statement_type * output_section_statement AND
1460 unsigned short fill AND
1461 bfd_vma dot)
2fa0b342
DHW
1462{
1463
1464 for (; s != (lang_statement_union_type *)NULL ; s = s->next)
1465 {
1466 switch (s->header.type) {
1467 case lang_output_section_statement_enum:
1468 {
1469 lang_output_section_statement_type *os =
1470 &(s->output_section_statement);
1471 dot = os->bfd_section->vma;
1472 (void) lang_do_assignments(os->children.head, os, os->fill, dot);
1473 dot = os->bfd_section->vma + os->bfd_section->size;
1474 }
1475 break;
1476 case lang_wild_statement_enum:
1477
1478 dot = lang_do_assignments(s->wild_statement.children.head,
1479 output_section_statement,
1480 fill, dot);
1481
1482 break;
1483
1484 case lang_object_symbols_statement_enum:
1485 case lang_output_statement_enum:
1486 case lang_target_statement_enum:
1418c83b 1487#if 0
2fa0b342 1488 case lang_common_statement_enum:
1418c83b 1489#endif
2fa0b342
DHW
1490 break;
1491 case lang_data_statement_enum:
1492 {
1493 etree_value_type value ;
1494 value = exp_fold_tree(s->data_statement.exp,
1495 0, lang_final_phase_enum, dot, &dot);
1496 s->data_statement.value = value.value;
1497 if (value.valid == false) info("%F%P: Invalid data statement\n");
1498 }
1499 switch (s->data_statement.type) {
1500 case LONG:
1501 dot += LONG_SIZE;
1502 break;
1503 case SHORT:
1504 dot += SHORT_SIZE;
1505 break;
1506 case BYTE:
1507 dot += BYTE_SIZE;
1508 break;
1509 }
1510 break;
1511 case lang_input_section_enum:
1512 {
1513 asection *in = s->input_section.section;
1514 dot += in->size;
1515 }
1516 break;
1517
1518 case lang_input_statement_enum:
1519 break;
1520 case lang_fill_statement_enum:
1521 fill = s->fill_statement.fill;
1522 break;
1523 case lang_assignment_statement_enum:
1524 {
1525 exp_fold_tree(s->assignment_statement.exp,
1526 output_section_statement,
1527 lang_final_phase_enum,
1528 dot,
1529 &dot);
1530 }
1531
1532 break;
1533 case lang_padding_statement_enum:
1534 dot += s->padding_statement.size;
1535 break;
1536 default:
1537 FAIL();
1538 break;
1539 case lang_address_statement_enum:
1540 break;
1541 }
1542
1543 }
1544 return dot;
1545}
1546
1547
1548
1418c83b
SC
1549static void
1550DEFUN_VOID(lang_relocate_globals)
2fa0b342
DHW
1551{
1552
1553 /*
1418c83b
SC
1554 Each ldsym_type maintains a chain of pointers to asymbols which
1555 references the definition. Replace each pointer to the referenence
1556 with a pointer to only one place, preferably the definition. If
1557 the defintion isn't available then the common symbol, and if
1558 there isn't one of them then choose one reference.
1559 */
2fa0b342
DHW
1560
1561 FOR_EACH_LDSYM(lgs) {
1562 asymbol *it;
1563 if (lgs->sdefs_chain) {
1564 it = *(lgs->sdefs_chain);
1565 }
1566 else if (lgs->scoms_chain != (asymbol **)NULL) {
1567 it = *(lgs->scoms_chain);
1568 }
1569 else if (lgs->srefs_chain != (asymbol **)NULL) {
1570 it = *(lgs->srefs_chain);
1571 }
1572 else {
1418c83b
SC
1573 /* This can happen when the command line asked for a symbol to
1574 be -u */
1575 it = (asymbol *)NULL;
2fa0b342
DHW
1576 }
1577 if (it != (asymbol *)NULL)
1418c83b
SC
1578 {
1579 asymbol **ptr= lgs->srefs_chain;
2fa0b342 1580
1418c83b
SC
1581 while (ptr != (asymbol **)NULL) {
1582 asymbol *ref = *ptr;
1583 *ptr = it;
1584 ptr = (asymbol **)(ref->udata);
1585 }
2fa0b342 1586 }
2fa0b342
DHW
1587 }
1588}
1589
1590
1591
2fa0b342 1592static void
1418c83b 1593DEFUN_VOID(lang_finish)
2fa0b342
DHW
1594{
1595 ldsym_type *lgs;
1596
1597 if (entry_symbol == (char *)NULL) {
1598 /* No entry has been specified, look for start */
1599 entry_symbol = "start";
1600 }
1601 lgs = ldsym_get_soft(entry_symbol);
1602 if (lgs && lgs->sdefs_chain) {
1603 asymbol *sy = *(lgs->sdefs_chain);
1604 /* We can set the entry address*/
1605 bfd_set_start_address(output_bfd,
1606 outside_symbol_address(sy));
1607
1608 }
1609 else {
1610 /* Can't find anything reasonable,
1611 use the first address in the text section
1612 */
1613 asection *ts = bfd_get_section_by_name(output_bfd, ".text");
1614 if (ts) {
1615 bfd_set_start_address(output_bfd, ts->vma);
1616 }
1617 }
1618}
1619
1620/* By now we know the target architecture, and we may have an */
1621/* ldfile_output_machine_name */
1622static void
1418c83b 1623DEFUN_VOID(lang_check)
2fa0b342
DHW
1624{
1625 lang_statement_union_type *file;
7bc4a0d7 1626
3f8d46e7
JG
1627 bfd * input_bfd;
1628 unsigned long input_machine;
7bc4a0d7 1629 enum bfd_architecture input_architecture;
06850bea
SC
1630CONST char *out_arch;
1631 char *out_arch2;
2fa0b342 1632
7bc4a0d7 1633
2fa0b342
DHW
1634 for (file = file_chain.head;
1635 file != (lang_statement_union_type *)NULL;
1636 file=file->input_statement.next)
1418c83b 1637 {
06850bea
SC
1638 unsigned long ldfile_new_output_machine = 0;
1639 enum bfd_architecture ldfile_new_output_architecture = bfd_arch_unknown;
7bc4a0d7 1640
3f8d46e7 1641 input_bfd = file->input_statement.the_bfd;
7bc4a0d7 1642
3f8d46e7 1643 input_machine = bfd_get_machine(input_bfd);
7bc4a0d7
SC
1644 input_architecture = bfd_get_architecture(input_bfd);
1645
3f8d46e7
JG
1646
1647 /* Inspect the architecture and ensure we're linking like with like */
7bc4a0d7
SC
1648 if (!bfd_arch_compatible(input_bfd,
1649 output_bfd,
1650 &ldfile_new_output_architecture,
1651 &ldfile_new_output_machine))
1652 {
1653
1654 /* Result of bfd_printable_arch_mach is not guaranteed to stick
1655 around after next call, so we have to copy it. */
1656 out_arch = bfd_printable_arch_mach(ldfile_output_architecture,
1657 ldfile_output_machine);
1658 out_arch2 = ldmalloc (strlen (out_arch)+1);
1659 strcpy (out_arch2, out_arch);
1660
1661 info("%P: warning, %s architecture of input file `%B' incompatible with %s output\n",
1662 bfd_printable_arch_mach(input_architecture, input_machine),
1663 input_bfd,
1664 out_arch2);
1665 free (out_arch2);
1666
1667
1668 bfd_set_arch_mach(output_bfd,
1669 ldfile_new_output_architecture,
1670 ldfile_new_output_machine);
1671 }
2fa0b342 1672 }
7bc4a0d7 1673
2fa0b342
DHW
1674}
1675
1676
1677/*
1678 * run through all the global common symbols and tie them
b6316534
SC
1679 * to the output section requested.
1680 *
1681 As an experiment we do this 4 times, once for all the byte sizes,
1682 then all the two bytes, all the four bytes and then everything else
1683 */
2fa0b342
DHW
1684
1685static void
1418c83b 1686DEFUN_VOID(lang_common)
2fa0b342
DHW
1687{
1688 ldsym_type *lgs;
b6316534 1689 size_t power;
2fa0b342
DHW
1690 if (config.relocateable_output == false ||
1691 command_line.force_common_definition== true) {
b6316534
SC
1692 for (power = 1; (config.sort_common == true && power == 1) || (power <= 16); power <<=1) {
1693 for (lgs = symbol_head;
1694 lgs != (ldsym_type *)NULL;
1695 lgs=lgs->next)
1418c83b
SC
1696 {
1697 asymbol *com ;
1698 unsigned int power_of_two;
1699 size_t size;
1700 size_t align;
1701 if (lgs->scoms_chain != (asymbol **)NULL) {
1702 com = *(lgs->scoms_chain);
1703 size = com->value;
1704 switch (size) {
1705 case 0:
1706 case 1:
1707 align = 1;
1708 power_of_two = 0;
1709 break;
1710 case 2:
1711 power_of_two = 1;
1712 align = 2;
1713 break;
1714 case 3:
1715 case 4:
1716 power_of_two =2;
1717 align = 4;
1718 break;
1719 case 5:
1720 case 6:
1721 case 7:
1722 case 8:
1723 power_of_two = 3;
2fa0b342 1724 align = 8;
1418c83b
SC
1725 break;
1726 default:
1727 power_of_two = 4;
1728 align = 16;
1729 break;
2fa0b342 1730 }
b6316534
SC
1731 if (config.sort_common == false || align == power) {
1732 /* Change from a common symbol into a definition of
1733 a symbol */
1734 lgs->sdefs_chain = lgs->scoms_chain;
1735 lgs->scoms_chain = (asymbol **)NULL;
1736 commons_pending--;
1737 /* Point to the correct common section */
1738 com->section =
1739 ((lang_input_statement_type *)
1740 (com->the_bfd->usrdata))->common_section;
1741 /* Fix the size of the common section */
1742 com->section->size = ALIGN(com->section->size, align);
1743
1744 /* Remember if this is the biggest alignment ever seen */
1745 if (power_of_two > com->section->alignment_power) {
1746 com->section->alignment_power = power_of_two;
1747 }
2fa0b342 1748
b6316534
SC
1749 /* Symbol stops being common and starts being global, but
1750 we remember that it was common once. */
2fa0b342 1751
b6316534
SC
1752 com->flags = BSF_EXPORT | BSF_GLOBAL | BSF_OLD_COMMON;
1753 com->value = com->section->size;
1418c83b 1754
b6316534 1755 if (write_map)
1418c83b 1756 {
b6316534 1757 printf ("Allocating common %s: %x at %x %s\n",
1418c83b
SC
1758 lgs->name,
1759 (unsigned) size,
b6316534
SC
1760 (unsigned) com->value,
1761 com->the_bfd->filename);
1418c83b 1762 }
097879bc 1763
b6316534 1764 com->section->size += size;
1418c83b 1765
b6316534 1766 }
1418c83b 1767 }
b6316534 1768
2fa0b342 1769 }
b6316534 1770 }
2fa0b342 1771 }
1418c83b
SC
1772
1773
2fa0b342
DHW
1774}
1775
1776/*
1777run through the input files and ensure that every input
1778section has somewhere to go. If one is found without
1779a destination then create an input request and place it
1780into the statement tree.
1781*/
1782
1418c83b
SC
1783static void
1784DEFUN_VOID(lang_place_orphans)
2fa0b342
DHW
1785{
1786 lang_input_statement_type *file;
1787 for (file = (lang_input_statement_type*)file_chain.head;
1788 file != (lang_input_statement_type*)NULL;
1789 file = (lang_input_statement_type*)file->next) {
1790 asection *s;
1791 for (s = file->the_bfd->sections;
1792 s != (asection *)NULL;
1793 s = s->next) {
1794 if ( s->output_section == (asection *)NULL) {
1795 /* This section of the file is not attatched, root
1796 around for a sensible place for it to go */
1797
1798 if (file->common_section == s) {
1799 /* This is a lonely common section which must
1800 have come from an archive. We attatch to the
1801 section with the wildcard */
1418c83b
SC
1802 if (config.relocateable_output != true
1803 && command_line.force_common_definition == false) {
1804 if (default_common_section ==
1805 (lang_output_section_statement_type *)NULL) {
1806 info("%P: No [COMMON] command, defaulting to .bss\n");
1807
1808 default_common_section =
1809 lang_output_section_statement_lookup(".bss");
1810
1811 }
1812 wild_doit(&default_common_section->children, s,
1813 default_common_section, file);
1814 }
2fa0b342
DHW
1815 }
1816 else {
1817 lang_output_section_statement_type *os =
1818 lang_output_section_statement_lookup(s->name);
1819
1820 wild_doit(&os->children, s, os, file);
1821 }
1822 }
1823 }
2fa0b342
DHW
1824 }
1825}
1826
1827
2fa0b342 1828void
1418c83b 1829DEFUN(lang_set_flags,(ptr, flags),
7bc4a0d7 1830 int *ptr AND
1418c83b 1831 CONST char *flags)
2fa0b342
DHW
1832{
1833 boolean state = true;
7bc4a0d7 1834*ptr= 0;
2fa0b342 1835 while (*flags)
1418c83b
SC
1836 {
1837 if (*flags == '!') {
1838 state = false;
1839 flags++;
1840 }
1841 else state = true;
1842 switch (*flags) {
1843 case 'R':
7bc4a0d7 1844/* ptr->flag_read = state; */
1418c83b
SC
1845 break;
1846 case 'W':
7bc4a0d7 1847/* ptr->flag_write = state; */
1418c83b
SC
1848 break;
1849 case 'X':
7bc4a0d7 1850/* ptr->flag_executable= state;*/
1418c83b
SC
1851 break;
1852 case 'L':
b6316534 1853 case 'I':
7bc4a0d7 1854/* ptr->flag_loadable= state;*/
1418c83b
SC
1855 break;
1856 default:
1857 info("%P%F illegal syntax in flags\n");
1858 break;
1859 }
2fa0b342
DHW
1860 flags++;
1861 }
2fa0b342
DHW
1862}
1863
1864
1865
1866void
1418c83b
SC
1867DEFUN(lang_for_each_file,(func),
1868 PROTO(void, (*func),(lang_input_statement_type *)))
2fa0b342
DHW
1869{
1870 lang_input_statement_type *f;
1871 for (f = (lang_input_statement_type *)file_chain.head;
1872 f != (lang_input_statement_type *)NULL;
1873 f = (lang_input_statement_type *)f->next)
1418c83b
SC
1874 {
1875 func(f);
1876 }
2fa0b342
DHW
1877}
1878
1879
1880void
1418c83b
SC
1881DEFUN(lang_for_each_input_section, (func),
1882 PROTO(void ,(*func),(bfd *ab, asection*as)))
2fa0b342
DHW
1883{
1884 lang_input_statement_type *f;
1885 for (f = (lang_input_statement_type *)file_chain.head;
1886 f != (lang_input_statement_type *)NULL;
1887 f = (lang_input_statement_type *)f->next)
1888 {
1889 asection *s;
1890 for (s = f->the_bfd->sections;
1891 s != (asection *)NULL;
1892 s = s->next) {
1893 func(f->the_bfd, s);
1894 }
1895 }
1896}
1897
1898
1899
1900void
1418c83b
SC
1901DEFUN(ldlang_add_file,(entry),
1902 lang_input_statement_type *entry)
2fa0b342 1903{
1418c83b 1904
2fa0b342
DHW
1905 lang_statement_append(&file_chain,
1906 (lang_statement_union_type *)entry,
1907 &entry->next);
1908}
1909
1910
1911
1912void
1418c83b
SC
1913DEFUN(lang_add_output,(name),
1914 CONST char *name)
2fa0b342
DHW
1915{
1916 lang_output_statement_type *new = new_stat(lang_output_statement,
1917 stat_ptr);
1918 new->name = name;
1919 had_output_filename = true;
1920}
1921
1922
1923static lang_output_section_statement_type *current_section;
1924
1925void
1418c83b
SC
1926DEFUN(lang_enter_output_section_statement,
1927 (output_section_statement_name,
1928 address_exp,
7bc4a0d7 1929 flags,
1418c83b
SC
1930 block_value),
1931 char *output_section_statement_name AND
1932 etree_type *address_exp AND
7bc4a0d7 1933 int flags AND
1418c83b 1934 bfd_vma block_value)
2fa0b342
DHW
1935{
1936 lang_output_section_statement_type *os;
1937 current_section =
1938 os =
1939 lang_output_section_statement_lookup(output_section_statement_name);
1940
1941
1942 /* Add this statement to tree */
1943 /* add_statement(lang_output_section_statement_enum,
1944 output_section_statement);*/
1945 /* Make next things chain into subchain of this */
1946
1947 if (os->addr_tree ==
1948 (etree_type *)NULL) {
1949 os->addr_tree =
1950 address_exp;
1951 }
7bc4a0d7 1952 os->flags = flags;
2fa0b342
DHW
1953 os->block_value = block_value;
1954 stat_ptr = & os->children;
1955
1956}
1957
1958
1959void
1418c83b 1960DEFUN_VOID(lang_final)
2fa0b342
DHW
1961{
1962 if (had_output_filename == false) {
e89432c7
SC
1963 extern CONST char *output_filename;
1964 lang_add_output(output_filename);
2fa0b342 1965 }
2fa0b342
DHW
1966}
1967
1968
1969
1970
1971
1418c83b
SC
1972asymbol *
1973DEFUN(create_symbol,(name, flags, section),
1974 CONST char *name AND
1975 flagword flags AND
1976 asection *section)
2fa0b342
DHW
1977{
1978 extern lang_input_statement_type *script_file;
3f8d46e7 1979 asymbol **def_ptr = (asymbol **)ldmalloc((bfd_size_type)(sizeof(asymbol **)));
2fa0b342
DHW
1980 /* Add this definition to script file */
1981 asymbol *def = (asymbol *)bfd_make_empty_symbol(script_file->the_bfd);
1418c83b 1982 def->name = buystring(name);
2fa0b342
DHW
1983 def->udata = 0;
1984 def->flags = flags;
1985 def->section = section;
1986
1987 *def_ptr = def;
1988 Q_enter_global_ref(def_ptr);
1989 return def;
1990}
1991
1992
1993void
1418c83b
SC
1994DEFUN_VOID(lang_process)
1995{
1996 if (had_script == false) {
1997 parse_line(ldemul_get_script());
1998 }
1999 lang_reasonable_defaults();
2000 current_target = default_target;
2001
2002 lang_for_each_statement(ldlang_open_output); /* Open the output file */
2003 /* For each output section statement, create a section in the output
2004 file */
2005 lang_create_output_section_statements();
2006
2007 /* Create a dummy bfd for the script */
2008 lang_init_script_file();
2009
2010 /* Add to the hash table all undefineds on the command line */
2011 lang_place_undefineds();
2012
2013 /* Create a bfd for each input file */
2014 current_target = default_target;
2015 lang_for_each_statement(open_input_bfds);
2016
a0ad3035 2017 common_section.userdata = (PTR)&common_section_userdata;
1418c83b
SC
2018
2019 /* Run through the contours of the script and attatch input sections
2020 to the correct output sections
2021 */
2022 map_input_to_output_sections(statement_list.head, (char *)NULL,
2023 ( lang_output_section_statement_type *)NULL);
2024
2025 /* Find any sections not attatched explicitly and handle them */
2026 lang_place_orphans();
2027
2028 /* Size up the common data */
2029 lang_common();
2030
2031 ldemul_before_allocation();
2032
2033 /* Size up the sections */
2034 lang_size_sections(statement_list.head,
2035 (lang_output_section_statement_type *)NULL,
2036 &(statement_list.head), 0, (bfd_vma)0);
2037
2038 /* See if anything special should be done now we know how big
2039 everything is */
2040 ldemul_after_allocation();
2041
2042 /* Do all the assignments, now that we know the final restingplaces
2043 of all the symbols */
2044
2045 lang_do_assignments(statement_list.head,
2046 (lang_output_section_statement_type *)NULL,
2047 0, (bfd_vma)0);
2048
2049 /* Make sure that we're not mixing architectures */
2050
2051 lang_check();
2052
2053 /* Move the global symbols around */
2054 lang_relocate_globals();
2055
2056 /* Final stuffs */
2057 lang_finish();
2fa0b342
DHW
2058}
2059
2060
2061/* EXPORTED TO YACC */
1418c83b 2062
2fa0b342 2063void
1418c83b
SC
2064DEFUN(lang_add_wild,(section_name, filename),
2065 CONST char *CONST section_name AND
2066 CONST char *CONST filename)
2067{
2068 lang_wild_statement_type *new = new_stat(lang_wild_statement,
2069 stat_ptr);
2070
2071 if (section_name != (char *)NULL && strcmp(section_name,"COMMON") == 0)
2072 {
2073 placed_commons = true;
2074 }
2075 if (filename != (char *)NULL) {
2076 lang_has_input_file = true;
2077 }
2078 new->section_name = section_name;
2079 new->filename = filename;
2080 lang_list_init(&new->children);
2081}
2082void
2083DEFUN(lang_section_start,(name, address),
2084 CONST char *name AND
2085 etree_type *address)
2fa0b342
DHW
2086{
2087 lang_address_statement_type *ad =new_stat(lang_address_statement, stat_ptr);
2088 ad->section_name = name;
2089 ad->address = address;
2090}
1418c83b
SC
2091
2092void
2093DEFUN(lang_add_entry,(name),
2094 CONST char *name)
2fa0b342
DHW
2095{
2096 entry_symbol = name;
2097}
2098
2099void
1418c83b
SC
2100DEFUN(lang_add_target,(name),
2101 CONST char *name)
2fa0b342
DHW
2102{
2103 lang_target_statement_type *new = new_stat(lang_target_statement,
2104 stat_ptr);
2105 new->target = name;
2106
2107}
2fa0b342 2108
1418c83b
SC
2109
2110
2fa0b342
DHW
2111
2112void
1418c83b
SC
2113DEFUN(lang_add_map,(name),
2114 CONST char *name)
2fa0b342
DHW
2115{
2116 while (*name) {
2117 switch (*name) {
2118 case 'F':
2119 map_option_f = true;
2120 break;
2121 }
2122 name++;
2123 }
2124}
2125
1418c83b
SC
2126void
2127DEFUN(lang_add_fill,(exp),
2128 int exp)
2fa0b342
DHW
2129{
2130 lang_fill_statement_type *new = new_stat(lang_fill_statement,
2131 stat_ptr);
2132 new->fill = exp;
2133}
2134
1418c83b
SC
2135void
2136DEFUN(lang_add_data,(type, exp),
2137 int type AND
2138 union etree_union *exp)
2fa0b342
DHW
2139{
2140
2141 lang_data_statement_type *new = new_stat(lang_data_statement,
2142 stat_ptr);
2143 new->exp = exp;
2144 new->type = type;
2145
2146}
2147void
1418c83b
SC
2148DEFUN(lang_add_assignment,(exp),
2149 etree_type *exp)
2fa0b342
DHW
2150{
2151 lang_assignment_statement_type *new = new_stat(lang_assignment_statement,
2152 stat_ptr);
2153 new->exp = exp;
2154}
2155
2156void
1418c83b
SC
2157DEFUN(lang_add_attribute,(attribute),
2158 enum statement_enum attribute)
2fa0b342
DHW
2159{
2160 new_statement(attribute, sizeof(lang_statement_union_type),stat_ptr);
2161}
2162
2163
2164
2165void
1418c83b
SC
2166DEFUN(lang_startup,(name),
2167 CONST char *name)
2fa0b342
DHW
2168{
2169 if (startup_file != (char *)NULL) {
2170 info("%P%FMultiple STARTUP files\n");
2171 }
2172 first_file->filename = name;
2173 first_file->local_sym_name = name;
2174
2175 startup_file= name;
2176}
2177void
1418c83b
SC
2178DEFUN(lang_float,(maybe),
2179 boolean maybe)
2fa0b342
DHW
2180{
2181 lang_float_flag = maybe;
2182}
2183
2184void
1418c83b
SC
2185DEFUN(lang_leave_output_section_statement,(fill, memspec),
2186 bfd_vma fill AND
2187 CONST char *memspec)
2fa0b342
DHW
2188{
2189 current_section->fill = fill;
2190 current_section->region = lang_memory_region_lookup(memspec);
2191 stat_ptr = &statement_list;
2192}
9f32f7c2
SC
2193/*
2194 Create an absolute symbol with the given name with the value of the
2195 address of first byte of the section named.
2fa0b342 2196
9f32f7c2
SC
2197 If the symbol already exists, then do nothing.
2198*/
8cb5eb31 2199void
1418c83b
SC
2200DEFUN(lang_abs_symbol_at_beginning_of,(section, name),
2201 CONST char *section AND
2202 CONST char *name)
8cb5eb31 2203{
c660714f 2204 if (ldsym_undefined(name)) {
9f32f7c2
SC
2205 extern bfd *output_bfd;
2206 extern asymbol *create_symbol();
2207 asection *s = bfd_get_section_by_name(output_bfd, section);
2208 asymbol *def = create_symbol(name,
2209 BSF_GLOBAL | BSF_EXPORT |
2210 BSF_ABSOLUTE,
2211 (asection *)NULL);
2212 if (s != (asection *)NULL) {
2213 def->value = s->vma;
2214 }
2215 else {
2216 def->value = 0;
2217 }
8cb5eb31
SC
2218 }
2219}
2220
9f32f7c2
SC
2221/*
2222 Create an absolute symbol with the given name with the value of the
2223 address of the first byte after the end of the section named.
2224
2225 If the symbol already exists, then do nothing.
2226*/
2fa0b342 2227void
1418c83b
SC
2228DEFUN(lang_abs_symbol_at_end_of,(section, name),
2229 CONST char *section AND
2230 CONST char *name)
2fa0b342 2231{
c660714f 2232 if (ldsym_undefined(name)){
9f32f7c2
SC
2233 extern bfd *output_bfd;
2234 extern asymbol *create_symbol();
2235 asection *s = bfd_get_section_by_name(output_bfd, section);
2236 /* Add a symbol called _end */
2237 asymbol *def = create_symbol(name,
2238 BSF_GLOBAL | BSF_EXPORT |
2239 BSF_ABSOLUTE,
2240 (asection *)NULL);
2241 if (s != (asection *)NULL) {
2242 def->value = s->vma + s->size;
2243 }
2244 else {
2245 def->value = 0;
2246 }
2fa0b342
DHW
2247 }
2248}
2249
2250void
1418c83b
SC
2251DEFUN(lang_statement_append,(list, element, field),
2252 lang_statement_list_type *list AND
2253 lang_statement_union_type *element AND
2254 lang_statement_union_type **field)
2fa0b342
DHW
2255{
2256 *(list->tail) = element;
2257 list->tail = field;
2258}
2259
097879bc
SC
2260/* Set the output format type */
2261void
2262DEFUN(lang_add_output_format,(format),
2263CONST char *format)
2264{
2265 output_target = format;
2266}
a37cc0c0 2267
This page took 0.125956 seconds and 4 git commands to generate.