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
);
169 memset(ptr
, 0, (size_t) size
);
173 #endif /* bfd_zmalloc */
178 /* Note that archive entries don't have streams; they share their parent's.
179 This allows someone to play with the iostream behind BFD's back.
181 Also, note that the origin pointer points to the beginning of a file's
182 contents (0 for non-archive elements). For archive entries this is the
183 first octet in the file, NOT the beginning of the archive header. */
186 real_read (where
, a
,b
, file
)
192 return fread (where
, a
, b
, file
);
195 /* Return value is amount read (FIXME: how are errors and end of file dealt
196 with? We never call bfd_set_error, which is probably a mistake). */
199 bfd_read (ptr
, size
, nitems
, abfd
)
202 bfd_size_type nitems
;
206 nread
= real_read (ptr
, 1, (size_t)(size
*nitems
), bfd_cache_lookup(abfd
));
207 #ifdef FILE_OFFSET_IS_CHAR_INDEX
209 abfd
->where
+= nread
;
212 /* Set bfd_error if we did not read as much data as we expected.
214 If the read failed due to an error set the bfd_error_system_call,
215 else set bfd_error_file_truncated.
217 A BFD backend may wish to override bfd_error_file_truncated to
218 provide something more useful (eg. no_symbols or wrong_format). */
219 if (nread
< (int)(size
* nitems
))
221 if (ferror (bfd_cache_lookup (abfd
)))
222 bfd_set_error (bfd_error_system_call
);
224 bfd_set_error (bfd_error_file_truncated
);
230 /* The window support stuff should probably be broken out into
232 /* The idea behind the next and refcount fields is that one mapped
233 region can suffice for multiple read-only windows or multiple
234 non-overlapping read-write windows. It's not implemented yet
236 struct _bfd_window_internal
{
237 struct _bfd_window_internal
*next
;
240 int refcount
: 31; /* should be enough... */
241 unsigned mapped
: 1; /* 1 = mmap, 0 = malloc */
245 bfd_init_window (windowp
)
253 #undef HAVE_MPROTECT /* code's not tested yet */
255 #if HAVE_MMAP || HAVE_MPROTECT
256 #include <sys/types.h>
257 #include <sys/mman.h>
264 static int debug_windows
;
267 bfd_free_window (windowp
)
270 bfd_window_internal
*i
= windowp
->i
;
277 fprintf (stderr
, "freeing window @%p<%p,%lx,%p>\n",
278 windowp
, windowp
->data
, windowp
->size
, windowp
->i
);
279 if (i
->refcount
!= 0)
285 munmap (i
->data
, i
->size
);
292 mprotect (i
->data
, i
->size
, PROT_READ
| PROT_WRITE
);
299 /* There should be no more references to i at this point. */
303 static int ok_to_map
= 1;
306 bfd_get_file_window (abfd
, offset
, size
, windowp
, writable
)
313 static size_t pagesize
;
314 bfd_window_internal
*i
= windowp
->i
;
315 size_t size_to_alloc
= size
;
318 fprintf (stderr
, "bfd_get_file_window (%p, %6ld, %6ld, %p<%p,%lx,%p>, %d)",
319 abfd
, (long) offset
, (long) size
,
320 windowp
, windowp
->data
, windowp
->size
, windowp
->i
,
323 /* Make sure we know the page size, so we can be friendly to mmap. */
325 pagesize
= getpagesize ();
331 windowp
->i
= i
= (bfd_window_internal
*) bfd_zmalloc (sizeof (bfd_window_internal
));
337 if (ok_to_map
&& (i
->data
== 0 || i
->mapped
== 1))
339 file_ptr file_offset
, offset2
;
344 /* Find the real file and the real offset into it. */
345 while (abfd
->my_archive
!= NULL
)
347 offset
+= abfd
->origin
;
348 abfd
= abfd
->my_archive
;
350 f
= bfd_cache_lookup (abfd
);
353 /* Compute offsets and size for mmap and for the user's data. */
354 offset2
= offset
% pagesize
;
357 file_offset
= offset
- offset2
;
358 real_size
= offset
+ size
- file_offset
;
359 real_size
= real_size
+ pagesize
- 1;
360 real_size
-= real_size
% pagesize
;
362 /* If we're re-using a memory region, make sure it's big enough. */
363 if (i
->data
&& i
->size
< size
)
365 munmap (i
->data
, i
->size
);
368 i
->data
= mmap (i
->data
, real_size
,
369 writable
? PROT_WRITE
| PROT_READ
: PROT_READ
,
371 ? MAP_FILE
| MAP_PRIVATE
372 : MAP_FILE
| MAP_SHARED
),
374 if (i
->data
== (PTR
) -1)
376 /* An error happened. Report it, or try using malloc, or
378 bfd_set_error (bfd_error_system_call
);
382 fprintf (stderr
, "\t\tmmap failed!\n");
386 fprintf (stderr
, "\n\tmapped %ld at %p, offset is %ld\n",
387 (long) real_size
, i
->data
, (long) offset2
);
389 windowp
->data
= i
->data
+ offset2
;
390 windowp
->size
= size
;
394 else if (debug_windows
)
397 fprintf (stderr
, "not mapping: data=%x mapped=%d\n",
398 i
->data
, (int) i
->mapped
);
400 fprintf (stderr
, "not mapping: env var not set\n");
409 size_to_alloc
+= pagesize
- 1;
410 size_to_alloc
-= size_to_alloc
% pagesize
;
414 fprintf (stderr
, "\n\t%s(%6ld)",
415 i
->data
? "realloc" : " malloc", (long) size_to_alloc
);
417 i
->data
= (PTR
) realloc (i
->data
, size_to_alloc
);
419 i
->data
= (PTR
) malloc (size_to_alloc
);
421 fprintf (stderr
, "\t-> %p\n", i
->data
);
425 if (size_to_alloc
== 0)
427 bfd_set_error (bfd_error_no_memory
);
430 if (bfd_seek (abfd
, offset
, SEEK_SET
) != 0)
432 i
->size
= bfd_read (i
->data
, size
, 1, abfd
);
440 fprintf (stderr
, "\tmprotect (%p, %ld, PROT_READ)\n", i
->data
,
442 mprotect (i
->data
, i
->size
, PROT_READ
);
445 windowp
->data
= i
->data
;
446 windowp
->size
= i
->size
;
451 bfd_write (ptr
, size
, nitems
, abfd
)
454 bfd_size_type nitems
;
457 long nwrote
= fwrite (ptr
, 1, (size_t) (size
* nitems
),
458 bfd_cache_lookup (abfd
));
459 #ifdef FILE_OFFSET_IS_CHAR_INDEX
461 abfd
->where
+= nwrote
;
463 if ((bfd_size_type
) nwrote
!= size
* nitems
)
469 bfd_set_error (bfd_error_system_call
);
476 bfd_write_bigendian_4byte_int
479 void bfd_write_bigendian_4byte_int(bfd *abfd, int i);
482 Write a 4 byte integer @var{i} to the output BFD @var{abfd}, in big
483 endian order regardless of what else is going on. This is useful in
488 bfd_write_bigendian_4byte_int (abfd
, i
)
493 bfd_putb32(i
, buffer
);
494 if (bfd_write((PTR
)buffer
, 4, 1, abfd
) != 4)
504 ptr
= ftell (bfd_cache_lookup(abfd
));
506 if (abfd
->my_archive
)
516 return fflush (bfd_cache_lookup(abfd
));
519 /* Returns 0 for success, negative value for failure (in which case
520 bfd_get_error can retrieve the error code). */
522 bfd_stat (abfd
, statbuf
)
524 struct stat
*statbuf
;
528 f
= bfd_cache_lookup (abfd
);
531 bfd_set_error (bfd_error_system_call
);
534 result
= fstat (fileno (f
), statbuf
);
536 bfd_set_error (bfd_error_system_call
);
540 /* Returns 0 for success, nonzero for failure (in which case bfd_get_error
541 can retrieve the error code). */
544 bfd_seek (abfd
, position
, direction
)
551 file_ptr file_position
;
552 /* For the time being, a BFD may not seek to it's end. The problem
553 is that we don't easily have a way to recognize the end of an
554 element in an archive. */
556 BFD_ASSERT (direction
== SEEK_SET
|| direction
== SEEK_CUR
);
558 if (direction
== SEEK_CUR
&& position
== 0)
560 #ifdef FILE_OFFSET_IS_CHAR_INDEX
561 if (abfd
->format
!= bfd_archive
&& abfd
->my_archive
== 0)
564 /* Explanation for this code: I'm only about 95+% sure that the above
565 conditions are sufficient and that all i/o calls are properly
566 adjusting the `where' field. So this is sort of an `assert'
567 that the `where' field is correct. If we can go a while without
568 tripping the abort, we can probably safely disable this code,
569 so that the real optimizations happen. */
570 file_ptr where_am_i_now
;
571 where_am_i_now
= ftell (bfd_cache_lookup (abfd
));
572 if (abfd
->my_archive
)
573 where_am_i_now
-= abfd
->origin
;
574 if (where_am_i_now
!= abfd
->where
)
577 if (direction
== SEEK_SET
&& position
== abfd
->where
)
582 /* We need something smarter to optimize access to archives.
583 Currently, anything inside an archive is read via the file
584 handle for the archive. Which means that a bfd_seek on one
585 component affects the `current position' in the archive, as
586 well as in any other component.
588 It might be sufficient to put a spike through the cache
589 abstraction, and look to the archive for the file position,
590 but I think we should try for something cleaner.
592 In the meantime, no optimization for archives. */
596 f
= bfd_cache_lookup (abfd
);
597 file_position
= position
;
598 if (direction
== SEEK_SET
&& abfd
->my_archive
!= NULL
)
599 file_position
+= abfd
->origin
;
601 result
= fseek (f
, file_position
, direction
);
605 /* Force redetermination of `where' field. */
607 bfd_set_error (bfd_error_system_call
);
611 #ifdef FILE_OFFSET_IS_CHAR_INDEX
612 /* Adjust `where' field. */
613 if (direction
== SEEK_SET
)
614 abfd
->where
= position
;
616 abfd
->where
+= position
;
622 /** The do-it-yourself (byte) sex-change kit */
624 /* The middle letter e.g. get<b>short indicates Big or Little endian
625 target machine. It doesn't matter what the byte order of the host
626 machine is; these routines work for either. */
628 /* FIXME: Should these take a count argument?
629 Answer (gnu@cygnus.com): No, but perhaps they should be inline
630 functions in swap.h #ifdef __GNUC__.
631 Gprof them later and find out. */
640 These macros as used for reading and writing raw data in
641 sections; each access (except for bytes) is vectored through
642 the target format of the BFD and mangled accordingly. The
643 mangling performs any necessary endian translations and
644 removes alignment restrictions. Note that types accepted and
645 returned by these macros are identical so they can be swapped
646 around in macros---for example, @file{libaout.h} defines <<GET_WORD>>
647 to either <<bfd_get_32>> or <<bfd_get_64>>.
649 In the put routines, @var{val} must be a <<bfd_vma>>. If we are on a
650 system without prototypes, the caller is responsible for making
651 sure that is true, with a cast if necessary. We don't cast
652 them in the macro definitions because that would prevent <<lint>>
653 or <<gcc -Wall>> from detecting sins such as passing a pointer.
654 To detect calling these with less than a <<bfd_vma>>, use
655 <<gcc -Wconversion>> on a host with 64 bit <<bfd_vma>>'s.
658 .{* Byte swapping macros for user section data. *}
660 .#define bfd_put_8(abfd, val, ptr) \
661 . (*((unsigned char *)(ptr)) = (unsigned char)(val))
662 .#define bfd_put_signed_8 \
664 .#define bfd_get_8(abfd, ptr) \
665 . (*(unsigned char *)(ptr))
666 .#define bfd_get_signed_8(abfd, ptr) \
667 . ((*(unsigned char *)(ptr) ^ 0x80) - 0x80)
669 .#define bfd_put_16(abfd, val, ptr) \
670 . BFD_SEND(abfd, bfd_putx16, ((val),(ptr)))
671 .#define bfd_put_signed_16 \
673 .#define bfd_get_16(abfd, ptr) \
674 . BFD_SEND(abfd, bfd_getx16, (ptr))
675 .#define bfd_get_signed_16(abfd, ptr) \
676 . BFD_SEND (abfd, bfd_getx_signed_16, (ptr))
678 .#define bfd_put_32(abfd, val, ptr) \
679 . BFD_SEND(abfd, bfd_putx32, ((val),(ptr)))
680 .#define bfd_put_signed_32 \
682 .#define bfd_get_32(abfd, ptr) \
683 . BFD_SEND(abfd, bfd_getx32, (ptr))
684 .#define bfd_get_signed_32(abfd, ptr) \
685 . BFD_SEND(abfd, bfd_getx_signed_32, (ptr))
687 .#define bfd_put_64(abfd, val, ptr) \
688 . BFD_SEND(abfd, bfd_putx64, ((val), (ptr)))
689 .#define bfd_put_signed_64 \
691 .#define bfd_get_64(abfd, ptr) \
692 . BFD_SEND(abfd, bfd_getx64, (ptr))
693 .#define bfd_get_signed_64(abfd, ptr) \
694 . BFD_SEND(abfd, bfd_getx_signed_64, (ptr))
704 These macros have the same function as their <<bfd_get_x>>
705 bretheren, except that they are used for removing information
706 for the header records of object files. Believe it or not,
707 some object files keep their header records in big endian
708 order and their data in little endian order.
710 .{* Byte swapping macros for file header data. *}
712 .#define bfd_h_put_8(abfd, val, ptr) \
713 . bfd_put_8 (abfd, val, ptr)
714 .#define bfd_h_put_signed_8(abfd, val, ptr) \
715 . bfd_put_8 (abfd, val, ptr)
716 .#define bfd_h_get_8(abfd, ptr) \
717 . bfd_get_8 (abfd, ptr)
718 .#define bfd_h_get_signed_8(abfd, ptr) \
719 . bfd_get_signed_8 (abfd, ptr)
721 .#define bfd_h_put_16(abfd, val, ptr) \
722 . BFD_SEND(abfd, bfd_h_putx16,(val,ptr))
723 .#define bfd_h_put_signed_16 \
725 .#define bfd_h_get_16(abfd, ptr) \
726 . BFD_SEND(abfd, bfd_h_getx16,(ptr))
727 .#define bfd_h_get_signed_16(abfd, ptr) \
728 . BFD_SEND(abfd, bfd_h_getx_signed_16, (ptr))
730 .#define bfd_h_put_32(abfd, val, ptr) \
731 . BFD_SEND(abfd, bfd_h_putx32,(val,ptr))
732 .#define bfd_h_put_signed_32 \
734 .#define bfd_h_get_32(abfd, ptr) \
735 . BFD_SEND(abfd, bfd_h_getx32,(ptr))
736 .#define bfd_h_get_signed_32(abfd, ptr) \
737 . BFD_SEND(abfd, bfd_h_getx_signed_32, (ptr))
739 .#define bfd_h_put_64(abfd, val, ptr) \
740 . BFD_SEND(abfd, bfd_h_putx64,(val, ptr))
741 .#define bfd_h_put_signed_64 \
743 .#define bfd_h_get_64(abfd, ptr) \
744 . BFD_SEND(abfd, bfd_h_getx64,(ptr))
745 .#define bfd_h_get_signed_64(abfd, ptr) \
746 . BFD_SEND(abfd, bfd_h_getx_signed_64, (ptr))
750 /* Sign extension to bfd_signed_vma. */
751 #define COERCE16(x) (((bfd_signed_vma) (x) ^ 0x8000) - 0x8000)
752 #define COERCE32(x) (((bfd_signed_vma) (x) ^ 0x80000000) - 0x80000000)
753 #define EIGHT_GAZILLION (((BFD_HOST_64_BIT)0x80000000) << 32)
754 #define COERCE64(x) \
755 (((bfd_signed_vma) (x) ^ EIGHT_GAZILLION) - EIGHT_GAZILLION)
759 register const bfd_byte
*addr
;
761 return (addr
[0] << 8) | addr
[1];
766 register const bfd_byte
*addr
;
768 return (addr
[1] << 8) | addr
[0];
772 bfd_getb_signed_16 (addr
)
773 register const bfd_byte
*addr
;
775 return COERCE16((addr
[0] << 8) | addr
[1]);
779 bfd_getl_signed_16 (addr
)
780 register const bfd_byte
*addr
;
782 return COERCE16((addr
[1] << 8) | addr
[0]);
786 bfd_putb16 (data
, addr
)
788 register bfd_byte
*addr
;
790 addr
[0] = (bfd_byte
)(data
>> 8);
791 addr
[1] = (bfd_byte
)data
;
795 bfd_putl16 (data
, addr
)
797 register bfd_byte
*addr
;
799 addr
[0] = (bfd_byte
)data
;
800 addr
[1] = (bfd_byte
)(data
>> 8);
805 register const bfd_byte
*addr
;
807 return (((((bfd_vma
)addr
[0] << 8) | addr
[1]) << 8)
808 | addr
[2]) << 8 | addr
[3];
813 register const bfd_byte
*addr
;
815 return (((((bfd_vma
)addr
[3] << 8) | addr
[2]) << 8)
816 | addr
[1]) << 8 | addr
[0];
820 bfd_getb_signed_32 (addr
)
821 register const bfd_byte
*addr
;
823 return COERCE32((((((bfd_vma
)addr
[0] << 8) | addr
[1]) << 8)
824 | addr
[2]) << 8 | addr
[3]);
828 bfd_getl_signed_32 (addr
)
829 register const bfd_byte
*addr
;
831 return COERCE32((((((bfd_vma
)addr
[3] << 8) | addr
[2]) << 8)
832 | addr
[1]) << 8 | addr
[0]);
837 register const bfd_byte
*addr
;
842 high
= ((((((((addr
[0]) << 8) |
847 low
= (((((((((bfd_vma
)addr
[4]) << 8) |
852 return high
<< 32 | low
;
861 register const bfd_byte
*addr
;
865 high
= (((((((addr
[7] << 8) |
870 low
= ((((((((bfd_vma
)addr
[3] << 8) |
875 return high
<< 32 | low
;
884 bfd_getb_signed_64 (addr
)
885 register const bfd_byte
*addr
;
890 high
= ((((((((addr
[0]) << 8) |
895 low
= (((((((((bfd_vma
)addr
[4]) << 8) |
900 return COERCE64(high
<< 32 | low
);
908 bfd_getl_signed_64 (addr
)
909 register const bfd_byte
*addr
;
913 high
= (((((((addr
[7] << 8) |
918 low
= ((((((((bfd_vma
)addr
[3] << 8) |
923 return COERCE64(high
<< 32 | low
);
931 bfd_putb32 (data
, addr
)
933 register bfd_byte
*addr
;
935 addr
[0] = (bfd_byte
)(data
>> 24);
936 addr
[1] = (bfd_byte
)(data
>> 16);
937 addr
[2] = (bfd_byte
)(data
>> 8);
938 addr
[3] = (bfd_byte
)data
;
942 bfd_putl32 (data
, addr
)
944 register bfd_byte
*addr
;
946 addr
[0] = (bfd_byte
)data
;
947 addr
[1] = (bfd_byte
)(data
>> 8);
948 addr
[2] = (bfd_byte
)(data
>> 16);
949 addr
[3] = (bfd_byte
)(data
>> 24);
953 bfd_putb64 (data
, addr
)
955 register bfd_byte
*addr
;
958 addr
[0] = (bfd_byte
)(data
>> (7*8));
959 addr
[1] = (bfd_byte
)(data
>> (6*8));
960 addr
[2] = (bfd_byte
)(data
>> (5*8));
961 addr
[3] = (bfd_byte
)(data
>> (4*8));
962 addr
[4] = (bfd_byte
)(data
>> (3*8));
963 addr
[5] = (bfd_byte
)(data
>> (2*8));
964 addr
[6] = (bfd_byte
)(data
>> (1*8));
965 addr
[7] = (bfd_byte
)(data
>> (0*8));
972 bfd_putl64 (data
, addr
)
974 register bfd_byte
*addr
;
977 addr
[7] = (bfd_byte
)(data
>> (7*8));
978 addr
[6] = (bfd_byte
)(data
>> (6*8));
979 addr
[5] = (bfd_byte
)(data
>> (5*8));
980 addr
[4] = (bfd_byte
)(data
>> (4*8));
981 addr
[3] = (bfd_byte
)(data
>> (3*8));
982 addr
[2] = (bfd_byte
)(data
>> (2*8));
983 addr
[1] = (bfd_byte
)(data
>> (1*8));
984 addr
[0] = (bfd_byte
)(data
>> (0*8));
990 /* Default implementation */
993 _bfd_generic_get_section_contents (abfd
, section
, location
, offset
, count
)
1002 if ((bfd_size_type
)(offset
+count
) > section
->_raw_size
1003 || bfd_seek(abfd
, (file_ptr
)(section
->filepos
+ offset
), SEEK_SET
) == -1
1004 || bfd_read(location
, (bfd_size_type
)1, count
, abfd
) != count
)
1005 return (false); /* on error */
1010 _bfd_generic_get_section_contents_in_window (abfd
, section
, w
, offset
, count
)
1015 bfd_size_type count
;
1019 if (abfd
->xvec
->_bfd_get_section_contents
!= _bfd_generic_get_section_contents
)
1021 /* We don't know what changes the bfd's get_section_contents
1022 method may have to make. So punt trying to map the file
1023 window, and let get_section_contents do its thing. */
1024 /* @@ FIXME : If the internal window has a refcount of 1 and was
1025 allocated with malloc instead of mmap, just reuse it. */
1026 bfd_free_window (w
);
1027 w
->i
= (bfd_window_internal
*) bfd_zmalloc (sizeof (bfd_window_internal
));
1030 w
->i
->data
= (PTR
) malloc ((size_t) count
);
1031 if (w
->i
->data
== NULL
)
1039 w
->size
= w
->i
->size
= count
;
1040 w
->data
= w
->i
->data
;
1041 return bfd_get_section_contents (abfd
, section
, w
->data
, offset
, count
);
1043 if ((bfd_size_type
) (offset
+count
) > section
->_raw_size
1044 || (bfd_get_file_window (abfd
, section
->filepos
+ offset
, count
, w
, true)
1050 /* This generic function can only be used in implementations where creating
1051 NEW sections is disallowed. It is useful in patching existing sections
1052 in read-write files, though. See other set_section_contents functions
1053 to see why it doesn't work for new sections. */
1055 _bfd_generic_set_section_contents (abfd
, section
, location
, offset
, count
)
1060 bfd_size_type count
;
1065 if (bfd_seek (abfd
, (file_ptr
) (section
->filepos
+ offset
), SEEK_SET
) == -1
1066 || bfd_write (location
, (bfd_size_type
) 1, count
, abfd
) != count
)
1077 unsigned int bfd_log2(bfd_vma x);
1080 Return the log base 2 of the value supplied, rounded up. E.g., an
1081 @var{x} of 1025 returns 11.
1088 unsigned result
= 0;
1089 while ( (bfd_vma
)(1<< result
) < x
)
1095 bfd_generic_is_local_label (abfd
, sym
)
1099 char locals_prefix
= (bfd_get_symbol_leading_char (abfd
) == '_') ? 'L' : '.';
1101 return (sym
->name
[0] == locals_prefix
);