1 /* Assorted BFD support routines, only used internally.
2 Copyright 1990, 91, 92, 93, 94, 95, 96, 97, 1998
3 Free Software Foundation, Inc.
4 Written by Cygnus Support.
6 This file is part of BFD, the Binary File Descriptor library.
8 This program is free software; you can redistribute it and/or modify
9 it under the terms of the GNU General Public License as published by
10 the Free Software Foundation; either version 2 of the License, or
11 (at your option) any later version.
13 This program is distributed in the hope that it will be useful,
14 but WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 GNU General Public License for more details.
18 You should have received a copy of the GNU General Public License
19 along with this program; if not, write to the Free Software
20 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */
26 #ifndef HAVE_GETPAGESIZE
27 #define getpagesize() 2048
30 static int real_read
PARAMS ((PTR
, size_t, size_t, FILE *));
37 These routines are used within BFD.
38 They are not intended for export, but are documented here for
42 /* A routine which is used in target vectors for unsupported
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. */
65 /* A routine which is used in target vectors for unsupported
66 operations which return a pointer value. */
70 bfd_nullvoidptr (ignore
)
73 bfd_set_error (bfd_error_invalid_operation
);
101 /* A routine which is used in target vectors for unsupported
102 operations which return -1 on error. */
106 _bfd_n1 (ignore_abfd
)
109 bfd_set_error (bfd_error_invalid_operation
);
122 _bfd_nocore_core_file_matches_executable_p (ignore_core_bfd
, ignore_exec_bfd
)
123 bfd
*ignore_core_bfd
;
124 bfd
*ignore_exec_bfd
;
126 bfd_set_error (bfd_error_invalid_operation
);
130 /* Routine to handle core_file_failing_command entry point for targets
131 without core file support. */
135 _bfd_nocore_core_file_failing_command (ignore_abfd
)
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. */
147 _bfd_nocore_core_file_failing_signal (ignore_abfd
)
150 bfd_set_error (bfd_error_invalid_operation
);
156 _bfd_dummy_target (ignore_abfd
)
159 bfd_set_error (bfd_error_wrong_format
);
163 /* Allocate memory using malloc. */
171 ptr
= (PTR
) malloc (size
);
172 if (ptr
== NULL
&& size
!= 0)
173 bfd_set_error (bfd_error_no_memory
);
177 /* Reallocate memory using realloc. */
180 bfd_realloc (ptr
, size
)
189 ret
= realloc (ptr
, size
);
192 bfd_set_error (bfd_error_no_memory
);
197 /* Allocate memory using malloc and clear it. */
205 ptr
= (PTR
) malloc (size
);
210 bfd_set_error (bfd_error_no_memory
);
212 memset (ptr
, 0, size
);
221 /* Note that archive entries don't have streams; they share their parent's.
222 This allows someone to play with the iostream behind BFD's back.
224 Also, note that the origin pointer points to the beginning of a file's
225 contents (0 for non-archive elements). For archive entries this is the
226 first octet in the file, NOT the beginning of the archive header. */
229 real_read (where
, a
,b
, file
)
235 #if defined (__VAX) && defined (VMS)
236 /* Apparently fread on Vax VMS does not keep the record length
238 return read (fileno (file
), where
, a
* b
);
240 return fread (where
, a
, b
, file
);
244 /* Return value is amount read (FIXME: how are errors and end of file dealt
245 with? We never call bfd_set_error, which is probably a mistake). */
248 bfd_read (ptr
, size
, nitems
, abfd
)
251 bfd_size_type nitems
;
256 if ((abfd
->flags
& BFD_IN_MEMORY
) != 0)
258 struct bfd_in_memory
*bim
;
261 bim
= (struct bfd_in_memory
*) abfd
->iostream
;
263 if (abfd
->where
+ get
> bim
->size
)
265 get
= bim
->size
- abfd
->where
;
266 bfd_set_error (bfd_error_file_truncated
);
268 memcpy (ptr
, bim
->buffer
+ abfd
->where
, get
);
273 nread
= real_read (ptr
, 1, (size_t)(size
*nitems
), bfd_cache_lookup(abfd
));
275 abfd
->where
+= nread
;
277 /* Set bfd_error if we did not read as much data as we expected.
279 If the read failed due to an error set the bfd_error_system_call,
280 else set bfd_error_file_truncated.
282 A BFD backend may wish to override bfd_error_file_truncated to
283 provide something more useful (eg. no_symbols or wrong_format). */
284 if (nread
< (int)(size
* nitems
))
286 if (ferror (bfd_cache_lookup (abfd
)))
287 bfd_set_error (bfd_error_system_call
);
289 bfd_set_error (bfd_error_file_truncated
);
295 /* The window support stuff should probably be broken out into
297 /* The idea behind the next and refcount fields is that one mapped
298 region can suffice for multiple read-only windows or multiple
299 non-overlapping read-write windows. It's not implemented yet
301 struct _bfd_window_internal
{
302 struct _bfd_window_internal
*next
;
305 int refcount
: 31; /* should be enough... */
306 unsigned mapped
: 1; /* 1 = mmap, 0 = malloc */
310 bfd_init_window (windowp
)
318 /* Currently, if USE_MMAP is undefined, none if the window stuff is
319 used. Okay, so it's mis-named. At least the command-line option
320 "--without-mmap" is more obvious than "--without-windows" or some
324 #undef HAVE_MPROTECT /* code's not tested yet */
326 #if HAVE_MMAP || HAVE_MPROTECT || HAVE_MADVISE
327 #include <sys/mman.h>
334 static int debug_windows
;
337 bfd_free_window (windowp
)
340 bfd_window_internal
*i
= windowp
->i
;
347 fprintf (stderr
, "freeing window @%p<%p,%lx,%p>\n",
348 windowp
, windowp
->data
, windowp
->size
, windowp
->i
);
349 if (i
->refcount
!= 0)
355 munmap (i
->data
, i
->size
);
362 mprotect (i
->data
, i
->size
, PROT_READ
| PROT_WRITE
);
369 /* There should be no more references to i at this point. */
373 static int ok_to_map
= 1;
376 bfd_get_file_window (abfd
, offset
, size
, windowp
, writable
)
383 static size_t pagesize
;
384 bfd_window_internal
*i
= windowp
->i
;
385 size_t size_to_alloc
= size
;
388 fprintf (stderr
, "bfd_get_file_window (%p, %6ld, %6ld, %p<%p,%lx,%p>, %d)",
389 abfd
, (long) offset
, (long) size
,
390 windowp
, windowp
->data
, (unsigned long) windowp
->size
,
391 windowp
->i
, writable
);
393 /* Make sure we know the page size, so we can be friendly to mmap. */
395 pagesize
= getpagesize ();
401 windowp
->i
= i
= (bfd_window_internal
*) bfd_zmalloc (sizeof (bfd_window_internal
));
408 && (i
->data
== 0 || i
->mapped
== 1)
409 && (abfd
->flags
& BFD_IN_MEMORY
) == 0)
411 file_ptr file_offset
, offset2
;
416 /* Find the real file and the real offset into it. */
417 while (abfd
->my_archive
!= NULL
)
419 offset
+= abfd
->origin
;
420 abfd
= abfd
->my_archive
;
422 f
= bfd_cache_lookup (abfd
);
425 /* Compute offsets and size for mmap and for the user's data. */
426 offset2
= offset
% pagesize
;
429 file_offset
= offset
- offset2
;
430 real_size
= offset
+ size
- file_offset
;
431 real_size
= real_size
+ pagesize
- 1;
432 real_size
-= real_size
% pagesize
;
434 /* If we're re-using a memory region, make sure it's big enough. */
435 if (i
->data
&& i
->size
< size
)
437 munmap (i
->data
, i
->size
);
440 i
->data
= mmap (i
->data
, real_size
,
441 writable
? PROT_WRITE
| PROT_READ
: PROT_READ
,
443 ? MAP_FILE
| MAP_PRIVATE
444 : MAP_FILE
| MAP_SHARED
),
446 if (i
->data
== (PTR
) -1)
448 /* An error happened. Report it, or try using malloc, or
450 bfd_set_error (bfd_error_system_call
);
454 fprintf (stderr
, "\t\tmmap failed!\n");
458 fprintf (stderr
, "\n\tmapped %ld at %p, offset is %ld\n",
459 (long) real_size
, i
->data
, (long) offset2
);
461 windowp
->data
= (PTR
) ((bfd_byte
*) i
->data
+ offset2
);
462 windowp
->size
= size
;
466 else if (debug_windows
)
469 fprintf (stderr
, _("not mapping: data=%lx mapped=%d\n"),
470 (unsigned long) i
->data
, (int) i
->mapped
);
472 fprintf (stderr
, _("not mapping: env var not set\n"));
481 size_to_alloc
+= pagesize
- 1;
482 size_to_alloc
-= size_to_alloc
% pagesize
;
486 fprintf (stderr
, "\n\t%s(%6ld)",
487 i
->data
? "realloc" : " malloc", (long) size_to_alloc
);
488 i
->data
= (PTR
) bfd_realloc (i
->data
, size_to_alloc
);
490 fprintf (stderr
, "\t-> %p\n", i
->data
);
494 if (size_to_alloc
== 0)
496 bfd_set_error (bfd_error_no_memory
);
499 if (bfd_seek (abfd
, offset
, SEEK_SET
) != 0)
501 i
->size
= bfd_read (i
->data
, size
, 1, abfd
);
509 fprintf (stderr
, "\tmprotect (%p, %ld, PROT_READ)\n", i
->data
,
511 mprotect (i
->data
, i
->size
, PROT_READ
);
514 windowp
->data
= i
->data
;
515 windowp
->size
= i
->size
;
519 #endif /* USE_MMAP */
522 bfd_write (ptr
, size
, nitems
, abfd
)
525 bfd_size_type nitems
;
530 if ((abfd
->flags
& BFD_IN_MEMORY
) != 0)
533 nwrote
= fwrite (ptr
, 1, (size_t) (size
* nitems
),
534 bfd_cache_lookup (abfd
));
536 abfd
->where
+= nwrote
;
537 if ((bfd_size_type
) nwrote
!= size
* nitems
)
543 bfd_set_error (bfd_error_system_call
);
550 bfd_write_bigendian_4byte_int
553 void bfd_write_bigendian_4byte_int(bfd *abfd, int i);
556 Write a 4 byte integer @var{i} to the output BFD @var{abfd}, in big
557 endian order regardless of what else is going on. This is useful in
562 bfd_write_bigendian_4byte_int (abfd
, i
)
567 bfd_putb32(i
, buffer
);
568 if (bfd_write((PTR
)buffer
, 4, 1, abfd
) != 4)
578 if ((abfd
->flags
& BFD_IN_MEMORY
) != 0)
581 ptr
= ftell (bfd_cache_lookup(abfd
));
583 if (abfd
->my_archive
)
593 if ((abfd
->flags
& BFD_IN_MEMORY
) != 0)
595 return fflush (bfd_cache_lookup(abfd
));
598 /* Returns 0 for success, negative value for failure (in which case
599 bfd_get_error can retrieve the error code). */
601 bfd_stat (abfd
, statbuf
)
603 struct stat
*statbuf
;
608 if ((abfd
->flags
& BFD_IN_MEMORY
) != 0)
611 f
= bfd_cache_lookup (abfd
);
614 bfd_set_error (bfd_error_system_call
);
617 result
= fstat (fileno (f
), statbuf
);
619 bfd_set_error (bfd_error_system_call
);
623 /* Returns 0 for success, nonzero for failure (in which case bfd_get_error
624 can retrieve the error code). */
627 bfd_seek (abfd
, position
, direction
)
634 file_ptr file_position
;
635 /* For the time being, a BFD may not seek to it's end. The problem
636 is that we don't easily have a way to recognize the end of an
637 element in an archive. */
639 BFD_ASSERT (direction
== SEEK_SET
|| direction
== SEEK_CUR
);
641 if (direction
== SEEK_CUR
&& position
== 0)
644 if ((abfd
->flags
& BFD_IN_MEMORY
) != 0)
646 if (direction
== SEEK_SET
)
647 abfd
->where
= position
;
649 abfd
->where
+= position
;
653 if (abfd
->format
!= bfd_archive
&& abfd
->my_archive
== 0)
656 /* Explanation for this code: I'm only about 95+% sure that the above
657 conditions are sufficient and that all i/o calls are properly
658 adjusting the `where' field. So this is sort of an `assert'
659 that the `where' field is correct. If we can go a while without
660 tripping the abort, we can probably safely disable this code,
661 so that the real optimizations happen. */
662 file_ptr where_am_i_now
;
663 where_am_i_now
= ftell (bfd_cache_lookup (abfd
));
664 if (abfd
->my_archive
)
665 where_am_i_now
-= abfd
->origin
;
666 if (where_am_i_now
!= abfd
->where
)
669 if (direction
== SEEK_SET
&& position
== abfd
->where
)
674 /* We need something smarter to optimize access to archives.
675 Currently, anything inside an archive is read via the file
676 handle for the archive. Which means that a bfd_seek on one
677 component affects the `current position' in the archive, as
678 well as in any other component.
680 It might be sufficient to put a spike through the cache
681 abstraction, and look to the archive for the file position,
682 but I think we should try for something cleaner.
684 In the meantime, no optimization for archives. */
687 f
= bfd_cache_lookup (abfd
);
688 file_position
= position
;
689 if (direction
== SEEK_SET
&& abfd
->my_archive
!= NULL
)
690 file_position
+= abfd
->origin
;
692 result
= fseek (f
, file_position
, direction
);
696 int hold_errno
= errno
;
698 /* Force redetermination of `where' field. */
701 /* An EINVAL error probably means that the file offset was
703 if (hold_errno
== EINVAL
)
704 bfd_set_error (bfd_error_file_truncated
);
707 bfd_set_error (bfd_error_system_call
);
713 /* Adjust `where' field. */
714 if (direction
== SEEK_SET
)
715 abfd
->where
= position
;
717 abfd
->where
+= position
;
722 /** The do-it-yourself (byte) sex-change kit */
724 /* The middle letter e.g. get<b>short indicates Big or Little endian
725 target machine. It doesn't matter what the byte order of the host
726 machine is; these routines work for either. */
728 /* FIXME: Should these take a count argument?
729 Answer (gnu@cygnus.com): No, but perhaps they should be inline
730 functions in swap.h #ifdef __GNUC__.
731 Gprof them later and find out. */
740 These macros as used for reading and writing raw data in
741 sections; each access (except for bytes) is vectored through
742 the target format of the BFD and mangled accordingly. The
743 mangling performs any necessary endian translations and
744 removes alignment restrictions. Note that types accepted and
745 returned by these macros are identical so they can be swapped
746 around in macros---for example, @file{libaout.h} defines <<GET_WORD>>
747 to either <<bfd_get_32>> or <<bfd_get_64>>.
749 In the put routines, @var{val} must be a <<bfd_vma>>. If we are on a
750 system without prototypes, the caller is responsible for making
751 sure that is true, with a cast if necessary. We don't cast
752 them in the macro definitions because that would prevent <<lint>>
753 or <<gcc -Wall>> from detecting sins such as passing a pointer.
754 To detect calling these with less than a <<bfd_vma>>, use
755 <<gcc -Wconversion>> on a host with 64 bit <<bfd_vma>>'s.
758 .{* Byte swapping macros for user section data. *}
760 .#define bfd_put_8(abfd, val, ptr) \
761 . (*((unsigned char *)(ptr)) = (unsigned char)(val))
762 .#define bfd_put_signed_8 \
764 .#define bfd_get_8(abfd, ptr) \
765 . (*(unsigned char *)(ptr))
766 .#define bfd_get_signed_8(abfd, ptr) \
767 . ((*(unsigned char *)(ptr) ^ 0x80) - 0x80)
769 .#define bfd_put_16(abfd, val, ptr) \
770 . BFD_SEND(abfd, bfd_putx16, ((val),(ptr)))
771 .#define bfd_put_signed_16 \
773 .#define bfd_get_16(abfd, ptr) \
774 . BFD_SEND(abfd, bfd_getx16, (ptr))
775 .#define bfd_get_signed_16(abfd, ptr) \
776 . BFD_SEND (abfd, bfd_getx_signed_16, (ptr))
778 .#define bfd_put_32(abfd, val, ptr) \
779 . BFD_SEND(abfd, bfd_putx32, ((val),(ptr)))
780 .#define bfd_put_signed_32 \
782 .#define bfd_get_32(abfd, ptr) \
783 . BFD_SEND(abfd, bfd_getx32, (ptr))
784 .#define bfd_get_signed_32(abfd, ptr) \
785 . BFD_SEND(abfd, bfd_getx_signed_32, (ptr))
787 .#define bfd_put_64(abfd, val, ptr) \
788 . BFD_SEND(abfd, bfd_putx64, ((val), (ptr)))
789 .#define bfd_put_signed_64 \
791 .#define bfd_get_64(abfd, ptr) \
792 . BFD_SEND(abfd, bfd_getx64, (ptr))
793 .#define bfd_get_signed_64(abfd, ptr) \
794 . BFD_SEND(abfd, bfd_getx_signed_64, (ptr))
804 These macros have the same function as their <<bfd_get_x>>
805 bretheren, except that they are used for removing information
806 for the header records of object files. Believe it or not,
807 some object files keep their header records in big endian
808 order and their data in little endian order.
810 .{* Byte swapping macros for file header data. *}
812 .#define bfd_h_put_8(abfd, val, ptr) \
813 . bfd_put_8 (abfd, val, ptr)
814 .#define bfd_h_put_signed_8(abfd, val, ptr) \
815 . bfd_put_8 (abfd, val, ptr)
816 .#define bfd_h_get_8(abfd, ptr) \
817 . bfd_get_8 (abfd, ptr)
818 .#define bfd_h_get_signed_8(abfd, ptr) \
819 . bfd_get_signed_8 (abfd, ptr)
821 .#define bfd_h_put_16(abfd, val, ptr) \
822 . BFD_SEND(abfd, bfd_h_putx16,(val,ptr))
823 .#define bfd_h_put_signed_16 \
825 .#define bfd_h_get_16(abfd, ptr) \
826 . BFD_SEND(abfd, bfd_h_getx16,(ptr))
827 .#define bfd_h_get_signed_16(abfd, ptr) \
828 . BFD_SEND(abfd, bfd_h_getx_signed_16, (ptr))
830 .#define bfd_h_put_32(abfd, val, ptr) \
831 . BFD_SEND(abfd, bfd_h_putx32,(val,ptr))
832 .#define bfd_h_put_signed_32 \
834 .#define bfd_h_get_32(abfd, ptr) \
835 . BFD_SEND(abfd, bfd_h_getx32,(ptr))
836 .#define bfd_h_get_signed_32(abfd, ptr) \
837 . BFD_SEND(abfd, bfd_h_getx_signed_32, (ptr))
839 .#define bfd_h_put_64(abfd, val, ptr) \
840 . BFD_SEND(abfd, bfd_h_putx64,(val, ptr))
841 .#define bfd_h_put_signed_64 \
843 .#define bfd_h_get_64(abfd, ptr) \
844 . BFD_SEND(abfd, bfd_h_getx64,(ptr))
845 .#define bfd_h_get_signed_64(abfd, ptr) \
846 . BFD_SEND(abfd, bfd_h_getx_signed_64, (ptr))
850 /* Sign extension to bfd_signed_vma. */
851 #define COERCE16(x) (((bfd_signed_vma) (x) ^ 0x8000) - 0x8000)
852 #define COERCE32(x) (((bfd_signed_vma) (x) ^ 0x80000000) - 0x80000000)
853 #define EIGHT_GAZILLION (((BFD_HOST_64_BIT)0x80000000) << 32)
854 #define COERCE64(x) \
855 (((bfd_signed_vma) (x) ^ EIGHT_GAZILLION) - EIGHT_GAZILLION)
859 register const bfd_byte
*addr
;
861 return (addr
[0] << 8) | addr
[1];
866 register const bfd_byte
*addr
;
868 return (addr
[1] << 8) | addr
[0];
872 bfd_getb_signed_16 (addr
)
873 register const bfd_byte
*addr
;
875 return COERCE16((addr
[0] << 8) | addr
[1]);
879 bfd_getl_signed_16 (addr
)
880 register const bfd_byte
*addr
;
882 return COERCE16((addr
[1] << 8) | addr
[0]);
886 bfd_putb16 (data
, addr
)
888 register bfd_byte
*addr
;
890 addr
[0] = (bfd_byte
)(data
>> 8);
891 addr
[1] = (bfd_byte
)data
;
895 bfd_putl16 (data
, addr
)
897 register bfd_byte
*addr
;
899 addr
[0] = (bfd_byte
)data
;
900 addr
[1] = (bfd_byte
)(data
>> 8);
905 register const bfd_byte
*addr
;
907 return (((((bfd_vma
)addr
[0] << 8) | addr
[1]) << 8)
908 | addr
[2]) << 8 | addr
[3];
913 register const bfd_byte
*addr
;
915 return (((((bfd_vma
)addr
[3] << 8) | addr
[2]) << 8)
916 | addr
[1]) << 8 | addr
[0];
920 bfd_getb_signed_32 (addr
)
921 register const bfd_byte
*addr
;
923 return COERCE32((((((bfd_vma
)addr
[0] << 8) | addr
[1]) << 8)
924 | addr
[2]) << 8 | addr
[3]);
928 bfd_getl_signed_32 (addr
)
929 register const bfd_byte
*addr
;
931 return COERCE32((((((bfd_vma
)addr
[3] << 8) | addr
[2]) << 8)
932 | addr
[1]) << 8 | addr
[0]);
937 register const bfd_byte
*addr
;
942 high
= ((((((((addr
[0]) << 8) |
947 low
= (((((((((bfd_vma
)addr
[4]) << 8) |
952 return high
<< 32 | low
;
961 register const bfd_byte
*addr
;
965 high
= (((((((addr
[7] << 8) |
970 low
= ((((((((bfd_vma
)addr
[3] << 8) |
975 return high
<< 32 | low
;
984 bfd_getb_signed_64 (addr
)
985 register const bfd_byte
*addr
;
990 high
= ((((((((addr
[0]) << 8) |
995 low
= (((((((((bfd_vma
)addr
[4]) << 8) |
1000 return COERCE64(high
<< 32 | low
);
1008 bfd_getl_signed_64 (addr
)
1009 register const bfd_byte
*addr
;
1013 high
= (((((((addr
[7] << 8) |
1018 low
= ((((((((bfd_vma
)addr
[3] << 8) |
1023 return COERCE64(high
<< 32 | low
);
1031 bfd_putb32 (data
, addr
)
1033 register bfd_byte
*addr
;
1035 addr
[0] = (bfd_byte
)(data
>> 24);
1036 addr
[1] = (bfd_byte
)(data
>> 16);
1037 addr
[2] = (bfd_byte
)(data
>> 8);
1038 addr
[3] = (bfd_byte
)data
;
1042 bfd_putl32 (data
, addr
)
1044 register bfd_byte
*addr
;
1046 addr
[0] = (bfd_byte
)data
;
1047 addr
[1] = (bfd_byte
)(data
>> 8);
1048 addr
[2] = (bfd_byte
)(data
>> 16);
1049 addr
[3] = (bfd_byte
)(data
>> 24);
1053 bfd_putb64 (data
, addr
)
1055 register bfd_byte
*addr
;
1058 addr
[0] = (bfd_byte
)(data
>> (7*8));
1059 addr
[1] = (bfd_byte
)(data
>> (6*8));
1060 addr
[2] = (bfd_byte
)(data
>> (5*8));
1061 addr
[3] = (bfd_byte
)(data
>> (4*8));
1062 addr
[4] = (bfd_byte
)(data
>> (3*8));
1063 addr
[5] = (bfd_byte
)(data
>> (2*8));
1064 addr
[6] = (bfd_byte
)(data
>> (1*8));
1065 addr
[7] = (bfd_byte
)(data
>> (0*8));
1072 bfd_putl64 (data
, addr
)
1074 register bfd_byte
*addr
;
1077 addr
[7] = (bfd_byte
)(data
>> (7*8));
1078 addr
[6] = (bfd_byte
)(data
>> (6*8));
1079 addr
[5] = (bfd_byte
)(data
>> (5*8));
1080 addr
[4] = (bfd_byte
)(data
>> (4*8));
1081 addr
[3] = (bfd_byte
)(data
>> (3*8));
1082 addr
[2] = (bfd_byte
)(data
>> (2*8));
1083 addr
[1] = (bfd_byte
)(data
>> (1*8));
1084 addr
[0] = (bfd_byte
)(data
>> (0*8));
1090 /* Default implementation */
1093 _bfd_generic_get_section_contents (abfd
, section
, location
, offset
, count
)
1098 bfd_size_type count
;
1102 if ((bfd_size_type
)(offset
+count
) > section
->_raw_size
1103 || bfd_seek(abfd
, (file_ptr
)(section
->filepos
+ offset
), SEEK_SET
) == -1
1104 || bfd_read(location
, (bfd_size_type
)1, count
, abfd
) != count
)
1105 return (false); /* on error */
1110 _bfd_generic_get_section_contents_in_window (abfd
, section
, w
, offset
, count
)
1115 bfd_size_type count
;
1120 if (abfd
->xvec
->_bfd_get_section_contents
!= _bfd_generic_get_section_contents
)
1122 /* We don't know what changes the bfd's get_section_contents
1123 method may have to make. So punt trying to map the file
1124 window, and let get_section_contents do its thing. */
1125 /* @@ FIXME : If the internal window has a refcount of 1 and was
1126 allocated with malloc instead of mmap, just reuse it. */
1127 bfd_free_window (w
);
1128 w
->i
= (bfd_window_internal
*) bfd_zmalloc (sizeof (bfd_window_internal
));
1131 w
->i
->data
= (PTR
) bfd_malloc ((size_t) count
);
1132 if (w
->i
->data
== NULL
)
1140 w
->size
= w
->i
->size
= count
;
1141 w
->data
= w
->i
->data
;
1142 return bfd_get_section_contents (abfd
, section
, w
->data
, offset
, count
);
1144 if ((bfd_size_type
) (offset
+count
) > section
->_raw_size
1145 || (bfd_get_file_window (abfd
, section
->filepos
+ offset
, count
, w
, true)
1154 /* This generic function can only be used in implementations where creating
1155 NEW sections is disallowed. It is useful in patching existing sections
1156 in read-write files, though. See other set_section_contents functions
1157 to see why it doesn't work for new sections. */
1159 _bfd_generic_set_section_contents (abfd
, section
, location
, offset
, count
)
1164 bfd_size_type count
;
1169 if (bfd_seek (abfd
, (file_ptr
) (section
->filepos
+ offset
), SEEK_SET
) == -1
1170 || bfd_write (location
, (bfd_size_type
) 1, count
, abfd
) != count
)
1181 unsigned int bfd_log2(bfd_vma x);
1184 Return the log base 2 of the value supplied, rounded up. E.g., an
1185 @var{x} of 1025 returns 11.
1192 unsigned int result
= 0;
1194 while ((((bfd_vma
) 1) << result
) < x
)
1200 bfd_generic_is_local_label_name (abfd
, name
)
1204 char locals_prefix
= (bfd_get_symbol_leading_char (abfd
) == '_') ? 'L' : '.';
1206 return (name
[0] == locals_prefix
);