1 /* Assorted BFD support routines, only used internally.
2 Copyright 1990, 91, 92, 93, 94 Free Software Foundation, Inc.
3 Written by Cygnus Support.
5 This file is part of BFD, the Binary File Descriptor library.
7 This program is free software; you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by
9 the Free Software Foundation; either version 2 of the License, or
10 (at your option) any later version.
12 This program is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
17 You should have received a copy of the GNU General Public License
18 along with this program; if not, write to the Free Software
19 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */
25 static int real_read
PARAMS ((PTR
, size_t, size_t, FILE *));
32 These routines are used within BFD.
33 They are not intended for export, but are documented here for
37 /* A routine which is used in target vectors for unsupported
45 bfd_set_error (bfd_error_invalid_operation
);
49 /* A routine which is used in target vectors for supported operations
50 which do not actually do anything. */
60 /* A routine which is used in target vectors for unsupported
61 operations which return a pointer value. */
65 bfd_nullvoidptr (ignore
)
68 bfd_set_error (bfd_error_invalid_operation
);
96 /* A routine which is used in target vectors for unsupported
97 operations which return -1 on error. */
101 _bfd_n1 (ignore_abfd
)
104 bfd_set_error (bfd_error_invalid_operation
);
117 _bfd_nocore_core_file_matches_executable_p (ignore_core_bfd
, ignore_exec_bfd
)
118 bfd
*ignore_core_bfd
;
119 bfd
*ignore_exec_bfd
;
121 bfd_set_error (bfd_error_invalid_operation
);
125 /* Routine to handle core_file_failing_command entry point for targets
126 without core file support. */
130 _bfd_nocore_core_file_failing_command (ignore_abfd
)
133 bfd_set_error (bfd_error_invalid_operation
);
137 /* Routine to handle core_file_failing_signal entry point for targets
138 without core file support. */
142 _bfd_nocore_core_file_failing_signal (ignore_abfd
)
145 bfd_set_error (bfd_error_invalid_operation
);
151 _bfd_dummy_target (ignore_abfd
)
154 bfd_set_error (bfd_error_wrong_format
);
160 /* allocate and clear storage */
166 char *ptr
= (char *) malloc ((size_t) size
);
171 bfd_set_error (bfd_error_no_memory
);
173 memset (ptr
, 0, (size_t) size
);
178 #endif /* bfd_zmalloc */
183 /* Note that archive entries don't have streams; they share their parent's.
184 This allows someone to play with the iostream behind BFD's back.
186 Also, note that the origin pointer points to the beginning of a file's
187 contents (0 for non-archive elements). For archive entries this is the
188 first octet in the file, NOT the beginning of the archive header. */
191 real_read (where
, a
,b
, file
)
197 return fread (where
, a
, b
, file
);
200 /* Return value is amount read (FIXME: how are errors and end of file dealt
201 with? We never call bfd_set_error, which is probably a mistake). */
204 bfd_read (ptr
, size
, nitems
, abfd
)
207 bfd_size_type nitems
;
211 nread
= real_read (ptr
, 1, (size_t)(size
*nitems
), bfd_cache_lookup(abfd
));
212 #ifdef FILE_OFFSET_IS_CHAR_INDEX
214 abfd
->where
+= nread
;
217 /* Set bfd_error if we did not read as much data as we expected.
219 If the read failed due to an error set the bfd_error_system_call,
220 else set bfd_error_file_truncated.
222 A BFD backend may wish to override bfd_error_file_truncated to
223 provide something more useful (eg. no_symbols or wrong_format). */
224 if (nread
< (int)(size
* nitems
))
226 if (ferror (bfd_cache_lookup (abfd
)))
227 bfd_set_error (bfd_error_system_call
);
229 bfd_set_error (bfd_error_file_truncated
);
235 /* The window support stuff should probably be broken out into
237 /* The idea behind the next and refcount fields is that one mapped
238 region can suffice for multiple read-only windows or multiple
239 non-overlapping read-write windows. It's not implemented yet
241 struct _bfd_window_internal
{
242 struct _bfd_window_internal
*next
;
245 int refcount
: 31; /* should be enough... */
246 unsigned mapped
: 1; /* 1 = mmap, 0 = malloc */
250 bfd_init_window (windowp
)
258 #undef HAVE_MPROTECT /* code's not tested yet */
260 #if HAVE_MMAP || HAVE_MPROTECT || HAVE_MADVISE
261 #include <sys/types.h>
262 #include <sys/mman.h>
269 static int debug_windows
;
271 /* Currently, if USE_MMAP is undefined, none if the window stuff is
272 used. Okay, so it's mis-named. At least the command-line option
273 "--without-mmap" is more obvious than "--without-windows" or some
278 bfd_free_window (windowp
)
281 bfd_window_internal
*i
= windowp
->i
;
288 fprintf (stderr
, "freeing window @%p<%p,%lx,%p>\n",
289 windowp
, windowp
->data
, windowp
->size
, windowp
->i
);
290 if (i
->refcount
!= 0)
296 munmap (i
->data
, i
->size
);
303 mprotect (i
->data
, i
->size
, PROT_READ
| PROT_WRITE
);
310 /* There should be no more references to i at this point. */
315 static int ok_to_map
= 1;
318 bfd_get_file_window (abfd
, offset
, size
, windowp
, writable
)
325 static size_t pagesize
;
326 bfd_window_internal
*i
= windowp
->i
;
327 size_t size_to_alloc
= size
;
334 fprintf (stderr
, "bfd_get_file_window (%p, %6ld, %6ld, %p<%p,%lx,%p>, %d)",
335 abfd
, (long) offset
, (long) size
,
336 windowp
, windowp
->data
, windowp
->size
, windowp
->i
,
339 /* Make sure we know the page size, so we can be friendly to mmap. */
341 pagesize
= getpagesize ();
347 windowp
->i
= i
= (bfd_window_internal
*) bfd_zmalloc (sizeof (bfd_window_internal
));
353 if (ok_to_map
&& (i
->data
== 0 || i
->mapped
== 1))
355 file_ptr file_offset
, offset2
;
360 /* Find the real file and the real offset into it. */
361 while (abfd
->my_archive
!= NULL
)
363 offset
+= abfd
->origin
;
364 abfd
= abfd
->my_archive
;
366 f
= bfd_cache_lookup (abfd
);
369 /* Compute offsets and size for mmap and for the user's data. */
370 offset2
= offset
% pagesize
;
373 file_offset
= offset
- offset2
;
374 real_size
= offset
+ size
- file_offset
;
375 real_size
= real_size
+ pagesize
- 1;
376 real_size
-= real_size
% pagesize
;
378 /* If we're re-using a memory region, make sure it's big enough. */
379 if (i
->data
&& i
->size
< size
)
381 munmap (i
->data
, i
->size
);
384 i
->data
= mmap (i
->data
, real_size
,
385 writable
? PROT_WRITE
| PROT_READ
: PROT_READ
,
387 ? MAP_FILE
| MAP_PRIVATE
388 : MAP_FILE
| MAP_SHARED
),
390 if (i
->data
== (PTR
) -1)
392 /* An error happened. Report it, or try using malloc, or
394 bfd_set_error (bfd_error_system_call
);
398 fprintf (stderr
, "\t\tmmap failed!\n");
402 fprintf (stderr
, "\n\tmapped %ld at %p, offset is %ld\n",
403 (long) real_size
, i
->data
, (long) offset2
);
405 windowp
->data
= (PTR
) ((bfd_byte
*) i
->data
+ offset2
);
406 windowp
->size
= size
;
410 else if (debug_windows
)
413 fprintf (stderr
, "not mapping: data=%lx mapped=%d\n",
414 (unsigned long) i
->data
, (int) i
->mapped
);
416 fprintf (stderr
, "not mapping: env var not set\n");
425 size_to_alloc
+= pagesize
- 1;
426 size_to_alloc
-= size_to_alloc
% pagesize
;
430 fprintf (stderr
, "\n\t%s(%6ld)",
431 i
->data
? "realloc" : " malloc", (long) size_to_alloc
);
433 i
->data
= (PTR
) realloc (i
->data
, size_to_alloc
);
435 i
->data
= (PTR
) malloc (size_to_alloc
);
437 fprintf (stderr
, "\t-> %p\n", i
->data
);
441 if (size_to_alloc
== 0)
443 bfd_set_error (bfd_error_no_memory
);
446 if (bfd_seek (abfd
, offset
, SEEK_SET
) != 0)
448 i
->size
= bfd_read (i
->data
, size
, 1, abfd
);
456 fprintf (stderr
, "\tmprotect (%p, %ld, PROT_READ)\n", i
->data
,
458 mprotect (i
->data
, i
->size
, PROT_READ
);
461 windowp
->data
= i
->data
;
462 windowp
->size
= i
->size
;
467 bfd_write (ptr
, size
, nitems
, abfd
)
470 bfd_size_type nitems
;
473 long nwrote
= fwrite (ptr
, 1, (size_t) (size
* nitems
),
474 bfd_cache_lookup (abfd
));
475 #ifdef FILE_OFFSET_IS_CHAR_INDEX
477 abfd
->where
+= nwrote
;
479 if ((bfd_size_type
) nwrote
!= size
* nitems
)
485 bfd_set_error (bfd_error_system_call
);
492 bfd_write_bigendian_4byte_int
495 void bfd_write_bigendian_4byte_int(bfd *abfd, int i);
498 Write a 4 byte integer @var{i} to the output BFD @var{abfd}, in big
499 endian order regardless of what else is going on. This is useful in
504 bfd_write_bigendian_4byte_int (abfd
, i
)
509 bfd_putb32(i
, buffer
);
510 if (bfd_write((PTR
)buffer
, 4, 1, abfd
) != 4)
520 ptr
= ftell (bfd_cache_lookup(abfd
));
522 if (abfd
->my_archive
)
532 return fflush (bfd_cache_lookup(abfd
));
535 /* Returns 0 for success, negative value for failure (in which case
536 bfd_get_error can retrieve the error code). */
538 bfd_stat (abfd
, statbuf
)
540 struct stat
*statbuf
;
544 f
= bfd_cache_lookup (abfd
);
547 bfd_set_error (bfd_error_system_call
);
550 result
= fstat (fileno (f
), statbuf
);
552 bfd_set_error (bfd_error_system_call
);
556 /* Returns 0 for success, nonzero for failure (in which case bfd_get_error
557 can retrieve the error code). */
560 bfd_seek (abfd
, position
, direction
)
567 file_ptr file_position
;
568 /* For the time being, a BFD may not seek to it's end. The problem
569 is that we don't easily have a way to recognize the end of an
570 element in an archive. */
572 BFD_ASSERT (direction
== SEEK_SET
|| direction
== SEEK_CUR
);
574 if (direction
== SEEK_CUR
&& position
== 0)
576 #ifdef FILE_OFFSET_IS_CHAR_INDEX
577 if (abfd
->format
!= bfd_archive
&& abfd
->my_archive
== 0)
580 /* Explanation for this code: I'm only about 95+% sure that the above
581 conditions are sufficient and that all i/o calls are properly
582 adjusting the `where' field. So this is sort of an `assert'
583 that the `where' field is correct. If we can go a while without
584 tripping the abort, we can probably safely disable this code,
585 so that the real optimizations happen. */
586 file_ptr where_am_i_now
;
587 where_am_i_now
= ftell (bfd_cache_lookup (abfd
));
588 if (abfd
->my_archive
)
589 where_am_i_now
-= abfd
->origin
;
590 if (where_am_i_now
!= abfd
->where
)
593 if (direction
== SEEK_SET
&& position
== abfd
->where
)
598 /* We need something smarter to optimize access to archives.
599 Currently, anything inside an archive is read via the file
600 handle for the archive. Which means that a bfd_seek on one
601 component affects the `current position' in the archive, as
602 well as in any other component.
604 It might be sufficient to put a spike through the cache
605 abstraction, and look to the archive for the file position,
606 but I think we should try for something cleaner.
608 In the meantime, no optimization for archives. */
612 f
= bfd_cache_lookup (abfd
);
613 file_position
= position
;
614 if (direction
== SEEK_SET
&& abfd
->my_archive
!= NULL
)
615 file_position
+= abfd
->origin
;
617 result
= fseek (f
, file_position
, direction
);
621 /* Force redetermination of `where' field. */
623 bfd_set_error (bfd_error_system_call
);
627 #ifdef FILE_OFFSET_IS_CHAR_INDEX
628 /* Adjust `where' field. */
629 if (direction
== SEEK_SET
)
630 abfd
->where
= position
;
632 abfd
->where
+= position
;
638 /** The do-it-yourself (byte) sex-change kit */
640 /* The middle letter e.g. get<b>short indicates Big or Little endian
641 target machine. It doesn't matter what the byte order of the host
642 machine is; these routines work for either. */
644 /* FIXME: Should these take a count argument?
645 Answer (gnu@cygnus.com): No, but perhaps they should be inline
646 functions in swap.h #ifdef __GNUC__.
647 Gprof them later and find out. */
656 These macros as used for reading and writing raw data in
657 sections; each access (except for bytes) is vectored through
658 the target format of the BFD and mangled accordingly. The
659 mangling performs any necessary endian translations and
660 removes alignment restrictions. Note that types accepted and
661 returned by these macros are identical so they can be swapped
662 around in macros---for example, @file{libaout.h} defines <<GET_WORD>>
663 to either <<bfd_get_32>> or <<bfd_get_64>>.
665 In the put routines, @var{val} must be a <<bfd_vma>>. If we are on a
666 system without prototypes, the caller is responsible for making
667 sure that is true, with a cast if necessary. We don't cast
668 them in the macro definitions because that would prevent <<lint>>
669 or <<gcc -Wall>> from detecting sins such as passing a pointer.
670 To detect calling these with less than a <<bfd_vma>>, use
671 <<gcc -Wconversion>> on a host with 64 bit <<bfd_vma>>'s.
674 .{* Byte swapping macros for user section data. *}
676 .#define bfd_put_8(abfd, val, ptr) \
677 . (*((unsigned char *)(ptr)) = (unsigned char)(val))
678 .#define bfd_put_signed_8 \
680 .#define bfd_get_8(abfd, ptr) \
681 . (*(unsigned char *)(ptr))
682 .#define bfd_get_signed_8(abfd, ptr) \
683 . ((*(unsigned char *)(ptr) ^ 0x80) - 0x80)
685 .#define bfd_put_16(abfd, val, ptr) \
686 . BFD_SEND(abfd, bfd_putx16, ((val),(ptr)))
687 .#define bfd_put_signed_16 \
689 .#define bfd_get_16(abfd, ptr) \
690 . BFD_SEND(abfd, bfd_getx16, (ptr))
691 .#define bfd_get_signed_16(abfd, ptr) \
692 . BFD_SEND (abfd, bfd_getx_signed_16, (ptr))
694 .#define bfd_put_32(abfd, val, ptr) \
695 . BFD_SEND(abfd, bfd_putx32, ((val),(ptr)))
696 .#define bfd_put_signed_32 \
698 .#define bfd_get_32(abfd, ptr) \
699 . BFD_SEND(abfd, bfd_getx32, (ptr))
700 .#define bfd_get_signed_32(abfd, ptr) \
701 . BFD_SEND(abfd, bfd_getx_signed_32, (ptr))
703 .#define bfd_put_64(abfd, val, ptr) \
704 . BFD_SEND(abfd, bfd_putx64, ((val), (ptr)))
705 .#define bfd_put_signed_64 \
707 .#define bfd_get_64(abfd, ptr) \
708 . BFD_SEND(abfd, bfd_getx64, (ptr))
709 .#define bfd_get_signed_64(abfd, ptr) \
710 . BFD_SEND(abfd, bfd_getx_signed_64, (ptr))
720 These macros have the same function as their <<bfd_get_x>>
721 bretheren, except that they are used for removing information
722 for the header records of object files. Believe it or not,
723 some object files keep their header records in big endian
724 order and their data in little endian order.
726 .{* Byte swapping macros for file header data. *}
728 .#define bfd_h_put_8(abfd, val, ptr) \
729 . bfd_put_8 (abfd, val, ptr)
730 .#define bfd_h_put_signed_8(abfd, val, ptr) \
731 . bfd_put_8 (abfd, val, ptr)
732 .#define bfd_h_get_8(abfd, ptr) \
733 . bfd_get_8 (abfd, ptr)
734 .#define bfd_h_get_signed_8(abfd, ptr) \
735 . bfd_get_signed_8 (abfd, ptr)
737 .#define bfd_h_put_16(abfd, val, ptr) \
738 . BFD_SEND(abfd, bfd_h_putx16,(val,ptr))
739 .#define bfd_h_put_signed_16 \
741 .#define bfd_h_get_16(abfd, ptr) \
742 . BFD_SEND(abfd, bfd_h_getx16,(ptr))
743 .#define bfd_h_get_signed_16(abfd, ptr) \
744 . BFD_SEND(abfd, bfd_h_getx_signed_16, (ptr))
746 .#define bfd_h_put_32(abfd, val, ptr) \
747 . BFD_SEND(abfd, bfd_h_putx32,(val,ptr))
748 .#define bfd_h_put_signed_32 \
750 .#define bfd_h_get_32(abfd, ptr) \
751 . BFD_SEND(abfd, bfd_h_getx32,(ptr))
752 .#define bfd_h_get_signed_32(abfd, ptr) \
753 . BFD_SEND(abfd, bfd_h_getx_signed_32, (ptr))
755 .#define bfd_h_put_64(abfd, val, ptr) \
756 . BFD_SEND(abfd, bfd_h_putx64,(val, ptr))
757 .#define bfd_h_put_signed_64 \
759 .#define bfd_h_get_64(abfd, ptr) \
760 . BFD_SEND(abfd, bfd_h_getx64,(ptr))
761 .#define bfd_h_get_signed_64(abfd, ptr) \
762 . BFD_SEND(abfd, bfd_h_getx_signed_64, (ptr))
766 /* Sign extension to bfd_signed_vma. */
767 #define COERCE16(x) (((bfd_signed_vma) (x) ^ 0x8000) - 0x8000)
768 #define COERCE32(x) (((bfd_signed_vma) (x) ^ 0x80000000) - 0x80000000)
769 #define EIGHT_GAZILLION (((BFD_HOST_64_BIT)0x80000000) << 32)
770 #define COERCE64(x) \
771 (((bfd_signed_vma) (x) ^ EIGHT_GAZILLION) - EIGHT_GAZILLION)
775 register const bfd_byte
*addr
;
777 return (addr
[0] << 8) | addr
[1];
782 register const bfd_byte
*addr
;
784 return (addr
[1] << 8) | addr
[0];
788 bfd_getb_signed_16 (addr
)
789 register const bfd_byte
*addr
;
791 return COERCE16((addr
[0] << 8) | addr
[1]);
795 bfd_getl_signed_16 (addr
)
796 register const bfd_byte
*addr
;
798 return COERCE16((addr
[1] << 8) | addr
[0]);
802 bfd_putb16 (data
, addr
)
804 register bfd_byte
*addr
;
806 addr
[0] = (bfd_byte
)(data
>> 8);
807 addr
[1] = (bfd_byte
)data
;
811 bfd_putl16 (data
, addr
)
813 register bfd_byte
*addr
;
815 addr
[0] = (bfd_byte
)data
;
816 addr
[1] = (bfd_byte
)(data
>> 8);
821 register const bfd_byte
*addr
;
823 return (((((bfd_vma
)addr
[0] << 8) | addr
[1]) << 8)
824 | addr
[2]) << 8 | addr
[3];
829 register const bfd_byte
*addr
;
831 return (((((bfd_vma
)addr
[3] << 8) | addr
[2]) << 8)
832 | addr
[1]) << 8 | addr
[0];
836 bfd_getb_signed_32 (addr
)
837 register const bfd_byte
*addr
;
839 return COERCE32((((((bfd_vma
)addr
[0] << 8) | addr
[1]) << 8)
840 | addr
[2]) << 8 | addr
[3]);
844 bfd_getl_signed_32 (addr
)
845 register const bfd_byte
*addr
;
847 return COERCE32((((((bfd_vma
)addr
[3] << 8) | addr
[2]) << 8)
848 | addr
[1]) << 8 | addr
[0]);
853 register const bfd_byte
*addr
;
858 high
= ((((((((addr
[0]) << 8) |
863 low
= (((((((((bfd_vma
)addr
[4]) << 8) |
868 return high
<< 32 | low
;
877 register const bfd_byte
*addr
;
881 high
= (((((((addr
[7] << 8) |
886 low
= ((((((((bfd_vma
)addr
[3] << 8) |
891 return high
<< 32 | low
;
900 bfd_getb_signed_64 (addr
)
901 register const bfd_byte
*addr
;
906 high
= ((((((((addr
[0]) << 8) |
911 low
= (((((((((bfd_vma
)addr
[4]) << 8) |
916 return COERCE64(high
<< 32 | low
);
924 bfd_getl_signed_64 (addr
)
925 register const bfd_byte
*addr
;
929 high
= (((((((addr
[7] << 8) |
934 low
= ((((((((bfd_vma
)addr
[3] << 8) |
939 return COERCE64(high
<< 32 | low
);
947 bfd_putb32 (data
, addr
)
949 register bfd_byte
*addr
;
951 addr
[0] = (bfd_byte
)(data
>> 24);
952 addr
[1] = (bfd_byte
)(data
>> 16);
953 addr
[2] = (bfd_byte
)(data
>> 8);
954 addr
[3] = (bfd_byte
)data
;
958 bfd_putl32 (data
, addr
)
960 register bfd_byte
*addr
;
962 addr
[0] = (bfd_byte
)data
;
963 addr
[1] = (bfd_byte
)(data
>> 8);
964 addr
[2] = (bfd_byte
)(data
>> 16);
965 addr
[3] = (bfd_byte
)(data
>> 24);
969 bfd_putb64 (data
, addr
)
971 register bfd_byte
*addr
;
974 addr
[0] = (bfd_byte
)(data
>> (7*8));
975 addr
[1] = (bfd_byte
)(data
>> (6*8));
976 addr
[2] = (bfd_byte
)(data
>> (5*8));
977 addr
[3] = (bfd_byte
)(data
>> (4*8));
978 addr
[4] = (bfd_byte
)(data
>> (3*8));
979 addr
[5] = (bfd_byte
)(data
>> (2*8));
980 addr
[6] = (bfd_byte
)(data
>> (1*8));
981 addr
[7] = (bfd_byte
)(data
>> (0*8));
988 bfd_putl64 (data
, addr
)
990 register bfd_byte
*addr
;
993 addr
[7] = (bfd_byte
)(data
>> (7*8));
994 addr
[6] = (bfd_byte
)(data
>> (6*8));
995 addr
[5] = (bfd_byte
)(data
>> (5*8));
996 addr
[4] = (bfd_byte
)(data
>> (4*8));
997 addr
[3] = (bfd_byte
)(data
>> (3*8));
998 addr
[2] = (bfd_byte
)(data
>> (2*8));
999 addr
[1] = (bfd_byte
)(data
>> (1*8));
1000 addr
[0] = (bfd_byte
)(data
>> (0*8));
1006 /* Default implementation */
1009 _bfd_generic_get_section_contents (abfd
, section
, location
, offset
, count
)
1014 bfd_size_type count
;
1018 if ((bfd_size_type
)(offset
+count
) > section
->_raw_size
1019 || bfd_seek(abfd
, (file_ptr
)(section
->filepos
+ offset
), SEEK_SET
) == -1
1020 || bfd_read(location
, (bfd_size_type
)1, count
, abfd
) != count
)
1021 return (false); /* on error */
1026 _bfd_generic_get_section_contents_in_window (abfd
, section
, w
, offset
, count
)
1031 bfd_size_type count
;
1036 if (abfd
->xvec
->_bfd_get_section_contents
!= _bfd_generic_get_section_contents
)
1038 /* We don't know what changes the bfd's get_section_contents
1039 method may have to make. So punt trying to map the file
1040 window, and let get_section_contents do its thing. */
1041 /* @@ FIXME : If the internal window has a refcount of 1 and was
1042 allocated with malloc instead of mmap, just reuse it. */
1043 bfd_free_window (w
);
1044 w
->i
= (bfd_window_internal
*) bfd_zmalloc (sizeof (bfd_window_internal
));
1047 w
->i
->data
= (PTR
) malloc ((size_t) count
);
1048 if (w
->i
->data
== NULL
)
1056 w
->size
= w
->i
->size
= count
;
1057 w
->data
= w
->i
->data
;
1058 return bfd_get_section_contents (abfd
, section
, w
->data
, offset
, count
);
1060 if ((bfd_size_type
) (offset
+count
) > section
->_raw_size
1061 || (bfd_get_file_window (abfd
, section
->filepos
+ offset
, count
, w
, true)
1070 /* This generic function can only be used in implementations where creating
1071 NEW sections is disallowed. It is useful in patching existing sections
1072 in read-write files, though. See other set_section_contents functions
1073 to see why it doesn't work for new sections. */
1075 _bfd_generic_set_section_contents (abfd
, section
, location
, offset
, count
)
1080 bfd_size_type count
;
1085 if (bfd_seek (abfd
, (file_ptr
) (section
->filepos
+ offset
), SEEK_SET
) == -1
1086 || bfd_write (location
, (bfd_size_type
) 1, count
, abfd
) != count
)
1097 unsigned int bfd_log2(bfd_vma x);
1100 Return the log base 2 of the value supplied, rounded up. E.g., an
1101 @var{x} of 1025 returns 11.
1108 unsigned result
= 0;
1109 while ( (bfd_vma
)(1<< result
) < x
)
1115 bfd_generic_is_local_label (abfd
, sym
)
1119 char locals_prefix
= (bfd_get_symbol_leading_char (abfd
) == '_') ? 'L' : '.';
1121 return (sym
->name
[0] == locals_prefix
);