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