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
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_nocore_core_file_matches_executable_p
108 (bfd
*ignore_core_bfd ATTRIBUTE_UNUSED
,
109 bfd
*ignore_exec_bfd ATTRIBUTE_UNUSED
)
111 bfd_set_error (bfd_error_invalid_operation
);
115 /* Routine to handle core_file_failing_command entry point for targets
116 without core file support. */
119 _bfd_nocore_core_file_failing_command (bfd
*ignore_abfd ATTRIBUTE_UNUSED
)
121 bfd_set_error (bfd_error_invalid_operation
);
125 /* Routine to handle core_file_failing_signal entry point for targets
126 without core file support. */
129 _bfd_nocore_core_file_failing_signal (bfd
*ignore_abfd ATTRIBUTE_UNUSED
)
131 bfd_set_error (bfd_error_invalid_operation
);
136 _bfd_dummy_target (bfd
*ignore_abfd ATTRIBUTE_UNUSED
)
138 bfd_set_error (bfd_error_wrong_format
);
142 /* Allocate memory using malloc. */
145 bfd_malloc (bfd_size_type size
)
149 if (size
!= (size_t) size
)
151 bfd_set_error (bfd_error_no_memory
);
155 ptr
= malloc ((size_t) size
);
156 if (ptr
== NULL
&& (size_t) size
!= 0)
157 bfd_set_error (bfd_error_no_memory
);
162 /* Allocate memory using malloc, nmemb * size with overflow checking. */
165 bfd_malloc2 (bfd_size_type nmemb
, bfd_size_type size
)
169 if ((nmemb
| size
) >= HALF_BFD_SIZE_TYPE
171 && nmemb
> ~(bfd_size_type
) 0 / size
)
173 bfd_set_error (bfd_error_no_memory
);
179 if (size
!= (size_t) size
)
181 bfd_set_error (bfd_error_no_memory
);
185 ptr
= malloc ((size_t) size
);
186 if (ptr
== NULL
&& (size_t) size
!= 0)
187 bfd_set_error (bfd_error_no_memory
);
192 /* Reallocate memory using realloc. */
195 bfd_realloc (void *ptr
, bfd_size_type size
)
199 if (size
!= (size_t) size
)
201 bfd_set_error (bfd_error_no_memory
);
206 ret
= malloc ((size_t) size
);
208 ret
= realloc (ptr
, (size_t) size
);
210 if (ret
== NULL
&& (size_t) size
!= 0)
211 bfd_set_error (bfd_error_no_memory
);
216 /* Reallocate memory using realloc, nmemb * size with overflow checking. */
219 bfd_realloc2 (void *ptr
, bfd_size_type nmemb
, bfd_size_type size
)
223 if ((nmemb
| size
) >= HALF_BFD_SIZE_TYPE
225 && nmemb
> ~(bfd_size_type
) 0 / size
)
227 bfd_set_error (bfd_error_no_memory
);
233 if (size
!= (size_t) size
)
235 bfd_set_error (bfd_error_no_memory
);
240 ret
= malloc ((size_t) size
);
242 ret
= realloc (ptr
, (size_t) size
);
244 if (ret
== NULL
&& (size_t) size
!= 0)
245 bfd_set_error (bfd_error_no_memory
);
250 /* Allocate memory using malloc and clear it. */
253 bfd_zmalloc (bfd_size_type size
)
257 if (size
!= (size_t) size
)
259 bfd_set_error (bfd_error_no_memory
);
263 ptr
= malloc ((size_t) size
);
265 if ((size_t) size
!= 0)
268 bfd_set_error (bfd_error_no_memory
);
270 memset (ptr
, 0, (size_t) size
);
276 /* Allocate memory using malloc (nmemb * size) with overflow checking
280 bfd_zmalloc2 (bfd_size_type nmemb
, bfd_size_type size
)
284 if ((nmemb
| size
) >= HALF_BFD_SIZE_TYPE
286 && nmemb
> ~(bfd_size_type
) 0 / size
)
288 bfd_set_error (bfd_error_no_memory
);
294 if (size
!= (size_t) size
)
296 bfd_set_error (bfd_error_no_memory
);
300 ptr
= malloc ((size_t) size
);
302 if ((size_t) size
!= 0)
305 bfd_set_error (bfd_error_no_memory
);
307 memset (ptr
, 0, (size_t) size
);
315 bfd_write_bigendian_4byte_int
318 bfd_boolean bfd_write_bigendian_4byte_int (bfd *, unsigned int);
321 Write a 4 byte integer @var{i} to the output BFD @var{abfd}, in big
322 endian order regardless of what else is going on. This is useful in
327 bfd_write_bigendian_4byte_int (bfd
*abfd
, unsigned int i
)
330 bfd_putb32 ((bfd_vma
) i
, buffer
);
331 return bfd_bwrite (buffer
, (bfd_size_type
) 4, abfd
) == 4;
335 /** The do-it-yourself (byte) sex-change kit */
337 /* The middle letter e.g. get<b>short indicates Big or Little endian
338 target machine. It doesn't matter what the byte order of the host
339 machine is; these routines work for either. */
341 /* FIXME: Should these take a count argument?
342 Answer (gnu@cygnus.com): No, but perhaps they should be inline
343 functions in swap.h #ifdef __GNUC__.
344 Gprof them later and find out. */
353 These macros as used for reading and writing raw data in
354 sections; each access (except for bytes) is vectored through
355 the target format of the BFD and mangled accordingly. The
356 mangling performs any necessary endian translations and
357 removes alignment restrictions. Note that types accepted and
358 returned by these macros are identical so they can be swapped
359 around in macros---for example, @file{libaout.h} defines <<GET_WORD>>
360 to either <<bfd_get_32>> or <<bfd_get_64>>.
362 In the put routines, @var{val} must be a <<bfd_vma>>. If we are on a
363 system without prototypes, the caller is responsible for making
364 sure that is true, with a cast if necessary. We don't cast
365 them in the macro definitions because that would prevent <<lint>>
366 or <<gcc -Wall>> from detecting sins such as passing a pointer.
367 To detect calling these with less than a <<bfd_vma>>, use
368 <<gcc -Wconversion>> on a host with 64 bit <<bfd_vma>>'s.
371 .{* Byte swapping macros for user section data. *}
373 .#define bfd_put_8(abfd, val, ptr) \
374 . ((void) (*((unsigned char *) (ptr)) = (val) & 0xff))
375 .#define bfd_put_signed_8 \
377 .#define bfd_get_8(abfd, ptr) \
378 . (*(unsigned char *) (ptr) & 0xff)
379 .#define bfd_get_signed_8(abfd, ptr) \
380 . (((*(unsigned char *) (ptr) & 0xff) ^ 0x80) - 0x80)
382 .#define bfd_put_16(abfd, val, ptr) \
383 . BFD_SEND (abfd, bfd_putx16, ((val),(ptr)))
384 .#define bfd_put_signed_16 \
386 .#define bfd_get_16(abfd, ptr) \
387 . BFD_SEND (abfd, bfd_getx16, (ptr))
388 .#define bfd_get_signed_16(abfd, ptr) \
389 . BFD_SEND (abfd, bfd_getx_signed_16, (ptr))
391 .#define bfd_put_32(abfd, val, ptr) \
392 . BFD_SEND (abfd, bfd_putx32, ((val),(ptr)))
393 .#define bfd_put_signed_32 \
395 .#define bfd_get_32(abfd, ptr) \
396 . BFD_SEND (abfd, bfd_getx32, (ptr))
397 .#define bfd_get_signed_32(abfd, ptr) \
398 . BFD_SEND (abfd, bfd_getx_signed_32, (ptr))
400 .#define bfd_put_64(abfd, val, ptr) \
401 . BFD_SEND (abfd, bfd_putx64, ((val), (ptr)))
402 .#define bfd_put_signed_64 \
404 .#define bfd_get_64(abfd, ptr) \
405 . BFD_SEND (abfd, bfd_getx64, (ptr))
406 .#define bfd_get_signed_64(abfd, ptr) \
407 . BFD_SEND (abfd, bfd_getx_signed_64, (ptr))
409 .#define bfd_get(bits, abfd, ptr) \
410 . ((bits) == 8 ? (bfd_vma) bfd_get_8 (abfd, ptr) \
411 . : (bits) == 16 ? bfd_get_16 (abfd, ptr) \
412 . : (bits) == 32 ? bfd_get_32 (abfd, ptr) \
413 . : (bits) == 64 ? bfd_get_64 (abfd, ptr) \
414 . : (abort (), (bfd_vma) - 1))
416 .#define bfd_put(bits, abfd, val, ptr) \
417 . ((bits) == 8 ? bfd_put_8 (abfd, val, ptr) \
418 . : (bits) == 16 ? bfd_put_16 (abfd, val, ptr) \
419 . : (bits) == 32 ? bfd_put_32 (abfd, val, ptr) \
420 . : (bits) == 64 ? bfd_put_64 (abfd, val, ptr) \
421 . : (abort (), (void) 0))
431 These macros have the same function as their <<bfd_get_x>>
432 brethren, except that they are used for removing information
433 for the header records of object files. Believe it or not,
434 some object files keep their header records in big endian
435 order and their data in little endian order.
437 .{* Byte swapping macros for file header data. *}
439 .#define bfd_h_put_8(abfd, val, ptr) \
440 . bfd_put_8 (abfd, val, ptr)
441 .#define bfd_h_put_signed_8(abfd, val, ptr) \
442 . bfd_put_8 (abfd, val, ptr)
443 .#define bfd_h_get_8(abfd, ptr) \
444 . bfd_get_8 (abfd, ptr)
445 .#define bfd_h_get_signed_8(abfd, ptr) \
446 . bfd_get_signed_8 (abfd, ptr)
448 .#define bfd_h_put_16(abfd, val, ptr) \
449 . BFD_SEND (abfd, bfd_h_putx16, (val, ptr))
450 .#define bfd_h_put_signed_16 \
452 .#define bfd_h_get_16(abfd, ptr) \
453 . BFD_SEND (abfd, bfd_h_getx16, (ptr))
454 .#define bfd_h_get_signed_16(abfd, ptr) \
455 . BFD_SEND (abfd, bfd_h_getx_signed_16, (ptr))
457 .#define bfd_h_put_32(abfd, val, ptr) \
458 . BFD_SEND (abfd, bfd_h_putx32, (val, ptr))
459 .#define bfd_h_put_signed_32 \
461 .#define bfd_h_get_32(abfd, ptr) \
462 . BFD_SEND (abfd, bfd_h_getx32, (ptr))
463 .#define bfd_h_get_signed_32(abfd, ptr) \
464 . BFD_SEND (abfd, bfd_h_getx_signed_32, (ptr))
466 .#define bfd_h_put_64(abfd, val, ptr) \
467 . BFD_SEND (abfd, bfd_h_putx64, (val, ptr))
468 .#define bfd_h_put_signed_64 \
470 .#define bfd_h_get_64(abfd, ptr) \
471 . BFD_SEND (abfd, bfd_h_getx64, (ptr))
472 .#define bfd_h_get_signed_64(abfd, ptr) \
473 . BFD_SEND (abfd, bfd_h_getx_signed_64, (ptr))
475 .{* Aliases for the above, which should eventually go away. *}
477 .#define H_PUT_64 bfd_h_put_64
478 .#define H_PUT_32 bfd_h_put_32
479 .#define H_PUT_16 bfd_h_put_16
480 .#define H_PUT_8 bfd_h_put_8
481 .#define H_PUT_S64 bfd_h_put_signed_64
482 .#define H_PUT_S32 bfd_h_put_signed_32
483 .#define H_PUT_S16 bfd_h_put_signed_16
484 .#define H_PUT_S8 bfd_h_put_signed_8
485 .#define H_GET_64 bfd_h_get_64
486 .#define H_GET_32 bfd_h_get_32
487 .#define H_GET_16 bfd_h_get_16
488 .#define H_GET_8 bfd_h_get_8
489 .#define H_GET_S64 bfd_h_get_signed_64
490 .#define H_GET_S32 bfd_h_get_signed_32
491 .#define H_GET_S16 bfd_h_get_signed_16
492 .#define H_GET_S8 bfd_h_get_signed_8
496 /* Sign extension to bfd_signed_vma. */
497 #define COERCE16(x) (((bfd_signed_vma) (x) ^ 0x8000) - 0x8000)
498 #define COERCE32(x) (((bfd_signed_vma) (x) ^ 0x80000000) - 0x80000000)
499 #define EIGHT_GAZILLION ((bfd_int64_t) 1 << 63)
500 #define COERCE64(x) \
501 (((bfd_int64_t) (x) ^ EIGHT_GAZILLION) - EIGHT_GAZILLION)
504 bfd_getb16 (const void *p
)
506 const bfd_byte
*addr
= p
;
507 return (addr
[0] << 8) | addr
[1];
511 bfd_getl16 (const void *p
)
513 const bfd_byte
*addr
= p
;
514 return (addr
[1] << 8) | addr
[0];
518 bfd_getb_signed_16 (const void *p
)
520 const bfd_byte
*addr
= p
;
521 return COERCE16 ((addr
[0] << 8) | addr
[1]);
525 bfd_getl_signed_16 (const void *p
)
527 const bfd_byte
*addr
= p
;
528 return COERCE16 ((addr
[1] << 8) | addr
[0]);
532 bfd_putb16 (bfd_vma data
, void *p
)
535 addr
[0] = (data
>> 8) & 0xff;
536 addr
[1] = data
& 0xff;
540 bfd_putl16 (bfd_vma data
, void *p
)
543 addr
[0] = data
& 0xff;
544 addr
[1] = (data
>> 8) & 0xff;
548 bfd_getb32 (const void *p
)
550 const bfd_byte
*addr
= p
;
553 v
= (unsigned long) addr
[0] << 24;
554 v
|= (unsigned long) addr
[1] << 16;
555 v
|= (unsigned long) addr
[2] << 8;
556 v
|= (unsigned long) addr
[3];
561 bfd_getl32 (const void *p
)
563 const bfd_byte
*addr
= p
;
566 v
= (unsigned long) addr
[0];
567 v
|= (unsigned long) addr
[1] << 8;
568 v
|= (unsigned long) addr
[2] << 16;
569 v
|= (unsigned long) addr
[3] << 24;
574 bfd_getb_signed_32 (const void *p
)
576 const bfd_byte
*addr
= p
;
579 v
= (unsigned long) addr
[0] << 24;
580 v
|= (unsigned long) addr
[1] << 16;
581 v
|= (unsigned long) addr
[2] << 8;
582 v
|= (unsigned long) addr
[3];
587 bfd_getl_signed_32 (const void *p
)
589 const bfd_byte
*addr
= p
;
592 v
= (unsigned long) addr
[0];
593 v
|= (unsigned long) addr
[1] << 8;
594 v
|= (unsigned long) addr
[2] << 16;
595 v
|= (unsigned long) addr
[3] << 24;
600 bfd_getb64 (const void *p ATTRIBUTE_UNUSED
)
602 #ifdef BFD_HOST_64_BIT
603 const bfd_byte
*addr
= p
;
606 v
= addr
[0]; v
<<= 8;
607 v
|= addr
[1]; v
<<= 8;
608 v
|= addr
[2]; v
<<= 8;
609 v
|= addr
[3]; v
<<= 8;
610 v
|= addr
[4]; v
<<= 8;
611 v
|= addr
[5]; v
<<= 8;
612 v
|= addr
[6]; v
<<= 8;
623 bfd_getl64 (const void *p ATTRIBUTE_UNUSED
)
625 #ifdef BFD_HOST_64_BIT
626 const bfd_byte
*addr
= p
;
629 v
= addr
[7]; v
<<= 8;
630 v
|= addr
[6]; v
<<= 8;
631 v
|= addr
[5]; v
<<= 8;
632 v
|= addr
[4]; v
<<= 8;
633 v
|= addr
[3]; v
<<= 8;
634 v
|= addr
[2]; v
<<= 8;
635 v
|= addr
[1]; v
<<= 8;
647 bfd_getb_signed_64 (const void *p ATTRIBUTE_UNUSED
)
649 #ifdef BFD_HOST_64_BIT
650 const bfd_byte
*addr
= p
;
653 v
= addr
[0]; v
<<= 8;
654 v
|= addr
[1]; v
<<= 8;
655 v
|= addr
[2]; v
<<= 8;
656 v
|= addr
[3]; v
<<= 8;
657 v
|= addr
[4]; v
<<= 8;
658 v
|= addr
[5]; v
<<= 8;
659 v
|= addr
[6]; v
<<= 8;
670 bfd_getl_signed_64 (const void *p ATTRIBUTE_UNUSED
)
672 #ifdef BFD_HOST_64_BIT
673 const bfd_byte
*addr
= p
;
676 v
= addr
[7]; v
<<= 8;
677 v
|= addr
[6]; v
<<= 8;
678 v
|= addr
[5]; v
<<= 8;
679 v
|= addr
[4]; v
<<= 8;
680 v
|= addr
[3]; v
<<= 8;
681 v
|= addr
[2]; v
<<= 8;
682 v
|= addr
[1]; v
<<= 8;
693 bfd_putb32 (bfd_vma data
, void *p
)
696 addr
[0] = (data
>> 24) & 0xff;
697 addr
[1] = (data
>> 16) & 0xff;
698 addr
[2] = (data
>> 8) & 0xff;
699 addr
[3] = data
& 0xff;
703 bfd_putl32 (bfd_vma data
, void *p
)
706 addr
[0] = data
& 0xff;
707 addr
[1] = (data
>> 8) & 0xff;
708 addr
[2] = (data
>> 16) & 0xff;
709 addr
[3] = (data
>> 24) & 0xff;
713 bfd_putb64 (bfd_uint64_t data ATTRIBUTE_UNUSED
, void *p ATTRIBUTE_UNUSED
)
715 #ifdef BFD_HOST_64_BIT
717 addr
[0] = (data
>> (7*8)) & 0xff;
718 addr
[1] = (data
>> (6*8)) & 0xff;
719 addr
[2] = (data
>> (5*8)) & 0xff;
720 addr
[3] = (data
>> (4*8)) & 0xff;
721 addr
[4] = (data
>> (3*8)) & 0xff;
722 addr
[5] = (data
>> (2*8)) & 0xff;
723 addr
[6] = (data
>> (1*8)) & 0xff;
724 addr
[7] = (data
>> (0*8)) & 0xff;
731 bfd_putl64 (bfd_uint64_t data ATTRIBUTE_UNUSED
, void *p ATTRIBUTE_UNUSED
)
733 #ifdef BFD_HOST_64_BIT
735 addr
[7] = (data
>> (7*8)) & 0xff;
736 addr
[6] = (data
>> (6*8)) & 0xff;
737 addr
[5] = (data
>> (5*8)) & 0xff;
738 addr
[4] = (data
>> (4*8)) & 0xff;
739 addr
[3] = (data
>> (3*8)) & 0xff;
740 addr
[2] = (data
>> (2*8)) & 0xff;
741 addr
[1] = (data
>> (1*8)) & 0xff;
742 addr
[0] = (data
>> (0*8)) & 0xff;
749 bfd_put_bits (bfd_uint64_t data
, void *p
, int bits
, bfd_boolean big_p
)
759 for (i
= 0; i
< bytes
; i
++)
761 int index
= big_p
? bytes
- i
- 1 : i
;
763 addr
[index
] = data
& 0xff;
769 bfd_get_bits (const void *p
, int bits
, bfd_boolean big_p
)
771 const bfd_byte
*addr
= p
;
781 for (i
= 0; i
< bytes
; i
++)
783 int index
= big_p
? i
: bytes
- i
- 1;
785 data
= (data
<< 8) | addr
[index
];
791 /* Default implementation */
794 _bfd_generic_get_section_contents (bfd
*abfd
,
804 sz
= section
->rawsize
? section
->rawsize
: section
->size
;
805 if (offset
+ count
> sz
)
807 bfd_set_error (bfd_error_invalid_operation
);
811 if (bfd_seek (abfd
, section
->filepos
+ offset
, SEEK_SET
) != 0
812 || bfd_bread (location
, count
, abfd
) != count
)
819 _bfd_generic_get_section_contents_in_window
820 (bfd
*abfd ATTRIBUTE_UNUSED
,
821 sec_ptr section ATTRIBUTE_UNUSED
,
822 bfd_window
*w ATTRIBUTE_UNUSED
,
823 file_ptr offset ATTRIBUTE_UNUSED
,
824 bfd_size_type count ATTRIBUTE_UNUSED
)
831 if (abfd
->xvec
->_bfd_get_section_contents
832 != _bfd_generic_get_section_contents
)
834 /* We don't know what changes the bfd's get_section_contents
835 method may have to make. So punt trying to map the file
836 window, and let get_section_contents do its thing. */
837 /* @@ FIXME : If the internal window has a refcount of 1 and was
838 allocated with malloc instead of mmap, just reuse it. */
840 w
->i
= bfd_zmalloc (sizeof (bfd_window_internal
));
843 w
->i
->data
= bfd_malloc (count
);
844 if (w
->i
->data
== NULL
)
852 w
->size
= w
->i
->size
= count
;
853 w
->data
= w
->i
->data
;
854 return bfd_get_section_contents (abfd
, section
, w
->data
, offset
, count
);
856 sz
= section
->rawsize
? section
->rawsize
: section
->size
;
857 if (offset
+ count
> sz
858 || ! bfd_get_file_window (abfd
, section
->filepos
+ offset
, count
, w
,
867 /* This generic function can only be used in implementations where creating
868 NEW sections is disallowed. It is useful in patching existing sections
869 in read-write files, though. See other set_section_contents functions
870 to see why it doesn't work for new sections. */
872 _bfd_generic_set_section_contents (bfd
*abfd
,
874 const void *location
,
881 if (bfd_seek (abfd
, section
->filepos
+ offset
, SEEK_SET
) != 0
882 || bfd_bwrite (location
, count
, abfd
) != count
)
893 unsigned int bfd_log2 (bfd_vma x);
896 Return the log base 2 of the value supplied, rounded up. E.g., an
897 @var{x} of 1025 returns 11. A @var{x} of 0 returns 0.
903 unsigned int result
= 0;
905 while ((x
= (x
>> 1)) != 0)
911 bfd_generic_is_local_label_name (bfd
*abfd
, const char *name
)
913 char locals_prefix
= (bfd_get_symbol_leading_char (abfd
) == '_') ? 'L' : '.';
915 return name
[0] == locals_prefix
;
918 /* Can be used from / for bfd_merge_private_bfd_data to check that
919 endianness matches between input and output file. Returns
920 TRUE for a match, otherwise returns FALSE and emits an error. */
922 _bfd_generic_verify_endian_match (bfd
*ibfd
, bfd
*obfd
)
924 if (ibfd
->xvec
->byteorder
!= obfd
->xvec
->byteorder
925 && ibfd
->xvec
->byteorder
!= BFD_ENDIAN_UNKNOWN
926 && obfd
->xvec
->byteorder
!= BFD_ENDIAN_UNKNOWN
)
930 if (bfd_big_endian (ibfd
))
931 msg
= _("%B: compiled for a big endian system and target is little endian");
933 msg
= _("%B: compiled for a little endian system and target is big endian");
935 (*_bfd_error_handler
) (msg
, ibfd
);
937 bfd_set_error (bfd_error_wrong_format
);
944 /* Give a warning at runtime if someone compiles code which calls
948 warn_deprecated (const char *what
,
953 /* Poor man's tracking of functions we've already warned about. */
954 static size_t mask
= 0;
956 if (~(size_t) func
& ~mask
)
958 /* Note: separate sentences in order to allow
959 for translation into other languages. */
961 fprintf (stderr
, _("Deprecated %s called at %s line %d in %s\n"),
962 what
, file
, line
, func
);
964 fprintf (stderr
, _("Deprecated %s called\n"), what
);
965 mask
|= ~(size_t) func
;
969 /* Helper function for reading uleb128 encoded data. */
972 read_unsigned_leb128 (bfd
*abfd ATTRIBUTE_UNUSED
,
974 unsigned int *bytes_read_ptr
)
977 unsigned int num_read
;
986 byte
= bfd_get_8 (abfd
, buf
);
989 result
|= (((bfd_vma
) byte
& 0x7f) << shift
);
993 *bytes_read_ptr
= num_read
;
997 /* Helper function for reading sleb128 encoded data. */
1000 read_signed_leb128 (bfd
*abfd ATTRIBUTE_UNUSED
,
1002 unsigned int *bytes_read_ptr
)
1006 unsigned int num_read
;
1014 byte
= bfd_get_8 (abfd
, buf
);
1017 result
|= (((bfd_vma
) byte
& 0x7f) << shift
);
1020 while (byte
& 0x80);
1021 if (shift
< 8 * sizeof (result
) && (byte
& 0x40))
1022 result
|= (((bfd_vma
) -1) << shift
);
1023 *bytes_read_ptr
= num_read
;
1028 _bfd_generic_find_line (bfd
*abfd ATTRIBUTE_UNUSED
,
1029 asymbol
**symbols ATTRIBUTE_UNUSED
,
1030 asymbol
*symbol ATTRIBUTE_UNUSED
,
1031 const char **filename_ptr ATTRIBUTE_UNUSED
,
1032 unsigned int *linenumber_ptr ATTRIBUTE_UNUSED
)
1038 _bfd_generic_init_private_section_data (bfd
*ibfd ATTRIBUTE_UNUSED
,
1039 asection
*isec ATTRIBUTE_UNUSED
,
1040 bfd
*obfd ATTRIBUTE_UNUSED
,
1041 asection
*osec ATTRIBUTE_UNUSED
,
1042 struct bfd_link_info
*link_info ATTRIBUTE_UNUSED
)