Ignore:
Timestamp:
Aug 16, 2003, 6:59:22 PM (22 years ago)
Author:
bird
Message:

binutils v2.14 - offical sources.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • branches/GNU/src/binutils/bfd/libbfd.c

    • Property cvs2svn:cvs-rev changed from 1.1 to 1.1.1.2
    r608 r609  
    11/* Assorted BFD support routines, only used internally.
    22   Copyright 1990, 1991, 1992, 1993, 1994, 1995, 1996, 1997, 1998, 1999,
    3    2000, 2001
     3   2000, 2001, 2002
    44   Free Software Foundation, Inc.
    55   Written by Cygnus Support.
    66
    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.  */
     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.  */
    2222
    2323#include "bfd.h"
     
    2828#define getpagesize() 2048
    2929#endif
    30 
    31 static int real_read PARAMS ((PTR, size_t, size_t, FILE *));
    3230
    3331/*
     
    4442   operations.  */
    4543
    46 boolean
     44bfd_boolean
    4745bfd_false (ignore)
    4846     bfd *ignore ATTRIBUTE_UNUSED;
    4947{
    5048  bfd_set_error (bfd_error_invalid_operation);
    51   return false;
     49  return FALSE;
    5250}
    5351
     
    5553   which do not actually do anything.  */
    5654
    57 boolean
     55bfd_boolean
    5856bfd_true (ignore)
    5957     bfd *ignore ATTRIBUTE_UNUSED;
    6058{
    61   return true;
     59  return TRUE;
    6260}
    6361
     
    111109}
    112110
    113 boolean
     111bfd_boolean
    114112_bfd_nocore_core_file_matches_executable_p (ignore_core_bfd, ignore_exec_bfd)
    115113     bfd *ignore_core_bfd ATTRIBUTE_UNUSED;
     
    117115{
    118116  bfd_set_error (bfd_error_invalid_operation);
    119   return false;
     117  return FALSE;
    120118}
    121119
     
    155153PTR
    156154bfd_malloc (size)
    157      size_t size;
     155     bfd_size_type size;
    158156{
    159157  PTR ptr;
    160158
    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)
    163167    bfd_set_error (bfd_error_no_memory);
     168
    164169  return ptr;
    165170}
     
    170175bfd_realloc (ptr, size)
    171176     PTR ptr;
    172      size_t size;
     177     bfd_size_type size;
    173178{
    174179  PTR ret;
    175180
     181  if (size != (size_t) size)
     182    {
     183      bfd_set_error (bfd_error_no_memory);
     184      return NULL;
     185    }
     186
    176187  if (ptr == NULL)
    177     ret = malloc (size);
     188    ret = (PTR) malloc ((size_t) size);
    178189  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)
    182193    bfd_set_error (bfd_error_no_memory);
    183194
     
    189200PTR
    190201bfd_zmalloc (size)
    191      size_t size;
     202     bfd_size_type size;
    192203{
    193204  PTR ptr;
    194205
    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)
    198215    {
    199216      if (ptr == NULL)
    200217        bfd_set_error (bfd_error_no_memory);
    201218      else
    202         memset (ptr, 0, size);
     219        memset (ptr, 0, (size_t) size);
    203220    }
    204221
    205222  return ptr;
    206223}
    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's
    215    contents (0 for non-archive elements).  For archive entries this is the
    216    first octet in the file, NOT the beginning of the archive header.  */
    217 
    218 static int
    219 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 cover
    226      up for a feature of some OSs (not solaris - sigh) that
    227      ld/pe-dll.c takes advantage of (apparently) when it creates BFDs
    228      internally and tries to link against them.  BFD seems to be smart
    229      enough to realize there are no symbol records in the "file" that
    230      doesn't exist but attempts to read them anyway.  On Solaris,
    231      attempting to read zero bytes from a NULL file results in a core
    232      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 length
    240      information.  */
    241   return read (fileno (file), where, a * b);
    242 #else
    243   return fread (where, a, b, file);
    244 #endif
    245 }
    246 
    247 /* Return value is amount read (FIXME: how are errors and end of file dealt
    248    with?  We never call bfd_set_error, which is probably a mistake).  */
    249 
    250 bfd_size_type
    251 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           else
    271             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 to
    289      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       else
    295         bfd_set_error (bfd_error_file_truncated);
    296     }
    297 
    298   return nread;
    299 }
    300 
    301 /* The window support stuff should probably be broken out into
    302    another file....  */
    303 /* The idea behind the next and refcount fields is that one mapped
    304    region can suffice for multiple read-only windows or multiple
    305    non-overlapping read-write windows.  It's not implemented yet
    306    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 void
    316 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 is
    326    used.  Okay, so it's mis-named.  At least the command-line option
    327    "--without-mmap" is more obvious than "--without-windows" or some
    328    such.  */
    329 #ifdef USE_MMAP
    330 
    331 #undef HAVE_MPROTECT /* code's not tested yet */
    332 
    333 #if HAVE_MMAP || HAVE_MPROTECT || HAVE_MADVISE
    334 #include <sys/mman.h>
    335 #endif
    336 
    337 #ifndef MAP_FILE
    338 #define MAP_FILE 0
    339 #endif
    340 
    341 static int debug_windows;
    342 
    343 void
    344 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_MMAP
    362       munmap (i->data, i->size);
    363       goto no_free;
    364 #else
    365       abort ();
    366 #endif
    367     }
    368 #ifdef HAVE_MPROTECT
    369   mprotect (i->data, i->size, PROT_READ | PROT_WRITE);
    370 #endif
    371   free (i->data);
    372 #ifdef HAVE_MMAP
    373  no_free:
    374 #endif
    375   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 boolean
    383 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_MMAP
    414   if (ok_to_map
    415       && (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                       (writable
    450                        ? MAP_FILE | MAP_PRIVATE
    451                        : 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, or
    456              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       else
    479         fprintf (stderr, _("not mapping: env var not set\n"));
    480     }
    481 #else
    482   ok_to_map = 0;
    483 #endif
    484 
    485 #ifdef HAVE_MPROTECT
    486   if (!writable)
    487     {
    488       size_to_alloc += pagesize - 1;
    489       size_to_alloc -= size_to_alloc % pagesize;
    490     }
    491 #endif
    492   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_MPROTECT
    513   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 #endif
    521   windowp->data = i->data;
    522   windowp->size = i->size;
    523   return true;
    524 }
    525 
    526 #endif /* USE_MMAP */
    527 
    528 
    529 bfd_size_type
    530 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 ENOSPC
    570       if (nwrote >= 0)
    571         errno = ENOSPC;
    572 #endif
    573       bfd_set_error (bfd_error_system_call);
    574     }
    575   return nwrote;
    576 }
    577 
    578224/*
    579225INTERNAL_FUNCTION
     
    581227
    582228SYNOPSIS
    583         void bfd_write_bigendian_4byte_int(bfd *abfd,  int i);
     229        bfd_boolean bfd_write_bigendian_4byte_int (bfd *, unsigned int);
    584230
    585231DESCRIPTION
     
    589235
    590236*/
    591 void
     237bfd_boolean
    592238bfd_write_bigendian_4byte_int (abfd, i)
    593239     bfd *abfd;
    594      int i;
     240     unsigned int i;
    595241{
    596242  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
    782247
    783248
     
    825290.               bfd_put_8
    826291.#define bfd_get_8(abfd, ptr) \
    827 .                (*(unsigned char *) (ptr))
     292.                (*(unsigned char *) (ptr) & 0xff)
    828293.#define bfd_get_signed_8(abfd, ptr) \
    829 .               ((*(unsigned char *) (ptr) ^ 0x80) - 0x80)
     294.               (((*(unsigned char *) (ptr) & 0xff) ^ 0x80) - 0x80)
    830295.
    831296.#define bfd_put_16(abfd, val, ptr) \
     
    857322.
    858323.#define bfd_get(bits, abfd, ptr)                               \
    859 .                ((bits) == 8 ? bfd_get_8 (abfd, ptr)           \
     324.                ( (bits) ==  8 ? (bfd_vma) bfd_get_8 (abfd, ptr)       \
    860325.                : (bits) == 16 ? bfd_get_16 (abfd, ptr)        \
    861326.                : (bits) == 32 ? bfd_get_32 (abfd, ptr)        \
     
    864329.
    865330.#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)   \
    867332.                : (bits) == 16 ? bfd_put_16 (abfd, val, ptr)   \
    868333.                : (bits) == 32 ? bfd_put_32 (abfd, val, ptr)   \
     
    879344DESCRIPTION
    880345        These macros have the same function as their <<bfd_get_x>>
    881         bretheren, except that they are used for removing information
     346        brethren, except that they are used for removing information
    882347        for the header records of object files. Believe it or not,
    883348        some object files keep their header records in big endian
     
    887352.
    888353.#define bfd_h_put_8(abfd, val, ptr) \
    889 .               bfd_put_8 (abfd, val, ptr)
     354.  bfd_put_8 (abfd, val, ptr)
    890355.#define bfd_h_put_signed_8(abfd, val, ptr) \
    891 .               bfd_put_8 (abfd, val, ptr)
     356.  bfd_put_8 (abfd, val, ptr)
    892357.#define bfd_h_get_8(abfd, ptr) \
    893 .               bfd_get_8 (abfd, ptr)
     358.  bfd_get_8 (abfd, ptr)
    894359.#define bfd_h_get_signed_8(abfd, ptr) \
    895 .               bfd_get_signed_8 (abfd, ptr)
     360.  bfd_get_signed_8 (abfd, ptr)
    896361.
    897362.#define bfd_h_put_16(abfd, val, ptr) \
    898               BFD_SEND(abfd, bfd_h_putx16,(val,ptr))
     363BFD_SEND (abfd, bfd_h_putx16, (val, ptr))
    899364.#define bfd_h_put_signed_16 \
    900 .                bfd_h_put_16
     365.  bfd_h_put_16
    901366.#define bfd_h_get_16(abfd, ptr) \
    902               BFD_SEND(abfd, bfd_h_getx16,(ptr))
     367BFD_SEND (abfd, bfd_h_getx16, (ptr))
    903368.#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))
    905370.
    906371.#define bfd_h_put_32(abfd, val, ptr) \
    907               BFD_SEND(abfd, bfd_h_putx32,(val,ptr))
     372BFD_SEND (abfd, bfd_h_putx32, (val, ptr))
    908373.#define bfd_h_put_signed_32 \
    909 .                bfd_h_put_32
     374.  bfd_h_put_32
    910375.#define bfd_h_get_32(abfd, ptr) \
    911               BFD_SEND(abfd, bfd_h_getx32,(ptr))
     376BFD_SEND (abfd, bfd_h_getx32, (ptr))
    912377.#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))
    914379.
    915380.#define bfd_h_put_64(abfd, val, ptr) \
    916               BFD_SEND(abfd, bfd_h_putx64,(val, ptr))
     381BFD_SEND (abfd, bfd_h_putx64, (val, ptr))
    917382.#define bfd_h_put_signed_64 \
    918 .                bfd_h_put_64
     383.  bfd_h_put_64
    919384.#define bfd_h_get_64(abfd, ptr) \
    920               BFD_SEND(abfd, bfd_h_getx64,(ptr))
     385BFD_SEND (abfd, bfd_h_getx64, (ptr))
    921386.#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.*/
    925437
    926438/* Sign extension to bfd_signed_vma.  */
     
    1190702     bfd_byte *addr;
    1191703     int bits;
    1192      boolean big_p;
     704     bfd_boolean big_p;
    1193705{
    1194706  int i;
     
    1212724     bfd_byte *addr;
    1213725     int bits;
    1214      boolean big_p;
     726     bfd_boolean big_p;
    1215727{
    1216728  bfd_vma data;
     
    1236748/* Default implementation */
    1237749
    1238 boolean
     750bfd_boolean
    1239751_bfd_generic_get_section_contents (abfd, section, location, offset, count)
    1240752     bfd *abfd;
     
    1245757{
    1246758  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)
    1250762    {
    1251763      bfd_set_error (bfd_error_invalid_operation);
    1252       return false;
     764      return FALSE;
    1253765    }
    1254766
    1255767  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 boolean
     768      || bfd_bread (location, count, abfd) != count)
     769    return FALSE;
     770
     771  return TRUE;
     772}
     773
     774bfd_boolean
    1263775_bfd_generic_get_section_contents_in_window (abfd, section, w, offset, count)
    1264776     bfd *abfd ATTRIBUTE_UNUSED;
     
    1270782#ifdef USE_MMAP
    1271783  if (count == 0)
    1272     return true;
     784    return TRUE;
    1273785  if (abfd->xvec->_bfd_get_section_contents != _bfd_generic_get_section_contents)
    1274786    {
     
    1279791         allocated with malloc instead of mmap, just reuse it.  */
    1280792      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)));
    1282795      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);
    1285798      if (w->i->data == NULL)
    1286799        {
    1287800          free (w->i);
    1288801          w->i = NULL;
    1289           return false;
     802          return FALSE;
    1290803        }
    1291804      w->i->mapped = 0;
     
    1295808      return bfd_get_section_contents (abfd, section, w->data, offset, count);
    1296809    }
    1297   if ((bfd_size_type) (offset+count) > section->_raw_size
    1298       || (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;
    1302815#else
    1303816  abort ();
     
    1309822   in read-write files, though.  See other set_section_contents functions
    1310823   to see why it doesn't work for new sections.  */
    1311 boolean
     824bfd_boolean
    1312825_bfd_generic_set_section_contents (abfd, section, location, offset, count)
    1313826     bfd *abfd;
     
    1318831{
    1319832  if (count == 0)
    1320     return true;
    1321 
    1322   if (bfd_seek (abfd, (file_ptr) (section->filepos + offset), SEEK_SET) == -1
    1323       || 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;
    1327840}
    1328841
     
    1332845
    1333846SYNOPSIS
    1334         unsigned int bfd_log2(bfd_vma x);
     847        unsigned int bfd_log2 (bfd_vma x);
    1335848
    1336849DESCRIPTION
    1337850        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.
    1339852*/
    1340853
     
    1350863}
    1351864
    1352 boolean
     865bfd_boolean
    1353866bfd_generic_is_local_label_name (abfd, name)
    1354867     bfd *abfd;
     
    1357870  char locals_prefix = (bfd_get_symbol_leading_char (abfd) == '_') ? 'L' : '.';
    1358871
    1359   return (name[0] == locals_prefix);
     872  return name[0] == locals_prefix;
    1360873}
    1361874
    1362875/*  Can be used from / for bfd_merge_private_bfd_data to check that
    1363876    endianness matches between input and output file.  Returns
    1364     true for a match, otherwise returns false and emits an error.  */
    1365 boolean
     877    TRUE for a match, otherwise returns FALSE and emits an error.  */
     878bfd_boolean
    1366879_bfd_generic_verify_endian_match (ibfd, obfd)
    1367880     bfd *ibfd;
     
    1379892        msg = _("%s: compiled for a little endian system and target is big endian");
    1380893
    1381       (*_bfd_error_handler) (msg, bfd_get_filename (ibfd));
     894      (*_bfd_error_handler) (msg, bfd_archive_filename (ibfd));
    1382895
    1383896      bfd_set_error (bfd_error_wrong_format);
    1384       return false;
     897      return FALSE;
    1385898    }
    1386899
    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
     906void
     907warn_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}
Note: See TracChangeset for help on using the changeset viewer.