include/
[deliverable/binutils-gdb.git] / bfd / ieee.c
CommitLineData
252b5132 1/* BFD back-end for ieee-695 objects.
7898deda 2 Copyright 1990, 1991, 1992, 1993, 1994, 1995, 1996, 1997, 1998, 1999,
72adc230 3 2000, 2001, 2002, 2003, 2004
252b5132
RH
4 Free Software Foundation, Inc.
5
6 Written by Steve Chamberlain of Cygnus Support.
7
ca09e32b 8 This file is part of BFD, the Binary File Descriptor library.
252b5132 9
ca09e32b
NC
10 This program is free software; you can redistribute it and/or modify
11 it under the terms of the GNU General Public License as published by
12 the Free Software Foundation; either version 2 of the License, or
13 (at your option) any later version.
252b5132 14
ca09e32b
NC
15 This program is distributed in the hope that it will be useful,
16 but WITHOUT ANY WARRANTY; without even the implied warranty of
17 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 GNU General Public License for more details.
252b5132 19
ca09e32b
NC
20 You should have received a copy of the GNU General Public License
21 along with this program; if not, write to the Free Software
22 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */
252b5132
RH
23
24#define KEEPMINUSPCININST 0
25
26/* IEEE 695 format is a stream of records, which we parse using a simple one-
27 token (which is one byte in this lexicon) lookahead recursive decent
28 parser. */
29
30#include "bfd.h"
31#include "sysdep.h"
32#include "libbfd.h"
33#include "ieee.h"
34#include "libieee.h"
3882b010 35#include "safe-ctype.h"
252b5132 36
47fda0d3
AM
37struct output_buffer_struct
38{
39 unsigned char *ptrp;
40 int buffer;
41};
42
b34976b6
AM
43static bfd_boolean ieee_write_byte
44 PARAMS ((bfd *, int));
45static bfd_boolean ieee_write_2bytes
46 PARAMS ((bfd *, int));
47static bfd_boolean ieee_write_int
48 PARAMS ((bfd *, bfd_vma));
49static bfd_boolean ieee_write_id
50 PARAMS ((bfd *, const char *));
51static unsigned short read_2bytes
52 PARAMS ((common_header_type *));
53static void bfd_get_string
54 PARAMS ((common_header_type *, char *, size_t));
55static char *read_id
56 PARAMS ((common_header_type *));
57static bfd_boolean ieee_write_expression
58 PARAMS ((bfd *, bfd_vma, asymbol *, bfd_boolean, unsigned int));
59static void ieee_write_int5
60 PARAMS ((bfd_byte *, bfd_vma));
61static bfd_boolean ieee_write_int5_out
62 PARAMS ((bfd *, bfd_vma));
63static bfd_boolean parse_int
64 PARAMS ((common_header_type *, bfd_vma *));
65static int parse_i
66 PARAMS ((common_header_type *, bfd_boolean *));
67static bfd_vma must_parse_int
68 PARAMS ((common_header_type *));
47fda0d3
AM
69static void parse_expression
70 PARAMS ((ieee_data_type *, bfd_vma *, ieee_symbol_index_type *,
b34976b6
AM
71 bfd_boolean *, unsigned int *, asection **));
72static file_ptr ieee_part_after
73 PARAMS ((ieee_data_type *, file_ptr));
47fda0d3
AM
74static ieee_symbol_type *get_symbol
75 PARAMS ((bfd *, ieee_data_type *, ieee_symbol_type *, unsigned int *,
dc810e39 76 ieee_symbol_type ***, unsigned int *, int));
b34976b6
AM
77static bfd_boolean ieee_slurp_external_symbols
78 PARAMS ((bfd *));
79static bfd_boolean ieee_slurp_symbol_table
80 PARAMS ((bfd *));
81static long ieee_get_symtab_upper_bound
82 PARAMS ((bfd *));
6cee3f79 83static long ieee_canonicalize_symtab
b34976b6 84 PARAMS ((bfd *, asymbol **));
47fda0d3
AM
85static asection *get_section_entry
86 PARAMS ((bfd *, ieee_data_type *i, unsigned int));
b34976b6
AM
87static void ieee_slurp_sections
88 PARAMS ((bfd *));
89static bfd_boolean ieee_slurp_debug
90 PARAMS ((bfd *));
91const bfd_target *ieee_archive_p
92 PARAMS ((bfd *));
93const bfd_target *ieee_object_p
94 PARAMS ((bfd *));
95static void ieee_get_symbol_info
96 PARAMS ((bfd *, asymbol *, symbol_info *));
47fda0d3
AM
97static void ieee_print_symbol
98 PARAMS ((bfd *, PTR, asymbol *, bfd_print_symbol_type));
b34976b6 99static bfd_boolean do_one
47fda0d3
AM
100 PARAMS ((ieee_data_type *, ieee_per_section_type *, unsigned char *,
101 asection *, int));
b34976b6
AM
102static bfd_boolean ieee_slurp_section_data
103 PARAMS ((bfd *));
104static bfd_boolean ieee_new_section_hook
105 PARAMS ((bfd *, asection *));
106static long ieee_get_reloc_upper_bound
107 PARAMS ((bfd *, sec_ptr));
108static bfd_boolean ieee_get_section_contents
47fda0d3
AM
109 PARAMS ((bfd *, sec_ptr, PTR, file_ptr, bfd_size_type));
110static long ieee_canonicalize_reloc
111 PARAMS ((bfd *, sec_ptr, arelent **, asymbol **));
b34976b6
AM
112static int comp
113 PARAMS ((const PTR, const PTR));
114static bfd_boolean ieee_write_section_part
115 PARAMS ((bfd *));
116static bfd_boolean do_with_relocs
117 PARAMS ((bfd *, asection *));
118static bfd_boolean do_as_repeat
119 PARAMS ((bfd *, asection *));
120static bfd_boolean do_without_relocs
121 PARAMS ((bfd *, asection *));
122static bfd_boolean ieee_mkobject
123 PARAMS ((bfd *));
124static void fill
125 PARAMS ((void));
126static void flush
127 PARAMS ((void));
128static void write_int
129 PARAMS ((int));
130static void copy_id
131 PARAMS ((void));
132static void copy_expression
133 PARAMS ((void));
134static void fill_int
135 PARAMS ((struct output_buffer_struct *));
136static void drop_int
137 PARAMS ((struct output_buffer_struct *));
138static void copy_int
139 PARAMS ((void));
140static void f1_record
141 PARAMS ((void));
142static void f0_record
143 PARAMS ((void));
144static void copy_till_end
145 PARAMS ((void));
146static void f2_record
147 PARAMS ((void));
148static void f8_record
149 PARAMS ((void));
150static void e2_record
151 PARAMS ((void));
152static void block
153 PARAMS ((void));
154static void relocate_debug
155 PARAMS ((bfd *, bfd *));
156static bfd_boolean ieee_write_debug_part
157 PARAMS ((bfd *));
158static bfd_boolean ieee_write_data_part
159 PARAMS ((bfd *));
160static bfd_boolean init_for_output
161 PARAMS ((bfd *));
162static bfd_boolean ieee_set_section_contents
0f867abe 163 PARAMS ((bfd *, sec_ptr, const PTR, file_ptr, bfd_size_type));
b34976b6
AM
164static bfd_boolean ieee_write_external_part
165 PARAMS ((bfd *));
166static bfd_boolean ieee_write_me_part
167 PARAMS ((bfd *));
168static bfd_boolean ieee_write_processor
169 PARAMS ((bfd *));
170static bfd_boolean ieee_write_object_contents
171 PARAMS ((bfd *));
172static asymbol *ieee_make_empty_symbol
173 PARAMS ((bfd *));
174static bfd *ieee_openr_next_archived_file
175 PARAMS ((bfd *, bfd *));
176static bfd_boolean ieee_find_nearest_line
47fda0d3
AM
177 PARAMS ((bfd *, asection *, asymbol **, bfd_vma, const char **,
178 const char **, unsigned int *));
b34976b6
AM
179static int ieee_generic_stat_arch_elt
180 PARAMS ((bfd *, struct stat *));
181static int ieee_sizeof_headers
182 PARAMS ((bfd *, bfd_boolean));
252b5132
RH
183
184/* Functions for writing to ieee files in the strange way that the
185 standard requires. */
186
b34976b6 187static bfd_boolean
252b5132
RH
188ieee_write_byte (abfd, barg)
189 bfd *abfd;
190 int barg;
191{
192 bfd_byte byte;
193
194 byte = barg;
dc810e39 195 if (bfd_bwrite ((PTR) &byte, (bfd_size_type) 1, abfd) != 1)
b34976b6
AM
196 return FALSE;
197 return TRUE;
252b5132
RH
198}
199
b34976b6 200static bfd_boolean
252b5132
RH
201ieee_write_2bytes (abfd, bytes)
202 bfd *abfd;
203 int bytes;
204{
205 bfd_byte buffer[2];
206
207 buffer[0] = bytes >> 8;
208 buffer[1] = bytes & 0xff;
dc810e39 209 if (bfd_bwrite ((PTR) buffer, (bfd_size_type) 2, abfd) != 2)
b34976b6
AM
210 return FALSE;
211 return TRUE;
252b5132
RH
212}
213
b34976b6 214static bfd_boolean
252b5132
RH
215ieee_write_int (abfd, value)
216 bfd *abfd;
217 bfd_vma value;
218{
219 if (value <= 127)
220 {
221 if (! ieee_write_byte (abfd, (bfd_byte) value))
b34976b6 222 return FALSE;
252b5132
RH
223 }
224 else
225 {
226 unsigned int length;
227
49ae03bf
NC
228 /* How many significant bytes ? */
229 /* FIXME FOR LONGER INTS. */
252b5132
RH
230 if (value & 0xff000000)
231 length = 4;
232 else if (value & 0x00ff0000)
233 length = 3;
234 else if (value & 0x0000ff00)
235 length = 2;
236 else
237 length = 1;
238
239 if (! ieee_write_byte (abfd,
240 (bfd_byte) ((int) ieee_number_repeat_start_enum
241 + length)))
b34976b6 242 return FALSE;
252b5132
RH
243 switch (length)
244 {
245 case 4:
246 if (! ieee_write_byte (abfd, (bfd_byte) (value >> 24)))
b34976b6 247 return FALSE;
252b5132
RH
248 /* Fall through. */
249 case 3:
250 if (! ieee_write_byte (abfd, (bfd_byte) (value >> 16)))
b34976b6 251 return FALSE;
252b5132
RH
252 /* Fall through. */
253 case 2:
254 if (! ieee_write_byte (abfd, (bfd_byte) (value >> 8)))
b34976b6 255 return FALSE;
252b5132
RH
256 /* Fall through. */
257 case 1:
258 if (! ieee_write_byte (abfd, (bfd_byte) (value)))
b34976b6 259 return FALSE;
252b5132
RH
260 }
261 }
262
b34976b6 263 return TRUE;
252b5132
RH
264}
265
b34976b6 266static bfd_boolean
252b5132
RH
267ieee_write_id (abfd, id)
268 bfd *abfd;
269 const char *id;
270{
271 size_t length = strlen (id);
272
273 if (length <= 127)
274 {
275 if (! ieee_write_byte (abfd, (bfd_byte) length))
b34976b6 276 return FALSE;
252b5132
RH
277 }
278 else if (length < 255)
279 {
280 if (! ieee_write_byte (abfd, ieee_extension_length_1_enum)
281 || ! ieee_write_byte (abfd, (bfd_byte) length))
b34976b6 282 return FALSE;
252b5132
RH
283 }
284 else if (length < 65535)
285 {
286 if (! ieee_write_byte (abfd, ieee_extension_length_2_enum)
287 || ! ieee_write_2bytes (abfd, (int) length))
b34976b6 288 return FALSE;
252b5132
RH
289 }
290 else
291 {
292 (*_bfd_error_handler)
293 (_("%s: string too long (%d chars, max 65535)"),
294 bfd_get_filename (abfd), length);
295 bfd_set_error (bfd_error_invalid_operation);
b34976b6 296 return FALSE;
252b5132
RH
297 }
298
dc810e39 299 if (bfd_bwrite ((PTR) id, (bfd_size_type) length, abfd) != length)
b34976b6
AM
300 return FALSE;
301 return TRUE;
252b5132
RH
302}
303\f
49ae03bf
NC
304/* Functions for reading from ieee files in the strange way that the
305 standard requires. */
252b5132
RH
306
307#define this_byte(ieee) *((ieee)->input_p)
308#define next_byte(ieee) ((ieee)->input_p++)
309#define this_byte_and_next(ieee) (*((ieee)->input_p++))
310
311static unsigned short
312read_2bytes (ieee)
313 common_header_type *ieee;
314{
315 unsigned char c1 = this_byte_and_next (ieee);
316 unsigned char c2 = this_byte_and_next (ieee);
49ae03bf 317
252b5132
RH
318 return (c1 << 8) | c2;
319}
320
321static void
322bfd_get_string (ieee, string, length)
323 common_header_type *ieee;
324 char *string;
325 size_t length;
326{
327 size_t i;
49ae03bf 328
252b5132 329 for (i = 0; i < length; i++)
49ae03bf 330 string[i] = this_byte_and_next (ieee);
252b5132
RH
331}
332
333static char *
334read_id (ieee)
335 common_header_type *ieee;
336{
337 size_t length;
338 char *string;
49ae03bf 339
252b5132
RH
340 length = this_byte_and_next (ieee);
341 if (length <= 0x7f)
342 {
49ae03bf 343 /* Simple string of length 0 to 127. */
252b5132
RH
344 }
345 else if (length == 0xde)
346 {
49ae03bf 347 /* Length is next byte, allowing 0..255. */
252b5132
RH
348 length = this_byte_and_next (ieee);
349 }
350 else if (length == 0xdf)
351 {
49ae03bf 352 /* Length is next two bytes, allowing 0..65535. */
252b5132
RH
353 length = this_byte_and_next (ieee);
354 length = (length * 256) + this_byte_and_next (ieee);
355 }
49ae03bf
NC
356
357 /* Buy memory and read string. */
dc810e39 358 string = bfd_alloc (ieee->abfd, (bfd_size_type) length + 1);
252b5132
RH
359 if (!string)
360 return NULL;
361 bfd_get_string (ieee, string, length);
362 string[length] = 0;
363 return string;
364}
365
b34976b6 366static bfd_boolean
252b5132
RH
367ieee_write_expression (abfd, value, symbol, pcrel, index)
368 bfd *abfd;
369 bfd_vma value;
370 asymbol *symbol;
b34976b6 371 bfd_boolean pcrel;
252b5132
RH
372 unsigned int index;
373{
374 unsigned int term_count = 0;
375
376 if (value != 0)
377 {
378 if (! ieee_write_int (abfd, value))
b34976b6 379 return FALSE;
252b5132
RH
380 term_count++;
381 }
382
49ae03bf
NC
383 /* Badly formatted binaries can have a missing symbol,
384 so test here to prevent a seg fault. */
385 if (symbol != NULL)
252b5132 386 {
49ae03bf
NC
387 if (bfd_is_com_section (symbol->section)
388 || bfd_is_und_section (symbol->section))
252b5132 389 {
49ae03bf
NC
390 /* Def of a common symbol. */
391 if (! ieee_write_byte (abfd, ieee_variable_X_enum)
252b5132 392 || ! ieee_write_int (abfd, symbol->value))
b34976b6 393 return FALSE;
49ae03bf 394 term_count ++;
252b5132 395 }
49ae03bf 396 else if (! bfd_is_abs_section (symbol->section))
252b5132 397 {
49ae03bf
NC
398 /* Ref to defined symbol - */
399
400 if (symbol->flags & BSF_GLOBAL)
252b5132 401 {
49ae03bf
NC
402 if (! ieee_write_byte (abfd, ieee_variable_I_enum)
403 || ! ieee_write_int (abfd, symbol->value))
b34976b6 404 return FALSE;
252b5132
RH
405 term_count++;
406 }
49ae03bf
NC
407 else if (symbol->flags & (BSF_LOCAL | BSF_SECTION_SYM))
408 {
409 /* This is a reference to a defined local symbol. We can
410 easily do a local as a section+offset. */
411 if (! ieee_write_byte (abfd, ieee_variable_R_enum)
412 || ! ieee_write_byte (abfd,
413 (bfd_byte) (symbol->section->index
414 + IEEE_SECTION_NUMBER_BASE)))
415 return FALSE;
416
417 term_count++;
418 if (symbol->value != 0)
419 {
420 if (! ieee_write_int (abfd, symbol->value))
421 return FALSE;
422 term_count++;
423 }
424 }
425 else
426 {
427 (*_bfd_error_handler)
428 (_("%s: unrecognized symbol `%s' flags 0x%x"),
429 bfd_get_filename (abfd), bfd_asymbol_name (symbol),
430 symbol->flags);
431 bfd_set_error (bfd_error_invalid_operation);
432 return FALSE;
433 }
252b5132
RH
434 }
435 }
436
437 if (pcrel)
438 {
49ae03bf 439 /* Subtract the pc from here by asking for PC of this section. */
252b5132
RH
440 if (! ieee_write_byte (abfd, ieee_variable_P_enum)
441 || ! ieee_write_byte (abfd,
442 (bfd_byte) (index + IEEE_SECTION_NUMBER_BASE))
443 || ! ieee_write_byte (abfd, ieee_function_minus_enum))
b34976b6 444 return FALSE;
252b5132
RH
445 }
446
447 /* Handle the degenerate case of a 0 address. */
448 if (term_count == 0)
49ae03bf
NC
449 if (! ieee_write_int (abfd, (bfd_vma) 0))
450 return FALSE;
252b5132
RH
451
452 while (term_count > 1)
453 {
454 if (! ieee_write_byte (abfd, ieee_function_plus_enum))
b34976b6 455 return FALSE;
252b5132
RH
456 term_count--;
457 }
458
b34976b6 459 return TRUE;
252b5132
RH
460}
461\f
49ae03bf 462/* Writes any integer into the buffer supplied and always takes 5 bytes. */
252b5132 463
252b5132
RH
464static void
465ieee_write_int5 (buffer, value)
466 bfd_byte *buffer;
467 bfd_vma value;
468{
469 buffer[0] = (bfd_byte) ieee_number_repeat_4_enum;
470 buffer[1] = (value >> 24) & 0xff;
471 buffer[2] = (value >> 16) & 0xff;
472 buffer[3] = (value >> 8) & 0xff;
473 buffer[4] = (value >> 0) & 0xff;
474}
475
b34976b6 476static bfd_boolean
252b5132
RH
477ieee_write_int5_out (abfd, value)
478 bfd *abfd;
479 bfd_vma value;
480{
481 bfd_byte b[5];
482
483 ieee_write_int5 (b, value);
dc810e39 484 if (bfd_bwrite ((PTR) b, (bfd_size_type) 5, abfd) != 5)
b34976b6
AM
485 return FALSE;
486 return TRUE;
252b5132
RH
487}
488
b34976b6 489static bfd_boolean
252b5132
RH
490parse_int (ieee, value_ptr)
491 common_header_type *ieee;
492 bfd_vma *value_ptr;
493{
494 int value = this_byte (ieee);
495 int result;
49ae03bf 496
252b5132
RH
497 if (value >= 0 && value <= 127)
498 {
499 *value_ptr = value;
500 next_byte (ieee);
b34976b6 501 return TRUE;
252b5132
RH
502 }
503 else if (value >= 0x80 && value <= 0x88)
504 {
505 unsigned int count = value & 0xf;
49ae03bf 506
252b5132
RH
507 result = 0;
508 next_byte (ieee);
509 while (count)
510 {
511 result = (result << 8) | this_byte_and_next (ieee);
512 count--;
513 }
514 *value_ptr = result;
b34976b6 515 return TRUE;
252b5132 516 }
b34976b6 517 return FALSE;
252b5132
RH
518}
519
520static int
521parse_i (ieee, ok)
522 common_header_type *ieee;
b34976b6 523 bfd_boolean *ok;
252b5132
RH
524{
525 bfd_vma x;
526 *ok = parse_int (ieee, &x);
527 return x;
528}
529
530static bfd_vma
531must_parse_int (ieee)
532 common_header_type *ieee;
533{
534 bfd_vma result;
82e51918 535 BFD_ASSERT (parse_int (ieee, &result));
252b5132
RH
536 return result;
537}
538
539typedef struct
540{
541 bfd_vma value;
542 asection *section;
543 ieee_symbol_index_type symbol;
544} ieee_value_type;
545
546
547#if KEEPMINUSPCININST
548
549#define SRC_MASK(arg) arg
b34976b6 550#define PCREL_OFFSET FALSE
252b5132
RH
551
552#else
553
554#define SRC_MASK(arg) 0
b34976b6 555#define PCREL_OFFSET TRUE
252b5132
RH
556
557#endif
558
559static reloc_howto_type abs32_howto =
560 HOWTO (1,
561 0,
562 2,
563 32,
b34976b6 564 FALSE,
252b5132
RH
565 0,
566 complain_overflow_bitfield,
567 0,
568 "abs32",
b34976b6 569 TRUE,
252b5132
RH
570 0xffffffff,
571 0xffffffff,
b34976b6 572 FALSE);
252b5132
RH
573
574static reloc_howto_type abs16_howto =
575 HOWTO (1,
576 0,
577 1,
578 16,
b34976b6 579 FALSE,
252b5132
RH
580 0,
581 complain_overflow_bitfield,
582 0,
583 "abs16",
b34976b6 584 TRUE,
252b5132
RH
585 0x0000ffff,
586 0x0000ffff,
b34976b6 587 FALSE);
252b5132
RH
588
589static reloc_howto_type abs8_howto =
590 HOWTO (1,
591 0,
592 0,
593 8,
b34976b6 594 FALSE,
252b5132
RH
595 0,
596 complain_overflow_bitfield,
597 0,
598 "abs8",
b34976b6 599 TRUE,
252b5132
RH
600 0x000000ff,
601 0x000000ff,
b34976b6 602 FALSE);
252b5132
RH
603
604static reloc_howto_type rel32_howto =
605 HOWTO (1,
606 0,
607 2,
608 32,
b34976b6 609 TRUE,
252b5132
RH
610 0,
611 complain_overflow_signed,
612 0,
613 "rel32",
b34976b6 614 TRUE,
252b5132
RH
615 SRC_MASK (0xffffffff),
616 0xffffffff,
617 PCREL_OFFSET);
618
619static reloc_howto_type rel16_howto =
620 HOWTO (1,
621 0,
622 1,
623 16,
b34976b6 624 TRUE,
252b5132
RH
625 0,
626 complain_overflow_signed,
627 0,
628 "rel16",
b34976b6 629 TRUE,
252b5132
RH
630 SRC_MASK (0x0000ffff),
631 0x0000ffff,
632 PCREL_OFFSET);
633
634static reloc_howto_type rel8_howto =
635 HOWTO (1,
636 0,
637 0,
638 8,
b34976b6 639 TRUE,
252b5132
RH
640 0,
641 complain_overflow_signed,
642 0,
643 "rel8",
b34976b6 644 TRUE,
252b5132
RH
645 SRC_MASK (0x000000ff),
646 0x000000ff,
647 PCREL_OFFSET);
648
649static ieee_symbol_index_type NOSYMBOL = {0, 0};
650
651static void
652parse_expression (ieee, value, symbol, pcrel, extra, section)
653 ieee_data_type *ieee;
654 bfd_vma *value;
655 ieee_symbol_index_type *symbol;
b34976b6 656 bfd_boolean *pcrel;
252b5132
RH
657 unsigned int *extra;
658 asection **section;
659
660{
661#define POS sp[1]
662#define TOS sp[0]
663#define NOS sp[-1]
664#define INC sp++;
665#define DEC sp--;
666
b34976b6 667 bfd_boolean loop = TRUE;
252b5132
RH
668 ieee_value_type stack[10];
669
49ae03bf 670 /* The stack pointer always points to the next unused location. */
252b5132
RH
671#define PUSH(x,y,z) TOS.symbol=x;TOS.section=y;TOS.value=z;INC;
672#define POP(x,y,z) DEC;x=TOS.symbol;y=TOS.section;z=TOS.value;
673 ieee_value_type *sp = stack;
47fda0d3 674 asection *dummy;
252b5132 675
47fda0d3 676 while (loop && ieee->h.input_p < ieee->h.last_byte)
252b5132
RH
677 {
678 switch (this_byte (&(ieee->h)))
679 {
680 case ieee_variable_P_enum:
49ae03bf 681 /* P variable, current program counter for section n. */
252b5132
RH
682 {
683 int section_n;
49ae03bf 684
252b5132 685 next_byte (&(ieee->h));
b34976b6 686 *pcrel = TRUE;
252b5132
RH
687 section_n = must_parse_int (&(ieee->h));
688 PUSH (NOSYMBOL, bfd_abs_section_ptr, 0);
689 break;
690 }
691 case ieee_variable_L_enum:
49ae03bf 692 /* L variable address of section N. */
252b5132
RH
693 next_byte (&(ieee->h));
694 PUSH (NOSYMBOL, ieee->section_table[must_parse_int (&(ieee->h))], 0);
695 break;
696 case ieee_variable_R_enum:
49ae03bf
NC
697 /* R variable, logical address of section module. */
698 /* FIXME, this should be different to L. */
252b5132
RH
699 next_byte (&(ieee->h));
700 PUSH (NOSYMBOL, ieee->section_table[must_parse_int (&(ieee->h))], 0);
701 break;
702 case ieee_variable_S_enum:
49ae03bf 703 /* S variable, size in MAUS of section module. */
252b5132
RH
704 next_byte (&(ieee->h));
705 PUSH (NOSYMBOL,
706 0,
eea6121a 707 ieee->section_table[must_parse_int (&(ieee->h))]->size);
252b5132
RH
708 break;
709 case ieee_variable_I_enum:
49ae03bf 710 /* Push the address of variable n. */
252b5132
RH
711 {
712 ieee_symbol_index_type sy;
713 next_byte (&(ieee->h));
714 sy.index = (int) must_parse_int (&(ieee->h));
715 sy.letter = 'I';
716
717 PUSH (sy, bfd_abs_section_ptr, 0);
718 }
719 break;
720 case ieee_variable_X_enum:
49ae03bf 721 /* Push the address of external variable n. */
252b5132
RH
722 {
723 ieee_symbol_index_type sy;
724 next_byte (&(ieee->h));
725 sy.index = (int) (must_parse_int (&(ieee->h)));
726 sy.letter = 'X';
727
728 PUSH (sy, bfd_und_section_ptr, 0);
729 }
730 break;
731 case ieee_function_minus_enum:
732 {
733 bfd_vma value1, value2;
734 asection *section1, *section_dummy;
735 ieee_symbol_index_type sy;
736 next_byte (&(ieee->h));
737
738 POP (sy, section1, value1);
739 POP (sy, section_dummy, value2);
740 PUSH (sy, section1 ? section1 : section_dummy, value2 - value1);
741 }
742 break;
743 case ieee_function_plus_enum:
744 {
745 bfd_vma value1, value2;
746 asection *section1;
747 asection *section2;
748 ieee_symbol_index_type sy1;
749 ieee_symbol_index_type sy2;
750 next_byte (&(ieee->h));
751
752 POP (sy1, section1, value1);
753 POP (sy2, section2, value2);
754 PUSH (sy1.letter ? sy1 : sy2,
755 bfd_is_abs_section (section1) ? section2 : section1,
756 value1 + value2);
757 }
758 break;
759 default:
760 {
761 bfd_vma va;
762 BFD_ASSERT (this_byte (&(ieee->h)) < (int) ieee_variable_A_enum
763 || this_byte (&(ieee->h)) > (int) ieee_variable_Z_enum);
764 if (parse_int (&(ieee->h), &va))
765 {
766 PUSH (NOSYMBOL, bfd_abs_section_ptr, va);
767 }
768 else
769 {
47fda0d3 770 /* Thats all that we can understand. */
b34976b6 771 loop = FALSE;
252b5132
RH
772 }
773 }
774 }
775 }
47fda0d3
AM
776
777 /* As far as I can see there is a bug in the Microtec IEEE output
778 which I'm using to scan, whereby the comma operator is omitted
779 sometimes in an expression, giving expressions with too many
780 terms. We can tell if that's the case by ensuring that
781 sp == stack here. If not, then we've pushed something too far,
782 so we keep adding. */
47fda0d3
AM
783 while (sp != stack + 1)
784 {
785 asection *section1;
786 ieee_symbol_index_type sy1;
787 POP (sy1, section1, *extra);
788 }
789
790 POP (*symbol, dummy, *value);
791 if (section)
792 *section = dummy;
252b5132
RH
793}
794
795
47fda0d3
AM
796#define ieee_seek(ieee, offset) \
797 do \
798 { \
799 ieee->h.input_p = ieee->h.first_byte + offset; \
800 ieee->h.last_byte = (ieee->h.first_byte \
801 + ieee_part_after (ieee, offset)); \
802 } \
803 while (0)
804
805#define ieee_pos(ieee) \
806 (ieee->h.input_p - ieee->h.first_byte)
252b5132 807
47fda0d3
AM
808/* Find the first part of the ieee file after HERE. */
809
810static file_ptr
811ieee_part_after (ieee, here)
812 ieee_data_type *ieee;
813 file_ptr here;
814{
815 int part;
816 file_ptr after = ieee->w.r.me_record;
817
818 /* File parts can come in any order, except that module end is
819 guaranteed to be last (and the header first). */
820 for (part = 0; part < N_W_VARIABLES; part++)
821 if (ieee->w.offset[part] > here && after > ieee->w.offset[part])
822 after = ieee->w.offset[part];
823
824 return after;
825}
252b5132
RH
826
827static unsigned int last_index;
49ae03bf 828static char last_type; /* Is the index for an X or a D. */
252b5132
RH
829
830static ieee_symbol_type *
47fda0d3 831get_symbol (abfd, ieee, last_symbol, symbol_count, pptr, max_index, this_type)
5f771d47 832 bfd *abfd ATTRIBUTE_UNUSED;
252b5132
RH
833 ieee_data_type *ieee;
834 ieee_symbol_type *last_symbol;
835 unsigned int *symbol_count;
836 ieee_symbol_type ***pptr;
837 unsigned int *max_index;
dc810e39 838 int this_type;
252b5132 839{
49ae03bf 840 /* Need a new symbol. */
252b5132 841 unsigned int new_index = must_parse_int (&(ieee->h));
49ae03bf 842
252b5132
RH
843 if (new_index != last_index || this_type != last_type)
844 {
dc810e39
AM
845 ieee_symbol_type *new_symbol;
846 bfd_size_type amt = sizeof (ieee_symbol_type);
847
848 new_symbol = (ieee_symbol_type *) bfd_alloc (ieee->h.abfd, amt);
252b5132
RH
849 if (!new_symbol)
850 return NULL;
851
852 new_symbol->index = new_index;
853 last_index = new_index;
854 (*symbol_count)++;
855 **pptr = new_symbol;
856 *pptr = &new_symbol->next;
857 if (new_index > *max_index)
49ae03bf
NC
858 *max_index = new_index;
859
252b5132
RH
860 last_type = this_type;
861 new_symbol->symbol.section = bfd_abs_section_ptr;
862 return new_symbol;
863 }
864 return last_symbol;
865}
866
b34976b6 867static bfd_boolean
252b5132
RH
868ieee_slurp_external_symbols (abfd)
869 bfd *abfd;
870{
871 ieee_data_type *ieee = IEEE_DATA (abfd);
872 file_ptr offset = ieee->w.r.external_part;
873
874 ieee_symbol_type **prev_symbols_ptr = &ieee->external_symbols;
875 ieee_symbol_type **prev_reference_ptr = &ieee->external_reference;
876 ieee_symbol_type *symbol = (ieee_symbol_type *) NULL;
877 unsigned int symbol_count = 0;
b34976b6 878 bfd_boolean loop = TRUE;
252b5132 879 last_index = 0xffffff;
b34976b6 880 ieee->symbol_table_full = TRUE;
252b5132 881
47fda0d3 882 ieee_seek (ieee, offset);
252b5132
RH
883
884 while (loop)
885 {
886 switch (this_byte (&(ieee->h)))
887 {
888 case ieee_nn_record:
889 next_byte (&(ieee->h));
890
891 symbol = get_symbol (abfd, ieee, symbol, &symbol_count,
892 &prev_symbols_ptr,
893 &ieee->external_symbol_max_index, 'I');
894 if (symbol == NULL)
b34976b6 895 return FALSE;
252b5132
RH
896
897 symbol->symbol.the_bfd = abfd;
898 symbol->symbol.name = read_id (&(ieee->h));
899 symbol->symbol.udata.p = (PTR) NULL;
900 symbol->symbol.flags = BSF_NO_FLAGS;
901 break;
902 case ieee_external_symbol_enum:
903 next_byte (&(ieee->h));
904
905 symbol = get_symbol (abfd, ieee, symbol, &symbol_count,
906 &prev_symbols_ptr,
907 &ieee->external_symbol_max_index, 'D');
908 if (symbol == NULL)
b34976b6 909 return FALSE;
252b5132
RH
910
911 BFD_ASSERT (symbol->index >= ieee->external_symbol_min_index);
912
913 symbol->symbol.the_bfd = abfd;
914 symbol->symbol.name = read_id (&(ieee->h));
915 symbol->symbol.udata.p = (PTR) NULL;
916 symbol->symbol.flags = BSF_NO_FLAGS;
917 break;
918 case ieee_attribute_record_enum >> 8:
919 {
920 unsigned int symbol_name_index;
921 unsigned int symbol_type_index;
922 unsigned int symbol_attribute_def;
923 bfd_vma value;
47fda0d3 924 switch (read_2bytes (&ieee->h))
252b5132
RH
925 {
926 case ieee_attribute_record_enum:
927 symbol_name_index = must_parse_int (&(ieee->h));
928 symbol_type_index = must_parse_int (&(ieee->h));
929 symbol_attribute_def = must_parse_int (&(ieee->h));
930 switch (symbol_attribute_def)
931 {
932 case 8:
933 case 19:
934 parse_int (&ieee->h, &value);
935 break;
936 default:
937 (*_bfd_error_handler)
d003868e
AM
938 (_("%B: unimplemented ATI record %u for symbol %u"),
939 abfd, symbol_attribute_def, symbol_name_index);
252b5132 940 bfd_set_error (bfd_error_bad_value);
b34976b6 941 return FALSE;
252b5132
RH
942 break;
943 }
944 break;
945 case ieee_external_reference_info_record_enum:
49ae03bf 946 /* Skip over ATX record. */
252b5132
RH
947 parse_int (&(ieee->h), &value);
948 parse_int (&(ieee->h), &value);
949 parse_int (&(ieee->h), &value);
950 parse_int (&(ieee->h), &value);
951 break;
952 case ieee_atn_record_enum:
953 /* We may get call optimization information here,
954 which we just ignore. The format is
49ae03bf 955 {$F1}${CE}{index}{$00}{$3F}{$3F}{#_of_ASNs}. */
252b5132
RH
956 parse_int (&ieee->h, &value);
957 parse_int (&ieee->h, &value);
958 parse_int (&ieee->h, &value);
959 if (value != 0x3f)
960 {
961 (*_bfd_error_handler)
d003868e
AM
962 (_("%B: unexpected ATN type %d in external part"),
963 abfd, (int) value);
252b5132 964 bfd_set_error (bfd_error_bad_value);
b34976b6 965 return FALSE;
252b5132
RH
966 }
967 parse_int (&ieee->h, &value);
968 parse_int (&ieee->h, &value);
969 while (value > 0)
970 {
971 bfd_vma val1;
972
973 --value;
974
47fda0d3 975 switch (read_2bytes (&ieee->h))
252b5132
RH
976 {
977 case ieee_asn_record_enum:
978 parse_int (&ieee->h, &val1);
979 parse_int (&ieee->h, &val1);
980 break;
981
982 default:
983 (*_bfd_error_handler)
d003868e 984 (_("%B: unexpected type after ATN"), abfd);
252b5132 985 bfd_set_error (bfd_error_bad_value);
b34976b6 986 return FALSE;
252b5132
RH
987 }
988 }
989 }
990 }
991 break;
992 case ieee_value_record_enum >> 8:
993 {
994 unsigned int symbol_name_index;
995 ieee_symbol_index_type symbol_ignore;
b34976b6 996 bfd_boolean pcrel_ignore;
252b5132
RH
997 unsigned int extra;
998 next_byte (&(ieee->h));
999 next_byte (&(ieee->h));
1000
1001 symbol_name_index = must_parse_int (&(ieee->h));
1002 parse_expression (ieee,
1003 &symbol->symbol.value,
1004 &symbol_ignore,
1005 &pcrel_ignore,
1006 &extra,
1007 &symbol->symbol.section);
1008
1009 /* Fully linked IEEE-695 files tend to give every symbol
1010 an absolute value. Try to convert that back into a
1011 section relative value. FIXME: This won't always to
1012 the right thing. */
1013 if (bfd_is_abs_section (symbol->symbol.section)
1014 && (abfd->flags & HAS_RELOC) == 0)
1015 {
1016 bfd_vma val;
1017 asection *s;
1018
1019 val = symbol->symbol.value;
1020 for (s = abfd->sections; s != NULL; s = s->next)
1021 {
eea6121a 1022 if (val >= s->vma && val < s->vma + s->size)
252b5132
RH
1023 {
1024 symbol->symbol.section = s;
1025 symbol->symbol.value -= s->vma;
1026 break;
1027 }
1028 }
1029 }
1030
1031 symbol->symbol.flags = BSF_GLOBAL | BSF_EXPORT;
1032
1033 }
1034 break;
1035 case ieee_weak_external_reference_enum:
1036 {
1037 bfd_vma size;
1038 bfd_vma value;
1039 next_byte (&(ieee->h));
49ae03bf 1040 /* Throw away the external reference index. */
252b5132 1041 (void) must_parse_int (&(ieee->h));
49ae03bf 1042 /* Fetch the default size if not resolved. */
252b5132 1043 size = must_parse_int (&(ieee->h));
7dee875e 1044 /* Fetch the default value if available. */
82e51918 1045 if (! parse_int (&(ieee->h), &value))
252b5132
RH
1046 {
1047 value = 0;
1048 }
49ae03bf 1049 /* This turns into a common. */
252b5132
RH
1050 symbol->symbol.section = bfd_com_section_ptr;
1051 symbol->symbol.value = size;
1052 }
1053 break;
1054
1055 case ieee_external_reference_enum:
1056 next_byte (&(ieee->h));
1057
1058 symbol = get_symbol (abfd, ieee, symbol, &symbol_count,
1059 &prev_reference_ptr,
1060 &ieee->external_reference_max_index, 'X');
1061 if (symbol == NULL)
b34976b6 1062 return FALSE;
252b5132
RH
1063
1064 symbol->symbol.the_bfd = abfd;
1065 symbol->symbol.name = read_id (&(ieee->h));
1066 symbol->symbol.udata.p = (PTR) NULL;
1067 symbol->symbol.section = bfd_und_section_ptr;
1068 symbol->symbol.value = (bfd_vma) 0;
1069 symbol->symbol.flags = 0;
1070
1071 BFD_ASSERT (symbol->index >= ieee->external_reference_min_index);
1072 break;
1073
1074 default:
b34976b6 1075 loop = FALSE;
252b5132
RH
1076 }
1077 }
1078
1079 if (ieee->external_symbol_max_index != 0)
1080 {
1081 ieee->external_symbol_count =
1082 ieee->external_symbol_max_index -
1083 ieee->external_symbol_min_index + 1;
1084 }
1085 else
1086 {
1087 ieee->external_symbol_count = 0;
1088 }
1089
1090 if (ieee->external_reference_max_index != 0)
1091 {
1092 ieee->external_reference_count =
1093 ieee->external_reference_max_index -
1094 ieee->external_reference_min_index + 1;
1095 }
1096 else
1097 {
1098 ieee->external_reference_count = 0;
1099 }
1100
1101 abfd->symcount =
1102 ieee->external_reference_count + ieee->external_symbol_count;
1103
1104 if (symbol_count != abfd->symcount)
1105 {
1106 /* There are gaps in the table -- */
b34976b6 1107 ieee->symbol_table_full = FALSE;
252b5132
RH
1108 }
1109
1110 *prev_symbols_ptr = (ieee_symbol_type *) NULL;
1111 *prev_reference_ptr = (ieee_symbol_type *) NULL;
1112
b34976b6 1113 return TRUE;
252b5132
RH
1114}
1115
b34976b6 1116static bfd_boolean
252b5132
RH
1117ieee_slurp_symbol_table (abfd)
1118 bfd *abfd;
1119{
82e51918 1120 if (! IEEE_DATA (abfd)->read_symbols)
252b5132
RH
1121 {
1122 if (! ieee_slurp_external_symbols (abfd))
b34976b6
AM
1123 return FALSE;
1124 IEEE_DATA (abfd)->read_symbols = TRUE;
252b5132 1125 }
b34976b6 1126 return TRUE;
252b5132
RH
1127}
1128
47fda0d3 1129static long
252b5132
RH
1130ieee_get_symtab_upper_bound (abfd)
1131 bfd *abfd;
1132{
1133 if (! ieee_slurp_symbol_table (abfd))
1134 return -1;
1135
1136 return (abfd->symcount != 0) ?
1137 (abfd->symcount + 1) * (sizeof (ieee_symbol_type *)) : 0;
1138}
1139
49ae03bf
NC
1140/* Move from our internal lists to the canon table, and insert in
1141 symbol index order. */
252b5132
RH
1142
1143extern const bfd_target ieee_vec;
1144
47fda0d3 1145static long
6cee3f79 1146ieee_canonicalize_symtab (abfd, location)
252b5132
RH
1147 bfd *abfd;
1148 asymbol **location;
1149{
1150 ieee_symbol_type *symp;
1151 static bfd dummy_bfd;
1152 static asymbol empty_symbol =
dcdea4f4
AM
1153 {
1154 &dummy_bfd,
1155 " ieee empty",
1156 (symvalue) 0,
1157 BSF_DEBUGGING,
1158 bfd_abs_section_ptr
1159#ifdef __STDC__
1160 /* K&R compilers can't initialise unions. */
1161 , { 0 }
1162#endif
1163 };
252b5132
RH
1164
1165 if (abfd->symcount)
1166 {
1167 ieee_data_type *ieee = IEEE_DATA (abfd);
1168 dummy_bfd.xvec = &ieee_vec;
1169 if (! ieee_slurp_symbol_table (abfd))
1170 return -1;
1171
82e51918 1172 if (! ieee->symbol_table_full)
252b5132 1173 {
49ae03bf
NC
1174 /* Arrgh - there are gaps in the table, run through and fill them
1175 up with pointers to a null place. */
252b5132 1176 unsigned int i;
49ae03bf 1177
252b5132 1178 for (i = 0; i < abfd->symcount; i++)
49ae03bf 1179 location[i] = &empty_symbol;
252b5132
RH
1180 }
1181
1182 ieee->external_symbol_base_offset = -ieee->external_symbol_min_index;
1183 for (symp = IEEE_DATA (abfd)->external_symbols;
1184 symp != (ieee_symbol_type *) NULL;
1185 symp = symp->next)
49ae03bf
NC
1186 /* Place into table at correct index locations. */
1187 location[symp->index + ieee->external_symbol_base_offset] = &symp->symbol;
252b5132 1188
49ae03bf 1189 /* The external refs are indexed in a bit. */
252b5132
RH
1190 ieee->external_reference_base_offset =
1191 -ieee->external_reference_min_index + ieee->external_symbol_count;
1192
1193 for (symp = IEEE_DATA (abfd)->external_reference;
1194 symp != (ieee_symbol_type *) NULL;
1195 symp = symp->next)
49ae03bf
NC
1196 location[symp->index + ieee->external_reference_base_offset] =
1197 &symp->symbol;
252b5132 1198 }
49ae03bf 1199
252b5132 1200 if (abfd->symcount)
49ae03bf
NC
1201 location[abfd->symcount] = (asymbol *) NULL;
1202
252b5132
RH
1203 return abfd->symcount;
1204}
1205
1206static asection *
1207get_section_entry (abfd, ieee, index)
1208 bfd *abfd;
1209 ieee_data_type *ieee;
1210 unsigned int index;
1211{
1212 if (index >= ieee->section_table_size)
1213 {
1214 unsigned int c, i;
1215 asection **n;
dc810e39 1216 bfd_size_type amt;
252b5132
RH
1217
1218 c = ieee->section_table_size;
1219 if (c == 0)
1220 c = 20;
1221 while (c <= index)
1222 c *= 2;
1223
dc810e39
AM
1224 amt = c;
1225 amt *= sizeof (asection *);
1226 n = (asection **) bfd_realloc (ieee->section_table, amt);
252b5132
RH
1227 if (n == NULL)
1228 return NULL;
1229
1230 for (i = ieee->section_table_size; i < c; i++)
1231 n[i] = NULL;
1232
1233 ieee->section_table = n;
1234 ieee->section_table_size = c;
1235 }
1236
1237 if (ieee->section_table[index] == (asection *) NULL)
1238 {
dc810e39 1239 char *tmp = bfd_alloc (abfd, (bfd_size_type) 11);
252b5132
RH
1240 asection *section;
1241
1242 if (!tmp)
1243 return NULL;
1244 sprintf (tmp, " fsec%4d", index);
1245 section = bfd_make_section (abfd, tmp);
1246 ieee->section_table[index] = section;
1247 section->flags = SEC_NO_FLAGS;
1248 section->target_index = index;
1249 ieee->section_table[index] = section;
1250 }
1251 return ieee->section_table[index];
1252}
1253
1254static void
1255ieee_slurp_sections (abfd)
1256 bfd *abfd;
1257{
1258 ieee_data_type *ieee = IEEE_DATA (abfd);
1259 file_ptr offset = ieee->w.r.section_part;
252b5132
RH
1260 char *name;
1261
1262 if (offset != 0)
1263 {
1264 bfd_byte section_type[3];
47fda0d3 1265 ieee_seek (ieee, offset);
b34976b6 1266 while (TRUE)
252b5132
RH
1267 {
1268 switch (this_byte (&(ieee->h)))
1269 {
1270 case ieee_section_type_enum:
1271 {
dc810e39 1272 asection *section;
252b5132
RH
1273 unsigned int section_index;
1274 next_byte (&(ieee->h));
1275 section_index = must_parse_int (&(ieee->h));
1276
1277 section = get_section_entry (abfd, ieee, section_index);
1278
1279 section_type[0] = this_byte_and_next (&(ieee->h));
1280
1281 /* Set minimal section attributes. Attributes are
49ae03bf 1282 extended later, based on section contents. */
252b5132
RH
1283 switch (section_type[0])
1284 {
1285 case 0xC1:
49ae03bf 1286 /* Normal attributes for absolute sections. */
252b5132
RH
1287 section_type[1] = this_byte (&(ieee->h));
1288 section->flags = SEC_ALLOC;
1289 switch (section_type[1])
1290 {
49ae03bf 1291 case 0xD3: /* AS Absolute section attributes. */
252b5132
RH
1292 next_byte (&(ieee->h));
1293 section_type[2] = this_byte (&(ieee->h));
1294 switch (section_type[2])
1295 {
1296 case 0xD0:
49ae03bf 1297 /* Normal code. */
252b5132
RH
1298 next_byte (&(ieee->h));
1299 section->flags |= SEC_CODE;
1300 break;
1301 case 0xC4:
49ae03bf 1302 /* Normal data. */
252b5132
RH
1303 next_byte (&(ieee->h));
1304 section->flags |= SEC_DATA;
1305 break;
1306 case 0xD2:
1307 next_byte (&(ieee->h));
49ae03bf 1308 /* Normal rom data. */
252b5132
RH
1309 section->flags |= SEC_ROM | SEC_DATA;
1310 break;
1311 default:
1312 break;
1313 }
1314 }
1315 break;
49ae03bf 1316 case 0xC3: /* Named relocatable sections (type C). */
252b5132
RH
1317 section_type[1] = this_byte (&(ieee->h));
1318 section->flags = SEC_ALLOC;
1319 switch (section_type[1])
1320 {
49ae03bf 1321 case 0xD0: /* Normal code (CP). */
252b5132
RH
1322 next_byte (&(ieee->h));
1323 section->flags |= SEC_CODE;
1324 break;
49ae03bf 1325 case 0xC4: /* Normal data (CD). */
252b5132
RH
1326 next_byte (&(ieee->h));
1327 section->flags |= SEC_DATA;
1328 break;
49ae03bf 1329 case 0xD2: /* Normal rom data (CR). */
252b5132
RH
1330 next_byte (&(ieee->h));
1331 section->flags |= SEC_ROM | SEC_DATA;
1332 break;
1333 default:
1334 break;
1335 }
1336 }
1337
49ae03bf 1338 /* Read section name, use it if non empty. */
252b5132
RH
1339 name = read_id (&ieee->h);
1340 if (name[0])
1341 section->name = name;
1342
49ae03bf 1343 /* Skip these fields, which we don't care about. */
252b5132
RH
1344 {
1345 bfd_vma parent, brother, context;
1346 parse_int (&(ieee->h), &parent);
1347 parse_int (&(ieee->h), &brother);
1348 parse_int (&(ieee->h), &context);
1349 }
1350 }
1351 break;
1352 case ieee_section_alignment_enum:
1353 {
1354 unsigned int section_index;
1355 bfd_vma value;
1356 asection *section;
1357 next_byte (&(ieee->h));
1358 section_index = must_parse_int (&ieee->h);
1359 section = get_section_entry (abfd, ieee, section_index);
1360 if (section_index > ieee->section_count)
1361 {
1362 ieee->section_count = section_index;
1363 }
1364 section->alignment_power =
1365 bfd_log2 (must_parse_int (&ieee->h));
1366 (void) parse_int (&(ieee->h), &value);
1367 }
1368 break;
1369 case ieee_e2_first_byte_enum:
1370 {
dc810e39
AM
1371 asection *section;
1372 ieee_record_enum_type t;
252b5132 1373
dc810e39 1374 t = (ieee_record_enum_type) (read_2bytes (&(ieee->h)));
252b5132
RH
1375 switch (t)
1376 {
1377 case ieee_section_size_enum:
1378 section = ieee->section_table[must_parse_int (&(ieee->h))];
eea6121a 1379 section->size = must_parse_int (&(ieee->h));
252b5132
RH
1380 break;
1381 case ieee_physical_region_size_enum:
1382 section = ieee->section_table[must_parse_int (&(ieee->h))];
eea6121a 1383 section->size = must_parse_int (&(ieee->h));
252b5132
RH
1384 break;
1385 case ieee_region_base_address_enum:
1386 section = ieee->section_table[must_parse_int (&(ieee->h))];
1387 section->vma = must_parse_int (&(ieee->h));
1388 section->lma = section->vma;
1389 break;
1390 case ieee_mau_size_enum:
1391 must_parse_int (&(ieee->h));
1392 must_parse_int (&(ieee->h));
1393 break;
1394 case ieee_m_value_enum:
1395 must_parse_int (&(ieee->h));
1396 must_parse_int (&(ieee->h));
1397 break;
1398 case ieee_section_base_address_enum:
1399 section = ieee->section_table[must_parse_int (&(ieee->h))];
1400 section->vma = must_parse_int (&(ieee->h));
1401 section->lma = section->vma;
1402 break;
1403 case ieee_section_offset_enum:
1404 (void) must_parse_int (&(ieee->h));
1405 (void) must_parse_int (&(ieee->h));
1406 break;
1407 default:
1408 return;
1409 }
1410 }
1411 break;
1412 default:
1413 return;
1414 }
1415 }
1416 }
1417}
1418
1419/* Make a section for the debugging information, if any. We don't try
1420 to interpret the debugging information; we just point the section
1421 at the area in the file so that program which understand can dig it
1422 out. */
1423
b34976b6 1424static bfd_boolean
252b5132
RH
1425ieee_slurp_debug (abfd)
1426 bfd *abfd;
1427{
1428 ieee_data_type *ieee = IEEE_DATA (abfd);
1429 asection *sec;
a8c5faf7 1430 file_ptr debug_end;
252b5132
RH
1431
1432 if (ieee->w.r.debug_information_part == 0)
b34976b6 1433 return TRUE;
252b5132
RH
1434
1435 sec = bfd_make_section (abfd, ".debug");
1436 if (sec == NULL)
b34976b6 1437 return FALSE;
252b5132
RH
1438 sec->flags |= SEC_DEBUGGING | SEC_HAS_CONTENTS;
1439 sec->filepos = ieee->w.r.debug_information_part;
a8c5faf7 1440
47fda0d3 1441 debug_end = ieee_part_after (ieee, ieee->w.r.debug_information_part);
eea6121a 1442 sec->size = debug_end - ieee->w.r.debug_information_part;
252b5132 1443
b34976b6 1444 return TRUE;
252b5132
RH
1445}
1446\f
49ae03bf 1447/* Archive stuff. */
252b5132
RH
1448
1449const bfd_target *
1450ieee_archive_p (abfd)
1451 bfd *abfd;
1452{
1453 char *library;
1454 unsigned int i;
1455 unsigned char buffer[512];
1456 file_ptr buffer_offset = 0;
1457 ieee_ar_data_type *save = abfd->tdata.ieee_ar_data;
1458 ieee_ar_data_type *ieee;
dc810e39 1459 bfd_size_type alc_elts;
252b5132 1460 ieee_ar_obstack_type *elts = NULL;
dc810e39 1461 bfd_size_type amt = sizeof (ieee_ar_data_type);
252b5132 1462
dc810e39 1463 abfd->tdata.ieee_ar_data = (ieee_ar_data_type *) bfd_alloc (abfd, amt);
252b5132 1464 if (!abfd->tdata.ieee_ar_data)
487e54f2 1465 goto error_ret_restore;
252b5132
RH
1466 ieee = IEEE_AR_DATA (abfd);
1467
47fda0d3
AM
1468 /* Ignore the return value here. It doesn't matter if we don't read
1469 the entire buffer. We might have a very small ieee file. */
dc810e39 1470 bfd_bread ((PTR) buffer, (bfd_size_type) sizeof (buffer), abfd);
252b5132
RH
1471
1472 ieee->h.first_byte = buffer;
1473 ieee->h.input_p = buffer;
1474
1475 ieee->h.abfd = abfd;
1476
1477 if (this_byte (&(ieee->h)) != Module_Beginning)
c4920b97 1478 goto got_wrong_format_error;
252b5132
RH
1479
1480 next_byte (&(ieee->h));
1481 library = read_id (&(ieee->h));
1482 if (strcmp (library, "LIBRARY") != 0)
c4920b97
NC
1483 goto got_wrong_format_error;
1484
1485 /* Throw away the filename. */
252b5132
RH
1486 read_id (&(ieee->h));
1487
1488 ieee->element_count = 0;
1489 ieee->element_index = 0;
1490
c4920b97
NC
1491 next_byte (&(ieee->h)); /* Drop the ad part. */
1492 must_parse_int (&(ieee->h)); /* And the two dummy numbers. */
252b5132
RH
1493 must_parse_int (&(ieee->h));
1494
1495 alc_elts = 10;
1496 elts = (ieee_ar_obstack_type *) bfd_malloc (alc_elts * sizeof *elts);
1497 if (elts == NULL)
1498 goto error_return;
1499
c4920b97 1500 /* Read the index of the BB table. */
252b5132
RH
1501 while (1)
1502 {
1503 int rec;
1504 ieee_ar_obstack_type *t;
1505
1506 rec = read_2bytes (&(ieee->h));
1507 if (rec != (int) ieee_assign_value_to_variable_enum)
1508 break;
1509
1510 if (ieee->element_count >= alc_elts)
1511 {
1512 ieee_ar_obstack_type *n;
1513
1514 alc_elts *= 2;
1515 n = ((ieee_ar_obstack_type *)
1516 bfd_realloc (elts, alc_elts * sizeof *elts));
1517 if (n == NULL)
1518 goto error_return;
1519 elts = n;
1520 }
1521
1522 t = &elts[ieee->element_count];
1523 ieee->element_count++;
1524
1525 must_parse_int (&(ieee->h));
1526 t->file_offset = must_parse_int (&(ieee->h));
1527 t->abfd = (bfd *) NULL;
1528
c4920b97 1529 /* Make sure that we don't go over the end of the buffer. */
47fda0d3 1530 if ((size_t) ieee_pos (IEEE_DATA (abfd)) > sizeof (buffer) / 2)
252b5132 1531 {
c4920b97 1532 /* Past half way, reseek and reprime. */
47fda0d3 1533 buffer_offset += ieee_pos (IEEE_DATA (abfd));
252b5132
RH
1534 if (bfd_seek (abfd, buffer_offset, SEEK_SET) != 0)
1535 goto error_return;
c4920b97 1536
dc810e39
AM
1537 /* Again ignore return value of bfd_bread. */
1538 bfd_bread ((PTR) buffer, (bfd_size_type) sizeof (buffer), abfd);
252b5132
RH
1539 ieee->h.first_byte = buffer;
1540 ieee->h.input_p = buffer;
1541 }
1542 }
1543
dc810e39
AM
1544 amt = ieee->element_count;
1545 amt *= sizeof *ieee->elements;
1546 ieee->elements = (ieee_ar_obstack_type *) bfd_alloc (abfd, amt);
252b5132
RH
1547 if (ieee->elements == NULL)
1548 goto error_return;
c4920b97 1549
dc810e39 1550 memcpy (ieee->elements, elts, (size_t) amt);
252b5132
RH
1551 free (elts);
1552 elts = NULL;
1553
c4920b97 1554 /* Now scan the area again, and replace BB offsets with file offsets. */
252b5132
RH
1555 for (i = 2; i < ieee->element_count; i++)
1556 {
1557 if (bfd_seek (abfd, ieee->elements[i].file_offset, SEEK_SET) != 0)
1558 goto error_return;
c4920b97 1559
dc810e39
AM
1560 /* Again ignore return value of bfd_bread. */
1561 bfd_bread ((PTR) buffer, (bfd_size_type) sizeof (buffer), abfd);
252b5132
RH
1562 ieee->h.first_byte = buffer;
1563 ieee->h.input_p = buffer;
1564
c4920b97
NC
1565 next_byte (&(ieee->h)); /* Drop F8. */
1566 next_byte (&(ieee->h)); /* Drop 14. */
1567 must_parse_int (&(ieee->h)); /* Drop size of block. */
dc810e39 1568
252b5132 1569 if (must_parse_int (&(ieee->h)) != 0)
c4920b97
NC
1570 /* This object has been deleted. */
1571 ieee->elements[i].file_offset = 0;
252b5132 1572 else
c4920b97 1573 ieee->elements[i].file_offset = must_parse_int (&(ieee->h));
252b5132
RH
1574 }
1575
1576 /* abfd->has_armap = ;*/
1577
1578 return abfd->xvec;
1579
911c6dae
AM
1580 got_wrong_format_error:
1581 bfd_set_error (bfd_error_wrong_format);
252b5132
RH
1582 error_return:
1583 if (elts != NULL)
1584 free (elts);
487e54f2
AM
1585 bfd_release (abfd, ieee);
1586 error_ret_restore:
1587 abfd->tdata.ieee_ar_data = save;
c4920b97 1588
252b5132
RH
1589 return NULL;
1590}
1591
252b5132
RH
1592const bfd_target *
1593ieee_object_p (abfd)
1594 bfd *abfd;
1595{
1596 char *processor;
1597 unsigned int part;
1598 ieee_data_type *ieee;
1599 unsigned char buffer[300];
1600 ieee_data_type *save = IEEE_DATA (abfd);
dc810e39 1601 bfd_size_type amt;
252b5132
RH
1602
1603 abfd->tdata.ieee_data = 0;
1604 ieee_mkobject (abfd);
1605
1606 ieee = IEEE_DATA (abfd);
1607 if (bfd_seek (abfd, (file_ptr) 0, SEEK_SET) != 0)
1608 goto fail;
47fda0d3 1609 /* Read the first few bytes in to see if it makes sense. Ignore
dc810e39
AM
1610 bfd_bread return value; The file might be very small. */
1611 bfd_bread ((PTR) buffer, (bfd_size_type) sizeof (buffer), abfd);
252b5132
RH
1612
1613 ieee->h.input_p = buffer;
1614 if (this_byte_and_next (&(ieee->h)) != Module_Beginning)
1615 goto got_wrong_format;
1616
b34976b6
AM
1617 ieee->read_symbols = FALSE;
1618 ieee->read_data = FALSE;
252b5132
RH
1619 ieee->section_count = 0;
1620 ieee->external_symbol_max_index = 0;
1621 ieee->external_symbol_min_index = IEEE_PUBLIC_BASE;
1622 ieee->external_reference_min_index = IEEE_REFERENCE_BASE;
1623 ieee->external_reference_max_index = 0;
1624 ieee->h.abfd = abfd;
1625 ieee->section_table = NULL;
1626 ieee->section_table_size = 0;
1627
1628 processor = ieee->mb.processor = read_id (&(ieee->h));
1629 if (strcmp (processor, "LIBRARY") == 0)
1630 goto got_wrong_format;
1631 ieee->mb.module_name = read_id (&(ieee->h));
47fda0d3 1632 if (abfd->filename == (const char *) NULL)
49ae03bf
NC
1633 abfd->filename = ieee->mb.module_name;
1634
1635 /* Determine the architecture and machine type of the object file. */
252b5132
RH
1636 {
1637 const bfd_arch_info_type *arch;
1638 char family[10];
1639
7dee875e 1640 /* IEEE does not specify the format of the processor identification
252b5132
RH
1641 string, so the compiler is free to put in it whatever it wants.
1642 We try here to recognize different processors belonging to the
1643 m68k family. Code for other processors can be added here. */
1644 if ((processor[0] == '6') && (processor[1] == '8'))
1645 {
1646 if (processor[2] == '3') /* 683xx integrated processors */
1647 {
1648 switch (processor[3])
1649 {
1650 case '0': /* 68302, 68306, 68307 */
1651 case '2': /* 68322, 68328 */
1652 case '5': /* 68356 */
1653 strcpy (family, "68000"); /* MC68000-based controllers */
1654 break;
1655
1656 case '3': /* 68330, 68331, 68332, 68333,
1657 68334, 68335, 68336, 68338 */
1658 case '6': /* 68360 */
1659 case '7': /* 68376 */
1660 strcpy (family, "68332"); /* CPU32 and CPU32+ */
1661 break;
1662
1663 case '4':
1664 if (processor[4] == '9') /* 68349 */
1665 strcpy (family, "68030"); /* CPU030 */
1666 else /* 68340, 68341 */
1667 strcpy (family, "68332"); /* CPU32 and CPU32+ */
1668 break;
1669
1670 default: /* Does not exist yet */
1671 strcpy (family, "68332"); /* Guess it will be CPU32 */
1672 }
1673 }
3882b010
L
1674 else if (TOUPPER (processor[3]) == 'F') /* 68F333 */
1675 strcpy (family, "68332"); /* CPU32 */
49ae03bf 1676 else if ((TOUPPER (processor[3]) == 'C') /* Embedded controllers. */
3882b010
L
1677 && ((TOUPPER (processor[2]) == 'E')
1678 || (TOUPPER (processor[2]) == 'H')
1679 || (TOUPPER (processor[2]) == 'L')))
252b5132
RH
1680 {
1681 strcpy (family, "68");
1682 strncat (family, processor + 4, 7);
1683 family[9] = '\0';
1684 }
49ae03bf 1685 else /* "Regular" processors. */
252b5132
RH
1686 {
1687 strncpy (family, processor, 9);
1688 family[9] = '\0';
1689 }
1690 }
1691 else if ((strncmp (processor, "cpu32", 5) == 0) /* CPU32 and CPU32+ */
1692 || (strncmp (processor, "CPU32", 5) == 0))
1693 strcpy (family, "68332");
1694 else
1695 {
1696 strncpy (family, processor, 9);
1697 family[9] = '\0';
1698 }
1699
1700 arch = bfd_scan_arch (family);
1701 if (arch == 0)
1702 goto got_wrong_format;
1703 abfd->arch_info = arch;
1704 }
1705
1706 if (this_byte (&(ieee->h)) != (int) ieee_address_descriptor_enum)
49ae03bf
NC
1707 goto fail;
1708
252b5132
RH
1709 next_byte (&(ieee->h));
1710
82e51918 1711 if (! parse_int (&(ieee->h), &ieee->ad.number_of_bits_mau))
49ae03bf
NC
1712 goto fail;
1713
82e51918 1714 if (! parse_int (&(ieee->h), &ieee->ad.number_of_maus_in_address))
49ae03bf 1715 goto fail;
252b5132 1716
49ae03bf
NC
1717 /* If there is a byte order info, take it. */
1718 if (this_byte (&(ieee->h)) == (int) ieee_variable_L_enum
1719 || this_byte (&(ieee->h)) == (int) ieee_variable_M_enum)
252b5132
RH
1720 next_byte (&(ieee->h));
1721
1722 for (part = 0; part < N_W_VARIABLES; part++)
1723 {
b34976b6 1724 bfd_boolean ok;
49ae03bf 1725
252b5132 1726 if (read_2bytes (&(ieee->h)) != (int) ieee_assign_value_to_variable_enum)
49ae03bf
NC
1727 goto fail;
1728
252b5132 1729 if (this_byte_and_next (&(ieee->h)) != part)
49ae03bf 1730 goto fail;
252b5132
RH
1731
1732 ieee->w.offset[part] = parse_i (&(ieee->h), &ok);
82e51918 1733 if (! ok)
49ae03bf 1734 goto fail;
252b5132
RH
1735 }
1736
1737 if (ieee->w.r.external_part != 0)
1738 abfd->flags = HAS_SYMS;
1739
1740 /* By now we know that this is a real IEEE file, we're going to read
1741 the whole thing into memory so that we can run up and down it
1742 quickly. We can work out how big the file is from the trailer
49ae03bf 1743 record. */
252b5132 1744
dc810e39 1745 amt = ieee->w.r.me_record + 1;
252b5132 1746 IEEE_DATA (abfd)->h.first_byte =
dc810e39 1747 (unsigned char *) bfd_alloc (ieee->h.abfd, amt);
252b5132
RH
1748 if (!IEEE_DATA (abfd)->h.first_byte)
1749 goto fail;
1750 if (bfd_seek (abfd, (file_ptr) 0, SEEK_SET) != 0)
1751 goto fail;
1752 /* FIXME: Check return value. I'm not sure whether it needs to read
1753 the entire buffer or not. */
dc810e39
AM
1754 bfd_bread ((PTR) (IEEE_DATA (abfd)->h.first_byte),
1755 (bfd_size_type) ieee->w.r.me_record + 1, abfd);
252b5132
RH
1756
1757 ieee_slurp_sections (abfd);
1758
1759 if (! ieee_slurp_debug (abfd))
1760 goto fail;
1761
1762 /* Parse section data to activate file and section flags implied by
1763 section contents. */
252b5132
RH
1764 if (! ieee_slurp_section_data (abfd))
1765 goto fail;
dc810e39 1766
252b5132
RH
1767 return abfd->xvec;
1768got_wrong_format:
1769 bfd_set_error (bfd_error_wrong_format);
1770fail:
487e54f2 1771 bfd_release (abfd, ieee);
252b5132
RH
1772 abfd->tdata.ieee_data = save;
1773 return (const bfd_target *) NULL;
1774}
1775
47fda0d3 1776static void
252b5132 1777ieee_get_symbol_info (ignore_abfd, symbol, ret)
5f771d47 1778 bfd *ignore_abfd ATTRIBUTE_UNUSED;
252b5132
RH
1779 asymbol *symbol;
1780 symbol_info *ret;
1781{
1782 bfd_symbol_info (symbol, ret);
1783 if (symbol->name[0] == ' ')
1784 ret->name = "* empty table entry ";
1785 if (!symbol->section)
1786 ret->type = (symbol->flags & BSF_LOCAL) ? 'a' : 'A';
1787}
1788
47fda0d3 1789static void
60b89a18
L
1790ieee_print_symbol (abfd, afile, symbol, how)
1791 bfd *abfd;
252b5132
RH
1792 PTR afile;
1793 asymbol *symbol;
1794 bfd_print_symbol_type how;
1795{
1796 FILE *file = (FILE *) afile;
1797
1798 switch (how)
1799 {
1800 case bfd_print_symbol_name:
1801 fprintf (file, "%s", symbol->name);
1802 break;
1803 case bfd_print_symbol_more:
252b5132
RH
1804 BFD_FAIL ();
1805 break;
1806 case bfd_print_symbol_all:
1807 {
1808 const char *section_name =
1809 (symbol->section == (asection *) NULL
1810 ? "*abs"
1811 : symbol->section->name);
49ae03bf 1812
252b5132
RH
1813 if (symbol->name[0] == ' ')
1814 {
1815 fprintf (file, "* empty table entry ");
1816 }
1817 else
1818 {
60b89a18 1819 bfd_print_symbol_vandf (abfd, (PTR) file, symbol);
252b5132
RH
1820
1821 fprintf (file, " %-5s %04x %02x %s",
1822 section_name,
1823 (unsigned) ieee_symbol (symbol)->index,
1824 (unsigned) 0,
1825 symbol->name);
1826 }
1827 }
1828 break;
1829 }
1830}
1831
b34976b6 1832static bfd_boolean
252b5132
RH
1833do_one (ieee, current_map, location_ptr, s, iterations)
1834 ieee_data_type *ieee;
1835 ieee_per_section_type *current_map;
1836 unsigned char *location_ptr;
1837 asection *s;
1838 int iterations;
1839{
1840 switch (this_byte (&(ieee->h)))
1841 {
1842 case ieee_load_constant_bytes_enum:
1843 {
1844 unsigned int number_of_maus;
1845 unsigned int i;
49ae03bf 1846
252b5132
RH
1847 next_byte (&(ieee->h));
1848 number_of_maus = must_parse_int (&(ieee->h));
1849
1850 for (i = 0; i < number_of_maus; i++)
1851 {
1852 location_ptr[current_map->pc++] = this_byte (&(ieee->h));
1853 next_byte (&(ieee->h));
1854 }
1855 }
1856 break;
1857
1858 case ieee_load_with_relocation_enum:
1859 {
b34976b6 1860 bfd_boolean loop = TRUE;
49ae03bf 1861
252b5132
RH
1862 next_byte (&(ieee->h));
1863 while (loop)
1864 {
1865 switch (this_byte (&(ieee->h)))
1866 {
1867 case ieee_variable_R_enum:
1868
1869 case ieee_function_signed_open_b_enum:
1870 case ieee_function_unsigned_open_b_enum:
1871 case ieee_function_either_open_b_enum:
1872 {
1873 unsigned int extra = 4;
b34976b6 1874 bfd_boolean pcrel = FALSE;
252b5132 1875 asection *section;
dc810e39
AM
1876 ieee_reloc_type *r;
1877 bfd_size_type amt = sizeof (ieee_reloc_type);
1878
1879 r = (ieee_reloc_type *) bfd_alloc (ieee->h.abfd, amt);
252b5132 1880 if (!r)
b34976b6 1881 return FALSE;
252b5132
RH
1882
1883 *(current_map->reloc_tail_ptr) = r;
1884 current_map->reloc_tail_ptr = &r->next;
1885 r->next = (ieee_reloc_type *) NULL;
1886 next_byte (&(ieee->h));
1887/* abort();*/
1888 r->relent.sym_ptr_ptr = 0;
1889 parse_expression (ieee,
1890 &r->relent.addend,
1891 &r->symbol,
1892 &pcrel, &extra, &section);
1893 r->relent.address = current_map->pc;
1894 s->flags |= SEC_RELOC;
1895 s->owner->flags |= HAS_RELOC;
1896 s->reloc_count++;
1897 if (r->relent.sym_ptr_ptr == NULL && section != NULL)
1898 r->relent.sym_ptr_ptr = section->symbol_ptr_ptr;
1899
1900 if (this_byte (&(ieee->h)) == (int) ieee_comma)
1901 {
1902 next_byte (&(ieee->h));
49ae03bf 1903 /* Fetch number of bytes to pad. */
252b5132
RH
1904 extra = must_parse_int (&(ieee->h));
1905 };
1906
1907 switch (this_byte (&(ieee->h)))
1908 {
1909 case ieee_function_signed_close_b_enum:
1910 next_byte (&(ieee->h));
1911 break;
1912 case ieee_function_unsigned_close_b_enum:
1913 next_byte (&(ieee->h));
1914 break;
1915 case ieee_function_either_close_b_enum:
1916 next_byte (&(ieee->h));
1917 break;
1918 default:
1919 break;
1920 }
49ae03bf 1921 /* Build a relocation entry for this type. */
252b5132
RH
1922 /* If pc rel then stick -ve pc into instruction
1923 and take out of reloc ..
1924
1925 I've changed this. It's all too complicated. I
1926 keep 0 in the instruction now. */
1927
1928 switch (extra)
1929 {
1930 case 0:
1931 case 4:
1932
82e51918 1933 if (pcrel)
252b5132
RH
1934 {
1935#if KEEPMINUSPCININST
dc810e39
AM
1936 bfd_put_32 (ieee->h.abfd, -current_map->pc,
1937 location_ptr + current_map->pc);
252b5132 1938 r->relent.howto = &rel32_howto;
dc810e39 1939 r->relent.addend -= current_map->pc;
252b5132 1940#else
dc810e39 1941 bfd_put_32 (ieee->h.abfd, (bfd_vma) 0, location_ptr +
252b5132
RH
1942 current_map->pc);
1943 r->relent.howto = &rel32_howto;
1944#endif
1945 }
1946 else
1947 {
dc810e39
AM
1948 bfd_put_32 (ieee->h.abfd, (bfd_vma) 0,
1949 location_ptr + current_map->pc);
252b5132
RH
1950 r->relent.howto = &abs32_howto;
1951 }
1952 current_map->pc += 4;
1953 break;
1954 case 2:
82e51918 1955 if (pcrel)
252b5132
RH
1956 {
1957#if KEEPMINUSPCININST
dc810e39
AM
1958 bfd_put_16 (ieee->h.abfd, (bfd_vma) -current_map->pc,
1959 location_ptr + current_map->pc);
252b5132
RH
1960 r->relent.addend -= current_map->pc;
1961 r->relent.howto = &rel16_howto;
1962#else
1963
dc810e39
AM
1964 bfd_put_16 (ieee->h.abfd, (bfd_vma) 0,
1965 location_ptr + current_map->pc);
252b5132
RH
1966 r->relent.howto = &rel16_howto;
1967#endif
1968 }
1969
1970 else
1971 {
dc810e39
AM
1972 bfd_put_16 (ieee->h.abfd, (bfd_vma) 0,
1973 location_ptr + current_map->pc);
252b5132
RH
1974 r->relent.howto = &abs16_howto;
1975 }
1976 current_map->pc += 2;
1977 break;
1978 case 1:
82e51918 1979 if (pcrel)
252b5132
RH
1980 {
1981#if KEEPMINUSPCININST
1982 bfd_put_8 (ieee->h.abfd, (int) (-current_map->pc), location_ptr + current_map->pc);
1983 r->relent.addend -= current_map->pc;
1984 r->relent.howto = &rel8_howto;
1985#else
1986 bfd_put_8 (ieee->h.abfd, 0, location_ptr + current_map->pc);
1987 r->relent.howto = &rel8_howto;
1988#endif
1989 }
1990 else
1991 {
1992 bfd_put_8 (ieee->h.abfd, 0, location_ptr + current_map->pc);
1993 r->relent.howto = &abs8_howto;
1994 }
1995 current_map->pc += 1;
1996 break;
1997
1998 default:
1999 BFD_FAIL ();
b34976b6 2000 return FALSE;
252b5132
RH
2001 }
2002 }
2003 break;
2004 default:
2005 {
2006 bfd_vma this_size;
82e51918 2007 if (parse_int (&(ieee->h), &this_size))
252b5132
RH
2008 {
2009 unsigned int i;
2010 for (i = 0; i < this_size; i++)
2011 {
2012 location_ptr[current_map->pc++] = this_byte (&(ieee->h));
2013 next_byte (&(ieee->h));
2014 }
2015 }
2016 else
2017 {
b34976b6 2018 loop = FALSE;
252b5132
RH
2019 }
2020 }
2021 }
2022
2023 /* Prevent more than the first load-item of an LR record
2024 from being repeated (MRI convention). */
2025 if (iterations != 1)
b34976b6 2026 loop = FALSE;
252b5132
RH
2027 }
2028 }
2029 }
b34976b6 2030 return TRUE;
252b5132
RH
2031}
2032
49ae03bf
NC
2033/* Read in all the section data and relocation stuff too. */
2034
b34976b6 2035static bfd_boolean
252b5132
RH
2036ieee_slurp_section_data (abfd)
2037 bfd *abfd;
2038{
2039 bfd_byte *location_ptr = (bfd_byte *) NULL;
2040 ieee_data_type *ieee = IEEE_DATA (abfd);
2041 unsigned int section_number;
2042
2043 ieee_per_section_type *current_map = (ieee_per_section_type *) NULL;
2044 asection *s;
49ae03bf 2045 /* Seek to the start of the data area. */
82e51918 2046 if (ieee->read_data)
b34976b6
AM
2047 return TRUE;
2048 ieee->read_data = TRUE;
47fda0d3 2049 ieee_seek (ieee, ieee->w.r.data_part);
252b5132 2050
49ae03bf 2051 /* Allocate enough space for all the section contents. */
252b5132
RH
2052 for (s = abfd->sections; s != (asection *) NULL; s = s->next)
2053 {
68bfbfcc 2054 ieee_per_section_type *per = ieee_per_section (s);
252b5132
RH
2055 if ((s->flags & SEC_DEBUGGING) != 0)
2056 continue;
eea6121a 2057 per->data = (bfd_byte *) bfd_alloc (ieee->h.abfd, s->size);
252b5132 2058 if (!per->data)
b34976b6 2059 return FALSE;
252b5132
RH
2060 per->reloc_tail_ptr =
2061 (ieee_reloc_type **) & (s->relocation);
2062 }
2063
b34976b6 2064 while (TRUE)
252b5132
RH
2065 {
2066 switch (this_byte (&(ieee->h)))
2067 {
49ae03bf 2068 /* IF we see anything strange then quit. */
252b5132 2069 default:
b34976b6 2070 return TRUE;
252b5132
RH
2071
2072 case ieee_set_current_section_enum:
2073 next_byte (&(ieee->h));
2074 section_number = must_parse_int (&(ieee->h));
2075 s = ieee->section_table[section_number];
2076 s->flags |= SEC_LOAD | SEC_HAS_CONTENTS;
68bfbfcc 2077 current_map = ieee_per_section (s);
252b5132 2078 location_ptr = current_map->data - s->vma;
49ae03bf
NC
2079 /* The document I have says that Microtec's compilers reset
2080 this after a sec section, even though the standard says not
2081 to, SO... */
252b5132
RH
2082 current_map->pc = s->vma;
2083 break;
2084
2085 case ieee_e2_first_byte_enum:
2086 next_byte (&(ieee->h));
2087 switch (this_byte (&(ieee->h)))
2088 {
2089 case ieee_set_current_pc_enum & 0xff:
2090 {
2091 bfd_vma value;
2092 ieee_symbol_index_type symbol;
2093 unsigned int extra;
b34976b6 2094 bfd_boolean pcrel;
49ae03bf 2095
252b5132 2096 next_byte (&(ieee->h));
49ae03bf 2097 must_parse_int (&(ieee->h)); /* Throw away section #. */
252b5132
RH
2098 parse_expression (ieee, &value,
2099 &symbol,
2100 &pcrel, &extra,
2101 0);
2102 current_map->pc = value;
eea6121a 2103 BFD_ASSERT ((unsigned) (value - s->vma) <= s->size);
252b5132
RH
2104 }
2105 break;
2106
2107 case ieee_value_starting_address_enum & 0xff:
2108 next_byte (&(ieee->h));
2109 if (this_byte (&(ieee->h)) == ieee_function_either_open_b_enum)
2110 next_byte (&(ieee->h));
2111 abfd->start_address = must_parse_int (&(ieee->h));
49ae03bf 2112 /* We've got to the end of the data now - */
b34976b6 2113 return TRUE;
252b5132
RH
2114 default:
2115 BFD_FAIL ();
b34976b6 2116 return FALSE;
252b5132
RH
2117 }
2118 break;
2119 case ieee_repeat_data_enum:
2120 {
2121 /* Repeat the following LD or LR n times - we do this by
49ae03bf
NC
2122 remembering the stream pointer before running it and
2123 resetting it and running it n times. We special case
2124 the repetition of a repeat_data/load_constant. */
252b5132
RH
2125 unsigned int iterations;
2126 unsigned char *start;
49ae03bf 2127
252b5132
RH
2128 next_byte (&(ieee->h));
2129 iterations = must_parse_int (&(ieee->h));
2130 start = ieee->h.input_p;
49ae03bf
NC
2131 if (start[0] == (int) ieee_load_constant_bytes_enum
2132 && start[1] == 1)
252b5132
RH
2133 {
2134 while (iterations != 0)
2135 {
2136 location_ptr[current_map->pc++] = start[2];
2137 iterations--;
2138 }
2139 next_byte (&(ieee->h));
2140 next_byte (&(ieee->h));
2141 next_byte (&(ieee->h));
2142 }
2143 else
2144 {
2145 while (iterations != 0)
2146 {
2147 ieee->h.input_p = start;
2148 if (!do_one (ieee, current_map, location_ptr, s,
dc810e39 2149 (int) iterations))
b34976b6 2150 return FALSE;
252b5132
RH
2151 iterations--;
2152 }
2153 }
2154 }
2155 break;
2156 case ieee_load_constant_bytes_enum:
2157 case ieee_load_with_relocation_enum:
49ae03bf
NC
2158 if (!do_one (ieee, current_map, location_ptr, s, 1))
2159 return FALSE;
252b5132
RH
2160 }
2161 }
2162}
2163
b34976b6 2164static bfd_boolean
252b5132
RH
2165ieee_new_section_hook (abfd, newsect)
2166 bfd *abfd;
2167 asection *newsect;
2168{
68bfbfcc
AM
2169 newsect->used_by_bfd
2170 = (PTR) bfd_alloc (abfd, (bfd_size_type) sizeof (ieee_per_section_type));
252b5132 2171 if (!newsect->used_by_bfd)
b34976b6 2172 return FALSE;
252b5132
RH
2173 ieee_per_section (newsect)->data = (bfd_byte *) NULL;
2174 ieee_per_section (newsect)->section = newsect;
b34976b6 2175 return TRUE;
252b5132
RH
2176}
2177
47fda0d3 2178static long
252b5132
RH
2179ieee_get_reloc_upper_bound (abfd, asect)
2180 bfd *abfd;
2181 sec_ptr asect;
2182{
2183 if ((asect->flags & SEC_DEBUGGING) != 0)
2184 return 0;
2185 if (! ieee_slurp_section_data (abfd))
2186 return -1;
2187 return (asect->reloc_count + 1) * sizeof (arelent *);
2188}
2189
b34976b6 2190static bfd_boolean
252b5132
RH
2191ieee_get_section_contents (abfd, section, location, offset, count)
2192 bfd *abfd;
2193 sec_ptr section;
2194 PTR location;
2195 file_ptr offset;
2196 bfd_size_type count;
2197{
68bfbfcc 2198 ieee_per_section_type *p = ieee_per_section (section);
252b5132
RH
2199 if ((section->flags & SEC_DEBUGGING) != 0)
2200 return _bfd_generic_get_section_contents (abfd, section, location,
2201 offset, count);
2202 ieee_slurp_section_data (abfd);
2203 (void) memcpy ((PTR) location, (PTR) (p->data + offset), (unsigned) count);
b34976b6 2204 return TRUE;
252b5132
RH
2205}
2206
47fda0d3 2207static long
252b5132
RH
2208ieee_canonicalize_reloc (abfd, section, relptr, symbols)
2209 bfd *abfd;
2210 sec_ptr section;
2211 arelent **relptr;
2212 asymbol **symbols;
2213{
252b5132
RH
2214 ieee_reloc_type *src = (ieee_reloc_type *) (section->relocation);
2215 ieee_data_type *ieee = IEEE_DATA (abfd);
2216
2217 if ((section->flags & SEC_DEBUGGING) != 0)
2218 return 0;
2219
2220 while (src != (ieee_reloc_type *) NULL)
2221 {
49ae03bf 2222 /* Work out which symbol to attach it this reloc to. */
252b5132
RH
2223 switch (src->symbol.letter)
2224 {
2225 case 'I':
2226 src->relent.sym_ptr_ptr =
2227 symbols + src->symbol.index + ieee->external_symbol_base_offset;
2228 break;
2229 case 'X':
2230 src->relent.sym_ptr_ptr =
2231 symbols + src->symbol.index + ieee->external_reference_base_offset;
2232 break;
2233 case 0:
2234 if (src->relent.sym_ptr_ptr != NULL)
2235 src->relent.sym_ptr_ptr =
2236 src->relent.sym_ptr_ptr[0]->section->symbol_ptr_ptr;
2237 break;
2238 default:
2239
2240 BFD_FAIL ();
2241 }
2242 *relptr++ = &src->relent;
2243 src = src->next;
2244 }
2245 *relptr = (arelent *) NULL;
2246 return section->reloc_count;
2247}
2248
2249static int
2250comp (ap, bp)
47fda0d3
AM
2251 const PTR ap;
2252 const PTR bp;
252b5132
RH
2253{
2254 arelent *a = *((arelent **) ap);
2255 arelent *b = *((arelent **) bp);
2256 return a->address - b->address;
2257}
2258
2259/* Write the section headers. */
2260
b34976b6 2261static bfd_boolean
252b5132
RH
2262ieee_write_section_part (abfd)
2263 bfd *abfd;
2264{
2265 ieee_data_type *ieee = IEEE_DATA (abfd);
2266 asection *s;
2267 ieee->w.r.section_part = bfd_tell (abfd);
2268 for (s = abfd->sections; s != (asection *) NULL; s = s->next)
2269 {
2270 if (! bfd_is_abs_section (s)
2271 && (s->flags & SEC_DEBUGGING) == 0)
2272 {
2273 if (! ieee_write_byte (abfd, ieee_section_type_enum)
2274 || ! ieee_write_byte (abfd,
2275 (bfd_byte) (s->index
2276 + IEEE_SECTION_NUMBER_BASE)))
b34976b6 2277 return FALSE;
252b5132
RH
2278
2279 if (abfd->flags & EXEC_P)
2280 {
49ae03bf 2281 /* This image is executable, so output absolute sections. */
252b5132
RH
2282 if (! ieee_write_byte (abfd, ieee_variable_A_enum)
2283 || ! ieee_write_byte (abfd, ieee_variable_S_enum))
b34976b6 2284 return FALSE;
252b5132
RH
2285 }
2286 else
2287 {
2288 if (! ieee_write_byte (abfd, ieee_variable_C_enum))
b34976b6 2289 return FALSE;
252b5132
RH
2290 }
2291
2292 switch (s->flags & (SEC_CODE | SEC_DATA | SEC_ROM))
2293 {
2294 case SEC_CODE | SEC_LOAD:
2295 case SEC_CODE:
2296 if (! ieee_write_byte (abfd, ieee_variable_P_enum))
b34976b6 2297 return FALSE;
252b5132
RH
2298 break;
2299 case SEC_DATA:
2300 default:
2301 if (! ieee_write_byte (abfd, ieee_variable_D_enum))
b34976b6 2302 return FALSE;
252b5132
RH
2303 break;
2304 case SEC_ROM:
2305 case SEC_ROM | SEC_DATA:
2306 case SEC_ROM | SEC_LOAD:
2307 case SEC_ROM | SEC_DATA | SEC_LOAD:
2308 if (! ieee_write_byte (abfd, ieee_variable_R_enum))
b34976b6 2309 return FALSE;
252b5132
RH
2310 }
2311
2312
2313 if (! ieee_write_id (abfd, s->name))
b34976b6 2314 return FALSE;
49ae03bf 2315 /* Alignment. */
252b5132
RH
2316 if (! ieee_write_byte (abfd, ieee_section_alignment_enum)
2317 || ! ieee_write_byte (abfd,
2318 (bfd_byte) (s->index
2319 + IEEE_SECTION_NUMBER_BASE))
dc810e39 2320 || ! ieee_write_int (abfd, (bfd_vma) 1 << s->alignment_power))
b34976b6 2321 return FALSE;
252b5132 2322
49ae03bf 2323 /* Size. */
252b5132
RH
2324 if (! ieee_write_2bytes (abfd, ieee_section_size_enum)
2325 || ! ieee_write_byte (abfd,
2326 (bfd_byte) (s->index
2327 + IEEE_SECTION_NUMBER_BASE))
eea6121a 2328 || ! ieee_write_int (abfd, s->size))
b34976b6 2329 return FALSE;
252b5132
RH
2330 if (abfd->flags & EXEC_P)
2331 {
49ae03bf
NC
2332 /* Relocateable sections don't have asl records. */
2333 /* Vma. */
252b5132
RH
2334 if (! ieee_write_2bytes (abfd, ieee_section_base_address_enum)
2335 || ! ieee_write_byte (abfd,
2336 ((bfd_byte)
2337 (s->index
2338 + IEEE_SECTION_NUMBER_BASE)))
2339 || ! ieee_write_int (abfd, s->lma))
b34976b6 2340 return FALSE;
252b5132
RH
2341 }
2342 }
2343 }
2344
b34976b6 2345 return TRUE;
252b5132
RH
2346}
2347
2348
b34976b6 2349static bfd_boolean
252b5132
RH
2350do_with_relocs (abfd, s)
2351 bfd *abfd;
2352 asection *s;
2353{
2354 unsigned int number_of_maus_in_address =
2355 bfd_arch_bits_per_address (abfd) / bfd_arch_bits_per_byte (abfd);
2356 unsigned int relocs_to_go = s->reloc_count;
2357 bfd_byte *stream = ieee_per_section (s)->data;
2358 arelent **p = s->orelocation;
2359 bfd_size_type current_byte_index = 0;
2360
2361 qsort (s->orelocation,
2362 relocs_to_go,
2363 sizeof (arelent **),
2364 comp);
2365
49ae03bf 2366 /* Output the section preheader. */
252b5132
RH
2367 if (! ieee_write_byte (abfd, ieee_set_current_section_enum)
2368 || ! ieee_write_byte (abfd,
2369 (bfd_byte) (s->index + IEEE_SECTION_NUMBER_BASE))
2370 || ! ieee_write_2bytes (abfd, ieee_set_current_pc_enum)
2371 || ! ieee_write_byte (abfd,
2372 (bfd_byte) (s->index + IEEE_SECTION_NUMBER_BASE)))
b34976b6 2373 return FALSE;
47fda0d3 2374
252b5132
RH
2375 if ((abfd->flags & EXEC_P) != 0 && relocs_to_go == 0)
2376 {
2377 if (! ieee_write_int (abfd, s->lma))
b34976b6 2378 return FALSE;
252b5132
RH
2379 }
2380 else
2381 {
dc810e39 2382 if (! ieee_write_expression (abfd, (bfd_vma) 0, s->symbol, 0, 0))
b34976b6 2383 return FALSE;
252b5132
RH
2384 }
2385
2386 if (relocs_to_go == 0)
2387 {
2388 /* If there aren't any relocations then output the load constant
49ae03bf 2389 byte opcode rather than the load with relocation opcode. */
eea6121a 2390 while (current_byte_index < s->size)
252b5132
RH
2391 {
2392 bfd_size_type run;
2393 unsigned int MAXRUN = 127;
49ae03bf 2394
252b5132 2395 run = MAXRUN;
eea6121a
AM
2396 if (run > s->size - current_byte_index)
2397 run = s->size - current_byte_index;
252b5132
RH
2398
2399 if (run != 0)
2400 {
2401 if (! ieee_write_byte (abfd, ieee_load_constant_bytes_enum))
b34976b6 2402 return FALSE;
49ae03bf 2403 /* Output a stream of bytes. */
252b5132 2404 if (! ieee_write_int (abfd, run))
b34976b6 2405 return FALSE;
dc810e39 2406 if (bfd_bwrite ((PTR) (stream + current_byte_index), run, abfd)
252b5132 2407 != run)
b34976b6 2408 return FALSE;
252b5132
RH
2409 current_byte_index += run;
2410 }
2411 }
2412 }
2413 else
2414 {
2415 if (! ieee_write_byte (abfd, ieee_load_with_relocation_enum))
b34976b6 2416 return FALSE;
252b5132
RH
2417
2418 /* Output the data stream as the longest sequence of bytes
2419 possible, allowing for the a reasonable packet size and
2420 relocation stuffs. */
2421
2422 if ((PTR) stream == (PTR) NULL)
2423 {
49ae03bf 2424 /* Outputting a section without data, fill it up. */
eea6121a 2425 stream = (unsigned char *) bfd_zalloc (abfd, s->size);
252b5132 2426 if (!stream)
b34976b6 2427 return FALSE;
252b5132 2428 }
eea6121a 2429 while (current_byte_index < s->size)
252b5132
RH
2430 {
2431 bfd_size_type run;
2432 unsigned int MAXRUN = 127;
49ae03bf 2433
252b5132
RH
2434 if (relocs_to_go)
2435 {
2436 run = (*p)->address - current_byte_index;
2437 if (run > MAXRUN)
2438 run = MAXRUN;
2439 }
2440 else
49ae03bf
NC
2441 run = MAXRUN;
2442
eea6121a
AM
2443 if (run > s->size - current_byte_index)
2444 run = s->size - current_byte_index;
252b5132
RH
2445
2446 if (run != 0)
2447 {
49ae03bf 2448 /* Output a stream of bytes. */
252b5132 2449 if (! ieee_write_int (abfd, run))
b34976b6 2450 return FALSE;
dc810e39 2451 if (bfd_bwrite ((PTR) (stream + current_byte_index), run, abfd)
252b5132 2452 != run)
b34976b6 2453 return FALSE;
252b5132
RH
2454 current_byte_index += run;
2455 }
49ae03bf
NC
2456
2457 /* Output any relocations here. */
252b5132
RH
2458 if (relocs_to_go && (*p) && (*p)->address == current_byte_index)
2459 {
2460 while (relocs_to_go
2461 && (*p) && (*p)->address == current_byte_index)
2462 {
2463 arelent *r = *p;
2464 bfd_signed_vma ov;
252b5132
RH
2465 switch (r->howto->size)
2466 {
2467 case 2:
2468
2469 ov = bfd_get_signed_32 (abfd,
2470 stream + current_byte_index);
2471 current_byte_index += 4;
2472 break;
2473 case 1:
2474 ov = bfd_get_signed_16 (abfd,
2475 stream + current_byte_index);
2476 current_byte_index += 2;
2477 break;
2478 case 0:
2479 ov = bfd_get_signed_8 (abfd,
2480 stream + current_byte_index);
2481 current_byte_index++;
2482 break;
2483 default:
2484 ov = 0;
2485 BFD_FAIL ();
b34976b6 2486 return FALSE;
252b5132
RH
2487 }
2488
2489 ov &= r->howto->src_mask;
2490
2491 if (r->howto->pc_relative
2492 && ! r->howto->pcrel_offset)
2493 ov += r->address;
2494
2495 if (! ieee_write_byte (abfd,
2496 ieee_function_either_open_b_enum))
b34976b6 2497 return FALSE;
252b5132
RH
2498
2499/* abort();*/
2500
2501 if (r->sym_ptr_ptr != (asymbol **) NULL)
2502 {
2503 if (! ieee_write_expression (abfd, r->addend + ov,
2504 *(r->sym_ptr_ptr),
2505 r->howto->pc_relative,
dc810e39 2506 (unsigned) s->index))
b34976b6 2507 return FALSE;
252b5132
RH
2508 }
2509 else
2510 {
2511 if (! ieee_write_expression (abfd, r->addend + ov,
2512 (asymbol *) NULL,
2513 r->howto->pc_relative,
dc810e39 2514 (unsigned) s->index))
b34976b6 2515 return FALSE;
252b5132
RH
2516 }
2517
2518 if (number_of_maus_in_address
2519 != bfd_get_reloc_size (r->howto))
2520 {
dc810e39
AM
2521 bfd_vma rsize = bfd_get_reloc_size (r->howto);
2522 if (! ieee_write_int (abfd, rsize))
b34976b6 2523 return FALSE;
252b5132
RH
2524 }
2525 if (! ieee_write_byte (abfd,
2526 ieee_function_either_close_b_enum))
b34976b6 2527 return FALSE;
252b5132
RH
2528
2529 relocs_to_go--;
2530 p++;
2531 }
2532
2533 }
2534 }
2535 }
2536
b34976b6 2537 return TRUE;
252b5132
RH
2538}
2539
2540/* If there are no relocations in the output section then we can be
2541 clever about how we write. We block items up into a max of 127
2542 bytes. */
2543
b34976b6 2544static bfd_boolean
252b5132
RH
2545do_as_repeat (abfd, s)
2546 bfd *abfd;
2547 asection *s;
2548{
eea6121a 2549 if (s->size)
252b5132
RH
2550 {
2551 if (! ieee_write_byte (abfd, ieee_set_current_section_enum)
2552 || ! ieee_write_byte (abfd,
2553 (bfd_byte) (s->index
2554 + IEEE_SECTION_NUMBER_BASE))
2555 || ! ieee_write_byte (abfd, ieee_set_current_pc_enum >> 8)
2556 || ! ieee_write_byte (abfd, ieee_set_current_pc_enum & 0xff)
2557 || ! ieee_write_byte (abfd,
2558 (bfd_byte) (s->index
47fda0d3 2559 + IEEE_SECTION_NUMBER_BASE)))
b34976b6 2560 return FALSE;
47fda0d3
AM
2561
2562 if ((abfd->flags & EXEC_P) != 0)
2563 {
2564 if (! ieee_write_int (abfd, s->lma))
b34976b6 2565 return FALSE;
47fda0d3
AM
2566 }
2567 else
2568 {
dc810e39 2569 if (! ieee_write_expression (abfd, (bfd_vma) 0, s->symbol, 0, 0))
b34976b6 2570 return FALSE;
47fda0d3
AM
2571 }
2572
2573 if (! ieee_write_byte (abfd, ieee_repeat_data_enum)
eea6121a 2574 || ! ieee_write_int (abfd, s->size)
252b5132
RH
2575 || ! ieee_write_byte (abfd, ieee_load_constant_bytes_enum)
2576 || ! ieee_write_byte (abfd, 1)
2577 || ! ieee_write_byte (abfd, 0))
b34976b6 2578 return FALSE;
252b5132
RH
2579 }
2580
b34976b6 2581 return TRUE;
252b5132
RH
2582}
2583
b34976b6 2584static bfd_boolean
252b5132
RH
2585do_without_relocs (abfd, s)
2586 bfd *abfd;
2587 asection *s;
2588{
2589 bfd_byte *stream = ieee_per_section (s)->data;
2590
2591 if (stream == 0 || ((s->flags & SEC_LOAD) == 0))
2592 {
2593 if (! do_as_repeat (abfd, s))
b34976b6 2594 return FALSE;
252b5132
RH
2595 }
2596 else
2597 {
2598 unsigned int i;
49ae03bf 2599
eea6121a 2600 for (i = 0; i < s->size; i++)
252b5132
RH
2601 {
2602 if (stream[i] != 0)
2603 {
2604 if (! do_with_relocs (abfd, s))
b34976b6
AM
2605 return FALSE;
2606 return TRUE;
252b5132
RH
2607 }
2608 }
2609 if (! do_as_repeat (abfd, s))
b34976b6 2610 return FALSE;
252b5132
RH
2611 }
2612
b34976b6 2613 return TRUE;
252b5132
RH
2614}
2615
2616
2617static unsigned char *output_ptr_start;
2618static unsigned char *output_ptr;
2619static unsigned char *output_ptr_end;
2620static unsigned char *input_ptr_start;
2621static unsigned char *input_ptr;
2622static unsigned char *input_ptr_end;
2623static bfd *input_bfd;
2624static bfd *output_bfd;
2625static int output_buffer;
2626
b34976b6 2627static bfd_boolean
47fda0d3
AM
2628ieee_mkobject (abfd)
2629 bfd *abfd;
2630{
dc810e39
AM
2631 bfd_size_type amt;
2632
47fda0d3
AM
2633 output_ptr_start = NULL;
2634 output_ptr = NULL;
2635 output_ptr_end = NULL;
2636 input_ptr_start = NULL;
2637 input_ptr = NULL;
2638 input_ptr_end = NULL;
2639 input_bfd = NULL;
2640 output_bfd = NULL;
2641 output_buffer = 0;
dc810e39
AM
2642 amt = sizeof (ieee_data_type);
2643 abfd->tdata.ieee_data = (ieee_data_type *) bfd_zalloc (abfd, amt);
82e51918 2644 return abfd->tdata.ieee_data != NULL;
47fda0d3
AM
2645}
2646
252b5132
RH
2647static void
2648fill ()
2649{
dc810e39 2650 bfd_size_type amt = input_ptr_end - input_ptr_start;
252b5132
RH
2651 /* FIXME: Check return value. I'm not sure whether it needs to read
2652 the entire buffer or not. */
dc810e39 2653 bfd_bread ((PTR) input_ptr_start, amt, input_bfd);
252b5132
RH
2654 input_ptr = input_ptr_start;
2655}
47fda0d3 2656
252b5132
RH
2657static void
2658flush ()
2659{
dc810e39 2660 bfd_size_type amt = output_ptr - output_ptr_start;
49ae03bf 2661
dc810e39 2662 if (bfd_bwrite ((PTR) (output_ptr_start), amt, output_bfd) != amt)
252b5132
RH
2663 abort ();
2664 output_ptr = output_ptr_start;
2665 output_buffer++;
2666}
2667
2668#define THIS() ( *input_ptr )
2669#define NEXT() { input_ptr++; if (input_ptr == input_ptr_end) fill(); }
2670#define OUT(x) { *output_ptr++ = (x); if(output_ptr == output_ptr_end) flush(); }
2671
2672static void
2673write_int (value)
2674 int value;
2675{
2676 if (value >= 0 && value <= 127)
2677 {
2678 OUT (value);
2679 }
2680 else
2681 {
2682 unsigned int length;
49ae03bf
NC
2683 /* How many significant bytes ? */
2684 /* FIXME FOR LONGER INTS. */
252b5132 2685 if (value & 0xff000000)
49ae03bf 2686 length = 4;
252b5132 2687 else if (value & 0x00ff0000)
49ae03bf 2688 length = 3;
252b5132 2689 else if (value & 0x0000ff00)
49ae03bf 2690 length = 2;
252b5132
RH
2691 else
2692 length = 1;
2693
2694 OUT ((int) ieee_number_repeat_start_enum + length);
2695 switch (length)
2696 {
2697 case 4:
2698 OUT (value >> 24);
2699 case 3:
2700 OUT (value >> 16);
2701 case 2:
2702 OUT (value >> 8);
2703 case 1:
2704 OUT (value);
2705 }
252b5132
RH
2706 }
2707}
2708
2709static void
2710copy_id ()
2711{
2712 int length = THIS ();
2713 char ch;
49ae03bf 2714
252b5132
RH
2715 OUT (length);
2716 NEXT ();
2717 while (length--)
2718 {
2719 ch = THIS ();
2720 OUT (ch);
2721 NEXT ();
2722 }
2723}
2724
2725#define VAR(x) ((x | 0x80))
2726static void
2727copy_expression ()
2728{
2729 int stack[10];
2730 int *tos = stack;
dc810e39 2731 int value;
49ae03bf 2732
252b5132
RH
2733 while (1)
2734 {
2735 switch (THIS ())
2736 {
2737 case 0x84:
2738 NEXT ();
2739 value = THIS ();
2740 NEXT ();
2741 value = (value << 8) | THIS ();
2742 NEXT ();
2743 value = (value << 8) | THIS ();
2744 NEXT ();
2745 value = (value << 8) | THIS ();
2746 NEXT ();
2747 *tos++ = value;
2748 break;
2749 case 0x83:
2750 NEXT ();
2751 value = THIS ();
2752 NEXT ();
2753 value = (value << 8) | THIS ();
2754 NEXT ();
2755 value = (value << 8) | THIS ();
2756 NEXT ();
2757 *tos++ = value;
2758 break;
2759 case 0x82:
2760 NEXT ();
2761 value = THIS ();
2762 NEXT ();
2763 value = (value << 8) | THIS ();
2764 NEXT ();
2765 *tos++ = value;
2766 break;
2767 case 0x81:
2768 NEXT ();
2769 value = THIS ();
2770 NEXT ();
2771 *tos++ = value;
2772 break;
2773 case 0x80:
2774 NEXT ();
2775 *tos++ = 0;
2776 break;
2777 default:
2778 if (THIS () > 0x84)
2779 {
49ae03bf 2780 /* Not a number, just bug out with the answer. */
252b5132
RH
2781 write_int (*(--tos));
2782 return;
2783 }
2784 *tos++ = THIS ();
2785 NEXT ();
252b5132
RH
2786 break;
2787 case 0xa5:
49ae03bf 2788 /* PLUS anything. */
dc810e39
AM
2789 value = *(--tos);
2790 value += *(--tos);
2791 *tos++ = value;
2792 NEXT ();
252b5132
RH
2793 break;
2794 case VAR ('R'):
2795 {
2796 int section_number;
2797 ieee_data_type *ieee;
2798 asection *s;
49ae03bf 2799
252b5132
RH
2800 NEXT ();
2801 section_number = THIS ();
2802
2803 NEXT ();
2804 ieee = IEEE_DATA (input_bfd);
2805 s = ieee->section_table[section_number];
dc810e39 2806 value = 0;
252b5132 2807 if (s->output_section)
dc810e39 2808 value = s->output_section->lma;
252b5132
RH
2809 value += s->output_offset;
2810 *tos++ = value;
252b5132
RH
2811 }
2812 break;
2813 case 0x90:
2814 {
2815 NEXT ();
2816 write_int (*(--tos));
2817 OUT (0x90);
2818 return;
252b5132
RH
2819 }
2820 }
2821 }
252b5132
RH
2822}
2823
2824/* Drop the int in the buffer, and copy a null into the gap, which we
2825 will overwrite later */
2826
252b5132
RH
2827static void
2828fill_int (buf)
2829 struct output_buffer_struct *buf;
2830{
2831 if (buf->buffer == output_buffer)
2832 {
49ae03bf 2833 /* Still a chance to output the size. */
252b5132
RH
2834 int value = output_ptr - buf->ptrp + 3;
2835 buf->ptrp[0] = value >> 24;
2836 buf->ptrp[1] = value >> 16;
2837 buf->ptrp[2] = value >> 8;
2838 buf->ptrp[3] = value >> 0;
2839 }
2840}
2841
2842static void
2843drop_int (buf)
2844 struct output_buffer_struct *buf;
2845{
2846 int type = THIS ();
2847 int ch;
49ae03bf 2848
252b5132
RH
2849 if (type <= 0x84)
2850 {
2851 NEXT ();
2852 switch (type)
2853 {
2854 case 0x84:
2855 ch = THIS ();
2856 NEXT ();
2857 case 0x83:
2858 ch = THIS ();
2859 NEXT ();
2860 case 0x82:
2861 ch = THIS ();
2862 NEXT ();
2863 case 0x81:
2864 ch = THIS ();
2865 NEXT ();
2866 case 0x80:
2867 break;
2868 }
2869 }
2870 OUT (0x84);
2871 buf->ptrp = output_ptr;
2872 buf->buffer = output_buffer;
2873 OUT (0);
2874 OUT (0);
2875 OUT (0);
2876 OUT (0);
2877}
2878
2879static void
2880copy_int ()
2881{
2882 int type = THIS ();
2883 int ch;
2884 if (type <= 0x84)
2885 {
2886 OUT (type);
2887 NEXT ();
2888 switch (type)
2889 {
2890 case 0x84:
2891 ch = THIS ();
2892 NEXT ();
2893 OUT (ch);
2894 case 0x83:
2895 ch = THIS ();
2896 NEXT ();
2897 OUT (ch);
2898 case 0x82:
2899 ch = THIS ();
2900 NEXT ();
2901 OUT (ch);
2902 case 0x81:
2903 ch = THIS ();
2904 NEXT ();
2905 OUT (ch);
2906 case 0x80:
2907 break;
2908 }
2909 }
2910}
2911
2912#define ID copy_id()
2913#define INT copy_int()
2914#define EXP copy_expression()
252b5132
RH
2915#define INTn(q) copy_int()
2916#define EXPn(q) copy_expression()
2917
2918static void
2919f1_record ()
2920{
2921 int ch;
49ae03bf
NC
2922
2923 /* ATN record. */
252b5132
RH
2924 NEXT ();
2925 ch = THIS ();
2926 switch (ch)
2927 {
2928 default:
2929 OUT (0xf1);
2930 OUT (ch);
2931 break;
2932 case 0xc9:
2933 NEXT ();
2934 OUT (0xf1);
2935 OUT (0xc9);
2936 INT;
2937 INT;
2938 ch = THIS ();
2939 switch (ch)
2940 {
2941 case 0x16:
2942 NEXT ();
2943 break;
2944 case 0x01:
2945 NEXT ();
2946 break;
2947 case 0x00:
2948 NEXT ();
2949 INT;
2950 break;
2951 case 0x03:
2952 NEXT ();
2953 INT;
2954 break;
2955 case 0x13:
2956 EXPn (instruction address);
2957 break;
2958 default:
2959 break;
2960 }
2961 break;
2962 case 0xd8:
49ae03bf 2963 /* EXternal ref. */
252b5132
RH
2964 NEXT ();
2965 OUT (0xf1);
2966 OUT (0xd8);
2967 EXP;
2968 EXP;
2969 EXP;
2970 EXP;
2971 break;
2972 case 0xce:
2973 NEXT ();
2974 OUT (0xf1);
2975 OUT (0xce);
2976 INT;
2977 INT;
2978 ch = THIS ();
2979 INT;
2980 switch (ch)
2981 {
2982 case 0x01:
2983 INT;
2984 INT;
2985 break;
2986 case 0x02:
2987 INT;
2988 break;
2989 case 0x04:
2990 EXPn (external function);
2991 break;
2992 case 0x05:
2993 break;
2994 case 0x07:
2995 INTn (line number);
2996 INT;
2997 case 0x08:
2998 break;
2999 case 0x0a:
3000 INTn (locked register);
3001 INT;
3002 break;
3003 case 0x3f:
3004 copy_till_end ();
3005 break;
3006 case 0x3e:
3007 copy_till_end ();
3008 break;
3009 case 0x40:
3010 copy_till_end ();
3011 break;
3012 case 0x41:
3013 ID;
3014 break;
3015 }
3016 }
252b5132
RH
3017}
3018
3019static void
3020f0_record ()
3021{
49ae03bf 3022 /* Attribute record. */
252b5132
RH
3023 NEXT ();
3024 OUT (0xf0);
3025 INTn (Symbol name);
3026 ID;
3027}
3028
3029static void
3030copy_till_end ()
3031{
3032 int ch = THIS ();
49ae03bf 3033
252b5132
RH
3034 while (1)
3035 {
3036 while (ch <= 0x80)
3037 {
3038 OUT (ch);
3039 NEXT ();
3040 ch = THIS ();
3041 }
3042 switch (ch)
3043 {
3044 case 0x84:
3045 OUT (THIS ());
3046 NEXT ();
3047 case 0x83:
3048 OUT (THIS ());
3049 NEXT ();
3050 case 0x82:
3051 OUT (THIS ());
3052 NEXT ();
3053 case 0x81:
3054 OUT (THIS ());
3055 NEXT ();
3056 OUT (THIS ());
3057 NEXT ();
3058
3059 ch = THIS ();
3060 break;
3061 default:
3062 return;
3063 }
3064 }
3065
3066}
3067
3068static void
3069f2_record ()
3070{
3071 NEXT ();
3072 OUT (0xf2);
3073 INT;
3074 NEXT ();
3075 OUT (0xce);
3076 INT;
3077 copy_till_end ();
3078}
3079
3080
252b5132
RH
3081static void
3082f8_record ()
3083{
3084 int ch;
3085 NEXT ();
3086 ch = THIS ();
3087 switch (ch)
3088 {
3089 case 0x01:
3090 case 0x02:
3091 case 0x03:
49ae03bf
NC
3092 /* Unique typedefs for module. */
3093 /* GLobal typedefs. */
3094 /* High level module scope beginning. */
252b5132
RH
3095 {
3096 struct output_buffer_struct ob;
49ae03bf 3097
252b5132
RH
3098 NEXT ();
3099 OUT (0xf8);
3100 OUT (ch);
3101 drop_int (&ob);
3102 ID;
3103
3104 block ();
3105
3106 NEXT ();
3107 fill_int (&ob);
3108 OUT (0xf9);
3109 }
3110 break;
3111 case 0x04:
49ae03bf 3112 /* Global function. */
252b5132
RH
3113 {
3114 struct output_buffer_struct ob;
49ae03bf 3115
252b5132
RH
3116 NEXT ();
3117 OUT (0xf8);
3118 OUT (0x04);
3119 drop_int (&ob);
3120 ID;
3121 INTn (stack size);
3122 INTn (ret val);
3123 EXPn (offset);
3124
3125 block ();
3126
3127 NEXT ();
3128 OUT (0xf9);
3129 EXPn (size of block);
3130 fill_int (&ob);
3131 }
3132 break;
3133
3134 case 0x05:
49ae03bf 3135 /* File name for source line numbers. */
252b5132
RH
3136 {
3137 struct output_buffer_struct ob;
49ae03bf 3138
252b5132
RH
3139 NEXT ();
3140 OUT (0xf8);
3141 OUT (0x05);
3142 drop_int (&ob);
3143 ID;
3144 INTn (year);
3145 INTn (month);
3146 INTn (day);
3147 INTn (hour);
3148 INTn (monute);
3149 INTn (second);
3150 block ();
3151 NEXT ();
3152 OUT (0xf9);
3153 fill_int (&ob);
3154 }
3155 break;
3156
3157 case 0x06:
49ae03bf 3158 /* Local function. */
252b5132
RH
3159 {
3160 struct output_buffer_struct ob;
49ae03bf 3161
252b5132
RH
3162 NEXT ();
3163 OUT (0xf8);
3164 OUT (0x06);
3165 drop_int (&ob);
3166 ID;
3167 INTn (stack size);
3168 INTn (type return);
3169 EXPn (offset);
3170 block ();
3171 NEXT ();
3172 OUT (0xf9);
3173 EXPn (size);
3174 fill_int (&ob);
3175 }
3176 break;
3177
3178 case 0x0a:
49ae03bf 3179 /* Assembler module scope beginning - */
252b5132
RH
3180 {
3181 struct output_buffer_struct ob;
3182
3183 NEXT ();
3184 OUT (0xf8);
3185 OUT (0x0a);
3186 drop_int (&ob);
3187 ID;
3188 ID;
3189 INT;
3190 ID;
3191 INT;
3192 INT;
3193 INT;
3194 INT;
3195 INT;
3196 INT;
3197
3198 block ();
3199
3200 NEXT ();
3201 OUT (0xf9);
3202 fill_int (&ob);
3203 }
3204 break;
3205 case 0x0b:
3206 {
3207 struct output_buffer_struct ob;
49ae03bf 3208
252b5132
RH
3209 NEXT ();
3210 OUT (0xf8);
3211 OUT (0x0b);
3212 drop_int (&ob);
3213 ID;
3214 INT;
3215 INTn (section index);
3216 EXPn (offset);
3217 INTn (stuff);
3218
3219 block ();
3220
3221 OUT (0xf9);
3222 NEXT ();
3223 EXPn (Size in Maus);
3224 fill_int (&ob);
3225 }
3226 break;
3227 }
3228}
3229
3230static void
3231e2_record ()
3232{
3233 OUT (0xe2);
3234 NEXT ();
3235 OUT (0xce);
3236 NEXT ();
3237 INT;
3238 EXP;
3239}
3240
3241static void
3242block ()
3243{
3244 int ch;
49ae03bf 3245
252b5132
RH
3246 while (1)
3247 {
3248 ch = THIS ();
3249 switch (ch)
3250 {
3251 case 0xe1:
3252 case 0xe5:
3253 return;
3254 case 0xf9:
3255 return;
3256 case 0xf0:
3257 f0_record ();
3258 break;
3259 case 0xf1:
3260 f1_record ();
3261 break;
3262 case 0xf2:
3263 f2_record ();
3264 break;
3265 case 0xf8:
3266 f8_record ();
3267 break;
3268 case 0xe2:
3269 e2_record ();
3270 break;
3271
3272 }
3273 }
3274}
3275
3276
49ae03bf
NC
3277/* Moves all the debug information from the source bfd to the output
3278 bfd, and relocates any expressions it finds. */
252b5132
RH
3279
3280static void
3281relocate_debug (output, input)
5f771d47 3282 bfd *output ATTRIBUTE_UNUSED;
252b5132
RH
3283 bfd *input;
3284{
3285#define IBS 400
3286#define OBS 400
3287 unsigned char input_buffer[IBS];
3288
3289 input_ptr_start = input_ptr = input_buffer;
3290 input_ptr_end = input_buffer + IBS;
3291 input_bfd = input;
3292 /* FIXME: Check return value. I'm not sure whether it needs to read
3293 the entire buffer or not. */
dc810e39 3294 bfd_bread ((PTR) input_ptr_start, (bfd_size_type) IBS, input);
252b5132
RH
3295 block ();
3296}
3297
dce61835
KH
3298/* Gather together all the debug information from each input BFD into
3299 one place, relocating it and emitting it as we go. */
252b5132 3300
b34976b6 3301static bfd_boolean
252b5132
RH
3302ieee_write_debug_part (abfd)
3303 bfd *abfd;
3304{
3305 ieee_data_type *ieee = IEEE_DATA (abfd);
3306 bfd_chain_type *chain = ieee->chain_root;
dc810e39 3307 unsigned char obuff[OBS];
b34976b6 3308 bfd_boolean some_debug = FALSE;
252b5132
RH
3309 file_ptr here = bfd_tell (abfd);
3310
dc810e39
AM
3311 output_ptr_start = output_ptr = obuff;
3312 output_ptr_end = obuff + OBS;
3313 output_ptr = obuff;
252b5132
RH
3314 output_bfd = abfd;
3315
3316 if (chain == (bfd_chain_type *) NULL)
3317 {
3318 asection *s;
3319
3320 for (s = abfd->sections; s != NULL; s = s->next)
3321 if ((s->flags & SEC_DEBUGGING) != 0)
3322 break;
3323 if (s == NULL)
3324 {
3325 ieee->w.r.debug_information_part = 0;
b34976b6 3326 return TRUE;
252b5132
RH
3327 }
3328
3329 ieee->w.r.debug_information_part = here;
eea6121a 3330 if (bfd_bwrite (s->contents, s->size, abfd) != s->size)
b34976b6 3331 return FALSE;
252b5132
RH
3332 }
3333 else
3334 {
3335 while (chain != (bfd_chain_type *) NULL)
3336 {
3337 bfd *entry = chain->this;
3338 ieee_data_type *entry_ieee = IEEE_DATA (entry);
49ae03bf 3339
252b5132
RH
3340 if (entry_ieee->w.r.debug_information_part)
3341 {
3342 if (bfd_seek (entry, entry_ieee->w.r.debug_information_part,
dc810e39 3343 SEEK_SET) != 0)
b34976b6 3344 return FALSE;
252b5132
RH
3345 relocate_debug (abfd, entry);
3346 }
3347
3348 chain = chain->next;
3349 }
49ae03bf 3350
252b5132 3351 if (some_debug)
49ae03bf 3352 ieee->w.r.debug_information_part = here;
252b5132 3353 else
49ae03bf 3354 ieee->w.r.debug_information_part = 0;
252b5132
RH
3355
3356 flush ();
3357 }
3358
b34976b6 3359 return TRUE;
252b5132
RH
3360}
3361
3362/* Write the data in an ieee way. */
3363
b34976b6 3364static bfd_boolean
252b5132
RH
3365ieee_write_data_part (abfd)
3366 bfd *abfd;
3367{
3368 asection *s;
49ae03bf 3369
252b5132
RH
3370 ieee_data_type *ieee = IEEE_DATA (abfd);
3371 ieee->w.r.data_part = bfd_tell (abfd);
49ae03bf 3372
252b5132
RH
3373 for (s = abfd->sections; s != (asection *) NULL; s = s->next)
3374 {
3375 /* Skip sections that have no loadable contents (.bss,
3376 debugging, etc.) */
3377 if ((s->flags & SEC_LOAD) == 0)
3378 continue;
3379
3380 /* Sort the reloc records so we can insert them in the correct
3381 places */
3382 if (s->reloc_count != 0)
3383 {
3384 if (! do_with_relocs (abfd, s))
b34976b6 3385 return FALSE;
252b5132
RH
3386 }
3387 else
3388 {
3389 if (! do_without_relocs (abfd, s))
b34976b6 3390 return FALSE;
252b5132
RH
3391 }
3392 }
3393
b34976b6 3394 return TRUE;
252b5132
RH
3395}
3396
3397
b34976b6 3398static bfd_boolean
252b5132
RH
3399init_for_output (abfd)
3400 bfd *abfd;
3401{
3402 asection *s;
49ae03bf 3403
252b5132
RH
3404 for (s = abfd->sections; s != (asection *) NULL; s = s->next)
3405 {
3406 if ((s->flags & SEC_DEBUGGING) != 0)
3407 continue;
eea6121a 3408 if (s->size != 0)
252b5132 3409 {
eea6121a 3410 bfd_size_type size = s->size;
dc810e39 3411 ieee_per_section (s)->data = (bfd_byte *) (bfd_alloc (abfd, size));
252b5132 3412 if (!ieee_per_section (s)->data)
b34976b6 3413 return FALSE;
252b5132
RH
3414 }
3415 }
b34976b6 3416 return TRUE;
252b5132
RH
3417}
3418\f
49ae03bf
NC
3419/* Exec and core file sections. */
3420
3421/* Set section contents is complicated with IEEE since the format is
3422 not a byte image, but a record stream. */
252b5132 3423
b34976b6 3424static bfd_boolean
252b5132
RH
3425ieee_set_section_contents (abfd, section, location, offset, count)
3426 bfd *abfd;
3427 sec_ptr section;
0f867abe 3428 const PTR location;
252b5132
RH
3429 file_ptr offset;
3430 bfd_size_type count;
3431{
3432 if ((section->flags & SEC_DEBUGGING) != 0)
3433 {
3434 if (section->contents == NULL)
3435 {
eea6121a 3436 bfd_size_type size = section->size;
dc810e39 3437 section->contents = (unsigned char *) bfd_alloc (abfd, size);
252b5132 3438 if (section->contents == NULL)
b34976b6 3439 return FALSE;
252b5132
RH
3440 }
3441 /* bfd_set_section_contents has already checked that everything
3442 is within range. */
dc810e39 3443 memcpy (section->contents + offset, location, (size_t) count);
b34976b6 3444 return TRUE;
252b5132
RH
3445 }
3446
3447 if (ieee_per_section (section)->data == (bfd_byte *) NULL)
3448 {
3449 if (!init_for_output (abfd))
b34976b6 3450 return FALSE;
252b5132
RH
3451 }
3452 memcpy ((PTR) (ieee_per_section (section)->data + offset),
3453 (PTR) location,
3454 (unsigned int) count);
b34976b6 3455 return TRUE;
252b5132
RH
3456}
3457
3458/* Write the external symbols of a file. IEEE considers two sorts of
3459 external symbols, public, and referenced. It uses to internal
3460 forms to index them as well. When we write them out we turn their
3461 symbol values into indexes from the right base. */
3462
b34976b6 3463static bfd_boolean
252b5132
RH
3464ieee_write_external_part (abfd)
3465 bfd *abfd;
3466{
3467 asymbol **q;
3468 ieee_data_type *ieee = IEEE_DATA (abfd);
252b5132
RH
3469 unsigned int reference_index = IEEE_REFERENCE_BASE;
3470 unsigned int public_index = IEEE_PUBLIC_BASE + 2;
3471 file_ptr here = bfd_tell (abfd);
b34976b6 3472 bfd_boolean hadone = FALSE;
49ae03bf 3473
252b5132
RH
3474 if (abfd->outsymbols != (asymbol **) NULL)
3475 {
3476
3477 for (q = abfd->outsymbols; *q != (asymbol *) NULL; q++)
3478 {
3479 asymbol *p = *q;
49ae03bf 3480
252b5132
RH
3481 if (bfd_is_und_section (p->section))
3482 {
49ae03bf 3483 /* This must be a symbol reference. */
252b5132 3484 if (! ieee_write_byte (abfd, ieee_external_reference_enum)
dc810e39 3485 || ! ieee_write_int (abfd, (bfd_vma) reference_index)
252b5132 3486 || ! ieee_write_id (abfd, p->name))
b34976b6 3487 return FALSE;
252b5132
RH
3488 p->value = reference_index;
3489 reference_index++;
b34976b6 3490 hadone = TRUE;
252b5132
RH
3491 }
3492 else if (bfd_is_com_section (p->section))
3493 {
49ae03bf 3494 /* This is a weak reference. */
252b5132 3495 if (! ieee_write_byte (abfd, ieee_external_reference_enum)
dc810e39 3496 || ! ieee_write_int (abfd, (bfd_vma) reference_index)
252b5132
RH
3497 || ! ieee_write_id (abfd, p->name)
3498 || ! ieee_write_byte (abfd,
3499 ieee_weak_external_reference_enum)
dc810e39 3500 || ! ieee_write_int (abfd, (bfd_vma) reference_index)
252b5132 3501 || ! ieee_write_int (abfd, p->value))
b34976b6 3502 return FALSE;
252b5132
RH
3503 p->value = reference_index;
3504 reference_index++;
b34976b6 3505 hadone = TRUE;
252b5132
RH
3506 }
3507 else if (p->flags & BSF_GLOBAL)
3508 {
49ae03bf 3509 /* This must be a symbol definition. */
252b5132 3510 if (! ieee_write_byte (abfd, ieee_external_symbol_enum)
dc810e39 3511 || ! ieee_write_int (abfd, (bfd_vma) public_index)
252b5132
RH
3512 || ! ieee_write_id (abfd, p->name)
3513 || ! ieee_write_2bytes (abfd, ieee_attribute_record_enum)
dc810e39 3514 || ! ieee_write_int (abfd, (bfd_vma) public_index)
252b5132
RH
3515 || ! ieee_write_byte (abfd, 15) /* instruction address */
3516 || ! ieee_write_byte (abfd, 19) /* static symbol */
3517 || ! ieee_write_byte (abfd, 1)) /* one of them */
b34976b6 3518 return FALSE;
252b5132 3519
49ae03bf 3520 /* Write out the value. */
252b5132 3521 if (! ieee_write_2bytes (abfd, ieee_value_record_enum)
dc810e39 3522 || ! ieee_write_int (abfd, (bfd_vma) public_index))
b34976b6 3523 return FALSE;
252b5132
RH
3524 if (! bfd_is_abs_section (p->section))
3525 {
3526 if (abfd->flags & EXEC_P)
3527 {
3528 /* If fully linked, then output all symbols
49ae03bf 3529 relocated. */
252b5132
RH
3530 if (! (ieee_write_int
3531 (abfd,
3532 (p->value
3533 + p->section->output_offset
3534 + p->section->output_section->vma))))
b34976b6 3535 return FALSE;
252b5132
RH
3536 }
3537 else
3538 {
3539 if (! (ieee_write_expression
3540 (abfd,
3541 p->value + p->section->output_offset,
3542 p->section->output_section->symbol,
b34976b6
AM
3543 FALSE, 0)))
3544 return FALSE;
252b5132
RH
3545 }
3546 }
3547 else
3548 {
3549 if (! ieee_write_expression (abfd,
3550 p->value,
3551 bfd_abs_section_ptr->symbol,
b34976b6
AM
3552 FALSE, 0))
3553 return FALSE;
252b5132
RH
3554 }
3555 p->value = public_index;
3556 public_index++;
b34976b6 3557 hadone = TRUE;
252b5132
RH
3558 }
3559 else
3560 {
49ae03bf
NC
3561 /* This can happen - when there are gaps in the symbols read
3562 from an input ieee file. */
252b5132
RH
3563 }
3564 }
3565 }
3566 if (hadone)
3567 ieee->w.r.external_part = here;
3568
b34976b6 3569 return TRUE;
252b5132
RH
3570}
3571
3572
47fda0d3 3573static const unsigned char exten[] =
252b5132
RH
3574{
3575 0xf0, 0x20, 0x00,
49ae03bf
NC
3576 0xf1, 0xce, 0x20, 0x00, 37, 3, 3, /* Set version 3 rev 3. */
3577 0xf1, 0xce, 0x20, 0x00, 39, 2, /* Keep symbol in original case. */
1049f94e 3578 0xf1, 0xce, 0x20, 0x00, 38 /* Set object type relocatable to x. */
252b5132
RH
3579};
3580
47fda0d3 3581static const unsigned char envi[] =
252b5132
RH
3582{
3583 0xf0, 0x21, 0x00,
3584
3585/* 0xf1, 0xce, 0x21, 00, 50, 0x82, 0x07, 0xc7, 0x09, 0x11, 0x11,
3586 0x19, 0x2c,
3587*/
3588 0xf1, 0xce, 0x21, 00, 52, 0x00, /* exec ok */
3589
3590 0xf1, 0xce, 0x21, 0, 53, 0x03,/* host unix */
3591/* 0xf1, 0xce, 0x21, 0, 54, 2,1,1 tool & version # */
3592};
3593
b34976b6 3594static bfd_boolean
252b5132
RH
3595ieee_write_me_part (abfd)
3596 bfd *abfd;
3597{
3598 ieee_data_type *ieee = IEEE_DATA (abfd);
3599 ieee->w.r.trailer_part = bfd_tell (abfd);
3600 if (abfd->start_address)
3601 {
3602 if (! ieee_write_2bytes (abfd, ieee_value_starting_address_enum)
3603 || ! ieee_write_byte (abfd, ieee_function_either_open_b_enum)
3604 || ! ieee_write_int (abfd, abfd->start_address)
3605 || ! ieee_write_byte (abfd, ieee_function_either_close_b_enum))
b34976b6 3606 return FALSE;
252b5132
RH
3607 }
3608 ieee->w.r.me_record = bfd_tell (abfd);
3609 if (! ieee_write_byte (abfd, ieee_module_end_enum))
b34976b6
AM
3610 return FALSE;
3611 return TRUE;
252b5132
RH
3612}
3613
3614/* Write out the IEEE processor ID. */
3615
b34976b6 3616static bfd_boolean
252b5132
RH
3617ieee_write_processor (abfd)
3618 bfd *abfd;
3619{
3620 const bfd_arch_info_type *arch;
3621
3622 arch = bfd_get_arch_info (abfd);
3623 switch (arch->arch)
3624 {
3625 default:
3626 if (! ieee_write_id (abfd, bfd_printable_name (abfd)))
b34976b6 3627 return FALSE;
252b5132
RH
3628 break;
3629
3630 case bfd_arch_a29k:
3631 if (! ieee_write_id (abfd, "29000"))
b34976b6 3632 return FALSE;
252b5132
RH
3633 break;
3634
3635 case bfd_arch_h8300:
3636 if (! ieee_write_id (abfd, "H8/300"))
b34976b6 3637 return FALSE;
252b5132
RH
3638 break;
3639
3640 case bfd_arch_h8500:
3641 if (! ieee_write_id (abfd, "H8/500"))
b34976b6 3642 return FALSE;
252b5132
RH
3643 break;
3644
3645 case bfd_arch_i960:
3646 switch (arch->mach)
3647 {
3648 default:
3649 case bfd_mach_i960_core:
3650 case bfd_mach_i960_ka_sa:
3651 if (! ieee_write_id (abfd, "80960KA"))
b34976b6 3652 return FALSE;
252b5132
RH
3653 break;
3654
3655 case bfd_mach_i960_kb_sb:
3656 if (! ieee_write_id (abfd, "80960KB"))
b34976b6 3657 return FALSE;
252b5132
RH
3658 break;
3659
3660 case bfd_mach_i960_ca:
3661 if (! ieee_write_id (abfd, "80960CA"))
b34976b6 3662 return FALSE;
252b5132
RH
3663 break;
3664
3665 case bfd_mach_i960_mc:
3666 case bfd_mach_i960_xa:
3667 if (! ieee_write_id (abfd, "80960MC"))
b34976b6 3668 return FALSE;
252b5132
RH
3669 break;
3670 }
3671 break;
3672
3673 case bfd_arch_m68k:
3674 {
3675 const char *id;
3676
3677 switch (arch->mach)
3678 {
3679 default: id = "68020"; break;
3680 case bfd_mach_m68000: id = "68000"; break;
3681 case bfd_mach_m68008: id = "68008"; break;
3682 case bfd_mach_m68010: id = "68010"; break;
3683 case bfd_mach_m68020: id = "68020"; break;
3684 case bfd_mach_m68030: id = "68030"; break;
3685 case bfd_mach_m68040: id = "68040"; break;
3686 case bfd_mach_m68060: id = "68060"; break;
3687 case bfd_mach_cpu32: id = "cpu32"; break;
3cac17ae
NC
3688 case bfd_mach_mcf5200:id = "5200"; break;
3689 case bfd_mach_mcf5206e:id = "5206e"; break;
3690 case bfd_mach_mcf5307:id = "5307"; break;
3691 case bfd_mach_mcf5407:id = "5407"; break;
3e602632 3692 case bfd_mach_mcf528x:id = "5282"; break;
252b5132
RH
3693 }
3694
3695 if (! ieee_write_id (abfd, id))
b34976b6 3696 return FALSE;
252b5132
RH
3697 }
3698 break;
3699 }
3700
b34976b6 3701 return TRUE;
252b5132
RH
3702}
3703
b34976b6 3704static bfd_boolean
252b5132
RH
3705ieee_write_object_contents (abfd)
3706 bfd *abfd;
3707{
3708 ieee_data_type *ieee = IEEE_DATA (abfd);
3709 unsigned int i;
3710 file_ptr old;
3711
49ae03bf 3712 /* Fast forward over the header area. */
252b5132 3713 if (bfd_seek (abfd, (file_ptr) 0, SEEK_SET) != 0)
b34976b6 3714 return FALSE;
252b5132
RH
3715
3716 if (! ieee_write_byte (abfd, ieee_module_beginning_enum)
3717 || ! ieee_write_processor (abfd)
3718 || ! ieee_write_id (abfd, abfd->filename))
b34976b6 3719 return FALSE;
252b5132 3720
49ae03bf 3721 /* Fast forward over the variable bits. */
252b5132 3722 if (! ieee_write_byte (abfd, ieee_address_descriptor_enum))
b34976b6 3723 return FALSE;
252b5132 3724
49ae03bf 3725 /* Bits per MAU. */
252b5132 3726 if (! ieee_write_byte (abfd, (bfd_byte) (bfd_arch_bits_per_byte (abfd))))
b34976b6 3727 return FALSE;
49ae03bf 3728 /* MAU's per address. */
252b5132
RH
3729 if (! ieee_write_byte (abfd,
3730 (bfd_byte) (bfd_arch_bits_per_address (abfd)
3731 / bfd_arch_bits_per_byte (abfd))))
b34976b6 3732 return FALSE;
252b5132
RH
3733
3734 old = bfd_tell (abfd);
3735 if (bfd_seek (abfd, (file_ptr) (8 * N_W_VARIABLES), SEEK_CUR) != 0)
b34976b6 3736 return FALSE;
252b5132
RH
3737
3738 ieee->w.r.extension_record = bfd_tell (abfd);
dc810e39
AM
3739 if (bfd_bwrite ((char *) exten, (bfd_size_type) sizeof (exten), abfd)
3740 != sizeof (exten))
b34976b6 3741 return FALSE;
252b5132
RH
3742 if (abfd->flags & EXEC_P)
3743 {
3744 if (! ieee_write_byte (abfd, 0x1)) /* Absolute */
b34976b6 3745 return FALSE;
252b5132
RH
3746 }
3747 else
3748 {
3749 if (! ieee_write_byte (abfd, 0x2)) /* Relocateable */
b34976b6 3750 return FALSE;
252b5132
RH
3751 }
3752
3753 ieee->w.r.environmental_record = bfd_tell (abfd);
dc810e39
AM
3754 if (bfd_bwrite ((char *) envi, (bfd_size_type) sizeof (envi), abfd)
3755 != sizeof (envi))
b34976b6 3756 return FALSE;
252b5132
RH
3757
3758 /* The HP emulator database requires a timestamp in the file. */
3759 {
3760 time_t now;
3761 const struct tm *t;
3762
3763 time (&now);
3764 t = (struct tm *) localtime (&now);
3765 if (! ieee_write_2bytes (abfd, (int) ieee_atn_record_enum)
3766 || ! ieee_write_byte (abfd, 0x21)
3767 || ! ieee_write_byte (abfd, 0)
3768 || ! ieee_write_byte (abfd, 50)
dc810e39
AM
3769 || ! ieee_write_int (abfd, (bfd_vma) (t->tm_year + 1900))
3770 || ! ieee_write_int (abfd, (bfd_vma) (t->tm_mon + 1))
3771 || ! ieee_write_int (abfd, (bfd_vma) t->tm_mday)
3772 || ! ieee_write_int (abfd, (bfd_vma) t->tm_hour)
3773 || ! ieee_write_int (abfd, (bfd_vma) t->tm_min)
3774 || ! ieee_write_int (abfd, (bfd_vma) t->tm_sec))
b34976b6 3775 return FALSE;
252b5132
RH
3776 }
3777
3778 output_bfd = abfd;
3779
3780 flush ();
3781
3782 if (! ieee_write_section_part (abfd))
b34976b6 3783 return FALSE;
252b5132
RH
3784 /* First write the symbols. This changes their values into table
3785 indeces so we cant use it after this point. */
3786 if (! ieee_write_external_part (abfd))
b34976b6 3787 return FALSE;
252b5132 3788
252b5132
RH
3789 /* Write any debugs we have been told about. */
3790 if (! ieee_write_debug_part (abfd))
b34976b6 3791 return FALSE;
252b5132
RH
3792
3793 /* Can only write the data once the symbols have been written, since
3794 the data contains relocation information which points to the
3795 symbols. */
3796 if (! ieee_write_data_part (abfd))
b34976b6 3797 return FALSE;
252b5132
RH
3798
3799 /* At the end we put the end! */
3800 if (! ieee_write_me_part (abfd))
b34976b6 3801 return FALSE;
252b5132 3802
49ae03bf 3803 /* Generate the header. */
252b5132 3804 if (bfd_seek (abfd, old, SEEK_SET) != 0)
b34976b6 3805 return FALSE;
252b5132
RH
3806
3807 for (i = 0; i < N_W_VARIABLES; i++)
3808 {
3809 if (! ieee_write_2bytes (abfd, ieee_assign_value_to_variable_enum)
3810 || ! ieee_write_byte (abfd, (bfd_byte) i)
dc810e39 3811 || ! ieee_write_int5_out (abfd, (bfd_vma) ieee->w.offset[i]))
b34976b6 3812 return FALSE;
252b5132
RH
3813 }
3814
b34976b6 3815 return TRUE;
252b5132
RH
3816}
3817\f
3818/* Native-level interface to symbols. */
3819
3820/* We read the symbols into a buffer, which is discarded when this
3821 function exits. We read the strings into a buffer large enough to
49ae03bf 3822 hold them all plus all the cached symbol entries. */
252b5132 3823
47fda0d3 3824static asymbol *
252b5132
RH
3825ieee_make_empty_symbol (abfd)
3826 bfd *abfd;
3827{
dc810e39
AM
3828 bfd_size_type amt = sizeof (ieee_symbol_type);
3829 ieee_symbol_type *new = (ieee_symbol_type *) bfd_zalloc (abfd, amt);
49ae03bf 3830
252b5132
RH
3831 if (!new)
3832 return NULL;
3833 new->symbol.the_bfd = abfd;
3834 return &new->symbol;
3835}
3836
3837static bfd *
3838ieee_openr_next_archived_file (arch, prev)
3839 bfd *arch;
3840 bfd *prev;
3841{
3842 ieee_ar_data_type *ar = IEEE_AR_DATA (arch);
49ae03bf
NC
3843
3844 /* Take the next one from the arch state, or reset. */
252b5132 3845 if (prev == (bfd *) NULL)
49ae03bf
NC
3846 /* Reset the index - the first two entries are bogus. */
3847 ar->element_index = 2;
3848
b34976b6 3849 while (TRUE)
252b5132
RH
3850 {
3851 ieee_ar_obstack_type *p = ar->elements + ar->element_index;
49ae03bf 3852
252b5132
RH
3853 ar->element_index++;
3854 if (ar->element_index <= ar->element_count)
3855 {
3856 if (p->file_offset != (file_ptr) 0)
3857 {
3858 if (p->abfd == (bfd *) NULL)
3859 {
3860 p->abfd = _bfd_create_empty_archive_element_shell (arch);
3861 p->abfd->origin = p->file_offset;
3862 }
3863 return p->abfd;
3864 }
3865 }
3866 else
3867 {
3868 bfd_set_error (bfd_error_no_more_archived_files);
3869 return (bfd *) NULL;
3870 }
252b5132
RH
3871 }
3872}
3873
b34976b6 3874static bfd_boolean
47fda0d3
AM
3875ieee_find_nearest_line (abfd, section, symbols, offset, filename_ptr,
3876 functionname_ptr, line_ptr)
5f771d47
ILT
3877 bfd *abfd ATTRIBUTE_UNUSED;
3878 asection *section ATTRIBUTE_UNUSED;
3879 asymbol **symbols ATTRIBUTE_UNUSED;
3880 bfd_vma offset ATTRIBUTE_UNUSED;
3881 const char **filename_ptr ATTRIBUTE_UNUSED;
3882 const char **functionname_ptr ATTRIBUTE_UNUSED;
3883 unsigned int *line_ptr ATTRIBUTE_UNUSED;
252b5132 3884{
b34976b6 3885 return FALSE;
252b5132
RH
3886}
3887
3888static int
3889ieee_generic_stat_arch_elt (abfd, buf)
3890 bfd *abfd;
3891 struct stat *buf;
3892{
3893 ieee_ar_data_type *ar = (ieee_ar_data_type *) NULL;
3894 ieee_data_type *ieee;
3895
3896 if (abfd->my_archive != NULL)
3897 ar = abfd->my_archive->tdata.ieee_ar_data;
3898 if (ar == (ieee_ar_data_type *) NULL)
3899 {
3900 bfd_set_error (bfd_error_invalid_operation);
3901 return -1;
3902 }
3903
3904 if (IEEE_DATA (abfd) == NULL)
3905 {
3906 if (ieee_object_p (abfd) == NULL)
3907 {
3908 bfd_set_error (bfd_error_wrong_format);
3909 return -1;
3910 }
3911 }
3912
3913 ieee = IEEE_DATA (abfd);
3914
3915 buf->st_size = ieee->w.r.me_record + 1;
3916 buf->st_mode = 0644;
3917 return 0;
3918}
3919
3920static int
3921ieee_sizeof_headers (abfd, x)
5f771d47 3922 bfd *abfd ATTRIBUTE_UNUSED;
b34976b6 3923 bfd_boolean x ATTRIBUTE_UNUSED;
252b5132
RH
3924{
3925 return 0;
3926}
3927
252b5132
RH
3928#define ieee_close_and_cleanup _bfd_generic_close_and_cleanup
3929#define ieee_bfd_free_cached_info _bfd_generic_bfd_free_cached_info
3930
3931#define ieee_slurp_armap bfd_true
3932#define ieee_slurp_extended_name_table bfd_true
3933#define ieee_construct_extended_name_table \
b34976b6
AM
3934 ((bfd_boolean (*) \
3935 PARAMS ((bfd *, char **, bfd_size_type *, const char **))) \
252b5132
RH
3936 bfd_true)
3937#define ieee_truncate_arname bfd_dont_truncate_arname
3938#define ieee_write_armap \
b34976b6 3939 ((bfd_boolean (*) \
252b5132
RH
3940 PARAMS ((bfd *, unsigned int, struct orl *, unsigned int, int))) \
3941 bfd_true)
3942#define ieee_read_ar_hdr bfd_nullvoidptr
3943#define ieee_update_armap_timestamp bfd_true
3944#define ieee_get_elt_at_index _bfd_generic_get_elt_at_index
3945
3c9458e9
NC
3946#define ieee_bfd_is_target_special_symbol \
3947 ((bfd_boolean (*) (bfd *, asymbol *)) bfd_false)
252b5132
RH
3948#define ieee_bfd_is_local_label_name bfd_generic_is_local_label_name
3949#define ieee_get_lineno _bfd_nosymbols_get_lineno
3950#define ieee_bfd_make_debug_symbol _bfd_nosymbols_bfd_make_debug_symbol
3951#define ieee_read_minisymbols _bfd_generic_read_minisymbols
3952#define ieee_minisymbol_to_symbol _bfd_generic_minisymbol_to_symbol
3953
3954#define ieee_bfd_reloc_type_lookup _bfd_norelocs_bfd_reloc_type_lookup
3955
3956#define ieee_set_arch_mach _bfd_generic_set_arch_mach
3957
3958#define ieee_get_section_contents_in_window \
3959 _bfd_generic_get_section_contents_in_window
3960#define ieee_bfd_get_relocated_section_contents \
3961 bfd_generic_get_relocated_section_contents
3962#define ieee_bfd_relax_section bfd_generic_relax_section
3963#define ieee_bfd_gc_sections bfd_generic_gc_sections
8550eb6e 3964#define ieee_bfd_merge_sections bfd_generic_merge_sections
72adc230 3965#define ieee_bfd_is_group_section bfd_generic_is_group_section
e61463e1 3966#define ieee_bfd_discard_group bfd_generic_discard_group
082b7297
L
3967#define ieee_section_already_linked \
3968 _bfd_generic_section_already_linked
252b5132 3969#define ieee_bfd_link_hash_table_create _bfd_generic_link_hash_table_create
e2d34d7d 3970#define ieee_bfd_link_hash_table_free _bfd_generic_link_hash_table_free
252b5132 3971#define ieee_bfd_link_add_symbols _bfd_generic_link_add_symbols
2d653fc7 3972#define ieee_bfd_link_just_syms _bfd_generic_link_just_syms
252b5132
RH
3973#define ieee_bfd_final_link _bfd_generic_final_link
3974#define ieee_bfd_link_split_section _bfd_generic_link_split_section
3975
252b5132
RH
3976const bfd_target ieee_vec =
3977{
3978 "ieee", /* name */
3979 bfd_target_ieee_flavour,
3980 BFD_ENDIAN_UNKNOWN, /* target byte order */
3981 BFD_ENDIAN_UNKNOWN, /* target headers byte order */
3982 (HAS_RELOC | EXEC_P | /* object flags */
3983 HAS_LINENO | HAS_DEBUG |
3984 HAS_SYMS | HAS_LOCALS | WP_TEXT | D_PAGED),
3985 (SEC_CODE | SEC_DATA | SEC_ROM | SEC_HAS_CONTENTS
3986 | SEC_ALLOC | SEC_LOAD | SEC_RELOC), /* section flags */
3987 '_', /* leading underscore */
3988 ' ', /* ar_pad_char */
3989 16, /* ar_max_namelen */
3990 bfd_getb64, bfd_getb_signed_64, bfd_putb64,
3991 bfd_getb32, bfd_getb_signed_32, bfd_putb32,
3992 bfd_getb16, bfd_getb_signed_16, bfd_putb16, /* data */
3993 bfd_getb64, bfd_getb_signed_64, bfd_putb64,
3994 bfd_getb32, bfd_getb_signed_32, bfd_putb32,
3995 bfd_getb16, bfd_getb_signed_16, bfd_putb16, /* hdrs */
3996
3997 {_bfd_dummy_target,
3998 ieee_object_p, /* bfd_check_format */
3999 ieee_archive_p,
4000 _bfd_dummy_target,
4001 },
4002 {
4003 bfd_false,
4004 ieee_mkobject,
4005 _bfd_generic_mkarchive,
4006 bfd_false
4007 },
4008 {
4009 bfd_false,
4010 ieee_write_object_contents,
4011 _bfd_write_archive_contents,
4012 bfd_false,
4013 },
4014
47fda0d3
AM
4015 /* ieee_close_and_cleanup, ieee_bfd_free_cached_info, ieee_new_section_hook,
4016 ieee_get_section_contents, ieee_get_section_contents_in_window */
252b5132 4017 BFD_JUMP_TABLE_GENERIC (ieee),
47fda0d3 4018
252b5132
RH
4019 BFD_JUMP_TABLE_COPY (_bfd_generic),
4020 BFD_JUMP_TABLE_CORE (_bfd_nocore),
47fda0d3
AM
4021
4022 /* ieee_slurp_armap, ieee_slurp_extended_name_table,
4023 ieee_construct_extended_name_table, ieee_truncate_arname,
4024 ieee_write_armap, ieee_read_ar_hdr, ieee_openr_next_archived_file,
4025 ieee_get_elt_at_index, ieee_generic_stat_arch_elt,
4026 ieee_update_armap_timestamp */
252b5132 4027 BFD_JUMP_TABLE_ARCHIVE (ieee),
47fda0d3 4028
6cee3f79
AC
4029 /* ieee_get_symtab_upper_bound, ieee_canonicalize_symtab,
4030 ieee_make_empty_symbol, ieee_print_symbol, ieee_get_symbol_info,
4031 ieee_bfd_is_local_label_name, ieee_get_lineno,
4032 ieee_find_nearest_line, ieee_bfd_make_debug_symbol,
4033 ieee_read_minisymbols, ieee_minisymbol_to_symbol */
252b5132 4034 BFD_JUMP_TABLE_SYMBOLS (ieee),
47fda0d3
AM
4035
4036 /* ieee_get_reloc_upper_bound, ieee_canonicalize_reloc,
4037 ieee_bfd_reloc_type_lookup */
252b5132 4038 BFD_JUMP_TABLE_RELOCS (ieee),
47fda0d3
AM
4039
4040 /* ieee_set_arch_mach, ieee_set_section_contents */
252b5132 4041 BFD_JUMP_TABLE_WRITE (ieee),
47fda0d3
AM
4042
4043 /* ieee_sizeof_headers, ieee_bfd_get_relocated_section_contents,
4044 ieee_bfd_relax_section, ieee_bfd_link_hash_table_create,
e2d34d7d 4045 _bfd_generic_link_hash_table_free,
47fda0d3
AM
4046 ieee_bfd_link_add_symbols, ieee_bfd_final_link,
4047 ieee_bfd_link_split_section, ieee_bfd_gc_sections,
4048 ieee_bfd_merge_sections */
252b5132 4049 BFD_JUMP_TABLE_LINK (ieee),
47fda0d3 4050
252b5132
RH
4051 BFD_JUMP_TABLE_DYNAMIC (_bfd_nodynamic),
4052
c3c89269 4053 NULL,
dc810e39 4054
252b5132
RH
4055 (PTR) 0
4056};
This page took 0.507808 seconds and 4 git commands to generate.