Changeset 609 for branches/GNU/src/binutils/bfd/coffgen.c
- Timestamp:
- Aug 16, 2003, 6:59:22 PM (22 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/GNU/src/binutils/bfd/coffgen.c
-
Property cvs2svn:cvs-rev
changed from
1.1
to1.1.1.2
r608 r609 1 1 /* Support for the generic parts of COFF, for BFD. 2 2 Copyright 1990, 1991, 1992, 1993, 1994, 1995, 1996, 1997, 1998, 1999, 3 2000, 2001 3 2000, 2001, 2002 4 4 Free Software Foundation, Inc. 5 5 Written by Cygnus Support. … … 47 47 PARAMS ((bfd *, asymbol *, combined_entry_type *, bfd_size_type *, 48 48 asection **, bfd_size_type *)); 49 static b oolean coff_write_symbol50 PARAMS ((bfd *, asymbol *, combined_entry_type *, unsigned int*,49 static bfd_boolean coff_write_symbol 50 PARAMS ((bfd *, asymbol *, combined_entry_type *, bfd_vma *, 51 51 bfd_size_type *, asection **, bfd_size_type *)); 52 static b oolean coff_write_alien_symbol53 PARAMS ((bfd *, asymbol *, unsigned int*, bfd_size_type *,52 static bfd_boolean coff_write_alien_symbol 53 PARAMS ((bfd *, asymbol *, bfd_vma *, bfd_size_type *, 54 54 asection **, bfd_size_type *)); 55 static b oolean coff_write_native_symbol56 PARAMS ((bfd *, coff_symbol_type *, unsigned int*, bfd_size_type *,55 static bfd_boolean coff_write_native_symbol 56 PARAMS ((bfd *, coff_symbol_type *, bfd_vma *, bfd_size_type *, 57 57 asection **, bfd_size_type *)); 58 58 static void coff_pointerize_aux 59 59 PARAMS ((bfd *, combined_entry_type *, combined_entry_type *, 60 60 unsigned int, combined_entry_type *)); 61 static b oolean make_a_section_from_file61 static bfd_boolean make_a_section_from_file 62 62 PARAMS ((bfd *, struct internal_scnhdr *, unsigned int)); 63 63 static const bfd_target *coff_real_object_p … … 69 69 PARAMS ((bfd *)); 70 70 static char *copy_name 71 PARAMS ((bfd *, char *, int));71 PARAMS ((bfd *, char *, size_t)); 72 72 73 73 #define STRING_SIZE_SIZE (4) … … 75 75 /* Take a section header read from a coff file (in HOST byte order), 76 76 and make a BFD "section" out of it. This is used by ECOFF. */ 77 static b oolean77 static bfd_boolean 78 78 make_a_section_from_file (abfd, hdr, target_index) 79 79 bfd *abfd; … … 83 83 asection *return_section; 84 84 char *name; 85 bfd_boolean result = TRUE; 86 flagword flags; 85 87 86 88 name = NULL; … … 102 104 strings = _bfd_coff_read_string_table (abfd); 103 105 if (strings == NULL) 104 return false;106 return FALSE; 105 107 /* FIXME: For extra safety, we should make sure that 106 108 strindex does not run us past the end, but right now we 107 109 don't know the length of the string table. */ 108 110 strings += strindex; 109 name = bfd_alloc (abfd, strlen (strings) + 1);111 name = bfd_alloc (abfd, (bfd_size_type) strlen (strings) + 1); 110 112 if (name == NULL) 111 return false;113 return FALSE; 112 114 strcpy (name, strings); 113 115 } … … 117 119 { 118 120 /* Assorted wastage to null-terminate the name, thanks AT&T! */ 119 name = bfd_alloc (abfd, sizeof (hdr->s_name) + 1);121 name = bfd_alloc (abfd, (bfd_size_type) sizeof (hdr->s_name) + 1); 120 122 if (name == NULL) 121 return false;123 return FALSE; 122 124 strncpy (name, (char *) &hdr->s_name[0], sizeof (hdr->s_name)); 123 125 name[sizeof (hdr->s_name)] = 0; … … 126 128 return_section = bfd_make_section_anyway (abfd, name); 127 129 if (return_section == NULL) 128 return false;130 return FALSE; 129 131 130 132 return_section->vma = hdr->s_vaddr; … … 143 145 return_section->next = (asection *) NULL; 144 146 return_section->target_index = target_index; 145 return_section->flags = bfd_coff_styp_to_sec_flags_hook (abfd, hdr, name, 146 return_section); 147 148 if (! bfd_coff_styp_to_sec_flags_hook (abfd, hdr, name, return_section, 149 & flags)) 150 result = FALSE; 151 152 return_section->flags = flags; 147 153 148 154 /* At least on i386-coff, the line number count for a shared library … … 156 162 if (hdr->s_scnptr != 0) 157 163 return_section->flags |= SEC_HAS_CONTENTS; 158 return true; 164 165 return result; 159 166 } 160 167 … … 172 179 bfd_vma ostart = bfd_get_start_address (abfd); 173 180 PTR tdata; 174 size_t readsize; /* length of file_info */ 181 PTR tdata_save; 182 bfd_size_type readsize; /* length of file_info */ 175 183 unsigned int scnhsz; 176 184 char *external_sections; … … 200 208 /* Set up the tdata area. ECOFF uses its own routine, and overrides 201 209 abfd->flags. */ 210 tdata_save = abfd->tdata.any; 202 211 tdata = bfd_coff_mkobject_hook (abfd, (PTR) internal_f, (PTR) internal_a); 203 212 if (tdata == NULL) 204 return 0;213 goto fail2; 205 214 206 215 scnhsz = bfd_coff_scnhsz (abfd); 207 readsize = nscns * scnhsz;216 readsize = (bfd_size_type) nscns * scnhsz; 208 217 external_sections = (char *) bfd_alloc (abfd, readsize); 209 218 if (!external_sections) 210 219 goto fail; 211 220 212 if (bfd_ read ((PTR) external_sections, 1, readsize, abfd) != readsize)221 if (bfd_bread ((PTR) external_sections, readsize, abfd) != readsize) 213 222 goto fail; 214 223 215 224 /* Set the arch/mach *before* swapping in sections; section header swapping 216 225 may depend on arch/mach info. */ 217 if ( bfd_coff_set_arch_mach_hook (abfd, (PTR) internal_f) == false)226 if (! bfd_coff_set_arch_mach_hook (abfd, (PTR) internal_f)) 218 227 goto fail; 219 228 220 /* Now copy data as required; construct all asections etc */229 /* Now copy data as required; construct all asections etc. */ 221 230 if (nscns != 0) 222 231 { … … 233 242 } 234 243 235 /* make_abs_section (abfd); */236 237 244 return abfd->xvec; 238 245 239 246 fail: 240 247 bfd_release (abfd, tdata); 248 fail2: 249 abfd->tdata.any = tdata_save; 241 250 abfd->flags = oflags; 242 251 bfd_get_start_address (abfd) = ostart; … … 251 260 bfd *abfd; 252 261 { 253 unsigned intfilhsz;254 unsigned intaoutsz;255 int nscns;262 bfd_size_type filhsz; 263 bfd_size_type aoutsz; 264 unsigned int nscns; 256 265 PTR filehdr; 257 266 struct internal_filehdr internal_f; … … 264 273 filehdr = bfd_alloc (abfd, filhsz); 265 274 if (filehdr == NULL) 266 return 0;267 if (bfd_ read (filehdr, 1, filhsz, abfd) != filhsz)275 return NULL; 276 if (bfd_bread (filehdr, filhsz, abfd) != filhsz) 268 277 { 269 278 if (bfd_get_error () != bfd_error_system_call) 270 279 bfd_set_error (bfd_error_wrong_format); 271 return 0; 280 bfd_release (abfd, filehdr); 281 return NULL; 272 282 } 273 283 bfd_coff_swap_filehdr_in (abfd, filehdr, &internal_f); 274 284 bfd_release (abfd, filehdr); 275 285 276 if (bfd_coff_bad_format_hook (abfd, &internal_f) == false) 286 /* The XCOFF format has two sizes for the f_opthdr. SMALL_AOUTSZ 287 (less than aoutsz) used in object files and AOUTSZ (equal to 288 aoutsz) in executables. The bfd_coff_swap_aouthdr_in function 289 expects this header to be aoutsz bytes in length, so we use that 290 value in the call to bfd_alloc below. But we must be careful to 291 only read in f_opthdr bytes in the call to bfd_bread. We should 292 also attempt to catch corrupt or non-COFF binaries with a strange 293 value for f_opthdr. */ 294 if (! bfd_coff_bad_format_hook (abfd, &internal_f) 295 || internal_f.f_opthdr > aoutsz) 277 296 { 278 297 bfd_set_error (bfd_error_wrong_format); 279 return 0;298 return NULL; 280 299 } 281 300 nscns = internal_f.f_nscns; … … 287 306 opthdr = bfd_alloc (abfd, aoutsz); 288 307 if (opthdr == NULL) 289 return 0;;290 if (bfd_ read (opthdr, 1,internal_f.f_opthdr, abfd)308 return NULL; 309 if (bfd_bread (opthdr, (bfd_size_type) internal_f.f_opthdr, abfd) 291 310 != internal_f.f_opthdr) 292 311 { 293 return 0; 312 bfd_release (abfd, opthdr); 313 return NULL; 294 314 } 295 315 bfd_coff_swap_aouthdr_in (abfd, opthdr, (PTR) &internal_a); 316 bfd_release (abfd, opthdr); 296 317 } 297 318 … … 401 422 402 423 /* Read in and swap the relocs. This returns a buffer holding the 403 relocs for section SEC in file ABFD. If CACHE is trueand424 relocs for section SEC in file ABFD. If CACHE is TRUE and 404 425 INTERNAL_RELOCS is NULL, the relocs read in will be saved in case 405 426 the function is called again. If EXTERNAL_RELOCS is not NULL, it 406 427 is a buffer large enough to hold the unswapped relocs. If 407 428 INTERNAL_RELOCS is not NULL, it is a buffer large enough to hold 408 the swapped relocs. If REQUIRE_INTERNAL is true, then the return429 the swapped relocs. If REQUIRE_INTERNAL is TRUE, then the return 409 430 value must be INTERNAL_RELOCS. The function returns NULL on error. */ 410 431 … … 414 435 bfd *abfd; 415 436 asection *sec; 416 b oolean cache;437 bfd_boolean cache; 417 438 bfd_byte *external_relocs; 418 b oolean require_internal;439 bfd_boolean require_internal; 419 440 struct internal_reloc *internal_relocs; 420 441 { … … 425 446 bfd_byte *erel_end; 426 447 struct internal_reloc *irel; 448 bfd_size_type amt; 427 449 428 450 if (coff_section_data (abfd, sec) != NULL … … 438 460 relsz = bfd_coff_relsz (abfd); 439 461 462 amt = sec->reloc_count * relsz; 440 463 if (external_relocs == NULL) 441 464 { 442 free_external = (bfd_byte *) bfd_malloc ( sec->reloc_count * relsz);465 free_external = (bfd_byte *) bfd_malloc (amt); 443 466 if (free_external == NULL && sec->reloc_count > 0) 444 467 goto error_return; … … 447 470 448 471 if (bfd_seek (abfd, sec->rel_filepos, SEEK_SET) != 0 449 || (bfd_read (external_relocs, relsz, sec->reloc_count, abfd) 450 != relsz * sec->reloc_count)) 472 || bfd_bread (external_relocs, amt, abfd) != amt) 451 473 goto error_return; 452 474 453 475 if (internal_relocs == NULL) 454 476 { 455 free_internal = ((struct internal_reloc *)456 bfd_malloc (sec->reloc_count 457 * sizeof (struct internal_reloc)));477 amt = sec->reloc_count; 478 amt *= sizeof (struct internal_reloc); 479 free_internal = (struct internal_reloc *) bfd_malloc (amt); 458 480 if (free_internal == NULL && sec->reloc_count > 0) 459 481 goto error_return; … … 478 500 if (coff_section_data (abfd, sec) == NULL) 479 501 { 480 sec->used_by_bfd = 481 (PTR) bfd_zalloc (abfd, 482 sizeof (struct coff_section_tdata)); 502 amt = sizeof (struct coff_section_tdata); 503 sec->used_by_bfd = (PTR) bfd_zalloc (abfd, amt); 483 504 if (sec->used_by_bfd == NULL) 484 505 goto error_return; … … 540 561 alent *l = q->lineno; 541 562 542 ++q->symbol.section->output_section->lineno_count; 543 ++total; 544 ++l; 545 while (l->line_number != 0) 563 do 546 564 { 565 asection * sec = q->symbol.section->output_section; 566 567 /* Do not try to update fields in read-only sections. */ 568 if (! bfd_is_const_section (sec)) 569 sec->lineno_count ++; 570 547 571 ++total; 548 ++q->symbol.section->output_section->lineno_count;549 572 ++l; 550 573 } 574 while (l->line_number != 0); 551 575 } 552 576 } … … 631 655 do that here too. */ 632 656 633 b oolean657 bfd_boolean 634 658 coff_renumber_symbols (bfd_ptr, first_undef) 635 659 bfd *bfd_ptr; … … 655 679 asymbol **newsyms; 656 680 unsigned int i; 657 658 newsyms = (asymbol **) bfd_alloc (bfd_ptr, 659 sizeof (asymbol *) * (symbol_count + 1)); 681 bfd_size_type amt; 682 683 amt = sizeof (asymbol *) * ((bfd_size_type) symbol_count + 1); 684 newsyms = (asymbol **) bfd_alloc (bfd_ptr, amt); 660 685 if (!newsyms) 661 return false;686 return FALSE; 662 687 bfd_ptr->outsymbols = newsyms; 663 688 for (i = 0; i < symbol_count; i++) … … 722 747 obj_conv_table_size (bfd_ptr) = native_index; 723 748 724 return true;749 return TRUE; 725 750 } 726 751 … … 751 776 /* FIXME: We should use a union here. */ 752 777 s->u.syment.n_value = 753 ((combined_entry_type *) s->u.syment.n_value)->offset; 778 (bfd_vma)((combined_entry_type *) 779 ((unsigned long) s->u.syment.n_value))->offset; 754 780 s->fix_value = 0; 755 781 } … … 869 895 else 870 896 { 871 longfilepos;897 file_ptr filepos; 872 898 bfd_byte buf[4]; 873 899 int prefix_len = bfd_coff_debug_string_prefix_length (abfd); … … 882 908 filepos = bfd_tell (abfd); 883 909 if (prefix_len == 4) 884 bfd_put_32 (abfd, name_length + 1, buf);910 bfd_put_32 (abfd, (bfd_vma) (name_length + 1), buf); 885 911 else 886 bfd_put_16 (abfd, name_length + 1, buf);912 bfd_put_16 (abfd, (bfd_vma) (name_length + 1), buf); 887 913 888 914 if (!bfd_set_section_contents (abfd, … … 894 920 *debug_string_section_p, 895 921 (PTR) symbol->name, 896 ( (file_ptr)*debug_string_size_p897 922 (file_ptr) (*debug_string_size_p 923 + prefix_len), 898 924 (bfd_size_type) name_length + 1)) 899 925 abort (); … … 916 942 /* Write a symbol out to a COFF file. */ 917 943 918 static b oolean944 static bfd_boolean 919 945 coff_write_symbol (abfd, symbol, native, written, string_size_p, 920 946 debug_string_section_p, debug_string_size_p) … … 922 948 asymbol *symbol; 923 949 combined_entry_type *native; 924 unsigned int*written;950 bfd_vma *written; 925 951 bfd_size_type *string_size_p; 926 952 asection **debug_string_section_p; … … 961 987 buf = bfd_alloc (abfd, symesz); 962 988 if (!buf) 963 return false;989 return FALSE; 964 990 bfd_coff_swap_sym_out (abfd, &native->u.syment, buf); 965 if (bfd_ write (buf, 1, symesz, abfd) != symesz)966 return false;991 if (bfd_bwrite (buf, symesz, abfd) != symesz) 992 return FALSE; 967 993 bfd_release (abfd, buf); 968 994 … … 975 1001 buf = bfd_alloc (abfd, auxesz); 976 1002 if (!buf) 977 return false;1003 return FALSE; 978 1004 for (j = 0; j < native->u.syment.n_numaux; j++) 979 1005 { … … 982 1008 type, 983 1009 class, 984 j,1010 (int) j, 985 1011 native->u.syment.n_numaux, 986 1012 buf); 987 if (bfd_ write (buf, 1, auxesz, abfd) != auxesz)988 return false;1013 if (bfd_bwrite (buf, auxesz, abfd) != auxesz) 1014 return FALSE; 989 1015 } 990 1016 bfd_release (abfd, buf); … … 995 1021 996 1022 *written += numaux + 1; 997 return true;1023 return TRUE; 998 1024 } 999 1025 … … 1002 1028 or we may be linking a non COFF file to a COFF file. */ 1003 1029 1004 static b oolean1030 static bfd_boolean 1005 1031 coff_write_alien_symbol (abfd, symbol, written, string_size_p, 1006 1032 debug_string_section_p, debug_string_size_p) 1007 1033 bfd *abfd; 1008 1034 asymbol *symbol; 1009 unsigned int*written;1035 bfd_vma *written; 1010 1036 bfd_size_type *string_size_p; 1011 1037 asection **debug_string_section_p; … … 1035 1061 name to keep it from being put in the string table. */ 1036 1062 symbol->name = ""; 1037 return true;1063 return TRUE; 1038 1064 } 1039 1065 else … … 1046 1072 native->u.syment.n_value += symbol->section->output_section->vma; 1047 1073 1048 /* Copy the any flags from the thefile header into the symbol.1074 /* Copy the any flags from the file header into the symbol. 1049 1075 FIXME: Why? */ 1050 1076 { … … 1070 1096 /* Write a native symbol to a COFF file. */ 1071 1097 1072 static b oolean1098 static bfd_boolean 1073 1099 coff_write_native_symbol (abfd, symbol, written, string_size_p, 1074 1100 debug_string_section_p, debug_string_size_p) 1075 1101 bfd *abfd; 1076 1102 coff_symbol_type *symbol; 1077 unsigned int*written;1103 bfd_vma *written; 1078 1104 bfd_size_type *string_size_p; 1079 1105 asection **debug_string_section_p; … … 1126 1152 count++; 1127 1153 } 1128 symbol->done_lineno = true; 1129 1130 symbol->symbol.section->output_section->moving_line_filepos += 1131 count * bfd_coff_linesz (abfd); 1154 symbol->done_lineno = TRUE; 1155 1156 if (! bfd_is_const_section (symbol->symbol.section->output_section)) 1157 symbol->symbol.section->output_section->moving_line_filepos += 1158 count * bfd_coff_linesz (abfd); 1132 1159 } 1133 1160 … … 1139 1166 /* Write out the COFF symbols. */ 1140 1167 1141 b oolean1168 bfd_boolean 1142 1169 coff_write_symbols (abfd) 1143 1170 bfd *abfd; … … 1148 1175 unsigned int i; 1149 1176 unsigned int limit = bfd_get_symcount (abfd); 1150 unsigned intwritten = 0;1177 bfd_signed_vma written = 0; 1151 1178 asymbol **p; 1152 1179 … … 1175 1202 /* Seek to the right place */ 1176 1203 if (bfd_seek (abfd, obj_sym_filepos (abfd), SEEK_SET) != 0) 1177 return false;1204 return FALSE; 1178 1205 1179 1206 /* Output all the symbols we have */ … … 1191 1218 &debug_string_section, 1192 1219 &debug_string_size)) 1193 return false;1220 return FALSE; 1194 1221 } 1195 1222 else … … 1198 1225 &string_size, &debug_string_section, 1199 1226 &debug_string_size)) 1200 return false;1227 return FALSE; 1201 1228 } 1202 1229 } … … 1212 1239 1213 1240 #if STRING_SIZE_SIZE == 4 1214 bfd_h_put_32 (abfd, size, buffer);1241 H_PUT_32 (abfd, size, buffer); 1215 1242 #else 1216 #error Change bfd_h_put_321243 #error Change H_PUT_32 1217 1244 #endif 1218 if (bfd_write ((PTR) buffer, 1, sizeof (buffer), abfd) != sizeof (buffer)) 1219 return false; 1245 if (bfd_bwrite ((PTR) buffer, (bfd_size_type) sizeof (buffer), abfd) 1246 != sizeof (buffer)) 1247 return FALSE; 1220 1248 1221 1249 /* Handle long section names. This code must handle section … … 1232 1260 if (len > SCNNMLEN) 1233 1261 { 1234 if (bfd_write (o->name, 1, len + 1, abfd) != len + 1) 1235 return false; 1262 if (bfd_bwrite (o->name, (bfd_size_type) (len + 1), abfd) 1263 != len + 1) 1264 return FALSE; 1236 1265 } 1237 1266 } … … 1272 1301 { 1273 1302 if (bfd_coff_force_symnames_in_strings (abfd)) 1274 bfd_write (".file", 1, 6, abfd); 1303 { 1304 if (bfd_bwrite (".file", (bfd_size_type) 6, abfd) != 6) 1305 return FALSE; 1306 } 1275 1307 maxlen = bfd_coff_filnmlen (abfd); 1276 1308 } … … 1280 1312 if (name_length > maxlen) 1281 1313 { 1282 if (bfd_ write ((PTR) (q->name), 1, name_length + 1, abfd)1283 1284 return false;1314 if (bfd_bwrite ((PTR) (q->name), (bfd_size_type) name_length + 1, 1315 abfd) != name_length + 1) 1316 return FALSE; 1285 1317 } 1286 1318 } … … 1295 1327 1296 1328 #if STRING_SIZE_SIZE == 4 1297 bfd_h_put_32 (abfd, size, buffer);1329 H_PUT_32 (abfd, size, buffer); 1298 1330 #else 1299 #error Change bfd_h_put_321331 #error Change H_PUT_32 1300 1332 #endif 1301 if (bfd_ write ((PTR) buffer, 1,STRING_SIZE_SIZE, abfd)1333 if (bfd_bwrite ((PTR) buffer, (bfd_size_type) STRING_SIZE_SIZE, abfd) 1302 1334 != STRING_SIZE_SIZE) 1303 return false;1335 return FALSE; 1304 1336 } 1305 1337 … … 1315 1347 == bfd_section_size (abfd, debug_string_section)))); 1316 1348 1317 return true;1318 } 1319 1320 b oolean1349 return TRUE; 1350 } 1351 1352 bfd_boolean 1321 1353 coff_write_linenumbers (abfd) 1322 1354 bfd *abfd; … … 1329 1361 buff = bfd_alloc (abfd, linesz); 1330 1362 if (!buff) 1331 return false;1363 return FALSE; 1332 1364 for (s = abfd->sections; s != (asection *) NULL; s = s->next) 1333 1365 { … … 1336 1368 asymbol **q = abfd->outsymbols; 1337 1369 if (bfd_seek (abfd, s->line_filepos, SEEK_SET) != 0) 1338 return false;1370 return FALSE; 1339 1371 /* Find all the linenumbers in this section */ 1340 1372 while (*q) … … 1354 1386 out.l_addr.l_symndx = l->u.offset; 1355 1387 bfd_coff_swap_lineno_out (abfd, &out, buff); 1356 if (bfd_write (buff, 1, linesz, abfd) != linesz) 1357 return false; 1388 if (bfd_bwrite (buff, (bfd_size_type) linesz, abfd) 1389 != linesz) 1390 return FALSE; 1358 1391 l++; 1359 1392 while (l->line_number) … … 1362 1395 out.l_addr.l_symndx = l->u.offset; 1363 1396 bfd_coff_swap_lineno_out (abfd, &out, buff); 1364 if (bfd_write (buff, 1, linesz, abfd) != linesz) 1365 return false; 1397 if (bfd_bwrite (buff, (bfd_size_type) linesz, abfd) 1398 != linesz) 1399 return FALSE; 1366 1400 l++; 1367 1401 } … … 1373 1407 } 1374 1408 bfd_release (abfd, buff); 1375 return true;1409 return TRUE; 1376 1410 } 1377 1411 … … 1410 1444 }; 1411 1445 struct foo *f; 1412 f = (struct foo *) bfd_alloc (abfd, sizeof (*f)); 1446 1447 f = (struct foo *) bfd_zalloc (abfd, (bfd_size_type) sizeof (*f)); 1413 1448 if (!f) 1414 1449 { … … 1416 1451 return NULL; 1417 1452 } 1418 memset ((char *) f, 0, sizeof (*f));1419 1453 coff_symbol_from (abfd, sym)->native = csym = f->e; 1420 1454 } … … 1493 1527 { 1494 1528 char *debug_section; 1495 long position; 1529 file_ptr position; 1530 bfd_size_type sec_size; 1496 1531 1497 1532 asection *sect = bfd_get_section_by_name (abfd, ".debug"); … … 1503 1538 } 1504 1539 1505 debug_section = (PTR) bfd_alloc (abfd,1506 bfd_get_section_size_before_reloc (sect));1540 sec_size = bfd_get_section_size_before_reloc (sect); 1541 debug_section = (PTR) bfd_alloc (abfd, sec_size); 1507 1542 if (debug_section == NULL) 1508 1543 return NULL; … … 1514 1549 position = bfd_tell (abfd); 1515 1550 if (bfd_seek (abfd, sect->filepos, SEEK_SET) != 0 1516 || (bfd_read (debug_section, 1517 bfd_get_section_size_before_reloc (sect), 1, abfd) 1518 != bfd_get_section_size_before_reloc (sect)) 1551 || bfd_bread (debug_section, sec_size, abfd) != sec_size 1519 1552 || bfd_seek (abfd, position, SEEK_SET) != 0) 1520 1553 return NULL; … … 1529 1562 bfd *abfd; 1530 1563 char *name; 1531 int maxlen;1532 { 1533 int len;1564 size_t maxlen; 1565 { 1566 size_t len; 1534 1567 char *newname; 1535 1568 … … 1542 1575 } 1543 1576 1544 if ((newname = (PTR) bfd_alloc (abfd, len + 1)) == NULL)1577 if ((newname = (PTR) bfd_alloc (abfd, (bfd_size_type) len + 1)) == NULL) 1545 1578 return (NULL); 1546 1579 strncpy (newname, name, len); … … 1551 1584 /* Read in the external symbols. */ 1552 1585 1553 b oolean1586 bfd_boolean 1554 1587 _bfd_coff_get_external_symbols (abfd) 1555 1588 bfd *abfd; 1556 1589 { 1557 1590 bfd_size_type symesz; 1558 size_tsize;1591 bfd_size_type size; 1559 1592 PTR syms; 1560 1593 1561 1594 if (obj_coff_external_syms (abfd) != NULL) 1562 return true;1595 return TRUE; 1563 1596 1564 1597 symesz = bfd_coff_symesz (abfd); … … 1568 1601 syms = (PTR) bfd_malloc (size); 1569 1602 if (syms == NULL && size != 0) 1570 return false;1603 return FALSE; 1571 1604 1572 1605 if (bfd_seek (abfd, obj_sym_filepos (abfd), SEEK_SET) != 0 1573 || bfd_ read (syms, size, 1, abfd) != size)1606 || bfd_bread (syms, size, abfd) != size) 1574 1607 { 1575 1608 if (syms != NULL) 1576 1609 free (syms); 1577 return false;1610 return FALSE; 1578 1611 } 1579 1612 1580 1613 obj_coff_external_syms (abfd) = syms; 1581 1614 1582 return true;1615 return TRUE; 1583 1616 } 1584 1617 … … 1592 1625 { 1593 1626 char extstrsize[STRING_SIZE_SIZE]; 1594 size_tstrsize;1627 bfd_size_type strsize; 1595 1628 char *strings; 1629 file_ptr pos; 1596 1630 1597 1631 if (obj_coff_strings (abfd) != NULL) … … 1604 1638 } 1605 1639 1606 if (bfd_seek (abfd, 1607 (obj_sym_filepos (abfd) 1608 + obj_raw_syment_count (abfd) * bfd_coff_symesz (abfd)), 1609 SEEK_SET) != 0) 1640 pos = obj_sym_filepos (abfd); 1641 pos += obj_raw_syment_count (abfd) * bfd_coff_symesz (abfd); 1642 if (bfd_seek (abfd, pos, SEEK_SET) != 0) 1610 1643 return NULL; 1611 1644 1612 if (bfd_read (extstrsize, sizeof extstrsize, 1, abfd) != sizeof extstrsize) 1645 if (bfd_bread (extstrsize, (bfd_size_type) sizeof extstrsize, abfd) 1646 != sizeof extstrsize) 1613 1647 { 1614 1648 if (bfd_get_error () != bfd_error_file_truncated) … … 1621 1655 { 1622 1656 #if STRING_SIZE_SIZE == 4 1623 strsize = bfd_h_get_32 (abfd, (bfd_byte *)extstrsize);1657 strsize = H_GET_32 (abfd, extstrsize); 1624 1658 #else 1625 #error Change bfd_h_get_321659 #error Change H_GET_32 1626 1660 #endif 1627 1661 } … … 1630 1664 { 1631 1665 (*_bfd_error_handler) 1632 (_("%s: bad string table size %lu"), bfd_ get_filename (abfd),1666 (_("%s: bad string table size %lu"), bfd_archive_filename (abfd), 1633 1667 (unsigned long) strsize); 1634 1668 bfd_set_error (bfd_error_bad_value); … … 1640 1674 return NULL; 1641 1675 1642 if (bfd_read (strings + STRING_SIZE_SIZE, 1643 strsize - STRING_SIZE_SIZE, 1, abfd) 1676 if (bfd_bread (strings + STRING_SIZE_SIZE, strsize - STRING_SIZE_SIZE, abfd) 1644 1677 != strsize - STRING_SIZE_SIZE) 1645 1678 { … … 1655 1688 /* Free up the external symbols and strings read from a COFF file. */ 1656 1689 1657 b oolean1690 bfd_boolean 1658 1691 _bfd_coff_free_symbols (abfd) 1659 1692 bfd *abfd; … … 1671 1704 obj_coff_strings (abfd) = NULL; 1672 1705 } 1673 return true;1706 return TRUE; 1674 1707 } 1675 1708 … … 1687 1720 combined_entry_type *symbol_ptr; 1688 1721 combined_entry_type *internal_end; 1689 bfd_size_typesymesz;1722 size_t symesz; 1690 1723 char *raw_src; 1691 1724 char *raw_end; 1692 1725 const char *string_table = NULL; 1693 1726 char *debug_section = NULL; 1694 unsigned longsize;1727 bfd_size_type size; 1695 1728 1696 1729 if (obj_raw_syments (abfd) != NULL) … … 1735 1768 symbol_ptr->u.syment.n_type, 1736 1769 symbol_ptr->u.syment.n_sclass, 1737 i, symbol_ptr->u.syment.n_numaux,1770 (int) i, symbol_ptr->u.syment.n_numaux, 1738 1771 &(internal_ptr->u.auxent)); 1739 1772 coff_pointerize_aux (abfd, internal, symbol_ptr, i, … … 1743 1776 1744 1777 /* Free the raw symbols, but not the strings (if we have them). */ 1745 obj_coff_keep_strings (abfd) = true;1778 obj_coff_keep_strings (abfd) = TRUE; 1746 1779 if (! _bfd_coff_free_symbols (abfd)) 1747 1780 return NULL; … … 1790 1823 copy_name (abfd, 1791 1824 (internal_ptr + 1)->u.auxent.x_file.x_fname, 1792 bfd_coff_filnmlen (abfd)));1825 (size_t) bfd_coff_filnmlen (abfd))); 1793 1826 } 1794 1827 } … … 1799 1832 { 1800 1833 /* This is a "short" name. Make it long. */ 1801 unsigned long i = 0;1802 char *newstring = NULL;1834 size_t i; 1835 char *newstring; 1803 1836 1804 1837 /* find the length of this string without walking into memory 1805 1838 that isn't ours. */ 1806 1839 for (i = 0; i < 8; ++i) 1807 { 1808 if (internal_ptr->u.syment._n._n_name[i] == '\0') 1809 { 1810 break; 1811 } /* if end of string */ 1812 } /* possible lengths of this string. */ 1813 1814 if ((newstring = (PTR) bfd_alloc (abfd, ++i)) == NULL) 1840 if (internal_ptr->u.syment._n._n_name[i] == '\0') 1841 break; 1842 1843 newstring = (PTR) bfd_zalloc (abfd, (bfd_size_type) (i + 1)); 1844 if (newstring == NULL) 1815 1845 return (NULL); 1816 memset (newstring, 0, i); 1817 strncpy (newstring, internal_ptr->u.syment._n._n_name, i - 1); 1846 strncpy (newstring, internal_ptr->u.syment._n._n_name, i); 1818 1847 internal_ptr->u.syment._n._n_n._n_offset = (long int) newstring; 1819 1848 internal_ptr->u.syment._n._n_n._n_zeroes = 0; … … 1872 1901 bfd *abfd; 1873 1902 { 1874 coff_symbol_type *new = (coff_symbol_type *) bfd_alloc (abfd, sizeof (coff_symbol_type)); 1903 bfd_size_type amt = sizeof (coff_symbol_type); 1904 coff_symbol_type *new = (coff_symbol_type *) bfd_zalloc (abfd, amt); 1875 1905 if (new == NULL) 1876 1906 return (NULL); 1877 memset (new, 0, sizeof *new);1878 1907 new->symbol.section = 0; 1879 1908 new->native = 0; 1880 1909 new->lineno = (alent *) NULL; 1881 new->done_lineno = false;1910 new->done_lineno = FALSE; 1882 1911 new->symbol.the_bfd = abfd; 1883 1912 return &new->symbol; … … 1892 1921 unsigned long sz ATTRIBUTE_UNUSED; 1893 1922 { 1894 coff_symbol_type *new = (coff_symbol_type *) bfd_alloc (abfd, sizeof (coff_symbol_type)); 1923 bfd_size_type amt = sizeof (coff_symbol_type); 1924 coff_symbol_type *new = (coff_symbol_type *) bfd_alloc (abfd, amt); 1895 1925 if (new == NULL) 1896 1926 return (NULL); 1897 1927 /* @@ The 10 is a guess at a plausible maximum number of aux entries 1898 1928 (but shouldn't be a constant). */ 1899 new->native = (combined_entry_type *) bfd_zalloc (abfd, sizeof (combined_entry_type) * 10); 1929 amt = sizeof (combined_entry_type) * 10; 1930 new->native = (combined_entry_type *) bfd_zalloc (abfd, amt); 1900 1931 if (!new->native) 1901 1932 return (NULL); … … 1903 1934 new->symbol.flags = BSF_DEBUGGING; 1904 1935 new->lineno = (alent *) NULL; 1905 new->done_lineno = false;1936 new->done_lineno = FALSE; 1906 1937 new->symbol.the_bfd = abfd; 1907 1938 return &new->symbol; … … 1918 1949 && coffsymbol (symbol)->native->fix_value) 1919 1950 { 1920 combined_entry_type *psym; 1921 1922 psym = ((combined_entry_type *) 1923 coffsymbol (symbol)->native->u.syment.n_value); 1924 ret->value = (bfd_vma) (psym - obj_raw_syments (abfd)); 1951 ret->value = coffsymbol (symbol)->native->u.syment.n_value - 1952 (unsigned long) obj_raw_syments (abfd); 1925 1953 } 1926 1954 } … … 1928 1956 /* Return the COFF syment for a symbol. */ 1929 1957 1930 b oolean1958 bfd_boolean 1931 1959 bfd_coff_get_syment (abfd, symbol, psyment) 1932 1960 bfd *abfd; … … 1940 1968 { 1941 1969 bfd_set_error (bfd_error_invalid_operation); 1942 return false;1970 return FALSE; 1943 1971 } 1944 1972 … … 1946 1974 1947 1975 if (csym->native->fix_value) 1948 psyment->n_value = ((combined_entry_type *) psyment->n_value1949 - obj_raw_syments (abfd));1976 psyment->n_value = psyment->n_value - 1977 (unsigned long) obj_raw_syments (abfd); 1950 1978 1951 1979 /* FIXME: We should handle fix_line here. */ 1952 1980 1953 return true;1981 return TRUE; 1954 1982 } 1955 1983 1956 1984 /* Return the COFF auxent for a symbol. */ 1957 1985 1958 b oolean1986 bfd_boolean 1959 1987 bfd_coff_get_auxent (abfd, symbol, indx, pauxent) 1960 1988 bfd *abfd; … … 1973 2001 { 1974 2002 bfd_set_error (bfd_error_invalid_operation); 1975 return false;2003 return FALSE; 1976 2004 } 1977 2005 … … 1995 2023 - obj_raw_syments (abfd)); 1996 2024 1997 return true;2025 return TRUE; 1998 2026 } 1999 2027 … … 2024 2052 if (coffsymbol (symbol)->native) 2025 2053 { 2026 unsigned longval;2054 bfd_vma val; 2027 2055 unsigned int aux; 2028 2056 combined_entry_type *combined = coffsymbol (symbol)->native; … … 2033 2061 2034 2062 if (! combined->fix_value) 2035 val = ( unsigned long) combined->u.syment.n_value;2063 val = (bfd_vma) combined->u.syment.n_value; 2036 2064 else 2037 val = ((unsigned long) 2038 ((combined_entry_type *) combined->u.syment.n_value 2039 - root)); 2040 2065 val = combined->u.syment.n_value - (unsigned long) root; 2066 2067 #ifndef XCOFF64 2041 2068 fprintf (file, 2042 2069 "(sec %2d)(fl 0x%02x)(ty %3x)(scl %3d) (nx %d) 0x%08lx %s", … … 2046 2073 combined->u.syment.n_sclass, 2047 2074 combined->u.syment.n_numaux, 2075 (unsigned long) val, 2076 symbol->name); 2077 #else 2078 /* Print out the wide, 64 bit, symbol value */ 2079 fprintf (file, 2080 "(sec %2d)(fl 0x%02x)(ty %3x)(scl %3d) (nx %d) 0x%016llx %s", 2081 combined->u.syment.n_scnum, 2082 combined->u.syment.n_flags, 2083 combined->u.syment.n_type, 2084 combined->u.syment.n_sclass, 2085 combined->u.syment.n_numaux, 2048 2086 val, 2049 2087 symbol->name); 2088 #endif 2050 2089 2051 2090 for (aux = 0; aux < combined->u.syment.n_numaux; aux++) … … 2091 2130 if (ISFCN (combined->u.syment.n_type)) 2092 2131 { 2132 long next, llnos; 2133 2134 if (auxp->fix_end) 2135 next = (auxp->u.auxent.x_sym.x_fcnary.x_fcn.x_endndx.p 2136 - root); 2137 else 2138 next = auxp->u.auxent.x_sym.x_fcnary.x_fcn.x_endndx.l; 2139 llnos = auxp->u.auxent.x_sym.x_fcnary.x_fcn.x_lnnoptr; 2093 2140 fprintf (file, 2094 _("AUX tagndx %ld ttlsiz 0x%lx lnnos %ld next %ld"), 2095 tagndx, 2096 auxp->u.auxent.x_sym.x_misc.x_fsize, 2097 auxp->u.auxent.x_sym.x_fcnary.x_fcn.x_lnnoptr, 2098 (auxp->fix_end 2099 ? ((long) 2100 (auxp->u.auxent.x_sym.x_fcnary.x_fcn.x_endndx.p 2101 - root)) 2102 : auxp->u.auxent.x_sym.x_fcnary.x_fcn.x_endndx.l)); 2141 "AUX tagndx %ld ttlsiz 0x%lx lnnos %ld next %ld", 2142 tagndx, auxp->u.auxent.x_sym.x_misc.x_fsize, 2143 llnos, next); 2103 2144 break; 2104 2145 } … … 2134 2175 else 2135 2176 { 2136 bfd_print_symbol_vandf ( (PTR) file, symbol);2177 bfd_print_symbol_vandf (abfd, (PTR) file, symbol); 2137 2178 fprintf (file, " %-5s %s %s %s", 2138 2179 symbol->section->name, … … 2149 2190 override it. */ 2150 2191 2151 b oolean2192 bfd_boolean 2152 2193 _bfd_coff_is_local_label_name (abfd, name) 2153 2194 bfd *abfd ATTRIBUTE_UNUSED; … … 2161 2202 nearest to the wanted location. */ 2162 2203 2163 b oolean2204 bfd_boolean 2164 2205 coff_find_nearest_line (abfd, section, symbols, offset, filename_ptr, 2165 2206 functionname_ptr, line_ptr) … … 2168 2209 asymbol **symbols; 2169 2210 bfd_vma offset; 2170 CONSTchar **filename_ptr;2171 CONSTchar **functionname_ptr;2211 const char **filename_ptr; 2212 const char **functionname_ptr; 2172 2213 unsigned int *line_ptr; 2173 2214 { 2174 b oolean found;2215 bfd_boolean found; 2175 2216 unsigned int i; 2176 2217 unsigned int line_base; … … 2181 2222 alent *l; 2182 2223 struct coff_section_tdata *sec_data; 2224 bfd_size_type amt; 2183 2225 2184 2226 /* Before looking through the symbol table, try to use a .stab … … 2188 2230 functionname_ptr, line_ptr, 2189 2231 &coff_data(abfd)->line_info)) 2190 return false;2232 return FALSE; 2191 2233 2192 2234 if (found) 2193 return true;2235 return TRUE; 2194 2236 2195 2237 /* Also try examining DWARF2 debugging information. */ … … 2198 2240 line_ptr, 0, 2199 2241 &coff_data(abfd)->dwarf2_find_line_info)) 2200 return true;2242 return TRUE; 2201 2243 2202 2244 *filename_ptr = 0; … … 2206 2248 /* Don't try and find line numbers in a non coff file */ 2207 2249 if (!bfd_family_coff (abfd)) 2208 return false;2250 return FALSE; 2209 2251 2210 2252 if (cof == NULL) 2211 return false;2253 return FALSE; 2212 2254 2213 2255 /* Find the first C_FILE symbol. */ 2214 2256 p = cof->raw_syments; 2215 2257 if (!p) 2216 return false;2258 return FALSE; 2217 2259 2218 2260 pend = p + cof->raw_syment_count; … … 2265 2307 /* Avoid endless loops on erroneous files by ensuring that 2266 2308 we always move forward in the file. */ 2267 if (p - cof->raw_syments >=p->u.syment.n_value)2309 if (p >= cof->raw_syments + p->u.syment.n_value) 2268 2310 break; 2269 2311 … … 2355 2397 if (sec_data == NULL && section->owner == abfd) 2356 2398 { 2357 section->used_by_bfd = 2358 ((PTR) bfd_zalloc (abfd, 2359 sizeof (struct coff_section_tdata))); 2399 amt = sizeof (struct coff_section_tdata); 2400 section->used_by_bfd = (PTR) bfd_zalloc (abfd, amt); 2360 2401 sec_data = (struct coff_section_tdata *) section->used_by_bfd; 2361 2402 } … … 2368 2409 } 2369 2410 2370 return true;2411 return TRUE; 2371 2412 } 2372 2413 … … 2374 2415 coff_sizeof_headers (abfd, reloc) 2375 2416 bfd *abfd; 2376 b oolean reloc;2417 bfd_boolean reloc; 2377 2418 { 2378 2419 size_t size; 2379 2420 2380 if ( reloc == false)2421 if (! reloc) 2381 2422 { 2382 2423 size = bfd_coff_filhsz (abfd) + bfd_coff_aoutsz (abfd); … … 2392 2433 2393 2434 /* Change the class of a coff symbol held by BFD. */ 2394 b oolean2435 bfd_boolean 2395 2436 bfd_coff_set_symbol_class (abfd, symbol, class) 2396 2437 bfd * abfd; … … 2404 2445 { 2405 2446 bfd_set_error (bfd_error_invalid_operation); 2406 return false;2447 return FALSE; 2407 2448 } 2408 2449 else if (csym->native == NULL) … … 2414 2455 2415 2456 combined_entry_type * native; 2416 2417 native = (combined_entry_type *) bfd_alloc (abfd, sizeof (* native)); 2457 bfd_size_type amt = sizeof (* native); 2458 2459 native = (combined_entry_type *) bfd_zalloc (abfd, amt); 2418 2460 if (native == NULL) 2419 return false; 2420 2421 memset (native, 0, sizeof (* native)); 2461 return FALSE; 2422 2462 2423 2463 native->u.syment.n_type = T_NULL; … … 2443 2483 native->u.syment.n_value += symbol->section->output_section->vma; 2444 2484 2445 /* Copy the any flags from the thefile header into the symbol.2485 /* Copy the any flags from the file header into the symbol. 2446 2486 FIXME: Why? */ 2447 2487 native->u.syment.n_flags = bfd_asymbol_bfd (& csym->symbol)->flags; … … 2455 2495 } 2456 2496 2457 return true;2458 } 2497 return TRUE; 2498 } -
Property cvs2svn:cvs-rev
changed from
Note:
See TracChangeset
for help on using the changeset viewer.