1 /* BFD back-end for binary objects.
2 Copyright 1994 Free Software Foundation, Inc.
3 Written by Ian Lance Taylor, Cygnus Support, <ian@cygnus.com>
5 This file is part of BFD, the Binary File Descriptor library.
7 This program is free software; you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by
9 the Free Software Foundation; either version 2 of the License, or
10 (at your option) any later version.
12 This program is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
17 You should have received a copy of the GNU General Public License
18 along with this program; if not, write to the Free Software
19 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */
21 /* This is a BFD backend which may be used to write binary objects.
22 It may only be used for output, not input. The intention is that
23 this may be used as an output format for objcopy in order to
24 generate raw binary data.
26 This is very simple. The only complication is that the real data
27 will start at some address X, and in some cases we will not want to
28 include X zeroes just to get to that point. Since the start
29 address is not meaningful for this object file format, we use it
30 instead to indicate the number of zeroes to skip at the start of
31 the file. objcopy cooperates by specially setting the start
32 address to zero by default. */
38 static boolean binary_mkobject
PARAMS ((bfd
*));
39 static asymbol
*binary_make_empty_symbol
PARAMS ((bfd
*));
40 static boolean binary_set_section_contents
41 PARAMS ((bfd
*, asection
*, PTR
, file_ptr
, bfd_size_type
));
43 /* Create a binary object. Invoked via bfd_set_format. */
46 binary_mkobject (abfd
)
52 /* Most of the symbol routines can just return an error. */
53 #define binary_get_symtab_upper_bound _bfd_nosymbols_get_symtab_upper_bound
54 #define binary_get_symtab _bfd_nosymbols_get_symtab
55 #define binary_print_symbol _bfd_nosymbols_print_symbol
56 #define binary_get_symbol_info _bfd_nosymbols_get_symbol_info
57 #define binary_bfd_is_local_label _bfd_nosymbols_bfd_is_local_label
58 #define binary_get_lineno _bfd_nosymbols_get_lineno
59 #define binary_find_nearest_line _bfd_nosymbols_find_nearest_line
60 #define binary_bfd_make_debug_symbol _bfd_nosymbols_bfd_make_debug_symbol
62 /* We do have to provide a routine to make an empty symbol. */
65 binary_make_empty_symbol (abfd
)
70 ret
= (asymbol
*) bfd_alloc (abfd
, sizeof (asymbol
));
72 bfd_set_error (bfd_error_no_memory
);
76 /* Set the architecture of a binary file. */
77 #define binary_set_arch_mach _bfd_generic_set_arch_mach
79 /* Write section contents of a binary file. */
82 binary_set_section_contents (abfd
, sec
, data
, offset
, size
)
89 /* In a binary file, the file position of a section is just the VMA
90 minus the start address. */
91 sec
->filepos
= bfd_section_vma (abfd
, sec
) - bfd_get_start_address (abfd
);
93 if (sec
->filepos
+ offset
< 0)
97 adjust
= - (sec
->filepos
+ offset
);
101 data
= (PTR
) ((bfd_byte
*) data
+ adjust
);
105 return _bfd_generic_set_section_contents (abfd
, sec
, data
, offset
, size
);
108 const bfd_target binary_vec
=
111 bfd_target_unknown_flavour
, /* flavour */
112 true, /* byteorder_big_p */
113 true, /* header_byteorder_big_p */
114 EXEC_P
, /* object_flags */
115 (SEC_ALLOC
| SEC_LOAD
| SEC_READONLY
| SEC_CODE
| SEC_DATA
116 | SEC_ROM
| SEC_HAS_CONTENTS
), /* section_flags */
117 0, /* symbol_leading_char */
118 ' ', /* ar_pad_char */
119 16, /* ar_max_namelen */
120 1, /* align_power_min */
121 bfd_getb64
, bfd_getb_signed_64
, bfd_putb64
,
122 bfd_getb32
, bfd_getb_signed_32
, bfd_putb32
,
123 bfd_getb16
, bfd_getb_signed_16
, bfd_putb16
, /* data */
124 bfd_getb64
, bfd_getb_signed_64
, bfd_putb64
,
125 bfd_getb32
, bfd_getb_signed_32
, bfd_putb32
,
126 bfd_getb16
, bfd_getb_signed_16
, bfd_putb16
, /* hdrs */
127 { /* bfd_check_format */
133 { /* bfd_set_format */
139 { /* bfd_write_contents */
146 BFD_JUMP_TABLE_GENERIC (_bfd_generic
),
147 BFD_JUMP_TABLE_COPY (_bfd_generic
),
148 BFD_JUMP_TABLE_CORE (_bfd_nocore
),
149 BFD_JUMP_TABLE_ARCHIVE (_bfd_noarchive
),
150 BFD_JUMP_TABLE_SYMBOLS (binary
),
151 BFD_JUMP_TABLE_RELOCS (_bfd_norelocs
),
152 BFD_JUMP_TABLE_WRITE (binary
),
153 BFD_JUMP_TABLE_LINK (_bfd_nolink
),
154 BFD_JUMP_TABLE_DYNAMIC (_bfd_nodynamic
),