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
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
36 These routines are used within BFD.
37 They are not intended for export, but are documented here for
41 /* A routine which is used in target vectors for unsupported
45 bfd_false (bfd
*ignore ATTRIBUTE_UNUSED
)
47 bfd_set_error (bfd_error_invalid_operation
);
51 /* A routine which is used in target vectors for supported operations
52 which do not actually do anything. */
55 bfd_true (bfd
*ignore ATTRIBUTE_UNUSED
)
60 /* A routine which is used in target vectors for unsupported
61 operations which return a pointer value. */
64 bfd_nullvoidptr (bfd
*ignore ATTRIBUTE_UNUSED
)
66 bfd_set_error (bfd_error_invalid_operation
);
71 bfd_0 (bfd
*ignore ATTRIBUTE_UNUSED
)
77 bfd_0u (bfd
*ignore ATTRIBUTE_UNUSED
)
83 bfd_0l (bfd
*ignore ATTRIBUTE_UNUSED
)
88 /* A routine which is used in target vectors for unsupported
89 operations which return -1 on error. */
92 _bfd_n1 (bfd
*ignore_abfd ATTRIBUTE_UNUSED
)
94 bfd_set_error (bfd_error_invalid_operation
);
99 bfd_void (bfd
*ignore ATTRIBUTE_UNUSED
)
104 _bfd_nocore_core_file_matches_executable_p
105 (bfd
*ignore_core_bfd ATTRIBUTE_UNUSED
,
106 bfd
*ignore_exec_bfd ATTRIBUTE_UNUSED
)
108 bfd_set_error (bfd_error_invalid_operation
);
112 /* Routine to handle core_file_failing_command entry point for targets
113 without core file support. */
116 _bfd_nocore_core_file_failing_command (bfd
*ignore_abfd ATTRIBUTE_UNUSED
)
118 bfd_set_error (bfd_error_invalid_operation
);
122 /* Routine to handle core_file_failing_signal entry point for targets
123 without core file support. */
126 _bfd_nocore_core_file_failing_signal (bfd
*ignore_abfd ATTRIBUTE_UNUSED
)
128 bfd_set_error (bfd_error_invalid_operation
);
133 _bfd_dummy_target (bfd
*ignore_abfd ATTRIBUTE_UNUSED
)
135 bfd_set_error (bfd_error_wrong_format
);
139 /* Allocate memory using malloc. */
142 bfd_malloc (bfd_size_type size
)
146 if (size
!= (size_t) size
)
148 bfd_set_error (bfd_error_no_memory
);
152 ptr
= malloc ((size_t) size
);
153 if (ptr
== NULL
&& (size_t) size
!= 0)
154 bfd_set_error (bfd_error_no_memory
);
159 /* Allocate memory using malloc, nmemb * size with overflow checking. */
162 bfd_malloc2 (bfd_size_type nmemb
, bfd_size_type size
)
166 if ((nmemb
| size
) >= HALF_BFD_SIZE_TYPE
168 && nmemb
> ~(bfd_size_type
) 0 / size
)
170 bfd_set_error (bfd_error_no_memory
);
176 if (size
!= (size_t) size
)
178 bfd_set_error (bfd_error_no_memory
);
182 ptr
= malloc ((size_t) size
);
183 if (ptr
== NULL
&& (size_t) size
!= 0)
184 bfd_set_error (bfd_error_no_memory
);
189 /* Reallocate memory using realloc. */
192 bfd_realloc (void *ptr
, bfd_size_type size
)
196 if (size
!= (size_t) size
)
198 bfd_set_error (bfd_error_no_memory
);
203 ret
= malloc ((size_t) size
);
205 ret
= realloc (ptr
, (size_t) size
);
207 if (ret
== NULL
&& (size_t) size
!= 0)
208 bfd_set_error (bfd_error_no_memory
);
213 /* Reallocate memory using realloc, nmemb * size with overflow checking. */
216 bfd_realloc2 (void *ptr
, bfd_size_type nmemb
, bfd_size_type size
)
220 if ((nmemb
| size
) >= HALF_BFD_SIZE_TYPE
222 && nmemb
> ~(bfd_size_type
) 0 / size
)
224 bfd_set_error (bfd_error_no_memory
);
230 if (size
!= (size_t) size
)
232 bfd_set_error (bfd_error_no_memory
);
237 ret
= malloc ((size_t) size
);
239 ret
= realloc (ptr
, (size_t) size
);
241 if (ret
== NULL
&& (size_t) size
!= 0)
242 bfd_set_error (bfd_error_no_memory
);
247 /* Allocate memory using malloc and clear it. */
250 bfd_zmalloc (bfd_size_type size
)
254 if (size
!= (size_t) size
)
256 bfd_set_error (bfd_error_no_memory
);
260 ptr
= malloc ((size_t) size
);
262 if ((size_t) size
!= 0)
265 bfd_set_error (bfd_error_no_memory
);
267 memset (ptr
, 0, (size_t) size
);
273 /* Allocate memory using malloc (nmemb * size) with overflow checking
277 bfd_zmalloc2 (bfd_size_type nmemb
, bfd_size_type size
)
281 if ((nmemb
| size
) >= HALF_BFD_SIZE_TYPE
283 && nmemb
> ~(bfd_size_type
) 0 / size
)
285 bfd_set_error (bfd_error_no_memory
);
291 if (size
!= (size_t) size
)
293 bfd_set_error (bfd_error_no_memory
);
297 ptr
= malloc ((size_t) size
);
299 if ((size_t) size
!= 0)
302 bfd_set_error (bfd_error_no_memory
);
304 memset (ptr
, 0, (size_t) size
);
312 bfd_write_bigendian_4byte_int
315 bfd_boolean bfd_write_bigendian_4byte_int (bfd *, unsigned int);
318 Write a 4 byte integer @var{i} to the output BFD @var{abfd}, in big
319 endian order regardless of what else is going on. This is useful in
324 bfd_write_bigendian_4byte_int (bfd
*abfd
, unsigned int i
)
327 bfd_putb32 ((bfd_vma
) i
, buffer
);
328 return bfd_bwrite (buffer
, (bfd_size_type
) 4, abfd
) == 4;
332 /** The do-it-yourself (byte) sex-change kit */
334 /* The middle letter e.g. get<b>short indicates Big or Little endian
335 target machine. It doesn't matter what the byte order of the host
336 machine is; these routines work for either. */
338 /* FIXME: Should these take a count argument?
339 Answer (gnu@cygnus.com): No, but perhaps they should be inline
340 functions in swap.h #ifdef __GNUC__.
341 Gprof them later and find out. */
350 These macros as used for reading and writing raw data in
351 sections; each access (except for bytes) is vectored through
352 the target format of the BFD and mangled accordingly. The
353 mangling performs any necessary endian translations and
354 removes alignment restrictions. Note that types accepted and
355 returned by these macros are identical so they can be swapped
356 around in macros---for example, @file{libaout.h} defines <<GET_WORD>>
357 to either <<bfd_get_32>> or <<bfd_get_64>>.
359 In the put routines, @var{val} must be a <<bfd_vma>>. If we are on a
360 system without prototypes, the caller is responsible for making
361 sure that is true, with a cast if necessary. We don't cast
362 them in the macro definitions because that would prevent <<lint>>
363 or <<gcc -Wall>> from detecting sins such as passing a pointer.
364 To detect calling these with less than a <<bfd_vma>>, use
365 <<gcc -Wconversion>> on a host with 64 bit <<bfd_vma>>'s.
368 .{* Byte swapping macros for user section data. *}
370 .#define bfd_put_8(abfd, val, ptr) \
371 . ((void) (*((unsigned char *) (ptr)) = (val) & 0xff))
372 .#define bfd_put_signed_8 \
374 .#define bfd_get_8(abfd, ptr) \
375 . (*(unsigned char *) (ptr) & 0xff)
376 .#define bfd_get_signed_8(abfd, ptr) \
377 . (((*(unsigned char *) (ptr) & 0xff) ^ 0x80) - 0x80)
379 .#define bfd_put_16(abfd, val, ptr) \
380 . BFD_SEND (abfd, bfd_putx16, ((val),(ptr)))
381 .#define bfd_put_signed_16 \
383 .#define bfd_get_16(abfd, ptr) \
384 . BFD_SEND (abfd, bfd_getx16, (ptr))
385 .#define bfd_get_signed_16(abfd, ptr) \
386 . BFD_SEND (abfd, bfd_getx_signed_16, (ptr))
388 .#define bfd_put_32(abfd, val, ptr) \
389 . BFD_SEND (abfd, bfd_putx32, ((val),(ptr)))
390 .#define bfd_put_signed_32 \
392 .#define bfd_get_32(abfd, ptr) \
393 . BFD_SEND (abfd, bfd_getx32, (ptr))
394 .#define bfd_get_signed_32(abfd, ptr) \
395 . BFD_SEND (abfd, bfd_getx_signed_32, (ptr))
397 .#define bfd_put_64(abfd, val, ptr) \
398 . BFD_SEND (abfd, bfd_putx64, ((val), (ptr)))
399 .#define bfd_put_signed_64 \
401 .#define bfd_get_64(abfd, ptr) \
402 . BFD_SEND (abfd, bfd_getx64, (ptr))
403 .#define bfd_get_signed_64(abfd, ptr) \
404 . BFD_SEND (abfd, bfd_getx_signed_64, (ptr))
406 .#define bfd_get(bits, abfd, ptr) \
407 . ((bits) == 8 ? (bfd_vma) bfd_get_8 (abfd, ptr) \
408 . : (bits) == 16 ? bfd_get_16 (abfd, ptr) \
409 . : (bits) == 32 ? bfd_get_32 (abfd, ptr) \
410 . : (bits) == 64 ? bfd_get_64 (abfd, ptr) \
411 . : (abort (), (bfd_vma) - 1))
413 .#define bfd_put(bits, abfd, val, ptr) \
414 . ((bits) == 8 ? bfd_put_8 (abfd, val, ptr) \
415 . : (bits) == 16 ? bfd_put_16 (abfd, val, ptr) \
416 . : (bits) == 32 ? bfd_put_32 (abfd, val, ptr) \
417 . : (bits) == 64 ? bfd_put_64 (abfd, val, ptr) \
418 . : (abort (), (void) 0))
428 These macros have the same function as their <<bfd_get_x>>
429 brethren, except that they are used for removing information
430 for the header records of object files. Believe it or not,
431 some object files keep their header records in big endian
432 order and their data in little endian order.
434 .{* Byte swapping macros for file header data. *}
436 .#define bfd_h_put_8(abfd, val, ptr) \
437 . bfd_put_8 (abfd, val, ptr)
438 .#define bfd_h_put_signed_8(abfd, val, ptr) \
439 . bfd_put_8 (abfd, val, ptr)
440 .#define bfd_h_get_8(abfd, ptr) \
441 . bfd_get_8 (abfd, ptr)
442 .#define bfd_h_get_signed_8(abfd, ptr) \
443 . bfd_get_signed_8 (abfd, ptr)
445 .#define bfd_h_put_16(abfd, val, ptr) \
446 . BFD_SEND (abfd, bfd_h_putx16, (val, ptr))
447 .#define bfd_h_put_signed_16 \
449 .#define bfd_h_get_16(abfd, ptr) \
450 . BFD_SEND (abfd, bfd_h_getx16, (ptr))
451 .#define bfd_h_get_signed_16(abfd, ptr) \
452 . BFD_SEND (abfd, bfd_h_getx_signed_16, (ptr))
454 .#define bfd_h_put_32(abfd, val, ptr) \
455 . BFD_SEND (abfd, bfd_h_putx32, (val, ptr))
456 .#define bfd_h_put_signed_32 \
458 .#define bfd_h_get_32(abfd, ptr) \
459 . BFD_SEND (abfd, bfd_h_getx32, (ptr))
460 .#define bfd_h_get_signed_32(abfd, ptr) \
461 . BFD_SEND (abfd, bfd_h_getx_signed_32, (ptr))
463 .#define bfd_h_put_64(abfd, val, ptr) \
464 . BFD_SEND (abfd, bfd_h_putx64, (val, ptr))
465 .#define bfd_h_put_signed_64 \
467 .#define bfd_h_get_64(abfd, ptr) \
468 . BFD_SEND (abfd, bfd_h_getx64, (ptr))
469 .#define bfd_h_get_signed_64(abfd, ptr) \
470 . BFD_SEND (abfd, bfd_h_getx_signed_64, (ptr))
472 .{* Aliases for the above, which should eventually go away. *}
474 .#define H_PUT_64 bfd_h_put_64
475 .#define H_PUT_32 bfd_h_put_32
476 .#define H_PUT_16 bfd_h_put_16
477 .#define H_PUT_8 bfd_h_put_8
478 .#define H_PUT_S64 bfd_h_put_signed_64
479 .#define H_PUT_S32 bfd_h_put_signed_32
480 .#define H_PUT_S16 bfd_h_put_signed_16
481 .#define H_PUT_S8 bfd_h_put_signed_8
482 .#define H_GET_64 bfd_h_get_64
483 .#define H_GET_32 bfd_h_get_32
484 .#define H_GET_16 bfd_h_get_16
485 .#define H_GET_8 bfd_h_get_8
486 .#define H_GET_S64 bfd_h_get_signed_64
487 .#define H_GET_S32 bfd_h_get_signed_32
488 .#define H_GET_S16 bfd_h_get_signed_16
489 .#define H_GET_S8 bfd_h_get_signed_8
493 /* Sign extension to bfd_signed_vma. */
494 #define COERCE16(x) (((bfd_signed_vma) (x) ^ 0x8000) - 0x8000)
495 #define COERCE32(x) (((bfd_signed_vma) (x) ^ 0x80000000) - 0x80000000)
496 #define EIGHT_GAZILLION ((bfd_int64_t) 1 << 63)
497 #define COERCE64(x) \
498 (((bfd_int64_t) (x) ^ EIGHT_GAZILLION) - EIGHT_GAZILLION)
501 bfd_getb16 (const void *p
)
503 const bfd_byte
*addr
= p
;
504 return (addr
[0] << 8) | addr
[1];
508 bfd_getl16 (const void *p
)
510 const bfd_byte
*addr
= p
;
511 return (addr
[1] << 8) | addr
[0];
515 bfd_getb_signed_16 (const void *p
)
517 const bfd_byte
*addr
= p
;
518 return COERCE16 ((addr
[0] << 8) | addr
[1]);
522 bfd_getl_signed_16 (const void *p
)
524 const bfd_byte
*addr
= p
;
525 return COERCE16 ((addr
[1] << 8) | addr
[0]);
529 bfd_putb16 (bfd_vma data
, void *p
)
532 addr
[0] = (data
>> 8) & 0xff;
533 addr
[1] = data
& 0xff;
537 bfd_putl16 (bfd_vma data
, void *p
)
540 addr
[0] = data
& 0xff;
541 addr
[1] = (data
>> 8) & 0xff;
545 bfd_getb32 (const void *p
)
547 const bfd_byte
*addr
= p
;
550 v
= (unsigned long) addr
[0] << 24;
551 v
|= (unsigned long) addr
[1] << 16;
552 v
|= (unsigned long) addr
[2] << 8;
553 v
|= (unsigned long) addr
[3];
558 bfd_getl32 (const void *p
)
560 const bfd_byte
*addr
= p
;
563 v
= (unsigned long) addr
[0];
564 v
|= (unsigned long) addr
[1] << 8;
565 v
|= (unsigned long) addr
[2] << 16;
566 v
|= (unsigned long) addr
[3] << 24;
571 bfd_getb_signed_32 (const void *p
)
573 const bfd_byte
*addr
= p
;
576 v
= (unsigned long) addr
[0] << 24;
577 v
|= (unsigned long) addr
[1] << 16;
578 v
|= (unsigned long) addr
[2] << 8;
579 v
|= (unsigned long) addr
[3];
584 bfd_getl_signed_32 (const void *p
)
586 const bfd_byte
*addr
= p
;
589 v
= (unsigned long) addr
[0];
590 v
|= (unsigned long) addr
[1] << 8;
591 v
|= (unsigned long) addr
[2] << 16;
592 v
|= (unsigned long) addr
[3] << 24;
597 bfd_getb64 (const void *p ATTRIBUTE_UNUSED
)
599 #ifdef BFD_HOST_64_BIT
600 const bfd_byte
*addr
= p
;
603 v
= addr
[0]; v
<<= 8;
604 v
|= addr
[1]; v
<<= 8;
605 v
|= addr
[2]; v
<<= 8;
606 v
|= addr
[3]; v
<<= 8;
607 v
|= addr
[4]; v
<<= 8;
608 v
|= addr
[5]; v
<<= 8;
609 v
|= addr
[6]; v
<<= 8;
620 bfd_getl64 (const void *p ATTRIBUTE_UNUSED
)
622 #ifdef BFD_HOST_64_BIT
623 const bfd_byte
*addr
= p
;
626 v
= addr
[7]; v
<<= 8;
627 v
|= addr
[6]; v
<<= 8;
628 v
|= addr
[5]; v
<<= 8;
629 v
|= addr
[4]; v
<<= 8;
630 v
|= addr
[3]; v
<<= 8;
631 v
|= addr
[2]; v
<<= 8;
632 v
|= addr
[1]; v
<<= 8;
644 bfd_getb_signed_64 (const void *p ATTRIBUTE_UNUSED
)
646 #ifdef BFD_HOST_64_BIT
647 const bfd_byte
*addr
= p
;
650 v
= addr
[0]; v
<<= 8;
651 v
|= addr
[1]; v
<<= 8;
652 v
|= addr
[2]; v
<<= 8;
653 v
|= addr
[3]; v
<<= 8;
654 v
|= addr
[4]; v
<<= 8;
655 v
|= addr
[5]; v
<<= 8;
656 v
|= addr
[6]; v
<<= 8;
667 bfd_getl_signed_64 (const void *p ATTRIBUTE_UNUSED
)
669 #ifdef BFD_HOST_64_BIT
670 const bfd_byte
*addr
= p
;
673 v
= addr
[7]; v
<<= 8;
674 v
|= addr
[6]; v
<<= 8;
675 v
|= addr
[5]; v
<<= 8;
676 v
|= addr
[4]; v
<<= 8;
677 v
|= addr
[3]; v
<<= 8;
678 v
|= addr
[2]; v
<<= 8;
679 v
|= addr
[1]; v
<<= 8;
690 bfd_putb32 (bfd_vma data
, void *p
)
693 addr
[0] = (data
>> 24) & 0xff;
694 addr
[1] = (data
>> 16) & 0xff;
695 addr
[2] = (data
>> 8) & 0xff;
696 addr
[3] = data
& 0xff;
700 bfd_putl32 (bfd_vma data
, void *p
)
703 addr
[0] = data
& 0xff;
704 addr
[1] = (data
>> 8) & 0xff;
705 addr
[2] = (data
>> 16) & 0xff;
706 addr
[3] = (data
>> 24) & 0xff;
710 bfd_putb64 (bfd_uint64_t data ATTRIBUTE_UNUSED
, void *p ATTRIBUTE_UNUSED
)
712 #ifdef BFD_HOST_64_BIT
714 addr
[0] = (data
>> (7*8)) & 0xff;
715 addr
[1] = (data
>> (6*8)) & 0xff;
716 addr
[2] = (data
>> (5*8)) & 0xff;
717 addr
[3] = (data
>> (4*8)) & 0xff;
718 addr
[4] = (data
>> (3*8)) & 0xff;
719 addr
[5] = (data
>> (2*8)) & 0xff;
720 addr
[6] = (data
>> (1*8)) & 0xff;
721 addr
[7] = (data
>> (0*8)) & 0xff;
728 bfd_putl64 (bfd_uint64_t data ATTRIBUTE_UNUSED
, void *p ATTRIBUTE_UNUSED
)
730 #ifdef BFD_HOST_64_BIT
732 addr
[7] = (data
>> (7*8)) & 0xff;
733 addr
[6] = (data
>> (6*8)) & 0xff;
734 addr
[5] = (data
>> (5*8)) & 0xff;
735 addr
[4] = (data
>> (4*8)) & 0xff;
736 addr
[3] = (data
>> (3*8)) & 0xff;
737 addr
[2] = (data
>> (2*8)) & 0xff;
738 addr
[1] = (data
>> (1*8)) & 0xff;
739 addr
[0] = (data
>> (0*8)) & 0xff;
746 bfd_put_bits (bfd_uint64_t data
, void *p
, int bits
, bfd_boolean big_p
)
756 for (i
= 0; i
< bytes
; i
++)
758 int index
= big_p
? bytes
- i
- 1 : i
;
760 addr
[index
] = data
& 0xff;
766 bfd_get_bits (const void *p
, int bits
, bfd_boolean big_p
)
768 const bfd_byte
*addr
= p
;
778 for (i
= 0; i
< bytes
; i
++)
780 int index
= big_p
? i
: bytes
- i
- 1;
782 data
= (data
<< 8) | addr
[index
];
788 /* Default implementation */
791 _bfd_generic_get_section_contents (bfd
*abfd
,
801 sz
= section
->rawsize
? section
->rawsize
: section
->size
;
802 if (offset
+ count
> sz
)
804 bfd_set_error (bfd_error_invalid_operation
);
808 if (bfd_seek (abfd
, section
->filepos
+ offset
, SEEK_SET
) != 0
809 || bfd_bread (location
, count
, abfd
) != count
)
816 _bfd_generic_get_section_contents_in_window
817 (bfd
*abfd ATTRIBUTE_UNUSED
,
818 sec_ptr section ATTRIBUTE_UNUSED
,
819 bfd_window
*w ATTRIBUTE_UNUSED
,
820 file_ptr offset ATTRIBUTE_UNUSED
,
821 bfd_size_type count ATTRIBUTE_UNUSED
)
828 if (abfd
->xvec
->_bfd_get_section_contents
829 != _bfd_generic_get_section_contents
)
831 /* We don't know what changes the bfd's get_section_contents
832 method may have to make. So punt trying to map the file
833 window, and let get_section_contents do its thing. */
834 /* @@ FIXME : If the internal window has a refcount of 1 and was
835 allocated with malloc instead of mmap, just reuse it. */
837 w
->i
= bfd_zmalloc (sizeof (bfd_window_internal
));
840 w
->i
->data
= bfd_malloc (count
);
841 if (w
->i
->data
== NULL
)
849 w
->size
= w
->i
->size
= count
;
850 w
->data
= w
->i
->data
;
851 return bfd_get_section_contents (abfd
, section
, w
->data
, offset
, count
);
853 sz
= section
->rawsize
? section
->rawsize
: section
->size
;
854 if (offset
+ count
> sz
855 || ! bfd_get_file_window (abfd
, section
->filepos
+ offset
, count
, w
,
864 /* This generic function can only be used in implementations where creating
865 NEW sections is disallowed. It is useful in patching existing sections
866 in read-write files, though. See other set_section_contents functions
867 to see why it doesn't work for new sections. */
869 _bfd_generic_set_section_contents (bfd
*abfd
,
871 const void *location
,
878 if (bfd_seek (abfd
, section
->filepos
+ offset
, SEEK_SET
) != 0
879 || bfd_bwrite (location
, count
, abfd
) != count
)
890 unsigned int bfd_log2 (bfd_vma x);
893 Return the log base 2 of the value supplied, rounded up. E.g., an
894 @var{x} of 1025 returns 11. A @var{x} of 0 returns 0.
900 unsigned int result
= 0;
902 while ((x
= (x
>> 1)) != 0)
908 bfd_generic_is_local_label_name (bfd
*abfd
, const char *name
)
910 char locals_prefix
= (bfd_get_symbol_leading_char (abfd
) == '_') ? 'L' : '.';
912 return name
[0] == locals_prefix
;
915 /* Can be used from / for bfd_merge_private_bfd_data to check that
916 endianness matches between input and output file. Returns
917 TRUE for a match, otherwise returns FALSE and emits an error. */
919 _bfd_generic_verify_endian_match (bfd
*ibfd
, bfd
*obfd
)
921 if (ibfd
->xvec
->byteorder
!= obfd
->xvec
->byteorder
922 && ibfd
->xvec
->byteorder
!= BFD_ENDIAN_UNKNOWN
923 && obfd
->xvec
->byteorder
!= BFD_ENDIAN_UNKNOWN
)
927 if (bfd_big_endian (ibfd
))
928 msg
= _("%B: compiled for a big endian system and target is little endian");
930 msg
= _("%B: compiled for a little endian system and target is big endian");
932 (*_bfd_error_handler
) (msg
, ibfd
);
934 bfd_set_error (bfd_error_wrong_format
);
941 /* Give a warning at runtime if someone compiles code which calls
945 warn_deprecated (const char *what
,
950 /* Poor man's tracking of functions we've already warned about. */
951 static size_t mask
= 0;
953 if (~(size_t) func
& ~mask
)
955 /* Note: separate sentences in order to allow
956 for translation into other languages. */
958 fprintf (stderr
, _("Deprecated %s called at %s line %d in %s\n"),
959 what
, file
, line
, func
);
961 fprintf (stderr
, _("Deprecated %s called\n"), what
);
962 mask
|= ~(size_t) func
;
966 /* Helper function for reading uleb128 encoded data. */
969 read_unsigned_leb128 (bfd
*abfd ATTRIBUTE_UNUSED
,
971 unsigned int *bytes_read_ptr
)
974 unsigned int num_read
;
983 byte
= bfd_get_8 (abfd
, buf
);
986 result
|= (((bfd_vma
) byte
& 0x7f) << shift
);
990 *bytes_read_ptr
= num_read
;
994 /* Helper function for reading sleb128 encoded data. */
997 read_signed_leb128 (bfd
*abfd ATTRIBUTE_UNUSED
,
999 unsigned int *bytes_read_ptr
)
1003 unsigned int num_read
;
1011 byte
= bfd_get_8 (abfd
, buf
);
1014 result
|= (((bfd_vma
) byte
& 0x7f) << shift
);
1017 while (byte
& 0x80);
1018 if (shift
< 8 * sizeof (result
) && (byte
& 0x40))
1019 result
|= (((bfd_vma
) -1) << shift
);
1020 *bytes_read_ptr
= num_read
;
1025 _bfd_generic_find_line (bfd
*abfd ATTRIBUTE_UNUSED
,
1026 asymbol
**symbols ATTRIBUTE_UNUSED
,
1027 asymbol
*symbol ATTRIBUTE_UNUSED
,
1028 const char **filename_ptr ATTRIBUTE_UNUSED
,
1029 unsigned int *linenumber_ptr ATTRIBUTE_UNUSED
)