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 (%ld chars, max 65535)"), abfd
, (long) 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 (long) 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 %Ld 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
);
1252 section
->name
= name
;
1254 /* Skip these fields, which we don't care about. */
1256 bfd_vma parent
, brother
, context
;
1258 parse_int (&(ieee
->h
), &parent
);
1259 parse_int (&(ieee
->h
), &brother
);
1260 parse_int (&(ieee
->h
), &context
);
1264 case ieee_section_alignment_enum
:
1266 unsigned int section_index
;
1270 if (! next_byte (&(ieee
->h
)))
1272 section_index
= must_parse_int (&ieee
->h
);
1273 section
= get_section_entry (abfd
, ieee
, section_index
);
1274 if (section_index
> ieee
->section_count
)
1275 ieee
->section_count
= section_index
;
1277 section
->alignment_power
=
1278 bfd_log2 (must_parse_int (&ieee
->h
));
1279 (void) parse_int (&(ieee
->h
), &value
);
1282 case ieee_e2_first_byte_enum
:
1285 ieee_record_enum_type t
;
1287 t
= (ieee_record_enum_type
) (read_2bytes (&(ieee
->h
)));
1290 case ieee_section_size_enum
:
1291 section
= ieee
->section_table
[must_parse_int (&(ieee
->h
))];
1292 section
->size
= must_parse_int (&(ieee
->h
));
1294 case ieee_physical_region_size_enum
:
1295 section
= ieee
->section_table
[must_parse_int (&(ieee
->h
))];
1296 section
->size
= must_parse_int (&(ieee
->h
));
1298 case ieee_region_base_address_enum
:
1299 section
= ieee
->section_table
[must_parse_int (&(ieee
->h
))];
1300 section
->vma
= must_parse_int (&(ieee
->h
));
1301 section
->lma
= section
->vma
;
1303 case ieee_mau_size_enum
:
1304 must_parse_int (&(ieee
->h
));
1305 must_parse_int (&(ieee
->h
));
1307 case ieee_m_value_enum
:
1308 must_parse_int (&(ieee
->h
));
1309 must_parse_int (&(ieee
->h
));
1311 case ieee_section_base_address_enum
:
1312 section
= ieee
->section_table
[must_parse_int (&(ieee
->h
))];
1313 section
->vma
= must_parse_int (&(ieee
->h
));
1314 section
->lma
= section
->vma
;
1316 case ieee_section_offset_enum
:
1317 (void) must_parse_int (&(ieee
->h
));
1318 (void) must_parse_int (&(ieee
->h
));
1334 /* Make a section for the debugging information, if any. We don't try
1335 to interpret the debugging information; we just point the section
1336 at the area in the file so that program which understand can dig it
1340 ieee_slurp_debug (bfd
*abfd
)
1342 ieee_data_type
*ieee
= IEEE_DATA (abfd
);
1347 if (ieee
->w
.r
.debug_information_part
== 0)
1350 flags
= SEC_DEBUGGING
| SEC_HAS_CONTENTS
;
1351 sec
= bfd_make_section_with_flags (abfd
, ".debug", flags
);
1354 sec
->filepos
= ieee
->w
.r
.debug_information_part
;
1356 debug_end
= ieee_part_after (ieee
, ieee
->w
.r
.debug_information_part
);
1357 sec
->size
= debug_end
- ieee
->w
.r
.debug_information_part
;
1362 /* Archive stuff. */
1364 static const bfd_target
*
1365 ieee_archive_p (bfd
*abfd
)
1369 static unsigned char buffer
[512];
1370 file_ptr buffer_offset
= 0;
1371 ieee_ar_data_type
*save
= abfd
->tdata
.ieee_ar_data
;
1372 ieee_ar_data_type
*ieee
;
1373 bfd_size_type alc_elts
;
1374 ieee_ar_obstack_type
*elts
= NULL
;
1375 bfd_size_type amt
= sizeof (ieee_ar_data_type
);
1377 abfd
->tdata
.ieee_ar_data
= bfd_alloc (abfd
, amt
);
1378 if (!abfd
->tdata
.ieee_ar_data
)
1379 goto error_ret_restore
;
1380 ieee
= IEEE_AR_DATA (abfd
);
1382 /* Ignore the return value here. It doesn't matter if we don't read
1383 the entire buffer. We might have a very small ieee file. */
1384 if (bfd_bread ((void *) buffer
, (bfd_size_type
) sizeof (buffer
), abfd
) <= 0)
1385 goto got_wrong_format_error
;
1387 ieee
->h
.first_byte
= buffer
;
1388 ieee
->h
.input_p
= buffer
;
1389 ieee
->h
.total_amt
= sizeof (buffer
);
1390 ieee
->h
.end_p
= buffer
+ sizeof (buffer
);
1392 ieee
->h
.abfd
= abfd
;
1394 if (this_byte (&(ieee
->h
)) != Module_Beginning
)
1395 goto got_wrong_format_error
;
1397 (void) next_byte (&(ieee
->h
));
1399 library
= read_id (&(ieee
->h
));
1400 if (library
== NULL
)
1401 goto got_wrong_format_error
;
1402 if (strcmp (library
, "LIBRARY") != 0)
1403 goto got_wrong_format_error
;
1405 /* Throw away the filename. */
1406 read_id (&(ieee
->h
));
1408 ieee
->element_count
= 0;
1409 ieee
->element_index
= 0;
1411 (void) next_byte (&(ieee
->h
)); /* Drop the ad part. */
1412 must_parse_int (&(ieee
->h
)); /* And the two dummy numbers. */
1413 must_parse_int (&(ieee
->h
));
1416 elts
= bfd_malloc (alc_elts
* sizeof *elts
);
1420 /* Read the index of the BB table. */
1424 ieee_ar_obstack_type
*t
;
1426 rec
= read_2bytes (&(ieee
->h
));
1427 if (rec
!= (int) ieee_assign_value_to_variable_enum
)
1430 if (ieee
->element_count
>= alc_elts
)
1432 ieee_ar_obstack_type
*n
;
1435 n
= bfd_realloc (elts
, alc_elts
* sizeof (* elts
));
1441 t
= &elts
[ieee
->element_count
];
1442 ieee
->element_count
++;
1444 must_parse_int (&(ieee
->h
));
1445 t
->file_offset
= must_parse_int (&(ieee
->h
));
1446 t
->abfd
= (bfd
*) NULL
;
1448 /* Make sure that we don't go over the end of the buffer. */
1449 if ((size_t) ieee_pos (IEEE_DATA (abfd
)) > sizeof (buffer
) / 2)
1451 /* Past half way, reseek and reprime. */
1452 buffer_offset
+= ieee_pos (IEEE_DATA (abfd
));
1453 if (bfd_seek (abfd
, buffer_offset
, SEEK_SET
) != 0)
1456 /* Again ignore return value of bfd_bread. */
1457 bfd_bread ((void *) buffer
, (bfd_size_type
) sizeof (buffer
), abfd
);
1458 ieee
->h
.first_byte
= buffer
;
1459 ieee
->h
.input_p
= buffer
;
1460 ieee
->h
.total_amt
= sizeof (buffer
);
1461 ieee
->h
.end_p
= buffer
+ sizeof (buffer
);
1465 amt
= ieee
->element_count
;
1466 amt
*= sizeof *ieee
->elements
;
1467 ieee
->elements
= bfd_alloc (abfd
, amt
);
1468 if (ieee
->elements
== NULL
)
1471 memcpy (ieee
->elements
, elts
, (size_t) amt
);
1475 /* Now scan the area again, and replace BB offsets with file offsets. */
1476 for (i
= 2; i
< ieee
->element_count
; i
++)
1478 if (bfd_seek (abfd
, ieee
->elements
[i
].file_offset
, SEEK_SET
) != 0)
1481 /* Again ignore return value of bfd_bread. */
1482 bfd_bread ((void *) buffer
, (bfd_size_type
) sizeof (buffer
), abfd
);
1483 ieee
->h
.first_byte
= buffer
;
1484 ieee
->h
.input_p
= buffer
;
1485 ieee
->h
.total_amt
= sizeof (buffer
);
1486 ieee
->h
.end_p
= buffer
+ sizeof (buffer
);
1488 (void) next_byte (&(ieee
->h
)); /* Drop F8. */
1489 if (! next_byte (&(ieee
->h
))) /* Drop 14. */
1491 must_parse_int (&(ieee
->h
)); /* Drop size of block. */
1493 if (must_parse_int (&(ieee
->h
)) != 0)
1494 /* This object has been deleted. */
1495 ieee
->elements
[i
].file_offset
= 0;
1497 ieee
->elements
[i
].file_offset
= must_parse_int (&(ieee
->h
));
1500 /* abfd->has_armap = ;*/
1504 got_wrong_format_error
:
1505 bfd_set_error (bfd_error_wrong_format
);
1509 bfd_release (abfd
, ieee
);
1511 abfd
->tdata
.ieee_ar_data
= save
;
1517 ieee_mkobject (bfd
*abfd
)
1521 output_ptr_start
= NULL
;
1523 output_ptr_end
= NULL
;
1524 input_ptr_start
= NULL
;
1526 input_ptr_end
= NULL
;
1530 amt
= sizeof (ieee_data_type
);
1531 abfd
->tdata
.ieee_data
= bfd_zalloc (abfd
, amt
);
1532 return abfd
->tdata
.ieee_data
!= NULL
;
1536 do_one (ieee_data_type
*ieee
,
1537 ieee_per_section_type
*current_map
,
1538 unsigned char *location_ptr
,
1542 switch (this_byte (&(ieee
->h
)))
1544 case ieee_load_constant_bytes_enum
:
1546 unsigned int number_of_maus
;
1549 if (! next_byte (&(ieee
->h
)))
1551 number_of_maus
= must_parse_int (&(ieee
->h
));
1553 for (i
= 0; i
< number_of_maus
; i
++)
1555 location_ptr
[current_map
->pc
++] = this_byte (&(ieee
->h
));
1556 next_byte (&(ieee
->h
));
1561 case ieee_load_with_relocation_enum
:
1563 bfd_boolean loop
= TRUE
;
1565 if (! next_byte (&(ieee
->h
)))
1569 switch (this_byte (&(ieee
->h
)))
1571 case ieee_variable_R_enum
:
1573 case ieee_function_signed_open_b_enum
:
1574 case ieee_function_unsigned_open_b_enum
:
1575 case ieee_function_either_open_b_enum
:
1577 unsigned int extra
= 4;
1578 bfd_boolean pcrel
= FALSE
;
1582 r
= bfd_alloc (ieee
->h
.abfd
, sizeof (* r
));
1586 *(current_map
->reloc_tail_ptr
) = r
;
1587 current_map
->reloc_tail_ptr
= &r
->next
;
1588 r
->next
= (ieee_reloc_type
*) NULL
;
1589 if (! next_byte (&(ieee
->h
)))
1592 r
->relent
.sym_ptr_ptr
= 0;
1593 if (! parse_expression (ieee
,
1596 &pcrel
, &extra
, §ion
))
1599 r
->relent
.address
= current_map
->pc
;
1600 s
->flags
|= SEC_RELOC
;
1601 s
->owner
->flags
|= HAS_RELOC
;
1603 if (r
->relent
.sym_ptr_ptr
== NULL
&& section
!= NULL
)
1604 r
->relent
.sym_ptr_ptr
= section
->symbol_ptr_ptr
;
1606 if (this_byte (&(ieee
->h
)) == (int) ieee_comma
)
1608 if (! next_byte (&(ieee
->h
)))
1610 /* Fetch number of bytes to pad. */
1611 extra
= must_parse_int (&(ieee
->h
));
1614 switch (this_byte (&(ieee
->h
)))
1616 case ieee_function_signed_close_b_enum
:
1617 if (! next_byte (&(ieee
->h
)))
1620 case ieee_function_unsigned_close_b_enum
:
1621 if (! next_byte (&(ieee
->h
)))
1624 case ieee_function_either_close_b_enum
:
1625 if (! next_byte (&(ieee
->h
)))
1631 /* Build a relocation entry for this type. */
1632 /* If pc rel then stick -ve pc into instruction
1633 and take out of reloc ..
1635 I've changed this. It's all too complicated. I
1636 keep 0 in the instruction now. */
1645 #if KEEPMINUSPCININST
1646 bfd_put_32 (ieee
->h
.abfd
, -current_map
->pc
,
1647 location_ptr
+ current_map
->pc
);
1648 r
->relent
.howto
= &rel32_howto
;
1649 r
->relent
.addend
-= current_map
->pc
;
1651 bfd_put_32 (ieee
->h
.abfd
, (bfd_vma
) 0, location_ptr
+
1653 r
->relent
.howto
= &rel32_howto
;
1658 bfd_put_32 (ieee
->h
.abfd
, (bfd_vma
) 0,
1659 location_ptr
+ current_map
->pc
);
1660 r
->relent
.howto
= &abs32_howto
;
1662 current_map
->pc
+= 4;
1667 #if KEEPMINUSPCININST
1668 bfd_put_16 (ieee
->h
.abfd
, (bfd_vma
) -current_map
->pc
,
1669 location_ptr
+ current_map
->pc
);
1670 r
->relent
.addend
-= current_map
->pc
;
1671 r
->relent
.howto
= &rel16_howto
;
1674 bfd_put_16 (ieee
->h
.abfd
, (bfd_vma
) 0,
1675 location_ptr
+ current_map
->pc
);
1676 r
->relent
.howto
= &rel16_howto
;
1682 bfd_put_16 (ieee
->h
.abfd
, (bfd_vma
) 0,
1683 location_ptr
+ current_map
->pc
);
1684 r
->relent
.howto
= &abs16_howto
;
1686 current_map
->pc
+= 2;
1691 #if KEEPMINUSPCININST
1692 bfd_put_8 (ieee
->h
.abfd
, (int) (-current_map
->pc
), location_ptr
+ current_map
->pc
);
1693 r
->relent
.addend
-= current_map
->pc
;
1694 r
->relent
.howto
= &rel8_howto
;
1696 bfd_put_8 (ieee
->h
.abfd
, 0, location_ptr
+ current_map
->pc
);
1697 r
->relent
.howto
= &rel8_howto
;
1702 bfd_put_8 (ieee
->h
.abfd
, 0, location_ptr
+ current_map
->pc
);
1703 r
->relent
.howto
= &abs8_howto
;
1705 current_map
->pc
+= 1;
1718 if (parse_int (&(ieee
->h
), &this_size
))
1722 for (i
= 0; i
< this_size
; i
++)
1724 location_ptr
[current_map
->pc
++] = this_byte (&(ieee
->h
));
1725 if (! next_byte (&(ieee
->h
)))
1734 /* Prevent more than the first load-item of an LR record
1735 from being repeated (MRI convention). */
1736 if (iterations
!= 1)
1744 /* Read in all the section data and relocation stuff too. */
1747 ieee_slurp_section_data (bfd
*abfd
)
1749 bfd_byte
*location_ptr
= (bfd_byte
*) NULL
;
1750 ieee_data_type
*ieee
= IEEE_DATA (abfd
);
1751 unsigned int section_number
;
1752 ieee_per_section_type
*current_map
= NULL
;
1755 /* Seek to the start of the data area. */
1756 if (ieee
->read_data
)
1758 ieee
->read_data
= TRUE
;
1760 if (! ieee_seek (ieee
, ieee
->w
.r
.data_part
))
1763 /* Allocate enough space for all the section contents. */
1764 for (s
= abfd
->sections
; s
!= (asection
*) NULL
; s
= s
->next
)
1766 ieee_per_section_type
*per
= ieee_per_section (s
);
1769 if ((s
->flags
& SEC_DEBUGGING
) != 0)
1771 per
->data
= bfd_alloc (ieee
->h
.abfd
, s
->size
);
1774 relpp
= &s
->relocation
;
1775 per
->reloc_tail_ptr
= (ieee_reloc_type
**) relpp
;
1780 switch (this_byte (&(ieee
->h
)))
1782 /* IF we see anything strange then quit. */
1786 case ieee_set_current_section_enum
:
1787 if (! next_byte (&(ieee
->h
)))
1789 section_number
= must_parse_int (&(ieee
->h
));
1790 s
= ieee
->section_table
[section_number
];
1791 s
->flags
|= SEC_LOAD
| SEC_HAS_CONTENTS
;
1792 current_map
= ieee_per_section (s
);
1793 location_ptr
= current_map
->data
- s
->vma
;
1794 /* The document I have says that Microtec's compilers reset
1795 this after a sec section, even though the standard says not
1797 current_map
->pc
= s
->vma
;
1800 case ieee_e2_first_byte_enum
:
1801 if (! next_byte (&(ieee
->h
)))
1803 switch (this_byte (&(ieee
->h
)))
1805 case ieee_set_current_pc_enum
& 0xff:
1808 ieee_symbol_index_type symbol
;
1812 if (! next_byte (&(ieee
->h
)))
1814 must_parse_int (&(ieee
->h
)); /* Throw away section #. */
1815 if (! parse_expression (ieee
, &value
,
1821 current_map
->pc
= value
;
1822 BFD_ASSERT ((unsigned) (value
- s
->vma
) <= s
->size
);
1826 case ieee_value_starting_address_enum
& 0xff:
1827 if (! next_byte (&(ieee
->h
)))
1829 if (this_byte (&(ieee
->h
)) == ieee_function_either_open_b_enum
)
1831 if (! next_byte (&(ieee
->h
)))
1834 abfd
->start_address
= must_parse_int (&(ieee
->h
));
1835 /* We've got to the end of the data now - */
1842 case ieee_repeat_data_enum
:
1844 /* Repeat the following LD or LR n times - we do this by
1845 remembering the stream pointer before running it and
1846 resetting it and running it n times. We special case
1847 the repetition of a repeat_data/load_constant. */
1848 unsigned int iterations
;
1849 unsigned char *start
;
1851 if (! next_byte (&(ieee
->h
)))
1853 iterations
= must_parse_int (&(ieee
->h
));
1854 start
= ieee
->h
.input_p
;
1855 if (start
[0] == (int) ieee_load_constant_bytes_enum
1858 while (iterations
!= 0)
1860 location_ptr
[current_map
->pc
++] = start
[2];
1863 (void) next_byte (&(ieee
->h
));
1864 (void) next_byte (&(ieee
->h
));
1865 if (! next_byte (&(ieee
->h
)))
1870 while (iterations
!= 0)
1872 ieee
->h
.input_p
= start
;
1873 if (!do_one (ieee
, current_map
, location_ptr
, s
,
1881 case ieee_load_constant_bytes_enum
:
1882 case ieee_load_with_relocation_enum
:
1883 if (!do_one (ieee
, current_map
, location_ptr
, s
, 1))
1889 static const bfd_target
*
1890 ieee_object_p (bfd
*abfd
)
1894 ieee_data_type
*ieee
;
1895 static unsigned char buffer
[300];
1896 ieee_data_type
*save
= IEEE_DATA (abfd
);
1899 abfd
->tdata
.ieee_data
= 0;
1900 ieee_mkobject (abfd
);
1902 ieee
= IEEE_DATA (abfd
);
1903 if (bfd_seek (abfd
, (file_ptr
) 0, SEEK_SET
) != 0)
1905 /* Read the first few bytes in to see if it makes sense. Ignore
1906 bfd_bread return value; The file might be very small. */
1907 if (bfd_bread ((void *) buffer
, (bfd_size_type
) sizeof (buffer
), abfd
) <= 0)
1908 goto got_wrong_format
;
1910 ieee
->h
.input_p
= buffer
;
1911 ieee
->h
.total_amt
= sizeof (buffer
);
1912 ieee
->h
.end_p
= buffer
+ sizeof (buffer
);
1914 if (this_byte_and_next (&(ieee
->h
)) != Module_Beginning
)
1915 goto got_wrong_format
;
1917 ieee
->read_symbols
= FALSE
;
1918 ieee
->read_data
= FALSE
;
1919 ieee
->section_count
= 0;
1920 ieee
->external_symbol_max_index
= 0;
1921 ieee
->external_symbol_min_index
= IEEE_PUBLIC_BASE
;
1922 ieee
->external_reference_min_index
= IEEE_REFERENCE_BASE
;
1923 ieee
->external_reference_max_index
= 0;
1924 ieee
->h
.abfd
= abfd
;
1925 ieee
->section_table
= NULL
;
1926 ieee
->section_table_size
= 0;
1928 processor
= ieee
->mb
.processor
= read_id (&(ieee
->h
));
1929 if (processor
== NULL
)
1930 goto got_wrong_format
;
1931 if (strcmp (processor
, "LIBRARY") == 0)
1932 goto got_wrong_format
;
1933 ieee
->mb
.module_name
= read_id (&(ieee
->h
));
1934 if (ieee
->mb
.module_name
== NULL
)
1935 goto got_wrong_format
;
1936 if (abfd
->filename
== (const char *) NULL
)
1937 abfd
->filename
= xstrdup (ieee
->mb
.module_name
);
1939 /* Determine the architecture and machine type of the object file. */
1941 const bfd_arch_info_type
*arch
;
1944 /* IEEE does not specify the format of the processor identification
1945 string, so the compiler is free to put in it whatever it wants.
1946 We try here to recognize different processors belonging to the
1947 m68k family. Code for other processors can be added here. */
1948 if ((processor
[0] == '6') && (processor
[1] == '8'))
1950 if (processor
[2] == '3') /* 683xx integrated processors. */
1952 switch (processor
[3])
1954 case '0': /* 68302, 68306, 68307 */
1955 case '2': /* 68322, 68328 */
1956 case '5': /* 68356 */
1957 strcpy (family
, "68000"); /* MC68000-based controllers. */
1960 case '3': /* 68330, 68331, 68332, 68333,
1961 68334, 68335, 68336, 68338 */
1962 case '6': /* 68360 */
1963 case '7': /* 68376 */
1964 strcpy (family
, "68332"); /* CPU32 and CPU32+ */
1968 if (processor
[4] == '9') /* 68349 */
1969 strcpy (family
, "68030"); /* CPU030 */
1970 else /* 68340, 68341 */
1971 strcpy (family
, "68332"); /* CPU32 and CPU32+ */
1974 default: /* Does not exist yet. */
1975 strcpy (family
, "68332"); /* Guess it will be CPU32 */
1978 else if (TOUPPER (processor
[3]) == 'F') /* 68F333 */
1979 strcpy (family
, "68332"); /* CPU32 */
1980 else if ((TOUPPER (processor
[3]) == 'C') /* Embedded controllers. */
1981 && ((TOUPPER (processor
[2]) == 'E')
1982 || (TOUPPER (processor
[2]) == 'H')
1983 || (TOUPPER (processor
[2]) == 'L')))
1985 strcpy (family
, "68");
1986 strncat (family
, processor
+ 4, 7);
1989 else /* "Regular" processors. */
1991 strncpy (family
, processor
, 9);
1995 else if ((CONST_STRNEQ (processor
, "cpu32")) /* CPU32 and CPU32+ */
1996 || (CONST_STRNEQ (processor
, "CPU32")))
1997 strcpy (family
, "68332");
2000 strncpy (family
, processor
, 9);
2004 arch
= bfd_scan_arch (family
);
2006 goto got_wrong_format
;
2007 abfd
->arch_info
= arch
;
2010 if (this_byte (&(ieee
->h
)) != (int) ieee_address_descriptor_enum
)
2013 if (! next_byte (&(ieee
->h
)))
2016 if (! parse_int (&(ieee
->h
), &ieee
->ad
.number_of_bits_mau
))
2019 if (! parse_int (&(ieee
->h
), &ieee
->ad
.number_of_maus_in_address
))
2022 /* If there is a byte order info, take it. */
2023 if (this_byte (&(ieee
->h
)) == (int) ieee_variable_L_enum
2024 || this_byte (&(ieee
->h
)) == (int) ieee_variable_M_enum
)
2026 if (! next_byte (&(ieee
->h
)))
2030 for (part
= 0; part
< N_W_VARIABLES
; part
++)
2034 if (read_2bytes (&(ieee
->h
)) != (int) ieee_assign_value_to_variable_enum
)
2037 if (this_byte_and_next (&(ieee
->h
)) != part
)
2040 ieee
->w
.offset
[part
] = parse_i (&(ieee
->h
), &ok
);
2045 if (ieee
->w
.r
.external_part
!= 0)
2046 abfd
->flags
= HAS_SYMS
;
2048 /* By now we know that this is a real IEEE file, we're going to read
2049 the whole thing into memory so that we can run up and down it
2050 quickly. We can work out how big the file is from the trailer
2053 amt
= ieee
->w
.r
.me_record
+ 1;
2054 IEEE_DATA (abfd
)->h
.first_byte
= bfd_alloc (ieee
->h
.abfd
, amt
);
2055 if (!IEEE_DATA (abfd
)->h
.first_byte
)
2057 if (bfd_seek (abfd
, (file_ptr
) 0, SEEK_SET
) != 0)
2060 /* FIXME: Check return value. I'm not sure whether it needs to read
2061 the entire buffer or not. */
2062 amt
= bfd_bread ((void *) (IEEE_DATA (abfd
)->h
.first_byte
),
2063 (bfd_size_type
) ieee
->w
.r
.me_record
+ 1, abfd
);
2067 IEEE_DATA (abfd
)->h
.total_amt
= amt
;
2068 if (ieee_slurp_sections (abfd
))
2071 if (! ieee_slurp_debug (abfd
))
2074 /* Parse section data to activate file and section flags implied by
2075 section contents. */
2076 if (! ieee_slurp_section_data (abfd
))
2081 bfd_set_error (bfd_error_wrong_format
);
2083 bfd_release (abfd
, ieee
);
2084 abfd
->tdata
.ieee_data
= save
;
2085 return (const bfd_target
*) NULL
;
2089 ieee_get_symbol_info (bfd
*ignore_abfd ATTRIBUTE_UNUSED
,
2093 bfd_symbol_info (symbol
, ret
);
2094 if (symbol
->name
[0] == ' ')
2095 ret
->name
= "* empty table entry ";
2096 if (!symbol
->section
)
2097 ret
->type
= (symbol
->flags
& BSF_LOCAL
) ? 'a' : 'A';
2101 ieee_print_symbol (bfd
*abfd
,
2104 bfd_print_symbol_type how
)
2106 FILE *file
= (FILE *) afile
;
2110 case bfd_print_symbol_name
:
2111 fprintf (file
, "%s", symbol
->name
);
2113 case bfd_print_symbol_more
:
2116 case bfd_print_symbol_all
:
2118 const char *section_name
=
2119 (symbol
->section
== (asection
*) NULL
2121 : symbol
->section
->name
);
2123 if (symbol
->name
[0] == ' ')
2124 fprintf (file
, "* empty table entry ");
2127 bfd_print_symbol_vandf (abfd
, (void *) file
, symbol
);
2129 fprintf (file
, " %-5s %04x %02x %s",
2131 (unsigned) ieee_symbol (symbol
)->index
,
2141 ieee_new_section_hook (bfd
*abfd
, asection
*newsect
)
2143 if (!newsect
->used_by_bfd
)
2145 newsect
->used_by_bfd
= bfd_alloc (abfd
, sizeof (ieee_per_section_type
));
2146 if (!newsect
->used_by_bfd
)
2149 ieee_per_section (newsect
)->data
= NULL
;
2150 ieee_per_section (newsect
)->section
= newsect
;
2151 return _bfd_generic_new_section_hook (abfd
, newsect
);
2155 ieee_get_reloc_upper_bound (bfd
*abfd
, sec_ptr asect
)
2157 if ((asect
->flags
& SEC_DEBUGGING
) != 0)
2159 if (! ieee_slurp_section_data (abfd
))
2161 return (asect
->reloc_count
+ 1) * sizeof (arelent
*);
2165 ieee_get_section_contents (bfd
*abfd
,
2169 bfd_size_type count
)
2171 ieee_per_section_type
*p
= ieee_per_section (section
);
2172 if ((section
->flags
& SEC_DEBUGGING
) != 0)
2173 return _bfd_generic_get_section_contents (abfd
, section
, location
,
2175 ieee_slurp_section_data (abfd
);
2176 (void) memcpy ((void *) location
, (void *) (p
->data
+ offset
), (unsigned) count
);
2181 ieee_canonicalize_reloc (bfd
*abfd
,
2186 ieee_reloc_type
*src
= (ieee_reloc_type
*) (section
->relocation
);
2187 ieee_data_type
*ieee
= IEEE_DATA (abfd
);
2189 if ((section
->flags
& SEC_DEBUGGING
) != 0)
2192 while (src
!= (ieee_reloc_type
*) NULL
)
2194 /* Work out which symbol to attach it this reloc to. */
2195 switch (src
->symbol
.letter
)
2198 src
->relent
.sym_ptr_ptr
=
2199 symbols
+ src
->symbol
.index
+ ieee
->external_symbol_base_offset
;
2202 src
->relent
.sym_ptr_ptr
=
2203 symbols
+ src
->symbol
.index
+ ieee
->external_reference_base_offset
;
2206 if (src
->relent
.sym_ptr_ptr
!= NULL
)
2207 src
->relent
.sym_ptr_ptr
=
2208 src
->relent
.sym_ptr_ptr
[0]->section
->symbol_ptr_ptr
;
2214 *relptr
++ = &src
->relent
;
2218 return section
->reloc_count
;
2222 comp (const void * ap
, const void * bp
)
2224 arelent
*a
= *((arelent
**) ap
);
2225 arelent
*b
= *((arelent
**) bp
);
2226 return a
->address
- b
->address
;
2229 /* Write the section headers. */
2232 ieee_write_section_part (bfd
*abfd
)
2234 ieee_data_type
*ieee
= IEEE_DATA (abfd
);
2237 ieee
->w
.r
.section_part
= bfd_tell (abfd
);
2238 for (s
= abfd
->sections
; s
!= (asection
*) NULL
; s
= s
->next
)
2240 if (! bfd_is_abs_section (s
)
2241 && (s
->flags
& SEC_DEBUGGING
) == 0)
2243 if (! ieee_write_byte (abfd
, ieee_section_type_enum
)
2244 || ! ieee_write_byte (abfd
,
2245 (bfd_byte
) (s
->index
2246 + IEEE_SECTION_NUMBER_BASE
)))
2249 if (abfd
->flags
& EXEC_P
)
2251 /* This image is executable, so output absolute sections. */
2252 if (! ieee_write_byte (abfd
, ieee_variable_A_enum
)
2253 || ! ieee_write_byte (abfd
, ieee_variable_S_enum
))
2258 if (! ieee_write_byte (abfd
, ieee_variable_C_enum
))
2262 switch (s
->flags
& (SEC_CODE
| SEC_DATA
| SEC_ROM
))
2264 case SEC_CODE
| SEC_LOAD
:
2266 if (! ieee_write_byte (abfd
, ieee_variable_P_enum
))
2271 if (! ieee_write_byte (abfd
, ieee_variable_D_enum
))
2275 case SEC_ROM
| SEC_DATA
:
2276 case SEC_ROM
| SEC_LOAD
:
2277 case SEC_ROM
| SEC_DATA
| SEC_LOAD
:
2278 if (! ieee_write_byte (abfd
, ieee_variable_R_enum
))
2283 if (! ieee_write_id (abfd
, s
->name
))
2286 if (! ieee_write_byte (abfd
, ieee_section_alignment_enum
)
2287 || ! ieee_write_byte (abfd
,
2288 (bfd_byte
) (s
->index
2289 + IEEE_SECTION_NUMBER_BASE
))
2290 || ! ieee_write_int (abfd
, (bfd_vma
) 1 << s
->alignment_power
))
2294 if (! ieee_write_2bytes (abfd
, ieee_section_size_enum
)
2295 || ! ieee_write_byte (abfd
,
2296 (bfd_byte
) (s
->index
2297 + IEEE_SECTION_NUMBER_BASE
))
2298 || ! ieee_write_int (abfd
, s
->size
))
2300 if (abfd
->flags
& EXEC_P
)
2302 /* Relocateable sections don't have asl records. */
2304 if (! ieee_write_2bytes (abfd
, ieee_section_base_address_enum
)
2305 || ! ieee_write_byte (abfd
,
2308 + IEEE_SECTION_NUMBER_BASE
)))
2309 || ! ieee_write_int (abfd
, s
->lma
))
2319 do_with_relocs (bfd
*abfd
, asection
*s
)
2321 unsigned int number_of_maus_in_address
=
2322 bfd_arch_bits_per_address (abfd
) / bfd_arch_bits_per_byte (abfd
);
2323 unsigned int relocs_to_go
= s
->reloc_count
;
2324 bfd_byte
*stream
= ieee_per_section (s
)->data
;
2325 arelent
**p
= s
->orelocation
;
2326 bfd_size_type current_byte_index
= 0;
2328 qsort (s
->orelocation
,
2330 sizeof (arelent
**),
2333 /* Output the section preheader. */
2334 if (! ieee_write_byte (abfd
, ieee_set_current_section_enum
)
2335 || ! ieee_write_byte (abfd
,
2336 (bfd_byte
) (s
->index
+ IEEE_SECTION_NUMBER_BASE
))
2337 || ! ieee_write_2bytes (abfd
, ieee_set_current_pc_enum
)
2338 || ! ieee_write_byte (abfd
,
2339 (bfd_byte
) (s
->index
+ IEEE_SECTION_NUMBER_BASE
)))
2342 if ((abfd
->flags
& EXEC_P
) != 0 && relocs_to_go
== 0)
2344 if (! ieee_write_int (abfd
, s
->lma
))
2349 if (! ieee_write_expression (abfd
, (bfd_vma
) 0, s
->symbol
, 0, 0))
2353 if (relocs_to_go
== 0)
2355 /* If there aren't any relocations then output the load constant
2356 byte opcode rather than the load with relocation opcode. */
2357 while (current_byte_index
< s
->size
)
2360 unsigned int MAXRUN
= 127;
2363 if (run
> s
->size
- current_byte_index
)
2364 run
= s
->size
- current_byte_index
;
2368 if (! ieee_write_byte (abfd
, ieee_load_constant_bytes_enum
))
2370 /* Output a stream of bytes. */
2371 if (! ieee_write_int (abfd
, run
))
2373 if (bfd_bwrite ((void *) (stream
+ current_byte_index
), run
, abfd
)
2376 current_byte_index
+= run
;
2382 if (! ieee_write_byte (abfd
, ieee_load_with_relocation_enum
))
2385 /* Output the data stream as the longest sequence of bytes
2386 possible, allowing for the a reasonable packet size and
2387 relocation stuffs. */
2390 /* Outputting a section without data, fill it up. */
2391 stream
= bfd_zalloc (abfd
, s
->size
);
2395 while (current_byte_index
< s
->size
)
2398 unsigned int MAXRUN
= 127;
2402 run
= (*p
)->address
- current_byte_index
;
2409 if (run
> s
->size
- current_byte_index
)
2410 run
= s
->size
- current_byte_index
;
2414 /* Output a stream of bytes. */
2415 if (! ieee_write_int (abfd
, run
))
2417 if (bfd_bwrite ((void *) (stream
+ current_byte_index
), run
, abfd
)
2420 current_byte_index
+= run
;
2423 /* Output any relocations here. */
2424 if (relocs_to_go
&& (*p
) && (*p
)->address
== current_byte_index
)
2427 && (*p
) && (*p
)->address
== current_byte_index
)
2431 switch (r
->howto
->size
)
2434 ov
= bfd_get_signed_32 (abfd
,
2435 stream
+ current_byte_index
);
2436 current_byte_index
+= 4;
2439 ov
= bfd_get_signed_16 (abfd
,
2440 stream
+ current_byte_index
);
2441 current_byte_index
+= 2;
2444 ov
= bfd_get_signed_8 (abfd
,
2445 stream
+ current_byte_index
);
2446 current_byte_index
++;
2454 ov
&= r
->howto
->src_mask
;
2456 if (r
->howto
->pc_relative
2457 && ! r
->howto
->pcrel_offset
)
2460 if (! ieee_write_byte (abfd
,
2461 ieee_function_either_open_b_enum
))
2464 if (r
->sym_ptr_ptr
!= (asymbol
**) NULL
)
2466 if (! ieee_write_expression (abfd
, r
->addend
+ ov
,
2468 r
->howto
->pc_relative
,
2469 (unsigned) s
->index
))
2474 if (! ieee_write_expression (abfd
, r
->addend
+ ov
,
2476 r
->howto
->pc_relative
,
2477 (unsigned) s
->index
))
2481 if (number_of_maus_in_address
2482 != bfd_get_reloc_size (r
->howto
))
2484 bfd_vma rsize
= bfd_get_reloc_size (r
->howto
);
2485 if (! ieee_write_int (abfd
, rsize
))
2488 if (! ieee_write_byte (abfd
,
2489 ieee_function_either_close_b_enum
))
2503 /* If there are no relocations in the output section then we can be
2504 clever about how we write. We block items up into a max of 127
2508 do_as_repeat (bfd
*abfd
, asection
*s
)
2512 if (! ieee_write_byte (abfd
, ieee_set_current_section_enum
)
2513 || ! ieee_write_byte (abfd
,
2514 (bfd_byte
) (s
->index
2515 + IEEE_SECTION_NUMBER_BASE
))
2516 || ! ieee_write_byte (abfd
, ieee_set_current_pc_enum
>> 8)
2517 || ! ieee_write_byte (abfd
, ieee_set_current_pc_enum
& 0xff)
2518 || ! ieee_write_byte (abfd
,
2519 (bfd_byte
) (s
->index
2520 + IEEE_SECTION_NUMBER_BASE
)))
2523 if ((abfd
->flags
& EXEC_P
) != 0)
2525 if (! ieee_write_int (abfd
, s
->lma
))
2530 if (! ieee_write_expression (abfd
, (bfd_vma
) 0, s
->symbol
, 0, 0))
2534 if (! ieee_write_byte (abfd
, ieee_repeat_data_enum
)
2535 || ! ieee_write_int (abfd
, s
->size
)
2536 || ! ieee_write_byte (abfd
, ieee_load_constant_bytes_enum
)
2537 || ! ieee_write_byte (abfd
, 1)
2538 || ! ieee_write_byte (abfd
, 0))
2546 do_without_relocs (bfd
*abfd
, asection
*s
)
2548 bfd_byte
*stream
= ieee_per_section (s
)->data
;
2550 if (stream
== 0 || ((s
->flags
& SEC_LOAD
) == 0))
2552 if (! do_as_repeat (abfd
, s
))
2559 for (i
= 0; i
< s
->size
; i
++)
2563 if (! do_with_relocs (abfd
, s
))
2568 if (! do_as_repeat (abfd
, s
))
2578 bfd_size_type amt
= input_ptr_end
- input_ptr_start
;
2579 /* FIXME: Check return value. I'm not sure whether it needs to read
2580 the entire buffer or not. */
2581 bfd_bread ((void *) input_ptr_start
, amt
, input_bfd
);
2582 input_ptr
= input_ptr_start
;
2588 bfd_size_type amt
= output_ptr
- output_ptr_start
;
2590 if (bfd_bwrite ((void *) (output_ptr_start
), amt
, output_bfd
) != amt
)
2592 output_ptr
= output_ptr_start
;
2596 #define THIS() ( *input_ptr )
2597 #define NEXT() { input_ptr++; if (input_ptr == input_ptr_end) fill (); }
2598 #define OUT(x) { *output_ptr++ = (x); if (output_ptr == output_ptr_end) flush (); }
2601 write_int (int value
)
2603 if (value
>= 0 && value
<= 127)
2609 unsigned int length
;
2611 /* How many significant bytes ? */
2612 /* FIXME FOR LONGER INTS. */
2613 if (value
& 0xff000000)
2615 else if (value
& 0x00ff0000)
2617 else if (value
& 0x0000ff00)
2622 OUT ((int) ieee_number_repeat_start_enum
+ length
);
2643 int length
= THIS ();
2656 #define VAR(x) ((x | 0x80))
2658 copy_expression (void)
2672 value
= (value
<< 8) | THIS ();
2674 value
= (value
<< 8) | THIS ();
2676 value
= (value
<< 8) | THIS ();
2684 value
= (value
<< 8) | THIS ();
2686 value
= (value
<< 8) | THIS ();
2694 value
= (value
<< 8) | THIS ();
2711 /* Not a number, just bug out with the answer. */
2712 write_int (*(--tos
));
2719 /* PLUS anything. */
2728 ieee_data_type
*ieee
;
2732 section_number
= THIS ();
2735 ieee
= IEEE_DATA (input_bfd
);
2736 s
= ieee
->section_table
[section_number
];
2738 if (s
->output_section
)
2739 value
= s
->output_section
->lma
;
2740 value
+= s
->output_offset
;
2747 write_int (*(--tos
));
2755 /* Drop the int in the buffer, and copy a null into the gap, which we
2756 will overwrite later. */
2759 fill_int (struct output_buffer_struct
*buf
)
2761 if (buf
->buffer
== output_buffer
)
2763 /* Still a chance to output the size. */
2764 int value
= output_ptr
- buf
->ptrp
+ 3;
2765 buf
->ptrp
[0] = value
>> 24;
2766 buf
->ptrp
[1] = value
>> 16;
2767 buf
->ptrp
[2] = value
>> 8;
2768 buf
->ptrp
[3] = value
>> 0;
2773 drop_int (struct output_buffer_struct
*buf
)
2805 buf
->ptrp
= output_ptr
;
2806 buf
->buffer
= output_buffer
;
2850 #define ID copy_id ()
2851 #define INT copy_int ()
2852 #define EXP copy_expression ()
2853 #define INTn(q) copy_int ()
2854 #define EXPn(q) copy_expression ()
2857 copy_till_end (void)
2936 EXPn (instruction address
);
2970 EXPn (external function
);
2980 INTn (locked
register);
3002 /* Attribute record. */
3032 /* Unique typedefs for module. */
3033 /* GLobal typedefs. */
3034 /* High level module scope beginning. */
3036 struct output_buffer_struct ob
;
3052 /* Global function. */
3054 struct output_buffer_struct ob
;
3069 EXPn (size of block
);
3075 /* File name for source line numbers. */
3077 struct output_buffer_struct ob
;
3098 /* Local function. */
3100 struct output_buffer_struct ob
;
3119 /* Assembler module scope beginning - */
3121 struct output_buffer_struct ob
;
3147 struct output_buffer_struct ob
;
3155 INTn (section index
);
3163 EXPn (Size in Maus
);
3216 /* Moves all the debug information from the source bfd to the output
3217 bfd, and relocates any expressions it finds. */
3220 relocate_debug (bfd
*output ATTRIBUTE_UNUSED
,
3225 unsigned char input_buffer
[IBS
];
3227 input_ptr_start
= input_ptr
= input_buffer
;
3228 input_ptr_end
= input_buffer
+ IBS
;
3230 /* FIXME: Check return value. I'm not sure whether it needs to read
3231 the entire buffer or not. */
3232 bfd_bread ((void *) input_ptr_start
, (bfd_size_type
) IBS
, input
);
3236 /* Gather together all the debug information from each input BFD into
3237 one place, relocating it and emitting it as we go. */
3240 ieee_write_debug_part (bfd
*abfd
)
3242 ieee_data_type
*ieee
= IEEE_DATA (abfd
);
3243 bfd_chain_type
*chain
= ieee
->chain_root
;
3244 unsigned char obuff
[OBS
];
3245 bfd_boolean some_debug
= FALSE
;
3246 file_ptr here
= bfd_tell (abfd
);
3248 output_ptr_start
= output_ptr
= obuff
;
3249 output_ptr_end
= obuff
+ OBS
;
3253 if (chain
== (bfd_chain_type
*) NULL
)
3257 for (s
= abfd
->sections
; s
!= NULL
; s
= s
->next
)
3258 if ((s
->flags
& SEC_DEBUGGING
) != 0)
3262 ieee
->w
.r
.debug_information_part
= 0;
3266 ieee
->w
.r
.debug_information_part
= here
;
3267 if (bfd_bwrite (s
->contents
, s
->size
, abfd
) != s
->size
)
3272 while (chain
!= (bfd_chain_type
*) NULL
)
3274 bfd
*entry
= chain
->this;
3275 ieee_data_type
*entry_ieee
= IEEE_DATA (entry
);
3277 if (entry_ieee
->w
.r
.debug_information_part
)
3279 if (bfd_seek (entry
, entry_ieee
->w
.r
.debug_information_part
,
3282 relocate_debug (abfd
, entry
);
3285 chain
= chain
->next
;
3289 ieee
->w
.r
.debug_information_part
= here
;
3291 ieee
->w
.r
.debug_information_part
= 0;
3299 /* Write the data in an ieee way. */
3302 ieee_write_data_part (bfd
*abfd
)
3306 ieee_data_type
*ieee
= IEEE_DATA (abfd
);
3307 ieee
->w
.r
.data_part
= bfd_tell (abfd
);
3309 for (s
= abfd
->sections
; s
!= (asection
*) NULL
; s
= s
->next
)
3311 /* Skip sections that have no loadable contents (.bss,
3313 if ((s
->flags
& SEC_LOAD
) == 0)
3316 /* Sort the reloc records so we can insert them in the correct
3318 if (s
->reloc_count
!= 0)
3320 if (! do_with_relocs (abfd
, s
))
3325 if (! do_without_relocs (abfd
, s
))
3334 init_for_output (bfd
*abfd
)
3338 for (s
= abfd
->sections
; s
!= (asection
*) NULL
; s
= s
->next
)
3340 if ((s
->flags
& SEC_DEBUGGING
) != 0)
3344 bfd_size_type size
= s
->size
;
3345 ieee_per_section (s
)->data
= bfd_alloc (abfd
, size
);
3346 if (!ieee_per_section (s
)->data
)
3353 /* Exec and core file sections. */
3355 /* Set section contents is complicated with IEEE since the format is
3356 not a byte image, but a record stream. */
3359 ieee_set_section_contents (bfd
*abfd
,
3361 const void * location
,
3363 bfd_size_type count
)
3365 if ((section
->flags
& SEC_DEBUGGING
) != 0)
3367 if (section
->contents
== NULL
)
3369 bfd_size_type size
= section
->size
;
3370 section
->contents
= bfd_alloc (abfd
, size
);
3371 if (section
->contents
== NULL
)
3374 /* bfd_set_section_contents has already checked that everything
3376 memcpy (section
->contents
+ offset
, location
, (size_t) count
);
3380 if (ieee_per_section (section
)->data
== (bfd_byte
*) NULL
)
3382 if (!init_for_output (abfd
))
3385 memcpy ((void *) (ieee_per_section (section
)->data
+ offset
),
3387 (unsigned int) count
);
3391 /* Write the external symbols of a file. IEEE considers two sorts of
3392 external symbols, public, and referenced. It uses to internal
3393 forms to index them as well. When we write them out we turn their
3394 symbol values into indexes from the right base. */
3397 ieee_write_external_part (bfd
*abfd
)
3400 ieee_data_type
*ieee
= IEEE_DATA (abfd
);
3401 unsigned int reference_index
= IEEE_REFERENCE_BASE
;
3402 unsigned int public_index
= IEEE_PUBLIC_BASE
+ 2;
3403 file_ptr here
= bfd_tell (abfd
);
3404 bfd_boolean hadone
= FALSE
;
3406 if (abfd
->outsymbols
!= (asymbol
**) NULL
)
3409 for (q
= abfd
->outsymbols
; *q
!= (asymbol
*) NULL
; q
++)
3413 if (bfd_is_und_section (p
->section
))
3415 /* This must be a symbol reference. */
3416 if (! ieee_write_byte (abfd
, ieee_external_reference_enum
)
3417 || ! ieee_write_int (abfd
, (bfd_vma
) reference_index
)
3418 || ! ieee_write_id (abfd
, p
->name
))
3420 p
->value
= reference_index
;
3424 else if (bfd_is_com_section (p
->section
))
3426 /* This is a weak reference. */
3427 if (! ieee_write_byte (abfd
, ieee_external_reference_enum
)
3428 || ! ieee_write_int (abfd
, (bfd_vma
) reference_index
)
3429 || ! ieee_write_id (abfd
, p
->name
)
3430 || ! ieee_write_byte (abfd
,
3431 ieee_weak_external_reference_enum
)
3432 || ! ieee_write_int (abfd
, (bfd_vma
) reference_index
)
3433 || ! ieee_write_int (abfd
, p
->value
))
3435 p
->value
= reference_index
;
3439 else if (p
->flags
& BSF_GLOBAL
)
3441 /* This must be a symbol definition. */
3442 if (! ieee_write_byte (abfd
, ieee_external_symbol_enum
)
3443 || ! ieee_write_int (abfd
, (bfd_vma
) public_index
)
3444 || ! ieee_write_id (abfd
, p
->name
)
3445 || ! ieee_write_2bytes (abfd
, ieee_attribute_record_enum
)
3446 || ! ieee_write_int (abfd
, (bfd_vma
) public_index
)
3447 || ! ieee_write_byte (abfd
, 15) /* Instruction address. */
3448 || ! ieee_write_byte (abfd
, 19) /* Static symbol. */
3449 || ! ieee_write_byte (abfd
, 1)) /* One of them. */
3452 /* Write out the value. */
3453 if (! ieee_write_2bytes (abfd
, ieee_value_record_enum
)
3454 || ! ieee_write_int (abfd
, (bfd_vma
) public_index
))
3456 if (! bfd_is_abs_section (p
->section
))
3458 if (abfd
->flags
& EXEC_P
)
3460 /* If fully linked, then output all symbols
3462 if (! (ieee_write_int
3465 + p
->section
->output_offset
3466 + p
->section
->output_section
->vma
))))
3471 if (! (ieee_write_expression
3473 p
->value
+ p
->section
->output_offset
,
3474 p
->section
->output_section
->symbol
,
3481 if (! ieee_write_expression (abfd
,
3483 bfd_abs_section_ptr
->symbol
,
3487 p
->value
= public_index
;
3493 /* This can happen - when there are gaps in the symbols read
3494 from an input ieee file. */
3499 ieee
->w
.r
.external_part
= here
;
3505 static const unsigned char exten
[] =
3508 0xf1, 0xce, 0x20, 0x00, 37, 3, 3, /* Set version 3 rev 3. */
3509 0xf1, 0xce, 0x20, 0x00, 39, 2, /* Keep symbol in original case. */
3510 0xf1, 0xce, 0x20, 0x00, 38 /* Set object type relocatable to x. */
3513 static const unsigned char envi
[] =
3517 /* 0xf1, 0xce, 0x21, 00, 50, 0x82, 0x07, 0xc7, 0x09, 0x11, 0x11,
3520 0xf1, 0xce, 0x21, 00, 52, 0x00, /* exec ok. */
3522 0xf1, 0xce, 0x21, 0, 53, 0x03,/* host unix. */
3523 /* 0xf1, 0xce, 0x21, 0, 54, 2,1,1 tool & version # */
3527 ieee_write_me_part (bfd
*abfd
)
3529 ieee_data_type
*ieee
= IEEE_DATA (abfd
);
3530 ieee
->w
.r
.trailer_part
= bfd_tell (abfd
);
3531 if (abfd
->start_address
)
3533 if (! ieee_write_2bytes (abfd
, ieee_value_starting_address_enum
)
3534 || ! ieee_write_byte (abfd
, ieee_function_either_open_b_enum
)
3535 || ! ieee_write_int (abfd
, abfd
->start_address
)
3536 || ! ieee_write_byte (abfd
, ieee_function_either_close_b_enum
))
3539 ieee
->w
.r
.me_record
= bfd_tell (abfd
);
3540 if (! ieee_write_byte (abfd
, ieee_module_end_enum
))
3545 /* Write out the IEEE processor ID. */
3548 ieee_write_processor (bfd
*abfd
)
3550 const bfd_arch_info_type
*arch
;
3552 arch
= bfd_get_arch_info (abfd
);
3556 if (! ieee_write_id (abfd
, bfd_printable_name (abfd
)))
3560 case bfd_arch_h8300
:
3561 if (! ieee_write_id (abfd
, "H8/300"))
3565 case bfd_arch_h8500
:
3566 if (! ieee_write_id (abfd
, "H8/500"))
3574 case bfd_mach_i960_core
:
3575 case bfd_mach_i960_ka_sa
:
3576 if (! ieee_write_id (abfd
, "80960KA"))
3580 case bfd_mach_i960_kb_sb
:
3581 if (! ieee_write_id (abfd
, "80960KB"))
3585 case bfd_mach_i960_ca
:
3586 if (! ieee_write_id (abfd
, "80960CA"))
3590 case bfd_mach_i960_mc
:
3591 case bfd_mach_i960_xa
:
3592 if (! ieee_write_id (abfd
, "80960MC"))
3604 default: id
= "68020"; break;
3605 case bfd_mach_m68000
: id
= "68000"; break;
3606 case bfd_mach_m68008
: id
= "68008"; break;
3607 case bfd_mach_m68010
: id
= "68010"; break;
3608 case bfd_mach_m68020
: id
= "68020"; break;
3609 case bfd_mach_m68030
: id
= "68030"; break;
3610 case bfd_mach_m68040
: id
= "68040"; break;
3611 case bfd_mach_m68060
: id
= "68060"; break;
3612 case bfd_mach_cpu32
: id
= "cpu32"; break;
3613 case bfd_mach_mcf_isa_a_nodiv
: id
= "isa-a:nodiv"; break;
3614 case bfd_mach_mcf_isa_a
: id
= "isa-a"; break;
3615 case bfd_mach_mcf_isa_a_mac
: id
= "isa-a:mac"; break;
3616 case bfd_mach_mcf_isa_a_emac
: id
= "isa-a:emac"; break;
3617 case bfd_mach_mcf_isa_aplus
: id
= "isa-aplus"; break;
3618 case bfd_mach_mcf_isa_aplus_mac
: id
= "isa-aplus:mac"; break;
3619 case bfd_mach_mcf_isa_aplus_emac
: id
= "isa-aplus:mac"; break;
3620 case bfd_mach_mcf_isa_b_nousp
: id
= "isa-b:nousp"; break;
3621 case bfd_mach_mcf_isa_b_nousp_mac
: id
= "isa-b:nousp:mac"; break;
3622 case bfd_mach_mcf_isa_b_nousp_emac
: id
= "isa-b:nousp:emac"; break;
3623 case bfd_mach_mcf_isa_b
: id
= "isa-b"; break;
3624 case bfd_mach_mcf_isa_b_mac
: id
= "isa-b:mac"; break;
3625 case bfd_mach_mcf_isa_b_emac
: id
= "isa-b:emac"; break;
3626 case bfd_mach_mcf_isa_b_float
: id
= "isa-b:float"; break;
3627 case bfd_mach_mcf_isa_b_float_mac
: id
= "isa-b:float:mac"; break;
3628 case bfd_mach_mcf_isa_b_float_emac
: id
= "isa-b:float:emac"; break;
3629 case bfd_mach_mcf_isa_c
: id
= "isa-c"; break;
3630 case bfd_mach_mcf_isa_c_mac
: id
= "isa-c:mac"; break;
3631 case bfd_mach_mcf_isa_c_emac
: id
= "isa-c:emac"; break;
3632 case bfd_mach_mcf_isa_c_nodiv
: id
= "isa-c:nodiv"; break;
3633 case bfd_mach_mcf_isa_c_nodiv_mac
: id
= "isa-c:nodiv:mac"; break;
3634 case bfd_mach_mcf_isa_c_nodiv_emac
: id
= "isa-c:nodiv:emac"; break;
3637 if (! ieee_write_id (abfd
, id
))
3647 ieee_write_object_contents (bfd
*abfd
)
3649 ieee_data_type
*ieee
= IEEE_DATA (abfd
);
3653 /* Fast forward over the header area. */
3654 if (bfd_seek (abfd
, (file_ptr
) 0, SEEK_SET
) != 0)
3657 if (! ieee_write_byte (abfd
, ieee_module_beginning_enum
)
3658 || ! ieee_write_processor (abfd
)
3659 || ! ieee_write_id (abfd
, abfd
->filename
))
3662 /* Fast forward over the variable bits. */
3663 if (! ieee_write_byte (abfd
, ieee_address_descriptor_enum
))
3667 if (! ieee_write_byte (abfd
, (bfd_byte
) (bfd_arch_bits_per_byte (abfd
))))
3669 /* MAU's per address. */
3670 if (! ieee_write_byte (abfd
,
3671 (bfd_byte
) (bfd_arch_bits_per_address (abfd
)
3672 / bfd_arch_bits_per_byte (abfd
))))
3675 old
= bfd_tell (abfd
);
3676 if (bfd_seek (abfd
, (file_ptr
) (8 * N_W_VARIABLES
), SEEK_CUR
) != 0)
3679 ieee
->w
.r
.extension_record
= bfd_tell (abfd
);
3680 if (bfd_bwrite ((char *) exten
, (bfd_size_type
) sizeof (exten
), abfd
)
3683 if (abfd
->flags
& EXEC_P
)
3685 if (! ieee_write_byte (abfd
, 0x1)) /* Absolute. */
3690 if (! ieee_write_byte (abfd
, 0x2)) /* Relocateable. */
3694 ieee
->w
.r
.environmental_record
= bfd_tell (abfd
);
3695 if (bfd_bwrite ((char *) envi
, (bfd_size_type
) sizeof (envi
), abfd
)
3699 /* The HP emulator database requires a timestamp in the file. */
3705 t
= (struct tm
*) localtime (&now
);
3706 if (! ieee_write_2bytes (abfd
, (int) ieee_atn_record_enum
)
3707 || ! ieee_write_byte (abfd
, 0x21)
3708 || ! ieee_write_byte (abfd
, 0)
3709 || ! ieee_write_byte (abfd
, 50)
3710 || ! ieee_write_int (abfd
, (bfd_vma
) (t
->tm_year
+ 1900))
3711 || ! ieee_write_int (abfd
, (bfd_vma
) (t
->tm_mon
+ 1))
3712 || ! ieee_write_int (abfd
, (bfd_vma
) t
->tm_mday
)
3713 || ! ieee_write_int (abfd
, (bfd_vma
) t
->tm_hour
)
3714 || ! ieee_write_int (abfd
, (bfd_vma
) t
->tm_min
)
3715 || ! ieee_write_int (abfd
, (bfd_vma
) t
->tm_sec
))
3723 if (! ieee_write_section_part (abfd
))
3725 /* First write the symbols. This changes their values into table
3726 indeces so we cant use it after this point. */
3727 if (! ieee_write_external_part (abfd
))
3730 /* Write any debugs we have been told about. */
3731 if (! ieee_write_debug_part (abfd
))
3734 /* Can only write the data once the symbols have been written, since
3735 the data contains relocation information which points to the
3737 if (! ieee_write_data_part (abfd
))
3740 /* At the end we put the end! */
3741 if (! ieee_write_me_part (abfd
))
3744 /* Generate the header. */
3745 if (bfd_seek (abfd
, old
, SEEK_SET
) != 0)
3748 for (i
= 0; i
< N_W_VARIABLES
; i
++)
3750 if (! ieee_write_2bytes (abfd
, ieee_assign_value_to_variable_enum
)
3751 || ! ieee_write_byte (abfd
, (bfd_byte
) i
)
3752 || ! ieee_write_int5_out (abfd
, (bfd_vma
) ieee
->w
.offset
[i
]))
3759 /* Native-level interface to symbols. */
3761 /* We read the symbols into a buffer, which is discarded when this
3762 function exits. We read the strings into a buffer large enough to
3763 hold them all plus all the cached symbol entries. */
3766 ieee_make_empty_symbol (bfd
*abfd
)
3768 bfd_size_type amt
= sizeof (ieee_symbol_type
);
3769 ieee_symbol_type
*new_symbol
= (ieee_symbol_type
*) bfd_zalloc (abfd
, amt
);
3773 new_symbol
->symbol
.the_bfd
= abfd
;
3774 return &new_symbol
->symbol
;
3778 ieee_openr_next_archived_file (bfd
*arch
, bfd
*prev
)
3780 ieee_ar_data_type
*ar
= IEEE_AR_DATA (arch
);
3782 /* Take the next one from the arch state, or reset. */
3783 if (prev
== (bfd
*) NULL
)
3784 /* Reset the index - the first two entries are bogus. */
3785 ar
->element_index
= 2;
3789 ieee_ar_obstack_type
*p
= ar
->elements
+ ar
->element_index
;
3791 ar
->element_index
++;
3792 if (ar
->element_index
<= ar
->element_count
)
3794 if (p
->file_offset
!= (file_ptr
) 0)
3796 if (p
->abfd
== (bfd
*) NULL
)
3798 p
->abfd
= _bfd_create_empty_archive_element_shell (arch
);
3799 p
->abfd
->origin
= p
->file_offset
;
3806 bfd_set_error (bfd_error_no_more_archived_files
);
3812 #define ieee_find_nearest_line _bfd_nosymbols_find_nearest_line
3813 #define ieee_find_line _bfd_nosymbols_find_line
3814 #define ieee_find_inliner_info _bfd_nosymbols_find_inliner_info
3817 ieee_generic_stat_arch_elt (bfd
*abfd
, struct stat
*buf
)
3819 ieee_ar_data_type
*ar
= (ieee_ar_data_type
*) NULL
;
3820 ieee_data_type
*ieee
;
3822 if (abfd
->my_archive
!= NULL
)
3823 ar
= abfd
->my_archive
->tdata
.ieee_ar_data
;
3824 if (ar
== (ieee_ar_data_type
*) NULL
)
3826 bfd_set_error (bfd_error_invalid_operation
);
3830 if (IEEE_DATA (abfd
) == NULL
)
3832 if (ieee_object_p (abfd
) == NULL
)
3834 bfd_set_error (bfd_error_wrong_format
);
3839 ieee
= IEEE_DATA (abfd
);
3841 buf
->st_size
= ieee
->w
.r
.me_record
+ 1;
3842 buf
->st_mode
= 0644;
3847 ieee_sizeof_headers (bfd
*abfd ATTRIBUTE_UNUSED
,
3848 struct bfd_link_info
*info ATTRIBUTE_UNUSED
)
3853 #define ieee_close_and_cleanup _bfd_generic_close_and_cleanup
3854 #define ieee_bfd_free_cached_info _bfd_generic_bfd_free_cached_info
3856 #define ieee_slurp_armap bfd_true
3857 #define ieee_slurp_extended_name_table bfd_true
3858 #define ieee_construct_extended_name_table \
3860 (bfd *, char **, bfd_size_type *, const char **)) \
3862 #define ieee_truncate_arname bfd_dont_truncate_arname
3863 #define ieee_write_armap \
3865 (bfd *, unsigned int, struct orl *, unsigned int, int)) \
3867 #define ieee_read_ar_hdr bfd_nullvoidptr
3868 #define ieee_write_ar_hdr ((bfd_boolean (*) (bfd *, bfd *)) bfd_false)
3869 #define ieee_update_armap_timestamp bfd_true
3870 #define ieee_get_elt_at_index _bfd_generic_get_elt_at_index
3872 #define ieee_get_symbol_version_string \
3873 _bfd_nosymbols_get_symbol_version_string
3874 #define ieee_bfd_is_target_special_symbol \
3875 ((bfd_boolean (*) (bfd *, asymbol *)) bfd_false)
3876 #define ieee_bfd_is_local_label_name bfd_generic_is_local_label_name
3877 #define ieee_get_lineno _bfd_nosymbols_get_lineno
3878 #define ieee_bfd_make_debug_symbol _bfd_nosymbols_bfd_make_debug_symbol
3879 #define ieee_read_minisymbols _bfd_generic_read_minisymbols
3880 #define ieee_minisymbol_to_symbol _bfd_generic_minisymbol_to_symbol
3882 #define ieee_bfd_reloc_type_lookup _bfd_norelocs_bfd_reloc_type_lookup
3883 #define ieee_bfd_reloc_name_lookup _bfd_norelocs_bfd_reloc_name_lookup
3885 #define ieee_set_arch_mach _bfd_generic_set_arch_mach
3887 #define ieee_get_section_contents_in_window \
3888 _bfd_generic_get_section_contents_in_window
3889 #define ieee_bfd_get_relocated_section_contents \
3890 bfd_generic_get_relocated_section_contents
3891 #define ieee_bfd_relax_section bfd_generic_relax_section
3892 #define ieee_bfd_gc_sections bfd_generic_gc_sections
3893 #define ieee_bfd_lookup_section_flags bfd_generic_lookup_section_flags
3894 #define ieee_bfd_merge_sections bfd_generic_merge_sections
3895 #define ieee_bfd_is_group_section bfd_generic_is_group_section
3896 #define ieee_bfd_discard_group bfd_generic_discard_group
3897 #define ieee_section_already_linked \
3898 _bfd_generic_section_already_linked
3899 #define ieee_bfd_define_common_symbol bfd_generic_define_common_symbol
3900 #define ieee_bfd_define_start_stop bfd_generic_define_start_stop
3901 #define ieee_bfd_link_hash_table_create _bfd_generic_link_hash_table_create
3902 #define ieee_bfd_link_add_symbols _bfd_generic_link_add_symbols
3903 #define ieee_bfd_link_just_syms _bfd_generic_link_just_syms
3904 #define ieee_bfd_copy_link_hash_symbol_type \
3905 _bfd_generic_copy_link_hash_symbol_type
3906 #define ieee_bfd_final_link _bfd_generic_final_link
3907 #define ieee_bfd_link_split_section _bfd_generic_link_split_section
3908 #define ieee_bfd_link_check_relocs _bfd_generic_link_check_relocs
3909 #define ieee_set_reloc _bfd_generic_set_reloc
3911 const bfd_target ieee_vec
=
3914 bfd_target_ieee_flavour
,
3915 BFD_ENDIAN_UNKNOWN
, /* Target byte order. */
3916 BFD_ENDIAN_UNKNOWN
, /* Target headers byte order. */
3917 (HAS_RELOC
| EXEC_P
| /* Object flags. */
3918 HAS_LINENO
| HAS_DEBUG
|
3919 HAS_SYMS
| HAS_LOCALS
| WP_TEXT
| D_PAGED
),
3920 (SEC_CODE
| SEC_DATA
| SEC_ROM
| SEC_HAS_CONTENTS
3921 | SEC_ALLOC
| SEC_LOAD
| SEC_RELOC
), /* Section flags. */
3922 '_', /* Leading underscore. */
3923 ' ', /* AR_pad_char. */
3924 16, /* AR_max_namelen. */
3925 0, /* match priority. */
3926 bfd_getb64
, bfd_getb_signed_64
, bfd_putb64
,
3927 bfd_getb32
, bfd_getb_signed_32
, bfd_putb32
,
3928 bfd_getb16
, bfd_getb_signed_16
, bfd_putb16
, /* Data. */
3929 bfd_getb64
, bfd_getb_signed_64
, bfd_putb64
,
3930 bfd_getb32
, bfd_getb_signed_32
, bfd_putb32
,
3931 bfd_getb16
, bfd_getb_signed_16
, bfd_putb16
, /* Headers. */
3934 ieee_object_p
, /* bfd_check_format. */
3941 _bfd_generic_mkarchive
,
3946 ieee_write_object_contents
,
3947 _bfd_write_archive_contents
,
3951 /* ieee_close_and_cleanup, ieee_bfd_free_cached_info, ieee_new_section_hook,
3952 ieee_get_section_contents, ieee_get_section_contents_in_window. */
3953 BFD_JUMP_TABLE_GENERIC (ieee
),
3955 BFD_JUMP_TABLE_COPY (_bfd_generic
),
3956 BFD_JUMP_TABLE_CORE (_bfd_nocore
),
3958 /* ieee_slurp_armap, ieee_slurp_extended_name_table,
3959 ieee_construct_extended_name_table, ieee_truncate_arname,
3960 ieee_write_armap, ieee_read_ar_hdr, ieee_openr_next_archived_file,
3961 ieee_get_elt_at_index, ieee_generic_stat_arch_elt,
3962 ieee_update_armap_timestamp. */
3963 BFD_JUMP_TABLE_ARCHIVE (ieee
),
3965 /* ieee_get_symtab_upper_bound, ieee_canonicalize_symtab,
3966 ieee_make_empty_symbol, ieee_print_symbol, ieee_get_symbol_info,
3967 ieee_bfd_is_local_label_name, ieee_get_lineno,
3968 ieee_find_nearest_line, ieee_bfd_make_debug_symbol,
3969 ieee_read_minisymbols, ieee_minisymbol_to_symbol. */
3970 BFD_JUMP_TABLE_SYMBOLS (ieee
),
3972 /* ieee_get_reloc_upper_bound, ieee_canonicalize_reloc,
3973 ieee_bfd_reloc_type_lookup. */
3974 BFD_JUMP_TABLE_RELOCS (ieee
),
3976 /* ieee_set_arch_mach, ieee_set_section_contents. */
3977 BFD_JUMP_TABLE_WRITE (ieee
),
3979 /* ieee_sizeof_headers, ieee_bfd_get_relocated_section_contents,
3980 ieee_bfd_relax_section, ieee_bfd_link_hash_table_create,
3981 ieee_bfd_link_add_symbols, ieee_bfd_final_link,
3982 ieee_bfd_link_split_section, ieee_bfd_gc_sections,
3983 ieee_bfd_merge_sections. */
3984 BFD_JUMP_TABLE_LINK (ieee
),
3986 BFD_JUMP_TABLE_DYNAMIC (_bfd_nodynamic
),