Home | History | Annotate | Line # | Download | only in bfd
libbfd.c revision 1.1.1.5
      1      1.1  christos /* Assorted BFD support routines, only used internally.
      2  1.1.1.5  christos    Copyright (C) 1990-2017 Free Software Foundation, Inc.
      3      1.1  christos    Written by Cygnus Support.
      4      1.1  christos 
      5      1.1  christos    This file is part of BFD, the Binary File Descriptor library.
      6      1.1  christos 
      7      1.1  christos    This program is free software; you can redistribute it and/or modify
      8      1.1  christos    it under the terms of the GNU General Public License as published by
      9      1.1  christos    the Free Software Foundation; either version 3 of the License, or
     10      1.1  christos    (at your option) any later version.
     11      1.1  christos 
     12      1.1  christos    This program is distributed in the hope that it will be useful,
     13      1.1  christos    but WITHOUT ANY WARRANTY; without even the implied warranty of
     14      1.1  christos    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
     15      1.1  christos    GNU General Public License for more details.
     16      1.1  christos 
     17      1.1  christos    You should have received a copy of the GNU General Public License
     18      1.1  christos    along with this program; if not, write to the Free Software
     19      1.1  christos    Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston,
     20      1.1  christos    MA 02110-1301, USA.  */
     21      1.1  christos 
     22      1.1  christos #include "sysdep.h"
     23      1.1  christos #include "bfd.h"
     24      1.1  christos #include "libbfd.h"
     25      1.1  christos 
     26      1.1  christos #ifndef HAVE_GETPAGESIZE
     27      1.1  christos #define getpagesize() 2048
     28      1.1  christos #endif
     29      1.1  christos 
     30      1.1  christos /*
     31      1.1  christos SECTION
     32      1.1  christos 	Implementation details
     33      1.1  christos 
     34      1.1  christos SUBSECTION
     35      1.1  christos 	Internal functions
     36      1.1  christos 
     37      1.1  christos DESCRIPTION
     38      1.1  christos 	These routines are used within BFD.
     39      1.1  christos 	They are not intended for export, but are documented here for
     40      1.1  christos 	completeness.
     41      1.1  christos */
     42      1.1  christos 
     43      1.1  christos /* A routine which is used in target vectors for unsupported
     44      1.1  christos    operations.  */
     45      1.1  christos 
     46      1.1  christos bfd_boolean
     47      1.1  christos bfd_false (bfd *ignore ATTRIBUTE_UNUSED)
     48      1.1  christos {
     49      1.1  christos   bfd_set_error (bfd_error_invalid_operation);
     50      1.1  christos   return FALSE;
     51      1.1  christos }
     52      1.1  christos 
     53      1.1  christos /* A routine which is used in target vectors for supported operations
     54      1.1  christos    which do not actually do anything.  */
     55      1.1  christos 
     56      1.1  christos bfd_boolean
     57      1.1  christos bfd_true (bfd *ignore ATTRIBUTE_UNUSED)
     58      1.1  christos {
     59      1.1  christos   return TRUE;
     60      1.1  christos }
     61      1.1  christos 
     62      1.1  christos /* A routine which is used in target vectors for unsupported
     63      1.1  christos    operations which return a pointer value.  */
     64      1.1  christos 
     65      1.1  christos void *
     66      1.1  christos bfd_nullvoidptr (bfd *ignore ATTRIBUTE_UNUSED)
     67      1.1  christos {
     68      1.1  christos   bfd_set_error (bfd_error_invalid_operation);
     69      1.1  christos   return NULL;
     70      1.1  christos }
     71      1.1  christos 
     72      1.1  christos int
     73      1.1  christos bfd_0 (bfd *ignore ATTRIBUTE_UNUSED)
     74      1.1  christos {
     75      1.1  christos   return 0;
     76      1.1  christos }
     77      1.1  christos 
     78      1.1  christos unsigned int
     79      1.1  christos bfd_0u (bfd *ignore ATTRIBUTE_UNUSED)
     80      1.1  christos {
     81      1.1  christos    return 0;
     82      1.1  christos }
     83      1.1  christos 
     84      1.1  christos long
     85      1.1  christos bfd_0l (bfd *ignore ATTRIBUTE_UNUSED)
     86      1.1  christos {
     87      1.1  christos   return 0;
     88      1.1  christos }
     89      1.1  christos 
     90      1.1  christos /* A routine which is used in target vectors for unsupported
     91      1.1  christos    operations which return -1 on error.  */
     92      1.1  christos 
     93      1.1  christos long
     94      1.1  christos _bfd_n1 (bfd *ignore_abfd ATTRIBUTE_UNUSED)
     95      1.1  christos {
     96      1.1  christos   bfd_set_error (bfd_error_invalid_operation);
     97      1.1  christos   return -1;
     98      1.1  christos }
     99      1.1  christos 
    100      1.1  christos void
    101      1.1  christos bfd_void (bfd *ignore ATTRIBUTE_UNUSED)
    102      1.1  christos {
    103      1.1  christos }
    104      1.1  christos 
    105      1.1  christos long
    106      1.1  christos _bfd_norelocs_get_reloc_upper_bound (bfd *abfd ATTRIBUTE_UNUSED,
    107      1.1  christos 				     asection *sec ATTRIBUTE_UNUSED)
    108      1.1  christos {
    109      1.1  christos   return sizeof (arelent *);
    110      1.1  christos }
    111      1.1  christos 
    112      1.1  christos long
    113      1.1  christos _bfd_norelocs_canonicalize_reloc (bfd *abfd ATTRIBUTE_UNUSED,
    114      1.1  christos 				  asection *sec ATTRIBUTE_UNUSED,
    115      1.1  christos 				  arelent **relptr,
    116      1.1  christos 				  asymbol **symbols ATTRIBUTE_UNUSED)
    117      1.1  christos {
    118      1.1  christos   *relptr = NULL;
    119      1.1  christos   return 0;
    120      1.1  christos }
    121      1.1  christos 
    122      1.1  christos bfd_boolean
    123      1.1  christos _bfd_nocore_core_file_matches_executable_p
    124      1.1  christos   (bfd *ignore_core_bfd ATTRIBUTE_UNUSED,
    125      1.1  christos    bfd *ignore_exec_bfd ATTRIBUTE_UNUSED)
    126      1.1  christos {
    127      1.1  christos   bfd_set_error (bfd_error_invalid_operation);
    128      1.1  christos   return FALSE;
    129      1.1  christos }
    130      1.1  christos 
    131      1.1  christos /* Routine to handle core_file_failing_command entry point for targets
    132      1.1  christos    without core file support.  */
    133      1.1  christos 
    134      1.1  christos char *
    135      1.1  christos _bfd_nocore_core_file_failing_command (bfd *ignore_abfd ATTRIBUTE_UNUSED)
    136      1.1  christos {
    137      1.1  christos   bfd_set_error (bfd_error_invalid_operation);
    138      1.1  christos   return NULL;
    139      1.1  christos }
    140      1.1  christos 
    141      1.1  christos /* Routine to handle core_file_failing_signal entry point for targets
    142      1.1  christos    without core file support.  */
    143      1.1  christos 
    144      1.1  christos int
    145      1.1  christos _bfd_nocore_core_file_failing_signal (bfd *ignore_abfd ATTRIBUTE_UNUSED)
    146      1.1  christos {
    147      1.1  christos   bfd_set_error (bfd_error_invalid_operation);
    148      1.1  christos   return 0;
    149      1.1  christos }
    150      1.1  christos 
    151      1.1  christos /* Routine to handle the core_file_pid entry point for targets without
    152      1.1  christos    core file support.  */
    153      1.1  christos 
    154      1.1  christos int
    155      1.1  christos _bfd_nocore_core_file_pid (bfd *ignore_abfd ATTRIBUTE_UNUSED)
    156      1.1  christos {
    157      1.1  christos   bfd_set_error (bfd_error_invalid_operation);
    158      1.1  christos   return 0;
    159      1.1  christos }
    160      1.1  christos 
    161      1.1  christos const bfd_target *
    162      1.1  christos _bfd_dummy_target (bfd *ignore_abfd ATTRIBUTE_UNUSED)
    163      1.1  christos {
    164      1.1  christos   bfd_set_error (bfd_error_wrong_format);
    165      1.1  christos   return 0;
    166      1.1  christos }
    167      1.1  christos 
    168      1.1  christos /* Allocate memory using malloc.  */
    170      1.1  christos 
    171      1.1  christos void *
    172      1.1  christos bfd_malloc (bfd_size_type size)
    173      1.1  christos {
    174  1.1.1.3  christos   void *ptr;
    175      1.1  christos   size_t sz = (size_t) size;
    176  1.1.1.3  christos 
    177  1.1.1.3  christos   if (size != sz
    178  1.1.1.3  christos       /* This is to pacify memory checkers like valgrind.  */
    179      1.1  christos       || ((signed long) sz) < 0)
    180      1.1  christos     {
    181      1.1  christos       bfd_set_error (bfd_error_no_memory);
    182      1.1  christos       return NULL;
    183      1.1  christos     }
    184  1.1.1.3  christos 
    185  1.1.1.3  christos   ptr = malloc (sz);
    186      1.1  christos   if (ptr == NULL && sz != 0)
    187      1.1  christos     bfd_set_error (bfd_error_no_memory);
    188      1.1  christos 
    189      1.1  christos   return ptr;
    190      1.1  christos }
    191      1.1  christos 
    192      1.1  christos /* Allocate memory using malloc, nmemb * size with overflow checking.  */
    193      1.1  christos 
    194      1.1  christos void *
    195      1.1  christos bfd_malloc2 (bfd_size_type nmemb, bfd_size_type size)
    196      1.1  christos {
    197      1.1  christos   if ((nmemb | size) >= HALF_BFD_SIZE_TYPE
    198      1.1  christos       && size != 0
    199      1.1  christos       && nmemb > ~(bfd_size_type) 0 / size)
    200      1.1  christos     {
    201      1.1  christos       bfd_set_error (bfd_error_no_memory);
    202      1.1  christos       return NULL;
    203      1.1  christos     }
    204  1.1.1.3  christos 
    205      1.1  christos   return bfd_malloc (size * nmemb);
    206      1.1  christos }
    207      1.1  christos 
    208      1.1  christos /* Reallocate memory using realloc.  */
    209      1.1  christos 
    210      1.1  christos void *
    211      1.1  christos bfd_realloc (void *ptr, bfd_size_type size)
    212      1.1  christos {
    213  1.1.1.3  christos   void *ret;
    214      1.1  christos   size_t sz = (size_t) size;
    215  1.1.1.3  christos 
    216  1.1.1.3  christos   if (ptr == NULL)
    217  1.1.1.3  christos     return bfd_malloc (size);
    218  1.1.1.3  christos 
    219  1.1.1.3  christos   if (size != sz
    220  1.1.1.3  christos       /* This is to pacify memory checkers like valgrind.  */
    221      1.1  christos       || ((signed long) sz) < 0)
    222      1.1  christos     {
    223      1.1  christos       bfd_set_error (bfd_error_no_memory);
    224      1.1  christos       return NULL;
    225      1.1  christos     }
    226  1.1.1.3  christos 
    227      1.1  christos   ret = realloc (ptr, sz);
    228  1.1.1.3  christos 
    229      1.1  christos   if (ret == NULL && sz != 0)
    230      1.1  christos     bfd_set_error (bfd_error_no_memory);
    231      1.1  christos 
    232      1.1  christos   return ret;
    233      1.1  christos }
    234      1.1  christos 
    235      1.1  christos /* Reallocate memory using realloc, nmemb * size with overflow checking.  */
    236      1.1  christos 
    237      1.1  christos void *
    238      1.1  christos bfd_realloc2 (void *ptr, bfd_size_type nmemb, bfd_size_type size)
    239      1.1  christos {
    240      1.1  christos   if ((nmemb | size) >= HALF_BFD_SIZE_TYPE
    241      1.1  christos       && size != 0
    242      1.1  christos       && nmemb > ~(bfd_size_type) 0 / size)
    243      1.1  christos     {
    244      1.1  christos       bfd_set_error (bfd_error_no_memory);
    245      1.1  christos       return NULL;
    246      1.1  christos     }
    247  1.1.1.3  christos 
    248      1.1  christos   return bfd_realloc (ptr, size * nmemb);
    249      1.1  christos }
    250      1.1  christos 
    251      1.1  christos /* Reallocate memory using realloc.
    252      1.1  christos    If this fails the pointer is freed before returning.  */
    253      1.1  christos 
    254      1.1  christos void *
    255      1.1  christos bfd_realloc_or_free (void *ptr, bfd_size_type size)
    256  1.1.1.3  christos {
    257      1.1  christos   void *ret = bfd_realloc (ptr, size);
    258  1.1.1.3  christos 
    259  1.1.1.3  christos   if (ret == NULL && ptr != NULL)
    260      1.1  christos     free (ptr);
    261      1.1  christos 
    262      1.1  christos   return ret;
    263      1.1  christos }
    264      1.1  christos 
    265      1.1  christos /* Allocate memory using malloc and clear it.  */
    266      1.1  christos 
    267      1.1  christos void *
    268      1.1  christos bfd_zmalloc (bfd_size_type size)
    269  1.1.1.3  christos {
    270      1.1  christos   void *ptr = bfd_malloc (size);
    271  1.1.1.3  christos 
    272  1.1.1.3  christos   if (ptr != NULL && size > 0)
    273      1.1  christos     memset (ptr, 0, (size_t) size);
    274      1.1  christos 
    275      1.1  christos   return ptr;
    276      1.1  christos }
    277      1.1  christos 
    278      1.1  christos /* Allocate memory using malloc (nmemb * size) with overflow checking
    279      1.1  christos    and clear it.  */
    280      1.1  christos 
    281      1.1  christos void *
    282      1.1  christos bfd_zmalloc2 (bfd_size_type nmemb, bfd_size_type size)
    283  1.1.1.3  christos {
    284      1.1  christos   void *ptr = bfd_malloc2 (nmemb, size);
    285  1.1.1.3  christos 
    286      1.1  christos   if (ptr != NULL)
    287  1.1.1.3  christos     {
    288      1.1  christos       size_t sz = nmemb * size;
    289  1.1.1.3  christos 
    290  1.1.1.3  christos       if (sz > 0)
    291      1.1  christos 	memset (ptr, 0, sz);
    292      1.1  christos     }
    293      1.1  christos 
    294      1.1  christos   return ptr;
    295      1.1  christos }
    296      1.1  christos 
    297      1.1  christos /*
    298      1.1  christos INTERNAL_FUNCTION
    299      1.1  christos 	bfd_write_bigendian_4byte_int
    300      1.1  christos 
    301      1.1  christos SYNOPSIS
    302      1.1  christos 	bfd_boolean bfd_write_bigendian_4byte_int (bfd *, unsigned int);
    303      1.1  christos 
    304      1.1  christos DESCRIPTION
    305      1.1  christos 	Write a 4 byte integer @var{i} to the output BFD @var{abfd}, in big
    306      1.1  christos 	endian order regardless of what else is going on.  This is useful in
    307      1.1  christos 	archives.
    308      1.1  christos 
    309      1.1  christos */
    310      1.1  christos bfd_boolean
    311      1.1  christos bfd_write_bigendian_4byte_int (bfd *abfd, unsigned int i)
    312      1.1  christos {
    313      1.1  christos   bfd_byte buffer[4];
    314      1.1  christos   bfd_putb32 ((bfd_vma) i, buffer);
    315      1.1  christos   return bfd_bwrite (buffer, (bfd_size_type) 4, abfd) == 4;
    316      1.1  christos }
    317      1.1  christos 
    318      1.1  christos 
    319      1.1  christos /** The do-it-yourself (byte) sex-change kit */
    321      1.1  christos 
    322      1.1  christos /* The middle letter e.g. get<b>short indicates Big or Little endian
    323      1.1  christos    target machine.  It doesn't matter what the byte order of the host
    324      1.1  christos    machine is; these routines work for either.  */
    325      1.1  christos 
    326      1.1  christos /* FIXME: Should these take a count argument?
    327      1.1  christos    Answer (gnu (at) cygnus.com):  No, but perhaps they should be inline
    328      1.1  christos                              functions in swap.h #ifdef __GNUC__.
    329      1.1  christos                              Gprof them later and find out.  */
    330      1.1  christos 
    331      1.1  christos /*
    332      1.1  christos FUNCTION
    333      1.1  christos 	bfd_put_size
    334      1.1  christos FUNCTION
    335      1.1  christos 	bfd_get_size
    336      1.1  christos 
    337      1.1  christos DESCRIPTION
    338      1.1  christos 	These macros as used for reading and writing raw data in
    339      1.1  christos 	sections; each access (except for bytes) is vectored through
    340      1.1  christos 	the target format of the BFD and mangled accordingly. The
    341      1.1  christos 	mangling performs any necessary endian translations and
    342      1.1  christos 	removes alignment restrictions.  Note that types accepted and
    343      1.1  christos 	returned by these macros are identical so they can be swapped
    344      1.1  christos 	around in macros---for example, @file{libaout.h} defines <<GET_WORD>>
    345      1.1  christos 	to either <<bfd_get_32>> or <<bfd_get_64>>.
    346      1.1  christos 
    347      1.1  christos 	In the put routines, @var{val} must be a <<bfd_vma>>.  If we are on a
    348      1.1  christos 	system without prototypes, the caller is responsible for making
    349      1.1  christos 	sure that is true, with a cast if necessary.  We don't cast
    350      1.1  christos 	them in the macro definitions because that would prevent <<lint>>
    351      1.1  christos 	or <<gcc -Wall>> from detecting sins such as passing a pointer.
    352      1.1  christos 	To detect calling these with less than a <<bfd_vma>>, use
    353      1.1  christos 	<<gcc -Wconversion>> on a host with 64 bit <<bfd_vma>>'s.
    354      1.1  christos 
    355      1.1  christos .
    356      1.1  christos .{* Byte swapping macros for user section data.  *}
    357      1.1  christos .
    358      1.1  christos .#define bfd_put_8(abfd, val, ptr) \
    359      1.1  christos .  ((void) (*((unsigned char *) (ptr)) = (val) & 0xff))
    360      1.1  christos .#define bfd_put_signed_8 \
    361  1.1.1.2  christos .  bfd_put_8
    362      1.1  christos .#define bfd_get_8(abfd, ptr) \
    363  1.1.1.2  christos .  (*(const unsigned char *) (ptr) & 0xff)
    364      1.1  christos .#define bfd_get_signed_8(abfd, ptr) \
    365      1.1  christos .  (((*(const unsigned char *) (ptr) & 0xff) ^ 0x80) - 0x80)
    366      1.1  christos .
    367      1.1  christos .#define bfd_put_16(abfd, val, ptr) \
    368      1.1  christos .  BFD_SEND (abfd, bfd_putx16, ((val),(ptr)))
    369      1.1  christos .#define bfd_put_signed_16 \
    370      1.1  christos .  bfd_put_16
    371      1.1  christos .#define bfd_get_16(abfd, ptr) \
    372      1.1  christos .  BFD_SEND (abfd, bfd_getx16, (ptr))
    373      1.1  christos .#define bfd_get_signed_16(abfd, ptr) \
    374      1.1  christos .  BFD_SEND (abfd, bfd_getx_signed_16, (ptr))
    375      1.1  christos .
    376      1.1  christos .#define bfd_put_32(abfd, val, ptr) \
    377      1.1  christos .  BFD_SEND (abfd, bfd_putx32, ((val),(ptr)))
    378      1.1  christos .#define bfd_put_signed_32 \
    379      1.1  christos .  bfd_put_32
    380      1.1  christos .#define bfd_get_32(abfd, ptr) \
    381      1.1  christos .  BFD_SEND (abfd, bfd_getx32, (ptr))
    382      1.1  christos .#define bfd_get_signed_32(abfd, ptr) \
    383      1.1  christos .  BFD_SEND (abfd, bfd_getx_signed_32, (ptr))
    384      1.1  christos .
    385      1.1  christos .#define bfd_put_64(abfd, val, ptr) \
    386      1.1  christos .  BFD_SEND (abfd, bfd_putx64, ((val), (ptr)))
    387      1.1  christos .#define bfd_put_signed_64 \
    388      1.1  christos .  bfd_put_64
    389      1.1  christos .#define bfd_get_64(abfd, ptr) \
    390      1.1  christos .  BFD_SEND (abfd, bfd_getx64, (ptr))
    391      1.1  christos .#define bfd_get_signed_64(abfd, ptr) \
    392      1.1  christos .  BFD_SEND (abfd, bfd_getx_signed_64, (ptr))
    393      1.1  christos .
    394      1.1  christos .#define bfd_get(bits, abfd, ptr)			\
    395      1.1  christos .  ((bits) == 8 ? (bfd_vma) bfd_get_8 (abfd, ptr)	\
    396      1.1  christos .   : (bits) == 16 ? bfd_get_16 (abfd, ptr)		\
    397      1.1  christos .   : (bits) == 32 ? bfd_get_32 (abfd, ptr)		\
    398      1.1  christos .   : (bits) == 64 ? bfd_get_64 (abfd, ptr)		\
    399      1.1  christos .   : (abort (), (bfd_vma) - 1))
    400      1.1  christos .
    401      1.1  christos .#define bfd_put(bits, abfd, val, ptr)			\
    402      1.1  christos .  ((bits) == 8 ? bfd_put_8  (abfd, val, ptr)		\
    403      1.1  christos .   : (bits) == 16 ? bfd_put_16 (abfd, val, ptr)		\
    404      1.1  christos .   : (bits) == 32 ? bfd_put_32 (abfd, val, ptr)		\
    405      1.1  christos .   : (bits) == 64 ? bfd_put_64 (abfd, val, ptr)		\
    406      1.1  christos .   : (abort (), (void) 0))
    407      1.1  christos .
    408      1.1  christos */
    409      1.1  christos 
    410      1.1  christos /*
    411      1.1  christos FUNCTION
    412      1.1  christos 	bfd_h_put_size
    413      1.1  christos 	bfd_h_get_size
    414      1.1  christos 
    415      1.1  christos DESCRIPTION
    416      1.1  christos 	These macros have the same function as their <<bfd_get_x>>
    417      1.1  christos 	brethren, except that they are used for removing information
    418      1.1  christos 	for the header records of object files. Believe it or not,
    419      1.1  christos 	some object files keep their header records in big endian
    420      1.1  christos 	order and their data in little endian order.
    421      1.1  christos .
    422      1.1  christos .{* Byte swapping macros for file header data.  *}
    423      1.1  christos .
    424      1.1  christos .#define bfd_h_put_8(abfd, val, ptr) \
    425      1.1  christos .  bfd_put_8 (abfd, val, ptr)
    426      1.1  christos .#define bfd_h_put_signed_8(abfd, val, ptr) \
    427      1.1  christos .  bfd_put_8 (abfd, val, ptr)
    428      1.1  christos .#define bfd_h_get_8(abfd, ptr) \
    429      1.1  christos .  bfd_get_8 (abfd, ptr)
    430      1.1  christos .#define bfd_h_get_signed_8(abfd, ptr) \
    431      1.1  christos .  bfd_get_signed_8 (abfd, ptr)
    432      1.1  christos .
    433      1.1  christos .#define bfd_h_put_16(abfd, val, ptr) \
    434      1.1  christos .  BFD_SEND (abfd, bfd_h_putx16, (val, ptr))
    435      1.1  christos .#define bfd_h_put_signed_16 \
    436      1.1  christos .  bfd_h_put_16
    437      1.1  christos .#define bfd_h_get_16(abfd, ptr) \
    438      1.1  christos .  BFD_SEND (abfd, bfd_h_getx16, (ptr))
    439      1.1  christos .#define bfd_h_get_signed_16(abfd, ptr) \
    440      1.1  christos .  BFD_SEND (abfd, bfd_h_getx_signed_16, (ptr))
    441      1.1  christos .
    442      1.1  christos .#define bfd_h_put_32(abfd, val, ptr) \
    443      1.1  christos .  BFD_SEND (abfd, bfd_h_putx32, (val, ptr))
    444      1.1  christos .#define bfd_h_put_signed_32 \
    445      1.1  christos .  bfd_h_put_32
    446      1.1  christos .#define bfd_h_get_32(abfd, ptr) \
    447      1.1  christos .  BFD_SEND (abfd, bfd_h_getx32, (ptr))
    448      1.1  christos .#define bfd_h_get_signed_32(abfd, ptr) \
    449      1.1  christos .  BFD_SEND (abfd, bfd_h_getx_signed_32, (ptr))
    450      1.1  christos .
    451      1.1  christos .#define bfd_h_put_64(abfd, val, ptr) \
    452      1.1  christos .  BFD_SEND (abfd, bfd_h_putx64, (val, ptr))
    453      1.1  christos .#define bfd_h_put_signed_64 \
    454      1.1  christos .  bfd_h_put_64
    455      1.1  christos .#define bfd_h_get_64(abfd, ptr) \
    456      1.1  christos .  BFD_SEND (abfd, bfd_h_getx64, (ptr))
    457      1.1  christos .#define bfd_h_get_signed_64(abfd, ptr) \
    458      1.1  christos .  BFD_SEND (abfd, bfd_h_getx_signed_64, (ptr))
    459      1.1  christos .
    460      1.1  christos .{* Aliases for the above, which should eventually go away.  *}
    461      1.1  christos .
    462      1.1  christos .#define H_PUT_64  bfd_h_put_64
    463      1.1  christos .#define H_PUT_32  bfd_h_put_32
    464      1.1  christos .#define H_PUT_16  bfd_h_put_16
    465      1.1  christos .#define H_PUT_8   bfd_h_put_8
    466      1.1  christos .#define H_PUT_S64 bfd_h_put_signed_64
    467      1.1  christos .#define H_PUT_S32 bfd_h_put_signed_32
    468      1.1  christos .#define H_PUT_S16 bfd_h_put_signed_16
    469      1.1  christos .#define H_PUT_S8  bfd_h_put_signed_8
    470      1.1  christos .#define H_GET_64  bfd_h_get_64
    471      1.1  christos .#define H_GET_32  bfd_h_get_32
    472      1.1  christos .#define H_GET_16  bfd_h_get_16
    473      1.1  christos .#define H_GET_8   bfd_h_get_8
    474      1.1  christos .#define H_GET_S64 bfd_h_get_signed_64
    475      1.1  christos .#define H_GET_S32 bfd_h_get_signed_32
    476      1.1  christos .#define H_GET_S16 bfd_h_get_signed_16
    477      1.1  christos .#define H_GET_S8  bfd_h_get_signed_8
    478      1.1  christos .
    479      1.1  christos .*/
    480  1.1.1.3  christos 
    481  1.1.1.3  christos /* Sign extension to bfd_signed_vma.  */
    482      1.1  christos #define COERCE16(x) (((bfd_vma) (x) ^ 0x8000) - 0x8000)
    483  1.1.1.3  christos #define COERCE32(x) (((bfd_vma) (x) ^ 0x80000000) - 0x80000000)
    484      1.1  christos #define COERCE64(x) \
    485      1.1  christos   (((bfd_uint64_t) (x) ^ ((bfd_uint64_t) 1 << 63)) - ((bfd_uint64_t) 1 << 63))
    486      1.1  christos 
    487      1.1  christos bfd_vma
    488      1.1  christos bfd_getb16 (const void *p)
    489      1.1  christos {
    490      1.1  christos   const bfd_byte *addr = (const bfd_byte *) p;
    491      1.1  christos   return (addr[0] << 8) | addr[1];
    492      1.1  christos }
    493      1.1  christos 
    494      1.1  christos bfd_vma
    495      1.1  christos bfd_getl16 (const void *p)
    496      1.1  christos {
    497      1.1  christos   const bfd_byte *addr = (const bfd_byte *) p;
    498      1.1  christos   return (addr[1] << 8) | addr[0];
    499      1.1  christos }
    500      1.1  christos 
    501      1.1  christos bfd_signed_vma
    502      1.1  christos bfd_getb_signed_16 (const void *p)
    503      1.1  christos {
    504      1.1  christos   const bfd_byte *addr = (const bfd_byte *) p;
    505      1.1  christos   return COERCE16 ((addr[0] << 8) | addr[1]);
    506      1.1  christos }
    507      1.1  christos 
    508      1.1  christos bfd_signed_vma
    509      1.1  christos bfd_getl_signed_16 (const void *p)
    510      1.1  christos {
    511      1.1  christos   const bfd_byte *addr = (const bfd_byte *) p;
    512      1.1  christos   return COERCE16 ((addr[1] << 8) | addr[0]);
    513      1.1  christos }
    514      1.1  christos 
    515      1.1  christos void
    516      1.1  christos bfd_putb16 (bfd_vma data, void *p)
    517      1.1  christos {
    518      1.1  christos   bfd_byte *addr = (bfd_byte *) p;
    519      1.1  christos   addr[0] = (data >> 8) & 0xff;
    520      1.1  christos   addr[1] = data & 0xff;
    521      1.1  christos }
    522      1.1  christos 
    523      1.1  christos void
    524      1.1  christos bfd_putl16 (bfd_vma data, void *p)
    525      1.1  christos {
    526      1.1  christos   bfd_byte *addr = (bfd_byte *) p;
    527      1.1  christos   addr[0] = data & 0xff;
    528      1.1  christos   addr[1] = (data >> 8) & 0xff;
    529      1.1  christos }
    530      1.1  christos 
    531      1.1  christos bfd_vma
    532      1.1  christos bfd_getb32 (const void *p)
    533      1.1  christos {
    534      1.1  christos   const bfd_byte *addr = (const bfd_byte *) p;
    535      1.1  christos   unsigned long v;
    536      1.1  christos 
    537      1.1  christos   v = (unsigned long) addr[0] << 24;
    538      1.1  christos   v |= (unsigned long) addr[1] << 16;
    539      1.1  christos   v |= (unsigned long) addr[2] << 8;
    540      1.1  christos   v |= (unsigned long) addr[3];
    541      1.1  christos   return v;
    542      1.1  christos }
    543      1.1  christos 
    544      1.1  christos bfd_vma
    545      1.1  christos bfd_getl32 (const void *p)
    546      1.1  christos {
    547      1.1  christos   const bfd_byte *addr = (const bfd_byte *) p;
    548      1.1  christos   unsigned long v;
    549      1.1  christos 
    550      1.1  christos   v = (unsigned long) addr[0];
    551      1.1  christos   v |= (unsigned long) addr[1] << 8;
    552      1.1  christos   v |= (unsigned long) addr[2] << 16;
    553      1.1  christos   v |= (unsigned long) addr[3] << 24;
    554      1.1  christos   return v;
    555      1.1  christos }
    556      1.1  christos 
    557      1.1  christos bfd_signed_vma
    558      1.1  christos bfd_getb_signed_32 (const void *p)
    559      1.1  christos {
    560      1.1  christos   const bfd_byte *addr = (const bfd_byte *) p;
    561      1.1  christos   unsigned long v;
    562      1.1  christos 
    563      1.1  christos   v = (unsigned long) addr[0] << 24;
    564      1.1  christos   v |= (unsigned long) addr[1] << 16;
    565      1.1  christos   v |= (unsigned long) addr[2] << 8;
    566      1.1  christos   v |= (unsigned long) addr[3];
    567      1.1  christos   return COERCE32 (v);
    568      1.1  christos }
    569      1.1  christos 
    570      1.1  christos bfd_signed_vma
    571      1.1  christos bfd_getl_signed_32 (const void *p)
    572      1.1  christos {
    573      1.1  christos   const bfd_byte *addr = (const bfd_byte *) p;
    574      1.1  christos   unsigned long v;
    575      1.1  christos 
    576      1.1  christos   v = (unsigned long) addr[0];
    577      1.1  christos   v |= (unsigned long) addr[1] << 8;
    578      1.1  christos   v |= (unsigned long) addr[2] << 16;
    579      1.1  christos   v |= (unsigned long) addr[3] << 24;
    580      1.1  christos   return COERCE32 (v);
    581      1.1  christos }
    582      1.1  christos 
    583      1.1  christos bfd_uint64_t
    584      1.1  christos bfd_getb64 (const void *p ATTRIBUTE_UNUSED)
    585      1.1  christos {
    586      1.1  christos #ifdef BFD_HOST_64_BIT
    587      1.1  christos   const bfd_byte *addr = (const bfd_byte *) p;
    588      1.1  christos   bfd_uint64_t v;
    589      1.1  christos 
    590      1.1  christos   v  = addr[0]; v <<= 8;
    591      1.1  christos   v |= addr[1]; v <<= 8;
    592      1.1  christos   v |= addr[2]; v <<= 8;
    593      1.1  christos   v |= addr[3]; v <<= 8;
    594      1.1  christos   v |= addr[4]; v <<= 8;
    595      1.1  christos   v |= addr[5]; v <<= 8;
    596      1.1  christos   v |= addr[6]; v <<= 8;
    597      1.1  christos   v |= addr[7];
    598      1.1  christos 
    599      1.1  christos   return v;
    600      1.1  christos #else
    601      1.1  christos   BFD_FAIL();
    602      1.1  christos   return 0;
    603      1.1  christos #endif
    604      1.1  christos }
    605      1.1  christos 
    606      1.1  christos bfd_uint64_t
    607      1.1  christos bfd_getl64 (const void *p ATTRIBUTE_UNUSED)
    608      1.1  christos {
    609      1.1  christos #ifdef BFD_HOST_64_BIT
    610      1.1  christos   const bfd_byte *addr = (const bfd_byte *) p;
    611      1.1  christos   bfd_uint64_t v;
    612      1.1  christos 
    613      1.1  christos   v  = addr[7]; v <<= 8;
    614      1.1  christos   v |= addr[6]; v <<= 8;
    615      1.1  christos   v |= addr[5]; v <<= 8;
    616      1.1  christos   v |= addr[4]; v <<= 8;
    617      1.1  christos   v |= addr[3]; v <<= 8;
    618      1.1  christos   v |= addr[2]; v <<= 8;
    619      1.1  christos   v |= addr[1]; v <<= 8;
    620      1.1  christos   v |= addr[0];
    621      1.1  christos 
    622      1.1  christos   return v;
    623      1.1  christos #else
    624      1.1  christos   BFD_FAIL();
    625      1.1  christos   return 0;
    626      1.1  christos #endif
    627      1.1  christos 
    628      1.1  christos }
    629      1.1  christos 
    630      1.1  christos bfd_int64_t
    631      1.1  christos bfd_getb_signed_64 (const void *p ATTRIBUTE_UNUSED)
    632      1.1  christos {
    633      1.1  christos #ifdef BFD_HOST_64_BIT
    634      1.1  christos   const bfd_byte *addr = (const bfd_byte *) p;
    635      1.1  christos   bfd_uint64_t v;
    636      1.1  christos 
    637      1.1  christos   v  = addr[0]; v <<= 8;
    638      1.1  christos   v |= addr[1]; v <<= 8;
    639      1.1  christos   v |= addr[2]; v <<= 8;
    640      1.1  christos   v |= addr[3]; v <<= 8;
    641      1.1  christos   v |= addr[4]; v <<= 8;
    642      1.1  christos   v |= addr[5]; v <<= 8;
    643      1.1  christos   v |= addr[6]; v <<= 8;
    644      1.1  christos   v |= addr[7];
    645      1.1  christos 
    646      1.1  christos   return COERCE64 (v);
    647      1.1  christos #else
    648      1.1  christos   BFD_FAIL();
    649      1.1  christos   return 0;
    650      1.1  christos #endif
    651      1.1  christos }
    652      1.1  christos 
    653      1.1  christos bfd_int64_t
    654      1.1  christos bfd_getl_signed_64 (const void *p ATTRIBUTE_UNUSED)
    655      1.1  christos {
    656      1.1  christos #ifdef BFD_HOST_64_BIT
    657      1.1  christos   const bfd_byte *addr = (const bfd_byte *) p;
    658      1.1  christos   bfd_uint64_t v;
    659      1.1  christos 
    660      1.1  christos   v  = addr[7]; v <<= 8;
    661      1.1  christos   v |= addr[6]; v <<= 8;
    662      1.1  christos   v |= addr[5]; v <<= 8;
    663      1.1  christos   v |= addr[4]; v <<= 8;
    664      1.1  christos   v |= addr[3]; v <<= 8;
    665      1.1  christos   v |= addr[2]; v <<= 8;
    666      1.1  christos   v |= addr[1]; v <<= 8;
    667      1.1  christos   v |= addr[0];
    668      1.1  christos 
    669      1.1  christos   return COERCE64 (v);
    670      1.1  christos #else
    671      1.1  christos   BFD_FAIL();
    672      1.1  christos   return 0;
    673      1.1  christos #endif
    674      1.1  christos }
    675      1.1  christos 
    676      1.1  christos void
    677      1.1  christos bfd_putb32 (bfd_vma data, void *p)
    678      1.1  christos {
    679      1.1  christos   bfd_byte *addr = (bfd_byte *) p;
    680      1.1  christos   addr[0] = (data >> 24) & 0xff;
    681      1.1  christos   addr[1] = (data >> 16) & 0xff;
    682      1.1  christos   addr[2] = (data >>  8) & 0xff;
    683      1.1  christos   addr[3] = data & 0xff;
    684      1.1  christos }
    685      1.1  christos 
    686      1.1  christos void
    687      1.1  christos bfd_putl32 (bfd_vma data, void *p)
    688      1.1  christos {
    689      1.1  christos   bfd_byte *addr = (bfd_byte *) p;
    690      1.1  christos   addr[0] = data & 0xff;
    691      1.1  christos   addr[1] = (data >>  8) & 0xff;
    692      1.1  christos   addr[2] = (data >> 16) & 0xff;
    693      1.1  christos   addr[3] = (data >> 24) & 0xff;
    694      1.1  christos }
    695      1.1  christos 
    696      1.1  christos void
    697      1.1  christos bfd_putb64 (bfd_uint64_t data ATTRIBUTE_UNUSED, void *p ATTRIBUTE_UNUSED)
    698      1.1  christos {
    699      1.1  christos #ifdef BFD_HOST_64_BIT
    700      1.1  christos   bfd_byte *addr = (bfd_byte *) p;
    701      1.1  christos   addr[0] = (data >> (7*8)) & 0xff;
    702      1.1  christos   addr[1] = (data >> (6*8)) & 0xff;
    703      1.1  christos   addr[2] = (data >> (5*8)) & 0xff;
    704      1.1  christos   addr[3] = (data >> (4*8)) & 0xff;
    705      1.1  christos   addr[4] = (data >> (3*8)) & 0xff;
    706      1.1  christos   addr[5] = (data >> (2*8)) & 0xff;
    707      1.1  christos   addr[6] = (data >> (1*8)) & 0xff;
    708      1.1  christos   addr[7] = (data >> (0*8)) & 0xff;
    709      1.1  christos #else
    710      1.1  christos   BFD_FAIL();
    711      1.1  christos #endif
    712      1.1  christos }
    713      1.1  christos 
    714      1.1  christos void
    715      1.1  christos bfd_putl64 (bfd_uint64_t data ATTRIBUTE_UNUSED, void *p ATTRIBUTE_UNUSED)
    716      1.1  christos {
    717      1.1  christos #ifdef BFD_HOST_64_BIT
    718      1.1  christos   bfd_byte *addr = (bfd_byte *) p;
    719      1.1  christos   addr[7] = (data >> (7*8)) & 0xff;
    720      1.1  christos   addr[6] = (data >> (6*8)) & 0xff;
    721      1.1  christos   addr[5] = (data >> (5*8)) & 0xff;
    722      1.1  christos   addr[4] = (data >> (4*8)) & 0xff;
    723      1.1  christos   addr[3] = (data >> (3*8)) & 0xff;
    724      1.1  christos   addr[2] = (data >> (2*8)) & 0xff;
    725      1.1  christos   addr[1] = (data >> (1*8)) & 0xff;
    726      1.1  christos   addr[0] = (data >> (0*8)) & 0xff;
    727      1.1  christos #else
    728      1.1  christos   BFD_FAIL();
    729      1.1  christos #endif
    730      1.1  christos }
    731      1.1  christos 
    732      1.1  christos void
    733      1.1  christos bfd_put_bits (bfd_uint64_t data, void *p, int bits, bfd_boolean big_p)
    734      1.1  christos {
    735      1.1  christos   bfd_byte *addr = (bfd_byte *) p;
    736      1.1  christos   int i;
    737      1.1  christos   int bytes;
    738      1.1  christos 
    739      1.1  christos   if (bits % 8 != 0)
    740      1.1  christos     abort ();
    741      1.1  christos 
    742      1.1  christos   bytes = bits / 8;
    743      1.1  christos   for (i = 0; i < bytes; i++)
    744      1.1  christos     {
    745      1.1  christos       int addr_index = big_p ? bytes - i - 1 : i;
    746      1.1  christos 
    747      1.1  christos       addr[addr_index] = data & 0xff;
    748      1.1  christos       data >>= 8;
    749      1.1  christos     }
    750      1.1  christos }
    751      1.1  christos 
    752      1.1  christos bfd_uint64_t
    753      1.1  christos bfd_get_bits (const void *p, int bits, bfd_boolean big_p)
    754      1.1  christos {
    755      1.1  christos   const bfd_byte *addr = (const bfd_byte *) p;
    756      1.1  christos   bfd_uint64_t data;
    757      1.1  christos   int i;
    758      1.1  christos   int bytes;
    759      1.1  christos 
    760      1.1  christos   if (bits % 8 != 0)
    761      1.1  christos     abort ();
    762      1.1  christos 
    763      1.1  christos   data = 0;
    764      1.1  christos   bytes = bits / 8;
    765      1.1  christos   for (i = 0; i < bytes; i++)
    766      1.1  christos     {
    767      1.1  christos       int addr_index = big_p ? i : bytes - i - 1;
    768      1.1  christos 
    769      1.1  christos       data = (data << 8) | addr[addr_index];
    770      1.1  christos     }
    771      1.1  christos 
    772      1.1  christos   return data;
    773      1.1  christos }
    774      1.1  christos 
    775      1.1  christos /* Default implementation */
    777      1.1  christos 
    778      1.1  christos bfd_boolean
    779      1.1  christos _bfd_generic_get_section_contents (bfd *abfd,
    780      1.1  christos 				   sec_ptr section,
    781      1.1  christos 				   void *location,
    782      1.1  christos 				   file_ptr offset,
    783      1.1  christos 				   bfd_size_type count)
    784      1.1  christos {
    785      1.1  christos   bfd_size_type sz;
    786      1.1  christos   if (count == 0)
    787      1.1  christos     return TRUE;
    788  1.1.1.5  christos 
    789  1.1.1.5  christos   if (section->compress_status != COMPRESS_SECTION_NONE)
    790      1.1  christos     {
    791      1.1  christos       _bfd_error_handler
    792      1.1  christos 	/* xgettext:c-format */
    793      1.1  christos 	(_("%B: unable to get decompressed section %A"),
    794      1.1  christos 	 abfd, section);
    795      1.1  christos       bfd_set_error (bfd_error_invalid_operation);
    796  1.1.1.2  christos       return FALSE;
    797  1.1.1.2  christos     }
    798  1.1.1.2  christos 
    799  1.1.1.2  christos   /* We do allow reading of a section after bfd_final_link has
    800  1.1.1.2  christos      written the contents out to disk.  In that situation, rawsize is
    801  1.1.1.2  christos      just a stale version of size, so ignore it.  Otherwise we must be
    802  1.1.1.2  christos      reading an input section, where rawsize, if different to size,
    803  1.1.1.2  christos      is the on-disk size.  */
    804  1.1.1.2  christos   if (abfd->direction != write_direction && section->rawsize != 0)
    805      1.1  christos     sz = section->rawsize;
    806      1.1  christos   else
    807      1.1  christos     sz = section->size;
    808      1.1  christos   if (offset + count < count
    809      1.1  christos       || offset + count > sz)
    810      1.1  christos     {
    811      1.1  christos       bfd_set_error (bfd_error_invalid_operation);
    812      1.1  christos       return FALSE;
    813      1.1  christos     }
    814      1.1  christos 
    815      1.1  christos   if (bfd_seek (abfd, section->filepos + offset, SEEK_SET) != 0
    816      1.1  christos       || bfd_bread (location, count, abfd) != count)
    817      1.1  christos     return FALSE;
    818      1.1  christos 
    819      1.1  christos   return TRUE;
    820      1.1  christos }
    821      1.1  christos 
    822      1.1  christos bfd_boolean
    823      1.1  christos _bfd_generic_get_section_contents_in_window
    824      1.1  christos   (bfd *abfd ATTRIBUTE_UNUSED,
    825      1.1  christos    sec_ptr section ATTRIBUTE_UNUSED,
    826      1.1  christos    bfd_window *w ATTRIBUTE_UNUSED,
    827      1.1  christos    file_ptr offset ATTRIBUTE_UNUSED,
    828      1.1  christos    bfd_size_type count ATTRIBUTE_UNUSED)
    829      1.1  christos {
    830      1.1  christos #ifdef USE_MMAP
    831      1.1  christos   bfd_size_type sz;
    832      1.1  christos 
    833      1.1  christos   if (count == 0)
    834      1.1  christos     return TRUE;
    835      1.1  christos   if (abfd->xvec->_bfd_get_section_contents
    836      1.1  christos       != _bfd_generic_get_section_contents)
    837      1.1  christos     {
    838      1.1  christos       /* We don't know what changes the bfd's get_section_contents
    839      1.1  christos 	 method may have to make.  So punt trying to map the file
    840      1.1  christos 	 window, and let get_section_contents do its thing.  */
    841      1.1  christos       /* @@ FIXME : If the internal window has a refcount of 1 and was
    842      1.1  christos 	 allocated with malloc instead of mmap, just reuse it.  */
    843      1.1  christos       bfd_free_window (w);
    844      1.1  christos       w->i = bfd_zmalloc (sizeof (bfd_window_internal));
    845      1.1  christos       if (w->i == NULL)
    846      1.1  christos 	return FALSE;
    847      1.1  christos       w->i->data = bfd_malloc (count);
    848      1.1  christos       if (w->i->data == NULL)
    849      1.1  christos 	{
    850      1.1  christos 	  free (w->i);
    851      1.1  christos 	  w->i = NULL;
    852      1.1  christos 	  return FALSE;
    853      1.1  christos 	}
    854      1.1  christos       w->i->mapped = 0;
    855      1.1  christos       w->i->refcount = 1;
    856      1.1  christos       w->size = w->i->size = count;
    857  1.1.1.2  christos       w->data = w->i->data;
    858  1.1.1.2  christos       return bfd_get_section_contents (abfd, section, w->data, offset, count);
    859  1.1.1.2  christos     }
    860  1.1.1.2  christos   if (abfd->direction != write_direction && section->rawsize != 0)
    861      1.1  christos     sz = section->rawsize;
    862      1.1  christos   else
    863      1.1  christos     sz = section->size;
    864      1.1  christos   if (offset + count > sz
    865      1.1  christos       || ! bfd_get_file_window (abfd, section->filepos + offset, count, w,
    866      1.1  christos 				TRUE))
    867      1.1  christos     return FALSE;
    868      1.1  christos   return TRUE;
    869      1.1  christos #else
    870      1.1  christos   abort ();
    871      1.1  christos #endif
    872      1.1  christos }
    873      1.1  christos 
    874      1.1  christos /* This generic function can only be used in implementations where creating
    875      1.1  christos    NEW sections is disallowed.  It is useful in patching existing sections
    876      1.1  christos    in read-write files, though.  See other set_section_contents functions
    877      1.1  christos    to see why it doesn't work for new sections.  */
    878      1.1  christos bfd_boolean
    879      1.1  christos _bfd_generic_set_section_contents (bfd *abfd,
    880      1.1  christos 				   sec_ptr section,
    881      1.1  christos 				   const void *location,
    882      1.1  christos 				   file_ptr offset,
    883      1.1  christos 				   bfd_size_type count)
    884      1.1  christos {
    885      1.1  christos   if (count == 0)
    886      1.1  christos     return TRUE;
    887      1.1  christos 
    888      1.1  christos   if (bfd_seek (abfd, section->filepos + offset, SEEK_SET) != 0
    889      1.1  christos       || bfd_bwrite (location, count, abfd) != count)
    890      1.1  christos     return FALSE;
    891      1.1  christos 
    892      1.1  christos   return TRUE;
    893      1.1  christos }
    894      1.1  christos 
    895      1.1  christos /*
    896      1.1  christos INTERNAL_FUNCTION
    897      1.1  christos 	bfd_log2
    898      1.1  christos 
    899      1.1  christos SYNOPSIS
    900      1.1  christos 	unsigned int bfd_log2 (bfd_vma x);
    901      1.1  christos 
    902      1.1  christos DESCRIPTION
    903      1.1  christos 	Return the log base 2 of the value supplied, rounded up.  E.g., an
    904      1.1  christos 	@var{x} of 1025 returns 11.  A @var{x} of 0 returns 0.
    905      1.1  christos */
    906      1.1  christos 
    907      1.1  christos unsigned int
    908      1.1  christos bfd_log2 (bfd_vma x)
    909  1.1.1.2  christos {
    910  1.1.1.2  christos   unsigned int result = 0;
    911  1.1.1.2  christos 
    912  1.1.1.2  christos   if (x <= 1)
    913      1.1  christos     return result;
    914  1.1.1.2  christos   --x;
    915      1.1  christos   do
    916      1.1  christos     ++result;
    917      1.1  christos   while ((x >>= 1) != 0);
    918      1.1  christos   return result;
    919      1.1  christos }
    920      1.1  christos 
    921      1.1  christos bfd_boolean
    922      1.1  christos bfd_generic_is_local_label_name (bfd *abfd, const char *name)
    923      1.1  christos {
    924      1.1  christos   char locals_prefix = (bfd_get_symbol_leading_char (abfd) == '_') ? 'L' : '.';
    925      1.1  christos 
    926      1.1  christos   return name[0] == locals_prefix;
    927      1.1  christos }
    928      1.1  christos 
    929      1.1  christos /* Give a warning at runtime if someone compiles code which calls
    930  1.1.1.5  christos    old routines.  */
    931  1.1.1.5  christos 
    932  1.1.1.5  christos void
    933  1.1.1.5  christos _bfd_warn_deprecated (const char *what,
    934      1.1  christos 		      const char *file,
    935      1.1  christos 		      int line,
    936      1.1  christos 		      const char *func)
    937      1.1  christos {
    938      1.1  christos   /* Poor man's tracking of functions we've already warned about.  */
    939      1.1  christos   static size_t mask = 0;
    940      1.1  christos 
    941      1.1  christos   if (~(size_t) func & ~mask)
    942      1.1  christos     {
    943      1.1  christos       fflush (stdout);
    944  1.1.1.5  christos       /* Note: separate sentences in order to allow
    945      1.1  christos 	 for translation into other languages.  */
    946      1.1  christos       if (func)
    947      1.1  christos 	/* xgettext:c-format */
    948      1.1  christos 	fprintf (stderr, _("Deprecated %s called at %s line %d in %s\n"),
    949      1.1  christos 		 what, file, line, func);
    950      1.1  christos       else
    951      1.1  christos 	fprintf (stderr, _("Deprecated %s called\n"), what);
    952      1.1  christos       fflush (stderr);
    953      1.1  christos       mask |= ~(size_t) func;
    954      1.1  christos     }
    955      1.1  christos }
    956      1.1  christos 
    957  1.1.1.5  christos /* Helper function for reading uleb128 encoded data.  */
    958  1.1.1.5  christos 
    959  1.1.1.5  christos bfd_vma
    960      1.1  christos _bfd_read_unsigned_leb128 (bfd *abfd ATTRIBUTE_UNUSED,
    961      1.1  christos 			   bfd_byte *buf,
    962      1.1  christos 			   unsigned int *bytes_read_ptr)
    963      1.1  christos {
    964      1.1  christos   bfd_vma result;
    965      1.1  christos   unsigned int num_read;
    966      1.1  christos   unsigned int shift;
    967      1.1  christos   unsigned char byte;
    968      1.1  christos 
    969      1.1  christos   result = 0;
    970      1.1  christos   shift = 0;
    971      1.1  christos   num_read = 0;
    972      1.1  christos   do
    973      1.1  christos     {
    974      1.1  christos       byte = bfd_get_8 (abfd, buf);
    975      1.1  christos       buf++;
    976      1.1  christos       num_read++;
    977      1.1  christos       result |= (((bfd_vma) byte & 0x7f) << shift);
    978      1.1  christos       shift += 7;
    979      1.1  christos     }
    980      1.1  christos   while (byte & 0x80);
    981      1.1  christos   *bytes_read_ptr = num_read;
    982  1.1.1.3  christos   return result;
    983  1.1.1.3  christos }
    984  1.1.1.3  christos 
    985  1.1.1.3  christos /* Read in a LEB128 encoded value from ABFD starting at DATA.
    986  1.1.1.3  christos    If SIGN is true, return a signed LEB128 value.
    987  1.1.1.3  christos    If LENGTH_RETURN is not NULL, return in it the number of bytes read.
    988  1.1.1.5  christos    No bytes will be read at address END or beyond.  */
    989  1.1.1.5  christos 
    990  1.1.1.5  christos bfd_vma
    991  1.1.1.5  christos _bfd_safe_read_leb128 (bfd *abfd ATTRIBUTE_UNUSED,
    992  1.1.1.5  christos 		       bfd_byte *data,
    993  1.1.1.3  christos 		       unsigned int *length_return,
    994  1.1.1.3  christos 		       bfd_boolean sign,
    995  1.1.1.3  christos 		       const bfd_byte * const end)
    996  1.1.1.3  christos {
    997  1.1.1.3  christos   bfd_vma result = 0;
    998  1.1.1.3  christos   unsigned int num_read = 0;
    999  1.1.1.3  christos   unsigned int shift = 0;
   1000  1.1.1.3  christos   unsigned char byte = 0;
   1001  1.1.1.3  christos 
   1002  1.1.1.3  christos   while (data < end)
   1003  1.1.1.3  christos     {
   1004  1.1.1.3  christos       byte = bfd_get_8 (abfd, data);
   1005  1.1.1.3  christos       data++;
   1006  1.1.1.3  christos       num_read++;
   1007  1.1.1.3  christos 
   1008  1.1.1.3  christos       result |= ((bfd_vma) (byte & 0x7f)) << shift;
   1009  1.1.1.3  christos 
   1010  1.1.1.3  christos       shift += 7;
   1011  1.1.1.3  christos       if ((byte & 0x80) == 0)
   1012  1.1.1.3  christos 	break;
   1013  1.1.1.3  christos     }
   1014  1.1.1.3  christos 
   1015  1.1.1.3  christos   if (length_return != NULL)
   1016  1.1.1.4  christos     *length_return = num_read;
   1017  1.1.1.3  christos 
   1018  1.1.1.3  christos   if (sign && (shift < 8 * sizeof (result)) && (byte & 0x40))
   1019  1.1.1.3  christos     result |= -((bfd_vma) 1 << shift);
   1020  1.1.1.3  christos 
   1021      1.1  christos   return result;
   1022      1.1  christos }
   1023      1.1  christos 
   1024  1.1.1.5  christos /* Helper function for reading sleb128 encoded data.  */
   1025  1.1.1.5  christos 
   1026  1.1.1.5  christos bfd_signed_vma
   1027      1.1  christos _bfd_read_signed_leb128 (bfd *abfd ATTRIBUTE_UNUSED,
   1028      1.1  christos 			 bfd_byte *buf,
   1029      1.1  christos 			 unsigned int *bytes_read_ptr)
   1030      1.1  christos {
   1031      1.1  christos   bfd_vma result;
   1032      1.1  christos   unsigned int shift;
   1033      1.1  christos   unsigned int num_read;
   1034      1.1  christos   unsigned char byte;
   1035      1.1  christos 
   1036      1.1  christos   result = 0;
   1037      1.1  christos   shift = 0;
   1038      1.1  christos   num_read = 0;
   1039      1.1  christos   do
   1040      1.1  christos     {
   1041      1.1  christos       byte = bfd_get_8 (abfd, buf);
   1042      1.1  christos       buf ++;
   1043      1.1  christos       num_read ++;
   1044      1.1  christos       result |= (((bfd_vma) byte & 0x7f) << shift);
   1045      1.1  christos       shift += 7;
   1046      1.1  christos     }
   1047      1.1  christos   while (byte & 0x80);
   1048      1.1  christos   if (shift < 8 * sizeof (result) && (byte & 0x40))
   1049      1.1  christos     result |= (((bfd_vma) -1) << shift);
   1050      1.1  christos   *bytes_read_ptr = num_read;
   1051      1.1  christos   return result;
   1052      1.1  christos }
   1053      1.1  christos 
   1054      1.1  christos bfd_boolean
   1055      1.1  christos _bfd_generic_init_private_section_data (bfd *ibfd ATTRIBUTE_UNUSED,
   1056      1.1  christos 					asection *isec ATTRIBUTE_UNUSED,
   1057      1.1  christos 					bfd *obfd ATTRIBUTE_UNUSED,
   1058      1.1  christos 					asection *osec ATTRIBUTE_UNUSED,
   1059      1.1  christos 					struct bfd_link_info *link_info ATTRIBUTE_UNUSED)
   1060                    {
   1061                      return TRUE;
   1062                    }
   1063