Changeset 609 for branches/GNU/src/binutils/bfd/libbfd.c
- Timestamp:
- Aug 16, 2003, 6:59:22 PM (22 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/GNU/src/binutils/bfd/libbfd.c
-
Property cvs2svn:cvs-rev
changed from
1.1
to1.1.1.2
r608 r609 1 1 /* Assorted BFD support routines, only used internally. 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. 6 6 7 This file is part of BFD, the Binary File Descriptor library.8 9 This program is free software; you can redistribute it and/or modify10 it under the terms of the GNU General Public License as published by11 the Free Software Foundation; either version 2 of the License, or12 (at your option) any later version.13 14 This program is distributed in the hope that it will be useful,15 but WITHOUT ANY WARRANTY; without even the implied warranty of16 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the17 GNU General Public License for more details.18 19 You should have received a copy of the GNU General Public License20 along with this program; if not, write to the Free Software21 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */7 This file is part of BFD, the Binary File Descriptor library. 8 9 This program is free software; you can redistribute it and/or modify 10 it under the terms of the GNU General Public License as published by 11 the Free Software Foundation; either version 2 of the License, or 12 (at your option) any later version. 13 14 This program is distributed in the hope that it will be useful, 15 but WITHOUT ANY WARRANTY; without even the implied warranty of 16 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 17 GNU General Public License for more details. 18 19 You should have received a copy of the GNU General Public License 20 along with this program; if not, write to the Free Software 21 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ 22 22 23 23 #include "bfd.h" … … 28 28 #define getpagesize() 2048 29 29 #endif 30 31 static int real_read PARAMS ((PTR, size_t, size_t, FILE *));32 30 33 31 /* … … 44 42 operations. */ 45 43 46 b oolean44 bfd_boolean 47 45 bfd_false (ignore) 48 46 bfd *ignore ATTRIBUTE_UNUSED; 49 47 { 50 48 bfd_set_error (bfd_error_invalid_operation); 51 return false;49 return FALSE; 52 50 } 53 51 … … 55 53 which do not actually do anything. */ 56 54 57 b oolean55 bfd_boolean 58 56 bfd_true (ignore) 59 57 bfd *ignore ATTRIBUTE_UNUSED; 60 58 { 61 return true;59 return TRUE; 62 60 } 63 61 … … 111 109 } 112 110 113 b oolean111 bfd_boolean 114 112 _bfd_nocore_core_file_matches_executable_p (ignore_core_bfd, ignore_exec_bfd) 115 113 bfd *ignore_core_bfd ATTRIBUTE_UNUSED; … … 117 115 { 118 116 bfd_set_error (bfd_error_invalid_operation); 119 return false;117 return FALSE; 120 118 } 121 119 … … 155 153 PTR 156 154 bfd_malloc (size) 157 size_tsize;155 bfd_size_type size; 158 156 { 159 157 PTR ptr; 160 158 161 ptr = (PTR) malloc (size); 162 if (ptr == NULL && size != 0) 159 if (size != (size_t) size) 160 { 161 bfd_set_error (bfd_error_no_memory); 162 return NULL; 163 } 164 165 ptr = (PTR) malloc ((size_t) size); 166 if (ptr == NULL && (size_t) size != 0) 163 167 bfd_set_error (bfd_error_no_memory); 168 164 169 return ptr; 165 170 } … … 170 175 bfd_realloc (ptr, size) 171 176 PTR ptr; 172 size_tsize;177 bfd_size_type size; 173 178 { 174 179 PTR ret; 175 180 181 if (size != (size_t) size) 182 { 183 bfd_set_error (bfd_error_no_memory); 184 return NULL; 185 } 186 176 187 if (ptr == NULL) 177 ret = malloc (size);188 ret = (PTR) malloc ((size_t) size); 178 189 else 179 ret = realloc (ptr,size);180 181 if (ret == NULL )190 ret = (PTR) realloc (ptr, (size_t) size); 191 192 if (ret == NULL && (size_t) size != 0) 182 193 bfd_set_error (bfd_error_no_memory); 183 194 … … 189 200 PTR 190 201 bfd_zmalloc (size) 191 size_tsize;202 bfd_size_type size; 192 203 { 193 204 PTR ptr; 194 205 195 ptr = (PTR) malloc (size); 196 197 if (size != 0) 206 if (size != (size_t) size) 207 { 208 bfd_set_error (bfd_error_no_memory); 209 return NULL; 210 } 211 212 ptr = (PTR) malloc ((size_t) size); 213 214 if ((size_t) size != 0) 198 215 { 199 216 if (ptr == NULL) 200 217 bfd_set_error (bfd_error_no_memory); 201 218 else 202 memset (ptr, 0, size);219 memset (ptr, 0, (size_t) size); 203 220 } 204 221 205 222 return ptr; 206 223 } 207 208 209 /* Some IO code */210 211 /* Note that archive entries don't have streams; they share their parent's.212 This allows someone to play with the iostream behind BFD's back.213 214 Also, note that the origin pointer points to the beginning of a file's215 contents (0 for non-archive elements). For archive entries this is the216 first octet in the file, NOT the beginning of the archive header. */217 218 static int219 real_read (where, a,b, file)220 PTR where;221 size_t a;222 size_t b;223 FILE *file;224 {225 /* FIXME - this looks like an optimization, but it's really to cover226 up for a feature of some OSs (not solaris - sigh) that227 ld/pe-dll.c takes advantage of (apparently) when it creates BFDs228 internally and tries to link against them. BFD seems to be smart229 enough to realize there are no symbol records in the "file" that230 doesn't exist but attempts to read them anyway. On Solaris,231 attempting to read zero bytes from a NULL file results in a core232 dump, but on other platforms it just returns zero bytes read.233 This makes it to something reasonable. - DJ */234 if (a == 0 || b == 0)235 return 0;236 237 238 #if defined (__VAX) && defined (VMS)239 /* Apparently fread on Vax VMS does not keep the record length240 information. */241 return read (fileno (file), where, a * b);242 #else243 return fread (where, a, b, file);244 #endif245 }246 247 /* Return value is amount read (FIXME: how are errors and end of file dealt248 with? We never call bfd_set_error, which is probably a mistake). */249 250 bfd_size_type251 bfd_read (ptr, size, nitems, abfd)252 PTR ptr;253 bfd_size_type size;254 bfd_size_type nitems;255 bfd *abfd;256 {257 int nread;258 259 if ((abfd->flags & BFD_IN_MEMORY) != 0)260 {261 struct bfd_in_memory *bim;262 bfd_size_type get;263 264 bim = (struct bfd_in_memory *) abfd->iostream;265 get = size * nitems;266 if (abfd->where + get > bim->size)267 {268 if (bim->size < (bfd_size_type) abfd->where)269 get = 0;270 else271 get = bim->size - abfd->where;272 bfd_set_error (bfd_error_file_truncated);273 }274 memcpy (ptr, bim->buffer + abfd->where, get);275 abfd->where += get;276 return get;277 }278 279 nread = real_read (ptr, 1, (size_t) (size*nitems), bfd_cache_lookup(abfd));280 if (nread > 0)281 abfd->where += nread;282 283 /* Set bfd_error if we did not read as much data as we expected.284 285 If the read failed due to an error set the bfd_error_system_call,286 else set bfd_error_file_truncated.287 288 A BFD backend may wish to override bfd_error_file_truncated to289 provide something more useful (eg. no_symbols or wrong_format). */290 if (nread != (int) (size * nitems))291 {292 if (ferror (bfd_cache_lookup (abfd)))293 bfd_set_error (bfd_error_system_call);294 else295 bfd_set_error (bfd_error_file_truncated);296 }297 298 return nread;299 }300 301 /* The window support stuff should probably be broken out into302 another file.... */303 /* The idea behind the next and refcount fields is that one mapped304 region can suffice for multiple read-only windows or multiple305 non-overlapping read-write windows. It's not implemented yet306 though. */307 struct _bfd_window_internal {308 struct _bfd_window_internal *next;309 PTR data;310 bfd_size_type size;311 int refcount : 31; /* should be enough... */312 unsigned mapped : 1; /* 1 = mmap, 0 = malloc */313 };314 315 void316 bfd_init_window (windowp)317 bfd_window *windowp;318 {319 windowp->data = 0;320 windowp->i = 0;321 windowp->size = 0;322 }323 324 325 /* Currently, if USE_MMAP is undefined, none if the window stuff is326 used. Okay, so it's mis-named. At least the command-line option327 "--without-mmap" is more obvious than "--without-windows" or some328 such. */329 #ifdef USE_MMAP330 331 #undef HAVE_MPROTECT /* code's not tested yet */332 333 #if HAVE_MMAP || HAVE_MPROTECT || HAVE_MADVISE334 #include <sys/mman.h>335 #endif336 337 #ifndef MAP_FILE338 #define MAP_FILE 0339 #endif340 341 static int debug_windows;342 343 void344 bfd_free_window (windowp)345 bfd_window *windowp;346 {347 bfd_window_internal *i = windowp->i;348 windowp->i = 0;349 windowp->data = 0;350 if (i == 0)351 return;352 i->refcount--;353 if (debug_windows)354 fprintf (stderr, "freeing window @%p<%p,%lx,%p>\n",355 windowp, windowp->data, windowp->size, windowp->i);356 if (i->refcount != 0)357 return;358 359 if (i->mapped)360 {361 #ifdef HAVE_MMAP362 munmap (i->data, i->size);363 goto no_free;364 #else365 abort ();366 #endif367 }368 #ifdef HAVE_MPROTECT369 mprotect (i->data, i->size, PROT_READ | PROT_WRITE);370 #endif371 free (i->data);372 #ifdef HAVE_MMAP373 no_free:374 #endif375 i->data = 0;376 /* There should be no more references to i at this point. */377 free (i);378 }379 380 static int ok_to_map = 1;381 382 boolean383 bfd_get_file_window (abfd, offset, size, windowp, writable)384 bfd *abfd;385 file_ptr offset;386 bfd_size_type size;387 bfd_window *windowp;388 boolean writable;389 {390 static size_t pagesize;391 bfd_window_internal *i = windowp->i;392 size_t size_to_alloc = size;393 394 if (debug_windows)395 fprintf (stderr, "bfd_get_file_window (%p, %6ld, %6ld, %p<%p,%lx,%p>, %d)",396 abfd, (long) offset, (long) size,397 windowp, windowp->data, (unsigned long) windowp->size,398 windowp->i, writable);399 400 /* Make sure we know the page size, so we can be friendly to mmap. */401 if (pagesize == 0)402 pagesize = getpagesize ();403 if (pagesize == 0)404 abort ();405 406 if (i == 0)407 {408 windowp->i = i = (bfd_window_internal *) bfd_zmalloc (sizeof (bfd_window_internal));409 if (i == 0)410 return false;411 i->data = 0;412 }413 #ifdef HAVE_MMAP414 if (ok_to_map415 && (i->data == 0 || i->mapped == 1)416 && (abfd->flags & BFD_IN_MEMORY) == 0)417 {418 file_ptr file_offset, offset2;419 size_t real_size;420 int fd;421 FILE *f;422 423 /* Find the real file and the real offset into it. */424 while (abfd->my_archive != NULL)425 {426 offset += abfd->origin;427 abfd = abfd->my_archive;428 }429 f = bfd_cache_lookup (abfd);430 fd = fileno (f);431 432 /* Compute offsets and size for mmap and for the user's data. */433 offset2 = offset % pagesize;434 if (offset2 < 0)435 abort ();436 file_offset = offset - offset2;437 real_size = offset + size - file_offset;438 real_size = real_size + pagesize - 1;439 real_size -= real_size % pagesize;440 441 /* If we're re-using a memory region, make sure it's big enough. */442 if (i->data && i->size < size)443 {444 munmap (i->data, i->size);445 i->data = 0;446 }447 i->data = mmap (i->data, real_size,448 writable ? PROT_WRITE | PROT_READ : PROT_READ,449 (writable450 ? MAP_FILE | MAP_PRIVATE451 : MAP_FILE | MAP_SHARED),452 fd, file_offset);453 if (i->data == (PTR) -1)454 {455 /* An error happened. Report it, or try using malloc, or456 something. */457 bfd_set_error (bfd_error_system_call);458 i->data = 0;459 windowp->data = 0;460 if (debug_windows)461 fprintf (stderr, "\t\tmmap failed!\n");462 return false;463 }464 if (debug_windows)465 fprintf (stderr, "\n\tmapped %ld at %p, offset is %ld\n",466 (long) real_size, i->data, (long) offset2);467 i->size = real_size;468 windowp->data = (PTR) ((bfd_byte *) i->data + offset2);469 windowp->size = size;470 i->mapped = 1;471 return true;472 }473 else if (debug_windows)474 {475 if (ok_to_map)476 fprintf (stderr, _("not mapping: data=%lx mapped=%d\n"),477 (unsigned long) i->data, (int) i->mapped);478 else479 fprintf (stderr, _("not mapping: env var not set\n"));480 }481 #else482 ok_to_map = 0;483 #endif484 485 #ifdef HAVE_MPROTECT486 if (!writable)487 {488 size_to_alloc += pagesize - 1;489 size_to_alloc -= size_to_alloc % pagesize;490 }491 #endif492 if (debug_windows)493 fprintf (stderr, "\n\t%s(%6ld)",494 i->data ? "realloc" : " malloc", (long) size_to_alloc);495 i->data = (PTR) bfd_realloc (i->data, size_to_alloc);496 if (debug_windows)497 fprintf (stderr, "\t-> %p\n", i->data);498 i->refcount = 1;499 if (i->data == NULL)500 {501 if (size_to_alloc == 0)502 return true;503 bfd_set_error (bfd_error_no_memory);504 return false;505 }506 if (bfd_seek (abfd, offset, SEEK_SET) != 0)507 return false;508 i->size = bfd_read (i->data, size, 1, abfd);509 if (i->size != size)510 return false;511 i->mapped = 0;512 #ifdef HAVE_MPROTECT513 if (!writable)514 {515 if (debug_windows)516 fprintf (stderr, "\tmprotect (%p, %ld, PROT_READ)\n", i->data,517 (long) i->size);518 mprotect (i->data, i->size, PROT_READ);519 }520 #endif521 windowp->data = i->data;522 windowp->size = i->size;523 return true;524 }525 526 #endif /* USE_MMAP */527 528 529 bfd_size_type530 bfd_write (ptr, size, nitems, abfd)531 CONST PTR ptr;532 bfd_size_type size;533 bfd_size_type nitems;534 bfd *abfd;535 {536 long nwrote;537 538 if ((abfd->flags & BFD_IN_MEMORY) != 0)539 {540 struct bfd_in_memory *bim = (struct bfd_in_memory *) (abfd->iostream);541 size *= nitems;542 if (abfd->where + size > bim->size)543 {544 long newsize, oldsize = (bim->size + 127) & ~127;545 bim->size = abfd->where + size;546 /* Round up to cut down on memory fragmentation */547 newsize = (bim->size + 127) & ~127;548 if (newsize > oldsize)549 {550 bim->buffer = bfd_realloc (bim->buffer, newsize);551 if (bim->buffer == 0)552 {553 bim->size = 0;554 return 0;555 }556 }557 }558 memcpy (bim->buffer + abfd->where, ptr, size);559 abfd->where += size;560 return size;561 }562 563 nwrote = fwrite (ptr, 1, (size_t) (size * nitems),564 bfd_cache_lookup (abfd));565 if (nwrote > 0)566 abfd->where += nwrote;567 if ((bfd_size_type) nwrote != size * nitems)568 {569 #ifdef ENOSPC570 if (nwrote >= 0)571 errno = ENOSPC;572 #endif573 bfd_set_error (bfd_error_system_call);574 }575 return nwrote;576 }577 578 224 /* 579 225 INTERNAL_FUNCTION … … 581 227 582 228 SYNOPSIS 583 void bfd_write_bigendian_4byte_int(bfd *abfd, int i);229 bfd_boolean bfd_write_bigendian_4byte_int (bfd *, unsigned int); 584 230 585 231 DESCRIPTION … … 589 235 590 236 */ 591 void 237 bfd_boolean 592 238 bfd_write_bigendian_4byte_int (abfd, i) 593 239 bfd *abfd; 594 int i;240 unsigned int i; 595 241 { 596 242 bfd_byte buffer[4]; 597 bfd_putb32(i, buffer); 598 if (bfd_write((PTR)buffer, 4, 1, abfd) != 4) 599 abort (); 600 } 601 602 long 603 bfd_tell (abfd) 604 bfd *abfd; 605 { 606 file_ptr ptr; 607 608 if ((abfd->flags & BFD_IN_MEMORY) != 0) 609 return abfd->where; 610 611 ptr = ftell (bfd_cache_lookup(abfd)); 612 613 if (abfd->my_archive) 614 ptr -= abfd->origin; 615 abfd->where = ptr; 616 return ptr; 617 } 618 619 int 620 bfd_flush (abfd) 621 bfd *abfd; 622 { 623 if ((abfd->flags & BFD_IN_MEMORY) != 0) 624 return 0; 625 return fflush (bfd_cache_lookup(abfd)); 626 } 627 628 /* Returns 0 for success, negative value for failure (in which case 629 bfd_get_error can retrieve the error code). */ 630 int 631 bfd_stat (abfd, statbuf) 632 bfd *abfd; 633 struct stat *statbuf; 634 { 635 FILE *f; 636 int result; 637 638 if ((abfd->flags & BFD_IN_MEMORY) != 0) 639 abort (); 640 641 f = bfd_cache_lookup (abfd); 642 if (f == NULL) 643 { 644 bfd_set_error (bfd_error_system_call); 645 return -1; 646 } 647 result = fstat (fileno (f), statbuf); 648 if (result < 0) 649 bfd_set_error (bfd_error_system_call); 650 return result; 651 } 652 653 /* Returns 0 for success, nonzero for failure (in which case bfd_get_error 654 can retrieve the error code). */ 655 656 int 657 bfd_seek (abfd, position, direction) 658 bfd *abfd; 659 file_ptr position; 660 int direction; 661 { 662 int result; 663 FILE *f; 664 file_ptr file_position; 665 /* For the time being, a BFD may not seek to it's end. The problem 666 is that we don't easily have a way to recognize the end of an 667 element in an archive. */ 668 669 BFD_ASSERT (direction == SEEK_SET || direction == SEEK_CUR); 670 671 if (direction == SEEK_CUR && position == 0) 672 return 0; 673 674 if ((abfd->flags & BFD_IN_MEMORY) != 0) 675 { 676 struct bfd_in_memory *bim; 677 678 bim = (struct bfd_in_memory *) abfd->iostream; 679 680 if (direction == SEEK_SET) 681 abfd->where = position; 682 else 683 abfd->where += position; 684 685 if ((bfd_size_type) abfd->where > bim->size) 686 { 687 if ((abfd->direction == write_direction) || 688 (abfd->direction == both_direction)) 689 { 690 long newsize, oldsize = (bim->size + 127) & ~127; 691 bim->size = abfd->where; 692 /* Round up to cut down on memory fragmentation */ 693 newsize = (bim->size + 127) & ~127; 694 if (newsize > oldsize) 695 { 696 bim->buffer = bfd_realloc (bim->buffer, newsize); 697 if (bim->buffer == 0) 698 { 699 bim->size = 0; 700 bfd_set_error (bfd_error_no_memory); 701 return -1; 702 } 703 } 704 } 705 else 706 { 707 abfd->where = bim->size; 708 bfd_set_error (bfd_error_file_truncated); 709 return -1; 710 } 711 } 712 return 0; 713 } 714 715 if (abfd->format != bfd_archive && abfd->my_archive == 0) 716 { 717 #if 0 718 /* Explanation for this code: I'm only about 95+% sure that the above 719 conditions are sufficient and that all i/o calls are properly 720 adjusting the `where' field. So this is sort of an `assert' 721 that the `where' field is correct. If we can go a while without 722 tripping the abort, we can probably safely disable this code, 723 so that the real optimizations happen. */ 724 file_ptr where_am_i_now; 725 where_am_i_now = ftell (bfd_cache_lookup (abfd)); 726 if (abfd->my_archive) 727 where_am_i_now -= abfd->origin; 728 if (where_am_i_now != abfd->where) 729 abort (); 730 #endif 731 if (direction == SEEK_SET && position == abfd->where) 732 return 0; 733 } 734 else 735 { 736 /* We need something smarter to optimize access to archives. 737 Currently, anything inside an archive is read via the file 738 handle for the archive. Which means that a bfd_seek on one 739 component affects the `current position' in the archive, as 740 well as in any other component. 741 742 It might be sufficient to put a spike through the cache 743 abstraction, and look to the archive for the file position, 744 but I think we should try for something cleaner. 745 746 In the meantime, no optimization for archives. */ 747 } 748 749 f = bfd_cache_lookup (abfd); 750 file_position = position; 751 if (direction == SEEK_SET && abfd->my_archive != NULL) 752 file_position += abfd->origin; 753 754 result = fseek (f, file_position, direction); 755 if (result != 0) 756 { 757 int hold_errno = errno; 758 759 /* Force redetermination of `where' field. */ 760 bfd_tell (abfd); 761 762 /* An EINVAL error probably means that the file offset was 763 absurd. */ 764 if (hold_errno == EINVAL) 765 bfd_set_error (bfd_error_file_truncated); 766 else 767 { 768 bfd_set_error (bfd_error_system_call); 769 errno = hold_errno; 770 } 771 } 772 else 773 { 774 /* Adjust `where' field. */ 775 if (direction == SEEK_SET) 776 abfd->where = position; 777 else 778 abfd->where += position; 779 } 780 return result; 781 } 243 bfd_putb32 ((bfd_vma) i, buffer); 244 return bfd_bwrite ((PTR) buffer, (bfd_size_type) 4, abfd) == 4; 245 } 246 782 247 783 248 … … 825 290 . bfd_put_8 826 291 .#define bfd_get_8(abfd, ptr) \ 827 . (*(unsigned char *) (ptr) )292 . (*(unsigned char *) (ptr) & 0xff) 828 293 .#define bfd_get_signed_8(abfd, ptr) \ 829 . (( *(unsigned char *) (ptr) ^ 0x80) - 0x80)294 . (((*(unsigned char *) (ptr) & 0xff) ^ 0x80) - 0x80) 830 295 . 831 296 .#define bfd_put_16(abfd, val, ptr) \ … … 857 322 . 858 323 .#define bfd_get(bits, abfd, ptr) \ 859 . ( (bits) == 8 ? bfd_get_8 (abfd, ptr)\324 . ( (bits) == 8 ? (bfd_vma) bfd_get_8 (abfd, ptr) \ 860 325 . : (bits) == 16 ? bfd_get_16 (abfd, ptr) \ 861 326 . : (bits) == 32 ? bfd_get_32 (abfd, ptr) \ … … 864 329 . 865 330 .#define bfd_put(bits, abfd, val, ptr) \ 866 . ( (bits) == 8 ? bfd_put_8(abfd, val, ptr) \331 . ( (bits) == 8 ? bfd_put_8 (abfd, val, ptr) \ 867 332 . : (bits) == 16 ? bfd_put_16 (abfd, val, ptr) \ 868 333 . : (bits) == 32 ? bfd_put_32 (abfd, val, ptr) \ … … 879 344 DESCRIPTION 880 345 These macros have the same function as their <<bfd_get_x>> 881 breth eren, except that they are used for removing information346 brethren, except that they are used for removing information 882 347 for the header records of object files. Believe it or not, 883 348 some object files keep their header records in big endian … … 887 352 . 888 353 .#define bfd_h_put_8(abfd, val, ptr) \ 889 . 354 . bfd_put_8 (abfd, val, ptr) 890 355 .#define bfd_h_put_signed_8(abfd, val, ptr) \ 891 . 356 . bfd_put_8 (abfd, val, ptr) 892 357 .#define bfd_h_get_8(abfd, ptr) \ 893 . 358 . bfd_get_8 (abfd, ptr) 894 359 .#define bfd_h_get_signed_8(abfd, ptr) \ 895 . 360 . bfd_get_signed_8 (abfd, ptr) 896 361 . 897 362 .#define bfd_h_put_16(abfd, val, ptr) \ 898 . BFD_SEND(abfd, bfd_h_putx16,(val,ptr))363 . BFD_SEND (abfd, bfd_h_putx16, (val, ptr)) 899 364 .#define bfd_h_put_signed_16 \ 900 . 365 . bfd_h_put_16 901 366 .#define bfd_h_get_16(abfd, ptr) \ 902 . BFD_SEND(abfd, bfd_h_getx16,(ptr))367 . BFD_SEND (abfd, bfd_h_getx16, (ptr)) 903 368 .#define bfd_h_get_signed_16(abfd, ptr) \ 904 . BFD_SEND(abfd, bfd_h_getx_signed_16, (ptr))369 . BFD_SEND (abfd, bfd_h_getx_signed_16, (ptr)) 905 370 . 906 371 .#define bfd_h_put_32(abfd, val, ptr) \ 907 . BFD_SEND(abfd, bfd_h_putx32,(val,ptr))372 . BFD_SEND (abfd, bfd_h_putx32, (val, ptr)) 908 373 .#define bfd_h_put_signed_32 \ 909 . 374 . bfd_h_put_32 910 375 .#define bfd_h_get_32(abfd, ptr) \ 911 . BFD_SEND(abfd, bfd_h_getx32,(ptr))376 . BFD_SEND (abfd, bfd_h_getx32, (ptr)) 912 377 .#define bfd_h_get_signed_32(abfd, ptr) \ 913 . BFD_SEND(abfd, bfd_h_getx_signed_32, (ptr))378 . BFD_SEND (abfd, bfd_h_getx_signed_32, (ptr)) 914 379 . 915 380 .#define bfd_h_put_64(abfd, val, ptr) \ 916 . BFD_SEND(abfd, bfd_h_putx64,(val, ptr))381 . BFD_SEND (abfd, bfd_h_putx64, (val, ptr)) 917 382 .#define bfd_h_put_signed_64 \ 918 . 383 . bfd_h_put_64 919 384 .#define bfd_h_get_64(abfd, ptr) \ 920 . BFD_SEND(abfd, bfd_h_getx64,(ptr))385 . BFD_SEND (abfd, bfd_h_getx64, (ptr)) 921 386 .#define bfd_h_get_signed_64(abfd, ptr) \ 922 . BFD_SEND(abfd, bfd_h_getx_signed_64, (ptr)) 923 . 924 */ 387 . BFD_SEND (abfd, bfd_h_getx_signed_64, (ptr)) 388 . 389 .{* Refinements on the above, which should eventually go away. Save 390 . cluttering the source with (bfd_vma) and (bfd_byte *) casts. *} 391 . 392 .#define H_PUT_64(abfd, val, where) \ 393 . bfd_h_put_64 ((abfd), (bfd_vma) (val), (bfd_byte *) (where)) 394 . 395 .#define H_PUT_32(abfd, val, where) \ 396 . bfd_h_put_32 ((abfd), (bfd_vma) (val), (bfd_byte *) (where)) 397 . 398 .#define H_PUT_16(abfd, val, where) \ 399 . bfd_h_put_16 ((abfd), (bfd_vma) (val), (bfd_byte *) (where)) 400 . 401 .#define H_PUT_8 bfd_h_put_8 402 . 403 .#define H_PUT_S64(abfd, val, where) \ 404 . bfd_h_put_signed_64 ((abfd), (bfd_vma) (val), (bfd_byte *) (where)) 405 . 406 .#define H_PUT_S32(abfd, val, where) \ 407 . bfd_h_put_signed_32 ((abfd), (bfd_vma) (val), (bfd_byte *) (where)) 408 . 409 .#define H_PUT_S16(abfd, val, where) \ 410 . bfd_h_put_signed_16 ((abfd), (bfd_vma) (val), (bfd_byte *) (where)) 411 . 412 .#define H_PUT_S8 bfd_h_put_signed_8 413 . 414 .#define H_GET_64(abfd, where) \ 415 . bfd_h_get_64 ((abfd), (bfd_byte *) (where)) 416 . 417 .#define H_GET_32(abfd, where) \ 418 . bfd_h_get_32 ((abfd), (bfd_byte *) (where)) 419 . 420 .#define H_GET_16(abfd, where) \ 421 . bfd_h_get_16 ((abfd), (bfd_byte *) (where)) 422 . 423 .#define H_GET_8 bfd_h_get_8 424 . 425 .#define H_GET_S64(abfd, where) \ 426 . bfd_h_get_signed_64 ((abfd), (bfd_byte *) (where)) 427 . 428 .#define H_GET_S32(abfd, where) \ 429 . bfd_h_get_signed_32 ((abfd), (bfd_byte *) (where)) 430 . 431 .#define H_GET_S16(abfd, where) \ 432 . bfd_h_get_signed_16 ((abfd), (bfd_byte *) (where)) 433 . 434 .#define H_GET_S8 bfd_h_get_signed_8 435 . 436 .*/ 925 437 926 438 /* Sign extension to bfd_signed_vma. */ … … 1190 702 bfd_byte *addr; 1191 703 int bits; 1192 b oolean big_p;704 bfd_boolean big_p; 1193 705 { 1194 706 int i; … … 1212 724 bfd_byte *addr; 1213 725 int bits; 1214 b oolean big_p;726 bfd_boolean big_p; 1215 727 { 1216 728 bfd_vma data; … … 1236 748 /* Default implementation */ 1237 749 1238 b oolean750 bfd_boolean 1239 751 _bfd_generic_get_section_contents (abfd, section, location, offset, count) 1240 752 bfd *abfd; … … 1245 757 { 1246 758 if (count == 0) 1247 return true;1248 1249 if ( (bfd_size_type) (offset + count)> section->_raw_size)759 return TRUE; 760 761 if (offset + count > section->_raw_size) 1250 762 { 1251 763 bfd_set_error (bfd_error_invalid_operation); 1252 return false;764 return FALSE; 1253 765 } 1254 766 1255 767 if (bfd_seek (abfd, section->filepos + offset, SEEK_SET) != 0 1256 || bfd_ read (location, (bfd_size_type) 1, count, abfd) != count)1257 return false;1258 1259 return true;1260 } 1261 1262 b oolean768 || bfd_bread (location, count, abfd) != count) 769 return FALSE; 770 771 return TRUE; 772 } 773 774 bfd_boolean 1263 775 _bfd_generic_get_section_contents_in_window (abfd, section, w, offset, count) 1264 776 bfd *abfd ATTRIBUTE_UNUSED; … … 1270 782 #ifdef USE_MMAP 1271 783 if (count == 0) 1272 return true;784 return TRUE; 1273 785 if (abfd->xvec->_bfd_get_section_contents != _bfd_generic_get_section_contents) 1274 786 { … … 1279 791 allocated with malloc instead of mmap, just reuse it. */ 1280 792 bfd_free_window (w); 1281 w->i = (bfd_window_internal *) bfd_zmalloc (sizeof (bfd_window_internal)); 793 w->i = ((bfd_window_internal *) 794 bfd_zmalloc ((bfd_size_type) sizeof (bfd_window_internal))); 1282 795 if (w->i == NULL) 1283 return false;1284 w->i->data = (PTR) bfd_malloc ( (size_t)count);796 return FALSE; 797 w->i->data = (PTR) bfd_malloc (count); 1285 798 if (w->i->data == NULL) 1286 799 { 1287 800 free (w->i); 1288 801 w->i = NULL; 1289 return false;802 return FALSE; 1290 803 } 1291 804 w->i->mapped = 0; … … 1295 808 return bfd_get_section_contents (abfd, section, w->data, offset, count); 1296 809 } 1297 if ( (bfd_size_type) (offset+count)> section->_raw_size1298 || (bfd_get_file_window (abfd, section->filepos + offset, count, w, true)1299 == false))1300 return false;1301 return true;810 if (offset + count > section->_raw_size 811 || ! bfd_get_file_window (abfd, section->filepos + offset, count, w, 812 TRUE)) 813 return FALSE; 814 return TRUE; 1302 815 #else 1303 816 abort (); … … 1309 822 in read-write files, though. See other set_section_contents functions 1310 823 to see why it doesn't work for new sections. */ 1311 b oolean824 bfd_boolean 1312 825 _bfd_generic_set_section_contents (abfd, section, location, offset, count) 1313 826 bfd *abfd; … … 1318 831 { 1319 832 if (count == 0) 1320 return true;1321 1322 if (bfd_seek (abfd, (file_ptr) (section->filepos + offset), SEEK_SET) == -11323 || bfd_ write (location, (bfd_size_type) 1, count, abfd) != count)1324 return false;1325 1326 return true;833 return TRUE; 834 835 if (bfd_seek (abfd, section->filepos + offset, SEEK_SET) != 0 836 || bfd_bwrite (location, count, abfd) != count) 837 return FALSE; 838 839 return TRUE; 1327 840 } 1328 841 … … 1332 845 1333 846 SYNOPSIS 1334 unsigned int bfd_log2 (bfd_vma x);847 unsigned int bfd_log2 (bfd_vma x); 1335 848 1336 849 DESCRIPTION 1337 850 Return the log base 2 of the value supplied, rounded up. E.g., an 1338 @var{x} of 1025 returns 11. 851 @var{x} of 1025 returns 11. A @var{x} of 0 returns 0. 1339 852 */ 1340 853 … … 1350 863 } 1351 864 1352 b oolean865 bfd_boolean 1353 866 bfd_generic_is_local_label_name (abfd, name) 1354 867 bfd *abfd; … … 1357 870 char locals_prefix = (bfd_get_symbol_leading_char (abfd) == '_') ? 'L' : '.'; 1358 871 1359 return (name[0] == locals_prefix);872 return name[0] == locals_prefix; 1360 873 } 1361 874 1362 875 /* Can be used from / for bfd_merge_private_bfd_data to check that 1363 876 endianness matches between input and output file. Returns 1364 true for a match, otherwise returns falseand emits an error. */1365 b oolean877 TRUE for a match, otherwise returns FALSE and emits an error. */ 878 bfd_boolean 1366 879 _bfd_generic_verify_endian_match (ibfd, obfd) 1367 880 bfd *ibfd; … … 1379 892 msg = _("%s: compiled for a little endian system and target is big endian"); 1380 893 1381 (*_bfd_error_handler) (msg, bfd_ get_filename (ibfd));894 (*_bfd_error_handler) (msg, bfd_archive_filename (ibfd)); 1382 895 1383 896 bfd_set_error (bfd_error_wrong_format); 1384 return false;897 return FALSE; 1385 898 } 1386 899 1387 return true; 1388 } 900 return TRUE; 901 } 902 903 /* Give a warning at runtime if someone compiles code which calls 904 old routines. */ 905 906 void 907 warn_deprecated (what, file, line, func) 908 const char *what; 909 const char *file; 910 int line; 911 const char *func; 912 { 913 /* Poor man's tracking of functions we've already warned about. */ 914 static size_t mask = 0; 915 916 if (~(size_t) func & ~mask) 917 { 918 /* Note: separate sentences in order to allow 919 for translation into other languages. */ 920 if (func) 921 fprintf (stderr, _("Deprecated %s called at %s line %d in %s\n"), 922 what, file, line, func); 923 else 924 fprintf (stderr, _("Deprecated %s called\n"), what); 925 mask |= ~(size_t) func; 926 } 927 } -
Property cvs2svn:cvs-rev
changed from
Note:
See TracChangeset
for help on using the changeset viewer.