Commit | Line | Data |
---|---|---|
c768bd3f ILT |
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> | |
4 | ||
5 | This file is part of BFD, the Binary File Descriptor library. | |
6 | ||
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. | |
11 | ||
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. | |
16 | ||
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. */ | |
20 | ||
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. | |
25 | ||
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. */ | |
33 | ||
34 | #include "bfd.h" | |
35 | #include "sysdep.h" | |
36 | #include "libbfd.h" | |
37 | ||
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)); | |
42 | ||
43 | /* Create a binary object. Invoked via bfd_set_format. */ | |
44 | ||
45 | static boolean | |
46 | binary_mkobject (abfd) | |
47 | bfd *abfd; | |
48 | { | |
49 | return true; | |
50 | } | |
51 | ||
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 | |
61 | ||
62 | /* We do have to provide a routine to make an empty symbol. */ | |
63 | ||
64 | static asymbol * | |
65 | binary_make_empty_symbol (abfd) | |
66 | bfd *abfd; | |
67 | { | |
68 | asymbol *ret; | |
69 | ||
70 | ret = (asymbol *) bfd_alloc (abfd, sizeof (asymbol)); | |
71 | if (ret == NULL) | |
72 | bfd_set_error (bfd_error_no_memory); | |
73 | return ret; | |
74 | } | |
75 | ||
76 | /* Set the architecture of a binary file. */ | |
77 | #define binary_set_arch_mach _bfd_generic_set_arch_mach | |
78 | ||
79 | /* Write section contents of a binary file. */ | |
80 | ||
81 | static boolean | |
82 | binary_set_section_contents (abfd, sec, data, offset, size) | |
83 | bfd *abfd; | |
84 | asection *sec; | |
85 | PTR data; | |
86 | file_ptr offset; | |
87 | bfd_size_type size; | |
88 | { | |
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); | |
92 | ||
93 | if (sec->filepos + offset < 0) | |
94 | { | |
95 | file_ptr adjust; | |
96 | ||
97 | adjust = - (sec->filepos + offset); | |
98 | if (size <= adjust) | |
99 | return true; | |
100 | size -= adjust; | |
101 | data = (PTR) ((bfd_byte *) data + adjust); | |
102 | offset += adjust; | |
103 | } | |
104 | ||
105 | return _bfd_generic_set_section_contents (abfd, sec, data, offset, size); | |
106 | } | |
107 | ||
108 | const bfd_target binary_vec = | |
109 | { | |
110 | "binary", /* name */ | |
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 */ | |
128 | _bfd_dummy_target, | |
129 | _bfd_dummy_target, | |
130 | _bfd_dummy_target, | |
131 | _bfd_dummy_target, | |
132 | }, | |
133 | { /* bfd_set_format */ | |
134 | bfd_false, | |
135 | binary_mkobject, | |
136 | bfd_false, | |
137 | bfd_false, | |
138 | }, | |
139 | { /* bfd_write_contents */ | |
140 | bfd_false, | |
141 | bfd_true, | |
142 | bfd_false, | |
143 | bfd_false, | |
144 | }, | |
145 | ||
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), | |
155 | ||
156 | NULL | |
157 | }; |