1 /* BFD back-end for mmo objects (MMIX-specific object-format).
2 Copyright 2001, 2002, 2003, 2004
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"
220 #define LOP_QUOTE_NEXT ((LOP << 24) | (LOP_QUOTE << 16) | 1)
221 #define SPEC_DATA_SECTION 80
222 #define LOP_SPEC_SECTION \
223 ((LOP << 24) | (LOP_SPEC << 16) | SPEC_DATA_SECTION)
225 /* Must be a power of two. If you change this to be >= 64k, you need a
226 new test-case; the ld test b-loc64k.d touches chunk-size problem areas. */
227 #define MMO_SEC_CONTENTS_CHUNK_SIZE (1 << 15)
229 /* An arbitrary number for the maximum length section name size. */
230 #define MAX_SECTION_NAME_SIZE (1024 * 1024)
232 /* A quite arbitrary number for the maximum length section size. */
233 #define MAX_ARTIFICIAL_SECTION_SIZE (1024 * 1024 * 1024)
235 #define MMO3_WCHAR 0x80
236 #define MMO3_LEFT 0x40
237 #define MMO3_MIDDLE 0x20
238 #define MMO3_RIGHT 0x10
239 #define MMO3_TYPEBITS 0xf
240 #define MMO3_REGQUAL_BITS 0xf
243 #define MMO3_SYMBITS 0x2f
245 /* Put these everywhere in new code. */
246 #define FATAL_DEBUG \
247 _bfd_abort (__FILE__, __LINE__, \
248 "Internal: Non-debugged code (test-case missing)")
250 #define BAD_CASE(x) \
251 _bfd_abort (__FILE__, __LINE__, \
254 enum mmo_sym_type { mmo_reg_sym, mmo_undef_sym, mmo_data_sym, mmo_abs_sym};
256 /* When scanning the mmo file, a linked list of mmo_symbol
257 structures is built to represent the symbol table (if there is
262 struct mmo_symbol *next;
265 enum mmo_sym_type sym_type;
269 struct mmo_data_list_struct
271 struct mmo_data_list_struct *next;
274 bfd_size_type allocated_size;
278 typedef struct mmo_data_list_struct mmo_data_list_type;
280 struct mmo_symbol_trie
282 struct mmo_symbol_trie *left;
283 struct mmo_symbol_trie *right;
284 struct mmo_symbol_trie *middle;
288 /* A zero name means there's nothing here. */
289 struct mmo_symbol sym;
292 /* The mmo tdata information. */
294 struct mmo_data_struct
296 struct mmo_symbol *symbols;
297 struct mmo_symbol *symtail;
300 /* File representation of time (NULL) when this file was created. */
303 /* When we're reading bytes recursively, check this occasionally.
304 Also holds write errors. */
305 bfd_boolean have_error;
307 /* Max symbol length that may appear in the lop_stab table. Note that
308 this table might just hold a subset of symbols for not-really large
309 programs, as it can only be 65536 * 4 bytes large. */
310 int max_symbol_length;
312 /* Here's the symbol we build in lop_stab. */
313 char *lop_stab_symbol;
315 /* Index into lop_stab_symbol for the next character when parsing the
316 symbol information. */
319 /* When creating arbitrary sections, we need to count section numbers. */
322 /* When writing or reading byte-wise, we need to count the bytes
323 within a 32-bit word. */
326 /* We also need a buffer to hold the bytes we count reading or writing. */
330 typedef struct mmo_data_struct tdata_type;
332 struct mmo_section_data_struct
334 mmo_data_list_type *head;
335 mmo_data_list_type *tail;
338 #define mmo_section_data(sec) \
339 ((struct mmo_section_data_struct *) (sec)->used_by_bfd)
341 /* These structures are used in bfd_map_over_sections constructs. */
343 /* Used when writing out sections; all but the register contents section
344 which is stored in reg_section. */
345 struct mmo_write_sec_info
347 asection *reg_section;
351 /* Used when trying to find a section corresponding to addr. */
352 struct mmo_find_sec_info
358 static bfd_boolean mmo_bfd_copy_private_bfd_data
359 PARAMS ((bfd *, bfd *));
360 static void mmo_write_section_unless_reg_contents
361 PARAMS ((bfd *, asection *, PTR));
362 static void mmo_find_sec_w_addr
363 PARAMS ((bfd *, asection *, PTR));
364 static void mmo_find_sec_w_addr_grow
365 PARAMS ((bfd *, asection *, PTR));
366 static asection *mmo_make_section
367 PARAMS ((bfd *, const char *));
368 static void mmo_get_symbol_info
369 PARAMS ((bfd *, asymbol *, symbol_info *));
370 static void mmo_print_symbol
371 PARAMS ((bfd *, PTR, asymbol *, bfd_print_symbol_type));
374 static bfd_boolean mmo_mkobject
376 static bfd_boolean mmo_scan
378 static asection *mmo_decide_section
379 PARAMS ((bfd *, bfd_vma));
380 static asection *mmo_get_generic_spec_data_section
381 PARAMS ((bfd *, int));
382 static asection *mmo_get_spec_section
383 PARAMS ((bfd *, int));
384 static INLINE bfd_byte *mmo_get_loc
385 PARAMS ((asection *, bfd_vma, int));
386 static void mmo_xore_64
387 PARAMS ((asection *, bfd_vma vma, bfd_vma value));
388 static void mmo_xore_32
389 PARAMS ((asection *, bfd_vma vma, unsigned int));
390 static void mmo_xore_16
391 PARAMS ((asection *, bfd_vma vma, unsigned int));
392 static const bfd_target *mmo_object_p
394 static void mmo_map_set_sizes
395 PARAMS ((bfd *, asection *, PTR));
396 static bfd_boolean mmo_get_symbols
398 static bfd_boolean mmo_create_symbol
399 PARAMS ((bfd *, const char *, bfd_vma, enum mmo_sym_type, unsigned int));
400 static bfd_boolean mmo_get_section_contents
401 PARAMS ((bfd *, asection *, PTR, file_ptr, bfd_size_type));
402 static long mmo_get_symtab_upper_bound
404 static long mmo_canonicalize_symtab
405 PARAMS ((bfd *, asymbol **));
406 static void mmo_get_symbol_info
407 PARAMS ((bfd *, asymbol *, symbol_info *));
408 static void mmo_print_symbol
409 PARAMS ((bfd *, PTR, asymbol *, bfd_print_symbol_type));
410 static bfd_boolean mmo_set_section_contents
411 PARAMS ((bfd *, sec_ptr, const PTR, file_ptr, bfd_size_type));
412 static int mmo_sizeof_headers
413 PARAMS ((bfd *, bfd_boolean));
414 static long mmo_get_reloc_upper_bound
415 PARAMS ((bfd *, asection *));
417 static bfd_boolean mmo_internal_write_header
419 static bfd_boolean mmo_internal_write_post
420 PARAMS ((bfd *, int, asection *));
421 static bfd_boolean mmo_internal_add_3_sym
422 PARAMS ((bfd *, struct mmo_symbol_trie *, const struct mmo_symbol *));
423 static unsigned int mmo_internal_3_length
424 PARAMS ((bfd *, struct mmo_symbol_trie *));
425 static void mmo_internal_3_dump
426 PARAMS ((bfd *, struct mmo_symbol_trie *));
427 static void mmo_beb128_out
428 PARAMS ((bfd *, int, int));
429 static bfd_boolean mmo_internal_write_section
430 PARAMS ((bfd *, asection *));
431 static void mmo_write_tetra
432 PARAMS ((bfd *, unsigned int));
433 static void mmo_write_tetra_raw
434 PARAMS ((bfd *, unsigned int));
435 static void mmo_write_octa
436 PARAMS ((bfd *, bfd_vma));
437 static void mmo_write_octa_raw
438 PARAMS ((bfd *, bfd_vma));
439 static bfd_boolean mmo_write_chunk
440 PARAMS ((bfd *, const bfd_byte *, unsigned int));
441 static bfd_boolean mmo_flush_chunk
443 static bfd_boolean mmo_write_loc_chunk
444 PARAMS ((bfd *, bfd_vma, const bfd_byte *, unsigned int, bfd_vma *));
445 static bfd_boolean mmo_write_chunk_list
446 PARAMS ((bfd *, mmo_data_list_type *));
447 static bfd_boolean mmo_write_loc_chunk_list
448 PARAMS ((bfd *, mmo_data_list_type *));
449 static bfd_boolean mmo_write_symbols_and_terminator
451 static flagword mmo_sec_flags_from_bfd_flags
453 static flagword bfd_sec_flags_from_mmo_flags
455 static bfd_byte mmo_get_byte
457 static void mmo_write_byte
458 PARAMS ((bfd *, bfd_byte));
459 static bfd_boolean mmo_new_section_hook
460 PARAMS ((bfd *, asection *));
461 static int mmo_sort_mmo_symbols
462 PARAMS ((const PTR, const PTR));
463 static bfd_boolean mmo_write_object_contents
465 static long mmo_canonicalize_reloc
466 PARAMS ((bfd *, sec_ptr, arelent **, asymbol **));
468 /* Global "const" variables initialized once. Must not depend on
469 particular input or caller; put such things into the bfd or elsewhere.
470 Look ma, no static per-invocation data! */
473 char valid_mmo_symbol_character_set[/* A-Z a-z (we assume consecutive
474 codes; sorry EBCDIC:ers!). */
475 + 'Z' - 'A' + 1 + 'z' - 'a' + 1
480 /* Codes higher than 126. */
486 /* Get section SECNAME or create one if it doesn't exist. When creating
487 one, new memory for the name is allocated. */
490 mmo_make_section (abfd, secname)
494 asection *sec = bfd_get_section_by_name (abfd, secname);
498 char *newsecname = strdup (secname);
500 if (newsecname == NULL)
502 (*_bfd_error_handler)
503 (_("%s: No core to allocate section name %s\n"),
504 bfd_get_filename (abfd), secname);
505 bfd_set_error (bfd_error_system_call);
508 sec = bfd_make_section (abfd, newsecname);
514 /* Nothing to do, but keep as a placeholder if we need it.
515 Note that state that might differ between bfd:s must not be initialized
516 here, nor must it be static. Add it to tdata information instead. */
521 static bfd_boolean inited = FALSE;
524 static const char letters[]
525 = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789:_";
531 /* Fill in the set of valid symbol characters. */
532 strcpy (valid_mmo_symbol_character_set, letters);
533 i = strlen (letters);
535 for (j = 126; j < 256; j++)
536 valid_mmo_symbol_character_set[i++] = j;
539 /* Check whether an existing file is an mmo file. */
541 static const bfd_target *
550 if (bfd_stat (abfd, &statbuf) < 0
551 || bfd_seek (abfd, (file_ptr) 0, SEEK_SET) != 0
552 || bfd_bread (b, 4, abfd) != 4)
555 /* All mmo files are a multiple of four bytes long.
556 Only recognize version one. */
557 if ((statbuf.st_size % 4) != 0
558 || b[0] != LOP || b[1] != LOP_PRE || b[2] != 1)
561 /* Get the last 32-bit word. */
562 if (bfd_seek (abfd, (file_ptr) statbuf.st_size - 4, SEEK_SET) != 0
563 || bfd_bread (b, 4, abfd) != 4)
566 /* Check if the file ends in a lop_end lopcode. */
567 if (b[0] != LOP || b[1] != LOP_END || ! mmo_mkobject (abfd))
570 /* Compute an upper bound on the max symbol length. Not really
571 important as all of the symbol information can only be 256k. */
572 abfd->tdata.mmo_data->max_symbol_length = (b[2] * 256 + b[3]) * 4;
573 abfd->tdata.mmo_data->lop_stab_symbol
574 = bfd_malloc (abfd->tdata.mmo_data->max_symbol_length + 1);
576 if (abfd->tdata.mmo_data->lop_stab_symbol == NULL)
578 (*_bfd_error_handler)
579 (_("%s: No core to allocate a symbol %d bytes long\n"),
580 bfd_get_filename (abfd), abfd->tdata.mmo_data->max_symbol_length);
584 /* Read in everything. */
585 if (! mmo_scan (abfd))
586 goto bad_format_free;
588 if (abfd->symcount > 0)
589 abfd->flags |= HAS_SYMS;
591 /* You'll have to tweak this if you want to use this format for other
592 arches (not recommended due to its small-size limitations). Look at
593 the ELF format for how to make it target-generic. */
594 if (! bfd_default_set_arch_mach (abfd, bfd_arch_mmix, 0))
595 goto bad_format_free;
600 free (abfd->tdata.mmo_data->lop_stab_symbol);
602 bfd_set_error (bfd_error_wrong_format);
607 /* Set up the mmo tdata information. */
615 if (abfd->tdata.mmo_data == NULL)
619 /* All fields are zero-initialized, so we don't have to explicitly
621 tdata_type *tdata = (tdata_type *) bfd_zmalloc (sizeof (tdata_type));
625 created = time (NULL);
626 bfd_put_32 (abfd, created, tdata->created);
628 abfd->tdata.mmo_data = tdata;
635 mmo_bfd_copy_private_bfd_data (ibfd, obfd)
639 if (bfd_get_flavour (ibfd) != bfd_target_mmo_flavour
640 || bfd_get_flavour (obfd) != bfd_target_mmo_flavour)
643 /* Copy the time the copied-from file was created. If people want the
644 time the file was last *modified*, they have that in the normal file
646 memcpy (obfd->tdata.mmo_data->created, ibfd->tdata.mmo_data->created,
647 sizeof (obfd->tdata.mmo_data->created));
651 /* Helper functions for mmo_decide_section, used through
652 bfd_map_over_sections. */
655 mmo_find_sec_w_addr (abfd, sec, p)
656 bfd *abfd ATTRIBUTE_UNUSED;
660 struct mmo_find_sec_info *infop = (struct mmo_find_sec_info *) p;
661 bfd_vma vma = bfd_get_section_vma (abfd, sec);
663 /* Ignore sections that aren't loaded. */
664 if ((bfd_get_section_flags (abfd, sec) & (SEC_LOAD | SEC_ALLOC))
665 != (SEC_LOAD | SEC_ALLOC))
668 if (infop->addr >= vma && infop->addr < vma + sec->size)
673 mmo_find_sec_w_addr_grow (abfd, sec, p)
674 bfd *abfd ATTRIBUTE_UNUSED;
678 struct mmo_find_sec_info *infop = (struct mmo_find_sec_info *) p;
679 bfd_vma vma = bfd_get_section_vma (abfd, sec);
681 /* Ignore sections that aren't loaded. */
682 if ((bfd_get_section_flags (abfd, sec) & (SEC_LOAD | SEC_ALLOC))
683 != (SEC_LOAD | SEC_ALLOC))
686 if (infop->addr >= vma && infop->addr < vma + MAX_ARTIFICIAL_SECTION_SIZE)
690 /* Find a section that corresponds to a VMA. Automatically create .text
691 or .data and set current section to it, depending on what vma. If we
692 can't deduce a section, make one up as ".MMIX.sec.N", where N is an
693 increasing number. */
696 mmo_decide_section (abfd, vma)
700 asection *sec = NULL;
701 char sec_name[sizeof (".MMIX.sec.") + 20];
702 struct mmo_find_sec_info info;
707 /* First see if there's a section that would match exactly. */
708 bfd_map_over_sections (abfd, mmo_find_sec_w_addr, &info);
710 if (info.sec != NULL)
713 /* If there's no such section, try and expand one of the existing ones,
714 up to a limit. Make sure we have .text and .data before we try that;
715 create them corresponding to expected addresses and set flags to make
716 them match the "loaded and with contents" expectation. */
717 if ((vma >> 56) == 0)
719 sec = bfd_make_section_old_way (abfd, MMO_TEXT_SECTION_NAME);
724 if (! sec->user_set_vma)
725 bfd_set_section_vma (abfd, sec, vma);
726 if (! bfd_set_section_flags (abfd, sec,
727 bfd_get_section_flags (abfd, sec)
728 | SEC_CODE | SEC_LOAD | SEC_ALLOC))
731 else if ((vma >> 56) == 0x20)
733 sec = bfd_make_section_old_way (abfd, MMO_DATA_SECTION_NAME);
738 if (! sec->user_set_vma)
739 bfd_set_section_vma (abfd, sec, vma);
740 if (! bfd_set_section_flags (abfd, sec,
741 bfd_get_section_flags (abfd, sec)
742 | SEC_LOAD | SEC_ALLOC))
746 bfd_map_over_sections (abfd, mmo_find_sec_w_addr_grow, &info);
748 if (info.sec != NULL)
751 /* If there's still no suitable section, make a new one. */
752 sprintf (sec_name, ".MMIX.sec.%d", abfd->tdata.mmo_data->sec_no++);
753 sec = mmo_make_section (abfd, sec_name);
754 if (! sec->user_set_vma)
755 bfd_set_section_vma (abfd, sec, vma);
757 if (! bfd_set_section_flags (abfd, sec,
758 bfd_get_section_flags (abfd, sec)
759 | SEC_LOAD | SEC_ALLOC))
764 /* Xor in a 64-bit value VALUE at VMA. */
767 mmo_xore_64 (sec, vma, value)
772 bfd_byte *loc = mmo_get_loc (sec, vma, 8);
773 bfd_vma prev = bfd_get_64 (sec->owner, loc);
776 bfd_put_64 (sec->owner, value, loc);
779 /* Xor in a 32-bit value VALUE at VMA. */
782 mmo_xore_32 (sec, vma, value)
787 bfd_byte *loc = mmo_get_loc (sec, vma, 4);
788 unsigned int prev = bfd_get_32 (sec->owner, loc);
791 bfd_put_32 (sec->owner, value, loc);
794 /* Xor in a 16-bit value VALUE at VMA. */
797 mmo_xore_16 (sec, vma, value)
802 bfd_byte *loc = mmo_get_loc (sec, vma, 2);
803 unsigned int prev = bfd_get_16 (sec->owner, loc);
806 bfd_put_16 (sec->owner, value, loc);
809 /* Write a 32-bit word to output file, no lop_quote generated. */
812 mmo_write_tetra_raw (abfd, value)
818 bfd_put_32 (abfd, value, buf);
820 if (bfd_bwrite ((PTR) buf, 4, abfd) != 4)
821 abfd->tdata.mmo_data->have_error = TRUE;
824 /* Write a 32-bit word to output file; lop_quote if necessary. */
827 mmo_write_tetra (abfd, value)
831 if (((value >> 24) & 0xff) == LOP)
832 mmo_write_tetra_raw (abfd, LOP_QUOTE_NEXT);
834 mmo_write_tetra_raw (abfd, value);
837 /* Write a 64-bit word to output file, perhaps with lop_quoting. */
840 mmo_write_octa (abfd, value)
844 mmo_write_tetra (abfd, (unsigned int) (value >> 32));
845 mmo_write_tetra (abfd, (unsigned int) value);
848 /* Write a 64-bit word to output file, without lop_quoting. */
851 mmo_write_octa_raw (abfd, value)
855 mmo_write_tetra_raw (abfd, (unsigned int) (value >> 32));
856 mmo_write_tetra_raw (abfd, (unsigned int) value);
859 /* Write quoted contents. Intended to be called multiple times in
860 sequence, followed by a call to mmo_flush_chunk. */
862 static INLINE bfd_boolean
863 mmo_write_chunk (abfd, loc, len)
868 bfd_boolean retval = TRUE;
870 /* Fill up a tetra from bytes remaining from a previous chunk. */
871 if (abfd->tdata.mmo_data->byte_no != 0)
873 while (abfd->tdata.mmo_data->byte_no < 4 && len != 0)
875 abfd->tdata.mmo_data->buf[abfd->tdata.mmo_data->byte_no++] = *loc++;
879 if (abfd->tdata.mmo_data->byte_no == 4)
881 mmo_write_tetra (abfd,
882 bfd_get_32 (abfd, abfd->tdata.mmo_data->buf));
883 abfd->tdata.mmo_data->byte_no = 0;
890 mmo_write_tetra_raw (abfd, LOP_QUOTE_NEXT);
893 && ! abfd->tdata.mmo_data->have_error
894 && 4 == bfd_bwrite ((PTR) loc, 4, abfd));
902 memcpy (abfd->tdata.mmo_data->buf, loc, len);
903 abfd->tdata.mmo_data->byte_no = len;
907 abfd->tdata.mmo_data->have_error = TRUE;
911 /* Flush remaining bytes, from a previous mmo_write_chunk, zero-padded to
914 static INLINE bfd_boolean
915 mmo_flush_chunk (abfd)
918 if (abfd->tdata.mmo_data->byte_no != 0)
920 memset (abfd->tdata.mmo_data->buf + abfd->tdata.mmo_data->byte_no,
921 0, 4 - abfd->tdata.mmo_data->byte_no);
922 mmo_write_tetra (abfd,
923 bfd_get_32 (abfd, abfd->tdata.mmo_data->buf));
924 abfd->tdata.mmo_data->byte_no = 0;
927 return ! abfd->tdata.mmo_data->have_error;
930 /* Same, but from a list. */
932 static INLINE bfd_boolean
933 mmo_write_chunk_list (abfd, datap)
935 mmo_data_list_type *datap;
937 for (; datap != NULL; datap = datap->next)
938 if (! mmo_write_chunk (abfd, datap->data, datap->size))
941 return mmo_flush_chunk (abfd);
944 /* Write a lop_loc and some contents. A caller needs to call
945 mmo_flush_chunk after calling this function. The location is only
946 output if different than *LAST_VMAP, which is updated after this call. */
949 mmo_write_loc_chunk (abfd, vma, loc, len, last_vmap)
956 /* Find an initial and trailing section of zero tetras; we don't need to
957 write out zeros. FIXME: When we do this, we should emit section size
958 and address specifiers, else objcopy can't always perform an identity
959 translation. Only do this if we *don't* have left-over data from a
960 previous write or the vma of this chunk is *not* the next address,
961 because then data isn't tetrabyte-aligned and we're concatenating to
962 that left-over data. */
964 if (abfd->tdata.mmo_data->byte_no == 0 || vma != *last_vmap)
966 while (len >= 4 && bfd_get_32 (abfd, loc) == 0)
973 while (len >= 4 && bfd_get_32 (abfd, loc + len - 4) == 0)
977 /* Only write out the location if it's different than the one the caller
978 (supposedly) previously handled, accounting for omitted leading zeros. */
979 if (vma != *last_vmap)
981 /* We might be in the middle of a sequence. */
982 mmo_flush_chunk (abfd);
984 /* We always write the location as 64 bits; no use saving bytes
986 mmo_write_tetra_raw (abfd, (LOP << 24) | (LOP_LOC << 16) | 2);
987 mmo_write_octa_raw (abfd, vma);
990 /* Update to reflect end of this chunk, with trailing zeros omitted. */
991 *last_vmap = vma + len;
993 return (! abfd->tdata.mmo_data->have_error
994 && mmo_write_chunk (abfd, loc, len));
997 /* Same, but from a list. */
999 static INLINE bfd_boolean
1000 mmo_write_loc_chunk_list (abfd, datap)
1002 mmo_data_list_type *datap;
1004 /* Get an address different than the address of the first chunk. */
1005 bfd_vma last_vma = datap ? datap->where - 1 : 0;
1007 for (; datap != NULL; datap = datap->next)
1008 if (! mmo_write_loc_chunk (abfd, datap->where, datap->data, datap->size,
1012 return mmo_flush_chunk (abfd);
1015 /* Make a .MMIX.spec_data.N section. */
1018 mmo_get_generic_spec_data_section (abfd, spec_data_number)
1020 int spec_data_number;
1023 char secname[sizeof (MMIX_OTHER_SPEC_SECTION_PREFIX) + 20]
1024 = MMIX_OTHER_SPEC_SECTION_PREFIX;
1026 sprintf (secname + strlen (MMIX_OTHER_SPEC_SECTION_PREFIX),
1027 "%d", spec_data_number);
1029 sec = mmo_make_section (abfd, secname);
1034 /* Make a special section for SPEC_DATA_NUMBER. If it is the one we use
1035 ourselves, parse some of its data to get at the section name. */
1038 mmo_get_spec_section (abfd, spec_data_number)
1040 int spec_data_number;
1045 unsigned int secname_length;
1047 bfd_vma section_length;
1048 bfd_vma section_vma;
1049 mmo_data_list_type *loc;
1053 /* If this isn't the "special" special data, then make a placeholder
1055 if (spec_data_number != SPEC_DATA_SECTION)
1056 return mmo_get_generic_spec_data_section (abfd, spec_data_number);
1058 /* Seek back to this position if there was a format error. */
1059 orig_pos = bfd_tell (abfd);
1061 /* Read the length (in 32-bit words). */
1062 if (bfd_bread (buf, 4, abfd) != 4)
1067 if (buf[1] != LOP_QUOTE)
1070 if (bfd_bread (buf, 4, abfd) != 4)
1074 /* We don't care to keep the name length accurate. It's
1076 secname_length = bfd_get_32 (abfd, buf) * 4;
1078 /* Check section name length for sanity. */
1079 if (secname_length > MAX_SECTION_NAME_SIZE)
1082 /* This should be free'd regardless if a section is created. */
1083 secname = bfd_malloc (secname_length + 1);
1084 secname[secname_length] = 0;
1086 for (i = 0; i < secname_length / 4; i++)
1088 if (bfd_bread (secname + i * 4, 4, abfd) != 4)
1089 goto format_error_free;
1091 if (secname[i * 4] == LOP)
1093 /* A bit of overkill, but we handle char 0x98 in a section name,
1094 and recognize misparsing. */
1095 if (secname[i * 4 + 1] != LOP_QUOTE
1096 || bfd_bread (secname + i * 4, 4, abfd) != 4)
1097 /* Whoops. We thought this was a name, and now we found a
1098 non-lop_quote lopcode before we parsed the whole length of
1099 the name. Signal end-of-file in the same manner. */
1100 goto format_error_free;
1104 /* Get the section flags. */
1105 if (bfd_bread (buf, 4, abfd) != 4
1107 && (buf[1] != LOP_QUOTE || bfd_bread (buf, 4, abfd) != 4)))
1108 goto format_error_free;
1110 flags = bfd_get_32 (abfd, buf);
1112 /* Get the section length. */
1113 if (bfd_bread (buf, 4, abfd) != 4
1115 && (buf[1] != LOP_QUOTE || bfd_bread (buf, 4, abfd) != 4)))
1116 goto format_error_free;
1118 section_length = (bfd_vma) bfd_get_32 (abfd, buf) << 32;
1120 /* That's the first, high-part. Now get the low part. */
1122 if (bfd_bread (buf, 4, abfd) != 4
1124 && (buf[1] != LOP_QUOTE || bfd_bread (buf, 4, abfd) != 4)))
1125 goto format_error_free;
1127 section_length |= (bfd_vma) bfd_get_32 (abfd, buf);
1129 /* Check the section length for sanity. */
1130 if (section_length > MAX_ARTIFICIAL_SECTION_SIZE)
1131 goto format_error_free;
1133 /* Get the section VMA. */
1134 if (bfd_bread (buf, 4, abfd) != 4
1136 && (buf[1] != LOP_QUOTE || bfd_bread (buf, 4, abfd) != 4)))
1137 goto format_error_free;
1139 section_vma = (bfd_vma) bfd_get_32 (abfd, buf) << 32;
1141 /* That's the first, high-part. Now get the low part. */
1142 if (bfd_bread (buf, 4, abfd) != 4
1144 && (buf[1] != LOP_QUOTE || bfd_bread (buf, 4, abfd) != 4)))
1145 goto format_error_free;
1147 section_vma |= (bfd_vma) bfd_get_32 (abfd, buf);
1149 sec = mmo_make_section (abfd, secname);
1154 /* We allocate a buffer here for the advertised size, with head room for
1155 tetrabyte alignment. */
1156 loc = bfd_zmalloc (section_length + 3
1157 + sizeof (struct mmo_data_list_struct));
1161 /* Use a TETRA-rounded size for the allocated buffer; we set the
1162 "visible" section size below. */
1163 loc->size = (section_length + 3) & ~3;
1165 /* Add in the section flags we found to those bfd entered during this
1166 process and set the contents. */
1167 if (! bfd_set_section_flags (abfd, sec,
1168 bfd_sec_flags_from_mmo_flags (flags)
1169 | bfd_get_section_flags (abfd, sec)
1170 | (section_length != 0 ? SEC_HAS_CONTENTS : 0))
1171 || ! bfd_set_section_size (abfd, sec, sec->size + section_length)
1172 /* Set VMA only for the first occurrence. */
1173 || (! sec->user_set_vma
1174 && ! bfd_set_section_vma (abfd, sec, section_vma)))
1176 /* If we get an error for any of the calls above, signal more than
1177 just a format error for the spec section. */
1182 if (mmo_section_data (sec)->tail != NULL)
1183 mmo_section_data (sec)->tail->next = loc;
1185 mmo_section_data (sec)->head = loc;
1186 mmo_section_data (sec)->tail = loc;
1187 loc->where = section_vma;
1194 if (bfd_seek (abfd, orig_pos, SEEK_SET) != 0)
1197 return mmo_get_generic_spec_data_section (abfd, spec_data_number);
1200 /* Read a byte, but read from file in multiples of 32-bit words. */
1208 if (abfd->tdata.mmo_data->byte_no == 0)
1210 if (! abfd->tdata.mmo_data->have_error
1211 && bfd_bread (abfd->tdata.mmo_data->buf, 4, abfd) != 4)
1213 abfd->tdata.mmo_data->have_error = TRUE;
1215 /* A value somewhat safe against tripping on some inconsistency
1216 when mopping up after this error. */
1221 retval = abfd->tdata.mmo_data->buf[abfd->tdata.mmo_data->byte_no];
1222 abfd->tdata.mmo_data->byte_no = (abfd->tdata.mmo_data->byte_no + 1) % 4;
1227 /* Write a byte, in multiples of 32-bit words. */
1230 mmo_write_byte (abfd, value)
1234 abfd->tdata.mmo_data->buf[(abfd->tdata.mmo_data->byte_no++ % 4)] = value;
1235 if ((abfd->tdata.mmo_data->byte_no % 4) == 0)
1237 if (! abfd->tdata.mmo_data->have_error
1238 && bfd_bwrite (abfd->tdata.mmo_data->buf, 4, abfd) != 4)
1239 abfd->tdata.mmo_data->have_error = TRUE;
1243 /* Create a symbol. */
1246 mmo_create_symbol (abfd, symname, addr, sym_type, serno)
1248 const char *symname;
1250 enum mmo_sym_type sym_type;
1253 struct mmo_symbol *n;
1255 n = (struct mmo_symbol *) bfd_alloc (abfd, sizeof (struct mmo_symbol));
1259 n->name = bfd_alloc (abfd, strlen (symname) + 1);
1260 if (n->name == NULL)
1263 strcpy ((PTR) n->name, symname);
1266 n->sym_type = sym_type;
1269 if (abfd->tdata.mmo_data->symbols == NULL)
1270 abfd->tdata.mmo_data->symbols = n;
1272 abfd->tdata.mmo_data->symtail->next = n;
1273 abfd->tdata.mmo_data->symtail = n;
1278 /* Check that :Main equals the last octa of the .MMIX.reg_contents
1279 section, as it's the one place we're sure to pass when reading a mmo
1280 object. For written objects, we do it while setting the symbol
1282 if (strcmp (symname, MMIX_START_SYMBOL_NAME) == 0
1283 && bfd_get_start_address (abfd) != addr)
1285 (*_bfd_error_handler)
1286 (_("%s: invalid mmo file: initialization value for $255 is not `Main'\n"),
1287 bfd_get_filename (abfd));
1288 bfd_set_error (bfd_error_bad_value);
1295 /* Read in symbols. */
1298 mmo_get_symbols (abfd)
1303 Symbol-table, mmo section mapping, File layout, mmo
1307 From mmixal.w (or really, the generated mmixal.tex) in
1308 @url{http://www-cs-faculty.stanford.edu/~knuth/programs/mmix.tar.gz}):
1309 ``Symbols are stored and retrieved by means of a @samp{ternary
1310 search trie}, following ideas of Bentley and Sedgewick. (See
1311 ACM--SIAM Symp.@: on Discrete Algorithms @samp{8} (1997), 360--369;
1312 R.@:Sedgewick, @samp{Algorithms in C} (Reading, Mass.@:
1313 Addison--Wesley, 1998), @samp{15.4}.) Each trie node stores a
1314 character, and there are branches to subtries for the cases where
1315 a given character is less than, equal to, or greater than the
1316 character in the trie. There also is a pointer to a symbol table
1317 entry if a symbol ends at the current node.''
1319 So it's a tree encoded as a stream of bytes. The stream of bytes
1320 acts on a single virtual global symbol, adding and removing
1321 characters and signalling complete symbol points. Here, we read
1322 the stream and create symbols at the completion points.
1324 First, there's a control byte <<m>>. If any of the listed bits
1325 in <<m>> is nonzero, we execute what stands at the right, in
1329 | 0x40 - Traverse left trie.
1330 | (Read a new command byte and recurse.)
1333 | 0x2f - Read the next byte as a character and store it in the
1334 | current character position; increment character position.
1335 | Test the bits of <<m>>:
1338 | 0x80 - The character is 16-bit (so read another byte,
1339 | merge into current character.
1342 | 0xf - We have a complete symbol; parse the type, value
1343 | and serial number and do what should be done
1344 | with a symbol. The type and length information
1345 | is in j = (m & 0xf).
1347 | (MMO3_REGQUAL_BITS)
1348 | j == 0xf: A register variable. The following
1349 | byte tells which register.
1350 | j <= 8: An absolute symbol. Read j bytes as the
1351 | big-endian number the symbol equals.
1352 | A j = 2 with two zero bytes denotes an
1354 | j > 8: As with j <= 8, but add (0x20 << 56)
1355 | to the value in the following j - 8
1358 | Then comes the serial number, as a variant of
1359 | uleb128, but better named ubeb128:
1360 | Read bytes and shift the previous value left 7
1361 | (multiply by 128). Add in the new byte, repeat
1362 | until a byte has bit 7 set. The serial number
1363 | is the computed value minus 128.
1366 | 0x20 - Traverse middle trie. (Read a new command byte
1367 | and recurse.) Decrement character position.
1370 | 0x10 - Traverse right trie. (Read a new command byte and
1373 Let's look again at the <<lop_stab>> for the trivial file
1374 (@pxref{File layout}).
1376 | 0x980b0000 - lop_stab for ":Main" = 0, serial 1.
1383 This forms the trivial trie (note that the path between ``:'' and
1384 ``M'' is redundant):
1395 | 016e "n" is the last character in a full symbol, and
1396 | with a value represented in one byte.
1397 | 00 The value is 0.
1398 | 81 The serial number is 1. */
1400 bfd_byte m = mmo_get_byte (abfd);
1402 /* Check first if we have a bad hair day. */
1403 if (abfd->tdata.mmo_data->have_error)
1407 /* Traverse left trie. */
1408 mmo_get_symbols (abfd);
1410 if (m & MMO3_SYMBITS)
1412 bfd_byte c = mmo_get_byte (abfd);
1413 bfd_byte j = m & MMO3_TYPEBITS;
1415 enum mmo_sym_type sym_type;
1416 unsigned int serno = 0;
1421 bfd_byte c2 = mmo_get_byte (abfd);
1423 /* A two-byte character. We can't grok this, but neither can
1424 mmotype, for other cases than the second byte being zero. */
1428 abfd->tdata.mmo_data->lop_stab_symbol
1429 [abfd->tdata.mmo_data->symbol_position] = 0;
1431 (*_bfd_error_handler)
1432 (_("%s: unsupported wide character sequence\
1433 0x%02X 0x%02X after symbol name starting with `%s'\n"),
1434 bfd_get_filename (abfd), c, c2,
1435 abfd->tdata.mmo_data->lop_stab_symbol);
1436 bfd_set_error (bfd_error_bad_value);
1437 abfd->tdata.mmo_data->have_error = TRUE;
1444 abfd->tdata.mmo_data->lop_stab_symbol[abfd->tdata.mmo_data->symbol_position++] = c;
1445 abfd->tdata.mmo_data->lop_stab_symbol[abfd->tdata.mmo_data->symbol_position] = 0;
1447 if (j & MMO3_REGQUAL_BITS)
1449 if (j == MMO3_REGQUAL_BITS)
1451 sym_type = mmo_reg_sym;
1452 addr = mmo_get_byte (abfd);
1458 for (i = 0; i < j; i++)
1459 addr = (addr << 8) + mmo_get_byte (abfd);
1461 if (addr == 0 && j == MMO3_UNDEF)
1462 sym_type = mmo_undef_sym;
1464 sym_type = mmo_abs_sym;
1470 for (i = MMO3_DATA; i < j; i++)
1471 addr = (addr << 8) + mmo_get_byte (abfd);
1473 addr += (bfd_vma) 0x20 << 56;
1474 sym_type = mmo_data_sym;
1477 /* Get the serial number. */
1480 k = mmo_get_byte (abfd);
1481 serno = (serno << 7) + k;
1486 /* Got it. Now enter it. Skip a leading ":". */
1487 if (! abfd->tdata.mmo_data->have_error
1488 && ! mmo_create_symbol (abfd,
1489 abfd->tdata.mmo_data->lop_stab_symbol
1491 addr, sym_type, serno))
1492 abfd->tdata.mmo_data->have_error = TRUE;
1495 if (m & MMO3_MIDDLE)
1496 /* Traverse middle trie. */
1497 mmo_get_symbols (abfd);
1499 abfd->tdata.mmo_data->symbol_position--;
1503 /* Traverse right trie. */
1504 mmo_get_symbols (abfd);
1506 return ! abfd->tdata.mmo_data->have_error;
1509 /* Get the location of memory area [VMA..VMA + SIZE - 1], which we think
1510 is in section SEC. Adjust and reallocate zero-initialized contents.
1511 If there's new contents, allocate to the next multiple of
1512 MMO_SEC_CONTENTS_CHUNK_SIZE. */
1514 static INLINE bfd_byte *
1515 mmo_get_loc (sec, vma, size)
1520 bfd_size_type allocated_size;
1521 struct mmo_section_data_struct *sdatap = mmo_section_data (sec);
1522 struct mmo_data_list_struct *datap = sdatap->head;
1523 struct mmo_data_list_struct *entry;
1525 /* First search the list to see if we have the requested chunk in one
1526 piece, or perhaps if we have a suitable chunk with room to fit. */
1527 for (; datap != NULL; datap = datap->next)
1529 if (datap->where <= vma
1530 && datap->where + datap->size >= vma + size)
1531 return datap->data + vma - datap->where;
1532 else if (datap->where <= vma
1533 && datap->where + datap->allocated_size >= vma + size
1534 /* Only munch on the "allocated size" if it does not
1535 overlap the next chunk. */
1536 && (datap->next == NULL || datap->next->where >= vma + size))
1538 /* There was room allocated, but the size wasn't set to include
1540 datap->size += (vma + size) - (datap->where + datap->size);
1542 /* Update the section size. This happens only if we update the
1543 32-bit-aligned chunk size. Callers that have
1544 non-32-bit-aligned sections should do all allocation and
1545 size-setting by themselves or at least set the section size
1546 after the last allocating call to this function. */
1547 if (vma + size > sec->vma + sec->size)
1548 sec->size += (vma + size) - (sec->vma + sec->size);
1550 return datap->data + vma - datap->where;
1554 /* Not found; allocate a new block. First check in case we get a
1555 request for a size split up over several blocks; we'll have to return
1556 NULL for those cases, requesting the caller to split up the request.
1557 Requests with an address aligned on MMO_SEC_CONTENTS_CHUNK_SIZE bytes and
1558 for no more than MMO_SEC_CONTENTS_CHUNK_SIZE will always get resolved. */
1560 for (datap = sdatap->head; datap != NULL; datap = datap->next)
1561 if ((datap->where <= vma && datap->where + datap->size > vma)
1562 || (datap->where < vma + size
1563 && datap->where + datap->size >= vma + size))
1567 = (size + MMO_SEC_CONTENTS_CHUNK_SIZE - 1) & ~(MMO_SEC_CONTENTS_CHUNK_SIZE - 1);
1568 entry = (mmo_data_list_type *)
1569 bfd_zalloc (sec->owner, sizeof (mmo_data_list_type) + allocated_size);
1574 entry->allocated_size = allocated_size;
1576 datap = sdatap->head;
1578 /* Sort the records by address. Optimize for the common case of adding
1579 a record to the end of the list. */
1580 if (sdatap->tail != NULL && entry->where >= sdatap->tail->where)
1582 sdatap->tail->next = entry;
1584 sdatap->tail = entry;
1588 mmo_data_list_type **look;
1589 for (look = &sdatap->head;
1590 *look != NULL && (*look)->where < entry->where;
1591 look = &(*look)->next)
1593 entry->next = *look;
1595 if (entry->next == NULL)
1597 sdatap->tail = entry;
1599 /* We get here for the first time (at other times too) for this
1600 section. Say we have contents. */
1601 if (! bfd_set_section_flags (sec->owner, sec,
1602 bfd_get_section_flags (sec->owner, sec)
1603 | SEC_HAS_CONTENTS))
1608 /* Update the section size. This happens only when we add contents and
1609 re-size as we go. The section size will then be aligned to 32 bits. */
1610 if (vma + size > sec->vma + sec->size)
1611 sec->size += (vma + size) - (sec->vma + sec->size);
1615 /* Set sizes once we've read in all sections. */
1618 mmo_map_set_sizes (abfd, sec, ignored)
1619 bfd *abfd ATTRIBUTE_UNUSED;
1621 PTR ignored ATTRIBUTE_UNUSED;
1623 sec->lma = sec->vma;
1626 /* Read the mmo file and turn it into sections. */
1633 unsigned int lineno = 1;
1634 bfd_boolean error = FALSE;
1636 asection *sec = bfd_make_section_old_way (abfd, MMO_TEXT_SECTION_NAME);
1637 asection *non_spec_sec = NULL;
1638 bfd_vma non_spec_vma = 0;
1639 char *current_filename = NULL;
1640 bfd_size_type nbytes_read = 0;
1641 /* Buffer with room to read a 64-bit value. */
1644 char *file_names[256];
1646 memset (file_names, 0, sizeof (file_names));
1648 if (bfd_seek (abfd, (file_ptr) 0, SEEK_SET) != 0)
1651 while ((nbytes_read = bfd_bread (buf, 4, abfd)) == 4)
1655 unsigned int y = bfd_get_8 (abfd, buf + 2);
1656 unsigned int z = bfd_get_8 (abfd, buf + 3);
1658 /* Change back to the original section for lopcodes other
1659 than LOP_QUOTE that comes after a LOP_SPEC. */
1660 if ((buf[1] != LOP_QUOTE || y != 0 || z != 1)
1661 && non_spec_sec != NULL)
1665 non_spec_sec = NULL;
1671 (*_bfd_error_handler)
1672 (_("%s: invalid mmo file: unsupported lopcode `%d'\n"),
1673 bfd_get_filename (abfd), buf[1]);
1674 bfd_set_error (bfd_error_bad_value);
1678 /* Quote the next 32-bit word. */
1679 if (y != 0 || z != 1)
1681 (*_bfd_error_handler)
1682 (_("%s: invalid mmo file: expected YZ = 1 got YZ = %d for lop_quote\n"),
1683 bfd_get_filename (abfd), y*256+z);
1684 bfd_set_error (bfd_error_bad_value);
1687 if (bfd_bread (buf, 4, abfd) != 4)
1690 mmo_xore_32 (sec, vma, bfd_get_32 (abfd, buf));
1697 /* Set vma (and section). */
1698 vma = (bfd_vma) y << 56;
1701 /* Get a 32-bit value. */
1702 if (bfd_bread (buf, 4, abfd) != 4)
1705 vma += bfd_get_32 (abfd, buf);
1709 /* Get a 64-bit value. */
1710 if (bfd_bread (buf, 8, abfd) != 8)
1713 vma += bfd_get_64 (abfd, buf);
1717 (*_bfd_error_handler)
1718 (_("%s: invalid mmo file: expected z = 1 or z = 2, got z = %d for lop_loc\n"),
1719 bfd_get_filename (abfd), z);
1720 bfd_set_error (bfd_error_bad_value);
1724 sec = mmo_decide_section (abfd, vma);
1730 /* Move forward within the same section. */
1733 sec = mmo_decide_section (abfd, vma);
1739 /* A fixup: Store the current vma somewhere. Position using
1740 same format as LOP_LOC. */
1742 bfd_vma p = (bfd_vma) y << 56;
1747 /* Get a 32-bit value. */
1748 if (bfd_bread (buf, 4, abfd) != 4)
1751 p += bfd_get_32 (abfd, buf);
1755 /* Get a 64-bit value. */
1756 if (bfd_bread (buf, 8, abfd) != 8)
1759 p += bfd_get_64 (abfd, buf);
1763 (*_bfd_error_handler)
1764 (_("%s: invalid mmo file: expected z = 1 or z = 2, got z = %d for lop_fixo\n"),
1765 bfd_get_filename (abfd), z);
1766 bfd_set_error (bfd_error_bad_value);
1770 /* The section where we store this address might be a
1771 different one than the current section. */
1772 fixosec = mmo_decide_section (abfd, p);
1773 if (fixosec == NULL)
1775 mmo_xore_64 (fixosec, p, vma);
1780 /* A fixup: Store YZ of this lopcode into YZ at vma - 4 * yz. */
1782 unsigned int yz = (y * 256 + z);
1783 bfd_vma p = vma + 2 - 4 * yz;
1784 asection *fixrsec = mmo_decide_section (abfd, p);
1785 if (fixrsec == NULL)
1787 mmo_xore_16 (fixrsec, p, yz);
1792 /* A fixup, similar to lop_fixr, but taking larger numbers
1793 and can change branches into the opposite direction
1802 (*_bfd_error_handler)
1803 (_("%s: invalid mmo file: expected y = 0, got y = %d for lop_fixrx\n"),
1804 bfd_get_filename (abfd), y);
1805 bfd_set_error (bfd_error_bad_value);
1809 if (z != 16 && z != 24)
1811 (*_bfd_error_handler)
1812 (_("%s: invalid mmo file: expected z = 16 or z = 24, got z = %d for lop_fixrx\n"),
1813 bfd_get_filename (abfd), z);
1814 bfd_set_error (bfd_error_bad_value);
1818 /* Get the next 32-bit value. */
1819 if (bfd_bread (buf, 4, abfd) != 4)
1822 delta = bfd_get_32 (abfd, buf);
1824 /* Do an, ehm, involved calculation for the location of
1825 the fixup. See mmixal documentation for a verbose
1826 explanation. We follow it verbosely here for the
1829 p = vma - 4 * delta;
1830 else if (buf[0] == 1)
1831 p = vma - 4 * ((delta & 0xffffff) - (1 << z));
1834 (*_bfd_error_handler)
1835 (_("%s: invalid mmo file: leading byte of operand word must be 0 or 1, got %d for lop_fixrx\n"),
1836 bfd_get_filename (abfd), buf[0]);
1837 bfd_set_error (bfd_error_bad_value);
1841 fixrsec = mmo_decide_section (abfd, vma);
1842 if (fixrsec == NULL)
1844 mmo_xore_32 (fixrsec, p, delta);
1849 /* Set current file and perhaps the file name. Reset line
1853 char *fname = bfd_malloc (z * 4 + 1);
1857 (*_bfd_error_handler)
1858 (_("%s: cannot allocate file name for file number %d, %d bytes\n"),
1859 bfd_get_filename (abfd), y, z * 4 + 1);
1860 bfd_set_error (bfd_error_system_call);
1866 for (i = 0; i < z; i++)
1868 if (bfd_bread (fname + i * 4, 4, abfd) != 4)
1875 if (file_names[y] != NULL)
1877 (*_bfd_error_handler)
1878 (_("%s: invalid mmo file: file number %d `%s',\
1879 was already entered as `%s'\n"),
1880 bfd_get_filename (abfd), y, fname, file_names[y]);
1881 bfd_set_error (bfd_error_bad_value);
1885 file_names[y] = fname;
1888 if (file_names[y] == NULL)
1890 (*_bfd_error_handler)
1891 (_("%s: invalid mmo file: file name for number %d\
1892 was not specified before use\n"),
1893 bfd_get_filename (abfd), y);
1894 bfd_set_error (bfd_error_bad_value);
1898 current_filename = file_names[y];
1903 /* Set line number. */
1904 lineno = y * 256 + z;
1905 /* FIXME: Create a sequence of mmo-specific line number
1906 entries for each section, then translate into canonical
1911 /* Special data follows until the next non-lop_quote
1915 sec = mmo_get_spec_section (abfd, y * 256 + z);
1924 /* We ignore header information, except we read in the
1925 creation time from the first 32-bit word with the time
1926 in seconds since era. */
1928 && bfd_bread (abfd->tdata.mmo_data->created, 4,
1932 for (i = 1; i < z; i++)
1933 if (bfd_bread (buf, 4, abfd) != 4)
1939 /* This tells of the contents of registers $Z..$255 at
1940 startup. We make a section out of it, with VMA = Z * 8,
1941 but only if Z != 255 or the contents is non-zero. */
1946 bfd_vma startaddr_octa;
1948 /* Read first octaword outside loop to simplify logic when
1949 excluding the Z == 255, octa == 0 case. */
1950 if (bfd_bread (buf, 8, abfd) != 8)
1953 first_octa = bfd_get_64 (abfd, buf);
1955 /* Don't emit contents for the trivial case which is
1956 always present; $255 pointing to Main. */
1960 = bfd_make_section_old_way (abfd,
1961 MMIX_REG_CONTENTS_SECTION_NAME);
1963 loc = mmo_get_loc (rsec, z * 8, (255 - z) * 8);
1964 bfd_put_64 (abfd, first_octa, loc);
1966 for (i = z + 1; i < 255; i++)
1968 if (bfd_bread (loc + (i - z) * 8, 8, abfd) != 8)
1972 /* Read out the last octabyte, and use it to set the
1974 if (bfd_bread (buf, 8, abfd) != 8)
1977 startaddr_octa = bfd_get_64 (abfd, buf);
1980 startaddr_octa = first_octa;
1982 if (! bfd_set_start_address (abfd, startaddr_octa))
1984 /* Currently this can't fail, but this should handle
1986 bfd_set_error (bfd_error_bad_value);
1993 /* We read in the symbols now, not later. */
1994 if (y != 0 || z != 0)
1996 (*_bfd_error_handler)
1997 (_("%s: invalid mmo file: fields y and z of lop_stab\
1998 non-zero, y: %d, z: %d\n"),
1999 bfd_get_filename (abfd), y, z);
2000 bfd_set_error (bfd_error_bad_value);
2004 /* Save the location, so we can check that YZ in the LOP_END
2006 stab_loc = bfd_tell (abfd);
2008 /* It's not said that an MMO can be without symbols (though
2009 mmixal will refuse to assemble files without Main), but
2010 it seems it would still be a valid mmo-file, so allow it.
2011 We detect the absence of a symbol area in that the upper
2012 limit is computed (from the lop_end YZ field) as 0.
2013 Don't call mmo_get_symbols; it can only detect the end of
2014 a valid symbol trie, not the absence of one. */
2015 if (abfd->tdata.mmo_data->max_symbol_length != 0
2016 && ! mmo_get_symbols (abfd))
2022 /* This must be the last 32-bit word in an mmo file.
2024 struct stat statbuf;
2025 long curpos = bfd_tell (abfd);
2027 if (bfd_stat (abfd, &statbuf) < 0)
2030 if (statbuf.st_size != curpos)
2032 (*_bfd_error_handler)
2033 (_("%s: invalid mmo file: lop_end not last item in\
2035 bfd_get_filename (abfd));
2036 bfd_set_error (bfd_error_bad_value);
2040 /* Check that the YZ field is right. Subtract the size of
2041 this LOP_END in the calculation; YZ does not include
2043 if ((long) (y * 256 + z) * 4 != (curpos - stab_loc) - 4)
2045 (*_bfd_error_handler)
2046 (_("%s: invalid mmo file: YZ of lop_end (%ld)\
2047 not equal to the number of tetras to the preceding lop_stab (%ld)\n"),
2048 bfd_get_filename (abfd), (long) (y * 256 + z),
2049 (curpos - stab_loc - 4)/4);
2050 bfd_set_error (bfd_error_bad_value);
2054 bfd_map_over_sections (abfd, mmo_map_set_sizes, NULL);
2061 /* This wasn't a lopcode, so store it in the current section. */
2062 mmo_xore_32 (sec, vma & ~3, bfd_get_32 (abfd, buf));
2069 /* We know this file is a multiple of four bytes (checked in
2070 mmo_object_p), so if we got something other than 0, this was a bad
2071 file (although it's more likely we'll get 0 in that case too).
2072 If we got end-of-file, then there was no lop_stab, so the file has
2075 if (nbytes_read != 0)
2076 bfd_set_error (bfd_error_system_call);
2078 bfd_set_error (bfd_error_bad_value);
2083 /* Mark the .text and .data section with their normal attribute if they
2084 contain anything. This is not redundant wrt. mmo_decide_section,
2085 since that code might never execute, and conversely the alloc+code
2086 section flags must be set then. */
2087 sec = bfd_get_section_by_name (abfd, MMO_TEXT_SECTION_NAME);
2089 && (bfd_get_section_flags (abfd, sec) & SEC_HAS_CONTENTS)
2090 && ! bfd_set_section_flags (abfd, sec,
2091 bfd_get_section_flags (abfd, sec)
2092 | SEC_ALLOC | SEC_LOAD | SEC_CODE))
2095 sec = bfd_get_section_by_name (abfd, MMO_DATA_SECTION_NAME);
2097 && (bfd_get_section_flags (abfd, sec) & SEC_HAS_CONTENTS)
2098 && ! bfd_set_section_flags (abfd, sec,
2099 bfd_get_section_flags (abfd, sec)
2100 | SEC_ALLOC | SEC_LOAD))
2103 /* Free whatever resources we took. */
2104 for (i = 0; i < sizeof (file_names) / sizeof (file_names[0]); i++)
2106 free (file_names[i]);
2110 /* A hook to set up object file dependent section information. For mmo,
2111 we point out the shape of allocated section contents. */
2114 mmo_new_section_hook (abfd, newsect)
2115 bfd *abfd ATTRIBUTE_UNUSED;
2118 /* We zero-fill all fields and assume NULL is represented by an all
2119 zero-bit pattern. */
2120 newsect->used_by_bfd =
2121 (PTR) bfd_zalloc (abfd, sizeof (struct mmo_section_data_struct));
2123 if (!newsect->used_by_bfd)
2126 /* Always align to at least 32-bit words. */
2127 newsect->alignment_power = 2;
2131 /* We already have section contents loaded for sections that have
2135 mmo_get_section_contents (abfd, sec, location, offset, bytes_to_do)
2136 bfd *abfd ATTRIBUTE_UNUSED;
2137 asection *sec ATTRIBUTE_UNUSED;
2138 PTR location ATTRIBUTE_UNUSED;
2139 file_ptr offset ATTRIBUTE_UNUSED;
2140 bfd_size_type bytes_to_do ATTRIBUTE_UNUSED;
2142 /* Iterate over diminishing chunk sizes, copying contents, like
2143 mmo_set_section_contents. */
2146 /* A minor song-and-dance to make sure we're not bitten by the
2147 distant possibility of the cast from bfd_vma to int making the
2148 chunk zero-sized. */
2150 = (int) bytes_to_do != 0 ? bytes_to_do : MMO_SEC_CONTENTS_CHUNK_SIZE;
2154 loc = mmo_get_loc (sec, sec->vma + offset, chunk_size);
2155 while (loc == NULL && (chunk_size /= 2) != 0);
2157 if (chunk_size == 0)
2160 memcpy (location, loc, chunk_size);
2162 location += chunk_size;
2163 bytes_to_do -= chunk_size;
2164 offset += chunk_size;
2169 /* Return the amount of memory needed to read the symbol table. */
2172 mmo_get_symtab_upper_bound (abfd)
2173 bfd *abfd ATTRIBUTE_UNUSED;
2175 return (abfd->symcount + 1) * sizeof (asymbol *);
2178 /* Sort mmo symbols by serial number. */
2181 mmo_sort_mmo_symbols (arg1, arg2)
2185 const struct mmo_symbol *sym1 = *(const struct mmo_symbol **) arg1;
2186 const struct mmo_symbol *sym2 = *(const struct mmo_symbol **) arg2;
2188 /* Sort by serial number first. */
2189 if (sym1->serno < sym2->serno)
2191 else if (sym1->serno > sym2->serno)
2194 /* Then sort by address of the table entries. */
2195 return ((const char *) arg1 - (const char *) arg2);
2198 /* Translate the symbol table. */
2201 mmo_canonicalize_symtab (abfd, alocation)
2203 asymbol **alocation;
2205 unsigned int symcount = bfd_get_symcount (abfd);
2209 csymbols = abfd->tdata.mmo_data->csymbols;
2210 if (csymbols == NULL)
2213 struct mmo_symbol *s;
2214 struct mmo_symbol **msp;
2216 /* First we store the symbols into the table we'll return, then we
2217 qsort it on the serial number, with secondary on the address of
2218 the symbol, to preserve order if there would be non-unique serial
2220 for (s = abfd->tdata.mmo_data->symbols,
2221 msp = (struct mmo_symbol **) alocation;
2228 qsort (alocation, symcount, sizeof (struct mmo_symbol *),
2229 mmo_sort_mmo_symbols);
2231 csymbols = (asymbol *) bfd_alloc (abfd, symcount * sizeof (asymbol));
2232 if (csymbols == NULL && symcount != 0)
2234 abfd->tdata.mmo_data->csymbols = csymbols;
2236 for (msp = (struct mmo_symbol **) alocation, c = csymbols;
2243 c->value = s->value;
2244 c->flags = BSF_GLOBAL;
2246 if (s->sym_type == mmo_data_sym)
2249 = bfd_get_section_by_name (abfd, MMO_DATA_SECTION_NAME);
2251 if (c->section == NULL)
2252 c->section = bfd_abs_section_ptr;
2254 c->value -= c->section->vma;
2256 else if (s->sym_type == mmo_undef_sym)
2257 c->section = bfd_und_section_ptr;
2258 else if (s->sym_type == mmo_reg_sym)
2261 = bfd_make_section_old_way (abfd, MMIX_REG_SECTION_NAME);
2266 = bfd_get_section_by_name (abfd, MMO_TEXT_SECTION_NAME);
2269 && c->value >= textsec->vma
2270 && c->value <= textsec->vma + textsec->size)
2272 c->section = textsec;
2273 c->value -= c->section->vma;
2276 c->section = bfd_abs_section_ptr;
2283 /* Last, overwrite the incoming table with the right-type entries. */
2284 for (i = 0; i < symcount; i++)
2285 *alocation++ = csymbols++;
2291 /* Get information about a symbol. */
2294 mmo_get_symbol_info (ignore_abfd, symbol, ret)
2295 bfd *ignore_abfd ATTRIBUTE_UNUSED;
2299 bfd_symbol_info (symbol, ret);
2303 mmo_print_symbol (abfd, afile, symbol, how)
2307 bfd_print_symbol_type how;
2309 FILE *file = (FILE *) afile;
2313 case bfd_print_symbol_name:
2314 fprintf (file, "%s", symbol->name);
2317 bfd_print_symbol_vandf (abfd, (PTR) file, symbol);
2319 fprintf (file, " %-5s %s",
2320 symbol->section->name,
2325 /* We can't map a file directly into executable code, so the
2326 size of header information is irrelevant. */
2329 mmo_sizeof_headers (abfd, exec)
2330 bfd *abfd ATTRIBUTE_UNUSED;
2331 bfd_boolean exec ATTRIBUTE_UNUSED;
2336 /* Write the (section-neutral) file preamble. */
2339 mmo_internal_write_header (abfd)
2342 const char lop_pre_bfd[] = { LOP, LOP_PRE, 1, 1};
2344 if (bfd_bwrite (lop_pre_bfd, 4, abfd) != 4)
2347 /* Copy creation time of original file. */
2348 if (bfd_bwrite (abfd->tdata.mmo_data->created, 4, abfd) != 4)
2354 /* Write the LOP_POST record, with global register initializations.
2355 Z is the Z field of the LOP_POST, corresponding to 255 - number of
2356 registers at DATA. The Z = 255 field is filled in with the
2360 mmo_internal_write_post (abfd, z, sec)
2367 mmo_write_tetra_raw (abfd, (LOP << 24) | (LOP_POST << 16) | z);
2369 for (i = z; i < 255; i++)
2371 bfd_byte *data = mmo_get_loc (sec, i * 8, 8);
2373 if (bfd_bwrite (data, 8, abfd) != 8)
2377 /* For Z == $255, we always emit the start location; supposedly Main,
2378 but we have it handy at bfd_get_start_address. If we're called with
2379 Z == 255, don't assume DATA is valid. */
2380 bfd_put_64 (abfd, bfd_get_start_address (abfd), buf);
2382 return ! abfd->tdata.mmo_data->have_error && bfd_bwrite (buf, 8, abfd) == 8;
2385 /* Translate to and from BFD flags. This is to make sure that we don't
2386 get bitten by BFD flag number changes. */
2389 mmo_sec_flags_from_bfd_flags (flags)
2392 flagword oflags = 0;
2394 if (flags & SEC_ALLOC)
2395 oflags |= MMO_SEC_ALLOC;
2396 if (flags & SEC_LOAD)
2397 oflags |= MMO_SEC_LOAD;
2398 if (flags & SEC_RELOC)
2399 oflags |= MMO_SEC_RELOC;
2400 if (flags & SEC_READONLY)
2401 oflags |= MMO_SEC_READONLY;
2402 if (flags & SEC_CODE)
2403 oflags |= MMO_SEC_CODE;
2404 if (flags & SEC_DATA)
2405 oflags |= MMO_SEC_DATA;
2406 if (flags & SEC_NEVER_LOAD)
2407 oflags |= MMO_SEC_NEVER_LOAD;
2408 if (flags & SEC_IS_COMMON)
2409 oflags |= MMO_SEC_IS_COMMON;
2410 if (flags & SEC_DEBUGGING)
2411 oflags |= MMO_SEC_DEBUGGING;
2417 bfd_sec_flags_from_mmo_flags (flags)
2420 flagword oflags = 0;
2422 if (flags & MMO_SEC_ALLOC)
2423 oflags |= SEC_ALLOC;
2424 if (flags & MMO_SEC_LOAD)
2426 if (flags & MMO_SEC_RELOC)
2427 oflags |= SEC_RELOC;
2428 if (flags & MMO_SEC_READONLY)
2429 oflags |= SEC_READONLY;
2430 if (flags & MMO_SEC_CODE)
2432 if (flags & MMO_SEC_DATA)
2434 if (flags & MMO_SEC_NEVER_LOAD)
2435 oflags |= SEC_NEVER_LOAD;
2436 if (flags & MMO_SEC_IS_COMMON)
2437 oflags |= SEC_IS_COMMON;
2438 if (flags & MMO_SEC_DEBUGGING)
2439 oflags |= SEC_DEBUGGING;
2444 /* Write a section. */
2447 mmo_internal_write_section (abfd, sec)
2451 /* We do it differently depending on what section this is:
2453 ".text": Output, prepended by information about the first source file
2454 (not yet implemented.)
2458 (".MMIX.reg_contents": Not handled here.)
2460 Anything else: Output inside a lop_spec 80, in the format described
2463 if (strcmp (sec->name, MMO_TEXT_SECTION_NAME) == 0)
2464 /* FIXME: Output source file name and line number. */
2465 return mmo_write_loc_chunk_list (abfd, mmo_section_data (sec)->head);
2466 else if (strcmp (sec->name, MMO_DATA_SECTION_NAME) == 0)
2467 return mmo_write_loc_chunk_list (abfd, mmo_section_data (sec)->head);
2468 else if (strcmp (sec->name, MMIX_REG_CONTENTS_SECTION_NAME) == 0)
2469 /* Not handled here. */
2471 /* This would normally be an abort call since this can't happen, but
2472 we don't do that. */
2473 bfd_set_error (bfd_error_bad_value);
2476 else if (strncmp (sec->name, MMIX_OTHER_SPEC_SECTION_PREFIX,
2477 strlen (MMIX_OTHER_SPEC_SECTION_PREFIX)) == 0)
2479 int n = atoi (sec->name + strlen (MMIX_OTHER_SPEC_SECTION_PREFIX));
2480 mmo_write_tetra_raw (abfd, (LOP << 24) | (LOP_SPEC << 16) | n);
2481 return (! abfd->tdata.mmo_data->have_error
2482 && mmo_write_chunk_list (abfd, mmo_section_data (sec)->head));
2484 /* Ignore sections that are just allocated or empty; we write out
2486 else if ((bfd_get_section_flags (abfd, sec) & SEC_HAS_CONTENTS) != 0
2489 /* Keep the document-comment formatted the way it is. */
2492 mmo section mapping, , Symbol-table, mmo
2496 The implementation in BFD uses special data type 80 (decimal) to
2497 encapsulate and describe named sections, containing e.g.@: debug
2498 information. If needed, any datum in the encapsulation will be
2499 quoted using lop_quote. First comes a 32-bit word holding the
2500 number of 32-bit words containing the zero-terminated zero-padded
2501 segment name. After the name there's a 32-bit word holding flags
2502 describing the section type. Then comes a 64-bit big-endian word
2503 with the section length (in bytes), then another with the section
2504 start address. Depending on the type of section, the contents
2505 might follow, zero-padded to 32-bit boundary. For a loadable
2506 section (such as data or code), the contents might follow at some
2507 later point, not necessarily immediately, as a lop_loc with the
2508 same start address as in the section description, followed by the
2509 contents. This in effect forms a descriptor that must be emitted
2510 before the actual contents. Sections described this way must not
2513 For areas that don't have such descriptors, synthetic sections are
2514 formed by BFD. Consecutive contents in the two memory areas
2515 @samp{0x0000@dots{}00} to @samp{0x01ff@dots{}ff} and
2516 @samp{0x2000@dots{}00} to @samp{0x20ff@dots{}ff} are entered in
2517 sections named <<.text>> and <<.data>> respectively. If an area
2518 is not otherwise described, but would together with a neighboring
2519 lower area be less than @samp{0x40000000} bytes long, it is joined
2520 with the lower area and the gap is zero-filled. For other cases,
2521 a new section is formed, named <<.MMIX.sec.@var{n}>>. Here,
2522 @var{n} is a number, a running count through the mmo file,
2526 A loadable section specified as:
2528 | .section secname,"ax"
2529 | TETRA 1,2,3,4,-1,-2009
2532 and linked to address @samp{0x4}, is represented by the sequence:
2534 | 0x98080050 - lop_spec 80
2535 | 0x00000002 - two 32-bit words for the section name
2536 | 0x7365636e - "secn"
2537 | 0x616d6500 - "ame\0"
2538 | 0x00000033 - flags CODE, READONLY, LOAD, ALLOC
2539 | 0x00000000 - high 32 bits of section length
2540 | 0x0000001c - section length is 28 bytes; 6 * 4 + 1 + alignment to 32 bits
2541 | 0x00000000 - high 32 bits of section address
2542 | 0x00000004 - section address is 4
2543 | 0x98010002 - 64 bits with address of following data
2544 | 0x00000000 - high 32 bits of address
2545 | 0x00000004 - low 32 bits: data starts at address 4
2551 | 0xfffff827 - -2009
2552 | 0x50000000 - 80 as a byte, padded with zeros.
2554 Note that the lop_spec wrapping does not include the section
2555 contents. Compare this to a non-loaded section specified as:
2558 | TETRA 200001,100002
2561 This, when linked to address @samp{0x200000000000001c}, is
2564 | 0x98080050 - lop_spec 80
2565 | 0x00000002 - two 32-bit words for the section name
2566 | 0x7365636e - "thir"
2567 | 0x616d6500 - "dsec"
2568 | 0x00000010 - flag READONLY
2569 | 0x00000000 - high 32 bits of section length
2570 | 0x0000000c - section length is 12 bytes; 2 * 4 + 2 + alignment to 32 bits
2571 | 0x20000000 - high 32 bits of address
2572 | 0x0000001c - low 32 bits of address 0x200000000000001c
2573 | 0x00030d41 - 200001
2574 | 0x000186a2 - 100002
2575 | 0x26280000 - 38, 40 as bytes, padded with zeros
2577 For the latter example, the section contents must not be
2578 loaded in memory, and is therefore specified as part of the
2579 special data. The address is usually unimportant but might
2580 provide information for e.g.@: the DWARF 2 debugging format. */
2582 mmo_write_tetra_raw (abfd, LOP_SPEC_SECTION);
2583 mmo_write_tetra (abfd, (strlen (sec->name) + 3) / 4);
2584 mmo_write_chunk (abfd, sec->name, strlen (sec->name));
2585 mmo_flush_chunk (abfd);
2586 /* FIXME: We can get debug sections (.debug_line & Co.) with a
2587 section flag still having SEC_RELOC set. Investigate. This
2588 might be true for all alien sections; perhaps mmo.em should clear
2589 that flag. Might be related to weak references. */
2590 mmo_write_tetra (abfd,
2591 mmo_sec_flags_from_bfd_flags
2592 (bfd_get_section_flags (abfd, sec)));
2593 mmo_write_octa (abfd, sec->size);
2594 mmo_write_octa (abfd, bfd_get_section_vma (abfd, sec));
2596 /* Writing a LOP_LOC ends the LOP_SPEC data, and makes data actually
2598 if (bfd_get_section_flags (abfd, sec) & SEC_LOAD)
2599 return (! abfd->tdata.mmo_data->have_error
2600 && mmo_write_loc_chunk_list (abfd,
2601 mmo_section_data (sec)->head));
2602 return (! abfd->tdata.mmo_data->have_error
2603 && mmo_write_chunk_list (abfd, mmo_section_data (sec)->head));
2608 /* We save up all data before output. */
2611 mmo_set_section_contents (abfd, sec, location, offset, bytes_to_do)
2612 bfd *abfd ATTRIBUTE_UNUSED;
2616 bfd_size_type bytes_to_do;
2618 /* Iterate over diminishing chunk sizes, copying contents. */
2621 /* A minor song-and-dance to make sure we're not bitten by the
2622 distant possibility of the cast from bfd_vma to int making the
2623 chunk zero-sized. */
2625 = (int) bytes_to_do != 0 ? bytes_to_do : MMO_SEC_CONTENTS_CHUNK_SIZE;
2629 loc = mmo_get_loc (sec, sec->vma + offset, chunk_size);
2630 while (loc == NULL && (chunk_size /= 2) != 0);
2632 if (chunk_size == 0)
2635 memcpy (loc, location, chunk_size);
2637 location += chunk_size;
2638 bytes_to_do -= chunk_size;
2639 offset += chunk_size;
2644 /* Add a symbol to a trie-tree. */
2647 mmo_internal_add_3_sym (abfd, rootp, symp)
2649 struct mmo_symbol_trie *rootp;
2650 const struct mmo_symbol *symp;
2652 const char *name = symp->name;
2653 struct mmo_symbol_trie *trie = rootp;
2654 struct mmo_symbol_trie **triep = NULL;
2656 while (*name && trie != NULL)
2658 if (*name < trie->symchar)
2660 triep = &trie->left;
2663 else if (*name > trie->symchar)
2665 triep = &trie->right;
2668 else if (*name == trie->symchar)
2670 triep = &trie->middle;
2673 /* Make sure "trie" points to where we should fill in the
2674 current symbol whenever we've iterated through "name". We
2675 would lose the right position if we encounter "foobar" then
2678 trie = trie->middle;
2684 /* Create middle branches for the rest of the characters. */
2685 trie = bfd_zalloc (abfd, sizeof (struct mmo_symbol_trie));
2687 trie->symchar = *name++;
2688 triep = &trie->middle;
2691 /* We discover a duplicate symbol rather late in the process, but still;
2692 we discover it and bail out. */
2693 if (trie->sym.name != NULL)
2695 (*_bfd_error_handler)
2696 (_("%s: invalid symbol table: duplicate symbol `%s'\n"),
2697 bfd_get_filename (abfd), trie->sym.name);
2698 bfd_set_error (bfd_error_bad_value);
2702 memcpy (&trie->sym, symp, sizeof *symp);
2706 /* Find out the length of the serialized version of a trie in bytes. */
2709 mmo_internal_3_length (abfd, trie)
2711 struct mmo_symbol_trie *trie;
2713 /* First, one for the control byte. */
2714 unsigned int length = 1;
2719 /* Add in the recursion to the left. */
2720 length += mmo_internal_3_length (abfd, trie->left);
2722 /* Add in the middle trie and the character. */
2723 length += 1 + mmo_internal_3_length (abfd, trie->middle);
2725 /* Add in the recursion to the right. */
2726 length += mmo_internal_3_length (abfd, trie->right);
2728 /* Add in bytes for the symbol (if this is an endnode). */
2729 if (trie->sym.name != NULL)
2731 unsigned int serno = trie->sym.serno;
2733 /* First what it takes to encode the value. */
2734 if (trie->sym.sym_type == mmo_reg_sym)
2736 else if (trie->sym.sym_type == mmo_undef_sym)
2740 bfd_vma value = trie->sym.value;
2742 /* Coded in one to eight following bytes. */
2743 if (trie->sym.sym_type == mmo_data_sym)
2744 value -= (bfd_vma) 0x20 << 56;
2754 /* Find out what it takes to encode the serial number. */
2766 /* Helper function for outputting the serial number of a symbol, output as
2767 a variant of leb128 (see dwarf2 documentation) which could be called
2768 beb128. Using a helper function and recursion simplifies debugging. */
2771 mmo_beb128_out (abfd, serno, marker)
2777 mmo_beb128_out (abfd, serno >> 7, 0);
2778 mmo_write_byte (abfd, marker | (serno & 0x7f));
2781 /* Serialize a trie. */
2784 mmo_internal_3_dump (abfd, trie)
2786 struct mmo_symbol_trie *trie;
2788 bfd_byte control = 0;
2794 control |= MMO3_LEFT;
2797 control |= MMO3_MIDDLE;
2800 control |= MMO3_RIGHT;
2802 if (trie->sym.name != NULL)
2804 /* Encode the symbol type and length of value bytes. */
2805 if (trie->sym.sym_type == mmo_reg_sym)
2806 control |= MMO3_REGQUAL_BITS;
2807 else if (trie->sym.sym_type == mmo_undef_sym)
2808 control |= MMO3_UNDEF;
2811 bfd_vma value = trie->sym.value;
2813 /* Coded in 1..8 following bytes. */
2814 if (trie->sym.sym_type == mmo_data_sym)
2816 control |= MMO3_DATA;
2817 value -= (bfd_vma) 0x20 << 56;
2829 /* The control byte is output before recursing. */
2830 mmo_write_byte (abfd, control);
2832 mmo_internal_3_dump (abfd, trie->left);
2834 if (control & MMO3_SYMBITS)
2836 mmo_write_byte (abfd, trie->symchar);
2838 if (trie->sym.name != NULL)
2840 if (trie->sym.sym_type == mmo_reg_sym)
2841 mmo_write_byte (abfd, trie->sym.value);
2842 else if (trie->sym.sym_type == mmo_undef_sym)
2844 mmo_write_byte (abfd, 0);
2845 mmo_write_byte (abfd, 0);
2849 bfd_vma value = trie->sym.value;
2851 bfd_byte byte_n = control & 15;
2853 /* Coded in 1..8 following bytes. Note that the value is
2854 shifted out big-endian. */
2855 if (trie->sym.sym_type == mmo_data_sym)
2857 value -= (bfd_vma) 0x20 << 56;
2863 mmo_write_byte (abfd, (value >> ((byte_n - 1) * 8)) & 0xff);
2866 while (byte_n != 0);
2869 mmo_beb128_out (abfd, trie->sym.serno, 128);
2871 mmo_internal_3_dump (abfd, trie->middle);
2873 mmo_internal_3_dump (abfd, trie->right);
2876 /* Write symbols in mmo format. Also write the lop_end terminator. */
2879 mmo_write_symbols_and_terminator (abfd)
2882 int count = bfd_get_symcount (abfd);
2883 asymbol *maintable[2];
2885 asymbol **orig_table = bfd_get_outsymbols (abfd);
2887 struct mmo_symbol_trie root;
2892 /* Create a symbol for "Main". */
2893 asymbol *fakemain = bfd_make_empty_symbol (abfd);
2895 fakemain->flags = BSF_GLOBAL;
2896 fakemain->value = bfd_get_start_address (abfd);
2897 fakemain->name = MMIX_START_SYMBOL_NAME;
2898 fakemain->section = bfd_abs_section_ptr;
2899 maintable[0] = fakemain;
2900 maintable[1] = NULL;
2902 memset (&root, 0, sizeof (root));
2904 /* Make all symbols take a left turn. */
2905 root.symchar = 0xff;
2907 /* There must always be a ":Main", so we'll add one if there are no
2908 symbols. Make sure we have room for it. */
2909 table = bfd_alloc (abfd, (count + 1) * sizeof (asymbol *));
2913 memcpy (table, orig_table, count * sizeof (asymbol *));
2915 /* Move :Main (if there is one) to the first position. This is
2916 necessary to get the same layout of the trie-tree when linking as
2917 when objcopying the result as in the objcopy.exp test "simple objcopy
2918 of executable". It also automatically takes care of assigning serial
2919 number 1 to :Main (as is mandatory). */
2920 for (i = 0; i < count; i++)
2921 if (table[i] != NULL
2922 && strcmp (table[i]->name, MMIX_START_SYMBOL_NAME) == 0
2923 && (table[i]->flags & (BSF_DEBUGGING|BSF_GLOBAL)) == BSF_GLOBAL)
2925 asymbol *mainsym = table[i];
2926 memcpy (table + 1, orig_table, i * sizeof (asymbol *));
2929 /* Check that the value assigned to :Main is the same as the entry
2930 address. The default linker script asserts this. This is as
2931 good a place as any to check this consistency. */
2933 + mainsym->section->output_section->vma
2934 + mainsym->section->output_offset)
2935 != bfd_get_start_address (abfd))
2937 /* Arbitrary buffer to hold the printable representation of a
2940 char vmas_start[40];
2941 bfd_vma vma_start = bfd_get_start_address (abfd);
2943 sprintf_vma (vmas_main, mainsym->value);
2944 sprintf_vma (vmas_start, vma_start);
2946 (*_bfd_error_handler)
2947 (_("%s: Bad symbol definition: `Main' set to %s rather\
2948 than the start address %s\n"),
2949 bfd_get_filename (abfd), vmas_main, vmas_start);
2950 bfd_set_error (bfd_error_bad_value);
2955 if (i == count && count != 0)
2957 /* When there are symbols, there must be a :Main. There was no
2958 :Main, so we need to add it manually. */
2959 memcpy (table + 1, orig_table, count * sizeof (asymbol *));
2960 table[0] = fakemain;
2964 for (i = 0, serno = 1; i < count && table[i] != NULL; i++)
2966 asymbol *s = table[i];
2968 /* It's not enough to consult bfd_is_local_label, since it does not
2969 mean "local" in the sense of linkable-and-observable-after-link.
2970 Let's just check the BSF_GLOBAL flag.
2972 Also, don't export symbols with characters not in the allowed set. */
2973 if ((s->flags & (BSF_DEBUGGING|BSF_GLOBAL)) == BSF_GLOBAL
2975 valid_mmo_symbol_character_set) == strlen (s->name))
2977 struct mmo_symbol sym;
2978 memset (&sym, 0, sizeof (sym));
2983 + s->section->output_section->vma
2984 + s->section->output_offset;
2986 if (bfd_is_und_section (s->section))
2987 sym.sym_type = mmo_undef_sym;
2988 else if (strcmp (s->section->name, MMO_DATA_SECTION_NAME) == 0
2989 /* The encoding of data symbols require that the "rest"
2990 of the value fits in 6 bytes, so the upper two bytes
2991 must be 0x2000. All other symbols get to be the
2993 && (sym.value >> 48) == 0x2000)
2994 sym.sym_type = mmo_data_sym;
2995 else if (strcmp (s->section->name, MMIX_REG_SECTION_NAME) == 0)
2996 sym.sym_type = mmo_reg_sym;
2997 else if (strcmp (s->section->name,
2998 MMIX_REG_CONTENTS_SECTION_NAME) == 0)
3000 sym.sym_type = mmo_reg_sym;
3004 sym.sym_type = mmo_abs_sym;
3006 /* FIXME: We assume the order of the received symbols is an
3007 ordered mapping of the serial numbers. This is not
3008 necessarily true if we e.g. objcopy a mmo file to another and
3009 there are gaps in the numbering. Not sure if this can
3010 happen. Not sure what to do. */
3011 sym.serno = serno++;
3013 if (! mmo_internal_add_3_sym (abfd, &root, &sym))
3018 /* Change the root node to be a ":"-prefix. */
3020 root.middle = root.left;
3024 /* We have to find out if we can fit the whole symbol table in the mmo
3025 symtab. It would be bad to assume we can always fit it in 262144
3026 bytes. If we can't, just leave the Main symbol. */
3027 trie_len = (mmo_internal_3_length (abfd, &root) + 3)/4;
3029 if (trie_len > 0xffff)
3031 /* Test this code by using a lower limit in the test above and check
3032 that the single "Main" symbol is emitted and handled properly.
3033 There's no specific test-case. */
3034 struct mmo_symbol sym;
3036 (*_bfd_error_handler)
3037 (_("%s: warning: symbol table too large for mmo, larger than 65535\
3038 32-bit words: %d. Only `Main' will be emitted.\n"),
3039 bfd_get_filename (abfd), trie_len);
3041 memset (&sym, 0, sizeof (sym));
3042 sym.sym_type = mmo_abs_sym;
3043 sym.name = MMIX_START_SYMBOL_NAME;
3045 sym.value = bfd_get_start_address (abfd);
3047 /* Then patch up a symbol table to be just the ":Main" symbol. */
3048 memset (&root, 0, sizeof (root));
3049 root.left = root.middle;
3050 root.symchar = 0xff;
3054 if (! mmo_internal_add_3_sym (abfd, &root, &sym))
3058 root.middle = root.left;
3062 trie_len = (mmo_internal_3_length (abfd, &root) + 3)/4;
3065 /* Reset the written-bytes counter. */
3066 abfd->tdata.mmo_data->byte_no = 0;
3068 /* Put out the lop_stab mark. */
3069 bfd_put_32 (abfd, (LOP << 24) | (LOP_STAB << 16), buf);
3070 if (bfd_bwrite (buf, 4, abfd) != 4)
3073 /* Dump out symbols. */
3074 mmo_internal_3_dump (abfd, &root);
3076 if (trie_len != (abfd->tdata.mmo_data->byte_no + 3)/4)
3078 /* I haven't seen this trig. It seems no use claiming this case
3079 isn't debugged and abort if we get here. Instead emit a
3080 diagnostic and fail "normally". */
3081 (*_bfd_error_handler)
3082 (_("%s: internal error, symbol table changed size from %d to %d\
3084 bfd_get_filename (abfd), trie_len,
3085 (abfd->tdata.mmo_data->byte_no + 3)/4);
3086 bfd_set_error (bfd_error_bad_value);
3090 /* Dump out remaining bytes in the buffer and handle I/O errors by
3091 propagating errors. */
3092 if ((abfd->tdata.mmo_data->byte_no % 4) != 0
3093 || abfd->tdata.mmo_data->have_error)
3095 memset (abfd->tdata.mmo_data->buf + (abfd->tdata.mmo_data->byte_no % 4),
3096 0, 4 - (abfd->tdata.mmo_data->byte_no % 4));
3098 if (abfd->tdata.mmo_data->have_error
3099 || bfd_bwrite (abfd->tdata.mmo_data->buf, 4, abfd) != 4)
3103 bfd_put_32 (abfd, (LOP << 24) | (LOP_END << 16) | trie_len, buf);
3104 return bfd_bwrite (buf, 4, abfd) == 4;
3107 /* Write section unless it is the register contents section. For that, we
3108 instead store the section in the supplied pointer. This function is
3109 used through bfd_map_over_sections. */
3112 mmo_write_section_unless_reg_contents (abfd, sec, p)
3117 struct mmo_write_sec_info *infop = (struct mmo_write_sec_info *) p;
3119 if (! infop->retval)
3122 if (strcmp (sec->name, MMIX_REG_CONTENTS_SECTION_NAME) == 0)
3124 infop->reg_section = sec;
3128 /* Exclude the convenience register section. */
3129 if (strcmp (sec->name, MMIX_REG_SECTION_NAME) == 0)
3131 if (bfd_get_section_flags (abfd, sec) & SEC_HAS_CONTENTS)
3133 /* Make sure it hasn't got contents. It seems impossible to
3134 make it carry contents, so we don't have a test-case for
3136 (*_bfd_error_handler)
3137 (_("%s: internal error, internal register section %s had\
3139 bfd_get_filename (abfd), sec->name);
3140 bfd_set_error (bfd_error_bad_value);
3141 infop->retval = FALSE;
3148 infop->retval = mmo_internal_write_section (abfd, sec);
3151 /* Do the actual output of a file. Assumes mmo_set_section_contents is
3155 mmo_write_object_contents (abfd)
3158 struct mmo_write_sec_info wsecinfo;
3160 /* First, there are a few words of preamble. */
3161 if (! mmo_internal_write_header (abfd))
3164 wsecinfo.reg_section = NULL;
3165 wsecinfo.retval = TRUE;
3167 bfd_map_over_sections (abfd, mmo_write_section_unless_reg_contents,
3170 if (! wsecinfo.retval)
3173 if (wsecinfo.reg_section != NULL)
3175 asection *sec = wsecinfo.reg_section;
3176 unsigned int z = (unsigned int) (sec->vma / 8);
3178 /* Registers 0..31 must not be global. Do sanity check on the "vma"
3179 of the register contents section and check that it corresponds to
3180 the length of the section. */
3181 if (z < 32 || z >= 255 || (sec->vma & 7) != 0
3182 || sec->vma != 256 * 8 - sec->size - 8)
3184 bfd_set_error (bfd_error_bad_value);
3187 /* There must always be at least one such register. */
3188 (*_bfd_error_handler)
3189 (_("%s: no initialized registers; section length 0\n"),
3190 bfd_get_filename (abfd));
3191 else if (sec->vma > (256 - 32) * 8)
3192 /* Provide better error message for the case of too many
3193 global registers. */
3194 (*_bfd_error_handler)
3195 (_("%s: too many initialized registers; section length %ld\n"),
3196 bfd_get_filename (abfd),
3199 (*_bfd_error_handler)
3200 (_("%s: invalid start address for initialized registers of\
3201 length %ld: 0x%lx%08lx\n"),
3202 bfd_get_filename (abfd),
3204 (unsigned long) (sec->vma >> 32), (unsigned long) (sec->vma));
3209 if (! mmo_internal_write_post (abfd, z, sec))
3213 if (! mmo_internal_write_post (abfd, 255, NULL))
3216 return mmo_write_symbols_and_terminator (abfd);
3219 /* Return the size of a NULL pointer, so we support linking in an mmo
3223 mmo_get_reloc_upper_bound (abfd, sec)
3224 bfd *abfd ATTRIBUTE_UNUSED;
3225 asection *sec ATTRIBUTE_UNUSED;
3227 return sizeof (PTR);
3230 /* Similarly canonicalize relocs to empty, filling in the terminating NULL
3234 mmo_canonicalize_reloc (abfd, section, relptr, symbols)
3235 bfd *abfd ATTRIBUTE_UNUSED;
3236 sec_ptr section ATTRIBUTE_UNUSED;
3238 asymbol **symbols ATTRIBUTE_UNUSED;
3244 /* If there's anything in particular in a mmo bfd that we want to free,
3245 make this a real function. Only do this if you see major memory
3246 thrashing; zealous free:ing will cause unwanted behavior, especially if
3247 you "free" memory allocated with "bfd_alloc", or even "bfd_release" a
3248 block allocated with "bfd_alloc"; they're really allocated from an
3249 obstack, and we don't know what was allocated there since this
3250 particular allocation. */
3252 #define mmo_close_and_cleanup _bfd_generic_close_and_cleanup
3253 #define mmo_bfd_free_cached_info _bfd_generic_bfd_free_cached_info
3255 /* Perhaps we need to adjust this one; mmo labels (originally) without a
3256 leading ':' might more appropriately be called local. */
3257 #define mmo_bfd_is_local_label_name bfd_generic_is_local_label_name
3258 #define mmo_bfd_is_target_special_symbol \
3259 ((bfd_boolean (*) (bfd *, asymbol *)) bfd_false)
3261 /* Is this one really used or defined by anyone? */
3262 #define mmo_get_lineno _bfd_nosymbols_get_lineno
3264 /* FIXME: We can do better on this one, if we have a dwarf2 .debug_line
3265 section or if MMO line numbers are implemented. */
3266 #define mmo_find_nearest_line _bfd_nosymbols_find_nearest_line
3267 #define mmo_make_empty_symbol _bfd_generic_make_empty_symbol
3268 #define mmo_bfd_make_debug_symbol _bfd_nosymbols_bfd_make_debug_symbol
3269 #define mmo_read_minisymbols _bfd_generic_read_minisymbols
3270 #define mmo_minisymbol_to_symbol _bfd_generic_minisymbol_to_symbol
3272 #define mmo_get_section_contents_in_window \
3273 _bfd_generic_get_section_contents_in_window
3274 #define mmo_bfd_get_relocated_section_contents \
3275 bfd_generic_get_relocated_section_contents
3276 #define mmo_bfd_gc_sections bfd_generic_gc_sections
3277 #define mmo_bfd_link_hash_table_create _bfd_generic_link_hash_table_create
3278 #define mmo_bfd_link_hash_table_free _bfd_generic_link_hash_table_free
3279 #define mmo_bfd_link_add_symbols _bfd_generic_link_add_symbols
3280 #define mmo_bfd_link_just_syms _bfd_generic_link_just_syms
3281 #define mmo_bfd_final_link _bfd_generic_final_link
3282 #define mmo_bfd_link_split_section _bfd_generic_link_split_section
3284 /* Strictly speaking, only MMIX uses this restricted format, but let's not
3285 stop anybody from shooting themselves in the foot. */
3286 #define mmo_set_arch_mach bfd_default_set_arch_mach
3287 #define mmo_bfd_relax_section bfd_generic_relax_section
3288 #define mmo_bfd_merge_sections bfd_generic_merge_sections
3289 #define mmo_bfd_is_group_section bfd_generic_is_group_section
3290 #define mmo_bfd_discard_group bfd_generic_discard_group
3291 #define mmo_section_already_linked \
3292 _bfd_generic_section_already_linked
3294 /* objcopy will be upset if we return -1 from bfd_get_reloc_upper_bound by
3295 using BFD_JUMP_TABLE_RELOCS (_bfd_norelocs) rather than 0. FIXME: Most
3296 likely a bug in the _bfd_norelocs definition.
3298 On the other hand, we smuggle in an mmo object (because setting up ELF
3299 is too cumbersome) when linking (from other formats, presumably ELF) to
3300 represent the g255 entry. We need to link that object, so need to say
3301 it has no relocs. Upper bound for the size of the relocation table is
3302 the size of a NULL pointer, and we support "canonicalization" for that
3304 #define mmo_bfd_reloc_type_lookup _bfd_norelocs_bfd_reloc_type_lookup
3306 /* We want to copy time of creation, otherwise we'd use
3307 BFD_JUMP_TABLE_COPY (_bfd_generic). */
3308 #define mmo_bfd_merge_private_bfd_data _bfd_generic_bfd_merge_private_bfd_data
3309 #define mmo_bfd_copy_private_section_data _bfd_generic_bfd_copy_private_section_data
3310 #define mmo_bfd_copy_private_symbol_data _bfd_generic_bfd_copy_private_symbol_data
3311 #define mmo_bfd_copy_private_header_data _bfd_generic_bfd_copy_private_header_data
3312 #define mmo_bfd_set_private_flags _bfd_generic_bfd_set_private_flags
3313 #define mmo_bfd_print_private_bfd_data _bfd_generic_bfd_print_private_bfd_data
3315 const bfd_target bfd_mmo_vec =
3318 bfd_target_mmo_flavour,
3319 BFD_ENDIAN_BIG, /* target byte order */
3320 BFD_ENDIAN_BIG, /* target headers byte order */
3322 /* FIXME: Might need adjustments. */
3323 (HAS_RELOC | EXEC_P | /* object flags */
3324 HAS_LINENO | HAS_DEBUG |
3325 HAS_SYMS | HAS_LOCALS | WP_TEXT),
3327 /* FIXME: Might need adjustments. */
3328 (SEC_CODE | SEC_DATA | SEC_HAS_CONTENTS | SEC_ALLOC | SEC_LOAD
3329 | SEC_READONLY | SEC_EXCLUDE | SEC_DEBUGGING | SEC_IN_MEMORY),
3331 0, /* leading underscore */
3332 ' ', /* ar_pad_char */
3333 16, /* ar_max_namelen */
3334 bfd_getb64, bfd_getb_signed_64, bfd_putb64,
3335 bfd_getb32, bfd_getb_signed_32, bfd_putb32,
3336 bfd_getb16, bfd_getb_signed_16, bfd_putb16, /* data */
3337 bfd_getb64, bfd_getb_signed_64, bfd_putb64,
3338 bfd_getb32, bfd_getb_signed_32, bfd_putb32,
3339 bfd_getb16, bfd_getb_signed_16, bfd_putb16, /* hdrs */
3343 mmo_object_p, /* bfd_check_format */
3353 { /* bfd_write_contents */
3355 mmo_write_object_contents,
3360 BFD_JUMP_TABLE_GENERIC (mmo),
3361 BFD_JUMP_TABLE_COPY (mmo),
3362 BFD_JUMP_TABLE_CORE (_bfd_nocore),
3363 BFD_JUMP_TABLE_ARCHIVE (_bfd_noarchive),
3364 BFD_JUMP_TABLE_SYMBOLS (mmo),
3365 /* We have to provide a valid method for getting relocs, returning zero,
3366 so we can't say BFD_JUMP_TABLE_RELOCS (_bfd_norelocs). */
3367 BFD_JUMP_TABLE_RELOCS (mmo),
3368 BFD_JUMP_TABLE_WRITE (mmo),
3369 BFD_JUMP_TABLE_LINK (mmo),
3370 BFD_JUMP_TABLE_DYNAMIC (_bfd_nodynamic),