00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037
00038
00039 #include "bfd.h"
00040 #include "sysdep.h"
00041 #include "safe-ctype.h"
00042 #include "libbfd.h"
00043
00044
00045
00046 #define BIN_SYMS 3
00047
00048 static bfd_boolean binary_mkobject PARAMS ((bfd *));
00049 static const bfd_target *binary_object_p PARAMS ((bfd *));
00050 static bfd_boolean binary_get_section_contents
00051 PARAMS ((bfd *, asection *, PTR, file_ptr, bfd_size_type));
00052 static long binary_get_symtab_upper_bound PARAMS ((bfd *));
00053 static char *mangle_name PARAMS ((bfd *, char *));
00054 static long binary_canonicalize_symtab PARAMS ((bfd *, asymbol **));
00055 static void binary_get_symbol_info PARAMS ((bfd *, asymbol *, symbol_info *));
00056 static bfd_boolean binary_set_section_contents
00057 PARAMS ((bfd *, asection *, const PTR, file_ptr, bfd_size_type));
00058 static int binary_sizeof_headers PARAMS ((bfd *, bfd_boolean));
00059
00060
00061
00062 enum bfd_architecture bfd_external_binary_architecture = bfd_arch_unknown;
00063 unsigned long bfd_external_machine = 0;
00064
00065
00066
00067 static bfd_boolean
00068 binary_mkobject (abfd)
00069 bfd *abfd ATTRIBUTE_UNUSED;
00070 {
00071 return TRUE;
00072 }
00073
00074
00075
00076
00077
00078 static const bfd_target *
00079 binary_object_p (abfd)
00080 bfd *abfd;
00081 {
00082 struct stat statbuf;
00083 asection *sec;
00084
00085 if (abfd->target_defaulted)
00086 {
00087 bfd_set_error (bfd_error_wrong_format);
00088 return NULL;
00089 }
00090
00091 abfd->symcount = BIN_SYMS;
00092
00093
00094 if (bfd_stat (abfd, &statbuf) < 0)
00095 {
00096 bfd_set_error (bfd_error_system_call);
00097 return NULL;
00098 }
00099
00100
00101 sec = bfd_make_section (abfd, ".data");
00102 if (sec == NULL)
00103 return NULL;
00104 sec->flags = SEC_ALLOC | SEC_LOAD | SEC_DATA | SEC_HAS_CONTENTS;
00105 sec->vma = 0;
00106 sec->size = statbuf.st_size;
00107 sec->filepos = 0;
00108
00109 abfd->tdata.any = (PTR) sec;
00110
00111 if (bfd_get_arch_info (abfd) != NULL)
00112 {
00113 if ((bfd_get_arch_info (abfd)->arch == bfd_arch_unknown)
00114 && (bfd_external_binary_architecture != bfd_arch_unknown))
00115 bfd_set_arch_info (abfd, bfd_lookup_arch
00116 (bfd_external_binary_architecture, bfd_external_machine));
00117 }
00118
00119 return abfd->xvec;
00120 }
00121
00122 #define binary_close_and_cleanup _bfd_generic_close_and_cleanup
00123 #define binary_bfd_free_cached_info _bfd_generic_bfd_free_cached_info
00124 #define binary_new_section_hook _bfd_generic_new_section_hook
00125
00126
00127
00128 static bfd_boolean
00129 binary_get_section_contents (abfd, section, location, offset, count)
00130 bfd *abfd;
00131 asection *section ATTRIBUTE_UNUSED;
00132 PTR location;
00133 file_ptr offset;
00134 bfd_size_type count;
00135 {
00136 if (bfd_seek (abfd, offset, SEEK_SET) != 0
00137 || bfd_bread (location, count, abfd) != count)
00138 return FALSE;
00139 return TRUE;
00140 }
00141
00142
00143
00144 static long
00145 binary_get_symtab_upper_bound (abfd)
00146 bfd *abfd ATTRIBUTE_UNUSED;
00147 {
00148 return (BIN_SYMS + 1) * sizeof (asymbol *);
00149 }
00150
00151
00152
00153 static char *
00154 mangle_name (abfd, suffix)
00155 bfd *abfd;
00156 char *suffix;
00157 {
00158 bfd_size_type size;
00159 char *buf;
00160 char *p;
00161
00162 size = (strlen (bfd_get_filename (abfd))
00163 + strlen (suffix)
00164 + sizeof "_binary__");
00165
00166 buf = (char *) bfd_alloc (abfd, size);
00167 if (buf == NULL)
00168 return "";
00169
00170 sprintf (buf, "_binary_%s_%s", bfd_get_filename (abfd), suffix);
00171
00172
00173 for (p = buf; *p; p++)
00174 if (! ISALNUM (*p))
00175 *p = '_';
00176
00177 return buf;
00178 }
00179
00180
00181
00182 static long
00183 binary_canonicalize_symtab (abfd, alocation)
00184 bfd *abfd;
00185 asymbol **alocation;
00186 {
00187 asection *sec = (asection *) abfd->tdata.any;
00188 asymbol *syms;
00189 unsigned int i;
00190 bfd_size_type amt = BIN_SYMS * sizeof (asymbol);
00191
00192 syms = (asymbol *) bfd_alloc (abfd, amt);
00193 if (syms == NULL)
00194 return 0;
00195
00196
00197 syms[0].the_bfd = abfd;
00198 syms[0].name = mangle_name (abfd, "start");
00199 syms[0].value = 0;
00200 syms[0].flags = BSF_GLOBAL;
00201 syms[0].section = sec;
00202 syms[0].udata.p = NULL;
00203
00204
00205 syms[1].the_bfd = abfd;
00206 syms[1].name = mangle_name (abfd, "end");
00207 syms[1].value = sec->size;
00208 syms[1].flags = BSF_GLOBAL;
00209 syms[1].section = sec;
00210 syms[1].udata.p = NULL;
00211
00212
00213 syms[2].the_bfd = abfd;
00214 syms[2].name = mangle_name (abfd, "size");
00215 syms[2].value = sec->size;
00216 syms[2].flags = BSF_GLOBAL;
00217 syms[2].section = bfd_abs_section_ptr;
00218 syms[2].udata.p = NULL;
00219
00220 for (i = 0; i < BIN_SYMS; i++)
00221 *alocation++ = syms++;
00222 *alocation = NULL;
00223
00224 return BIN_SYMS;
00225 }
00226
00227 #define binary_make_empty_symbol _bfd_generic_make_empty_symbol
00228 #define binary_print_symbol _bfd_nosymbols_print_symbol
00229
00230
00231
00232 static void
00233 binary_get_symbol_info (ignore_abfd, symbol, ret)
00234 bfd *ignore_abfd ATTRIBUTE_UNUSED;
00235 asymbol *symbol;
00236 symbol_info *ret;
00237 {
00238 bfd_symbol_info (symbol, ret);
00239 }
00240
00241 #define binary_bfd_is_target_special_symbol ((bfd_boolean (*) (bfd *, asymbol *)) bfd_false)
00242 #define binary_bfd_is_local_label_name bfd_generic_is_local_label_name
00243 #define binary_get_lineno _bfd_nosymbols_get_lineno
00244 #define binary_find_nearest_line _bfd_nosymbols_find_nearest_line
00245 #define binary_bfd_make_debug_symbol _bfd_nosymbols_bfd_make_debug_symbol
00246 #define binary_read_minisymbols _bfd_generic_read_minisymbols
00247 #define binary_minisymbol_to_symbol _bfd_generic_minisymbol_to_symbol
00248
00249 #define binary_get_reloc_upper_bound \
00250 ((long (*) PARAMS ((bfd *, asection *))) bfd_0l)
00251 #define binary_canonicalize_reloc \
00252 ((long (*) PARAMS ((bfd *, asection *, arelent **, asymbol **))) bfd_0l)
00253 #define binary_bfd_reloc_type_lookup _bfd_norelocs_bfd_reloc_type_lookup
00254
00255
00256 #define binary_set_arch_mach _bfd_generic_set_arch_mach
00257
00258
00259
00260 static bfd_boolean
00261 binary_set_section_contents (abfd, sec, data, offset, size)
00262 bfd *abfd;
00263 asection *sec;
00264 const PTR data;
00265 file_ptr offset;
00266 bfd_size_type size;
00267 {
00268 if (size == 0)
00269 return TRUE;
00270
00271 if (! abfd->output_has_begun)
00272 {
00273 bfd_boolean found_low;
00274 bfd_vma low;
00275 asection *s;
00276
00277
00278
00279
00280 found_low = FALSE;
00281 low = 0;
00282 for (s = abfd->sections; s != NULL; s = s->next)
00283 if (((s->flags
00284 & (SEC_HAS_CONTENTS | SEC_LOAD | SEC_ALLOC | SEC_NEVER_LOAD))
00285 == (SEC_HAS_CONTENTS | SEC_LOAD | SEC_ALLOC))
00286 && (s->size > 0)
00287 && (! found_low || s->lma < low))
00288 {
00289 low = s->lma;
00290 found_low = TRUE;
00291 }
00292
00293 for (s = abfd->sections; s != NULL; s = s->next)
00294 {
00295 s->filepos = s->lma - low;
00296
00297
00298
00299 if ((s->flags
00300 & (SEC_HAS_CONTENTS | SEC_ALLOC | SEC_NEVER_LOAD))
00301 != (SEC_HAS_CONTENTS | SEC_ALLOC)
00302 || (s->size == 0))
00303 continue;
00304
00305
00306
00307
00308
00309
00310
00311 if (s->filepos < 0)
00312 (*_bfd_error_handler)
00313 (_("Warning: Writing section `%s' to huge (ie negative) file offset 0x%lx."),
00314 bfd_get_section_name (abfd, s),
00315 (unsigned long) s->filepos);
00316 }
00317
00318 abfd->output_has_begun = TRUE;
00319 }
00320
00321
00322
00323
00324 if ((sec->flags & (SEC_LOAD | SEC_ALLOC)) == 0)
00325 return TRUE;
00326 if ((sec->flags & SEC_NEVER_LOAD) != 0)
00327 return TRUE;
00328
00329 return _bfd_generic_set_section_contents (abfd, sec, data, offset, size);
00330 }
00331
00332
00333
00334 static int
00335 binary_sizeof_headers (abfd, exec)
00336 bfd *abfd ATTRIBUTE_UNUSED;
00337 bfd_boolean exec ATTRIBUTE_UNUSED;
00338 {
00339 return 0;
00340 }
00341
00342 #define binary_bfd_get_relocated_section_contents \
00343 bfd_generic_get_relocated_section_contents
00344 #define binary_bfd_relax_section bfd_generic_relax_section
00345 #define binary_bfd_gc_sections bfd_generic_gc_sections
00346 #define binary_bfd_merge_sections bfd_generic_merge_sections
00347 #define binary_bfd_is_group_section bfd_generic_is_group_section
00348 #define binary_bfd_discard_group bfd_generic_discard_group
00349 #define binary_section_already_linked \
00350 _bfd_generic_section_already_linked
00351 #define binary_bfd_link_hash_table_create _bfd_generic_link_hash_table_create
00352 #define binary_bfd_link_hash_table_free _bfd_generic_link_hash_table_free
00353 #define binary_bfd_link_just_syms _bfd_generic_link_just_syms
00354 #define binary_bfd_link_add_symbols _bfd_generic_link_add_symbols
00355 #define binary_bfd_final_link _bfd_generic_final_link
00356 #define binary_bfd_link_split_section _bfd_generic_link_split_section
00357 #define binary_get_section_contents_in_window \
00358 _bfd_generic_get_section_contents_in_window
00359
00360 const bfd_target binary_vec =
00361 {
00362 "binary",
00363 bfd_target_unknown_flavour,
00364 BFD_ENDIAN_UNKNOWN,
00365 BFD_ENDIAN_UNKNOWN,
00366 EXEC_P,
00367 (SEC_ALLOC | SEC_LOAD | SEC_READONLY | SEC_CODE | SEC_DATA
00368 | SEC_ROM | SEC_HAS_CONTENTS),
00369 0,
00370 ' ',
00371 16,
00372 bfd_getb64, bfd_getb_signed_64, bfd_putb64,
00373 bfd_getb32, bfd_getb_signed_32, bfd_putb32,
00374 bfd_getb16, bfd_getb_signed_16, bfd_putb16,
00375 bfd_getb64, bfd_getb_signed_64, bfd_putb64,
00376 bfd_getb32, bfd_getb_signed_32, bfd_putb32,
00377 bfd_getb16, bfd_getb_signed_16, bfd_putb16,
00378 {
00379 _bfd_dummy_target,
00380 binary_object_p,
00381 _bfd_dummy_target,
00382 _bfd_dummy_target,
00383 },
00384 {
00385 bfd_false,
00386 binary_mkobject,
00387 bfd_false,
00388 bfd_false,
00389 },
00390 {
00391 bfd_false,
00392 bfd_true,
00393 bfd_false,
00394 bfd_false,
00395 },
00396
00397 BFD_JUMP_TABLE_GENERIC (binary),
00398 BFD_JUMP_TABLE_COPY (_bfd_generic),
00399 BFD_JUMP_TABLE_CORE (_bfd_nocore),
00400 BFD_JUMP_TABLE_ARCHIVE (_bfd_noarchive),
00401 BFD_JUMP_TABLE_SYMBOLS (binary),
00402 BFD_JUMP_TABLE_RELOCS (binary),
00403 BFD_JUMP_TABLE_WRITE (binary),
00404 BFD_JUMP_TABLE_LINK (binary),
00405 BFD_JUMP_TABLE_DYNAMIC (_bfd_nodynamic),
00406
00407 NULL,
00408
00409 NULL
00410 };