1 /* BFD back-end for mmo objects (MMIX-specific object-format).
3 Free Software Foundation, Inc.
4 Written by Hans-Peter Nilsson (hp@bitrange.com).
5 Infrastructure and other bits originally copied from srec.c and
8 This file is part of BFD, the Binary File Descriptor library.
10 This program is free software; you can redistribute it and/or modify
11 it under the terms of the GNU General Public License as published by
12 the Free Software Foundation; either version 2 of the License, or
13 (at your option) any later version.
15 This program is distributed in the hope that it will be useful,
16 but WITHOUT ANY WARRANTY; without even the implied warranty of
17 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 GNU General Public License for more details.
20 You should have received a copy of the GNU General Public License
21 along with this program; if not, write to the Free Software
22 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */
28 The mmo object format is used exclusively together with Professor
29 Donald E.@: Knuth's educational 64-bit processor MMIX. The simulator
30 @command{mmix} which is available at
31 @url{http://www-cs-faculty.stanford.edu/~knuth/programs/mmix.tar.gz}
32 understands this format. That package also includes a combined
33 assembler and linker called @command{mmixal}. The mmo format has
34 no advantages feature-wise compared to e.g. ELF. It is a simple
35 non-relocatable object format with no support for archives or
36 debugging information, except for symbol value information and
37 line numbers (which is not yet implemented in BFD). See
38 @url{http://www-cs-faculty.stanford.edu/~knuth/mmix.html} for more
39 information about MMIX. The ELF format is used for intermediate
40 object files in the BFD implementation.
42 @c We want to xref the symbol table node. A feature in "chew"
43 @c requires that "commands" do not contain spaces in the
44 @c arguments. Hence the hyphen in "Symbol-table".
48 @* mmo section mapping::
52 File layout, Symbol-table, mmo, mmo
56 The mmo file contents is not partitioned into named sections as
57 with e.g.@: ELF. Memory areas is formed by specifying the
58 location of the data that follows. Only the memory area
59 @samp{0x0000@dots{}00} to @samp{0x01ff@dots{}ff} is executable, so
60 it is used for code (and constants) and the area
61 @samp{0x2000@dots{}00} to @samp{0x20ff@dots{}ff} is used for
62 writable data. @xref{mmo section mapping}.
64 Contents is entered as 32-bit words, xor:ed over previous
65 contents, always zero-initialized. A word that starts with the
66 byte @samp{0x98} forms a command called a @samp{lopcode}, where
67 the next byte distinguished between the thirteen lopcodes. The
68 two remaining bytes, called the @samp{Y} and @samp{Z} fields, or
69 the @samp{YZ} field (a 16-bit big-endian number), are used for
70 various purposes different for each lopcode. As documented in
71 @url{http://www-cs-faculty.stanford.edu/~knuth/mmixal-intro.ps.gz},
74 There is provision for specifying ``special data'' of 65536
75 different types. We use type 80 (decimal), arbitrarily chosen the
76 same as the ELF <<e_machine>> number for MMIX, filling it with
77 section information normally found in ELF objects. @xref{mmo
82 0x98000001. The next word is contents, regardless of whether it
83 starts with 0x98 or not.
86 0x9801YYZZ, where @samp{Z} is 1 or 2. This is a location
87 directive, setting the location for the next data to the next
88 32-bit word (for @math{Z = 1}) or 64-bit word (for @math{Z = 2}),
89 plus @math{Y * 2^56}. Normally @samp{Y} is 0 for the text segment
90 and 2 for the data segment.
93 0x9802YYZZ. Increase the current location by @samp{YZ} bytes.
96 0x9803YYZZ, where @samp{Z} is 1 or 2. Store the current location
97 as 64 bits into the location pointed to by the next 32-bit
98 (@math{Z = 1}) or 64-bit (@math{Z = 2}) word, plus @math{Y *
102 0x9804YYZZ. @samp{YZ} is stored into the current location plus
106 0x980500ZZ. @samp{Z} is 16 or 24. A value @samp{L} derived from
107 the following 32-bit word are used in a manner similar to
108 @samp{YZ} in lop_fixr: it is xor:ed into the current location
109 minus @math{4 * L}. The first byte of the word is 0 or 1. If it
110 is 1, then @math{L = (@var{lowest 24 bits of word}) - 2^Z}, if 0,
111 then @math{L = (@var{lowest 24 bits of word})}.
114 0x9806YYZZ. @samp{Y} is the file number, @samp{Z} is count of
115 32-bit words. Set the file number to @samp{Y} and the line
116 counter to 0. The next @math{Z * 4} bytes contain the file name,
117 padded with zeros if the count is not a multiple of four. The
118 same @samp{Y} may occur multiple times, but @samp{Z} must be 0 for
119 all but the first occurrence.
122 0x9807YYZZ. @samp{YZ} is the line number. Together with
123 lop_file, it forms the source location for the next 32-bit word.
124 Note that for each non-lopcode 32-bit word, line numbers are
125 assumed incremented by one.
128 0x9808YYZZ. @samp{YZ} is the type number. Data until the next
129 lopcode other than lop_quote forms special data of type @samp{YZ}.
130 @xref{mmo section mapping}.
132 Other types than 80, (or type 80 with a content that does not
133 parse) is stored in sections named <<.MMIX.spec_data.@var{n}>>
134 where @var{n} is the @samp{YZ}-type. The flags for such a
135 sections say not to allocate or load the data. The vma is 0.
136 Contents of multiple occurrences of special data @var{n} is
137 concatenated to the data of the previous lop_spec @var{n}s. The
138 location in data or code at which the lop_spec occurred is lost.
141 0x980901ZZ. The first lopcode in a file. The @samp{Z} field forms the
142 length of header information in 32-bit words, where the first word
143 tells the time in seconds since @samp{00:00:00 GMT Jan 1 1970}.
146 0x980a00ZZ. @math{Z > 32}. This lopcode follows after all
147 content-generating lopcodes in a program. The @samp{Z} field
148 denotes the value of @samp{rG} at the beginning of the program.
149 The following @math{256 - Z} big-endian 64-bit words are loaded
150 into global registers @samp{$G} @dots{} @samp{$255}.
153 0x980b0000. The next-to-last lopcode in a program. Must follow
154 immediately after the lop_post lopcode and its data. After this
155 lopcode follows all symbols in a compressed format
156 (@pxref{Symbol-table}).
159 0x980cYYZZ. The last lopcode in a program. It must follow the
160 lop_stab lopcode and its data. The @samp{YZ} field contains the
161 number of 32-bit words of symbol table information after the
162 preceding lop_stab lopcode.
165 Note that the lopcode "fixups"; <<lop_fixr>>, <<lop_fixrx>> and
166 <<lop_fixo>> are not generated by BFD, but are handled. They are
167 generated by <<mmixal>>.
170 This trivial one-label, one-instruction file:
174 can be represented this way in mmo:
176 | 0x98090101 - lop_pre, one 32-bit word with timestamp.
178 | 0x98010002 - lop_loc, text segment, using a 64-bit address.
179 | Note that mmixal does not emit this for the file above.
180 | 0x00000000 - Address, high 32 bits.
181 | 0x00000000 - Address, low 32 bits.
182 | 0x98060002 - lop_file, 2 32-bit words for file-name.
183 | 0x74657374 - "test"
184 | 0x2e730000 - ".s\0\0"
185 | 0x98070001 - lop_line, line 1.
186 | 0x00010203 - TRAP 1,2,3
187 | 0x980a00ff - lop_post, setting $255 to 0.
190 | 0x980b0000 - lop_stab for ":Main" = 0, serial 1.
191 | 0x203a4040 @xref{Symbol-table}.
196 | 0x980c0005 - lop_end; symbol table contained five 32-bit words. */
201 #include "libiberty.h"
202 #include "elf/mmix.h"
203 #include "opcode/mmix.h"
221 #define LOP_QUOTE_NEXT ((LOP << 24) | (LOP_QUOTE << 16) | 1)
222 #define SPEC_DATA_SECTION 80
223 #define LOP_SPEC_SECTION \
224 ((LOP << 24) | (LOP_SPEC << 16) | SPEC_DATA_SECTION)
226 /* Must be a power of two. If you change this to be >= 64k, you need a
227 new test-case; the ld test b-loc64k.d touches chunk-size problem areas. */
228 #define MMO_SEC_CONTENTS_CHUNK_SIZE (1 << 15)
230 /* An arbitrary number for the maximum length section name size. */
231 #define MAX_SECTION_NAME_SIZE (1024 * 1024)
233 /* A quite arbitrary number for the maximum length section size. */
234 #define MAX_ARTIFICIAL_SECTION_SIZE (1024 * 1024 * 1024)
236 #define MMO3_WCHAR 0x80
237 #define MMO3_LEFT 0x40
238 #define MMO3_MIDDLE 0x20
239 #define MMO3_RIGHT 0x10
240 #define MMO3_TYPEBITS 0xf
241 #define MMO3_REGQUAL_BITS 0xf
244 #define MMO3_SYMBITS 0x2f
246 /* Put these everywhere in new code. */
247 #define FATAL_DEBUG \
248 _bfd_abort (__FILE__, __LINE__, \
249 "Internal: Non-debugged code (test-case missing)")
251 #define BAD_CASE(x) \
252 _bfd_abort (__FILE__, __LINE__, \
255 enum mmo_sym_type
{ mmo_reg_sym
, mmo_undef_sym
, mmo_data_sym
, mmo_abs_sym
};
257 /* When scanning the mmo file, a linked list of mmo_symbol
258 structures is built to represent the symbol table (if there is
263 struct mmo_symbol
*next
;
266 enum mmo_sym_type sym_type
;
270 struct mmo_data_list_struct
272 struct mmo_data_list_struct
*next
;
275 bfd_size_type allocated_size
;
279 typedef struct mmo_data_list_struct mmo_data_list_type
;
281 struct mmo_symbol_trie
283 struct mmo_symbol_trie
*left
;
284 struct mmo_symbol_trie
*right
;
285 struct mmo_symbol_trie
*middle
;
289 /* A zero name means there's nothing here. */
290 struct mmo_symbol sym
;
293 /* The mmo tdata information. */
295 struct mmo_data_struct
297 struct mmo_symbol
*symbols
;
298 struct mmo_symbol
*symtail
;
301 /* File representation of time (NULL) when this file was created. */
304 /* When we're reading bytes recursively, check this occasionally.
305 Also holds write errors. */
308 /* Max symbol length that may appear in the lop_stab table. Note that
309 this table might just hold a subset of symbols for not-really large
310 programs, as it can only be 65536 * 4 bytes large. */
311 int max_symbol_length
;
313 /* Here's the symbol we build in lop_stab. */
314 char *lop_stab_symbol
;
316 /* Index into lop_stab_symbol for the next character when parsing the
317 symbol information. */
320 /* When creating arbitrary sections, we need to count section numbers. */
323 /* When writing or reading byte-wise, we need to count the bytes
324 within a 32-bit word. */
327 /* We also need a buffer to hold the bytes we count reading or writing. */
331 typedef struct mmo_data_struct tdata_type
;
333 struct mmo_section_data_struct
335 mmo_data_list_type
*head
;
336 mmo_data_list_type
*tail
;
339 /* These structures are used in bfd_map_over_sections constructs. */
341 /* Used when writing out sections; all but the register contents section
342 which is stored in reg_section. */
343 struct mmo_write_sec_info
345 asection
*reg_section
;
349 /* Used when trying to find a section corresponding to addr. */
350 struct mmo_find_sec_info
356 static boolean mmo_bfd_copy_private_bfd_data
PARAMS ((bfd
*, bfd
*));
357 static void mmo_write_section_unless_reg_contents
358 PARAMS ((bfd
*, asection
*, PTR
));
359 static void mmo_find_sec_w_addr
PARAMS ((bfd
*, asection
*, PTR
));
360 static void mmo_find_sec_w_addr_grow
PARAMS ((bfd
*, asection
*, PTR
));
361 static asection
*mmo_make_section
PARAMS ((bfd
*, CONST
char *));
362 static void mmo_get_symbol_info
PARAMS ((bfd
*, asymbol
*, symbol_info
*));
363 static void mmo_print_symbol
364 PARAMS ((bfd
*, PTR
, asymbol
*, bfd_print_symbol_type
));
365 static void mmo_init
PARAMS ((void));
366 static boolean mmo_mkobject
PARAMS ((bfd
*));
367 static boolean mmo_scan
PARAMS ((bfd
*));
368 static asection
*mmo_decide_section
PARAMS ((bfd
*, bfd_vma
));
369 static asection
*mmo_get_generic_spec_data_section
PARAMS ((bfd
*, int));
370 static asection
*mmo_get_spec_section
PARAMS ((bfd
*, int));
371 static INLINE bfd_byte
*mmo_get_loc
PARAMS ((asection
*, bfd_vma
, int));
372 static void mmo_xore_64
PARAMS ((asection
*, bfd_vma vma
, bfd_vma value
));
373 static void mmo_xore_32
PARAMS ((asection
*, bfd_vma vma
, unsigned int));
374 static void mmo_xore_16
PARAMS ((asection
*, bfd_vma vma
, unsigned int));
375 static CONST bfd_target
*mmo_object_p
PARAMS ((bfd
*));
376 static void mmo_map_set_sizes
PARAMS ((bfd
*, asection
*, PTR
));
377 static boolean mmo_get_symbols
PARAMS ((bfd
*));
378 static boolean mmo_create_symbol
PARAMS ((bfd
*, CONST
char *, bfd_vma
,
379 enum mmo_sym_type
, unsigned int));
380 static boolean mmo_get_section_contents
381 PARAMS ((bfd
*, asection
*, PTR
, file_ptr
, bfd_size_type
));
382 static long mmo_get_symtab_upper_bound
PARAMS ((bfd
*));
383 static long mmo_get_symtab
PARAMS ((bfd
*, asymbol
**));
384 static void mmo_get_symbol_info
PARAMS ((bfd
*, asymbol
*, symbol_info
*));
385 static void mmo_print_symbol
PARAMS ((bfd
*, PTR
, asymbol
*,
386 bfd_print_symbol_type
));
387 static boolean mmo_set_section_contents
388 PARAMS ((bfd
*, sec_ptr
, PTR
, file_ptr
, bfd_size_type
));
389 static int mmo_sizeof_headers
PARAMS ((bfd
*, boolean
));
390 static long mmo_get_reloc_upper_bound
PARAMS ((bfd
*, asection
*));
392 static boolean mmo_internal_write_header
PARAMS ((bfd
*));
393 static boolean mmo_internal_write_post
PARAMS ((bfd
*, int, asection
*));
394 static boolean mmo_internal_add_3_sym
395 PARAMS ((bfd
*, struct mmo_symbol_trie
*, CONST
struct mmo_symbol
*));
396 static unsigned int mmo_internal_3_length
397 PARAMS ((bfd
*, struct mmo_symbol_trie
*));
398 static void mmo_internal_3_dump
399 PARAMS ((bfd
*, struct mmo_symbol_trie
*));
400 static void mmo_beb128_out
PARAMS ((bfd
*, int, int));
401 static boolean mmo_internal_write_section
402 PARAMS ((bfd
*, asection
*));
403 static void mmo_write_tetra
PARAMS ((bfd
*, unsigned int));
404 static void mmo_write_tetra_raw
PARAMS ((bfd
*, unsigned int));
405 static void mmo_write_octa
PARAMS ((bfd
*, bfd_vma
));
406 static void mmo_write_octa_raw
PARAMS ((bfd
*, bfd_vma
));
407 static boolean mmo_write_chunk
408 PARAMS ((bfd
*, CONST bfd_byte
*, unsigned int));
409 static boolean mmo_write_loc_chunk
410 PARAMS ((bfd
*, bfd_vma
, CONST bfd_byte
*, unsigned int));
411 static boolean mmo_write_chunk_list
PARAMS ((bfd
*, mmo_data_list_type
*));
412 static boolean mmo_write_loc_chunk_list
413 PARAMS ((bfd
*, mmo_data_list_type
*));
414 static boolean mmo_write_symbols_and_terminator
PARAMS ((bfd
*));
415 static flagword mmo_sec_flags_from_bfd_flags
PARAMS ((flagword
));
416 static flagword bfd_sec_flags_from_mmo_flags
PARAMS ((flagword
));
417 static bfd_byte mmo_get_byte
PARAMS ((bfd
*));
418 static void mmo_write_byte
PARAMS ((bfd
*, bfd_byte
));
419 static boolean mmo_new_section_hook
PARAMS ((bfd
*, asection
*));
420 static int mmo_sort_mmo_symbols
PARAMS ((CONST PTR
, CONST PTR
));
421 static boolean mmo_write_object_contents
PARAMS ((bfd
*));
422 static long mmo_canonicalize_reloc
423 PARAMS ((bfd
*, sec_ptr
, arelent
**, asymbol
**));
425 /* Global "const" variables initialized once. Must not depend on
426 particular input or caller; put such things into the bfd or elsewhere.
427 Look ma, no static per-invocation data! */
430 char valid_mmo_symbol_character_set
[/* A-Z a-z (we assume consecutive
431 codes; sorry EBCDIC:ers!). */
432 + 'Z' - 'A' + 1 + 'z' - 'a' + 1
437 /* Codes higher than 126. */
443 /* Get section SECNAME or create one if it doesn't exist. When creating
444 one, new memory for the name is allocated. */
447 mmo_make_section (abfd
, secname
)
451 asection
*sec
= bfd_get_section_by_name (abfd
, secname
);
455 char *newsecname
= strdup (secname
);
457 if (newsecname
== NULL
)
459 (*_bfd_error_handler
)
460 (_("%s: No core to allocate section name %s\n"),
461 bfd_get_filename (abfd
), secname
);
462 bfd_set_error (bfd_error_system_call
);
465 sec
= bfd_make_section (abfd
, newsecname
);
471 /* Nothing to do, but keep as a placeholder if we need it.
472 Note that state that might differ between bfd:s must not be initialized
473 here, nor must it be static. Add it to tdata information instead. */
478 static boolean inited
= false;
481 static const char letters
[]
482 = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789:_";
489 /* Fill in the set of valid symbol characters. */
490 strcpy (valid_mmo_symbol_character_set
, letters
);
491 i
= strlen (letters
);
493 for (j
= 126; j
< 256; j
++)
494 valid_mmo_symbol_character_set
[i
++] = j
;
497 /* Check whether an existing file is an mmo file. */
499 static CONST bfd_target
*
508 if (bfd_stat (abfd
, &statbuf
) < 0
509 || bfd_seek (abfd
, (file_ptr
) 0, SEEK_SET
) != 0
510 || bfd_bread (b
, 4, abfd
) != 4)
513 /* All mmo files are a multiple of four bytes long.
514 Only recognize version one. */
515 if ((statbuf
.st_size
% 4) != 0
516 || b
[0] != LOP
|| b
[1] != LOP_PRE
|| b
[2] != 1)
519 /* Get the last 32-bit word. */
520 if (bfd_seek (abfd
, (file_ptr
) statbuf
.st_size
- 4, SEEK_SET
) != 0
521 || bfd_bread (b
, 4, abfd
) != 4)
524 /* Check if the file ends in a lop_end lopcode. */
525 if (b
[0] != LOP
|| b
[1] != LOP_END
|| ! mmo_mkobject (abfd
))
528 /* Compute an upper bound on the max symbol length. Not really
529 important as all of the symbol information can only be 256k. */
530 abfd
->tdata
.mmo_data
->max_symbol_length
= (b
[2] * 256 + b
[3]) * 4;
531 abfd
->tdata
.mmo_data
->lop_stab_symbol
532 = bfd_malloc (abfd
->tdata
.mmo_data
->max_symbol_length
+ 1);
534 if (abfd
->tdata
.mmo_data
->lop_stab_symbol
== NULL
)
536 (*_bfd_error_handler
)
537 (_("%s: No core to allocate a symbol %d bytes long\n"),
538 bfd_get_filename (abfd
), abfd
->tdata
.mmo_data
->max_symbol_length
);
542 /* Read in everything. */
543 if (! mmo_scan (abfd
))
544 goto bad_format_free
;
546 if (abfd
->symcount
> 0)
547 abfd
->flags
|= HAS_SYMS
;
549 /* You'll have to tweak this if you want to use this format for other
550 arches (not recommended due to its small-size limitations). Look at
551 the ELF format for how to make it target-generic. */
552 if (! bfd_default_set_arch_mach (abfd
, bfd_arch_mmix
, 0))
553 goto bad_format_free
;
558 free (abfd
->tdata
.mmo_data
->lop_stab_symbol
);
560 bfd_set_error (bfd_error_wrong_format
);
565 /* Set up the mmo tdata information. */
573 if (abfd
->tdata
.mmo_data
== NULL
)
577 /* All fields are zero-initialized, so we don't have to explicitly
579 tdata_type
*tdata
= (tdata_type
*) bfd_zmalloc (sizeof (tdata_type
));
583 created
= time (NULL
);
584 bfd_put_32 (abfd
, created
, tdata
->created
);
586 abfd
->tdata
.mmo_data
= tdata
;
593 mmo_bfd_copy_private_bfd_data (ibfd
, obfd
)
597 if (bfd_get_flavour (ibfd
) != bfd_target_mmo_flavour
598 || bfd_get_flavour (obfd
) != bfd_target_mmo_flavour
)
601 /* Copy the time the copied-from file was created. If people want the
602 time the file was last *modified*, they have that in the normal file
604 memcpy (obfd
->tdata
.mmo_data
->created
, ibfd
->tdata
.mmo_data
->created
,
605 sizeof (obfd
->tdata
.mmo_data
->created
));
609 /* Helper functions for mmo_decide_section, used through
610 bfd_map_over_sections. */
613 mmo_find_sec_w_addr (abfd
, sec
, p
)
614 bfd
*abfd ATTRIBUTE_UNUSED
;
618 struct mmo_find_sec_info
*infop
= (struct mmo_find_sec_info
*) p
;
619 bfd_vma vma
= bfd_get_section_vma (abfd
, sec
);
621 /* Ignore sections that aren't loaded. */
622 if ((bfd_get_section_flags (abfd
, sec
) & (SEC_LOAD
| SEC_ALLOC
))
623 != (SEC_LOAD
| SEC_ALLOC
))
626 if (infop
->addr
>= vma
&& infop
->addr
< vma
+ sec
->_raw_size
)
631 mmo_find_sec_w_addr_grow (abfd
, sec
, p
)
632 bfd
*abfd ATTRIBUTE_UNUSED
;
636 struct mmo_find_sec_info
*infop
= (struct mmo_find_sec_info
*) p
;
637 bfd_vma vma
= bfd_get_section_vma (abfd
, sec
);
639 /* Ignore sections that aren't loaded. */
640 if ((bfd_get_section_flags (abfd
, sec
) & (SEC_LOAD
| SEC_ALLOC
))
641 != (SEC_LOAD
| SEC_ALLOC
))
644 if (infop
->addr
>= vma
&& infop
->addr
< vma
+ MAX_ARTIFICIAL_SECTION_SIZE
)
648 /* Find a section that corresponds to a VMA. Automatically create .text
649 or .data and set current section to it, depending on what vma. If we
650 can't deduce a section, make one up as ".MMIX.sec.N", where N is an
651 increasing number. */
654 mmo_decide_section (abfd
, vma
)
658 asection
*sec
= NULL
;
659 char sec_name
[sizeof (".MMIX.sec.") + 20];
660 struct mmo_find_sec_info info
;
665 /* First see if there's a section that would match exactly. */
666 bfd_map_over_sections (abfd
, mmo_find_sec_w_addr
, &info
);
668 if (info
.sec
!= NULL
)
671 /* If there's no such section, try and expand one of the existing ones,
672 up to a limit. Make sure we have .text and .data before we try that;
673 create them corresponding to expected addresses and set flags to make
674 them match the "loaded and with contents" expectation. */
675 if ((vma
>> 56) == 0)
677 sec
= bfd_make_section_old_way (abfd
, MMO_TEXT_SECTION_NAME
);
682 if (! sec
->user_set_vma
)
683 bfd_set_section_vma (abfd
, sec
, vma
);
684 if (! bfd_set_section_flags (abfd
, sec
,
685 bfd_get_section_flags (abfd
, sec
)
686 | SEC_CODE
| SEC_LOAD
| SEC_ALLOC
))
689 else if ((vma
>> 56) == 0x20)
691 sec
= bfd_make_section_old_way (abfd
, MMO_DATA_SECTION_NAME
);
696 if (! sec
->user_set_vma
)
697 bfd_set_section_vma (abfd
, sec
, vma
);
698 if (! bfd_set_section_flags (abfd
, sec
,
699 bfd_get_section_flags (abfd
, sec
)
700 | SEC_LOAD
| SEC_ALLOC
))
704 bfd_map_over_sections (abfd
, mmo_find_sec_w_addr_grow
, &info
);
706 if (info
.sec
!= NULL
)
709 /* If there's still no suitable section, make a new one. */
710 sprintf (sec_name
, ".MMIX.sec.%d", abfd
->tdata
.mmo_data
->sec_no
++);
711 sec
= mmo_make_section (abfd
, sec_name
);
712 if (! sec
->user_set_vma
)
713 bfd_set_section_vma (abfd
, sec
, vma
);
715 if (! bfd_set_section_flags (abfd
, sec
,
716 bfd_get_section_flags (abfd
, sec
)
717 | SEC_LOAD
| SEC_ALLOC
))
722 /* Xor in a 64-bit value VALUE at VMA. */
725 mmo_xore_64 (sec
, vma
, value
)
730 bfd_byte
*loc
= mmo_get_loc (sec
, vma
, 8);
731 bfd_vma prev
= bfd_get_64 (sec
->owner
, loc
);
734 bfd_put_64 (sec
->owner
, value
, loc
);
737 /* Xor in a 32-bit value VALUE at VMA. */
740 mmo_xore_32 (sec
, vma
, value
)
745 bfd_byte
*loc
= mmo_get_loc (sec
, vma
, 4);
746 unsigned int prev
= bfd_get_32 (sec
->owner
, loc
);
749 bfd_put_32 (sec
->owner
, value
, loc
);
752 /* Xor in a 16-bit value VALUE at VMA. */
755 mmo_xore_16 (sec
, vma
, value
)
760 bfd_byte
*loc
= mmo_get_loc (sec
, vma
, 2);
761 unsigned int prev
= bfd_get_16 (sec
->owner
, loc
);
764 bfd_put_16 (sec
->owner
, value
, loc
);
767 /* Write a 32-bit word to output file, no lop_quote generated. */
770 mmo_write_tetra_raw (abfd
, value
)
776 bfd_put_32 (abfd
, value
, buf
);
778 if (bfd_bwrite ((PTR
) buf
, 4, abfd
) != 4)
779 abfd
->tdata
.mmo_data
->have_error
= true;
782 /* Write a 32-bit word to output file; lop_quote if necessary. */
785 mmo_write_tetra (abfd
, value
)
789 if (((value
>> 24) & 0xff) == LOP
)
790 mmo_write_tetra_raw (abfd
, LOP_QUOTE_NEXT
);
792 mmo_write_tetra_raw (abfd
, value
);
795 /* Write a 64-bit word to output file, perhaps with lop_quoting. */
798 mmo_write_octa (abfd
, value
)
802 mmo_write_tetra (abfd
, (unsigned int) (value
>> 32));
803 mmo_write_tetra (abfd
, (unsigned int) value
);
806 /* Write a 64-bit word to output file, without lop_quoting. */
809 mmo_write_octa_raw (abfd
, value
)
813 mmo_write_tetra_raw (abfd
, (unsigned int) (value
>> 32));
814 mmo_write_tetra_raw (abfd
, (unsigned int) value
);
817 /* Write quoted contents, zero filled. */
819 static INLINE boolean
820 mmo_write_chunk (abfd
, loc
, len
)
825 boolean retval
= true;
826 bfd_byte buf
[4] = {0, 0, 0, 0};
831 mmo_write_tetra_raw (abfd
, LOP_QUOTE_NEXT
);
835 && abfd
->tdata
.mmo_data
->have_error
== false
836 && 4 == bfd_bwrite ((PTR
) loc
, 4, abfd
));
844 memcpy (buf
, loc
, len
);
846 mmo_write_tetra_raw (abfd
, LOP_QUOTE_NEXT
);
850 && abfd
->tdata
.mmo_data
->have_error
== false
851 && 4 == bfd_bwrite ((PTR
) buf
, 4, abfd
));
857 /* Same, but from a list. */
859 static INLINE boolean
860 mmo_write_chunk_list (abfd
, datap
)
862 mmo_data_list_type
*datap
;
864 for (; datap
!= NULL
; datap
= datap
->next
)
865 if (! mmo_write_chunk (abfd
, datap
->data
, datap
->size
))
871 /* Write a lop_loc and some contents. */
874 mmo_write_loc_chunk (abfd
, vma
, loc
, len
)
880 /* We always write the location as 64 bits; no use saving bytes here. */
881 mmo_write_tetra_raw (abfd
, (LOP
<< 24) | (LOP_LOC
<< 16) | 2);
883 /* Find an initial and trailing section of zero tetras; we don't need to
884 write out zeros. FIXME: When we do this, we should emit section size
885 and address specifiers, else objcopy can't perform a unity
887 while (len
>= 4 && bfd_get_32 (abfd
, loc
) == 0)
894 while (len
>= 4 && bfd_get_32 (abfd
, loc
+ len
- 4) == 0)
897 mmo_write_octa_raw (abfd
, vma
);
899 abfd
->tdata
.mmo_data
->have_error
== false
900 && mmo_write_chunk (abfd
, loc
, len
);
903 /* Same, but from a list. */
905 static INLINE boolean
906 mmo_write_loc_chunk_list (abfd
, datap
)
908 mmo_data_list_type
*datap
;
910 for (; datap
!= NULL
; datap
= datap
->next
)
911 if (! mmo_write_loc_chunk (abfd
, datap
->where
, datap
->data
, datap
->size
))
917 /* Make a .MMIX.spec_data.N section. */
920 mmo_get_generic_spec_data_section (abfd
, spec_data_number
)
922 int spec_data_number
;
925 char secname
[sizeof (MMIX_OTHER_SPEC_SECTION_PREFIX
) + 20]
926 = MMIX_OTHER_SPEC_SECTION_PREFIX
;
928 sprintf (secname
+ strlen (MMIX_OTHER_SPEC_SECTION_PREFIX
),
929 "%d", spec_data_number
);
931 sec
= mmo_make_section (abfd
, secname
);
936 /* Make a special section for SPEC_DATA_NUMBER. If it is the one we use
937 ourselves, parse some of its data to get at the section name. */
940 mmo_get_spec_section (abfd
, spec_data_number
)
942 int spec_data_number
;
947 unsigned int secname_length
;
949 bfd_vma section_length
;
951 mmo_data_list_type
*loc
;
955 /* If this isn't the "special" special data, then make a placeholder
957 if (spec_data_number
!= SPEC_DATA_SECTION
)
958 return mmo_get_generic_spec_data_section (abfd
, spec_data_number
);
960 /* Seek back to this position if there was a format error. */
961 orig_pos
= bfd_tell (abfd
);
963 /* Read the length (in 32-bit words). */
964 if (bfd_bread (buf
, 4, abfd
) != 4)
969 if (buf
[1] != LOP_QUOTE
)
972 if (bfd_bread (buf
, 4, abfd
) != 4)
976 /* We don't care to keep the name length accurate. It's
978 secname_length
= bfd_get_32 (abfd
, buf
) * 4;
980 /* Check section name length for sanity. */
981 if (secname_length
> MAX_SECTION_NAME_SIZE
)
984 /* This should be free'd regardless if a section is created. */
985 secname
= bfd_malloc (secname_length
+ 1);
986 secname
[secname_length
] = 0;
988 for (i
= 0; i
< secname_length
/ 4; i
++)
990 if (bfd_bread (secname
+ i
* 4, 4, abfd
) != 4)
991 goto format_error_free
;
993 if (secname
[i
* 4] == LOP
)
995 /* A bit of overkill, but we handle char 0x98 in a section name,
996 and recognize misparsing. */
997 if (secname
[i
* 4 + 1] != LOP_QUOTE
998 || bfd_bread (secname
+ i
* 4, 4, abfd
) != 4)
999 /* Whoops. We thought this was a name, and now we found a
1000 non-lop_quote lopcode before we parsed the whole length of
1001 the name. Signal end-of-file in the same manner. */
1002 goto format_error_free
;
1006 /* Get the section flags. */
1007 if (bfd_bread (buf
, 4, abfd
) != 4
1009 && (buf
[1] != LOP_QUOTE
|| bfd_bread (buf
, 4, abfd
) != 4)))
1010 goto format_error_free
;
1012 flags
= bfd_get_32 (abfd
, buf
);
1014 /* Get the section length. */
1015 if (bfd_bread (buf
, 4, abfd
) != 4
1017 && (buf
[1] != LOP_QUOTE
|| bfd_bread (buf
, 4, abfd
) != 4)))
1018 goto format_error_free
;
1020 section_length
= (bfd_vma
) bfd_get_32 (abfd
, buf
) << 32;
1022 /* That's the first, high-part. Now get the low part. */
1024 if (bfd_bread (buf
, 4, abfd
) != 4
1026 && (buf
[1] != LOP_QUOTE
|| bfd_bread (buf
, 4, abfd
) != 4)))
1027 goto format_error_free
;
1029 section_length
|= (bfd_vma
) bfd_get_32 (abfd
, buf
);
1031 /* Check the section length for sanity. */
1032 if (section_length
> MAX_ARTIFICIAL_SECTION_SIZE
)
1033 goto format_error_free
;
1035 /* Get the section VMA. */
1036 if (bfd_bread (buf
, 4, abfd
) != 4
1038 && (buf
[1] != LOP_QUOTE
|| bfd_bread (buf
, 4, abfd
) != 4)))
1039 goto format_error_free
;
1041 section_vma
= (bfd_vma
) bfd_get_32 (abfd
, buf
) << 32;
1043 /* That's the first, high-part. Now get the low part. */
1044 if (bfd_bread (buf
, 4, abfd
) != 4
1046 && (buf
[1] != LOP_QUOTE
|| bfd_bread (buf
, 4, abfd
) != 4)))
1047 goto format_error_free
;
1049 section_vma
|= (bfd_vma
) bfd_get_32 (abfd
, buf
);
1051 sec
= mmo_make_section (abfd
, secname
);
1056 /* We allocate a buffer here for the advertised size, with head room for
1057 tetrabyte alignment. */
1058 loc
= bfd_zmalloc (section_length
+ 3
1059 + sizeof (struct mmo_data_list_struct
));
1063 /* Use a TETRA-rounded size for the allocated buffer; we set the
1064 "visible" section size below. */
1065 loc
->size
= (section_length
+ 3) & ~3;
1067 /* Add in the section flags we found to those bfd entered during this
1068 process and set the contents. */
1069 if (! bfd_set_section_flags (abfd
, sec
,
1070 bfd_sec_flags_from_mmo_flags (flags
)
1071 | bfd_get_section_flags (abfd
, sec
)
1072 | (section_length
!= 0 ? SEC_HAS_CONTENTS
: 0))
1073 || ! bfd_set_section_size (abfd
, sec
,
1074 sec
->_cooked_size
+ section_length
)
1075 /* Set VMA only for the first occurrence. */
1076 || (! sec
->user_set_vma
1077 && ! bfd_set_section_vma (abfd
, sec
, section_vma
)))
1079 /* If we get an error for any of the calls above, signal more than
1080 just a format error for the spec section. */
1085 if (((struct mmo_section_data_struct
*) (sec
->used_by_bfd
))->tail
!= NULL
)
1086 ((struct mmo_section_data_struct
*) (sec
->used_by_bfd
))->tail
->next
1089 ((struct mmo_section_data_struct
*) (sec
->used_by_bfd
))->head
= loc
;
1090 ((struct mmo_section_data_struct
*) (sec
->used_by_bfd
))->tail
= loc
;
1091 loc
->where
= section_vma
;
1098 if (bfd_seek (abfd
, orig_pos
, SEEK_SET
) != 0)
1101 return mmo_get_generic_spec_data_section (abfd
, spec_data_number
);
1104 /* Read a byte, but read from file in multiples of 32-bit words. */
1112 if (abfd
->tdata
.mmo_data
->byte_no
== 0)
1114 if (abfd
->tdata
.mmo_data
->have_error
== false
1115 && bfd_bread (abfd
->tdata
.mmo_data
->buf
, 4, abfd
) != 4)
1117 abfd
->tdata
.mmo_data
->have_error
= true;
1119 /* A value somewhat safe against tripping on some inconsistency
1120 when mopping up after this error. */
1125 retval
= abfd
->tdata
.mmo_data
->buf
[abfd
->tdata
.mmo_data
->byte_no
];
1126 abfd
->tdata
.mmo_data
->byte_no
= (abfd
->tdata
.mmo_data
->byte_no
+ 1) % 4;
1131 /* Write a byte, in multiples of 32-bit words. */
1134 mmo_write_byte (abfd
, value
)
1138 abfd
->tdata
.mmo_data
->buf
[(abfd
->tdata
.mmo_data
->byte_no
++ % 4)] = value
;
1139 if ((abfd
->tdata
.mmo_data
->byte_no
% 4) == 0)
1141 if (abfd
->tdata
.mmo_data
->have_error
== false
1142 && bfd_bwrite (abfd
->tdata
.mmo_data
->buf
, 4, abfd
) != 4)
1143 abfd
->tdata
.mmo_data
->have_error
= true;
1147 /* Create a symbol. */
1150 mmo_create_symbol (abfd
, symname
, addr
, sym_type
, serno
)
1152 CONST
char *symname
;
1154 enum mmo_sym_type sym_type
;
1157 struct mmo_symbol
*n
;
1159 n
= (struct mmo_symbol
*) bfd_alloc (abfd
, sizeof (struct mmo_symbol
));
1163 n
->name
= bfd_alloc (abfd
, strlen (symname
) + 1);
1164 if (n
->name
== NULL
)
1167 strcpy ((PTR
) n
->name
, symname
);
1170 n
->sym_type
= sym_type
;
1173 if (abfd
->tdata
.mmo_data
->symbols
== NULL
)
1174 abfd
->tdata
.mmo_data
->symbols
= n
;
1176 abfd
->tdata
.mmo_data
->symtail
->next
= n
;
1177 abfd
->tdata
.mmo_data
->symtail
= n
;
1182 /* Check that :Main equals the last octa of the .MMIX.reg_contents
1183 section, as it's the one place we're sure to pass when reading a mmo
1184 object. For written objects, we do it while setting the symbol
1186 if (strcmp (symname
, MMIX_START_SYMBOL_NAME
) == 0
1187 && bfd_get_start_address (abfd
) != addr
)
1189 (*_bfd_error_handler
)
1190 (_("%s: invalid mmo file: initialization value for $255 is not `Main'\n"),
1191 bfd_get_filename (abfd
));
1192 bfd_set_error (bfd_error_bad_value
);
1199 /* Read in symbols. */
1202 mmo_get_symbols (abfd
)
1207 Symbol-table, mmo section mapping, File layout, mmo
1211 From mmixal.w (or really, the generated mmixal.tex) in
1212 @url{http://www-cs-faculty.stanford.edu/~knuth/programs/mmix.tar.gz}):
1213 ``Symbols are stored and retrieved by means of a @samp{ternary
1214 search trie}, following ideas of Bentley and Sedgewick. (See
1215 ACM--SIAM Symp.@: on Discrete Algorithms @samp{8} (1997), 360--369;
1216 R.@:Sedgewick, @samp{Algorithms in C} (Reading, Mass.@:
1217 Addison--Wesley, 1998), @samp{15.4}.) Each trie node stores a
1218 character, and there are branches to subtries for the cases where
1219 a given character is less than, equal to, or greater than the
1220 character in the trie. There also is a pointer to a symbol table
1221 entry if a symbol ends at the current node.''
1223 So it's a tree encoded as a stream of bytes. The stream of bytes
1224 acts on a single virtual global symbol, adding and removing
1225 characters and signalling complete symbol points. Here, we read
1226 the stream and create symbols at the completion points.
1228 First, there's a control byte <<m>>. If any of the listed bits
1229 in <<m>> is nonzero, we execute what stands at the right, in
1233 | 0x40 - Traverse left trie.
1234 | (Read a new command byte and recurse.)
1237 | 0x2f - Read the next byte as a character and store it in the
1238 | current character position; increment character position.
1239 | Test the bits of <<m>>:
1242 | 0x80 - The character is 16-bit (so read another byte,
1243 | merge into current character.
1246 | 0xf - We have a complete symbol; parse the type, value
1247 | and serial number and do what should be done
1248 | with a symbol. The type and length information
1249 | is in j = (m & 0xf).
1251 | (MMO3_REGQUAL_BITS)
1252 | j == 0xf: A register variable. The following
1253 | byte tells which register.
1254 | j <= 8: An absolute symbol. Read j bytes as the
1255 | big-endian number the symbol equals.
1256 | A j = 2 with two zero bytes denotes an
1258 | j > 8: As with j <= 8, but add (0x20 << 56)
1259 | to the value in the following j - 8
1262 | Then comes the serial number, as a variant of
1263 | uleb128, but better named ubeb128:
1264 | Read bytes and shift the previous value left 7
1265 | (multiply by 128). Add in the new byte, repeat
1266 | until a byte has bit 7 set. The serial number
1267 | is the computed value minus 128.
1270 | 0x20 - Traverse middle trie. (Read a new command byte
1271 | and recurse.) Decrement character position.
1274 | 0x10 - Traverse right trie. (Read a new command byte and
1277 Let's look again at the <<lop_stab>> for the trivial file
1278 (@pxref{File layout}).
1280 | 0x980b0000 - lop_stab for ":Main" = 0, serial 1.
1287 This forms the trivial trie (note that the path between ``:'' and
1288 ``M'' is redundant):
1299 | 016e "n" is the last character in a full symbol, and
1300 | with a value represented in one byte.
1301 | 00 The value is 0.
1302 | 81 The serial number is 1. */
1304 bfd_byte m
= mmo_get_byte (abfd
);
1306 /* Check first if we have a bad hair day. */
1307 if (abfd
->tdata
.mmo_data
->have_error
== true)
1311 /* Traverse left trie. */
1312 mmo_get_symbols (abfd
);
1314 if (m
& MMO3_SYMBITS
)
1316 bfd_byte c
= mmo_get_byte (abfd
);
1317 bfd_byte j
= m
& MMO3_TYPEBITS
;
1319 enum mmo_sym_type sym_type
;
1320 unsigned int serno
= 0;
1325 bfd_byte c2
= mmo_get_byte (abfd
);
1327 /* A two-byte character. We can't grok this, but neither can
1328 mmotype, for other cases than the second byte being zero. */
1332 abfd
->tdata
.mmo_data
->lop_stab_symbol
1333 [abfd
->tdata
.mmo_data
->symbol_position
] = 0;
1335 (*_bfd_error_handler
)
1336 (_("%s: unsupported wide character sequence\
1337 0x%02X 0x%02X after symbol name starting with `%s'\n"),
1338 bfd_get_filename (abfd
), c
, c2
,
1339 abfd
->tdata
.mmo_data
->lop_stab_symbol
);
1340 bfd_set_error (bfd_error_bad_value
);
1341 abfd
->tdata
.mmo_data
->have_error
= true;
1348 abfd
->tdata
.mmo_data
->lop_stab_symbol
[abfd
->tdata
.mmo_data
->symbol_position
++] = c
;
1349 abfd
->tdata
.mmo_data
->lop_stab_symbol
[abfd
->tdata
.mmo_data
->symbol_position
] = 0;
1351 if (j
& MMO3_REGQUAL_BITS
)
1353 if (j
== MMO3_REGQUAL_BITS
)
1355 sym_type
= mmo_reg_sym
;
1356 addr
= mmo_get_byte (abfd
);
1362 for (i
= 0; i
< j
; i
++)
1363 addr
= (addr
<< 8) + mmo_get_byte (abfd
);
1365 if (addr
== 0 && j
== MMO3_UNDEF
)
1366 sym_type
= mmo_undef_sym
;
1368 sym_type
= mmo_abs_sym
;
1374 for (i
= MMO3_DATA
; i
< j
; i
++)
1375 addr
= (addr
<< 8) + mmo_get_byte (abfd
);
1377 addr
+= (bfd_vma
) 0x20 << 56;
1378 sym_type
= mmo_data_sym
;
1381 /* Get the serial number. */
1384 k
= mmo_get_byte (abfd
);
1385 serno
= (serno
<< 7) + k
;
1390 /* Got it. Now enter it. Skip a leading ":". */
1391 if (abfd
->tdata
.mmo_data
->have_error
== false
1392 && ! mmo_create_symbol (abfd
,
1393 abfd
->tdata
.mmo_data
->lop_stab_symbol
1395 addr
, sym_type
, serno
))
1396 abfd
->tdata
.mmo_data
->have_error
= true;
1399 if (m
& MMO3_MIDDLE
)
1400 /* Traverse middle trie. */
1401 mmo_get_symbols (abfd
);
1403 abfd
->tdata
.mmo_data
->symbol_position
--;
1407 /* Traverse right trie. */
1408 mmo_get_symbols (abfd
);
1410 return abfd
->tdata
.mmo_data
->have_error
== false;
1413 /* Get the location of memory area [VMA..VMA + SIZE - 1], which we think
1414 is in section SEC. Adjust and reallocate zero-initialized contents.
1415 If there's new contents, allocate to the next multiple of
1416 MMO_SEC_CONTENTS_CHUNK_SIZE. */
1418 static INLINE bfd_byte
*
1419 mmo_get_loc (sec
, vma
, size
)
1424 bfd_size_type allocated_size
;
1425 struct mmo_section_data_struct
*sdatap
1426 = (struct mmo_section_data_struct
*) sec
->used_by_bfd
;
1427 struct mmo_data_list_struct
*datap
= sdatap
->head
;
1428 struct mmo_data_list_struct
*entry
;
1430 for (; datap
!= NULL
; datap
= datap
->next
)
1432 if (datap
->where
<= vma
1433 && datap
->where
+ datap
->size
>= vma
+ size
)
1434 return datap
->data
+ vma
- datap
->where
;
1435 else if (datap
->where
<= vma
1436 && datap
->where
+ datap
->allocated_size
>= vma
+ size
1437 /* Only munch on the "allocated size" if it does not
1438 overlap the next chunk. */
1439 && (datap
->next
== NULL
|| datap
->next
->where
>= vma
+ size
))
1441 /* There was room allocated, but the size wasn't set to include
1443 datap
->size
+= (vma
+ size
) - (datap
->where
+ datap
->size
);
1445 /* Update the section size. */
1446 if (vma
+ size
> sec
->vma
+ sec
->_raw_size
)
1447 sec
->_raw_size
+= (vma
+ size
) - (sec
->vma
+ sec
->_raw_size
);
1449 return datap
->data
+ vma
- datap
->where
;
1453 /* Not found; allocate a new block. First check in case we get a
1454 request for a size split up over several blocks; we'll have to return
1455 NULL for those cases, requesting the caller to split up the request.
1456 Requests with an address aligned on MMO_SEC_CONTENTS_CHUNK_SIZE bytes and
1457 for no more than MMO_SEC_CONTENTS_CHUNK_SIZE will always get resolved. */
1459 for (datap
= sdatap
->head
; datap
!= NULL
; datap
= datap
->next
)
1460 if ((datap
->where
<= vma
&& datap
->where
+ datap
->size
> vma
)
1461 || (datap
->where
< vma
+ size
1462 && datap
->where
+ datap
->size
>= vma
+ size
))
1466 = (size
+ MMO_SEC_CONTENTS_CHUNK_SIZE
- 1) & ~(MMO_SEC_CONTENTS_CHUNK_SIZE
- 1);
1467 entry
= (mmo_data_list_type
*)
1468 bfd_zalloc (sec
->owner
, sizeof (mmo_data_list_type
) + allocated_size
);
1473 entry
->allocated_size
= allocated_size
;
1475 datap
= sdatap
->head
;
1477 /* Sort the records by address. Optimize for the common case of adding
1478 a record to the end of the list. */
1479 if (sdatap
->tail
!= NULL
&& entry
->where
>= sdatap
->tail
->where
)
1481 sdatap
->tail
->next
= entry
;
1483 sdatap
->tail
= entry
;
1487 mmo_data_list_type
**look
;
1488 for (look
= &sdatap
->head
;
1489 *look
!= NULL
&& (*look
)->where
< entry
->where
;
1490 look
= &(*look
)->next
)
1492 entry
->next
= *look
;
1494 if (entry
->next
== NULL
)
1496 sdatap
->tail
= entry
;
1498 /* We get here for the first time (at other times too) for this
1499 section. Say we have contents. */
1500 if (! bfd_set_section_flags (sec
->owner
, sec
,
1501 bfd_get_section_flags (sec
->owner
, sec
)
1502 | SEC_HAS_CONTENTS
))
1507 /* Update the section size. */
1508 if (vma
+ size
> sec
->vma
+ sec
->_raw_size
)
1509 sec
->_raw_size
+= (vma
+ size
) - (sec
->vma
+ sec
->_raw_size
);
1513 /* Set sizes once we've read in all sections. */
1516 mmo_map_set_sizes (abfd
, sec
, ignored
)
1517 bfd
*abfd ATTRIBUTE_UNUSED
;
1519 PTR ignored ATTRIBUTE_UNUSED
;
1521 sec
->_cooked_size
= sec
->_raw_size
;
1522 sec
->lma
= sec
->vma
;
1525 /* Read the mmo file and turn it into sections. */
1532 unsigned int lineno
= 1;
1533 boolean error
= false;
1535 asection
*sec
= bfd_make_section_old_way (abfd
, MMO_TEXT_SECTION_NAME
);
1536 asection
*non_spec_sec
= NULL
;
1537 bfd_vma non_spec_vma
= 0;
1538 char *current_filename
= NULL
;
1539 bfd_size_type nbytes_read
= 0;
1540 /* Buffer with room to read a 64-bit value. */
1543 char *file_names
[256];
1545 memset (file_names
, 0, sizeof (file_names
));
1547 if (bfd_seek (abfd
, (file_ptr
) 0, SEEK_SET
) != 0)
1550 while ((nbytes_read
= bfd_bread (buf
, 4, abfd
)) == 4)
1554 unsigned int y
= bfd_get_8 (abfd
, buf
+ 2);
1555 unsigned int z
= bfd_get_8 (abfd
, buf
+ 3);
1557 /* Change back to the original section for lopcodes other
1558 than LOP_QUOTE that comes after a LOP_SPEC. */
1559 if ((buf
[1] != LOP_QUOTE
|| y
!= 0 || z
!= 1)
1560 && non_spec_sec
!= NULL
)
1564 non_spec_sec
= NULL
;
1570 (*_bfd_error_handler
)
1571 (_("%s: invalid mmo file: unsupported lopcode `%d'\n"),
1572 bfd_get_filename (abfd
), buf
[1]);
1573 bfd_set_error (bfd_error_bad_value
);
1577 /* Quote the next 32-bit word. */
1578 if (y
!= 0 || z
!= 1)
1580 (*_bfd_error_handler
)
1581 (_("%s: invalid mmo file: expected YZ = 1 got YZ = %d for lop_quote\n"),
1582 bfd_get_filename (abfd
), y
*256+z
);
1583 bfd_set_error (bfd_error_bad_value
);
1586 if (bfd_bread (buf
, 4, abfd
) != 4)
1589 mmo_xore_32 (sec
, vma
, bfd_get_32 (abfd
, buf
));
1596 /* Set vma (and section). */
1597 vma
= (bfd_vma
) y
<< 56;
1600 /* Get a 32-bit value. */
1601 if (bfd_bread (buf
, 4, abfd
) != 4)
1604 vma
+= bfd_get_32 (abfd
, buf
);
1608 /* Get a 64-bit value. */
1609 if (bfd_bread (buf
, 8, abfd
) != 8)
1612 vma
+= bfd_get_64 (abfd
, buf
);
1616 (*_bfd_error_handler
)
1617 (_("%s: invalid mmo file: expected z = 1 or z = 2, got z = %d for lop_loc\n"),
1618 bfd_get_filename (abfd
), z
);
1619 bfd_set_error (bfd_error_bad_value
);
1623 sec
= mmo_decide_section (abfd
, vma
);
1629 /* Move forward within the same section. */
1632 sec
= mmo_decide_section (abfd
, vma
);
1638 /* A fixup: Store the current vma somewhere. Position using
1639 same format as LOP_LOC. */
1641 bfd_vma p
= (bfd_vma
) y
<< 56;
1646 /* Get a 32-bit value. */
1647 if (bfd_bread (buf
, 4, abfd
) != 4)
1650 p
+= bfd_get_32 (abfd
, buf
);
1654 /* Get a 64-bit value. */
1655 if (bfd_bread (buf
, 8, abfd
) != 8)
1658 p
+= bfd_get_64 (abfd
, buf
);
1662 (*_bfd_error_handler
)
1663 (_("%s: invalid mmo file: expected z = 1 or z = 2, got z = %d for lop_fixo\n"),
1664 bfd_get_filename (abfd
), z
);
1665 bfd_set_error (bfd_error_bad_value
);
1669 /* The section where we store this address might be a
1670 different one than the current section. */
1671 fixosec
= mmo_decide_section (abfd
, p
);
1672 if (fixosec
== NULL
)
1674 mmo_xore_64 (fixosec
, p
, vma
);
1679 /* A fixup: Store YZ of this lopcode into YZ at vma - 4 * yz. */
1681 unsigned int yz
= (y
* 256 + z
);
1682 bfd_vma p
= vma
+ 2 - 4 * yz
;
1683 asection
*fixrsec
= mmo_decide_section (abfd
, p
);
1684 if (fixrsec
== NULL
)
1686 mmo_xore_16 (fixrsec
, p
, yz
);
1691 /* A fixup, similar to lop_fixr, but taking larger numbers
1692 and can change branches into the opposite direction
1701 (*_bfd_error_handler
)
1702 (_("%s: invalid mmo file: expected y = 0, got y = %d for lop_fixrx\n"),
1703 bfd_get_filename (abfd
), y
);
1704 bfd_set_error (bfd_error_bad_value
);
1708 if (z
!= 16 && z
!= 24)
1710 (*_bfd_error_handler
)
1711 (_("%s: invalid mmo file: expected z = 16 or z = 24, got z = %d for lop_fixrx\n"),
1712 bfd_get_filename (abfd
), z
);
1713 bfd_set_error (bfd_error_bad_value
);
1717 /* Get the next 32-bit value. */
1718 if (bfd_bread (buf
, 4, abfd
) != 4)
1721 delta
= bfd_get_32 (abfd
, buf
);
1723 /* Do an, ehm, involved calculation for the location of
1724 the fixup. See mmixal documentation for a verbose
1725 explanation. We follow it verbosely here for the
1728 p
= vma
- 4 * delta
;
1729 else if (buf
[0] == 1)
1730 p
= vma
- 4 * ((delta
& 0xffffff) - (1 << z
));
1733 (*_bfd_error_handler
)
1734 (_("%s: invalid mmo file: leading byte of operand word must be 0 or 1, got %d for lop_fixrx\n"),
1735 bfd_get_filename (abfd
), buf
[0]);
1736 bfd_set_error (bfd_error_bad_value
);
1740 fixrsec
= mmo_decide_section (abfd
, vma
);
1741 if (fixrsec
== NULL
)
1743 mmo_xore_32 (fixrsec
, p
, delta
);
1748 /* Set current file and perhaps the file name. Reset line
1752 char *fname
= bfd_malloc (z
* 4 + 1);
1756 (*_bfd_error_handler
)
1757 (_("%s: cannot allocate file name for file number %d, %d bytes\n"),
1758 bfd_get_filename (abfd
), y
, z
* 4 + 1);
1759 bfd_set_error (bfd_error_system_call
);
1765 for (i
= 0; i
< z
; i
++)
1767 if (bfd_bread (fname
+ i
* 4, 4, abfd
) != 4)
1774 if (file_names
[y
] != NULL
)
1776 (*_bfd_error_handler
)
1777 (_("%s: invalid mmo file: file number %d `%s',\
1778 was already entered as `%s'\n"),
1779 bfd_get_filename (abfd
), y
, fname
, file_names
[y
]);
1780 bfd_set_error (bfd_error_bad_value
);
1784 file_names
[y
] = fname
;
1787 if (file_names
[y
] == NULL
)
1789 (*_bfd_error_handler
)
1790 (_("%s: invalid mmo file: file name for number %d\
1791 was not specified before use\n"),
1792 bfd_get_filename (abfd
), y
);
1793 bfd_set_error (bfd_error_bad_value
);
1797 current_filename
= file_names
[y
];
1802 /* Set line number. */
1803 lineno
= y
* 256 + z
;
1804 /* FIXME: Create a sequence of mmo-specific line number
1805 entries for each section, then translate into canonical
1810 /* Special data follows until the next non-lop_quote
1814 sec
= mmo_get_spec_section (abfd
, y
* 256 + z
);
1823 /* We ignore header information, except we read in the
1824 creation time from the first 32-bit word with the time
1825 in seconds since era. */
1827 && bfd_bread (abfd
->tdata
.mmo_data
->created
, 4,
1831 for (i
= 1; i
< z
; i
++)
1832 if (bfd_bread (buf
, 4, abfd
) != 4)
1838 /* This tells of the contents of registers $Z..$255 at
1839 startup. We make a section out of it, with VMA = Z * 8,
1840 but only if Z != 255 or the contents is non-zero. */
1845 bfd_vma startaddr_octa
;
1847 /* Read first octaword outside loop to simplify logic when
1848 excluding the Z == 255, octa == 0 case. */
1849 if (bfd_bread (buf
, 8, abfd
) != 8)
1852 first_octa
= bfd_get_64 (abfd
, buf
);
1854 /* Don't emit contents for the trivial case which is
1855 always present; $255 pointing to Main. */
1859 = bfd_make_section_old_way (abfd
,
1860 MMIX_REG_CONTENTS_SECTION_NAME
);
1862 loc
= mmo_get_loc (rsec
, z
* 8, (255 - z
) * 8);
1863 bfd_put_64 (abfd
, first_octa
, loc
);
1865 for (i
= z
+ 1; i
< 255; i
++)
1867 if (bfd_bread (loc
+ (i
- z
) * 8, 8, abfd
) != 8)
1871 /* Read out the last octabyte, and use it to set the
1873 if (bfd_bread (buf
, 8, abfd
) != 8)
1876 startaddr_octa
= bfd_get_64 (abfd
, buf
);
1879 startaddr_octa
= first_octa
;
1881 if (! bfd_set_start_address (abfd
, startaddr_octa
))
1883 /* Currently this can't fail, but this should handle
1885 bfd_set_error (bfd_error_bad_value
);
1892 /* We read in the symbols now, not later. */
1893 if (y
!= 0 || z
!= 0)
1895 (*_bfd_error_handler
)
1896 (_("%s: invalid mmo file: fields y and z of lop_stab\
1897 non-zero, y: %d, z: %d\n"),
1898 bfd_get_filename (abfd
), y
, z
);
1899 bfd_set_error (bfd_error_bad_value
);
1903 /* Save the location, so we can check that YZ in the LOP_END
1905 stab_loc
= bfd_tell (abfd
);
1907 /* It's not said that an MMO can be without symbols (though
1908 mmixal will refuse to assemble files without Main), but
1909 it seems it would still be a valid mmo-file, so allow it.
1910 We detect the absence of a symbol area in that the upper
1911 limit is computed (from the lop_end YZ field) as 0.
1912 Don't call mmo_get_symbols; it can only detect the end of
1913 a valid symbol trie, not the absence of one. */
1914 if (abfd
->tdata
.mmo_data
->max_symbol_length
!= 0
1915 && ! mmo_get_symbols (abfd
))
1921 /* This must be the last 32-bit word in an mmo file.
1923 struct stat statbuf
;
1924 long curpos
= bfd_tell (abfd
);
1926 if (bfd_stat (abfd
, &statbuf
) < 0)
1929 if (statbuf
.st_size
!= curpos
)
1931 (*_bfd_error_handler
)
1932 (_("%s: invalid mmo file: lop_end not last item in\
1934 bfd_get_filename (abfd
));
1935 bfd_set_error (bfd_error_bad_value
);
1939 /* Check that the YZ field is right. Subtract the size of
1940 this LOP_END in the calculation; YZ does not include
1942 if ((long) (y
* 256 + z
) * 4 != (curpos
- stab_loc
) - 4)
1944 (*_bfd_error_handler
)
1945 (_("%s: invalid mmo file: YZ of lop_end (%ld)\
1946 not equal to the number of tetras to the preceding lop_stab (%ld)\n"),
1947 bfd_get_filename (abfd
), (long) (y
* 256 + z
),
1948 (curpos
- stab_loc
- 4)/4);
1949 bfd_set_error (bfd_error_bad_value
);
1953 bfd_map_over_sections (abfd
, mmo_map_set_sizes
, NULL
);
1960 /* This wasn't a lopcode, so store it in the current section. */
1961 mmo_xore_32 (sec
, vma
& ~3, bfd_get_32 (abfd
, buf
));
1968 /* We know this file is a multiple of four bytes (checked in
1969 mmo_object_p), so if we got something other than 0, this was a bad
1970 file (although it's more likely we'll get 0 in that case too).
1971 If we got end-of-file, then there was no lop_stab, so the file has
1974 if (nbytes_read
!= 0)
1975 bfd_set_error (bfd_error_system_call
);
1977 bfd_set_error (bfd_error_bad_value
);
1982 /* Mark the .text and .data section with their normal attribute if they
1983 contain anything. This is not redundant wrt. mmo_decide_section,
1984 since that code might never execute, and conversely the alloc+code
1985 section flags must be set then. */
1986 sec
= bfd_get_section_by_name (abfd
, MMO_TEXT_SECTION_NAME
);
1988 && (bfd_get_section_flags (abfd
, sec
) & SEC_HAS_CONTENTS
)
1989 && ! bfd_set_section_flags (abfd
, sec
,
1990 bfd_get_section_flags (abfd
, sec
)
1991 | SEC_ALLOC
| SEC_LOAD
| SEC_CODE
))
1994 sec
= bfd_get_section_by_name (abfd
, MMO_DATA_SECTION_NAME
);
1996 && (bfd_get_section_flags (abfd
, sec
) & SEC_HAS_CONTENTS
)
1997 && ! bfd_set_section_flags (abfd
, sec
,
1998 bfd_get_section_flags (abfd
, sec
)
1999 | SEC_ALLOC
| SEC_LOAD
))
2002 /* Free whatever resources we took. */
2003 for (i
= 0; i
< sizeof (file_names
) / sizeof (file_names
[0]); i
++)
2005 free (file_names
[i
]);
2006 return error
? false : true;
2009 /* A hook to set up object file dependent section information. For mmo,
2010 we point out the shape of allocated section contents. */
2013 mmo_new_section_hook (abfd
, newsect
)
2014 bfd
*abfd ATTRIBUTE_UNUSED
;
2017 /* We zero-fill all fields and assume NULL is represented by an all
2018 zero-bit pattern. */
2019 newsect
->used_by_bfd
=
2020 (PTR
) bfd_zalloc (abfd
, sizeof (struct mmo_section_data_struct
));
2022 if (!newsect
->used_by_bfd
)
2025 /* Always align to at least 32-bit words. */
2026 newsect
->alignment_power
= 2;
2030 /* We already have section contents loaded for sections that have
2034 mmo_get_section_contents (abfd
, sec
, location
, offset
, bytes_to_do
)
2035 bfd
*abfd ATTRIBUTE_UNUSED
;
2036 asection
*sec ATTRIBUTE_UNUSED
;
2037 PTR location ATTRIBUTE_UNUSED
;
2038 file_ptr offset ATTRIBUTE_UNUSED
;
2039 bfd_size_type bytes_to_do ATTRIBUTE_UNUSED
;
2041 /* Iterate over diminishing chunk sizes, copying contents, like
2042 mmo_set_section_contents. */
2045 /* A minor song-and-dance to make sure we're not bitten by the
2046 distant possibility of the cast from bfd_vma to int making the
2047 chunk zero-sized. */
2049 = (int) bytes_to_do
!= 0 ? bytes_to_do
: MMO_SEC_CONTENTS_CHUNK_SIZE
;
2053 loc
= mmo_get_loc (sec
, sec
->vma
+ offset
, chunk_size
);
2054 while (loc
== NULL
&& (chunk_size
/= 2) != 0);
2056 if (chunk_size
== 0)
2059 memcpy (location
, loc
, chunk_size
);
2061 location
+= chunk_size
;
2062 bytes_to_do
-= chunk_size
;
2063 offset
+= chunk_size
;
2068 /* Return the amount of memory needed to read the symbol table. */
2071 mmo_get_symtab_upper_bound (abfd
)
2072 bfd
*abfd ATTRIBUTE_UNUSED
;
2074 return (abfd
->symcount
+ 1) * sizeof (asymbol
*);
2077 /* Sort mmo symbols by serial number. */
2080 mmo_sort_mmo_symbols (arg1
, arg2
)
2084 CONST
struct mmo_symbol
*sym1
= *(CONST
struct mmo_symbol
**) arg1
;
2085 CONST
struct mmo_symbol
*sym2
= *(CONST
struct mmo_symbol
**) arg2
;
2087 /* Sort by serial number first. */
2088 if (sym1
->serno
< sym2
->serno
)
2090 else if (sym1
->serno
> sym2
->serno
)
2093 /* Then sort by address of the table entries. */
2094 return ((CONST
char *) arg1
- (CONST
char *) arg2
);
2097 /* Translate the symbol table. */
2100 mmo_get_symtab (abfd
, alocation
)
2102 asymbol
**alocation
;
2104 unsigned int symcount
= bfd_get_symcount (abfd
);
2108 csymbols
= abfd
->tdata
.mmo_data
->csymbols
;
2109 if (csymbols
== NULL
)
2112 struct mmo_symbol
*s
;
2113 struct mmo_symbol
**msp
;
2115 /* First we store the symbols into the table we'll return, then we
2116 qsort it on the serial number, with secondary on the address of
2117 the symbol, to preserve order if there would be non-unique serial
2119 for (s
= abfd
->tdata
.mmo_data
->symbols
,
2120 msp
= (struct mmo_symbol
**) alocation
;
2127 qsort (alocation
, symcount
, sizeof (struct mmo_symbol
*),
2128 mmo_sort_mmo_symbols
);
2130 csymbols
= (asymbol
*) bfd_alloc (abfd
, symcount
* sizeof (asymbol
));
2131 if (csymbols
== NULL
&& symcount
!= 0)
2133 abfd
->tdata
.mmo_data
->csymbols
= csymbols
;
2135 for (msp
= (struct mmo_symbol
**) alocation
, c
= csymbols
;
2142 c
->value
= s
->value
;
2143 c
->flags
= BSF_GLOBAL
;
2145 if (s
->sym_type
== mmo_data_sym
)
2148 = bfd_get_section_by_name (abfd
, MMO_DATA_SECTION_NAME
);
2150 if (c
->section
== NULL
)
2151 c
->section
= bfd_abs_section_ptr
;
2153 c
->value
-= c
->section
->vma
;
2155 else if (s
->sym_type
== mmo_undef_sym
)
2156 c
->section
= bfd_und_section_ptr
;
2157 else if (s
->sym_type
== mmo_reg_sym
)
2160 = bfd_make_section_old_way (abfd
, MMIX_REG_SECTION_NAME
);
2165 = bfd_get_section_by_name (abfd
, MMO_TEXT_SECTION_NAME
);
2168 && c
->value
>= textsec
->vma
2169 && c
->value
<= textsec
->vma
+ textsec
->_cooked_size
)
2171 c
->section
= textsec
;
2172 c
->value
-= c
->section
->vma
;
2175 c
->section
= bfd_abs_section_ptr
;
2182 /* Last, overwrite the incoming table with the right-type entries. */
2183 for (i
= 0; i
< symcount
; i
++)
2184 *alocation
++ = csymbols
++;
2190 /* Get information about a symbol. */
2193 mmo_get_symbol_info (ignore_abfd
, symbol
, ret
)
2194 bfd
*ignore_abfd ATTRIBUTE_UNUSED
;
2198 bfd_symbol_info (symbol
, ret
);
2202 mmo_print_symbol (abfd
, afile
, symbol
, how
)
2206 bfd_print_symbol_type how
;
2208 FILE *file
= (FILE *) afile
;
2212 case bfd_print_symbol_name
:
2213 fprintf (file
, "%s", symbol
->name
);
2216 bfd_print_symbol_vandf (abfd
, (PTR
) file
, symbol
);
2218 fprintf (file
, " %-5s %s",
2219 symbol
->section
->name
,
2224 /* We can't map a file directly into executable code, so the
2225 size of header information is irrelevant. */
2228 mmo_sizeof_headers (abfd
, exec
)
2229 bfd
*abfd ATTRIBUTE_UNUSED
;
2230 boolean exec ATTRIBUTE_UNUSED
;
2235 /* Write the (section-neutral) file preamble. */
2238 mmo_internal_write_header (abfd
)
2241 CONST
char lop_pre_bfd
[] = { LOP
, LOP_PRE
, 1, 1};
2243 if (bfd_bwrite (lop_pre_bfd
, 4, abfd
) != 4)
2246 /* Copy creation time of original file. */
2247 if (bfd_bwrite (abfd
->tdata
.mmo_data
->created
, 4, abfd
) != 4)
2253 /* Write the LOP_POST record, with global register initializations.
2254 Z is the Z field of the LOP_POST, corresponding to 255 - number of
2255 registers at DATA. The Z = 255 field is filled in with the
2259 mmo_internal_write_post (abfd
, z
, sec
)
2266 mmo_write_tetra_raw (abfd
, (LOP
<< 24) | (LOP_POST
<< 16) | z
);
2268 for (i
= z
; i
< 255; i
++)
2270 bfd_byte
*data
= mmo_get_loc (sec
, i
* 8, 8);
2272 if (bfd_bwrite (data
, 8, abfd
) != 8)
2276 /* For Z == $255, we always emit the start location; supposedly Main,
2277 but we have it handy at bfd_get_start_address. If we're called with
2278 Z == 255, don't assume DATA is valid. */
2279 bfd_put_64 (abfd
, bfd_get_start_address (abfd
), buf
);
2282 abfd
->tdata
.mmo_data
->have_error
== false
2283 && bfd_bwrite (buf
, 8, abfd
) == 8;
2286 /* Translate to and from BFD flags. This is to make sure that we don't
2287 get bitten by BFD flag number changes. */
2290 mmo_sec_flags_from_bfd_flags (flags
)
2293 flagword oflags
= 0;
2295 if (flags
& SEC_ALLOC
)
2296 oflags
|= MMO_SEC_ALLOC
;
2297 if (flags
& SEC_LOAD
)
2298 oflags
|= MMO_SEC_LOAD
;
2299 if (flags
& SEC_RELOC
)
2300 oflags
|= MMO_SEC_RELOC
;
2301 if (flags
& SEC_READONLY
)
2302 oflags
|= MMO_SEC_READONLY
;
2303 if (flags
& SEC_CODE
)
2304 oflags
|= MMO_SEC_CODE
;
2305 if (flags
& SEC_DATA
)
2306 oflags
|= MMO_SEC_DATA
;
2307 if (flags
& SEC_NEVER_LOAD
)
2308 oflags
|= MMO_SEC_NEVER_LOAD
;
2309 if (flags
& SEC_IS_COMMON
)
2310 oflags
|= MMO_SEC_IS_COMMON
;
2311 if (flags
& SEC_DEBUGGING
)
2312 oflags
|= MMO_SEC_DEBUGGING
;
2318 bfd_sec_flags_from_mmo_flags (flags
)
2321 flagword oflags
= 0;
2323 if (flags
& MMO_SEC_ALLOC
)
2324 oflags
|= SEC_ALLOC
;
2325 if (flags
& MMO_SEC_LOAD
)
2327 if (flags
& MMO_SEC_RELOC
)
2328 oflags
|= SEC_RELOC
;
2329 if (flags
& MMO_SEC_READONLY
)
2330 oflags
|= SEC_READONLY
;
2331 if (flags
& MMO_SEC_CODE
)
2333 if (flags
& MMO_SEC_DATA
)
2335 if (flags
& MMO_SEC_NEVER_LOAD
)
2336 oflags
|= SEC_NEVER_LOAD
;
2337 if (flags
& MMO_SEC_IS_COMMON
)
2338 oflags
|= SEC_IS_COMMON
;
2339 if (flags
& MMO_SEC_DEBUGGING
)
2340 oflags
|= SEC_DEBUGGING
;
2345 /* Write a section. */
2348 mmo_internal_write_section (abfd
, sec
)
2352 /* We do it differently depending on what section this is:
2354 ".text": Output, prepended by information about the first source file
2355 (not yet implemented.)
2359 (".MMIX.reg_contents": Not handled here.)
2361 Anything else: Output inside a lop_spec 80, in the format described
2364 if (strcmp (sec
->name
, MMO_TEXT_SECTION_NAME
) == 0)
2365 /* FIXME: Output source file name and line number. */
2367 mmo_write_loc_chunk_list (abfd
,
2368 ((struct mmo_section_data_struct
*)
2369 (sec
->used_by_bfd
))->head
);
2370 else if (strcmp (sec
->name
, MMO_DATA_SECTION_NAME
) == 0)
2372 mmo_write_loc_chunk_list (abfd
,
2373 ((struct mmo_section_data_struct
*)
2374 (sec
->used_by_bfd
))->head
);
2375 else if (strcmp (sec
->name
, MMIX_REG_CONTENTS_SECTION_NAME
) == 0)
2376 /* Not handled here. */
2378 /* This would normally be an abort call since this can't happen, but
2379 we don't do that. */
2380 bfd_set_error (bfd_error_bad_value
);
2383 else if (strncmp (sec
->name
, MMIX_OTHER_SPEC_SECTION_PREFIX
,
2384 strlen (MMIX_OTHER_SPEC_SECTION_PREFIX
)) == 0)
2386 int n
= atoi (sec
->name
+ strlen (MMIX_OTHER_SPEC_SECTION_PREFIX
));
2387 mmo_write_tetra_raw (abfd
, (LOP
<< 24) | (LOP_SPEC
<< 16) | n
);
2389 abfd
->tdata
.mmo_data
->have_error
== false
2390 && mmo_write_chunk_list (abfd
,
2391 ((struct mmo_section_data_struct
*)
2392 (sec
->used_by_bfd
))->head
);
2394 /* Ignore sections that are just allocated or empty; we write out
2396 else if ((bfd_get_section_flags (abfd
, sec
) & SEC_HAS_CONTENTS
) != 0
2397 && sec
->_raw_size
!= 0)
2399 /* Keep the document-comment formatted the way it is. */
2402 mmo section mapping, , Symbol-table, mmo
2406 The implementation in BFD uses special data type 80 (decimal) to
2407 encapsulate and describe named sections, containing e.g.@: debug
2408 information. If needed, any datum in the encapsulation will be
2409 quoted using lop_quote. First comes a 32-bit word holding the
2410 number of 32-bit words containing the zero-terminated zero-padded
2411 segment name. After the name there's a 32-bit word holding flags
2412 describing the section type. Then comes a 64-bit big-endian word
2413 with the section length (in bytes), then another with the section
2414 start address. Depending on the type of section, the contents
2415 might follow, zero-padded to 32-bit boundary. For a loadable
2416 section (such as data or code), the contents might follow at some
2417 later point, not necessarily immediately, as a lop_loc with the
2418 same start address as in the section description, followed by the
2419 contents. This in effect forms a descriptor that must be emitted
2420 before the actual contents. Sections described this way must not
2423 For areas that don't have such descriptors, synthetic sections are
2424 formed by BFD. Consecutive contents in the two memory areas
2425 @samp{0x0000@dots{}00} to @samp{0x01ff@dots{}ff} and
2426 @samp{0x2000@dots{}00} to @samp{0x20ff@dots{}ff} are entered in
2427 sections named <<.text>> and <<.data>> respectively. If an area
2428 is not otherwise described, but would together with a neighboring
2429 lower area be less than @samp{0x40000000} bytes long, it is joined
2430 with the lower area and the gap is zero-filled. For other cases,
2431 a new section is formed, named <<.MMIX.sec.@var{n}>>. Here,
2432 @var{n} is a number, a running count through the mmo file,
2436 A loadable section specified as:
2438 | .section secname,"ax"
2439 | TETRA 1,2,3,4,-1,-2009
2442 and linked to address @samp{0x4}, is represented by the sequence:
2444 | 0x98080050 - lop_spec 80
2445 | 0x00000002 - two 32-bit words for the section name
2446 | 0x7365636e - "secn"
2447 | 0x616d6500 - "ame\0"
2448 | 0x00000033 - flags CODE, READONLY, LOAD, ALLOC
2449 | 0x00000000 - high 32 bits of section length
2450 | 0x0000001c - section length is 28 bytes; 6 * 4 + 1 + alignment to 32 bits
2451 | 0x00000000 - high 32 bits of section address
2452 | 0x00000004 - section address is 4
2453 | 0x98010002 - 64 bits with address of following data
2454 | 0x00000000 - high 64 bits of address
2455 | 0x00000004 - data starts at address 4
2461 | 0xfffff827 - -2009
2462 | 0x50000000 - 80 as a byte, padded with zeros.
2464 Note that the lop_spec wrapping does not include the section
2465 contents. Compare this to a non-loaded section specified as:
2468 | TETRA 200001,100002
2471 This, when linked to address @samp{0x200000000000001c}, is
2474 | 0x98080050 - lop_spec 80
2475 | 0x00000002 - two 32-bit words for the section name
2476 | 0x7365636e - "thir"
2477 | 0x616d6500 - "dsec"
2478 | 0x00000010 - flag READONLY
2479 | 0x00000000 - high 32 bits of section length
2480 | 0x0000000c - section length is 12 bytes; 2 * 4 + 2 + alignment to 32 bits
2481 | 0x20000000 - high 64 bits of address
2482 | 0x0000001c - low 64 bits of address 0x200000000000001c
2483 | 0x00030d41 - 200001
2484 | 0x000186a2 - 100002
2485 | 0x26280000 - 38, 40 as bytes, padded with zeros
2487 For the latter example, the section contents must not to appear
2488 loaded in memory, and is therefore specified as part of the
2489 special data. The address is usually unimportant but might
2490 provide information for e.g.@: the DWARF 2 debugging format. */
2492 mmo_write_tetra_raw (abfd
, LOP_SPEC_SECTION
);
2493 mmo_write_tetra (abfd
, (strlen (sec
->name
) + 3) / 4);
2494 mmo_write_chunk (abfd
, sec
->name
, strlen (sec
->name
));
2495 /* FIXME: We can get debug sections (.debug_line & Co.) with a
2496 section flag still having SEC_RELOC set. Investigate. This
2497 might be true for all alien sections; perhaps mmo.em should clear
2498 that flag. Might be related to weak references. */
2499 mmo_write_tetra (abfd
,
2500 mmo_sec_flags_from_bfd_flags
2501 (bfd_get_section_flags (abfd
, sec
)));
2502 mmo_write_octa (abfd
, sec
->_raw_size
);
2503 mmo_write_octa (abfd
, bfd_get_section_vma (abfd
, sec
));
2505 /* Writing a LOP_LOC ends the LOP_SPEC data, and makes data actually
2507 if (bfd_get_section_flags (abfd
, sec
) & SEC_LOAD
)
2509 abfd
->tdata
.mmo_data
->have_error
== false
2510 && mmo_write_loc_chunk_list (abfd
,
2511 ((struct mmo_section_data_struct
*)
2512 (sec
->used_by_bfd
))->head
);
2514 abfd
->tdata
.mmo_data
->have_error
== false
2515 && mmo_write_chunk_list (abfd
,
2516 ((struct mmo_section_data_struct
*)
2517 (sec
->used_by_bfd
))->head
);
2522 /* We save up all data before output. */
2525 mmo_set_section_contents (abfd
, sec
, location
, offset
, bytes_to_do
)
2526 bfd
*abfd ATTRIBUTE_UNUSED
;
2530 bfd_size_type bytes_to_do
;
2532 /* Iterate over diminishing chunk sizes, copying contents. */
2535 /* A minor song-and-dance to make sure we're not bitten by the
2536 distant possibility of the cast from bfd_vma to int making the
2537 chunk zero-sized. */
2539 = (int) bytes_to_do
!= 0 ? bytes_to_do
: MMO_SEC_CONTENTS_CHUNK_SIZE
;
2543 loc
= mmo_get_loc (sec
, sec
->vma
+ offset
, chunk_size
);
2544 while (loc
== NULL
&& (chunk_size
/= 2) != 0);
2546 if (chunk_size
== 0)
2549 memcpy (loc
, location
, chunk_size
);
2551 location
+= chunk_size
;
2552 bytes_to_do
-= chunk_size
;
2553 offset
+= chunk_size
;
2558 /* Add a symbol to a trie-tree. */
2561 mmo_internal_add_3_sym (abfd
, rootp
, symp
)
2563 struct mmo_symbol_trie
*rootp
;
2564 CONST
struct mmo_symbol
*symp
;
2566 CONST
char *name
= symp
->name
;
2567 struct mmo_symbol_trie
*trie
= rootp
;
2568 struct mmo_symbol_trie
**triep
= NULL
;
2570 while (*name
&& trie
!= NULL
)
2572 if (*name
< trie
->symchar
)
2574 triep
= &trie
->left
;
2577 else if (*name
> trie
->symchar
)
2579 triep
= &trie
->right
;
2582 else if (*name
== trie
->symchar
)
2584 triep
= &trie
->middle
;
2587 /* Make sure "trie" points to where we should fill in the
2588 current symbol whenever we've iterated through "name". We
2589 would lose the right position if we encounter "foobar" then
2592 trie
= trie
->middle
;
2598 /* Create middle branches for the rest of the characters. */
2599 trie
= bfd_zalloc (abfd
, sizeof (struct mmo_symbol_trie
));
2601 trie
->symchar
= *name
++;
2602 triep
= &trie
->middle
;
2605 /* We discover a duplicate symbol rather late in the process, but still;
2606 we discover it and bail out. */
2607 if (trie
->sym
.name
!= NULL
)
2609 (*_bfd_error_handler
)
2610 (_("%s: invalid symbol table: duplicate symbol `%s'\n"),
2611 bfd_get_filename (abfd
), trie
->sym
.name
);
2612 bfd_set_error (bfd_error_bad_value
);
2616 memcpy (&trie
->sym
, symp
, sizeof *symp
);
2620 /* Find out the length of the serialized version of a trie in bytes. */
2623 mmo_internal_3_length (abfd
, trie
)
2625 struct mmo_symbol_trie
*trie
;
2627 /* First, one for the control byte. */
2628 unsigned int length
= 1;
2633 /* Add in the recursion to the left. */
2634 length
+= mmo_internal_3_length (abfd
, trie
->left
);
2636 /* Add in the middle trie and the character. */
2637 length
+= 1 + mmo_internal_3_length (abfd
, trie
->middle
);
2639 /* Add in the recursion to the right. */
2640 length
+= mmo_internal_3_length (abfd
, trie
->right
);
2642 /* Add in bytes for the symbol (if this is an endnode). */
2643 if (trie
->sym
.name
!= NULL
)
2645 unsigned int serno
= trie
->sym
.serno
;
2647 /* First what it takes to encode the value. */
2648 if (trie
->sym
.sym_type
== mmo_reg_sym
)
2650 else if (trie
->sym
.sym_type
== mmo_undef_sym
)
2654 bfd_vma value
= trie
->sym
.value
;
2656 /* Coded in one to eight following bytes. */
2657 if (trie
->sym
.sym_type
== mmo_data_sym
)
2658 value
-= (bfd_vma
) 0x20 << 56;
2668 /* Find out what it takes to encode the serial number. */
2680 /* Helper function for outputting the serial number of a symbol, output as
2681 a variant of leb128 (see dwarf2 documentation) which could be called
2682 beb128. Using a helper function and recursion simplifies debugging. */
2685 mmo_beb128_out (abfd
, serno
, marker
)
2691 mmo_beb128_out (abfd
, serno
>> 7, 0);
2692 mmo_write_byte (abfd
, marker
| (serno
& 0x7f));
2695 /* Serialize a trie. */
2698 mmo_internal_3_dump (abfd
, trie
)
2700 struct mmo_symbol_trie
*trie
;
2702 bfd_byte control
= 0;
2708 control
|= MMO3_LEFT
;
2711 control
|= MMO3_MIDDLE
;
2714 control
|= MMO3_RIGHT
;
2716 if (trie
->sym
.name
!= NULL
)
2718 /* Encode the symbol type and length of value bytes. */
2719 if (trie
->sym
.sym_type
== mmo_reg_sym
)
2720 control
|= MMO3_REGQUAL_BITS
;
2721 else if (trie
->sym
.sym_type
== mmo_undef_sym
)
2722 control
|= MMO3_UNDEF
;
2725 bfd_vma value
= trie
->sym
.value
;
2727 /* Coded in 1..8 following bytes. */
2728 if (trie
->sym
.sym_type
== mmo_data_sym
)
2730 control
|= MMO3_DATA
;
2731 value
-= (bfd_vma
) 0x20 << 56;
2743 /* The control byte is output before recursing. */
2744 mmo_write_byte (abfd
, control
);
2746 mmo_internal_3_dump (abfd
, trie
->left
);
2748 if (control
& MMO3_SYMBITS
)
2750 mmo_write_byte (abfd
, trie
->symchar
);
2752 if (trie
->sym
.name
!= NULL
)
2754 if (trie
->sym
.sym_type
== mmo_reg_sym
)
2755 mmo_write_byte (abfd
, trie
->sym
.value
);
2756 else if (trie
->sym
.sym_type
== mmo_undef_sym
)
2758 mmo_write_byte (abfd
, 0);
2759 mmo_write_byte (abfd
, 0);
2763 bfd_vma value
= trie
->sym
.value
;
2765 bfd_byte byte_n
= control
& 15;
2767 /* Coded in 1..8 following bytes. Note that the value is
2768 shifted out big-endian. */
2769 if (trie
->sym
.sym_type
== mmo_data_sym
)
2771 value
-= (bfd_vma
) 0x20 << 56;
2777 mmo_write_byte (abfd
, (value
>> ((byte_n
- 1) * 8)) & 0xff);
2780 while (byte_n
!= 0);
2783 mmo_beb128_out (abfd
, trie
->sym
.serno
, 128);
2785 mmo_internal_3_dump (abfd
, trie
->middle
);
2787 mmo_internal_3_dump (abfd
, trie
->right
);
2790 /* Write symbols, either in mmo format or hidden in a lop_spec 80 section.
2791 Write the lop_end terminator also. */
2794 mmo_write_symbols_and_terminator (abfd
)
2797 int count
= bfd_get_symcount (abfd
);
2798 asymbol
*fakemain
[2];
2801 struct mmo_symbol_trie root
;
2806 /* Create a symbol for "Main". */
2807 asymbol
*mainsym
= bfd_make_empty_symbol (abfd
);
2809 mainsym
->flags
= BSF_GLOBAL
;
2810 mainsym
->value
= bfd_get_start_address (abfd
);
2811 mainsym
->name
= MMIX_START_SYMBOL_NAME
;
2812 mainsym
->section
= bfd_abs_section_ptr
;
2813 fakemain
[0] = mainsym
;
2816 memset (&root
, 0, sizeof (root
));
2818 /* Make all symbols take a left turn. */
2819 root
.symchar
= 0xff;
2821 /* There must always be a ":Main", so we'll add one
2822 if there are no symbols. */
2829 table
= bfd_get_outsymbols (abfd
);
2831 for (i
= 0; i
< count
&& table
[i
] != NULL
; i
++)
2833 asymbol
*s
= table
[i
];
2835 /* It's not enough to consult bfd_is_local_label, since it does not
2836 mean "local" in the sense of linkable-and-observable-after-link.
2837 Let's just check the BSF_GLOBAL flag.
2839 Also, don't export symbols with characters not in the allowed set. */
2840 if ((s
->flags
& (BSF_DEBUGGING
|BSF_GLOBAL
)) == BSF_GLOBAL
2842 valid_mmo_symbol_character_set
) == strlen (s
->name
))
2844 struct mmo_symbol sym
;
2845 memset (&sym
, 0, sizeof (sym
));
2850 + s
->section
->output_section
->vma
2851 + s
->section
->output_offset
;
2853 if (bfd_is_und_section (s
->section
))
2854 sym
.sym_type
= mmo_undef_sym
;
2855 else if (strcmp (s
->section
->name
, MMO_DATA_SECTION_NAME
) == 0
2856 /* The encoding of data symbols require that the "rest"
2857 of the value fits in 6 bytes, so the upper two bytes
2858 must be 0x2000. All other symbols get to be the
2860 && (sym
.value
>> 48) == 0x2000)
2861 sym
.sym_type
= mmo_data_sym
;
2862 else if (strcmp (s
->section
->name
, MMIX_REG_SECTION_NAME
) == 0)
2863 sym
.sym_type
= mmo_reg_sym
;
2864 else if (strcmp (s
->section
->name
,
2865 MMIX_REG_CONTENTS_SECTION_NAME
) == 0)
2867 sym
.sym_type
= mmo_reg_sym
;
2871 sym
.sym_type
= mmo_abs_sym
;
2873 /* FIXME: We assume the order of the received symbols is an
2874 ordered mapping of the serial numbers. This is not
2875 necessarily true if we e.g. objcopy a mmo file to another and
2876 there are gaps in the numbering. Note sure if this can
2877 happen. Not sure what to do. */
2878 /* Make sure Main has serial number 1; others start at 2. */
2879 if (strcmp (s
->name
, MMIX_START_SYMBOL_NAME
) == 0)
2883 /* Check that the value assigned to :Main is the same as the
2884 entry address. The default linker script asserts this.
2885 This is as good a place as any to check this consistency. */
2886 if (sym
.value
!= bfd_get_start_address (abfd
))
2888 /* Arbitrary buffer to hold the printable representation
2891 char vmas_start
[40];
2892 bfd_vma vma_start
= bfd_get_start_address (abfd
);
2894 sprintf_vma (vmas_main
, s
->value
);
2895 sprintf_vma (vmas_start
, vma_start
);
2897 (*_bfd_error_handler
)
2898 (_("%s: Bad symbol definition: `Main' set to %s rather\
2899 than the start address %s\n"),
2900 bfd_get_filename (abfd
), vmas_main
, vmas_start
);
2901 bfd_set_error (bfd_error_bad_value
);
2906 sym
.serno
= serno
++;
2908 if (! mmo_internal_add_3_sym (abfd
, &root
, &sym
))
2913 /* Change the root node to be a ":"-prefix. */
2915 root
.middle
= root
.left
;
2919 /* We have to find out if we can fit the whole symbol table in the mmo
2920 symtab. It would be bad to assume we can always fit it in 262144
2921 bytes. If we can't, just leave the Main symbol. */
2922 trie_len
= (mmo_internal_3_length (abfd
, &root
) + 3)/4;
2924 if (trie_len
> 0xffff)
2926 /* Test this code by using a lower limit in the test above and check
2927 that the single "Main" symbol is emitted and handled properly.
2928 There's no specific test-case. */
2929 struct mmo_symbol sym
;
2931 (*_bfd_error_handler
)
2932 (_("%s: warning: symbol table too large for mmo, larger than 65535\
2933 32-bit words: %d. Only `Main' will be emitted.\n"),
2934 bfd_get_filename (abfd
), trie_len
);
2936 memset (&sym
, 0, sizeof (sym
));
2937 sym
.sym_type
= mmo_abs_sym
;
2938 sym
.name
= MMIX_START_SYMBOL_NAME
;
2940 sym
.value
= bfd_get_start_address (abfd
);
2942 /* Then patch up a symbol table to be just the ":Main" symbol. */
2943 memset (&root
, 0, sizeof (root
));
2944 root
.left
= root
.middle
;
2945 root
.symchar
= 0xff;
2949 if (! mmo_internal_add_3_sym (abfd
, &root
, &sym
))
2953 root
.middle
= root
.left
;
2957 trie_len
= (mmo_internal_3_length (abfd
, &root
) + 3)/4;
2960 /* Reset the written-bytes counter. */
2961 abfd
->tdata
.mmo_data
->byte_no
= 0;
2963 /* Put out the lop_stab mark. */
2964 bfd_put_32 (abfd
, (LOP
<< 24) | (LOP_STAB
<< 16), buf
);
2965 if (bfd_bwrite (buf
, 4, abfd
) != 4)
2968 /* Dump out symbols. */
2969 mmo_internal_3_dump (abfd
, &root
);
2971 if (trie_len
!= (abfd
->tdata
.mmo_data
->byte_no
+ 3)/4)
2973 /* I haven't seen this trig. It seems no use claiming this case
2974 isn't debugged and abort if we get here. Instead emit a
2975 diagnostic and fail "normally". */
2976 (*_bfd_error_handler
)
2977 (_("%s: internal error, symbol table changed size from %d to %d\
2979 bfd_get_filename (abfd
), trie_len
,
2980 (abfd
->tdata
.mmo_data
->byte_no
+ 3)/4);
2981 bfd_set_error (bfd_error_bad_value
);
2985 /* Dump out remaining bytes in the buffer and handle I/O errors by
2986 propagating errors. */
2987 if ((abfd
->tdata
.mmo_data
->byte_no
% 4) != 0
2988 || abfd
->tdata
.mmo_data
->have_error
)
2990 memset (abfd
->tdata
.mmo_data
->buf
+ (abfd
->tdata
.mmo_data
->byte_no
% 4),
2991 0, 4 - (abfd
->tdata
.mmo_data
->byte_no
% 4));
2993 if (abfd
->tdata
.mmo_data
->have_error
2994 || bfd_bwrite (abfd
->tdata
.mmo_data
->buf
, 4, abfd
) != 4)
2998 bfd_put_32 (abfd
, (LOP
<< 24) | (LOP_END
<< 16) | trie_len
, buf
);
2999 return bfd_bwrite (buf
, 4, abfd
) == 4;
3002 /* Write section unless it is the register contents section. For that, we
3003 instead store the section in the supplied pointer. This function is
3004 used through bfd_map_over_sections. */
3007 mmo_write_section_unless_reg_contents (abfd
, sec
, p
)
3012 struct mmo_write_sec_info
*infop
= (struct mmo_write_sec_info
*) p
;
3014 if (infop
->retval
== false)
3017 if (strcmp (sec
->name
, MMIX_REG_CONTENTS_SECTION_NAME
) == 0)
3019 infop
->reg_section
= sec
;
3023 /* Exclude the convenience register section. */
3024 if (strcmp (sec
->name
, MMIX_REG_SECTION_NAME
) == 0)
3026 if (bfd_get_section_flags (abfd
, sec
) & SEC_HAS_CONTENTS
)
3028 /* Make sure it hasn't got contents. It seems impossible to
3029 make it carry contents, so we don't have a test-case for
3031 (*_bfd_error_handler
)
3032 (_("%s: internal error, internal register section %s had\
3034 bfd_get_filename (abfd
), sec
->name
);
3035 bfd_set_error (bfd_error_bad_value
);
3036 infop
->retval
= false;
3043 infop
->retval
= mmo_internal_write_section (abfd
, sec
);
3046 /* Do the actual output of a file. Assumes mmo_set_section_contents is
3050 mmo_write_object_contents (abfd
)
3053 struct mmo_write_sec_info wsecinfo
;
3055 /* First, there are a few words of preamble. */
3056 if (! mmo_internal_write_header (abfd
))
3059 wsecinfo
.reg_section
= NULL
;
3060 wsecinfo
.retval
= true;
3062 bfd_map_over_sections (abfd
, mmo_write_section_unless_reg_contents
,
3065 if (wsecinfo
.retval
== false)
3068 if (wsecinfo
.reg_section
!= NULL
)
3070 asection
*sec
= wsecinfo
.reg_section
;
3071 unsigned int z
= (unsigned int) (sec
->vma
/ 8);
3073 /* Registers 0..31 must not be global. Do sanity check on the "vma"
3074 of the register contents section and check that it corresponds to
3075 the length of the section. */
3076 if (z
< 32 || z
>= 255 || (sec
->vma
& 7) != 0
3077 || sec
->vma
!= 256 * 8 - sec
->_raw_size
- 8)
3079 bfd_set_error (bfd_error_bad_value
);
3081 if (sec
->_raw_size
== 0)
3082 /* There must always be at least one such register. */
3083 (*_bfd_error_handler
)
3084 (_("%s: no initialized registers; section length 0\n"),
3085 bfd_get_filename (abfd
));
3086 else if (sec
->vma
> (256 - 32) * 8)
3087 /* Provide better error message for the case of too many
3088 global registers. */
3089 (*_bfd_error_handler
)
3090 (_("%s: too many initialized registers; section length %ld\n"),
3091 bfd_get_filename (abfd
),
3092 (long) sec
->_raw_size
);
3094 (*_bfd_error_handler
)
3095 (_("%s: invalid start address for initialized registers of\
3096 length %ld: 0x%lx%08lx\n"),
3097 bfd_get_filename (abfd
),
3098 (long) sec
->_raw_size
,
3099 (unsigned long) (sec
->vma
>> 32), (unsigned long) (sec
->vma
));
3104 if (! mmo_internal_write_post (abfd
, z
, sec
))
3108 if (! mmo_internal_write_post (abfd
, 255, NULL
))
3111 return mmo_write_symbols_and_terminator (abfd
);
3114 /* Return the size of a NULL pointer, so we support linking in an mmo
3118 mmo_get_reloc_upper_bound (abfd
, sec
)
3119 bfd
*abfd ATTRIBUTE_UNUSED
;
3120 asection
*sec ATTRIBUTE_UNUSED
;
3122 return sizeof (PTR
);
3125 /* Similarly canonicalize relocs to empty, filling in the terminating NULL
3129 mmo_canonicalize_reloc (abfd
, section
, relptr
, symbols
)
3130 bfd
*abfd ATTRIBUTE_UNUSED
;
3131 sec_ptr section ATTRIBUTE_UNUSED
;
3133 asymbol
**symbols ATTRIBUTE_UNUSED
;
3139 /* If there's anything in particular in a mmo bfd that we want to free,
3140 make this a real function. Only do this if you see major memory
3141 thrashing; zealous free:ing will cause unwanted behavior, especially if
3142 you "free" memory allocated with "bfd_alloc", or even "bfd_release" a
3143 block allocated with "bfd_alloc"; they're really allocated from an
3144 obstack, and we don't know what was allocated there since this
3145 particular allocation. */
3147 #define mmo_close_and_cleanup _bfd_generic_close_and_cleanup
3148 #define mmo_bfd_free_cached_info _bfd_generic_bfd_free_cached_info
3150 /* Perhaps we need to adjust this one; mmo labels (originally) without a
3151 leading ':' might more appropriately be called local. */
3152 #define mmo_bfd_is_local_label_name bfd_generic_is_local_label_name
3154 /* Is this one really used or defined by anyone? */
3155 #define mmo_get_lineno _bfd_nosymbols_get_lineno
3157 /* FIXME: We can do better on this one, if we have a dwarf2 .debug_line
3158 section or if MMO line numbers are implemented. */
3159 #define mmo_find_nearest_line _bfd_nosymbols_find_nearest_line
3160 #define mmo_make_empty_symbol _bfd_generic_make_empty_symbol
3161 #define mmo_bfd_make_debug_symbol _bfd_nosymbols_bfd_make_debug_symbol
3162 #define mmo_read_minisymbols _bfd_generic_read_minisymbols
3163 #define mmo_minisymbol_to_symbol _bfd_generic_minisymbol_to_symbol
3165 #define mmo_get_section_contents_in_window \
3166 _bfd_generic_get_section_contents_in_window
3167 #define mmo_bfd_get_relocated_section_contents \
3168 bfd_generic_get_relocated_section_contents
3169 #define mmo_bfd_gc_sections bfd_generic_gc_sections
3170 #define mmo_bfd_link_hash_table_create _bfd_generic_link_hash_table_create
3171 #define mmo_bfd_link_add_symbols _bfd_generic_link_add_symbols
3172 #define mmo_bfd_final_link _bfd_generic_final_link
3173 #define mmo_bfd_link_split_section _bfd_generic_link_split_section
3175 /* Strictly speaking, only MMIX uses this restricted format, but let's not
3176 stop anybody from shooting themselves in the foot. */
3177 #define mmo_set_arch_mach bfd_default_set_arch_mach
3178 #define mmo_bfd_relax_section bfd_generic_relax_section
3179 #define mmo_bfd_merge_sections bfd_generic_merge_sections
3181 /* objcopy will be upset if we return -1 from bfd_get_reloc_upper_bound by
3182 using BFD_JUMP_TABLE_RELOCS (_bfd_norelocs) rather than 0. FIXME: Most
3183 likely a bug in the _bfd_norelocs definition.
3185 On the other hand, we smuggle in an mmo object (because setting up ELF
3186 is too cumbersome) when linking (from other formats, presumably ELF) to
3187 represent the g255 entry. We need to link that object, so need to say
3188 it has no relocs. Upper bound for the size of the relocation table is
3189 the size of a NULL pointer, and we support "canonicalization" for that
3191 #define mmo_bfd_reloc_type_lookup _bfd_norelocs_bfd_reloc_type_lookup
3193 /* We want to copy time of creation, otherwise we'd use
3194 BFD_JUMP_TABLE_COPY (_bfd_generic). */
3195 #define mmo_bfd_merge_private_bfd_data _bfd_generic_bfd_merge_private_bfd_data
3196 #define mmo_bfd_copy_private_section_data _bfd_generic_bfd_copy_private_section_data
3197 #define mmo_bfd_copy_private_symbol_data _bfd_generic_bfd_copy_private_symbol_data
3198 #define mmo_bfd_set_private_flags _bfd_generic_bfd_set_private_flags
3199 #define mmo_bfd_print_private_bfd_data _bfd_generic_bfd_print_private_bfd_data
3201 CONST bfd_target bfd_mmo_vec
=
3204 bfd_target_mmo_flavour
,
3205 BFD_ENDIAN_BIG
, /* target byte order */
3206 BFD_ENDIAN_BIG
, /* target headers byte order */
3208 /* FIXME: Might need adjustments. */
3209 (HAS_RELOC
| EXEC_P
| /* object flags */
3210 HAS_LINENO
| HAS_DEBUG
|
3211 HAS_SYMS
| HAS_LOCALS
| WP_TEXT
),
3213 /* FIXME: Might need adjustments. */
3214 (SEC_CODE
| SEC_DATA
| SEC_HAS_CONTENTS
| SEC_ALLOC
| SEC_LOAD
3215 | SEC_READONLY
| SEC_EXCLUDE
| SEC_DEBUGGING
| SEC_IN_MEMORY
),
3217 0, /* leading underscore */
3218 ' ', /* ar_pad_char */
3219 16, /* ar_max_namelen */
3220 bfd_getb64
, bfd_getb_signed_64
, bfd_putb64
,
3221 bfd_getb32
, bfd_getb_signed_32
, bfd_putb32
,
3222 bfd_getb16
, bfd_getb_signed_16
, bfd_putb16
, /* data */
3223 bfd_getb64
, bfd_getb_signed_64
, bfd_putb64
,
3224 bfd_getb32
, bfd_getb_signed_32
, bfd_putb32
,
3225 bfd_getb16
, bfd_getb_signed_16
, bfd_putb16
, /* hdrs */
3229 mmo_object_p
, /* bfd_check_format */
3239 { /* bfd_write_contents */
3241 mmo_write_object_contents
,
3246 BFD_JUMP_TABLE_GENERIC (mmo
),
3247 BFD_JUMP_TABLE_COPY (mmo
),
3248 BFD_JUMP_TABLE_CORE (_bfd_nocore
),
3249 BFD_JUMP_TABLE_ARCHIVE (_bfd_noarchive
),
3250 BFD_JUMP_TABLE_SYMBOLS (mmo
),
3251 /* We have to provide a valid method for getting relocs, returning zero,
3252 so we can't say BFD_JUMP_TABLE_RELOCS (_bfd_norelocs). */
3253 BFD_JUMP_TABLE_RELOCS (mmo
),
3254 BFD_JUMP_TABLE_WRITE (mmo
),
3255 BFD_JUMP_TABLE_LINK (mmo
),
3256 BFD_JUMP_TABLE_DYNAMIC (_bfd_nodynamic
),