Changeset 609 for branches/GNU/src/binutils/bfd/oasys.c
- Timestamp:
- Aug 16, 2003, 6:59:22 PM (22 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/GNU/src/binutils/bfd/oasys.c
-
Property cvs2svn:cvs-rev
changed from
1.1
to1.1.1.2
r608 r609 1 1 /* BFD back-end for oasys objects. 2 Copyright 1990, 1991, 1992, 1993, 1994, 1995, 1996, 1998, 1999 3 Free Software Foundation, Inc.2 Copyright 1990, 1991, 1992, 1993, 1994, 1995, 1996, 1998, 1999, 2001, 3 2002, 2003 Free Software Foundation, Inc. 4 4 Written by Steve Chamberlain of Cygnus Support, <sac@cygnus.com>. 5 5 6 This file is part of BFD, the Binary File Descriptor library.7 8 This program is free software; you can redistribute it and/or modify9 it under the terms of the GNU General Public License as published by10 the Free Software Foundation; either version 2 of the License, or11 (at your option) any later version.12 13 This program is distributed in the hope that it will be useful,14 but WITHOUT ANY WARRANTY; without even the implied warranty of15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the16 GNU General Public License for more details.17 18 You should have received a copy of the GNU General Public License19 along with this program; if not, write to the Free Software20 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */6 This file is part of BFD, the Binary File Descriptor library. 7 8 This program is free software; you can redistribute it and/or modify 9 it under the terms of the GNU General Public License as published by 10 the Free Software Foundation; either version 2 of the License, or 11 (at your option) any later version. 12 13 This program is distributed in the hope that it will be useful, 14 but WITHOUT ANY WARRANTY; without even the implied warranty of 15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 16 GNU General Public License for more details. 17 18 You should have received a copy of the GNU General Public License 19 along with this program; if not, write to the Free Software 20 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ 21 21 22 22 #define UNDERSCORE_HACK 1 23 23 #include "bfd.h" 24 24 #include "sysdep.h" 25 #include <ctype.h>25 #include "safe-ctype.h" 26 26 #include "libbfd.h" 27 27 #include "oasys.h" 28 28 #include "liboasys.h" 29 29 30 /* XXX - FIXME. offsetof belongs in the system-specific files in 31 ../include/sys. */ 32 /* Define offsetof for those systems which lack it */ 33 34 #ifndef offsetof 35 #define offsetof(type, identifier) (size_t) &(((type *) 0)->identifier) 36 #endif 37 38 static boolean oasys_read_record PARAMS ((bfd *, 39 oasys_record_union_type *)); 40 static boolean oasys_write_sections PARAMS ((bfd *)); 41 static boolean oasys_write_record PARAMS ((bfd *, 42 oasys_record_enum_type, 43 oasys_record_union_type *, 44 size_t)); 45 static boolean oasys_write_syms PARAMS ((bfd *)); 46 static boolean oasys_write_header PARAMS ((bfd *)); 47 static boolean oasys_write_end PARAMS ((bfd *)); 48 static boolean oasys_write_data PARAMS ((bfd *)); 49 50 /* Read in all the section data and relocation stuff too */ 51 PROTO (static boolean, oasys_slurp_section_data, (bfd * CONST abfd)); 52 53 static boolean 30 static bfd_boolean oasys_slurp_section_data 31 PARAMS ((bfd * const)); 32 static bfd_boolean oasys_read_record 33 PARAMS ((bfd *, oasys_record_union_type *)); 34 static bfd_boolean oasys_write_sections 35 PARAMS ((bfd *)); 36 static bfd_boolean oasys_write_record 37 PARAMS ((bfd *, oasys_record_enum_type, oasys_record_union_type *, size_t)); 38 static bfd_boolean oasys_write_syms 39 PARAMS ((bfd *)); 40 static bfd_boolean oasys_write_header 41 PARAMS ((bfd *)); 42 static bfd_boolean oasys_write_end 43 PARAMS ((bfd *)); 44 static bfd_boolean oasys_write_data 45 PARAMS ((bfd *)); 46 static size_t oasys_string_length 47 PARAMS ((oasys_record_union_type *)); 48 static bfd_boolean oasys_slurp_symbol_table 49 PARAMS ((bfd *const)); 50 static long int oasys_get_symtab_upper_bound 51 PARAMS ((bfd *const)); 52 static const bfd_target *oasys_archive_p 53 PARAMS ((bfd *)); 54 static bfd_boolean oasys_mkobject 55 PARAMS ((bfd *)); 56 static const bfd_target *oasys_object_p 57 PARAMS ((bfd *)); 58 static void oasys_get_symbol_info 59 PARAMS ((bfd *, asymbol *, symbol_info *)); 60 static void oasys_print_symbol 61 PARAMS ((bfd *, void *, asymbol *, bfd_print_symbol_type)); 62 static bfd_boolean oasys_new_section_hook 63 PARAMS ((bfd *, asection *)); 64 static long int oasys_get_reloc_upper_bound 65 PARAMS ((bfd *, sec_ptr)); 66 static bfd_boolean oasys_get_section_contents 67 PARAMS ((bfd *, sec_ptr, void *, file_ptr, bfd_size_type)); 68 static int comp 69 PARAMS ((const void *, const void *)); 70 static bfd_boolean oasys_write_object_contents 71 PARAMS ((bfd *)); 72 static bfd_boolean oasys_set_section_contents 73 PARAMS ((bfd *, sec_ptr, void *, file_ptr, bfd_size_type)); 74 static asymbol *oasys_make_empty_symbol 75 PARAMS ((bfd *)); 76 static bfd *oasys_openr_next_archived_file 77 PARAMS ((bfd *, bfd *)); 78 static bfd_boolean oasys_find_nearest_line 79 PARAMS ((bfd *, asection *, asymbol **, bfd_vma, 80 const char **, const char **, unsigned int *)); 81 static int oasys_generic_stat_arch_elt 82 PARAMS ((bfd *, struct stat *)); 83 static int oasys_sizeof_headers 84 PARAMS ((bfd *, bfd_boolean)); 85 86 long oasys_get_symtab 87 PARAMS ((bfd *, asymbol **)); 88 long oasys_canonicalize_reloc 89 PARAMS ((bfd *, sec_ptr, arelent **, asymbol **)); 90 91 /* Read in all the section data and relocation stuff too. */ 92 93 static bfd_boolean 54 94 oasys_read_record (abfd, record) 55 95 bfd *abfd; 56 96 oasys_record_union_type *record; 57 97 { 58 if (bfd_read ((PTR) record, 1, sizeof (record->header), abfd)59 != sizeof (record->header))60 return false;61 62 if ((size_t) record->header.length <= (size_t) sizeof (record->header))63 return true;64 if (bfd_read ((PTR) (((char *) record) + sizeof (record->header)),65 1, record->header.length - sizeof (record->header), 66 abfd)67 != record->header.length - sizeof (record->header))68 return false;69 return true; 70 } 98 bfd_size_type amt = sizeof (record->header); 99 if (bfd_bread ((PTR) record, amt, abfd) != amt) 100 return FALSE; 101 102 amt = record->header.length - sizeof (record->header); 103 if ((long) amt <= 0) 104 return TRUE; 105 if (bfd_bread ((PTR) ((char *) record + sizeof (record->header)), amt, abfd) 106 != amt) 107 return FALSE; 108 return TRUE; 109 } 110 71 111 static size_t 72 112 oasys_string_length (record) … … 93 133 */ 94 134 95 static b oolean135 static bfd_boolean 96 136 oasys_slurp_symbol_table (abfd) 97 bfd * CONSTabfd;137 bfd *const abfd; 98 138 { 99 139 oasys_record_union_type record; 100 140 oasys_data_type *data = OASYS_DATA (abfd); 101 b oolean loop = true;141 bfd_boolean loop = TRUE; 102 142 asymbol *dest_defined; 103 143 asymbol *dest; 104 144 char *string_ptr; 105 145 bfd_size_type amt; 106 146 107 147 if (data->symbols != (asymbol *) NULL) 108 148 { 109 return true;149 return TRUE; 110 150 } 111 151 /* Buy enough memory for all the symbols and all the names */ 112 data->symbols = 113 (asymbol *) bfd_alloc (abfd, sizeof (asymbol) * abfd->symcount); 152 amt = abfd->symcount; 153 amt *= sizeof (asymbol); 154 data->symbols = (asymbol *) bfd_alloc (abfd, amt); 155 156 amt = data->symbol_string_length; 114 157 #ifdef UNDERSCORE_HACK 115 158 /* buy 1 more char for each symbol to keep the underscore in*/ 116 data->strings = bfd_alloc (abfd, data->symbol_string_length + 117 abfd->symcount); 118 #else 119 data->strings = bfd_alloc (abfd, data->symbol_string_length); 159 amt += abfd->symcount; 120 160 #endif 161 data->strings = bfd_alloc (abfd, amt); 162 121 163 if (!data->symbols || !data->strings) 122 return false;164 return FALSE; 123 165 124 166 dest_defined = data->symbols + abfd->symcount - 1; … … 126 168 string_ptr = data->strings; 127 169 if (bfd_seek (abfd, (file_ptr) 0, SEEK_SET) != 0) 128 return false;170 return FALSE; 129 171 while (loop) 130 172 { 131 173 132 174 if (! oasys_read_record (abfd, &record)) 133 return false;175 return FALSE; 134 176 switch (record.header.type) 135 177 { … … 175 217 break; 176 218 case RELOCATION_TYPE_UND: 177 dest = data->symbols + bfd_h_get_16 (abfd, record.symbol.refno);219 dest = data->symbols + H_GET_16 (abfd, record.symbol.refno); 178 220 dest->section = bfd_und_section_ptr; 179 221 break; … … 194 236 dest->the_bfd = abfd; 195 237 dest->udata.p = (PTR) NULL; 196 dest->value = bfd_h_get_32 (abfd, record.symbol.value);238 dest->value = H_GET_32 (abfd, record.symbol.value); 197 239 198 240 #ifdef UNDERSCORE_HACK … … 211 253 break; 212 254 default: 213 loop = false;255 loop = FALSE; 214 256 } 215 257 } 216 return true;258 return TRUE; 217 259 } 218 260 219 261 static long 220 262 oasys_get_symtab_upper_bound (abfd) 221 bfd * CONSTabfd;263 bfd *const abfd; 222 264 { 223 265 if (! oasys_slurp_symbol_table (abfd)) … … 227 269 } 228 270 229 /*230 */231 232 271 extern const bfd_target oasys_vec; 233 272 … … 239 278 asymbol *symbase; 240 279 unsigned int counter; 241 if ( oasys_slurp_symbol_table (abfd) == false)280 if (! oasys_slurp_symbol_table (abfd)) 242 281 { 243 282 return -1; … … 264 303 unsigned int i; 265 304 file_ptr filepos; 266 267 if (bfd_seek (abfd, (file_ptr) 0, false) != 0 268 || (bfd_read ((PTR) & header_ext, 1, sizeof (header_ext), abfd) 269 != sizeof (header_ext))) 305 bfd_size_type amt; 306 307 amt = sizeof (header_ext); 308 if (bfd_seek (abfd, (file_ptr) 0, 0) != 0 309 || bfd_bread ((PTR) &header_ext, amt, abfd) != amt) 270 310 { 271 311 if (bfd_get_error () != bfd_error_system_call) … … 274 314 } 275 315 276 header.version = bfd_h_get_32 (abfd, header_ext.version);277 header.mod_count = bfd_h_get_32 (abfd, header_ext.mod_count);278 header.mod_tbl_offset = bfd_h_get_32 (abfd, header_ext.mod_tbl_offset);279 header.sym_tbl_size = bfd_h_get_32 (abfd, header_ext.sym_tbl_size);280 header.sym_count = bfd_h_get_32 (abfd, header_ext.sym_count);281 header.sym_tbl_offset = bfd_h_get_32 (abfd, header_ext.sym_tbl_offset);282 header.xref_count = bfd_h_get_32 (abfd, header_ext.xref_count);283 header.xref_lst_offset = bfd_h_get_32 (abfd, header_ext.xref_lst_offset);316 header.version = H_GET_32 (abfd, header_ext.version); 317 header.mod_count = H_GET_32 (abfd, header_ext.mod_count); 318 header.mod_tbl_offset = H_GET_32 (abfd, header_ext.mod_tbl_offset); 319 header.sym_tbl_size = H_GET_32 (abfd, header_ext.sym_tbl_size); 320 header.sym_count = H_GET_32 (abfd, header_ext.sym_count); 321 header.sym_tbl_offset = H_GET_32 (abfd, header_ext.sym_tbl_offset); 322 header.xref_count = H_GET_32 (abfd, header_ext.xref_count); 323 header.xref_lst_offset = H_GET_32 (abfd, header_ext.xref_lst_offset); 284 324 285 325 /* … … 300 340 */ 301 341 { 302 oasys_ar_data_type *ar = 303 (oasys_ar_data_type *) bfd_alloc (abfd, sizeof (oasys_ar_data_type)); 304 305 oasys_module_info_type *module = 306 (oasys_module_info_type *) 307 bfd_alloc (abfd, sizeof (oasys_module_info_type) * header.mod_count); 342 oasys_ar_data_type *ar; 343 oasys_module_info_type *module; 308 344 oasys_module_table_type record; 345 346 amt = sizeof (oasys_ar_data_type); 347 ar = (oasys_ar_data_type *) bfd_alloc (abfd, amt); 348 349 amt = header.mod_count; 350 amt *= sizeof (oasys_module_info_type); 351 module = (oasys_module_info_type *) bfd_alloc (abfd, amt); 309 352 310 353 if (!ar || !module) … … 326 369 { 327 370 oasys_extmodule_table_type_a_type record_ext; 328 if (bfd_read ((PTR) & record_ext, 1, sizeof (record_ext), abfd) 329 != sizeof (record_ext)) 371 372 amt = sizeof (record_ext); 373 if (bfd_bread ((PTR) &record_ext, amt, abfd) != amt) 330 374 return NULL; 331 375 332 record.mod_size = bfd_h_get_32 (abfd, record_ext.mod_size);333 record.file_offset = bfd_h_get_32 (abfd, record_ext.file_offset);334 335 record.dep_count = bfd_h_get_32 (abfd, record_ext.dep_count);336 record.depee_count = bfd_h_get_32 (abfd, record_ext.depee_count);337 record.sect_count = bfd_h_get_32 (abfd, record_ext.sect_count);338 339 module[i].name = bfd_alloc (abfd, 33);376 record.mod_size = H_GET_32 (abfd, record_ext.mod_size); 377 record.file_offset = H_GET_32 (abfd, record_ext.file_offset); 378 379 record.dep_count = H_GET_32 (abfd, record_ext.dep_count); 380 record.depee_count = H_GET_32 (abfd, record_ext.depee_count); 381 record.sect_count = H_GET_32 (abfd, record_ext.sect_count); 382 383 module[i].name = bfd_alloc (abfd, (bfd_size_type) 33); 340 384 if (!module[i].name) 341 385 return NULL; … … 351 395 { 352 396 oasys_extmodule_table_type_b_type record_ext; 353 if (bfd_read ((PTR) & record_ext, 1, sizeof (record_ext), abfd) 354 != sizeof (record_ext)) 397 398 amt = sizeof (record_ext); 399 if (bfd_bread ((PTR) &record_ext, amt, abfd) != amt) 355 400 return NULL; 356 401 357 record.mod_size = bfd_h_get_32 (abfd, record_ext.mod_size); 358 record.file_offset = bfd_h_get_32 (abfd, record_ext.file_offset); 359 360 record.dep_count = bfd_h_get_32 (abfd, record_ext.dep_count); 361 record.depee_count = bfd_h_get_32 (abfd, record_ext.depee_count); 362 record.sect_count = bfd_h_get_32 (abfd, record_ext.sect_count); 363 record.module_name_size = bfd_h_get_32 (abfd, record_ext.mod_name_length); 364 365 module[i].name = bfd_alloc (abfd, record.module_name_size + 1); 402 record.mod_size = H_GET_32 (abfd, record_ext.mod_size); 403 record.file_offset = H_GET_32 (abfd, record_ext.file_offset); 404 405 record.dep_count = H_GET_32 (abfd, record_ext.dep_count); 406 record.depee_count = H_GET_32 (abfd, record_ext.depee_count); 407 record.sect_count = H_GET_32 (abfd, record_ext.sect_count); 408 record.module_name_size = H_GET_32 (abfd, 409 record_ext.mod_name_length); 410 411 amt = record.module_name_size; 412 module[i].name = bfd_alloc (abfd, amt + 1); 366 413 if (!module[i].name) 367 414 return NULL; 368 if (bfd_read ((PTR) module[i].name, 1, record.module_name_size, 369 abfd) 370 != record.module_name_size) 415 if (bfd_bread ((PTR) module[i].name, amt, abfd) != amt) 371 416 return NULL; 372 417 module[i].name[record.module_name_size] = 0; 373 filepos += 374 sizeof (record_ext) + 375 record.dep_count * 4 + 376 record.module_name_size + 1; 377 418 filepos += (sizeof (record_ext) 419 + record.dep_count * 4 420 + record.module_name_size + 1); 378 421 } 379 380 422 381 423 module[i].size = record.mod_size; … … 383 425 module[i].abfd = 0; 384 426 } 385 386 427 } 387 428 return abfd->xvec; 388 429 } 389 430 390 static b oolean431 static bfd_boolean 391 432 oasys_mkobject (abfd) 392 433 bfd *abfd; 393 434 { 394 395 abfd->tdata.oasys_obj_data = (oasys_data_type *) bfd_alloc (abfd, sizeof (oasys_data_type));396 return abfd->tdata.oasys_obj_data ? true : false;435 bfd_size_type amt = sizeof (oasys_data_type); 436 abfd->tdata.oasys_obj_data = (oasys_data_type *) bfd_alloc (abfd, amt); 437 return abfd->tdata.oasys_obj_data != NULL; 397 438 } 398 439 … … 404 445 oasys_data_type *oasys; 405 446 oasys_data_type *save = OASYS_DATA (abfd); 406 b oolean loop = true;407 b oolean had_usefull = false;447 bfd_boolean loop = TRUE; 448 bfd_boolean had_usefull = FALSE; 408 449 409 450 abfd->tdata.oasys_obj_data = 0; … … 432 473 { 433 474 case oasys_record_is_header_enum: 434 had_usefull = true;475 had_usefull = TRUE; 435 476 break; 436 477 case oasys_record_is_symbol_enum: … … 439 480 abfd->symcount++; 440 481 oasys->symbol_string_length += 1 + oasys_string_length (&record); 441 had_usefull = true;482 had_usefull = TRUE; 442 483 break; 443 484 case oasys_record_is_section_enum: … … 450 491 goto fail; 451 492 } 452 buffer = bfd_alloc (abfd, 3);493 buffer = bfd_alloc (abfd, (bfd_size_type) 3); 453 494 if (!buffer) 454 495 goto fail; … … 467 508 } 468 509 469 s->_raw_size = bfd_h_get_32 (abfd, record.section.value);470 s->vma = bfd_h_get_32 (abfd, record.section.vma);510 s->_raw_size = H_GET_32 (abfd, record.section.value); 511 s->vma = H_GET_32 (abfd, record.section.vma); 471 512 s->flags = 0; 472 had_usefull = true;513 had_usefull = TRUE; 473 514 } 474 515 break; … … 479 520 case oasys_record_is_named_section_enum: 480 521 case oasys_record_is_end_enum: 481 if ( had_usefull == false)522 if (! had_usefull) 482 523 goto fail; 483 loop = false;524 loop = FALSE; 484 525 break; 485 526 default: … … 526 567 527 568 static void 528 oasys_print_symbol ( ignore_abfd, afile, symbol, how)529 bfd * ignore_abfd ATTRIBUTE_UNUSED;569 oasys_print_symbol (abfd, afile, symbol, how) 570 bfd *abfd; 530 571 PTR afile; 531 572 asymbol *symbol; … … 542 583 case bfd_print_symbol_all: 543 584 { 544 CONSTchar *section_name = symbol->section == (asection *) NULL ?545 ( CONSTchar *) "*abs" : symbol->section->name;546 547 bfd_print_symbol_vandf ( (PTR) file, symbol);585 const char *section_name = symbol->section == (asection *) NULL ? 586 (const char *) "*abs" : symbol->section->name; 587 588 bfd_print_symbol_vandf (abfd, (PTR) file, symbol); 548 589 549 590 fprintf (file, " %-5s %s", … … 561 602 { 562 603 563 HOWTO (0, 0, 1, 16, false, 0, complain_overflow_bitfield, 0, "abs16", true, 0x0000ffff, 0x0000ffff, false),564 HOWTO (0, 0, 2, 32, false, 0, complain_overflow_bitfield, 0, "abs32", true, 0xffffffff, 0xffffffff, false),565 HOWTO (0, 0, 1, 16, true, 0, complain_overflow_signed, 0, "pcrel16", true, 0x0000ffff, 0x0000ffff, false),566 HOWTO (0, 0, 2, 32, true, 0, complain_overflow_signed, 0, "pcrel32", true, 0xffffffff, 0xffffffff, false)604 HOWTO (0, 0, 1, 16, FALSE, 0, complain_overflow_bitfield, 0, "abs16", TRUE, 0x0000ffff, 0x0000ffff, FALSE), 605 HOWTO (0, 0, 2, 32, FALSE, 0, complain_overflow_bitfield, 0, "abs32", TRUE, 0xffffffff, 0xffffffff, FALSE), 606 HOWTO (0, 0, 1, 16, TRUE, 0, complain_overflow_signed, 0, "pcrel16", TRUE, 0x0000ffff, 0x0000ffff, FALSE), 607 HOWTO (0, 0, 2, 32, TRUE, 0, complain_overflow_signed, 0, "pcrel32", TRUE, 0xffffffff, 0xffffffff, FALSE) 567 608 }; 568 609 569 610 /* Read in all the section data and relocation stuff too */ 570 static b oolean611 static bfd_boolean 571 612 oasys_slurp_section_data (abfd) 572 bfd * CONSTabfd;613 bfd *const abfd; 573 614 { 574 615 oasys_record_union_type record; 575 616 oasys_data_type *data = OASYS_DATA (abfd); 576 boolean loop = true; 577 617 bfd_boolean loop = TRUE; 578 618 oasys_per_section_type *per; 579 580 619 asection *s; 620 bfd_size_type amt; 581 621 582 622 /* See if the data has been slurped already .. */ … … 584 624 { 585 625 per = oasys_per_section (s); 586 if (per->initialized == true)587 return true;626 if (per->initialized) 627 return TRUE; 588 628 } 589 629 590 630 if (data->first_data_record == 0) 591 return true;631 return TRUE; 592 632 593 633 if (bfd_seek (abfd, data->first_data_record, SEEK_SET) != 0) 594 return false;634 return FALSE; 595 635 while (loop) 596 636 { 597 637 if (! oasys_read_record (abfd, &record)) 598 return false;638 return FALSE; 599 639 switch (record.header.type) 600 640 { … … 616 656 per = oasys_per_section (section); 617 657 618 if ( per->initialized == false)658 if (! per->initialized) 619 659 { 620 660 per->data = (bfd_byte *) bfd_zalloc (abfd, section->_raw_size); 621 661 if (!per->data) 622 return false; 623 per->reloc_tail_ptr = (oasys_reloc_type **) & (section->relocation); 624 per->had_vma = false; 625 per->initialized = true; 662 return FALSE; 663 per->reloc_tail_ptr 664 = (oasys_reloc_type **) §ion->relocation; 665 per->had_vma = FALSE; 666 per->initialized = TRUE; 626 667 section->reloc_count = 0; 627 668 section->flags = SEC_ALLOC; 628 669 } 629 670 630 dst_offset = bfd_h_get_32 (abfd, record.data.addr);631 if ( per->had_vma == false)671 dst_offset = H_GET_32 (abfd, record.data.addr); 672 if (! per->had_vma) 632 673 { 633 674 /* Take the first vma we see as the base */ 634 675 section->vma = dst_offset; 635 per->had_vma = true;676 per->had_vma = TRUE; 636 677 } 637 678 … … 682 723 { 683 724 /* Relocate the item relative to the section */ 684 oasys_reloc_type *r = 685 (oasys_reloc_type *) 686 bfd_alloc (abfd, 687 sizeof (oasys_reloc_type)); 725 oasys_reloc_type *r; 726 727 amt = sizeof (oasys_reloc_type); 728 r = (oasys_reloc_type *) bfd_alloc (abfd, 729 amt); 688 730 if (!r) 689 return false;731 return FALSE; 690 732 *(per->reloc_tail_ptr) = r; 691 733 per->reloc_tail_ptr = &r->next; … … 710 752 section->reloc_count++; 711 753 712 /* Fake up the data to look like it's got the -ve pc in it, this makes 713 it much easier to convert into other formats. This is done by 714 hitting the addend. 715 */ 716 if (r->relent.howto->pc_relative == true) 717 { 718 r->relent.addend -= dst_ptr - dst_base_ptr; 719 } 720 721 754 /* Fake up the data to look like 755 it's got the -ve pc in it, this 756 makes it much easier to convert 757 into other formats. This is done 758 by hitting the addend. */ 759 if (r->relent.howto->pc_relative) 760 r->relent.addend -= dst_ptr - dst_base_ptr; 722 761 } 723 762 break; … … 726 765 case RELOCATION_TYPE_UND: 727 766 { 728 oasys_reloc_type *r = 729 (oasys_reloc_type *) 730 bfd_alloc (abfd, 731 sizeof (oasys_reloc_type)); 767 oasys_reloc_type *r; 768 769 amt = sizeof (oasys_reloc_type); 770 r = (oasys_reloc_type *) bfd_alloc (abfd, 771 amt); 732 772 if (!r) 733 return false;773 return FALSE; 734 774 *(per->reloc_tail_ptr) = r; 735 775 per->reloc_tail_ptr = &r->next; … … 753 793 754 794 src += 2; 755 /* Fake up the data to look like it's got the -ve pc in it, this makes 756 it much easier to convert into other formats. This is done by 757 hitting the addend. 758 */ 759 if (r->relent.howto->pc_relative == true) 760 { 761 r->relent.addend -= dst_ptr - dst_base_ptr; 762 } 763 764 765 795 /* Fake up the data to look like 796 it's got the -ve pc in it, this 797 makes it much easier to convert 798 into other formats. This is done 799 by hitting the addend. */ 800 if (r->relent.howto->pc_relative) 801 r->relent.addend -= dst_ptr - dst_base_ptr; 766 802 } 767 803 break; … … 781 817 break; 782 818 default: 783 loop = false;819 loop = FALSE; 784 820 } 785 821 } 786 822 787 return true;788 789 } 790 791 static b oolean823 return TRUE; 824 825 } 826 827 static bfd_boolean 792 828 oasys_new_section_hook (abfd, newsect) 793 829 bfd *abfd; … … 795 831 { 796 832 newsect->used_by_bfd = (PTR) 797 bfd_alloc (abfd, sizeof (oasys_per_section_type));833 bfd_alloc (abfd, (bfd_size_type) sizeof (oasys_per_section_type)); 798 834 if (!newsect->used_by_bfd) 799 return false;835 return FALSE; 800 836 oasys_per_section (newsect)->data = (bfd_byte *) NULL; 801 837 oasys_per_section (newsect)->section = newsect; 802 838 oasys_per_section (newsect)->offset = 0; 803 oasys_per_section (newsect)->initialized = false;839 oasys_per_section (newsect)->initialized = FALSE; 804 840 newsect->alignment_power = 1; 805 841 /* Turn the section string into an index */ … … 807 843 sscanf (newsect->name, "%u", &newsect->target_index); 808 844 809 return true;845 return TRUE; 810 846 } 811 847 … … 821 857 } 822 858 823 static b oolean859 static bfd_boolean 824 860 oasys_get_section_contents (abfd, section, location, offset, count) 825 861 bfd *abfd; … … 829 865 bfd_size_type count; 830 866 { 831 oasys_per_section_type *p = (oasys_per_section_type *) section->used_by_bfd;867 oasys_per_section_type *p = oasys_per_section (section); 832 868 oasys_slurp_section_data (abfd); 833 if ( p->initialized == false)834 { 835 (void) memset (location, 0, ( int) count);869 if (! p->initialized) 870 { 871 (void) memset (location, 0, (size_t) count); 836 872 } 837 873 else 838 874 { 839 (void) memcpy (location, (PTR) (p->data + offset), ( int) count);840 } 841 return true;875 (void) memcpy (location, (PTR) (p->data + offset), (size_t) count); 876 } 877 return TRUE; 842 878 } 843 879 … … 878 914 879 915 /* Calculate the checksum and write one record */ 880 static b oolean916 static bfd_boolean 881 917 oasys_write_record (abfd, type, record, size) 882 918 bfd *abfd; … … 900 936 } 901 937 record->header.check_sum = 0xff & (-checksum); 902 if (bfd_ write ((PTR) record, 1,size, abfd) != size)903 return false;904 return true;938 if (bfd_bwrite ((PTR) record, (bfd_size_type) size, abfd) != size) 939 return FALSE; 940 return TRUE; 905 941 } 906 942 907 943 908 944 /* Write out all the symbols */ 909 static b oolean945 static bfd_boolean 910 946 oasys_write_syms (abfd) 911 947 bfd *abfd; … … 918 954 919 955 oasys_symbol_record_type symbol; 920 asymbol * CONSTg = generic[count];921 922 CONSTchar *src = g->name;956 asymbol *const g = generic[count]; 957 958 const char *src = g->name; 923 959 char *dst = symbol.name; 924 960 unsigned int l = 0; … … 927 963 { 928 964 symbol.relb = RELOCATION_TYPE_COM; 929 bfd_h_put_16 (abfd, index, symbol.refno);965 H_PUT_16 (abfd, index, symbol.refno); 930 966 index++; 931 967 } … … 933 969 { 934 970 symbol.relb = RELOCATION_TYPE_ABS; 935 bfd_h_put_16 (abfd, 0, symbol.refno);971 H_PUT_16 (abfd, 0, symbol.refno); 936 972 937 973 } … … 939 975 { 940 976 symbol.relb = RELOCATION_TYPE_UND; 941 bfd_h_put_16 (abfd, index, symbol.refno);977 H_PUT_16 (abfd, index, symbol.refno); 942 978 /* Overload the value field with the output index number */ 943 979 index++; … … 961 997 symbol.relb = RELOCATION_TYPE_REL | g->section->output_section->target_index; 962 998 } 963 bfd_h_put_16 (abfd, 0, symbol.refno);999 H_PUT_16 (abfd, 0, symbol.refno); 964 1000 } 965 1001 #ifdef UNDERSCORE_HACK … … 973 1009 } 974 1010 975 bfd_h_put_32 (abfd, g->value, symbol.value);1011 H_PUT_32 (abfd, g->value, symbol.value); 976 1012 977 1013 … … 983 1019 offsetof (oasys_symbol_record_type, 984 1020 name[0]) + l)) 985 return false;1021 return FALSE; 986 1022 } 987 1023 else … … 992 1028 offsetof (oasys_symbol_record_type, 993 1029 name[0]) + l)) 994 return false;1030 return FALSE; 995 1031 } 996 1032 g->value = index - 1; 997 1033 } 998 1034 999 return true;1035 return TRUE; 1000 1036 } 1001 1037 1002 1038 1003 1039 /* Write a section header for each section */ 1004 static b oolean1040 static bfd_boolean 1005 1041 oasys_write_sections (abfd) 1006 1042 bfd *abfd; … … 1011 1047 for (s = abfd->sections; s != (asection *) NULL; s = s->next) 1012 1048 { 1013 if (! isdigit ((unsigned char)s->name[0]))1049 if (!ISDIGIT (s->name[0])) 1014 1050 { 1015 1051 (*_bfd_error_handler) … … 1017 1053 bfd_get_filename (abfd), s->name); 1018 1054 bfd_set_error (bfd_error_nonrepresentable_section); 1019 return false;1055 return FALSE; 1020 1056 } 1021 1057 out.relb = RELOCATION_TYPE_REL | s->target_index; 1022 bfd_h_put_32 (abfd, s->_cooked_size, out.value);1023 bfd_h_put_32 (abfd, s->vma, out.vma);1058 H_PUT_32 (abfd, s->_cooked_size, out.value); 1059 H_PUT_32 (abfd, s->vma, out.vma); 1024 1060 1025 1061 if (! oasys_write_record (abfd, … … 1027 1063 (oasys_record_union_type *) & out, 1028 1064 sizeof (out))) 1029 return false;1030 } 1031 return true;1032 } 1033 1034 static b oolean1065 return FALSE; 1066 } 1067 return TRUE; 1068 } 1069 1070 static bfd_boolean 1035 1071 oasys_write_header (abfd) 1036 1072 bfd *abfd; … … 1058 1094 offsetof (oasys_header_record_type, 1059 1095 description[0]))) 1060 return false;1061 1062 return true;1063 } 1064 1065 static b oolean1096 return FALSE; 1097 1098 return TRUE; 1099 } 1100 1101 static bfd_boolean 1066 1102 oasys_write_end (abfd) 1067 1103 bfd *abfd; … … 1070 1106 unsigned char null = 0; 1071 1107 end.relb = RELOCATION_TYPE_ABS; 1072 bfd_h_put_32 (abfd, abfd->start_address, end.entry);1073 bfd_h_put_16 (abfd, 0, end.fill);1108 H_PUT_32 (abfd, abfd->start_address, end.entry); 1109 H_PUT_16 (abfd, 0, end.fill); 1074 1110 end.zero = 0; 1075 1111 if (! oasys_write_record (abfd, … … 1077 1113 (oasys_record_union_type *) & end, 1078 1114 sizeof (end))) 1079 return false;1080 if (bfd_ write ((PTR) & null, 1,1, abfd) != 1)1081 return false;1082 return true;1115 return FALSE; 1116 if (bfd_bwrite ((PTR) &null, (bfd_size_type) 1, abfd) != 1) 1117 return FALSE; 1118 return TRUE; 1083 1119 } 1084 1120 1085 1121 static int 1086 1122 comp (ap, bp) 1087 CONSTPTR ap;1088 CONSTPTR bp;1123 const PTR ap; 1124 const PTR bp; 1089 1125 { 1090 1126 arelent *a = *((arelent **) ap); … … 1097 1133 1098 1134 */ 1099 static b oolean1135 static bfd_boolean 1100 1136 oasys_write_data (abfd) 1101 1137 bfd *abfd; … … 1135 1171 1136 1172 1137 bfd_h_put_32 (abfd, s->vma + current_byte_index,1138 1173 H_PUT_32 (abfd, s->vma + current_byte_index, 1174 processed_data.addr); 1139 1175 1140 1176 /* Don't start a relocation unless you're sure you can finish it … … 1208 1244 #endif 1209 1245 { 1210 asymbol * p= *(r->sym_ptr_ptr);1246 asymbol *sym = *(r->sym_ptr_ptr); 1211 1247 1212 1248 /* If this symbol has a section attached, then it 1213 1249 has already been resolved. Change from a symbol 1214 1250 ref to a section ref */ 1215 if ( p->section != (asection *) NULL)1251 if (sym->section != (asection *) NULL) 1216 1252 { 1217 1253 rel_byte |= RELOCATION_TYPE_REL; 1218 1254 rel_byte |= 1219 p->section->output_section->target_index;1255 sym->section->output_section->target_index; 1220 1256 *dst++ = rel_byte; 1221 1257 } … … 1229 1265 symbol table was written 1230 1266 */ 1231 *dst++ = p->value >> 8;1232 *dst++ = p->value;1267 *dst++ = sym->value >> 8; 1268 *dst++ = sym->value; 1233 1269 } 1234 1270 } … … 1270 1306 } 1271 1307 1272 if (! oasys_write_record (abfd, 1273 oasys_record_is_data_enum, 1274 ((oasys_record_union_type *) 1275 & processed_data), 1276 dst - (bfd_byte *) & processed_data)) 1277 return false; 1308 if (! (oasys_write_record 1309 (abfd, oasys_record_is_data_enum, 1310 ((oasys_record_union_type *) &processed_data), 1311 (size_t) (dst - (bfd_byte *) &processed_data)))) 1312 return FALSE; 1278 1313 } 1279 1314 } 1280 1315 } 1281 1316 1282 return true;1283 } 1284 1285 static b oolean1317 return TRUE; 1318 } 1319 1320 static bfd_boolean 1286 1321 oasys_write_object_contents (abfd) 1287 1322 bfd *abfd; 1288 1323 { 1289 1324 if (! oasys_write_header (abfd)) 1290 return false;1325 return FALSE; 1291 1326 if (! oasys_write_syms (abfd)) 1292 return false;1327 return FALSE; 1293 1328 if (! oasys_write_sections (abfd)) 1294 return false;1329 return FALSE; 1295 1330 if (! oasys_write_data (abfd)) 1296 return false;1331 return FALSE; 1297 1332 if (! oasys_write_end (abfd)) 1298 return false;1299 return true;1333 return FALSE; 1334 return TRUE; 1300 1335 } 1301 1336 … … 1308 1343 * not a byte image, but a record stream. 1309 1344 */ 1310 static b oolean1345 static bfd_boolean 1311 1346 oasys_set_section_contents (abfd, section, location, offset, count) 1312 1347 bfd *abfd; … … 1323 1358 (bfd_byte *) (bfd_alloc (abfd, section->_cooked_size)); 1324 1359 if (!oasys_per_section (section)->data) 1325 return false;1360 return FALSE; 1326 1361 } 1327 1362 (void) memcpy ((PTR) (oasys_per_section (section)->data + offset), … … 1329 1364 (size_t) count); 1330 1365 } 1331 return true;1366 return TRUE; 1332 1367 } 1333 1368 … … 1344 1379 bfd *abfd; 1345 1380 { 1346 1347 oasys_symbol_type *new = 1348 (oasys_symbol_type *) bfd_zalloc (abfd, sizeof (oasys_symbol_type)); 1381 bfd_size_type amt = sizeof (oasys_symbol_type); 1382 oasys_symbol_type *new = (oasys_symbol_type *) bfd_zalloc (abfd, amt); 1349 1383 if (!new) 1350 1384 return NULL; … … 1397 1431 } 1398 1432 1399 static boolean 1400 oasys_find_nearest_line (abfd, 1401 section, 1402 symbols, 1403 offset, 1404 filename_ptr, 1405 functionname_ptr, 1406 line_ptr) 1433 static bfd_boolean 1434 oasys_find_nearest_line (abfd, section, symbols, offset, 1435 filename_ptr, functionname_ptr, line_ptr) 1407 1436 bfd *abfd ATTRIBUTE_UNUSED; 1408 1437 asection *section ATTRIBUTE_UNUSED; 1409 1438 asymbol **symbols ATTRIBUTE_UNUSED; 1410 1439 bfd_vma offset ATTRIBUTE_UNUSED; 1411 c har **filename_ptr ATTRIBUTE_UNUSED;1412 c har **functionname_ptr ATTRIBUTE_UNUSED;1440 const char **filename_ptr ATTRIBUTE_UNUSED; 1441 const char **functionname_ptr ATTRIBUTE_UNUSED; 1413 1442 unsigned int *line_ptr ATTRIBUTE_UNUSED; 1414 1443 { 1415 return false;1444 return FALSE; 1416 1445 1417 1446 } … … 1439 1468 oasys_sizeof_headers (abfd, exec) 1440 1469 bfd *abfd ATTRIBUTE_UNUSED; 1441 b oolean exec ATTRIBUTE_UNUSED;1470 bfd_boolean exec ATTRIBUTE_UNUSED; 1442 1471 { 1443 1472 return 0; … … 1450 1479 #define oasys_slurp_extended_name_table bfd_true 1451 1480 #define oasys_construct_extended_name_table \ 1452 ((b oolean (*) PARAMS ((bfd *, char **, bfd_size_type *, const char **))) \1481 ((bfd_boolean (*) PARAMS ((bfd *, char **, bfd_size_type *, const char **))) \ 1453 1482 bfd_true) 1454 1483 #define oasys_truncate_arname bfd_dont_truncate_arname 1455 1484 #define oasys_write_armap \ 1456 ((b oolean (*) \1485 ((bfd_boolean (*) \ 1457 1486 PARAMS ((bfd *, unsigned int, struct orl *, unsigned int, int))) \ 1458 1487 bfd_true) … … 1478 1507 #define oasys_bfd_relax_section bfd_generic_relax_section 1479 1508 #define oasys_bfd_gc_sections bfd_generic_gc_sections 1509 #define oasys_bfd_merge_sections bfd_generic_merge_sections 1510 #define oasys_bfd_discard_group bfd_generic_discard_group 1480 1511 #define oasys_bfd_link_hash_table_create _bfd_generic_link_hash_table_create 1512 #define oasys_bfd_link_hash_table_free _bfd_generic_link_hash_table_free 1481 1513 #define oasys_bfd_link_add_symbols _bfd_generic_link_add_symbols 1514 #define oasys_bfd_link_just_syms _bfd_generic_link_just_syms 1482 1515 #define oasys_bfd_final_link _bfd_generic_final_link 1483 1516 #define oasys_bfd_link_split_section _bfd_generic_link_split_section … … 1534 1567 1535 1568 NULL, 1536 1569 1537 1570 (PTR) 0 1538 1571 }; -
Property cvs2svn:cvs-rev
changed from
Note:
See TracChangeset
for help on using the changeset viewer.