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 /* FIXME - this looks like an optimization, but it's really to cover
236 up for a feature of some OSs (not solaris - sigh) that
237 ld/pe-dll.c takes advantage of (apparently) when it creates BFDs
238 internally and tries to link against them. BFD seems to be smart
239 enough to realize there are no symbol records in the "file" that
240 doesn't exist but attempts to read them anyway. On Solaris,
241 attempting to read zero bytes from a NULL file results in a core
242 dump, but on other platforms it just returns zero bytes read.
243 This makes it to something reasonable. - DJ */
244 if (a
== 0 || b
== 0)
247 #if defined (__VAX) && defined (VMS)
248 /* Apparently fread on Vax VMS does not keep the record length
250 return read (fileno (file
), where
, a
* b
);
252 return fread (where
, a
, b
, file
);
256 /* Return value is amount read (FIXME: how are errors and end of file dealt
257 with? We never call bfd_set_error, which is probably a mistake). */
260 bfd_read (ptr
, size
, nitems
, abfd
)
263 bfd_size_type nitems
;
268 if ((abfd
->flags
& BFD_IN_MEMORY
) != 0)
270 struct bfd_in_memory
*bim
;
273 bim
= (struct bfd_in_memory
*) abfd
->iostream
;
275 if (abfd
->where
+ get
> bim
->size
)
277 get
= bim
->size
- abfd
->where
;
278 bfd_set_error (bfd_error_file_truncated
);
280 memcpy (ptr
, bim
->buffer
+ abfd
->where
, get
);
285 nread
= real_read (ptr
, 1, (size_t)(size
*nitems
), bfd_cache_lookup(abfd
));
287 abfd
->where
+= nread
;
289 /* Set bfd_error if we did not read as much data as we expected.
291 If the read failed due to an error set the bfd_error_system_call,
292 else set bfd_error_file_truncated.
294 A BFD backend may wish to override bfd_error_file_truncated to
295 provide something more useful (eg. no_symbols or wrong_format). */
296 if (nread
< (int)(size
* nitems
))
298 if (ferror (bfd_cache_lookup (abfd
)))
299 bfd_set_error (bfd_error_system_call
);
301 bfd_set_error (bfd_error_file_truncated
);
307 /* The window support stuff should probably be broken out into
309 /* The idea behind the next and refcount fields is that one mapped
310 region can suffice for multiple read-only windows or multiple
311 non-overlapping read-write windows. It's not implemented yet
313 struct _bfd_window_internal
{
314 struct _bfd_window_internal
*next
;
317 int refcount
: 31; /* should be enough... */
318 unsigned mapped
: 1; /* 1 = mmap, 0 = malloc */
322 bfd_init_window (windowp
)
330 /* Currently, if USE_MMAP is undefined, none if the window stuff is
331 used. Okay, so it's mis-named. At least the command-line option
332 "--without-mmap" is more obvious than "--without-windows" or some
336 #undef HAVE_MPROTECT /* code's not tested yet */
338 #if HAVE_MMAP || HAVE_MPROTECT || HAVE_MADVISE
339 #include <sys/mman.h>
346 static int debug_windows
;
349 bfd_free_window (windowp
)
352 bfd_window_internal
*i
= windowp
->i
;
359 fprintf (stderr
, "freeing window @%p<%p,%lx,%p>\n",
360 windowp
, windowp
->data
, windowp
->size
, windowp
->i
);
361 if (i
->refcount
!= 0)
367 munmap (i
->data
, i
->size
);
374 mprotect (i
->data
, i
->size
, PROT_READ
| PROT_WRITE
);
381 /* There should be no more references to i at this point. */
385 static int ok_to_map
= 1;
388 bfd_get_file_window (abfd
, offset
, size
, windowp
, writable
)
395 static size_t pagesize
;
396 bfd_window_internal
*i
= windowp
->i
;
397 size_t size_to_alloc
= size
;
400 fprintf (stderr
, "bfd_get_file_window (%p, %6ld, %6ld, %p<%p,%lx,%p>, %d)",
401 abfd
, (long) offset
, (long) size
,
402 windowp
, windowp
->data
, (unsigned long) windowp
->size
,
403 windowp
->i
, writable
);
405 /* Make sure we know the page size, so we can be friendly to mmap. */
407 pagesize
= getpagesize ();
413 windowp
->i
= i
= (bfd_window_internal
*) bfd_zmalloc (sizeof (bfd_window_internal
));
420 && (i
->data
== 0 || i
->mapped
== 1)
421 && (abfd
->flags
& BFD_IN_MEMORY
) == 0)
423 file_ptr file_offset
, offset2
;
428 /* Find the real file and the real offset into it. */
429 while (abfd
->my_archive
!= NULL
)
431 offset
+= abfd
->origin
;
432 abfd
= abfd
->my_archive
;
434 f
= bfd_cache_lookup (abfd
);
437 /* Compute offsets and size for mmap and for the user's data. */
438 offset2
= offset
% pagesize
;
441 file_offset
= offset
- offset2
;
442 real_size
= offset
+ size
- file_offset
;
443 real_size
= real_size
+ pagesize
- 1;
444 real_size
-= real_size
% pagesize
;
446 /* If we're re-using a memory region, make sure it's big enough. */
447 if (i
->data
&& i
->size
< size
)
449 munmap (i
->data
, i
->size
);
452 i
->data
= mmap (i
->data
, real_size
,
453 writable
? PROT_WRITE
| PROT_READ
: PROT_READ
,
455 ? MAP_FILE
| MAP_PRIVATE
456 : MAP_FILE
| MAP_SHARED
),
458 if (i
->data
== (PTR
) -1)
460 /* An error happened. Report it, or try using malloc, or
462 bfd_set_error (bfd_error_system_call
);
466 fprintf (stderr
, "\t\tmmap failed!\n");
470 fprintf (stderr
, "\n\tmapped %ld at %p, offset is %ld\n",
471 (long) real_size
, i
->data
, (long) offset2
);
473 windowp
->data
= (PTR
) ((bfd_byte
*) i
->data
+ offset2
);
474 windowp
->size
= size
;
478 else if (debug_windows
)
481 fprintf (stderr
, _("not mapping: data=%lx mapped=%d\n"),
482 (unsigned long) i
->data
, (int) i
->mapped
);
484 fprintf (stderr
, _("not mapping: env var not set\n"));
493 size_to_alloc
+= pagesize
- 1;
494 size_to_alloc
-= size_to_alloc
% pagesize
;
498 fprintf (stderr
, "\n\t%s(%6ld)",
499 i
->data
? "realloc" : " malloc", (long) size_to_alloc
);
500 i
->data
= (PTR
) bfd_realloc (i
->data
, size_to_alloc
);
502 fprintf (stderr
, "\t-> %p\n", i
->data
);
506 if (size_to_alloc
== 0)
508 bfd_set_error (bfd_error_no_memory
);
511 if (bfd_seek (abfd
, offset
, SEEK_SET
) != 0)
513 i
->size
= bfd_read (i
->data
, size
, 1, abfd
);
521 fprintf (stderr
, "\tmprotect (%p, %ld, PROT_READ)\n", i
->data
,
523 mprotect (i
->data
, i
->size
, PROT_READ
);
526 windowp
->data
= i
->data
;
527 windowp
->size
= i
->size
;
531 #endif /* USE_MMAP */
534 bfd_write (ptr
, size
, nitems
, abfd
)
537 bfd_size_type nitems
;
542 if ((abfd
->flags
& BFD_IN_MEMORY
) != 0)
544 struct bfd_in_memory
*bim
= (struct bfd_in_memory
*) (abfd
->iostream
);
546 if (abfd
->where
+ size
> bim
->size
)
548 long newsize
, oldsize
= (bim
->size
+ 127) & ~127;
549 bim
->size
= abfd
->where
+ size
;
550 /* Round up to cut down on memory fragmentation */
551 newsize
= (bim
->size
+ 127) & ~127;
552 if (newsize
> oldsize
)
554 bim
->buffer
= bfd_realloc (bim
->buffer
, newsize
);
555 if (bim
->buffer
== 0)
562 memcpy (bim
->buffer
+ abfd
->where
, ptr
, size
);
567 nwrote
= fwrite (ptr
, 1, (size_t) (size
* nitems
),
568 bfd_cache_lookup (abfd
));
570 abfd
->where
+= nwrote
;
571 if ((bfd_size_type
) nwrote
!= size
* nitems
)
577 bfd_set_error (bfd_error_system_call
);
584 bfd_write_bigendian_4byte_int
587 void bfd_write_bigendian_4byte_int(bfd *abfd, int i);
590 Write a 4 byte integer @var{i} to the output BFD @var{abfd}, in big
591 endian order regardless of what else is going on. This is useful in
596 bfd_write_bigendian_4byte_int (abfd
, i
)
601 bfd_putb32(i
, buffer
);
602 if (bfd_write((PTR
)buffer
, 4, 1, abfd
) != 4)
612 if ((abfd
->flags
& BFD_IN_MEMORY
) != 0)
615 ptr
= ftell (bfd_cache_lookup(abfd
));
617 if (abfd
->my_archive
)
627 if ((abfd
->flags
& BFD_IN_MEMORY
) != 0)
629 return fflush (bfd_cache_lookup(abfd
));
632 /* Returns 0 for success, negative value for failure (in which case
633 bfd_get_error can retrieve the error code). */
635 bfd_stat (abfd
, statbuf
)
637 struct stat
*statbuf
;
642 if ((abfd
->flags
& BFD_IN_MEMORY
) != 0)
645 f
= bfd_cache_lookup (abfd
);
648 bfd_set_error (bfd_error_system_call
);
651 result
= fstat (fileno (f
), statbuf
);
653 bfd_set_error (bfd_error_system_call
);
657 /* Returns 0 for success, nonzero for failure (in which case bfd_get_error
658 can retrieve the error code). */
661 bfd_seek (abfd
, position
, direction
)
668 file_ptr file_position
;
669 /* For the time being, a BFD may not seek to it's end. The problem
670 is that we don't easily have a way to recognize the end of an
671 element in an archive. */
673 BFD_ASSERT (direction
== SEEK_SET
|| direction
== SEEK_CUR
);
675 if (direction
== SEEK_CUR
&& position
== 0)
678 if ((abfd
->flags
& BFD_IN_MEMORY
) != 0)
680 if (direction
== SEEK_SET
)
681 abfd
->where
= position
;
683 abfd
->where
+= position
;
687 if (abfd
->format
!= bfd_archive
&& abfd
->my_archive
== 0)
690 /* Explanation for this code: I'm only about 95+% sure that the above
691 conditions are sufficient and that all i/o calls are properly
692 adjusting the `where' field. So this is sort of an `assert'
693 that the `where' field is correct. If we can go a while without
694 tripping the abort, we can probably safely disable this code,
695 so that the real optimizations happen. */
696 file_ptr where_am_i_now
;
697 where_am_i_now
= ftell (bfd_cache_lookup (abfd
));
698 if (abfd
->my_archive
)
699 where_am_i_now
-= abfd
->origin
;
700 if (where_am_i_now
!= abfd
->where
)
703 if (direction
== SEEK_SET
&& position
== abfd
->where
)
708 /* We need something smarter to optimize access to archives.
709 Currently, anything inside an archive is read via the file
710 handle for the archive. Which means that a bfd_seek on one
711 component affects the `current position' in the archive, as
712 well as in any other component.
714 It might be sufficient to put a spike through the cache
715 abstraction, and look to the archive for the file position,
716 but I think we should try for something cleaner.
718 In the meantime, no optimization for archives. */
721 f
= bfd_cache_lookup (abfd
);
722 file_position
= position
;
723 if (direction
== SEEK_SET
&& abfd
->my_archive
!= NULL
)
724 file_position
+= abfd
->origin
;
726 result
= fseek (f
, file_position
, direction
);
730 int hold_errno
= errno
;
732 /* Force redetermination of `where' field. */
735 /* An EINVAL error probably means that the file offset was
737 if (hold_errno
== EINVAL
)
738 bfd_set_error (bfd_error_file_truncated
);
741 bfd_set_error (bfd_error_system_call
);
747 /* Adjust `where' field. */
748 if (direction
== SEEK_SET
)
749 abfd
->where
= position
;
751 abfd
->where
+= position
;
756 /** The do-it-yourself (byte) sex-change kit */
758 /* The middle letter e.g. get<b>short indicates Big or Little endian
759 target machine. It doesn't matter what the byte order of the host
760 machine is; these routines work for either. */
762 /* FIXME: Should these take a count argument?
763 Answer (gnu@cygnus.com): No, but perhaps they should be inline
764 functions in swap.h #ifdef __GNUC__.
765 Gprof them later and find out. */
774 These macros as used for reading and writing raw data in
775 sections; each access (except for bytes) is vectored through
776 the target format of the BFD and mangled accordingly. The
777 mangling performs any necessary endian translations and
778 removes alignment restrictions. Note that types accepted and
779 returned by these macros are identical so they can be swapped
780 around in macros---for example, @file{libaout.h} defines <<GET_WORD>>
781 to either <<bfd_get_32>> or <<bfd_get_64>>.
783 In the put routines, @var{val} must be a <<bfd_vma>>. If we are on a
784 system without prototypes, the caller is responsible for making
785 sure that is true, with a cast if necessary. We don't cast
786 them in the macro definitions because that would prevent <<lint>>
787 or <<gcc -Wall>> from detecting sins such as passing a pointer.
788 To detect calling these with less than a <<bfd_vma>>, use
789 <<gcc -Wconversion>> on a host with 64 bit <<bfd_vma>>'s.
792 .{* Byte swapping macros for user section data. *}
794 .#define bfd_put_8(abfd, val, ptr) \
795 . (*((unsigned char *)(ptr)) = (unsigned char)(val))
796 .#define bfd_put_signed_8 \
798 .#define bfd_get_8(abfd, ptr) \
799 . (*(unsigned char *)(ptr))
800 .#define bfd_get_signed_8(abfd, ptr) \
801 . ((*(unsigned char *)(ptr) ^ 0x80) - 0x80)
803 .#define bfd_put_16(abfd, val, ptr) \
804 . BFD_SEND(abfd, bfd_putx16, ((val),(ptr)))
805 .#define bfd_put_signed_16 \
807 .#define bfd_get_16(abfd, ptr) \
808 . BFD_SEND(abfd, bfd_getx16, (ptr))
809 .#define bfd_get_signed_16(abfd, ptr) \
810 . BFD_SEND (abfd, bfd_getx_signed_16, (ptr))
812 .#define bfd_put_32(abfd, val, ptr) \
813 . BFD_SEND(abfd, bfd_putx32, ((val),(ptr)))
814 .#define bfd_put_signed_32 \
816 .#define bfd_get_32(abfd, ptr) \
817 . BFD_SEND(abfd, bfd_getx32, (ptr))
818 .#define bfd_get_signed_32(abfd, ptr) \
819 . BFD_SEND(abfd, bfd_getx_signed_32, (ptr))
821 .#define bfd_put_64(abfd, val, ptr) \
822 . BFD_SEND(abfd, bfd_putx64, ((val), (ptr)))
823 .#define bfd_put_signed_64 \
825 .#define bfd_get_64(abfd, ptr) \
826 . BFD_SEND(abfd, bfd_getx64, (ptr))
827 .#define bfd_get_signed_64(abfd, ptr) \
828 . BFD_SEND(abfd, bfd_getx_signed_64, (ptr))
838 These macros have the same function as their <<bfd_get_x>>
839 bretheren, except that they are used for removing information
840 for the header records of object files. Believe it or not,
841 some object files keep their header records in big endian
842 order and their data in little endian order.
844 .{* Byte swapping macros for file header data. *}
846 .#define bfd_h_put_8(abfd, val, ptr) \
847 . bfd_put_8 (abfd, val, ptr)
848 .#define bfd_h_put_signed_8(abfd, val, ptr) \
849 . bfd_put_8 (abfd, val, ptr)
850 .#define bfd_h_get_8(abfd, ptr) \
851 . bfd_get_8 (abfd, ptr)
852 .#define bfd_h_get_signed_8(abfd, ptr) \
853 . bfd_get_signed_8 (abfd, ptr)
855 .#define bfd_h_put_16(abfd, val, ptr) \
856 . BFD_SEND(abfd, bfd_h_putx16,(val,ptr))
857 .#define bfd_h_put_signed_16 \
859 .#define bfd_h_get_16(abfd, ptr) \
860 . BFD_SEND(abfd, bfd_h_getx16,(ptr))
861 .#define bfd_h_get_signed_16(abfd, ptr) \
862 . BFD_SEND(abfd, bfd_h_getx_signed_16, (ptr))
864 .#define bfd_h_put_32(abfd, val, ptr) \
865 . BFD_SEND(abfd, bfd_h_putx32,(val,ptr))
866 .#define bfd_h_put_signed_32 \
868 .#define bfd_h_get_32(abfd, ptr) \
869 . BFD_SEND(abfd, bfd_h_getx32,(ptr))
870 .#define bfd_h_get_signed_32(abfd, ptr) \
871 . BFD_SEND(abfd, bfd_h_getx_signed_32, (ptr))
873 .#define bfd_h_put_64(abfd, val, ptr) \
874 . BFD_SEND(abfd, bfd_h_putx64,(val, ptr))
875 .#define bfd_h_put_signed_64 \
877 .#define bfd_h_get_64(abfd, ptr) \
878 . BFD_SEND(abfd, bfd_h_getx64,(ptr))
879 .#define bfd_h_get_signed_64(abfd, ptr) \
880 . BFD_SEND(abfd, bfd_h_getx_signed_64, (ptr))
884 /* Sign extension to bfd_signed_vma. */
885 #define COERCE16(x) (((bfd_signed_vma) (x) ^ 0x8000) - 0x8000)
886 #define COERCE32(x) \
887 ((bfd_signed_vma) (long) (((unsigned long) (x) ^ 0x80000000) - 0x80000000))
888 #define EIGHT_GAZILLION (((BFD_HOST_64_BIT)0x80000000) << 32)
889 #define COERCE64(x) \
890 (((bfd_signed_vma) (x) ^ EIGHT_GAZILLION) - EIGHT_GAZILLION)
894 register const bfd_byte
*addr
;
896 return (addr
[0] << 8) | addr
[1];
901 register const bfd_byte
*addr
;
903 return (addr
[1] << 8) | addr
[0];
907 bfd_getb_signed_16 (addr
)
908 register const bfd_byte
*addr
;
910 return COERCE16((addr
[0] << 8) | addr
[1]);
914 bfd_getl_signed_16 (addr
)
915 register const bfd_byte
*addr
;
917 return COERCE16((addr
[1] << 8) | addr
[0]);
921 bfd_putb16 (data
, addr
)
923 register bfd_byte
*addr
;
925 addr
[0] = (bfd_byte
)(data
>> 8);
926 addr
[1] = (bfd_byte
)data
;
930 bfd_putl16 (data
, addr
)
932 register bfd_byte
*addr
;
934 addr
[0] = (bfd_byte
)data
;
935 addr
[1] = (bfd_byte
)(data
>> 8);
940 register const bfd_byte
*addr
;
944 v
= (unsigned long) addr
[0] << 24;
945 v
|= (unsigned long) addr
[1] << 16;
946 v
|= (unsigned long) addr
[2] << 8;
947 v
|= (unsigned long) addr
[3];
953 register const bfd_byte
*addr
;
957 v
= (unsigned long) addr
[0];
958 v
|= (unsigned long) addr
[1] << 8;
959 v
|= (unsigned long) addr
[2] << 16;
960 v
|= (unsigned long) addr
[3] << 24;
965 bfd_getb_signed_32 (addr
)
966 register const bfd_byte
*addr
;
970 v
= (unsigned long) addr
[0] << 24;
971 v
|= (unsigned long) addr
[1] << 16;
972 v
|= (unsigned long) addr
[2] << 8;
973 v
|= (unsigned long) addr
[3];
978 bfd_getl_signed_32 (addr
)
979 register const bfd_byte
*addr
;
983 v
= (unsigned long) addr
[0];
984 v
|= (unsigned long) addr
[1] << 8;
985 v
|= (unsigned long) addr
[2] << 16;
986 v
|= (unsigned long) addr
[3] << 24;
992 register const bfd_byte
*addr
;
997 high
= ((((((((addr
[0]) << 8) |
1002 low
= (((((((((bfd_vma
)addr
[4]) << 8) |
1007 return high
<< 32 | low
;
1016 register const bfd_byte
*addr
;
1020 high
= (((((((addr
[7] << 8) |
1025 low
= ((((((((bfd_vma
)addr
[3] << 8) |
1030 return high
<< 32 | low
;
1039 bfd_getb_signed_64 (addr
)
1040 register const bfd_byte
*addr
;
1045 high
= ((((((((addr
[0]) << 8) |
1050 low
= (((((((((bfd_vma
)addr
[4]) << 8) |
1055 return COERCE64(high
<< 32 | low
);
1063 bfd_getl_signed_64 (addr
)
1064 register const bfd_byte
*addr
;
1068 high
= (((((((addr
[7] << 8) |
1073 low
= ((((((((bfd_vma
)addr
[3] << 8) |
1078 return COERCE64(high
<< 32 | low
);
1086 bfd_putb32 (data
, addr
)
1088 register bfd_byte
*addr
;
1090 addr
[0] = (bfd_byte
)(data
>> 24);
1091 addr
[1] = (bfd_byte
)(data
>> 16);
1092 addr
[2] = (bfd_byte
)(data
>> 8);
1093 addr
[3] = (bfd_byte
)data
;
1097 bfd_putl32 (data
, addr
)
1099 register bfd_byte
*addr
;
1101 addr
[0] = (bfd_byte
)data
;
1102 addr
[1] = (bfd_byte
)(data
>> 8);
1103 addr
[2] = (bfd_byte
)(data
>> 16);
1104 addr
[3] = (bfd_byte
)(data
>> 24);
1108 bfd_putb64 (data
, addr
)
1110 register bfd_byte
*addr
;
1113 addr
[0] = (bfd_byte
)(data
>> (7*8));
1114 addr
[1] = (bfd_byte
)(data
>> (6*8));
1115 addr
[2] = (bfd_byte
)(data
>> (5*8));
1116 addr
[3] = (bfd_byte
)(data
>> (4*8));
1117 addr
[4] = (bfd_byte
)(data
>> (3*8));
1118 addr
[5] = (bfd_byte
)(data
>> (2*8));
1119 addr
[6] = (bfd_byte
)(data
>> (1*8));
1120 addr
[7] = (bfd_byte
)(data
>> (0*8));
1127 bfd_putl64 (data
, addr
)
1129 register bfd_byte
*addr
;
1132 addr
[7] = (bfd_byte
)(data
>> (7*8));
1133 addr
[6] = (bfd_byte
)(data
>> (6*8));
1134 addr
[5] = (bfd_byte
)(data
>> (5*8));
1135 addr
[4] = (bfd_byte
)(data
>> (4*8));
1136 addr
[3] = (bfd_byte
)(data
>> (3*8));
1137 addr
[2] = (bfd_byte
)(data
>> (2*8));
1138 addr
[1] = (bfd_byte
)(data
>> (1*8));
1139 addr
[0] = (bfd_byte
)(data
>> (0*8));
1145 /* Default implementation */
1148 _bfd_generic_get_section_contents (abfd
, section
, location
, offset
, count
)
1153 bfd_size_type count
;
1157 if ((bfd_size_type
)(offset
+count
) > section
->_raw_size
1158 || bfd_seek(abfd
, (file_ptr
)(section
->filepos
+ offset
), SEEK_SET
) == -1
1159 || bfd_read(location
, (bfd_size_type
)1, count
, abfd
) != count
)
1160 return (false); /* on error */
1165 _bfd_generic_get_section_contents_in_window (abfd
, section
, w
, offset
, count
)
1170 bfd_size_type count
;
1175 if (abfd
->xvec
->_bfd_get_section_contents
!= _bfd_generic_get_section_contents
)
1177 /* We don't know what changes the bfd's get_section_contents
1178 method may have to make. So punt trying to map the file
1179 window, and let get_section_contents do its thing. */
1180 /* @@ FIXME : If the internal window has a refcount of 1 and was
1181 allocated with malloc instead of mmap, just reuse it. */
1182 bfd_free_window (w
);
1183 w
->i
= (bfd_window_internal
*) bfd_zmalloc (sizeof (bfd_window_internal
));
1186 w
->i
->data
= (PTR
) bfd_malloc ((size_t) count
);
1187 if (w
->i
->data
== NULL
)
1195 w
->size
= w
->i
->size
= count
;
1196 w
->data
= w
->i
->data
;
1197 return bfd_get_section_contents (abfd
, section
, w
->data
, offset
, count
);
1199 if ((bfd_size_type
) (offset
+count
) > section
->_raw_size
1200 || (bfd_get_file_window (abfd
, section
->filepos
+ offset
, count
, w
, true)
1209 /* This generic function can only be used in implementations where creating
1210 NEW sections is disallowed. It is useful in patching existing sections
1211 in read-write files, though. See other set_section_contents functions
1212 to see why it doesn't work for new sections. */
1214 _bfd_generic_set_section_contents (abfd
, section
, location
, offset
, count
)
1219 bfd_size_type count
;
1224 if (bfd_seek (abfd
, (file_ptr
) (section
->filepos
+ offset
), SEEK_SET
) == -1
1225 || bfd_write (location
, (bfd_size_type
) 1, count
, abfd
) != count
)
1236 unsigned int bfd_log2(bfd_vma x);
1239 Return the log base 2 of the value supplied, rounded up. E.g., an
1240 @var{x} of 1025 returns 11.
1247 unsigned int result
= 0;
1249 while ((((bfd_vma
) 1) << result
) < x
)
1255 bfd_generic_is_local_label_name (abfd
, name
)
1259 char locals_prefix
= (bfd_get_symbol_leading_char (abfd
) == '_') ? 'L' : '.';
1261 return (name
[0] == locals_prefix
);