1 /* BFD back-end for ieee-695 objects.
2 Copyright (C) 1990-2017 Free Software Foundation, Inc.
4 Written by Steve Chamberlain of Cygnus Support.
6 This file is part of BFD, the Binary File Descriptor library.
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
10 the Free Software Foundation; either version 3 of the License, or
11 (at your option) any later version.
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.
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
20 Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston,
21 MA 02110-1301, USA. */
24 #define KEEPMINUSPCININST 0
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
35 #include "safe-ctype.h"
36 #include "libiberty.h"
38 struct output_buffer_struct
44 static unsigned char *output_ptr_start
;
45 static unsigned char *output_ptr
;
46 static unsigned char *output_ptr_end
;
47 static unsigned char *input_ptr_start
;
48 static unsigned char *input_ptr
;
49 static unsigned char *input_ptr_end
;
50 static bfd
*input_bfd
;
51 static bfd
*output_bfd
;
52 static int output_buffer
;
55 static void block (void);
57 /* Functions for writing to ieee files in the strange way that the
61 ieee_write_byte (bfd
*abfd
, int barg
)
66 if (bfd_bwrite ((void *) &byte
, (bfd_size_type
) 1, abfd
) != 1)
72 ieee_write_2bytes (bfd
*abfd
, int bytes
)
76 buffer
[0] = bytes
>> 8;
77 buffer
[1] = bytes
& 0xff;
78 if (bfd_bwrite ((void *) buffer
, (bfd_size_type
) 2, abfd
) != 2)
84 ieee_write_int (bfd
*abfd
, bfd_vma value
)
88 if (! ieee_write_byte (abfd
, (bfd_byte
) value
))
95 /* How many significant bytes ? */
96 /* FIXME FOR LONGER INTS. */
97 if (value
& 0xff000000)
99 else if (value
& 0x00ff0000)
101 else if (value
& 0x0000ff00)
106 if (! ieee_write_byte (abfd
,
107 (bfd_byte
) ((int) ieee_number_repeat_start_enum
113 if (! ieee_write_byte (abfd
, (bfd_byte
) (value
>> 24)))
117 if (! ieee_write_byte (abfd
, (bfd_byte
) (value
>> 16)))
121 if (! ieee_write_byte (abfd
, (bfd_byte
) (value
>> 8)))
125 if (! ieee_write_byte (abfd
, (bfd_byte
) (value
)))
134 ieee_write_id (bfd
*abfd
, const char *id
)
136 size_t length
= strlen (id
);
140 if (! ieee_write_byte (abfd
, (bfd_byte
) length
))
143 else if (length
< 255)
145 if (! ieee_write_byte (abfd
, ieee_extension_length_1_enum
)
146 || ! ieee_write_byte (abfd
, (bfd_byte
) length
))
149 else if (length
< 65535)
151 if (! ieee_write_byte (abfd
, ieee_extension_length_2_enum
)
152 || ! ieee_write_2bytes (abfd
, (int) length
))
158 /* xgettext:c-format */
159 (_("%B: string too long (%d chars, max 65535)"), abfd
, length
);
160 bfd_set_error (bfd_error_invalid_operation
);
164 if (bfd_bwrite ((void *) id
, (bfd_size_type
) length
, abfd
) != length
)
169 /* Functions for reading from ieee files in the strange way that the
170 standard requires. */
172 #define this_byte(ieee) *((ieee)->input_p)
173 #define this_byte_and_next(ieee) ((ieee)->input_p < (ieee)->end_p ? *((ieee)->input_p++) : 0)
176 next_byte (common_header_type
* ieee
)
180 return ieee
->input_p
< ieee
->last_byte
;
183 static unsigned short
184 read_2bytes (common_header_type
*ieee
)
186 unsigned char c1
= this_byte_and_next (ieee
);
187 unsigned char c2
= this_byte_and_next (ieee
);
189 return (c1
<< 8) | c2
;
193 bfd_get_string (common_header_type
*ieee
, char *string
, size_t length
)
197 for (i
= 0; i
< length
; i
++)
198 string
[i
] = this_byte_and_next (ieee
);
202 read_id (common_header_type
*ieee
)
207 length
= this_byte_and_next (ieee
);
209 /* Simple string of length 0 to 127. */
212 else if (length
== 0xde)
213 /* Length is next byte, allowing 0..255. */
214 length
= this_byte_and_next (ieee
);
216 else if (length
== 0xdf)
218 /* Length is next two bytes, allowing 0..65535. */
219 length
= this_byte_and_next (ieee
);
220 length
= (length
* 256) + this_byte_and_next (ieee
);
223 /* PR 21612: Check for an invalid length. */
224 if (ieee
->input_p
+ length
>= ieee
->end_p
)
226 _bfd_error_handler (_("IEEE parser: string length: %#lx longer than buffer: %#lx"),
227 length
, (long) (ieee
->end_p
- ieee
->input_p
));
228 bfd_set_error (bfd_error_invalid_operation
);
232 /* Buy memory and read string. */
233 string
= bfd_alloc (ieee
->abfd
, (bfd_size_type
) length
+ 1);
236 bfd_get_string (ieee
, string
, length
);
242 ieee_write_expression (bfd
*abfd
,
248 unsigned int term_count
= 0;
252 if (! ieee_write_int (abfd
, value
))
257 /* Badly formatted binaries can have a missing symbol,
258 so test here to prevent a seg fault. */
261 if (bfd_is_com_section (symbol
->section
)
262 || bfd_is_und_section (symbol
->section
))
264 /* Def of a common symbol. */
265 if (! ieee_write_byte (abfd
, ieee_variable_X_enum
)
266 || ! ieee_write_int (abfd
, symbol
->value
))
270 else if (! bfd_is_abs_section (symbol
->section
))
272 /* Ref to defined symbol - */
273 if (symbol
->flags
& BSF_GLOBAL
)
275 if (! ieee_write_byte (abfd
, ieee_variable_I_enum
)
276 || ! ieee_write_int (abfd
, symbol
->value
))
280 else if (symbol
->flags
& (BSF_LOCAL
| BSF_SECTION_SYM
))
282 /* This is a reference to a defined local symbol. We can
283 easily do a local as a section+offset. */
284 if (! ieee_write_byte (abfd
, ieee_variable_R_enum
)
285 || ! ieee_write_byte (abfd
,
286 (bfd_byte
) (symbol
->section
->index
287 + IEEE_SECTION_NUMBER_BASE
)))
291 if (symbol
->value
!= 0)
293 if (! ieee_write_int (abfd
, symbol
->value
))
301 /* xgettext:c-format */
302 (_("%B: unrecognized symbol `%s' flags 0x%x"),
303 abfd
, bfd_asymbol_name (symbol
), symbol
->flags
);
304 bfd_set_error (bfd_error_invalid_operation
);
312 /* Subtract the pc from here by asking for PC of this section. */
313 if (! ieee_write_byte (abfd
, ieee_variable_P_enum
)
314 || ! ieee_write_byte (abfd
,
315 (bfd_byte
) (sindex
+ IEEE_SECTION_NUMBER_BASE
))
316 || ! ieee_write_byte (abfd
, ieee_function_minus_enum
))
320 /* Handle the degenerate case of a 0 address. */
322 if (! ieee_write_int (abfd
, (bfd_vma
) 0))
325 while (term_count
> 1)
327 if (! ieee_write_byte (abfd
, ieee_function_plus_enum
))
335 /* Writes any integer into the buffer supplied and always takes 5 bytes. */
338 ieee_write_int5 (bfd_byte
*buffer
, bfd_vma value
)
340 buffer
[0] = (bfd_byte
) ieee_number_repeat_4_enum
;
341 buffer
[1] = (value
>> 24) & 0xff;
342 buffer
[2] = (value
>> 16) & 0xff;
343 buffer
[3] = (value
>> 8) & 0xff;
344 buffer
[4] = (value
>> 0) & 0xff;
348 ieee_write_int5_out (bfd
*abfd
, bfd_vma value
)
352 ieee_write_int5 (b
, value
);
353 if (bfd_bwrite ((void *) b
, (bfd_size_type
) 5, abfd
) != 5)
359 parse_int (common_header_type
*ieee
, bfd_vma
*value_ptr
)
361 int value
= this_byte (ieee
);
364 if (value
>= 0 && value
<= 127)
367 return next_byte (ieee
);
369 else if (value
>= 0x80 && value
<= 0x88)
371 unsigned int count
= value
& 0xf;
374 if (! next_byte (ieee
))
378 result
= (result
<< 8) | this_byte_and_next (ieee
);
388 parse_i (common_header_type
*ieee
, bfd_boolean
*ok
)
391 *ok
= parse_int (ieee
, &x
);
396 must_parse_int (common_header_type
*ieee
)
399 BFD_ASSERT (parse_int (ieee
, &result
));
407 ieee_symbol_index_type symbol
;
411 #if KEEPMINUSPCININST
413 #define SRC_MASK(arg) arg
414 #define PCREL_OFFSET FALSE
418 #define SRC_MASK(arg) 0
419 #define PCREL_OFFSET TRUE
423 static reloc_howto_type abs32_howto
=
430 complain_overflow_bitfield
,
438 static reloc_howto_type abs16_howto
=
445 complain_overflow_bitfield
,
453 static reloc_howto_type abs8_howto
=
460 complain_overflow_bitfield
,
468 static reloc_howto_type rel32_howto
=
475 complain_overflow_signed
,
479 SRC_MASK (0xffffffff),
483 static reloc_howto_type rel16_howto
=
490 complain_overflow_signed
,
494 SRC_MASK (0x0000ffff),
498 static reloc_howto_type rel8_howto
=
505 complain_overflow_signed
,
509 SRC_MASK (0x000000ff),
513 static ieee_symbol_index_type NOSYMBOL
= {0, 0};
516 parse_expression (ieee_data_type
*ieee
,
518 ieee_symbol_index_type
*symbol
,
524 bfd_boolean loop
= TRUE
;
525 ieee_value_type stack
[10];
526 ieee_value_type
*sp
= stack
;
535 /* The stack pointer always points to the next unused location. */
536 #define PUSH(x,y,z) TOS.symbol = x; TOS.section = y; TOS.value = z; INC;
537 #define POP(x,y,z) DEC; x = TOS.symbol; y = TOS.section; z = TOS.value;
539 while (loop
&& ieee
->h
.input_p
< ieee
->h
.last_byte
)
541 switch (this_byte (&(ieee
->h
)))
543 case ieee_variable_P_enum
:
544 /* P variable, current program counter for section n. */
548 if (! next_byte (&(ieee
->h
)))
551 section_n
= must_parse_int (&(ieee
->h
));
553 PUSH (NOSYMBOL
, bfd_abs_section_ptr
, 0);
557 case ieee_variable_L_enum
:
558 /* L variable address of section N. */
559 if (! next_byte (&(ieee
->h
)))
561 PUSH (NOSYMBOL
, ieee
->section_table
[must_parse_int (&(ieee
->h
))], 0);
564 case ieee_variable_R_enum
:
565 /* R variable, logical address of section module. */
566 /* FIXME, this should be different to L. */
567 if (! next_byte (&(ieee
->h
)))
569 PUSH (NOSYMBOL
, ieee
->section_table
[must_parse_int (&(ieee
->h
))], 0);
572 case ieee_variable_S_enum
:
573 /* S variable, size in MAUS of section module. */
574 if (! next_byte (&(ieee
->h
)))
578 ieee
->section_table
[must_parse_int (&(ieee
->h
))]->size
);
581 case ieee_variable_I_enum
:
582 /* Push the address of variable n. */
584 ieee_symbol_index_type sy
;
586 if (! next_byte (&(ieee
->h
)))
588 sy
.index
= (int) must_parse_int (&(ieee
->h
));
591 PUSH (sy
, bfd_abs_section_ptr
, 0);
595 case ieee_variable_X_enum
:
596 /* Push the address of external variable n. */
598 ieee_symbol_index_type sy
;
600 if (! next_byte (&(ieee
->h
)))
603 sy
.index
= (int) (must_parse_int (&(ieee
->h
)));
606 PUSH (sy
, bfd_und_section_ptr
, 0);
610 case ieee_function_minus_enum
:
612 bfd_vma value1
, value2
;
613 asection
*section1
, *section_dummy
;
614 ieee_symbol_index_type sy
;
616 if (! next_byte (&(ieee
->h
)))
619 POP (sy
, section1
, value1
);
620 POP (sy
, section_dummy
, value2
);
621 PUSH (sy
, section1
? section1
: section_dummy
, value2
- value1
);
625 case ieee_function_plus_enum
:
627 bfd_vma value1
, value2
;
630 ieee_symbol_index_type sy1
;
631 ieee_symbol_index_type sy2
;
633 if (! next_byte (&(ieee
->h
)))
636 POP (sy1
, section1
, value1
);
637 POP (sy2
, section2
, value2
);
638 PUSH (sy1
.letter
? sy1
: sy2
,
639 bfd_is_abs_section (section1
) ? section2
: section1
,
648 BFD_ASSERT (this_byte (&(ieee
->h
)) < (int) ieee_variable_A_enum
649 || this_byte (&(ieee
->h
)) > (int) ieee_variable_Z_enum
);
650 if (parse_int (&(ieee
->h
), &va
))
652 PUSH (NOSYMBOL
, bfd_abs_section_ptr
, va
);
655 /* Thats all that we can understand. */
661 /* As far as I can see there is a bug in the Microtec IEEE output
662 which I'm using to scan, whereby the comma operator is omitted
663 sometimes in an expression, giving expressions with too many
664 terms. We can tell if that's the case by ensuring that
665 sp == stack here. If not, then we've pushed something too far,
666 so we keep adding. */
667 while (sp
!= stack
+ 1)
670 ieee_symbol_index_type sy1
;
672 POP (sy1
, section1
, *extra
);
677 POP (*symbol
, dummy
, *value
);
684 #define ieee_pos(ieee) \
685 (ieee->h.input_p - ieee->h.first_byte)
687 /* Find the first part of the ieee file after HERE. */
690 ieee_part_after (ieee_data_type
*ieee
, file_ptr here
)
693 file_ptr after
= ieee
->w
.r
.me_record
;
695 /* File parts can come in any order, except that module end is
696 guaranteed to be last (and the header first). */
697 for (part
= 0; part
< N_W_VARIABLES
; part
++)
698 if (ieee
->w
.offset
[part
] > here
&& after
> ieee
->w
.offset
[part
])
699 after
= ieee
->w
.offset
[part
];
705 ieee_seek (ieee_data_type
* ieee
, file_ptr offset
)
707 /* PR 17512: file: 017-1157-0.004. */
708 if (offset
< 0 || (bfd_size_type
) offset
>= ieee
->h
.total_amt
)
710 ieee
->h
.input_p
= ieee
->h
.first_byte
+ ieee
->h
.total_amt
;
711 ieee
->h
.end_p
= ieee
->h
.last_byte
= ieee
->h
.input_p
;
715 ieee
->h
.input_p
= ieee
->h
.first_byte
+ offset
;
716 ieee
->h
.end_p
= ieee
->h
.last_byte
= (ieee
->h
.first_byte
+ ieee_part_after (ieee
, offset
));
720 static unsigned int last_index
;
721 static char last_type
; /* Is the index for an X or a D. */
723 static ieee_symbol_type
*
724 get_symbol (bfd
*abfd ATTRIBUTE_UNUSED
,
725 ieee_data_type
*ieee
,
726 ieee_symbol_type
*last_symbol
,
727 unsigned int *symbol_count
,
728 ieee_symbol_type
***pptr
,
729 unsigned int *max_index
,
732 /* Need a new symbol. */
733 unsigned int new_index
= must_parse_int (&(ieee
->h
));
735 if (new_index
!= last_index
|| this_type
!= last_type
)
737 ieee_symbol_type
*new_symbol
;
738 bfd_size_type amt
= sizeof (ieee_symbol_type
);
740 new_symbol
= bfd_alloc (ieee
->h
.abfd
, amt
);
744 new_symbol
->index
= new_index
;
745 last_index
= new_index
;
748 *pptr
= &new_symbol
->next
;
749 if (new_index
> *max_index
)
750 *max_index
= new_index
;
752 last_type
= this_type
;
753 new_symbol
->symbol
.section
= bfd_abs_section_ptr
;
760 ieee_slurp_external_symbols (bfd
*abfd
)
762 ieee_data_type
*ieee
= IEEE_DATA (abfd
);
763 file_ptr offset
= ieee
->w
.r
.external_part
;
765 ieee_symbol_type
**prev_symbols_ptr
= &ieee
->external_symbols
;
766 ieee_symbol_type
**prev_reference_ptr
= &ieee
->external_reference
;
767 ieee_symbol_type
*symbol
= NULL
;
768 unsigned int symbol_count
= 0;
769 bfd_boolean loop
= TRUE
;
771 last_index
= 0xffffff;
772 ieee
->symbol_table_full
= TRUE
;
774 if (! ieee_seek (ieee
, offset
))
779 switch (this_byte (&(ieee
->h
)))
782 if (! next_byte (&(ieee
->h
)))
785 symbol
= get_symbol (abfd
, ieee
, symbol
, &symbol_count
,
787 & ieee
->external_symbol_max_index
, 'I');
791 symbol
->symbol
.the_bfd
= abfd
;
792 symbol
->symbol
.name
= read_id (&(ieee
->h
));
793 symbol
->symbol
.udata
.p
= NULL
;
794 symbol
->symbol
.flags
= BSF_NO_FLAGS
;
797 case ieee_external_symbol_enum
:
798 if (! next_byte (&(ieee
->h
)))
801 symbol
= get_symbol (abfd
, ieee
, symbol
, &symbol_count
,
803 &ieee
->external_symbol_max_index
, 'D');
807 BFD_ASSERT (symbol
->index
>= ieee
->external_symbol_min_index
);
809 symbol
->symbol
.the_bfd
= abfd
;
810 symbol
->symbol
.name
= read_id (&(ieee
->h
));
811 symbol
->symbol
.udata
.p
= NULL
;
812 symbol
->symbol
.flags
= BSF_NO_FLAGS
;
814 case ieee_attribute_record_enum
>> 8:
816 unsigned int symbol_name_index
;
817 unsigned int symbol_type_index
;
818 unsigned int symbol_attribute_def
;
821 switch (read_2bytes (&ieee
->h
))
823 case ieee_attribute_record_enum
:
824 symbol_name_index
= must_parse_int (&(ieee
->h
));
825 symbol_type_index
= must_parse_int (&(ieee
->h
));
826 (void) symbol_type_index
;
827 symbol_attribute_def
= must_parse_int (&(ieee
->h
));
828 switch (symbol_attribute_def
)
832 parse_int (&ieee
->h
, &value
);
836 /* xgettext:c-format */
837 (_("%B: unimplemented ATI record %u for symbol %u"),
838 abfd
, symbol_attribute_def
, symbol_name_index
);
839 bfd_set_error (bfd_error_bad_value
);
844 case ieee_external_reference_info_record_enum
:
845 /* Skip over ATX record. */
846 parse_int (&(ieee
->h
), &value
);
847 parse_int (&(ieee
->h
), &value
);
848 parse_int (&(ieee
->h
), &value
);
849 parse_int (&(ieee
->h
), &value
);
851 case ieee_atn_record_enum
:
852 /* We may get call optimization information here,
853 which we just ignore. The format is
854 {$F1}${CE}{index}{$00}{$3F}{$3F}{#_of_ASNs}. */
855 parse_int (&ieee
->h
, &value
);
856 parse_int (&ieee
->h
, &value
);
857 parse_int (&ieee
->h
, &value
);
861 /* xgettext:c-format */
862 (_("%B: unexpected ATN type %d in external part"),
864 bfd_set_error (bfd_error_bad_value
);
867 parse_int (&ieee
->h
, &value
);
868 parse_int (&ieee
->h
, &value
);
875 switch (read_2bytes (&ieee
->h
))
877 case ieee_asn_record_enum
:
878 parse_int (&ieee
->h
, &val1
);
879 parse_int (&ieee
->h
, &val1
);
884 (_("%B: unexpected type after ATN"), abfd
);
885 bfd_set_error (bfd_error_bad_value
);
893 case ieee_value_record_enum
>> 8:
895 unsigned int symbol_name_index
;
896 ieee_symbol_index_type symbol_ignore
;
897 bfd_boolean pcrel_ignore
;
900 if (! next_byte (&(ieee
->h
)))
902 if (! next_byte (&(ieee
->h
)))
905 symbol_name_index
= must_parse_int (&(ieee
->h
));
906 (void) symbol_name_index
;
907 if (! parse_expression (ieee
,
908 &symbol
->symbol
.value
,
912 &symbol
->symbol
.section
))
915 /* Fully linked IEEE-695 files tend to give every symbol
916 an absolute value. Try to convert that back into a
917 section relative value. FIXME: This won't always to
919 if (bfd_is_abs_section (symbol
->symbol
.section
)
920 && (abfd
->flags
& HAS_RELOC
) == 0)
925 val
= symbol
->symbol
.value
;
926 for (s
= abfd
->sections
; s
!= NULL
; s
= s
->next
)
928 if (val
>= s
->vma
&& val
< s
->vma
+ s
->size
)
930 symbol
->symbol
.section
= s
;
931 symbol
->symbol
.value
-= s
->vma
;
937 symbol
->symbol
.flags
= BSF_GLOBAL
| BSF_EXPORT
;
941 case ieee_weak_external_reference_enum
:
946 if (! next_byte (&(ieee
->h
)))
949 /* Throw away the external reference index. */
950 (void) must_parse_int (&(ieee
->h
));
951 /* Fetch the default size if not resolved. */
952 size
= must_parse_int (&(ieee
->h
));
953 /* Fetch the default value if available. */
954 if (! parse_int (&(ieee
->h
), &value
))
956 /* This turns into a common. */
957 symbol
->symbol
.section
= bfd_com_section_ptr
;
958 symbol
->symbol
.value
= size
;
962 case ieee_external_reference_enum
:
963 if (! next_byte (&(ieee
->h
)))
966 symbol
= get_symbol (abfd
, ieee
, symbol
, &symbol_count
,
968 &ieee
->external_reference_max_index
, 'X');
972 symbol
->symbol
.the_bfd
= abfd
;
973 symbol
->symbol
.name
= read_id (&(ieee
->h
));
974 symbol
->symbol
.udata
.p
= NULL
;
975 symbol
->symbol
.section
= bfd_und_section_ptr
;
976 symbol
->symbol
.value
= (bfd_vma
) 0;
977 symbol
->symbol
.flags
= 0;
979 BFD_ASSERT (symbol
->index
>= ieee
->external_reference_min_index
);
987 if (ieee
->external_symbol_max_index
!= 0)
989 ieee
->external_symbol_count
=
990 ieee
->external_symbol_max_index
-
991 ieee
->external_symbol_min_index
+ 1;
994 ieee
->external_symbol_count
= 0;
996 if (ieee
->external_reference_max_index
!= 0)
998 ieee
->external_reference_count
=
999 ieee
->external_reference_max_index
-
1000 ieee
->external_reference_min_index
+ 1;
1003 ieee
->external_reference_count
= 0;
1006 ieee
->external_reference_count
+ ieee
->external_symbol_count
;
1008 if (symbol_count
!= abfd
->symcount
)
1009 /* There are gaps in the table -- */
1010 ieee
->symbol_table_full
= FALSE
;
1012 *prev_symbols_ptr
= NULL
;
1013 *prev_reference_ptr
= NULL
;
1019 ieee_slurp_symbol_table (bfd
*abfd
)
1021 if (! IEEE_DATA (abfd
)->read_symbols
)
1023 if (! ieee_slurp_external_symbols (abfd
))
1025 IEEE_DATA (abfd
)->read_symbols
= TRUE
;
1031 ieee_get_symtab_upper_bound (bfd
*abfd
)
1033 if (! ieee_slurp_symbol_table (abfd
))
1036 return (abfd
->symcount
!= 0) ?
1037 (abfd
->symcount
+ 1) * (sizeof (ieee_symbol_type
*)) : 0;
1040 /* Move from our internal lists to the canon table, and insert in
1041 symbol index order. */
1043 extern const bfd_target ieee_vec
;
1046 ieee_canonicalize_symtab (bfd
*abfd
, asymbol
**location
)
1048 ieee_symbol_type
*symp
;
1049 static bfd dummy_bfd
;
1050 static asymbol empty_symbol
=
1058 /* K&R compilers can't initialise unions. */
1065 ieee_data_type
*ieee
= IEEE_DATA (abfd
);
1067 dummy_bfd
.xvec
= &ieee_vec
;
1068 if (! ieee_slurp_symbol_table (abfd
))
1071 if (! ieee
->symbol_table_full
)
1073 /* Arrgh - there are gaps in the table, run through and fill them
1074 up with pointers to a null place. */
1077 for (i
= 0; i
< abfd
->symcount
; i
++)
1078 location
[i
] = &empty_symbol
;
1081 ieee
->external_symbol_base_offset
= -ieee
->external_symbol_min_index
;
1082 for (symp
= IEEE_DATA (abfd
)->external_symbols
;
1083 symp
!= (ieee_symbol_type
*) NULL
;
1085 /* Place into table at correct index locations. */
1086 location
[symp
->index
+ ieee
->external_symbol_base_offset
] = &symp
->symbol
;
1088 /* The external refs are indexed in a bit. */
1089 ieee
->external_reference_base_offset
=
1090 -ieee
->external_reference_min_index
+ ieee
->external_symbol_count
;
1092 for (symp
= IEEE_DATA (abfd
)->external_reference
;
1093 symp
!= (ieee_symbol_type
*) NULL
;
1095 location
[symp
->index
+ ieee
->external_reference_base_offset
] =
1100 location
[abfd
->symcount
] = (asymbol
*) NULL
;
1102 return abfd
->symcount
;
1106 get_section_entry (bfd
*abfd
, ieee_data_type
*ieee
, unsigned int sindex
)
1108 if (sindex
>= ieee
->section_table_size
)
1114 c
= ieee
->section_table_size
;
1121 amt
*= sizeof (asection
*);
1122 n
= bfd_realloc (ieee
->section_table
, amt
);
1126 for (i
= ieee
->section_table_size
; i
< c
; i
++)
1129 ieee
->section_table
= n
;
1130 ieee
->section_table_size
= c
;
1133 if (ieee
->section_table
[sindex
] == (asection
*) NULL
)
1135 char *tmp
= bfd_alloc (abfd
, (bfd_size_type
) 11);
1140 sprintf (tmp
, " fsec%4d", sindex
);
1141 section
= bfd_make_section (abfd
, tmp
);
1142 ieee
->section_table
[sindex
] = section
;
1143 section
->target_index
= sindex
;
1144 ieee
->section_table
[sindex
] = section
;
1146 return ieee
->section_table
[sindex
];
1150 ieee_slurp_sections (bfd
*abfd
)
1152 ieee_data_type
*ieee
= IEEE_DATA (abfd
);
1153 file_ptr offset
= ieee
->w
.r
.section_part
;
1158 bfd_byte section_type
[3];
1160 if (! ieee_seek (ieee
, offset
))
1165 switch (this_byte (&(ieee
->h
)))
1167 case ieee_section_type_enum
:
1170 unsigned int section_index
;
1172 if (! next_byte (&(ieee
->h
)))
1174 section_index
= must_parse_int (&(ieee
->h
));
1176 section
= get_section_entry (abfd
, ieee
, section_index
);
1178 section_type
[0] = this_byte_and_next (&(ieee
->h
));
1180 /* Set minimal section attributes. Attributes are
1181 extended later, based on section contents. */
1182 switch (section_type
[0])
1185 /* Normal attributes for absolute sections. */
1186 section_type
[1] = this_byte (&(ieee
->h
));
1187 section
->flags
= SEC_ALLOC
;
1188 switch (section_type
[1])
1190 /* AS Absolute section attributes. */
1192 if (! next_byte (&(ieee
->h
)))
1194 section_type
[2] = this_byte (&(ieee
->h
));
1195 switch (section_type
[2])
1199 if (! next_byte (&(ieee
->h
)))
1201 section
->flags
|= SEC_CODE
;
1205 if (! next_byte (&(ieee
->h
)))
1207 section
->flags
|= SEC_DATA
;
1210 if (! next_byte (&(ieee
->h
)))
1212 /* Normal rom data. */
1213 section
->flags
|= SEC_ROM
| SEC_DATA
;
1221 /* Named relocatable sections (type C). */
1223 section_type
[1] = this_byte (&(ieee
->h
));
1224 section
->flags
= SEC_ALLOC
;
1225 switch (section_type
[1])
1227 case 0xD0: /* Normal code (CP). */
1228 if (! next_byte (&(ieee
->h
)))
1230 section
->flags
|= SEC_CODE
;
1232 case 0xC4: /* Normal data (CD). */
1233 if (! next_byte (&(ieee
->h
)))
1235 section
->flags
|= SEC_DATA
;
1237 case 0xD2: /* Normal rom data (CR). */
1238 if (! next_byte (&(ieee
->h
)))
1240 section
->flags
|= SEC_ROM
| SEC_DATA
;
1247 /* Read section name, use it if non empty. */
1248 name
= read_id (&ieee
->h
);
1250 section
->name
= name
;
1252 /* Skip these fields, which we don't care about. */
1254 bfd_vma parent
, brother
, context
;
1256 parse_int (&(ieee
->h
), &parent
);
1257 parse_int (&(ieee
->h
), &brother
);
1258 parse_int (&(ieee
->h
), &context
);
1262 case ieee_section_alignment_enum
:
1264 unsigned int section_index
;
1268 if (! next_byte (&(ieee
->h
)))
1270 section_index
= must_parse_int (&ieee
->h
);
1271 section
= get_section_entry (abfd
, ieee
, section_index
);
1272 if (section_index
> ieee
->section_count
)
1273 ieee
->section_count
= section_index
;
1275 section
->alignment_power
=
1276 bfd_log2 (must_parse_int (&ieee
->h
));
1277 (void) parse_int (&(ieee
->h
), &value
);
1280 case ieee_e2_first_byte_enum
:
1283 ieee_record_enum_type t
;
1285 t
= (ieee_record_enum_type
) (read_2bytes (&(ieee
->h
)));
1288 case ieee_section_size_enum
:
1289 section
= ieee
->section_table
[must_parse_int (&(ieee
->h
))];
1290 section
->size
= must_parse_int (&(ieee
->h
));
1292 case ieee_physical_region_size_enum
:
1293 section
= ieee
->section_table
[must_parse_int (&(ieee
->h
))];
1294 section
->size
= must_parse_int (&(ieee
->h
));
1296 case ieee_region_base_address_enum
:
1297 section
= ieee
->section_table
[must_parse_int (&(ieee
->h
))];
1298 section
->vma
= must_parse_int (&(ieee
->h
));
1299 section
->lma
= section
->vma
;
1301 case ieee_mau_size_enum
:
1302 must_parse_int (&(ieee
->h
));
1303 must_parse_int (&(ieee
->h
));
1305 case ieee_m_value_enum
:
1306 must_parse_int (&(ieee
->h
));
1307 must_parse_int (&(ieee
->h
));
1309 case ieee_section_base_address_enum
:
1310 section
= ieee
->section_table
[must_parse_int (&(ieee
->h
))];
1311 section
->vma
= must_parse_int (&(ieee
->h
));
1312 section
->lma
= section
->vma
;
1314 case ieee_section_offset_enum
:
1315 (void) must_parse_int (&(ieee
->h
));
1316 (void) must_parse_int (&(ieee
->h
));
1332 /* Make a section for the debugging information, if any. We don't try
1333 to interpret the debugging information; we just point the section
1334 at the area in the file so that program which understand can dig it
1338 ieee_slurp_debug (bfd
*abfd
)
1340 ieee_data_type
*ieee
= IEEE_DATA (abfd
);
1345 if (ieee
->w
.r
.debug_information_part
== 0)
1348 flags
= SEC_DEBUGGING
| SEC_HAS_CONTENTS
;
1349 sec
= bfd_make_section_with_flags (abfd
, ".debug", flags
);
1352 sec
->filepos
= ieee
->w
.r
.debug_information_part
;
1354 debug_end
= ieee_part_after (ieee
, ieee
->w
.r
.debug_information_part
);
1355 sec
->size
= debug_end
- ieee
->w
.r
.debug_information_part
;
1360 /* Archive stuff. */
1362 static const bfd_target
*
1363 ieee_archive_p (bfd
*abfd
)
1367 static unsigned char buffer
[512];
1368 file_ptr buffer_offset
= 0;
1369 ieee_ar_data_type
*save
= abfd
->tdata
.ieee_ar_data
;
1370 ieee_ar_data_type
*ieee
;
1371 bfd_size_type alc_elts
;
1372 ieee_ar_obstack_type
*elts
= NULL
;
1373 bfd_size_type amt
= sizeof (ieee_ar_data_type
);
1375 abfd
->tdata
.ieee_ar_data
= bfd_alloc (abfd
, amt
);
1376 if (!abfd
->tdata
.ieee_ar_data
)
1377 goto error_ret_restore
;
1378 ieee
= IEEE_AR_DATA (abfd
);
1380 /* Ignore the return value here. It doesn't matter if we don't read
1381 the entire buffer. We might have a very small ieee file. */
1382 if (bfd_bread ((void *) buffer
, (bfd_size_type
) sizeof (buffer
), abfd
) <= 0)
1383 goto got_wrong_format_error
;
1385 ieee
->h
.first_byte
= buffer
;
1386 ieee
->h
.input_p
= buffer
;
1387 ieee
->h
.total_amt
= sizeof (buffer
);
1388 ieee
->h
.end_p
= buffer
+ sizeof (buffer
);
1390 ieee
->h
.abfd
= abfd
;
1392 if (this_byte (&(ieee
->h
)) != Module_Beginning
)
1393 goto got_wrong_format_error
;
1395 (void) next_byte (&(ieee
->h
));
1397 library
= read_id (&(ieee
->h
));
1398 if (strcmp (library
, "LIBRARY") != 0)
1399 goto got_wrong_format_error
;
1401 /* Throw away the filename. */
1402 read_id (&(ieee
->h
));
1404 ieee
->element_count
= 0;
1405 ieee
->element_index
= 0;
1407 (void) next_byte (&(ieee
->h
)); /* Drop the ad part. */
1408 must_parse_int (&(ieee
->h
)); /* And the two dummy numbers. */
1409 must_parse_int (&(ieee
->h
));
1412 elts
= bfd_malloc (alc_elts
* sizeof *elts
);
1416 /* Read the index of the BB table. */
1420 ieee_ar_obstack_type
*t
;
1422 rec
= read_2bytes (&(ieee
->h
));
1423 if (rec
!= (int) ieee_assign_value_to_variable_enum
)
1426 if (ieee
->element_count
>= alc_elts
)
1428 ieee_ar_obstack_type
*n
;
1431 n
= bfd_realloc (elts
, alc_elts
* sizeof (* elts
));
1437 t
= &elts
[ieee
->element_count
];
1438 ieee
->element_count
++;
1440 must_parse_int (&(ieee
->h
));
1441 t
->file_offset
= must_parse_int (&(ieee
->h
));
1442 t
->abfd
= (bfd
*) NULL
;
1444 /* Make sure that we don't go over the end of the buffer. */
1445 if ((size_t) ieee_pos (IEEE_DATA (abfd
)) > sizeof (buffer
) / 2)
1447 /* Past half way, reseek and reprime. */
1448 buffer_offset
+= ieee_pos (IEEE_DATA (abfd
));
1449 if (bfd_seek (abfd
, buffer_offset
, SEEK_SET
) != 0)
1452 /* Again ignore return value of bfd_bread. */
1453 bfd_bread ((void *) buffer
, (bfd_size_type
) sizeof (buffer
), abfd
);
1454 ieee
->h
.first_byte
= buffer
;
1455 ieee
->h
.input_p
= buffer
;
1456 ieee
->h
.total_amt
= sizeof (buffer
);
1457 ieee
->h
.end_p
= buffer
+ sizeof (buffer
);
1461 amt
= ieee
->element_count
;
1462 amt
*= sizeof *ieee
->elements
;
1463 ieee
->elements
= bfd_alloc (abfd
, amt
);
1464 if (ieee
->elements
== NULL
)
1467 memcpy (ieee
->elements
, elts
, (size_t) amt
);
1471 /* Now scan the area again, and replace BB offsets with file offsets. */
1472 for (i
= 2; i
< ieee
->element_count
; i
++)
1474 if (bfd_seek (abfd
, ieee
->elements
[i
].file_offset
, SEEK_SET
) != 0)
1477 /* Again ignore return value of bfd_bread. */
1478 bfd_bread ((void *) buffer
, (bfd_size_type
) sizeof (buffer
), abfd
);
1479 ieee
->h
.first_byte
= buffer
;
1480 ieee
->h
.input_p
= buffer
;
1481 ieee
->h
.total_amt
= sizeof (buffer
);
1482 ieee
->h
.end_p
= buffer
+ sizeof (buffer
);
1484 (void) next_byte (&(ieee
->h
)); /* Drop F8. */
1485 if (! next_byte (&(ieee
->h
))) /* Drop 14. */
1487 must_parse_int (&(ieee
->h
)); /* Drop size of block. */
1489 if (must_parse_int (&(ieee
->h
)) != 0)
1490 /* This object has been deleted. */
1491 ieee
->elements
[i
].file_offset
= 0;
1493 ieee
->elements
[i
].file_offset
= must_parse_int (&(ieee
->h
));
1496 /* abfd->has_armap = ;*/
1500 got_wrong_format_error
:
1501 bfd_set_error (bfd_error_wrong_format
);
1505 bfd_release (abfd
, ieee
);
1507 abfd
->tdata
.ieee_ar_data
= save
;
1513 ieee_mkobject (bfd
*abfd
)
1517 output_ptr_start
= NULL
;
1519 output_ptr_end
= NULL
;
1520 input_ptr_start
= NULL
;
1522 input_ptr_end
= NULL
;
1526 amt
= sizeof (ieee_data_type
);
1527 abfd
->tdata
.ieee_data
= bfd_zalloc (abfd
, amt
);
1528 return abfd
->tdata
.ieee_data
!= NULL
;
1532 do_one (ieee_data_type
*ieee
,
1533 ieee_per_section_type
*current_map
,
1534 unsigned char *location_ptr
,
1538 switch (this_byte (&(ieee
->h
)))
1540 case ieee_load_constant_bytes_enum
:
1542 unsigned int number_of_maus
;
1545 if (! next_byte (&(ieee
->h
)))
1547 number_of_maus
= must_parse_int (&(ieee
->h
));
1549 for (i
= 0; i
< number_of_maus
; i
++)
1551 location_ptr
[current_map
->pc
++] = this_byte (&(ieee
->h
));
1552 next_byte (&(ieee
->h
));
1557 case ieee_load_with_relocation_enum
:
1559 bfd_boolean loop
= TRUE
;
1561 if (! next_byte (&(ieee
->h
)))
1565 switch (this_byte (&(ieee
->h
)))
1567 case ieee_variable_R_enum
:
1569 case ieee_function_signed_open_b_enum
:
1570 case ieee_function_unsigned_open_b_enum
:
1571 case ieee_function_either_open_b_enum
:
1573 unsigned int extra
= 4;
1574 bfd_boolean pcrel
= FALSE
;
1578 r
= bfd_alloc (ieee
->h
.abfd
, sizeof (* r
));
1582 *(current_map
->reloc_tail_ptr
) = r
;
1583 current_map
->reloc_tail_ptr
= &r
->next
;
1584 r
->next
= (ieee_reloc_type
*) NULL
;
1585 if (! next_byte (&(ieee
->h
)))
1588 r
->relent
.sym_ptr_ptr
= 0;
1589 if (! parse_expression (ieee
,
1592 &pcrel
, &extra
, §ion
))
1595 r
->relent
.address
= current_map
->pc
;
1596 s
->flags
|= SEC_RELOC
;
1597 s
->owner
->flags
|= HAS_RELOC
;
1599 if (r
->relent
.sym_ptr_ptr
== NULL
&& section
!= NULL
)
1600 r
->relent
.sym_ptr_ptr
= section
->symbol_ptr_ptr
;
1602 if (this_byte (&(ieee
->h
)) == (int) ieee_comma
)
1604 if (! next_byte (&(ieee
->h
)))
1606 /* Fetch number of bytes to pad. */
1607 extra
= must_parse_int (&(ieee
->h
));
1610 switch (this_byte (&(ieee
->h
)))
1612 case ieee_function_signed_close_b_enum
:
1613 if (! next_byte (&(ieee
->h
)))
1616 case ieee_function_unsigned_close_b_enum
:
1617 if (! next_byte (&(ieee
->h
)))
1620 case ieee_function_either_close_b_enum
:
1621 if (! next_byte (&(ieee
->h
)))
1627 /* Build a relocation entry for this type. */
1628 /* If pc rel then stick -ve pc into instruction
1629 and take out of reloc ..
1631 I've changed this. It's all too complicated. I
1632 keep 0 in the instruction now. */
1641 #if KEEPMINUSPCININST
1642 bfd_put_32 (ieee
->h
.abfd
, -current_map
->pc
,
1643 location_ptr
+ current_map
->pc
);
1644 r
->relent
.howto
= &rel32_howto
;
1645 r
->relent
.addend
-= current_map
->pc
;
1647 bfd_put_32 (ieee
->h
.abfd
, (bfd_vma
) 0, location_ptr
+
1649 r
->relent
.howto
= &rel32_howto
;
1654 bfd_put_32 (ieee
->h
.abfd
, (bfd_vma
) 0,
1655 location_ptr
+ current_map
->pc
);
1656 r
->relent
.howto
= &abs32_howto
;
1658 current_map
->pc
+= 4;
1663 #if KEEPMINUSPCININST
1664 bfd_put_16 (ieee
->h
.abfd
, (bfd_vma
) -current_map
->pc
,
1665 location_ptr
+ current_map
->pc
);
1666 r
->relent
.addend
-= current_map
->pc
;
1667 r
->relent
.howto
= &rel16_howto
;
1670 bfd_put_16 (ieee
->h
.abfd
, (bfd_vma
) 0,
1671 location_ptr
+ current_map
->pc
);
1672 r
->relent
.howto
= &rel16_howto
;
1678 bfd_put_16 (ieee
->h
.abfd
, (bfd_vma
) 0,
1679 location_ptr
+ current_map
->pc
);
1680 r
->relent
.howto
= &abs16_howto
;
1682 current_map
->pc
+= 2;
1687 #if KEEPMINUSPCININST
1688 bfd_put_8 (ieee
->h
.abfd
, (int) (-current_map
->pc
), location_ptr
+ current_map
->pc
);
1689 r
->relent
.addend
-= current_map
->pc
;
1690 r
->relent
.howto
= &rel8_howto
;
1692 bfd_put_8 (ieee
->h
.abfd
, 0, location_ptr
+ current_map
->pc
);
1693 r
->relent
.howto
= &rel8_howto
;
1698 bfd_put_8 (ieee
->h
.abfd
, 0, location_ptr
+ current_map
->pc
);
1699 r
->relent
.howto
= &abs8_howto
;
1701 current_map
->pc
+= 1;
1714 if (parse_int (&(ieee
->h
), &this_size
))
1718 for (i
= 0; i
< this_size
; i
++)
1720 location_ptr
[current_map
->pc
++] = this_byte (&(ieee
->h
));
1721 if (! next_byte (&(ieee
->h
)))
1730 /* Prevent more than the first load-item of an LR record
1731 from being repeated (MRI convention). */
1732 if (iterations
!= 1)
1740 /* Read in all the section data and relocation stuff too. */
1743 ieee_slurp_section_data (bfd
*abfd
)
1745 bfd_byte
*location_ptr
= (bfd_byte
*) NULL
;
1746 ieee_data_type
*ieee
= IEEE_DATA (abfd
);
1747 unsigned int section_number
;
1748 ieee_per_section_type
*current_map
= NULL
;
1751 /* Seek to the start of the data area. */
1752 if (ieee
->read_data
)
1754 ieee
->read_data
= TRUE
;
1756 if (! ieee_seek (ieee
, ieee
->w
.r
.data_part
))
1759 /* Allocate enough space for all the section contents. */
1760 for (s
= abfd
->sections
; s
!= (asection
*) NULL
; s
= s
->next
)
1762 ieee_per_section_type
*per
= ieee_per_section (s
);
1765 if ((s
->flags
& SEC_DEBUGGING
) != 0)
1767 per
->data
= bfd_alloc (ieee
->h
.abfd
, s
->size
);
1770 relpp
= &s
->relocation
;
1771 per
->reloc_tail_ptr
= (ieee_reloc_type
**) relpp
;
1776 switch (this_byte (&(ieee
->h
)))
1778 /* IF we see anything strange then quit. */
1782 case ieee_set_current_section_enum
:
1783 if (! next_byte (&(ieee
->h
)))
1785 section_number
= must_parse_int (&(ieee
->h
));
1786 s
= ieee
->section_table
[section_number
];
1787 s
->flags
|= SEC_LOAD
| SEC_HAS_CONTENTS
;
1788 current_map
= ieee_per_section (s
);
1789 location_ptr
= current_map
->data
- s
->vma
;
1790 /* The document I have says that Microtec's compilers reset
1791 this after a sec section, even though the standard says not
1793 current_map
->pc
= s
->vma
;
1796 case ieee_e2_first_byte_enum
:
1797 if (! next_byte (&(ieee
->h
)))
1799 switch (this_byte (&(ieee
->h
)))
1801 case ieee_set_current_pc_enum
& 0xff:
1804 ieee_symbol_index_type symbol
;
1808 if (! next_byte (&(ieee
->h
)))
1810 must_parse_int (&(ieee
->h
)); /* Throw away section #. */
1811 if (! parse_expression (ieee
, &value
,
1817 current_map
->pc
= value
;
1818 BFD_ASSERT ((unsigned) (value
- s
->vma
) <= s
->size
);
1822 case ieee_value_starting_address_enum
& 0xff:
1823 if (! next_byte (&(ieee
->h
)))
1825 if (this_byte (&(ieee
->h
)) == ieee_function_either_open_b_enum
)
1827 if (! next_byte (&(ieee
->h
)))
1830 abfd
->start_address
= must_parse_int (&(ieee
->h
));
1831 /* We've got to the end of the data now - */
1838 case ieee_repeat_data_enum
:
1840 /* Repeat the following LD or LR n times - we do this by
1841 remembering the stream pointer before running it and
1842 resetting it and running it n times. We special case
1843 the repetition of a repeat_data/load_constant. */
1844 unsigned int iterations
;
1845 unsigned char *start
;
1847 if (! next_byte (&(ieee
->h
)))
1849 iterations
= must_parse_int (&(ieee
->h
));
1850 start
= ieee
->h
.input_p
;
1851 if (start
[0] == (int) ieee_load_constant_bytes_enum
1854 while (iterations
!= 0)
1856 location_ptr
[current_map
->pc
++] = start
[2];
1859 (void) next_byte (&(ieee
->h
));
1860 (void) next_byte (&(ieee
->h
));
1861 if (! next_byte (&(ieee
->h
)))
1866 while (iterations
!= 0)
1868 ieee
->h
.input_p
= start
;
1869 if (!do_one (ieee
, current_map
, location_ptr
, s
,
1877 case ieee_load_constant_bytes_enum
:
1878 case ieee_load_with_relocation_enum
:
1879 if (!do_one (ieee
, current_map
, location_ptr
, s
, 1))
1885 static const bfd_target
*
1886 ieee_object_p (bfd
*abfd
)
1890 ieee_data_type
*ieee
;
1891 static unsigned char buffer
[300];
1892 ieee_data_type
*save
= IEEE_DATA (abfd
);
1895 abfd
->tdata
.ieee_data
= 0;
1896 ieee_mkobject (abfd
);
1898 ieee
= IEEE_DATA (abfd
);
1899 if (bfd_seek (abfd
, (file_ptr
) 0, SEEK_SET
) != 0)
1901 /* Read the first few bytes in to see if it makes sense. Ignore
1902 bfd_bread return value; The file might be very small. */
1903 if (bfd_bread ((void *) buffer
, (bfd_size_type
) sizeof (buffer
), abfd
) <= 0)
1904 goto got_wrong_format
;
1906 ieee
->h
.input_p
= buffer
;
1907 ieee
->h
.total_amt
= sizeof (buffer
);
1908 ieee
->h
.end_p
= buffer
+ sizeof (buffer
);
1910 if (this_byte_and_next (&(ieee
->h
)) != Module_Beginning
)
1911 goto got_wrong_format
;
1913 ieee
->read_symbols
= FALSE
;
1914 ieee
->read_data
= FALSE
;
1915 ieee
->section_count
= 0;
1916 ieee
->external_symbol_max_index
= 0;
1917 ieee
->external_symbol_min_index
= IEEE_PUBLIC_BASE
;
1918 ieee
->external_reference_min_index
= IEEE_REFERENCE_BASE
;
1919 ieee
->external_reference_max_index
= 0;
1920 ieee
->h
.abfd
= abfd
;
1921 ieee
->section_table
= NULL
;
1922 ieee
->section_table_size
= 0;
1924 processor
= ieee
->mb
.processor
= read_id (&(ieee
->h
));
1925 if (strcmp (processor
, "LIBRARY") == 0)
1926 goto got_wrong_format
;
1927 ieee
->mb
.module_name
= read_id (&(ieee
->h
));
1928 if (abfd
->filename
== (const char *) NULL
)
1929 abfd
->filename
= xstrdup (ieee
->mb
.module_name
);
1931 /* Determine the architecture and machine type of the object file. */
1933 const bfd_arch_info_type
*arch
;
1936 /* IEEE does not specify the format of the processor identification
1937 string, so the compiler is free to put in it whatever it wants.
1938 We try here to recognize different processors belonging to the
1939 m68k family. Code for other processors can be added here. */
1940 if ((processor
[0] == '6') && (processor
[1] == '8'))
1942 if (processor
[2] == '3') /* 683xx integrated processors. */
1944 switch (processor
[3])
1946 case '0': /* 68302, 68306, 68307 */
1947 case '2': /* 68322, 68328 */
1948 case '5': /* 68356 */
1949 strcpy (family
, "68000"); /* MC68000-based controllers. */
1952 case '3': /* 68330, 68331, 68332, 68333,
1953 68334, 68335, 68336, 68338 */
1954 case '6': /* 68360 */
1955 case '7': /* 68376 */
1956 strcpy (family
, "68332"); /* CPU32 and CPU32+ */
1960 if (processor
[4] == '9') /* 68349 */
1961 strcpy (family
, "68030"); /* CPU030 */
1962 else /* 68340, 68341 */
1963 strcpy (family
, "68332"); /* CPU32 and CPU32+ */
1966 default: /* Does not exist yet. */
1967 strcpy (family
, "68332"); /* Guess it will be CPU32 */
1970 else if (TOUPPER (processor
[3]) == 'F') /* 68F333 */
1971 strcpy (family
, "68332"); /* CPU32 */
1972 else if ((TOUPPER (processor
[3]) == 'C') /* Embedded controllers. */
1973 && ((TOUPPER (processor
[2]) == 'E')
1974 || (TOUPPER (processor
[2]) == 'H')
1975 || (TOUPPER (processor
[2]) == 'L')))
1977 strcpy (family
, "68");
1978 strncat (family
, processor
+ 4, 7);
1981 else /* "Regular" processors. */
1983 strncpy (family
, processor
, 9);
1987 else if ((CONST_STRNEQ (processor
, "cpu32")) /* CPU32 and CPU32+ */
1988 || (CONST_STRNEQ (processor
, "CPU32")))
1989 strcpy (family
, "68332");
1992 strncpy (family
, processor
, 9);
1996 arch
= bfd_scan_arch (family
);
1998 goto got_wrong_format
;
1999 abfd
->arch_info
= arch
;
2002 if (this_byte (&(ieee
->h
)) != (int) ieee_address_descriptor_enum
)
2005 if (! next_byte (&(ieee
->h
)))
2008 if (! parse_int (&(ieee
->h
), &ieee
->ad
.number_of_bits_mau
))
2011 if (! parse_int (&(ieee
->h
), &ieee
->ad
.number_of_maus_in_address
))
2014 /* If there is a byte order info, take it. */
2015 if (this_byte (&(ieee
->h
)) == (int) ieee_variable_L_enum
2016 || this_byte (&(ieee
->h
)) == (int) ieee_variable_M_enum
)
2018 if (! next_byte (&(ieee
->h
)))
2022 for (part
= 0; part
< N_W_VARIABLES
; part
++)
2026 if (read_2bytes (&(ieee
->h
)) != (int) ieee_assign_value_to_variable_enum
)
2029 if (this_byte_and_next (&(ieee
->h
)) != part
)
2032 ieee
->w
.offset
[part
] = parse_i (&(ieee
->h
), &ok
);
2037 if (ieee
->w
.r
.external_part
!= 0)
2038 abfd
->flags
= HAS_SYMS
;
2040 /* By now we know that this is a real IEEE file, we're going to read
2041 the whole thing into memory so that we can run up and down it
2042 quickly. We can work out how big the file is from the trailer
2045 amt
= ieee
->w
.r
.me_record
+ 1;
2046 IEEE_DATA (abfd
)->h
.first_byte
= bfd_alloc (ieee
->h
.abfd
, amt
);
2047 if (!IEEE_DATA (abfd
)->h
.first_byte
)
2049 if (bfd_seek (abfd
, (file_ptr
) 0, SEEK_SET
) != 0)
2052 /* FIXME: Check return value. I'm not sure whether it needs to read
2053 the entire buffer or not. */
2054 amt
= bfd_bread ((void *) (IEEE_DATA (abfd
)->h
.first_byte
),
2055 (bfd_size_type
) ieee
->w
.r
.me_record
+ 1, abfd
);
2059 IEEE_DATA (abfd
)->h
.total_amt
= amt
;
2060 if (ieee_slurp_sections (abfd
))
2063 if (! ieee_slurp_debug (abfd
))
2066 /* Parse section data to activate file and section flags implied by
2067 section contents. */
2068 if (! ieee_slurp_section_data (abfd
))
2073 bfd_set_error (bfd_error_wrong_format
);
2075 bfd_release (abfd
, ieee
);
2076 abfd
->tdata
.ieee_data
= save
;
2077 return (const bfd_target
*) NULL
;
2081 ieee_get_symbol_info (bfd
*ignore_abfd ATTRIBUTE_UNUSED
,
2085 bfd_symbol_info (symbol
, ret
);
2086 if (symbol
->name
[0] == ' ')
2087 ret
->name
= "* empty table entry ";
2088 if (!symbol
->section
)
2089 ret
->type
= (symbol
->flags
& BSF_LOCAL
) ? 'a' : 'A';
2093 ieee_print_symbol (bfd
*abfd
,
2096 bfd_print_symbol_type how
)
2098 FILE *file
= (FILE *) afile
;
2102 case bfd_print_symbol_name
:
2103 fprintf (file
, "%s", symbol
->name
);
2105 case bfd_print_symbol_more
:
2108 case bfd_print_symbol_all
:
2110 const char *section_name
=
2111 (symbol
->section
== (asection
*) NULL
2113 : symbol
->section
->name
);
2115 if (symbol
->name
[0] == ' ')
2116 fprintf (file
, "* empty table entry ");
2119 bfd_print_symbol_vandf (abfd
, (void *) file
, symbol
);
2121 fprintf (file
, " %-5s %04x %02x %s",
2123 (unsigned) ieee_symbol (symbol
)->index
,
2133 ieee_new_section_hook (bfd
*abfd
, asection
*newsect
)
2135 if (!newsect
->used_by_bfd
)
2137 newsect
->used_by_bfd
= bfd_alloc (abfd
, sizeof (ieee_per_section_type
));
2138 if (!newsect
->used_by_bfd
)
2141 ieee_per_section (newsect
)->data
= NULL
;
2142 ieee_per_section (newsect
)->section
= newsect
;
2143 return _bfd_generic_new_section_hook (abfd
, newsect
);
2147 ieee_get_reloc_upper_bound (bfd
*abfd
, sec_ptr asect
)
2149 if ((asect
->flags
& SEC_DEBUGGING
) != 0)
2151 if (! ieee_slurp_section_data (abfd
))
2153 return (asect
->reloc_count
+ 1) * sizeof (arelent
*);
2157 ieee_get_section_contents (bfd
*abfd
,
2161 bfd_size_type count
)
2163 ieee_per_section_type
*p
= ieee_per_section (section
);
2164 if ((section
->flags
& SEC_DEBUGGING
) != 0)
2165 return _bfd_generic_get_section_contents (abfd
, section
, location
,
2167 ieee_slurp_section_data (abfd
);
2168 (void) memcpy ((void *) location
, (void *) (p
->data
+ offset
), (unsigned) count
);
2173 ieee_canonicalize_reloc (bfd
*abfd
,
2178 ieee_reloc_type
*src
= (ieee_reloc_type
*) (section
->relocation
);
2179 ieee_data_type
*ieee
= IEEE_DATA (abfd
);
2181 if ((section
->flags
& SEC_DEBUGGING
) != 0)
2184 while (src
!= (ieee_reloc_type
*) NULL
)
2186 /* Work out which symbol to attach it this reloc to. */
2187 switch (src
->symbol
.letter
)
2190 src
->relent
.sym_ptr_ptr
=
2191 symbols
+ src
->symbol
.index
+ ieee
->external_symbol_base_offset
;
2194 src
->relent
.sym_ptr_ptr
=
2195 symbols
+ src
->symbol
.index
+ ieee
->external_reference_base_offset
;
2198 if (src
->relent
.sym_ptr_ptr
!= NULL
)
2199 src
->relent
.sym_ptr_ptr
=
2200 src
->relent
.sym_ptr_ptr
[0]->section
->symbol_ptr_ptr
;
2206 *relptr
++ = &src
->relent
;
2210 return section
->reloc_count
;
2214 comp (const void * ap
, const void * bp
)
2216 arelent
*a
= *((arelent
**) ap
);
2217 arelent
*b
= *((arelent
**) bp
);
2218 return a
->address
- b
->address
;
2221 /* Write the section headers. */
2224 ieee_write_section_part (bfd
*abfd
)
2226 ieee_data_type
*ieee
= IEEE_DATA (abfd
);
2229 ieee
->w
.r
.section_part
= bfd_tell (abfd
);
2230 for (s
= abfd
->sections
; s
!= (asection
*) NULL
; s
= s
->next
)
2232 if (! bfd_is_abs_section (s
)
2233 && (s
->flags
& SEC_DEBUGGING
) == 0)
2235 if (! ieee_write_byte (abfd
, ieee_section_type_enum
)
2236 || ! ieee_write_byte (abfd
,
2237 (bfd_byte
) (s
->index
2238 + IEEE_SECTION_NUMBER_BASE
)))
2241 if (abfd
->flags
& EXEC_P
)
2243 /* This image is executable, so output absolute sections. */
2244 if (! ieee_write_byte (abfd
, ieee_variable_A_enum
)
2245 || ! ieee_write_byte (abfd
, ieee_variable_S_enum
))
2250 if (! ieee_write_byte (abfd
, ieee_variable_C_enum
))
2254 switch (s
->flags
& (SEC_CODE
| SEC_DATA
| SEC_ROM
))
2256 case SEC_CODE
| SEC_LOAD
:
2258 if (! ieee_write_byte (abfd
, ieee_variable_P_enum
))
2263 if (! ieee_write_byte (abfd
, ieee_variable_D_enum
))
2267 case SEC_ROM
| SEC_DATA
:
2268 case SEC_ROM
| SEC_LOAD
:
2269 case SEC_ROM
| SEC_DATA
| SEC_LOAD
:
2270 if (! ieee_write_byte (abfd
, ieee_variable_R_enum
))
2275 if (! ieee_write_id (abfd
, s
->name
))
2278 if (! ieee_write_byte (abfd
, ieee_section_alignment_enum
)
2279 || ! ieee_write_byte (abfd
,
2280 (bfd_byte
) (s
->index
2281 + IEEE_SECTION_NUMBER_BASE
))
2282 || ! ieee_write_int (abfd
, (bfd_vma
) 1 << s
->alignment_power
))
2286 if (! ieee_write_2bytes (abfd
, ieee_section_size_enum
)
2287 || ! ieee_write_byte (abfd
,
2288 (bfd_byte
) (s
->index
2289 + IEEE_SECTION_NUMBER_BASE
))
2290 || ! ieee_write_int (abfd
, s
->size
))
2292 if (abfd
->flags
& EXEC_P
)
2294 /* Relocateable sections don't have asl records. */
2296 if (! ieee_write_2bytes (abfd
, ieee_section_base_address_enum
)
2297 || ! ieee_write_byte (abfd
,
2300 + IEEE_SECTION_NUMBER_BASE
)))
2301 || ! ieee_write_int (abfd
, s
->lma
))
2311 do_with_relocs (bfd
*abfd
, asection
*s
)
2313 unsigned int number_of_maus_in_address
=
2314 bfd_arch_bits_per_address (abfd
) / bfd_arch_bits_per_byte (abfd
);
2315 unsigned int relocs_to_go
= s
->reloc_count
;
2316 bfd_byte
*stream
= ieee_per_section (s
)->data
;
2317 arelent
**p
= s
->orelocation
;
2318 bfd_size_type current_byte_index
= 0;
2320 qsort (s
->orelocation
,
2322 sizeof (arelent
**),
2325 /* Output the section preheader. */
2326 if (! ieee_write_byte (abfd
, ieee_set_current_section_enum
)
2327 || ! ieee_write_byte (abfd
,
2328 (bfd_byte
) (s
->index
+ IEEE_SECTION_NUMBER_BASE
))
2329 || ! ieee_write_2bytes (abfd
, ieee_set_current_pc_enum
)
2330 || ! ieee_write_byte (abfd
,
2331 (bfd_byte
) (s
->index
+ IEEE_SECTION_NUMBER_BASE
)))
2334 if ((abfd
->flags
& EXEC_P
) != 0 && relocs_to_go
== 0)
2336 if (! ieee_write_int (abfd
, s
->lma
))
2341 if (! ieee_write_expression (abfd
, (bfd_vma
) 0, s
->symbol
, 0, 0))
2345 if (relocs_to_go
== 0)
2347 /* If there aren't any relocations then output the load constant
2348 byte opcode rather than the load with relocation opcode. */
2349 while (current_byte_index
< s
->size
)
2352 unsigned int MAXRUN
= 127;
2355 if (run
> s
->size
- current_byte_index
)
2356 run
= s
->size
- current_byte_index
;
2360 if (! ieee_write_byte (abfd
, ieee_load_constant_bytes_enum
))
2362 /* Output a stream of bytes. */
2363 if (! ieee_write_int (abfd
, run
))
2365 if (bfd_bwrite ((void *) (stream
+ current_byte_index
), run
, abfd
)
2368 current_byte_index
+= run
;
2374 if (! ieee_write_byte (abfd
, ieee_load_with_relocation_enum
))
2377 /* Output the data stream as the longest sequence of bytes
2378 possible, allowing for the a reasonable packet size and
2379 relocation stuffs. */
2382 /* Outputting a section without data, fill it up. */
2383 stream
= bfd_zalloc (abfd
, s
->size
);
2387 while (current_byte_index
< s
->size
)
2390 unsigned int MAXRUN
= 127;
2394 run
= (*p
)->address
- current_byte_index
;
2401 if (run
> s
->size
- current_byte_index
)
2402 run
= s
->size
- current_byte_index
;
2406 /* Output a stream of bytes. */
2407 if (! ieee_write_int (abfd
, run
))
2409 if (bfd_bwrite ((void *) (stream
+ current_byte_index
), run
, abfd
)
2412 current_byte_index
+= run
;
2415 /* Output any relocations here. */
2416 if (relocs_to_go
&& (*p
) && (*p
)->address
== current_byte_index
)
2419 && (*p
) && (*p
)->address
== current_byte_index
)
2423 switch (r
->howto
->size
)
2426 ov
= bfd_get_signed_32 (abfd
,
2427 stream
+ current_byte_index
);
2428 current_byte_index
+= 4;
2431 ov
= bfd_get_signed_16 (abfd
,
2432 stream
+ current_byte_index
);
2433 current_byte_index
+= 2;
2436 ov
= bfd_get_signed_8 (abfd
,
2437 stream
+ current_byte_index
);
2438 current_byte_index
++;
2446 ov
&= r
->howto
->src_mask
;
2448 if (r
->howto
->pc_relative
2449 && ! r
->howto
->pcrel_offset
)
2452 if (! ieee_write_byte (abfd
,
2453 ieee_function_either_open_b_enum
))
2456 if (r
->sym_ptr_ptr
!= (asymbol
**) NULL
)
2458 if (! ieee_write_expression (abfd
, r
->addend
+ ov
,
2460 r
->howto
->pc_relative
,
2461 (unsigned) s
->index
))
2466 if (! ieee_write_expression (abfd
, r
->addend
+ ov
,
2468 r
->howto
->pc_relative
,
2469 (unsigned) s
->index
))
2473 if (number_of_maus_in_address
2474 != bfd_get_reloc_size (r
->howto
))
2476 bfd_vma rsize
= bfd_get_reloc_size (r
->howto
);
2477 if (! ieee_write_int (abfd
, rsize
))
2480 if (! ieee_write_byte (abfd
,
2481 ieee_function_either_close_b_enum
))
2495 /* If there are no relocations in the output section then we can be
2496 clever about how we write. We block items up into a max of 127
2500 do_as_repeat (bfd
*abfd
, asection
*s
)
2504 if (! ieee_write_byte (abfd
, ieee_set_current_section_enum
)
2505 || ! ieee_write_byte (abfd
,
2506 (bfd_byte
) (s
->index
2507 + IEEE_SECTION_NUMBER_BASE
))
2508 || ! ieee_write_byte (abfd
, ieee_set_current_pc_enum
>> 8)
2509 || ! ieee_write_byte (abfd
, ieee_set_current_pc_enum
& 0xff)
2510 || ! ieee_write_byte (abfd
,
2511 (bfd_byte
) (s
->index
2512 + IEEE_SECTION_NUMBER_BASE
)))
2515 if ((abfd
->flags
& EXEC_P
) != 0)
2517 if (! ieee_write_int (abfd
, s
->lma
))
2522 if (! ieee_write_expression (abfd
, (bfd_vma
) 0, s
->symbol
, 0, 0))
2526 if (! ieee_write_byte (abfd
, ieee_repeat_data_enum
)
2527 || ! ieee_write_int (abfd
, s
->size
)
2528 || ! ieee_write_byte (abfd
, ieee_load_constant_bytes_enum
)
2529 || ! ieee_write_byte (abfd
, 1)
2530 || ! ieee_write_byte (abfd
, 0))
2538 do_without_relocs (bfd
*abfd
, asection
*s
)
2540 bfd_byte
*stream
= ieee_per_section (s
)->data
;
2542 if (stream
== 0 || ((s
->flags
& SEC_LOAD
) == 0))
2544 if (! do_as_repeat (abfd
, s
))
2551 for (i
= 0; i
< s
->size
; i
++)
2555 if (! do_with_relocs (abfd
, s
))
2560 if (! do_as_repeat (abfd
, s
))
2570 bfd_size_type amt
= input_ptr_end
- input_ptr_start
;
2571 /* FIXME: Check return value. I'm not sure whether it needs to read
2572 the entire buffer or not. */
2573 bfd_bread ((void *) input_ptr_start
, amt
, input_bfd
);
2574 input_ptr
= input_ptr_start
;
2580 bfd_size_type amt
= output_ptr
- output_ptr_start
;
2582 if (bfd_bwrite ((void *) (output_ptr_start
), amt
, output_bfd
) != amt
)
2584 output_ptr
= output_ptr_start
;
2588 #define THIS() ( *input_ptr )
2589 #define NEXT() { input_ptr++; if (input_ptr == input_ptr_end) fill (); }
2590 #define OUT(x) { *output_ptr++ = (x); if (output_ptr == output_ptr_end) flush (); }
2593 write_int (int value
)
2595 if (value
>= 0 && value
<= 127)
2601 unsigned int length
;
2603 /* How many significant bytes ? */
2604 /* FIXME FOR LONGER INTS. */
2605 if (value
& 0xff000000)
2607 else if (value
& 0x00ff0000)
2609 else if (value
& 0x0000ff00)
2614 OUT ((int) ieee_number_repeat_start_enum
+ length
);
2635 int length
= THIS ();
2648 #define VAR(x) ((x | 0x80))
2650 copy_expression (void)
2664 value
= (value
<< 8) | THIS ();
2666 value
= (value
<< 8) | THIS ();
2668 value
= (value
<< 8) | THIS ();
2676 value
= (value
<< 8) | THIS ();
2678 value
= (value
<< 8) | THIS ();
2686 value
= (value
<< 8) | THIS ();
2703 /* Not a number, just bug out with the answer. */
2704 write_int (*(--tos
));
2711 /* PLUS anything. */
2720 ieee_data_type
*ieee
;
2724 section_number
= THIS ();
2727 ieee
= IEEE_DATA (input_bfd
);
2728 s
= ieee
->section_table
[section_number
];
2730 if (s
->output_section
)
2731 value
= s
->output_section
->lma
;
2732 value
+= s
->output_offset
;
2739 write_int (*(--tos
));
2747 /* Drop the int in the buffer, and copy a null into the gap, which we
2748 will overwrite later. */
2751 fill_int (struct output_buffer_struct
*buf
)
2753 if (buf
->buffer
== output_buffer
)
2755 /* Still a chance to output the size. */
2756 int value
= output_ptr
- buf
->ptrp
+ 3;
2757 buf
->ptrp
[0] = value
>> 24;
2758 buf
->ptrp
[1] = value
>> 16;
2759 buf
->ptrp
[2] = value
>> 8;
2760 buf
->ptrp
[3] = value
>> 0;
2765 drop_int (struct output_buffer_struct
*buf
)
2797 buf
->ptrp
= output_ptr
;
2798 buf
->buffer
= output_buffer
;
2842 #define ID copy_id ()
2843 #define INT copy_int ()
2844 #define EXP copy_expression ()
2845 #define INTn(q) copy_int ()
2846 #define EXPn(q) copy_expression ()
2849 copy_till_end (void)
2928 EXPn (instruction address
);
2962 EXPn (external function
);
2972 INTn (locked
register);
2994 /* Attribute record. */
3024 /* Unique typedefs for module. */
3025 /* GLobal typedefs. */
3026 /* High level module scope beginning. */
3028 struct output_buffer_struct ob
;
3044 /* Global function. */
3046 struct output_buffer_struct ob
;
3061 EXPn (size of block
);
3067 /* File name for source line numbers. */
3069 struct output_buffer_struct ob
;
3090 /* Local function. */
3092 struct output_buffer_struct ob
;
3111 /* Assembler module scope beginning - */
3113 struct output_buffer_struct ob
;
3139 struct output_buffer_struct ob
;
3147 INTn (section index
);
3155 EXPn (Size in Maus
);
3208 /* Moves all the debug information from the source bfd to the output
3209 bfd, and relocates any expressions it finds. */
3212 relocate_debug (bfd
*output ATTRIBUTE_UNUSED
,
3217 unsigned char input_buffer
[IBS
];
3219 input_ptr_start
= input_ptr
= input_buffer
;
3220 input_ptr_end
= input_buffer
+ IBS
;
3222 /* FIXME: Check return value. I'm not sure whether it needs to read
3223 the entire buffer or not. */
3224 bfd_bread ((void *) input_ptr_start
, (bfd_size_type
) IBS
, input
);
3228 /* Gather together all the debug information from each input BFD into
3229 one place, relocating it and emitting it as we go. */
3232 ieee_write_debug_part (bfd
*abfd
)
3234 ieee_data_type
*ieee
= IEEE_DATA (abfd
);
3235 bfd_chain_type
*chain
= ieee
->chain_root
;
3236 unsigned char obuff
[OBS
];
3237 bfd_boolean some_debug
= FALSE
;
3238 file_ptr here
= bfd_tell (abfd
);
3240 output_ptr_start
= output_ptr
= obuff
;
3241 output_ptr_end
= obuff
+ OBS
;
3245 if (chain
== (bfd_chain_type
*) NULL
)
3249 for (s
= abfd
->sections
; s
!= NULL
; s
= s
->next
)
3250 if ((s
->flags
& SEC_DEBUGGING
) != 0)
3254 ieee
->w
.r
.debug_information_part
= 0;
3258 ieee
->w
.r
.debug_information_part
= here
;
3259 if (bfd_bwrite (s
->contents
, s
->size
, abfd
) != s
->size
)
3264 while (chain
!= (bfd_chain_type
*) NULL
)
3266 bfd
*entry
= chain
->this;
3267 ieee_data_type
*entry_ieee
= IEEE_DATA (entry
);
3269 if (entry_ieee
->w
.r
.debug_information_part
)
3271 if (bfd_seek (entry
, entry_ieee
->w
.r
.debug_information_part
,
3274 relocate_debug (abfd
, entry
);
3277 chain
= chain
->next
;
3281 ieee
->w
.r
.debug_information_part
= here
;
3283 ieee
->w
.r
.debug_information_part
= 0;
3291 /* Write the data in an ieee way. */
3294 ieee_write_data_part (bfd
*abfd
)
3298 ieee_data_type
*ieee
= IEEE_DATA (abfd
);
3299 ieee
->w
.r
.data_part
= bfd_tell (abfd
);
3301 for (s
= abfd
->sections
; s
!= (asection
*) NULL
; s
= s
->next
)
3303 /* Skip sections that have no loadable contents (.bss,
3305 if ((s
->flags
& SEC_LOAD
) == 0)
3308 /* Sort the reloc records so we can insert them in the correct
3310 if (s
->reloc_count
!= 0)
3312 if (! do_with_relocs (abfd
, s
))
3317 if (! do_without_relocs (abfd
, s
))
3326 init_for_output (bfd
*abfd
)
3330 for (s
= abfd
->sections
; s
!= (asection
*) NULL
; s
= s
->next
)
3332 if ((s
->flags
& SEC_DEBUGGING
) != 0)
3336 bfd_size_type size
= s
->size
;
3337 ieee_per_section (s
)->data
= bfd_alloc (abfd
, size
);
3338 if (!ieee_per_section (s
)->data
)
3345 /* Exec and core file sections. */
3347 /* Set section contents is complicated with IEEE since the format is
3348 not a byte image, but a record stream. */
3351 ieee_set_section_contents (bfd
*abfd
,
3353 const void * location
,
3355 bfd_size_type count
)
3357 if ((section
->flags
& SEC_DEBUGGING
) != 0)
3359 if (section
->contents
== NULL
)
3361 bfd_size_type size
= section
->size
;
3362 section
->contents
= bfd_alloc (abfd
, size
);
3363 if (section
->contents
== NULL
)
3366 /* bfd_set_section_contents has already checked that everything
3368 memcpy (section
->contents
+ offset
, location
, (size_t) count
);
3372 if (ieee_per_section (section
)->data
== (bfd_byte
*) NULL
)
3374 if (!init_for_output (abfd
))
3377 memcpy ((void *) (ieee_per_section (section
)->data
+ offset
),
3379 (unsigned int) count
);
3383 /* Write the external symbols of a file. IEEE considers two sorts of
3384 external symbols, public, and referenced. It uses to internal
3385 forms to index them as well. When we write them out we turn their
3386 symbol values into indexes from the right base. */
3389 ieee_write_external_part (bfd
*abfd
)
3392 ieee_data_type
*ieee
= IEEE_DATA (abfd
);
3393 unsigned int reference_index
= IEEE_REFERENCE_BASE
;
3394 unsigned int public_index
= IEEE_PUBLIC_BASE
+ 2;
3395 file_ptr here
= bfd_tell (abfd
);
3396 bfd_boolean hadone
= FALSE
;
3398 if (abfd
->outsymbols
!= (asymbol
**) NULL
)
3401 for (q
= abfd
->outsymbols
; *q
!= (asymbol
*) NULL
; q
++)
3405 if (bfd_is_und_section (p
->section
))
3407 /* This must be a symbol reference. */
3408 if (! ieee_write_byte (abfd
, ieee_external_reference_enum
)
3409 || ! ieee_write_int (abfd
, (bfd_vma
) reference_index
)
3410 || ! ieee_write_id (abfd
, p
->name
))
3412 p
->value
= reference_index
;
3416 else if (bfd_is_com_section (p
->section
))
3418 /* This is a weak reference. */
3419 if (! ieee_write_byte (abfd
, ieee_external_reference_enum
)
3420 || ! ieee_write_int (abfd
, (bfd_vma
) reference_index
)
3421 || ! ieee_write_id (abfd
, p
->name
)
3422 || ! ieee_write_byte (abfd
,
3423 ieee_weak_external_reference_enum
)
3424 || ! ieee_write_int (abfd
, (bfd_vma
) reference_index
)
3425 || ! ieee_write_int (abfd
, p
->value
))
3427 p
->value
= reference_index
;
3431 else if (p
->flags
& BSF_GLOBAL
)
3433 /* This must be a symbol definition. */
3434 if (! ieee_write_byte (abfd
, ieee_external_symbol_enum
)
3435 || ! ieee_write_int (abfd
, (bfd_vma
) public_index
)
3436 || ! ieee_write_id (abfd
, p
->name
)
3437 || ! ieee_write_2bytes (abfd
, ieee_attribute_record_enum
)
3438 || ! ieee_write_int (abfd
, (bfd_vma
) public_index
)
3439 || ! ieee_write_byte (abfd
, 15) /* Instruction address. */
3440 || ! ieee_write_byte (abfd
, 19) /* Static symbol. */
3441 || ! ieee_write_byte (abfd
, 1)) /* One of them. */
3444 /* Write out the value. */
3445 if (! ieee_write_2bytes (abfd
, ieee_value_record_enum
)
3446 || ! ieee_write_int (abfd
, (bfd_vma
) public_index
))
3448 if (! bfd_is_abs_section (p
->section
))
3450 if (abfd
->flags
& EXEC_P
)
3452 /* If fully linked, then output all symbols
3454 if (! (ieee_write_int
3457 + p
->section
->output_offset
3458 + p
->section
->output_section
->vma
))))
3463 if (! (ieee_write_expression
3465 p
->value
+ p
->section
->output_offset
,
3466 p
->section
->output_section
->symbol
,
3473 if (! ieee_write_expression (abfd
,
3475 bfd_abs_section_ptr
->symbol
,
3479 p
->value
= public_index
;
3485 /* This can happen - when there are gaps in the symbols read
3486 from an input ieee file. */
3491 ieee
->w
.r
.external_part
= here
;
3497 static const unsigned char exten
[] =
3500 0xf1, 0xce, 0x20, 0x00, 37, 3, 3, /* Set version 3 rev 3. */
3501 0xf1, 0xce, 0x20, 0x00, 39, 2, /* Keep symbol in original case. */
3502 0xf1, 0xce, 0x20, 0x00, 38 /* Set object type relocatable to x. */
3505 static const unsigned char envi
[] =
3509 /* 0xf1, 0xce, 0x21, 00, 50, 0x82, 0x07, 0xc7, 0x09, 0x11, 0x11,
3512 0xf1, 0xce, 0x21, 00, 52, 0x00, /* exec ok. */
3514 0xf1, 0xce, 0x21, 0, 53, 0x03,/* host unix. */
3515 /* 0xf1, 0xce, 0x21, 0, 54, 2,1,1 tool & version # */
3519 ieee_write_me_part (bfd
*abfd
)
3521 ieee_data_type
*ieee
= IEEE_DATA (abfd
);
3522 ieee
->w
.r
.trailer_part
= bfd_tell (abfd
);
3523 if (abfd
->start_address
)
3525 if (! ieee_write_2bytes (abfd
, ieee_value_starting_address_enum
)
3526 || ! ieee_write_byte (abfd
, ieee_function_either_open_b_enum
)
3527 || ! ieee_write_int (abfd
, abfd
->start_address
)
3528 || ! ieee_write_byte (abfd
, ieee_function_either_close_b_enum
))
3531 ieee
->w
.r
.me_record
= bfd_tell (abfd
);
3532 if (! ieee_write_byte (abfd
, ieee_module_end_enum
))
3537 /* Write out the IEEE processor ID. */
3540 ieee_write_processor (bfd
*abfd
)
3542 const bfd_arch_info_type
*arch
;
3544 arch
= bfd_get_arch_info (abfd
);
3548 if (! ieee_write_id (abfd
, bfd_printable_name (abfd
)))
3552 case bfd_arch_h8300
:
3553 if (! ieee_write_id (abfd
, "H8/300"))
3557 case bfd_arch_h8500
:
3558 if (! ieee_write_id (abfd
, "H8/500"))
3566 case bfd_mach_i960_core
:
3567 case bfd_mach_i960_ka_sa
:
3568 if (! ieee_write_id (abfd
, "80960KA"))
3572 case bfd_mach_i960_kb_sb
:
3573 if (! ieee_write_id (abfd
, "80960KB"))
3577 case bfd_mach_i960_ca
:
3578 if (! ieee_write_id (abfd
, "80960CA"))
3582 case bfd_mach_i960_mc
:
3583 case bfd_mach_i960_xa
:
3584 if (! ieee_write_id (abfd
, "80960MC"))
3596 default: id
= "68020"; break;
3597 case bfd_mach_m68000
: id
= "68000"; break;
3598 case bfd_mach_m68008
: id
= "68008"; break;
3599 case bfd_mach_m68010
: id
= "68010"; break;
3600 case bfd_mach_m68020
: id
= "68020"; break;
3601 case bfd_mach_m68030
: id
= "68030"; break;
3602 case bfd_mach_m68040
: id
= "68040"; break;
3603 case bfd_mach_m68060
: id
= "68060"; break;
3604 case bfd_mach_cpu32
: id
= "cpu32"; break;
3605 case bfd_mach_mcf_isa_a_nodiv
: id
= "isa-a:nodiv"; break;
3606 case bfd_mach_mcf_isa_a
: id
= "isa-a"; break;
3607 case bfd_mach_mcf_isa_a_mac
: id
= "isa-a:mac"; break;
3608 case bfd_mach_mcf_isa_a_emac
: id
= "isa-a:emac"; break;
3609 case bfd_mach_mcf_isa_aplus
: id
= "isa-aplus"; break;
3610 case bfd_mach_mcf_isa_aplus_mac
: id
= "isa-aplus:mac"; break;
3611 case bfd_mach_mcf_isa_aplus_emac
: id
= "isa-aplus:mac"; break;
3612 case bfd_mach_mcf_isa_b_nousp
: id
= "isa-b:nousp"; break;
3613 case bfd_mach_mcf_isa_b_nousp_mac
: id
= "isa-b:nousp:mac"; break;
3614 case bfd_mach_mcf_isa_b_nousp_emac
: id
= "isa-b:nousp:emac"; break;
3615 case bfd_mach_mcf_isa_b
: id
= "isa-b"; break;
3616 case bfd_mach_mcf_isa_b_mac
: id
= "isa-b:mac"; break;
3617 case bfd_mach_mcf_isa_b_emac
: id
= "isa-b:emac"; break;
3618 case bfd_mach_mcf_isa_b_float
: id
= "isa-b:float"; break;
3619 case bfd_mach_mcf_isa_b_float_mac
: id
= "isa-b:float:mac"; break;
3620 case bfd_mach_mcf_isa_b_float_emac
: id
= "isa-b:float:emac"; break;
3621 case bfd_mach_mcf_isa_c
: id
= "isa-c"; break;
3622 case bfd_mach_mcf_isa_c_mac
: id
= "isa-c:mac"; break;
3623 case bfd_mach_mcf_isa_c_emac
: id
= "isa-c:emac"; break;
3624 case bfd_mach_mcf_isa_c_nodiv
: id
= "isa-c:nodiv"; break;
3625 case bfd_mach_mcf_isa_c_nodiv_mac
: id
= "isa-c:nodiv:mac"; break;
3626 case bfd_mach_mcf_isa_c_nodiv_emac
: id
= "isa-c:nodiv:emac"; break;
3629 if (! ieee_write_id (abfd
, id
))
3639 ieee_write_object_contents (bfd
*abfd
)
3641 ieee_data_type
*ieee
= IEEE_DATA (abfd
);
3645 /* Fast forward over the header area. */
3646 if (bfd_seek (abfd
, (file_ptr
) 0, SEEK_SET
) != 0)
3649 if (! ieee_write_byte (abfd
, ieee_module_beginning_enum
)
3650 || ! ieee_write_processor (abfd
)
3651 || ! ieee_write_id (abfd
, abfd
->filename
))
3654 /* Fast forward over the variable bits. */
3655 if (! ieee_write_byte (abfd
, ieee_address_descriptor_enum
))
3659 if (! ieee_write_byte (abfd
, (bfd_byte
) (bfd_arch_bits_per_byte (abfd
))))
3661 /* MAU's per address. */
3662 if (! ieee_write_byte (abfd
,
3663 (bfd_byte
) (bfd_arch_bits_per_address (abfd
)
3664 / bfd_arch_bits_per_byte (abfd
))))
3667 old
= bfd_tell (abfd
);
3668 if (bfd_seek (abfd
, (file_ptr
) (8 * N_W_VARIABLES
), SEEK_CUR
) != 0)
3671 ieee
->w
.r
.extension_record
= bfd_tell (abfd
);
3672 if (bfd_bwrite ((char *) exten
, (bfd_size_type
) sizeof (exten
), abfd
)
3675 if (abfd
->flags
& EXEC_P
)
3677 if (! ieee_write_byte (abfd
, 0x1)) /* Absolute. */
3682 if (! ieee_write_byte (abfd
, 0x2)) /* Relocateable. */
3686 ieee
->w
.r
.environmental_record
= bfd_tell (abfd
);
3687 if (bfd_bwrite ((char *) envi
, (bfd_size_type
) sizeof (envi
), abfd
)
3691 /* The HP emulator database requires a timestamp in the file. */
3697 t
= (struct tm
*) localtime (&now
);
3698 if (! ieee_write_2bytes (abfd
, (int) ieee_atn_record_enum
)
3699 || ! ieee_write_byte (abfd
, 0x21)
3700 || ! ieee_write_byte (abfd
, 0)
3701 || ! ieee_write_byte (abfd
, 50)
3702 || ! ieee_write_int (abfd
, (bfd_vma
) (t
->tm_year
+ 1900))
3703 || ! ieee_write_int (abfd
, (bfd_vma
) (t
->tm_mon
+ 1))
3704 || ! ieee_write_int (abfd
, (bfd_vma
) t
->tm_mday
)
3705 || ! ieee_write_int (abfd
, (bfd_vma
) t
->tm_hour
)
3706 || ! ieee_write_int (abfd
, (bfd_vma
) t
->tm_min
)
3707 || ! ieee_write_int (abfd
, (bfd_vma
) t
->tm_sec
))
3715 if (! ieee_write_section_part (abfd
))
3717 /* First write the symbols. This changes their values into table
3718 indeces so we cant use it after this point. */
3719 if (! ieee_write_external_part (abfd
))
3722 /* Write any debugs we have been told about. */
3723 if (! ieee_write_debug_part (abfd
))
3726 /* Can only write the data once the symbols have been written, since
3727 the data contains relocation information which points to the
3729 if (! ieee_write_data_part (abfd
))
3732 /* At the end we put the end! */
3733 if (! ieee_write_me_part (abfd
))
3736 /* Generate the header. */
3737 if (bfd_seek (abfd
, old
, SEEK_SET
) != 0)
3740 for (i
= 0; i
< N_W_VARIABLES
; i
++)
3742 if (! ieee_write_2bytes (abfd
, ieee_assign_value_to_variable_enum
)
3743 || ! ieee_write_byte (abfd
, (bfd_byte
) i
)
3744 || ! ieee_write_int5_out (abfd
, (bfd_vma
) ieee
->w
.offset
[i
]))
3751 /* Native-level interface to symbols. */
3753 /* We read the symbols into a buffer, which is discarded when this
3754 function exits. We read the strings into a buffer large enough to
3755 hold them all plus all the cached symbol entries. */
3758 ieee_make_empty_symbol (bfd
*abfd
)
3760 bfd_size_type amt
= sizeof (ieee_symbol_type
);
3761 ieee_symbol_type
*new_symbol
= (ieee_symbol_type
*) bfd_zalloc (abfd
, amt
);
3765 new_symbol
->symbol
.the_bfd
= abfd
;
3766 return &new_symbol
->symbol
;
3770 ieee_openr_next_archived_file (bfd
*arch
, bfd
*prev
)
3772 ieee_ar_data_type
*ar
= IEEE_AR_DATA (arch
);
3774 /* Take the next one from the arch state, or reset. */
3775 if (prev
== (bfd
*) NULL
)
3776 /* Reset the index - the first two entries are bogus. */
3777 ar
->element_index
= 2;
3781 ieee_ar_obstack_type
*p
= ar
->elements
+ ar
->element_index
;
3783 ar
->element_index
++;
3784 if (ar
->element_index
<= ar
->element_count
)
3786 if (p
->file_offset
!= (file_ptr
) 0)
3788 if (p
->abfd
== (bfd
*) NULL
)
3790 p
->abfd
= _bfd_create_empty_archive_element_shell (arch
);
3791 p
->abfd
->origin
= p
->file_offset
;
3798 bfd_set_error (bfd_error_no_more_archived_files
);
3804 #define ieee_find_nearest_line _bfd_nosymbols_find_nearest_line
3805 #define ieee_find_line _bfd_nosymbols_find_line
3806 #define ieee_find_inliner_info _bfd_nosymbols_find_inliner_info
3809 ieee_generic_stat_arch_elt (bfd
*abfd
, struct stat
*buf
)
3811 ieee_ar_data_type
*ar
= (ieee_ar_data_type
*) NULL
;
3812 ieee_data_type
*ieee
;
3814 if (abfd
->my_archive
!= NULL
)
3815 ar
= abfd
->my_archive
->tdata
.ieee_ar_data
;
3816 if (ar
== (ieee_ar_data_type
*) NULL
)
3818 bfd_set_error (bfd_error_invalid_operation
);
3822 if (IEEE_DATA (abfd
) == NULL
)
3824 if (ieee_object_p (abfd
) == NULL
)
3826 bfd_set_error (bfd_error_wrong_format
);
3831 ieee
= IEEE_DATA (abfd
);
3833 buf
->st_size
= ieee
->w
.r
.me_record
+ 1;
3834 buf
->st_mode
= 0644;
3839 ieee_sizeof_headers (bfd
*abfd ATTRIBUTE_UNUSED
,
3840 struct bfd_link_info
*info ATTRIBUTE_UNUSED
)
3845 #define ieee_close_and_cleanup _bfd_generic_close_and_cleanup
3846 #define ieee_bfd_free_cached_info _bfd_generic_bfd_free_cached_info
3848 #define ieee_slurp_armap bfd_true
3849 #define ieee_slurp_extended_name_table bfd_true
3850 #define ieee_construct_extended_name_table \
3852 (bfd *, char **, bfd_size_type *, const char **)) \
3854 #define ieee_truncate_arname bfd_dont_truncate_arname
3855 #define ieee_write_armap \
3857 (bfd *, unsigned int, struct orl *, unsigned int, int)) \
3859 #define ieee_read_ar_hdr bfd_nullvoidptr
3860 #define ieee_write_ar_hdr ((bfd_boolean (*) (bfd *, bfd *)) bfd_false)
3861 #define ieee_update_armap_timestamp bfd_true
3862 #define ieee_get_elt_at_index _bfd_generic_get_elt_at_index
3864 #define ieee_get_symbol_version_string \
3865 _bfd_nosymbols_get_symbol_version_string
3866 #define ieee_bfd_is_target_special_symbol \
3867 ((bfd_boolean (*) (bfd *, asymbol *)) bfd_false)
3868 #define ieee_bfd_is_local_label_name bfd_generic_is_local_label_name
3869 #define ieee_get_lineno _bfd_nosymbols_get_lineno
3870 #define ieee_bfd_make_debug_symbol _bfd_nosymbols_bfd_make_debug_symbol
3871 #define ieee_read_minisymbols _bfd_generic_read_minisymbols
3872 #define ieee_minisymbol_to_symbol _bfd_generic_minisymbol_to_symbol
3874 #define ieee_bfd_reloc_type_lookup _bfd_norelocs_bfd_reloc_type_lookup
3875 #define ieee_bfd_reloc_name_lookup _bfd_norelocs_bfd_reloc_name_lookup
3877 #define ieee_set_arch_mach _bfd_generic_set_arch_mach
3879 #define ieee_get_section_contents_in_window \
3880 _bfd_generic_get_section_contents_in_window
3881 #define ieee_bfd_get_relocated_section_contents \
3882 bfd_generic_get_relocated_section_contents
3883 #define ieee_bfd_relax_section bfd_generic_relax_section
3884 #define ieee_bfd_gc_sections bfd_generic_gc_sections
3885 #define ieee_bfd_lookup_section_flags bfd_generic_lookup_section_flags
3886 #define ieee_bfd_merge_sections bfd_generic_merge_sections
3887 #define ieee_bfd_is_group_section bfd_generic_is_group_section
3888 #define ieee_bfd_discard_group bfd_generic_discard_group
3889 #define ieee_section_already_linked \
3890 _bfd_generic_section_already_linked
3891 #define ieee_bfd_define_common_symbol bfd_generic_define_common_symbol
3892 #define ieee_bfd_define_start_stop bfd_generic_define_start_stop
3893 #define ieee_bfd_link_hash_table_create _bfd_generic_link_hash_table_create
3894 #define ieee_bfd_link_add_symbols _bfd_generic_link_add_symbols
3895 #define ieee_bfd_link_just_syms _bfd_generic_link_just_syms
3896 #define ieee_bfd_copy_link_hash_symbol_type \
3897 _bfd_generic_copy_link_hash_symbol_type
3898 #define ieee_bfd_final_link _bfd_generic_final_link
3899 #define ieee_bfd_link_split_section _bfd_generic_link_split_section
3900 #define ieee_bfd_link_check_relocs _bfd_generic_link_check_relocs
3901 #define ieee_set_reloc _bfd_generic_set_reloc
3903 const bfd_target ieee_vec
=
3906 bfd_target_ieee_flavour
,
3907 BFD_ENDIAN_UNKNOWN
, /* Target byte order. */
3908 BFD_ENDIAN_UNKNOWN
, /* Target headers byte order. */
3909 (HAS_RELOC
| EXEC_P
| /* Object flags. */
3910 HAS_LINENO
| HAS_DEBUG
|
3911 HAS_SYMS
| HAS_LOCALS
| WP_TEXT
| D_PAGED
),
3912 (SEC_CODE
| SEC_DATA
| SEC_ROM
| SEC_HAS_CONTENTS
3913 | SEC_ALLOC
| SEC_LOAD
| SEC_RELOC
), /* Section flags. */
3914 '_', /* Leading underscore. */
3915 ' ', /* AR_pad_char. */
3916 16, /* AR_max_namelen. */
3917 0, /* match priority. */
3918 bfd_getb64
, bfd_getb_signed_64
, bfd_putb64
,
3919 bfd_getb32
, bfd_getb_signed_32
, bfd_putb32
,
3920 bfd_getb16
, bfd_getb_signed_16
, bfd_putb16
, /* Data. */
3921 bfd_getb64
, bfd_getb_signed_64
, bfd_putb64
,
3922 bfd_getb32
, bfd_getb_signed_32
, bfd_putb32
,
3923 bfd_getb16
, bfd_getb_signed_16
, bfd_putb16
, /* Headers. */
3926 ieee_object_p
, /* bfd_check_format. */
3933 _bfd_generic_mkarchive
,
3938 ieee_write_object_contents
,
3939 _bfd_write_archive_contents
,
3943 /* ieee_close_and_cleanup, ieee_bfd_free_cached_info, ieee_new_section_hook,
3944 ieee_get_section_contents, ieee_get_section_contents_in_window. */
3945 BFD_JUMP_TABLE_GENERIC (ieee
),
3947 BFD_JUMP_TABLE_COPY (_bfd_generic
),
3948 BFD_JUMP_TABLE_CORE (_bfd_nocore
),
3950 /* ieee_slurp_armap, ieee_slurp_extended_name_table,
3951 ieee_construct_extended_name_table, ieee_truncate_arname,
3952 ieee_write_armap, ieee_read_ar_hdr, ieee_openr_next_archived_file,
3953 ieee_get_elt_at_index, ieee_generic_stat_arch_elt,
3954 ieee_update_armap_timestamp. */
3955 BFD_JUMP_TABLE_ARCHIVE (ieee
),
3957 /* ieee_get_symtab_upper_bound, ieee_canonicalize_symtab,
3958 ieee_make_empty_symbol, ieee_print_symbol, ieee_get_symbol_info,
3959 ieee_bfd_is_local_label_name, ieee_get_lineno,
3960 ieee_find_nearest_line, ieee_bfd_make_debug_symbol,
3961 ieee_read_minisymbols, ieee_minisymbol_to_symbol. */
3962 BFD_JUMP_TABLE_SYMBOLS (ieee
),
3964 /* ieee_get_reloc_upper_bound, ieee_canonicalize_reloc,
3965 ieee_bfd_reloc_type_lookup. */
3966 BFD_JUMP_TABLE_RELOCS (ieee
),
3968 /* ieee_set_arch_mach, ieee_set_section_contents. */
3969 BFD_JUMP_TABLE_WRITE (ieee
),
3971 /* ieee_sizeof_headers, ieee_bfd_get_relocated_section_contents,
3972 ieee_bfd_relax_section, ieee_bfd_link_hash_table_create,
3973 ieee_bfd_link_add_symbols, ieee_bfd_final_link,
3974 ieee_bfd_link_split_section, ieee_bfd_gc_sections,
3975 ieee_bfd_merge_sections. */
3976 BFD_JUMP_TABLE_LINK (ieee
),
3978 BFD_JUMP_TABLE_DYNAMIC (_bfd_nodynamic
),