1 /* Assorted BFD support routines, only used internally.
2 Copyright 1990, 1991, 1992, 1993, 1994, 1995, 1996, 1997, 1998, 1999,
3 2000, 2001, 2002, 2003, 2004, 2005, 2007
4 Free Software Foundation, Inc.
5 Written by Cygnus Support.
7 This file is part of BFD, the Binary File Descriptor library.
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.
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.
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., 51 Franklin Street - Fifth Floor, Boston, MA 02110-1301, USA. */
27 #ifndef HAVE_GETPAGESIZE
28 #define getpagesize() 2048
33 Implementation details
39 These routines are used within BFD.
40 They are not intended for export, but are documented here for
44 /* A routine which is used in target vectors for unsupported
48 bfd_false (bfd
*ignore ATTRIBUTE_UNUSED
)
50 bfd_set_error (bfd_error_invalid_operation
);
54 /* A routine which is used in target vectors for supported operations
55 which do not actually do anything. */
58 bfd_true (bfd
*ignore ATTRIBUTE_UNUSED
)
63 /* A routine which is used in target vectors for unsupported
64 operations which return a pointer value. */
67 bfd_nullvoidptr (bfd
*ignore ATTRIBUTE_UNUSED
)
69 bfd_set_error (bfd_error_invalid_operation
);
74 bfd_0 (bfd
*ignore ATTRIBUTE_UNUSED
)
80 bfd_0u (bfd
*ignore ATTRIBUTE_UNUSED
)
86 bfd_0l (bfd
*ignore ATTRIBUTE_UNUSED
)
91 /* A routine which is used in target vectors for unsupported
92 operations which return -1 on error. */
95 _bfd_n1 (bfd
*ignore_abfd ATTRIBUTE_UNUSED
)
97 bfd_set_error (bfd_error_invalid_operation
);
102 bfd_void (bfd
*ignore ATTRIBUTE_UNUSED
)
107 _bfd_norelocs_get_reloc_upper_bound (bfd
*abfd ATTRIBUTE_UNUSED
,
108 asection
*sec ATTRIBUTE_UNUSED
)
110 return sizeof (arelent
*);
114 _bfd_norelocs_canonicalize_reloc (bfd
*abfd ATTRIBUTE_UNUSED
,
115 asection
*sec ATTRIBUTE_UNUSED
,
117 asymbol
**symbols ATTRIBUTE_UNUSED
)
124 _bfd_nocore_core_file_matches_executable_p
125 (bfd
*ignore_core_bfd ATTRIBUTE_UNUSED
,
126 bfd
*ignore_exec_bfd ATTRIBUTE_UNUSED
)
128 bfd_set_error (bfd_error_invalid_operation
);
132 /* Routine to handle core_file_failing_command entry point for targets
133 without core file support. */
136 _bfd_nocore_core_file_failing_command (bfd
*ignore_abfd ATTRIBUTE_UNUSED
)
138 bfd_set_error (bfd_error_invalid_operation
);
142 /* Routine to handle core_file_failing_signal entry point for targets
143 without core file support. */
146 _bfd_nocore_core_file_failing_signal (bfd
*ignore_abfd ATTRIBUTE_UNUSED
)
148 bfd_set_error (bfd_error_invalid_operation
);
153 _bfd_dummy_target (bfd
*ignore_abfd ATTRIBUTE_UNUSED
)
155 bfd_set_error (bfd_error_wrong_format
);
159 /* Allocate memory using malloc. */
162 bfd_malloc (bfd_size_type size
)
166 if (size
!= (size_t) size
)
168 bfd_set_error (bfd_error_no_memory
);
172 ptr
= malloc ((size_t) size
);
173 if (ptr
== NULL
&& (size_t) size
!= 0)
174 bfd_set_error (bfd_error_no_memory
);
179 /* Allocate memory using malloc, nmemb * size with overflow checking. */
182 bfd_malloc2 (bfd_size_type nmemb
, bfd_size_type size
)
186 if ((nmemb
| size
) >= HALF_BFD_SIZE_TYPE
188 && nmemb
> ~(bfd_size_type
) 0 / size
)
190 bfd_set_error (bfd_error_no_memory
);
196 if (size
!= (size_t) size
)
198 bfd_set_error (bfd_error_no_memory
);
202 ptr
= malloc ((size_t) size
);
203 if (ptr
== NULL
&& (size_t) size
!= 0)
204 bfd_set_error (bfd_error_no_memory
);
209 /* Reallocate memory using realloc. */
212 bfd_realloc (void *ptr
, bfd_size_type size
)
216 if (size
!= (size_t) size
)
218 bfd_set_error (bfd_error_no_memory
);
223 ret
= malloc ((size_t) size
);
225 ret
= realloc (ptr
, (size_t) size
);
227 if (ret
== NULL
&& (size_t) size
!= 0)
228 bfd_set_error (bfd_error_no_memory
);
233 /* Reallocate memory using realloc, nmemb * size with overflow checking. */
236 bfd_realloc2 (void *ptr
, bfd_size_type nmemb
, bfd_size_type size
)
240 if ((nmemb
| size
) >= HALF_BFD_SIZE_TYPE
242 && nmemb
> ~(bfd_size_type
) 0 / size
)
244 bfd_set_error (bfd_error_no_memory
);
250 if (size
!= (size_t) size
)
252 bfd_set_error (bfd_error_no_memory
);
257 ret
= malloc ((size_t) size
);
259 ret
= realloc (ptr
, (size_t) size
);
261 if (ret
== NULL
&& (size_t) size
!= 0)
262 bfd_set_error (bfd_error_no_memory
);
267 /* Allocate memory using malloc and clear it. */
270 bfd_zmalloc (bfd_size_type size
)
274 if (size
!= (size_t) size
)
276 bfd_set_error (bfd_error_no_memory
);
280 ptr
= malloc ((size_t) size
);
282 if ((size_t) size
!= 0)
285 bfd_set_error (bfd_error_no_memory
);
287 memset (ptr
, 0, (size_t) size
);
293 /* Allocate memory using malloc (nmemb * size) with overflow checking
297 bfd_zmalloc2 (bfd_size_type nmemb
, bfd_size_type size
)
301 if ((nmemb
| size
) >= HALF_BFD_SIZE_TYPE
303 && nmemb
> ~(bfd_size_type
) 0 / size
)
305 bfd_set_error (bfd_error_no_memory
);
311 if (size
!= (size_t) size
)
313 bfd_set_error (bfd_error_no_memory
);
317 ptr
= malloc ((size_t) size
);
319 if ((size_t) size
!= 0)
322 bfd_set_error (bfd_error_no_memory
);
324 memset (ptr
, 0, (size_t) size
);
332 bfd_write_bigendian_4byte_int
335 bfd_boolean bfd_write_bigendian_4byte_int (bfd *, unsigned int);
338 Write a 4 byte integer @var{i} to the output BFD @var{abfd}, in big
339 endian order regardless of what else is going on. This is useful in
344 bfd_write_bigendian_4byte_int (bfd
*abfd
, unsigned int i
)
347 bfd_putb32 ((bfd_vma
) i
, buffer
);
348 return bfd_bwrite (buffer
, (bfd_size_type
) 4, abfd
) == 4;
352 /** The do-it-yourself (byte) sex-change kit */
354 /* The middle letter e.g. get<b>short indicates Big or Little endian
355 target machine. It doesn't matter what the byte order of the host
356 machine is; these routines work for either. */
358 /* FIXME: Should these take a count argument?
359 Answer (gnu@cygnus.com): No, but perhaps they should be inline
360 functions in swap.h #ifdef __GNUC__.
361 Gprof them later and find out. */
370 These macros as used for reading and writing raw data in
371 sections; each access (except for bytes) is vectored through
372 the target format of the BFD and mangled accordingly. The
373 mangling performs any necessary endian translations and
374 removes alignment restrictions. Note that types accepted and
375 returned by these macros are identical so they can be swapped
376 around in macros---for example, @file{libaout.h} defines <<GET_WORD>>
377 to either <<bfd_get_32>> or <<bfd_get_64>>.
379 In the put routines, @var{val} must be a <<bfd_vma>>. If we are on a
380 system without prototypes, the caller is responsible for making
381 sure that is true, with a cast if necessary. We don't cast
382 them in the macro definitions because that would prevent <<lint>>
383 or <<gcc -Wall>> from detecting sins such as passing a pointer.
384 To detect calling these with less than a <<bfd_vma>>, use
385 <<gcc -Wconversion>> on a host with 64 bit <<bfd_vma>>'s.
388 .{* Byte swapping macros for user section data. *}
390 .#define bfd_put_8(abfd, val, ptr) \
391 . ((void) (*((unsigned char *) (ptr)) = (val) & 0xff))
392 .#define bfd_put_signed_8 \
394 .#define bfd_get_8(abfd, ptr) \
395 . (*(unsigned char *) (ptr) & 0xff)
396 .#define bfd_get_signed_8(abfd, ptr) \
397 . (((*(unsigned char *) (ptr) & 0xff) ^ 0x80) - 0x80)
399 .#define bfd_put_16(abfd, val, ptr) \
400 . BFD_SEND (abfd, bfd_putx16, ((val),(ptr)))
401 .#define bfd_put_signed_16 \
403 .#define bfd_get_16(abfd, ptr) \
404 . BFD_SEND (abfd, bfd_getx16, (ptr))
405 .#define bfd_get_signed_16(abfd, ptr) \
406 . BFD_SEND (abfd, bfd_getx_signed_16, (ptr))
408 .#define bfd_put_32(abfd, val, ptr) \
409 . BFD_SEND (abfd, bfd_putx32, ((val),(ptr)))
410 .#define bfd_put_signed_32 \
412 .#define bfd_get_32(abfd, ptr) \
413 . BFD_SEND (abfd, bfd_getx32, (ptr))
414 .#define bfd_get_signed_32(abfd, ptr) \
415 . BFD_SEND (abfd, bfd_getx_signed_32, (ptr))
417 .#define bfd_put_64(abfd, val, ptr) \
418 . BFD_SEND (abfd, bfd_putx64, ((val), (ptr)))
419 .#define bfd_put_signed_64 \
421 .#define bfd_get_64(abfd, ptr) \
422 . BFD_SEND (abfd, bfd_getx64, (ptr))
423 .#define bfd_get_signed_64(abfd, ptr) \
424 . BFD_SEND (abfd, bfd_getx_signed_64, (ptr))
426 .#define bfd_get(bits, abfd, ptr) \
427 . ((bits) == 8 ? (bfd_vma) bfd_get_8 (abfd, ptr) \
428 . : (bits) == 16 ? bfd_get_16 (abfd, ptr) \
429 . : (bits) == 32 ? bfd_get_32 (abfd, ptr) \
430 . : (bits) == 64 ? bfd_get_64 (abfd, ptr) \
431 . : (abort (), (bfd_vma) - 1))
433 .#define bfd_put(bits, abfd, val, ptr) \
434 . ((bits) == 8 ? bfd_put_8 (abfd, val, ptr) \
435 . : (bits) == 16 ? bfd_put_16 (abfd, val, ptr) \
436 . : (bits) == 32 ? bfd_put_32 (abfd, val, ptr) \
437 . : (bits) == 64 ? bfd_put_64 (abfd, val, ptr) \
438 . : (abort (), (void) 0))
448 These macros have the same function as their <<bfd_get_x>>
449 brethren, except that they are used for removing information
450 for the header records of object files. Believe it or not,
451 some object files keep their header records in big endian
452 order and their data in little endian order.
454 .{* Byte swapping macros for file header data. *}
456 .#define bfd_h_put_8(abfd, val, ptr) \
457 . bfd_put_8 (abfd, val, ptr)
458 .#define bfd_h_put_signed_8(abfd, val, ptr) \
459 . bfd_put_8 (abfd, val, ptr)
460 .#define bfd_h_get_8(abfd, ptr) \
461 . bfd_get_8 (abfd, ptr)
462 .#define bfd_h_get_signed_8(abfd, ptr) \
463 . bfd_get_signed_8 (abfd, ptr)
465 .#define bfd_h_put_16(abfd, val, ptr) \
466 . BFD_SEND (abfd, bfd_h_putx16, (val, ptr))
467 .#define bfd_h_put_signed_16 \
469 .#define bfd_h_get_16(abfd, ptr) \
470 . BFD_SEND (abfd, bfd_h_getx16, (ptr))
471 .#define bfd_h_get_signed_16(abfd, ptr) \
472 . BFD_SEND (abfd, bfd_h_getx_signed_16, (ptr))
474 .#define bfd_h_put_32(abfd, val, ptr) \
475 . BFD_SEND (abfd, bfd_h_putx32, (val, ptr))
476 .#define bfd_h_put_signed_32 \
478 .#define bfd_h_get_32(abfd, ptr) \
479 . BFD_SEND (abfd, bfd_h_getx32, (ptr))
480 .#define bfd_h_get_signed_32(abfd, ptr) \
481 . BFD_SEND (abfd, bfd_h_getx_signed_32, (ptr))
483 .#define bfd_h_put_64(abfd, val, ptr) \
484 . BFD_SEND (abfd, bfd_h_putx64, (val, ptr))
485 .#define bfd_h_put_signed_64 \
487 .#define bfd_h_get_64(abfd, ptr) \
488 . BFD_SEND (abfd, bfd_h_getx64, (ptr))
489 .#define bfd_h_get_signed_64(abfd, ptr) \
490 . BFD_SEND (abfd, bfd_h_getx_signed_64, (ptr))
492 .{* Aliases for the above, which should eventually go away. *}
494 .#define H_PUT_64 bfd_h_put_64
495 .#define H_PUT_32 bfd_h_put_32
496 .#define H_PUT_16 bfd_h_put_16
497 .#define H_PUT_8 bfd_h_put_8
498 .#define H_PUT_S64 bfd_h_put_signed_64
499 .#define H_PUT_S32 bfd_h_put_signed_32
500 .#define H_PUT_S16 bfd_h_put_signed_16
501 .#define H_PUT_S8 bfd_h_put_signed_8
502 .#define H_GET_64 bfd_h_get_64
503 .#define H_GET_32 bfd_h_get_32
504 .#define H_GET_16 bfd_h_get_16
505 .#define H_GET_8 bfd_h_get_8
506 .#define H_GET_S64 bfd_h_get_signed_64
507 .#define H_GET_S32 bfd_h_get_signed_32
508 .#define H_GET_S16 bfd_h_get_signed_16
509 .#define H_GET_S8 bfd_h_get_signed_8
513 /* Sign extension to bfd_signed_vma. */
514 #define COERCE16(x) (((bfd_signed_vma) (x) ^ 0x8000) - 0x8000)
515 #define COERCE32(x) (((bfd_signed_vma) (x) ^ 0x80000000) - 0x80000000)
516 #define EIGHT_GAZILLION ((bfd_int64_t) 1 << 63)
517 #define COERCE64(x) \
518 (((bfd_int64_t) (x) ^ EIGHT_GAZILLION) - EIGHT_GAZILLION)
521 bfd_getb16 (const void *p
)
523 const bfd_byte
*addr
= p
;
524 return (addr
[0] << 8) | addr
[1];
528 bfd_getl16 (const void *p
)
530 const bfd_byte
*addr
= p
;
531 return (addr
[1] << 8) | addr
[0];
535 bfd_getb_signed_16 (const void *p
)
537 const bfd_byte
*addr
= p
;
538 return COERCE16 ((addr
[0] << 8) | addr
[1]);
542 bfd_getl_signed_16 (const void *p
)
544 const bfd_byte
*addr
= p
;
545 return COERCE16 ((addr
[1] << 8) | addr
[0]);
549 bfd_putb16 (bfd_vma data
, void *p
)
552 addr
[0] = (data
>> 8) & 0xff;
553 addr
[1] = data
& 0xff;
557 bfd_putl16 (bfd_vma data
, void *p
)
560 addr
[0] = data
& 0xff;
561 addr
[1] = (data
>> 8) & 0xff;
565 bfd_getb32 (const void *p
)
567 const bfd_byte
*addr
= p
;
570 v
= (unsigned long) addr
[0] << 24;
571 v
|= (unsigned long) addr
[1] << 16;
572 v
|= (unsigned long) addr
[2] << 8;
573 v
|= (unsigned long) addr
[3];
578 bfd_getl32 (const void *p
)
580 const bfd_byte
*addr
= p
;
583 v
= (unsigned long) addr
[0];
584 v
|= (unsigned long) addr
[1] << 8;
585 v
|= (unsigned long) addr
[2] << 16;
586 v
|= (unsigned long) addr
[3] << 24;
591 bfd_getb_signed_32 (const void *p
)
593 const bfd_byte
*addr
= p
;
596 v
= (unsigned long) addr
[0] << 24;
597 v
|= (unsigned long) addr
[1] << 16;
598 v
|= (unsigned long) addr
[2] << 8;
599 v
|= (unsigned long) addr
[3];
604 bfd_getl_signed_32 (const void *p
)
606 const bfd_byte
*addr
= p
;
609 v
= (unsigned long) addr
[0];
610 v
|= (unsigned long) addr
[1] << 8;
611 v
|= (unsigned long) addr
[2] << 16;
612 v
|= (unsigned long) addr
[3] << 24;
617 bfd_getb64 (const void *p ATTRIBUTE_UNUSED
)
619 #ifdef BFD_HOST_64_BIT
620 const bfd_byte
*addr
= p
;
623 v
= addr
[0]; v
<<= 8;
624 v
|= addr
[1]; v
<<= 8;
625 v
|= addr
[2]; v
<<= 8;
626 v
|= addr
[3]; v
<<= 8;
627 v
|= addr
[4]; v
<<= 8;
628 v
|= addr
[5]; v
<<= 8;
629 v
|= addr
[6]; v
<<= 8;
640 bfd_getl64 (const void *p ATTRIBUTE_UNUSED
)
642 #ifdef BFD_HOST_64_BIT
643 const bfd_byte
*addr
= p
;
646 v
= addr
[7]; v
<<= 8;
647 v
|= addr
[6]; v
<<= 8;
648 v
|= addr
[5]; v
<<= 8;
649 v
|= addr
[4]; v
<<= 8;
650 v
|= addr
[3]; v
<<= 8;
651 v
|= addr
[2]; v
<<= 8;
652 v
|= addr
[1]; v
<<= 8;
664 bfd_getb_signed_64 (const void *p ATTRIBUTE_UNUSED
)
666 #ifdef BFD_HOST_64_BIT
667 const bfd_byte
*addr
= p
;
670 v
= addr
[0]; v
<<= 8;
671 v
|= addr
[1]; v
<<= 8;
672 v
|= addr
[2]; v
<<= 8;
673 v
|= addr
[3]; v
<<= 8;
674 v
|= addr
[4]; v
<<= 8;
675 v
|= addr
[5]; v
<<= 8;
676 v
|= addr
[6]; v
<<= 8;
687 bfd_getl_signed_64 (const void *p ATTRIBUTE_UNUSED
)
689 #ifdef BFD_HOST_64_BIT
690 const bfd_byte
*addr
= p
;
693 v
= addr
[7]; v
<<= 8;
694 v
|= addr
[6]; v
<<= 8;
695 v
|= addr
[5]; v
<<= 8;
696 v
|= addr
[4]; v
<<= 8;
697 v
|= addr
[3]; v
<<= 8;
698 v
|= addr
[2]; v
<<= 8;
699 v
|= addr
[1]; v
<<= 8;
710 bfd_putb32 (bfd_vma data
, void *p
)
713 addr
[0] = (data
>> 24) & 0xff;
714 addr
[1] = (data
>> 16) & 0xff;
715 addr
[2] = (data
>> 8) & 0xff;
716 addr
[3] = data
& 0xff;
720 bfd_putl32 (bfd_vma data
, void *p
)
723 addr
[0] = data
& 0xff;
724 addr
[1] = (data
>> 8) & 0xff;
725 addr
[2] = (data
>> 16) & 0xff;
726 addr
[3] = (data
>> 24) & 0xff;
730 bfd_putb64 (bfd_uint64_t data ATTRIBUTE_UNUSED
, void *p ATTRIBUTE_UNUSED
)
732 #ifdef BFD_HOST_64_BIT
734 addr
[0] = (data
>> (7*8)) & 0xff;
735 addr
[1] = (data
>> (6*8)) & 0xff;
736 addr
[2] = (data
>> (5*8)) & 0xff;
737 addr
[3] = (data
>> (4*8)) & 0xff;
738 addr
[4] = (data
>> (3*8)) & 0xff;
739 addr
[5] = (data
>> (2*8)) & 0xff;
740 addr
[6] = (data
>> (1*8)) & 0xff;
741 addr
[7] = (data
>> (0*8)) & 0xff;
748 bfd_putl64 (bfd_uint64_t data ATTRIBUTE_UNUSED
, void *p ATTRIBUTE_UNUSED
)
750 #ifdef BFD_HOST_64_BIT
752 addr
[7] = (data
>> (7*8)) & 0xff;
753 addr
[6] = (data
>> (6*8)) & 0xff;
754 addr
[5] = (data
>> (5*8)) & 0xff;
755 addr
[4] = (data
>> (4*8)) & 0xff;
756 addr
[3] = (data
>> (3*8)) & 0xff;
757 addr
[2] = (data
>> (2*8)) & 0xff;
758 addr
[1] = (data
>> (1*8)) & 0xff;
759 addr
[0] = (data
>> (0*8)) & 0xff;
766 bfd_put_bits (bfd_uint64_t data
, void *p
, int bits
, bfd_boolean big_p
)
776 for (i
= 0; i
< bytes
; i
++)
778 int index
= big_p
? bytes
- i
- 1 : i
;
780 addr
[index
] = data
& 0xff;
786 bfd_get_bits (const void *p
, int bits
, bfd_boolean big_p
)
788 const bfd_byte
*addr
= p
;
798 for (i
= 0; i
< bytes
; i
++)
800 int index
= big_p
? i
: bytes
- i
- 1;
802 data
= (data
<< 8) | addr
[index
];
808 /* Default implementation */
811 _bfd_generic_get_section_contents (bfd
*abfd
,
821 sz
= section
->rawsize
? section
->rawsize
: section
->size
;
822 if (offset
+ count
> sz
)
824 bfd_set_error (bfd_error_invalid_operation
);
828 if (bfd_seek (abfd
, section
->filepos
+ offset
, SEEK_SET
) != 0
829 || bfd_bread (location
, count
, abfd
) != count
)
836 _bfd_generic_get_section_contents_in_window
837 (bfd
*abfd ATTRIBUTE_UNUSED
,
838 sec_ptr section ATTRIBUTE_UNUSED
,
839 bfd_window
*w ATTRIBUTE_UNUSED
,
840 file_ptr offset ATTRIBUTE_UNUSED
,
841 bfd_size_type count ATTRIBUTE_UNUSED
)
848 if (abfd
->xvec
->_bfd_get_section_contents
849 != _bfd_generic_get_section_contents
)
851 /* We don't know what changes the bfd's get_section_contents
852 method may have to make. So punt trying to map the file
853 window, and let get_section_contents do its thing. */
854 /* @@ FIXME : If the internal window has a refcount of 1 and was
855 allocated with malloc instead of mmap, just reuse it. */
857 w
->i
= bfd_zmalloc (sizeof (bfd_window_internal
));
860 w
->i
->data
= bfd_malloc (count
);
861 if (w
->i
->data
== NULL
)
869 w
->size
= w
->i
->size
= count
;
870 w
->data
= w
->i
->data
;
871 return bfd_get_section_contents (abfd
, section
, w
->data
, offset
, count
);
873 sz
= section
->rawsize
? section
->rawsize
: section
->size
;
874 if (offset
+ count
> sz
875 || ! bfd_get_file_window (abfd
, section
->filepos
+ offset
, count
, w
,
884 /* This generic function can only be used in implementations where creating
885 NEW sections is disallowed. It is useful in patching existing sections
886 in read-write files, though. See other set_section_contents functions
887 to see why it doesn't work for new sections. */
889 _bfd_generic_set_section_contents (bfd
*abfd
,
891 const void *location
,
898 if (bfd_seek (abfd
, section
->filepos
+ offset
, SEEK_SET
) != 0
899 || bfd_bwrite (location
, count
, abfd
) != count
)
910 unsigned int bfd_log2 (bfd_vma x);
913 Return the log base 2 of the value supplied, rounded up. E.g., an
914 @var{x} of 1025 returns 11. A @var{x} of 0 returns 0.
920 unsigned int result
= 0;
922 while ((x
= (x
>> 1)) != 0)
928 bfd_generic_is_local_label_name (bfd
*abfd
, const char *name
)
930 char locals_prefix
= (bfd_get_symbol_leading_char (abfd
) == '_') ? 'L' : '.';
932 return name
[0] == locals_prefix
;
935 /* Can be used from / for bfd_merge_private_bfd_data to check that
936 endianness matches between input and output file. Returns
937 TRUE for a match, otherwise returns FALSE and emits an error. */
939 _bfd_generic_verify_endian_match (bfd
*ibfd
, bfd
*obfd
)
941 if (ibfd
->xvec
->byteorder
!= obfd
->xvec
->byteorder
942 && ibfd
->xvec
->byteorder
!= BFD_ENDIAN_UNKNOWN
943 && obfd
->xvec
->byteorder
!= BFD_ENDIAN_UNKNOWN
)
947 if (bfd_big_endian (ibfd
))
948 msg
= _("%B: compiled for a big endian system and target is little endian");
950 msg
= _("%B: compiled for a little endian system and target is big endian");
952 (*_bfd_error_handler
) (msg
, ibfd
);
954 bfd_set_error (bfd_error_wrong_format
);
961 /* Give a warning at runtime if someone compiles code which calls
965 warn_deprecated (const char *what
,
970 /* Poor man's tracking of functions we've already warned about. */
971 static size_t mask
= 0;
973 if (~(size_t) func
& ~mask
)
975 /* Note: separate sentences in order to allow
976 for translation into other languages. */
978 fprintf (stderr
, _("Deprecated %s called at %s line %d in %s\n"),
979 what
, file
, line
, func
);
981 fprintf (stderr
, _("Deprecated %s called\n"), what
);
982 mask
|= ~(size_t) func
;
986 /* Helper function for reading uleb128 encoded data. */
989 read_unsigned_leb128 (bfd
*abfd ATTRIBUTE_UNUSED
,
991 unsigned int *bytes_read_ptr
)
994 unsigned int num_read
;
1003 byte
= bfd_get_8 (abfd
, buf
);
1006 result
|= (((bfd_vma
) byte
& 0x7f) << shift
);
1009 while (byte
& 0x80);
1010 *bytes_read_ptr
= num_read
;
1014 /* Helper function for reading sleb128 encoded data. */
1017 read_signed_leb128 (bfd
*abfd ATTRIBUTE_UNUSED
,
1019 unsigned int *bytes_read_ptr
)
1023 unsigned int num_read
;
1031 byte
= bfd_get_8 (abfd
, buf
);
1034 result
|= (((bfd_vma
) byte
& 0x7f) << shift
);
1037 while (byte
& 0x80);
1038 if (shift
< 8 * sizeof (result
) && (byte
& 0x40))
1039 result
|= (((bfd_vma
) -1) << shift
);
1040 *bytes_read_ptr
= num_read
;
1045 _bfd_generic_find_line (bfd
*abfd ATTRIBUTE_UNUSED
,
1046 asymbol
**symbols ATTRIBUTE_UNUSED
,
1047 asymbol
*symbol ATTRIBUTE_UNUSED
,
1048 const char **filename_ptr ATTRIBUTE_UNUSED
,
1049 unsigned int *linenumber_ptr ATTRIBUTE_UNUSED
)
1055 _bfd_generic_init_private_section_data (bfd
*ibfd ATTRIBUTE_UNUSED
,
1056 asection
*isec ATTRIBUTE_UNUSED
,
1057 bfd
*obfd ATTRIBUTE_UNUSED
,
1058 asection
*osec ATTRIBUTE_UNUSED
,
1059 struct bfd_link_info
*link_info ATTRIBUTE_UNUSED
)