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);
158 /* Allocate memory using malloc. */
166 ptr = (PTR) malloc (size);
167 if (ptr == NULL && size != 0)
168 bfd_set_error (bfd_error_no_memory);
172 /* Reallocate memory using realloc. */
175 bfd_realloc (ptr, size)
184 ret = realloc (ptr, size);
187 bfd_set_error (bfd_error_no_memory);
192 /* Allocate memory using malloc and clear it. */
200 ptr = (PTR) malloc (size);
205 bfd_set_error (bfd_error_no_memory);
207 memset (ptr, 0, size);
216 /* Note that archive entries don't have streams; they share their parent's.
217 This allows someone to play with the iostream behind BFD's back.
219 Also, note that the origin pointer points to the beginning of a file's
220 contents (0 for non-archive elements). For archive entries this is the
221 first octet in the file, NOT the beginning of the archive header. */
224 real_read (where, a,b, file)
230 return fread (where, a, b, file);
233 /* Return value is amount read (FIXME: how are errors and end of file dealt
234 with? We never call bfd_set_error, which is probably a mistake). */
237 bfd_read (ptr, size, nitems, abfd)
240 bfd_size_type nitems;
245 if ((abfd->flags & BFD_IN_MEMORY) != 0)
247 struct bfd_in_memory *bim;
250 bim = (struct bfd_in_memory *) abfd->iostream;
252 if (abfd->where + get > bim->size)
254 get = bim->size - abfd->where;
255 bfd_set_error (bfd_error_file_truncated);
257 memcpy (ptr, bim->buffer + abfd->where, get);
262 nread = real_read (ptr, 1, (size_t)(size*nitems), bfd_cache_lookup(abfd));
263 #ifdef FILE_OFFSET_IS_CHAR_INDEX
265 abfd->where += nread;
268 /* Set bfd_error if we did not read as much data as we expected.
270 If the read failed due to an error set the bfd_error_system_call,
271 else set bfd_error_file_truncated.
273 A BFD backend may wish to override bfd_error_file_truncated to
274 provide something more useful (eg. no_symbols or wrong_format). */
275 if (nread < (int)(size * nitems))
277 if (ferror (bfd_cache_lookup (abfd)))
278 bfd_set_error (bfd_error_system_call);
280 bfd_set_error (bfd_error_file_truncated);
286 /* The window support stuff should probably be broken out into
288 /* The idea behind the next and refcount fields is that one mapped
289 region can suffice for multiple read-only windows or multiple
290 non-overlapping read-write windows. It's not implemented yet
292 struct _bfd_window_internal {
293 struct _bfd_window_internal *next;
296 int refcount : 31; /* should be enough... */
297 unsigned mapped : 1; /* 1 = mmap, 0 = malloc */
301 bfd_init_window (windowp)
309 #undef HAVE_MPROTECT /* code's not tested yet */
311 #if HAVE_MMAP || HAVE_MPROTECT || HAVE_MADVISE
312 #include <sys/types.h>
313 #include <sys/mman.h>
320 static int debug_windows;
322 /* Currently, if USE_MMAP is undefined, none if the window stuff is
323 used. Okay, so it's mis-named. At least the command-line option
324 "--without-mmap" is more obvious than "--without-windows" or some
329 bfd_free_window (windowp)
332 bfd_window_internal *i = windowp->i;
339 fprintf (stderr, "freeing window @%p<%p,%lx,%p>\n",
340 windowp, windowp->data, windowp->size, windowp->i);
341 if (i->refcount != 0)
347 munmap (i->data, i->size);
354 mprotect (i->data, i->size, PROT_READ | PROT_WRITE);
361 /* There should be no more references to i at this point. */
366 static int ok_to_map = 1;
369 bfd_get_file_window (abfd, offset, size, windowp, writable)
376 static size_t pagesize;
377 bfd_window_internal *i = windowp->i;
378 size_t size_to_alloc = size;
385 fprintf (stderr, "bfd_get_file_window (%p, %6ld, %6ld, %p<%p,%lx,%p>, %d)",
386 abfd, (long) offset, (long) size,
387 windowp, windowp->data, windowp->size, windowp->i,
390 /* Make sure we know the page size, so we can be friendly to mmap. */
392 pagesize = getpagesize ();
398 windowp->i = i = (bfd_window_internal *) bfd_zmalloc (sizeof (bfd_window_internal));
405 && (i->data == 0 || i->mapped == 1)
406 && (abfd->flags & BFD_IN_MEMORY) == 0)
408 file_ptr file_offset, offset2;
413 /* Find the real file and the real offset into it. */
414 while (abfd->my_archive != NULL)
416 offset += abfd->origin;
417 abfd = abfd->my_archive;
419 f = bfd_cache_lookup (abfd);
422 /* Compute offsets and size for mmap and for the user's data. */
423 offset2 = offset % pagesize;
426 file_offset = offset - offset2;
427 real_size = offset + size - file_offset;
428 real_size = real_size + pagesize - 1;
429 real_size -= real_size % pagesize;
431 /* If we're re-using a memory region, make sure it's big enough. */
432 if (i->data && i->size < size)
434 munmap (i->data, i->size);
437 i->data = mmap (i->data, real_size,
438 writable ? PROT_WRITE | PROT_READ : PROT_READ,
440 ? MAP_FILE | MAP_PRIVATE
441 : MAP_FILE | MAP_SHARED),
443 if (i->data == (PTR) -1)
445 /* An error happened. Report it, or try using malloc, or
447 bfd_set_error (bfd_error_system_call);
451 fprintf (stderr, "\t\tmmap failed!\n");
455 fprintf (stderr, "\n\tmapped %ld at %p, offset is %ld\n",
456 (long) real_size, i->data, (long) offset2);
458 windowp->data = (PTR) ((bfd_byte *) i->data + offset2);
459 windowp->size = size;
463 else if (debug_windows)
466 fprintf (stderr, "not mapping: data=%lx mapped=%d\n",
467 (unsigned long) i->data, (int) i->mapped);
469 fprintf (stderr, "not mapping: env var not set\n");
478 size_to_alloc += pagesize - 1;
479 size_to_alloc -= size_to_alloc % pagesize;
483 fprintf (stderr, "\n\t%s(%6ld)",
484 i->data ? "realloc" : " malloc", (long) size_to_alloc);
485 i->data = (PTR) bfd_realloc (i->data, size_to_alloc);
487 fprintf (stderr, "\t-> %p\n", i->data);
491 if (size_to_alloc == 0)
493 bfd_set_error (bfd_error_no_memory);
496 if (bfd_seek (abfd, offset, SEEK_SET) != 0)
498 i->size = bfd_read (i->data, size, 1, abfd);
506 fprintf (stderr, "\tmprotect (%p, %ld, PROT_READ)\n", i->data,
508 mprotect (i->data, i->size, PROT_READ);
511 windowp->data = i->data;
512 windowp->size = i->size;
517 bfd_write (ptr, size, nitems, abfd)
520 bfd_size_type nitems;
525 if ((abfd->flags & BFD_IN_MEMORY) != 0)
528 nwrote = fwrite (ptr, 1, (size_t) (size * nitems),
529 bfd_cache_lookup (abfd));
530 #ifdef FILE_OFFSET_IS_CHAR_INDEX
532 abfd->where += nwrote;
534 if ((bfd_size_type) nwrote != size * nitems)
540 bfd_set_error (bfd_error_system_call);
547 bfd_write_bigendian_4byte_int
550 void bfd_write_bigendian_4byte_int(bfd *abfd, int i);
553 Write a 4 byte integer @var{i} to the output BFD @var{abfd}, in big
554 endian order regardless of what else is going on. This is useful in
559 bfd_write_bigendian_4byte_int (abfd, i)
564 bfd_putb32(i, buffer);
565 if (bfd_write((PTR)buffer, 4, 1, abfd) != 4)
575 if ((abfd->flags & BFD_IN_MEMORY) != 0)
578 ptr = ftell (bfd_cache_lookup(abfd));
580 if (abfd->my_archive)
590 if ((abfd->flags & BFD_IN_MEMORY) != 0)
592 return fflush (bfd_cache_lookup(abfd));
595 /* Returns 0 for success, negative value for failure (in which case
596 bfd_get_error can retrieve the error code). */
598 bfd_stat (abfd, statbuf)
600 struct stat *statbuf;
605 if ((abfd->flags & BFD_IN_MEMORY) != 0)
608 f = bfd_cache_lookup (abfd);
611 bfd_set_error (bfd_error_system_call);
614 result = fstat (fileno (f), statbuf);
616 bfd_set_error (bfd_error_system_call);
620 /* Returns 0 for success, nonzero for failure (in which case bfd_get_error
621 can retrieve the error code). */
624 bfd_seek (abfd, position, direction)
631 file_ptr file_position;
632 /* For the time being, a BFD may not seek to it's end. The problem
633 is that we don't easily have a way to recognize the end of an
634 element in an archive. */
636 BFD_ASSERT (direction == SEEK_SET || direction == SEEK_CUR);
638 if (direction == SEEK_CUR && position == 0)
641 if ((abfd->flags & BFD_IN_MEMORY) != 0)
643 if (direction == SEEK_SET)
644 abfd->where = position;
646 abfd->where += position;
650 #ifdef FILE_OFFSET_IS_CHAR_INDEX
651 if (abfd->format != bfd_archive && abfd->my_archive == 0)
654 /* Explanation for this code: I'm only about 95+% sure that the above
655 conditions are sufficient and that all i/o calls are properly
656 adjusting the `where' field. So this is sort of an `assert'
657 that the `where' field is correct. If we can go a while without
658 tripping the abort, we can probably safely disable this code,
659 so that the real optimizations happen. */
660 file_ptr where_am_i_now;
661 where_am_i_now = ftell (bfd_cache_lookup (abfd));
662 if (abfd->my_archive)
663 where_am_i_now -= abfd->origin;
664 if (where_am_i_now != abfd->where)
667 if (direction == SEEK_SET && position == abfd->where)
672 /* We need something smarter to optimize access to archives.
673 Currently, anything inside an archive is read via the file
674 handle for the archive. Which means that a bfd_seek on one
675 component affects the `current position' in the archive, as
676 well as in any other component.
678 It might be sufficient to put a spike through the cache
679 abstraction, and look to the archive for the file position,
680 but I think we should try for something cleaner.
682 In the meantime, no optimization for archives. */
686 f = bfd_cache_lookup (abfd);
687 file_position = position;
688 if (direction == SEEK_SET && abfd->my_archive != NULL)
689 file_position += abfd->origin;
691 result = fseek (f, file_position, direction);
695 /* Force redetermination of `where' field. */
697 bfd_set_error (bfd_error_system_call);
701 #ifdef FILE_OFFSET_IS_CHAR_INDEX
702 /* Adjust `where' field. */
703 if (direction == SEEK_SET)
704 abfd->where = position;
706 abfd->where += position;
712 /** The do-it-yourself (byte) sex-change kit */
714 /* The middle letter e.g. get<b>short indicates Big or Little endian
715 target machine. It doesn't matter what the byte order of the host
716 machine is; these routines work for either. */
718 /* FIXME: Should these take a count argument?
720 functions in swap.h #ifdef __GNUC__.
721 Gprof them later and find out. */
730 These macros as used for reading and writing raw data in
731 sections; each access (except for bytes) is vectored through
732 the target format of the BFD and mangled accordingly. The
733 mangling performs any necessary endian translations and
734 removes alignment restrictions. Note that types accepted and
735 returned by these macros are identical so they can be swapped
736 around in macros---for example, @file{libaout.h} defines <<GET_WORD>>
737 to either <<bfd_get_32>> or <<bfd_get_64>>.
739 In the put routines, @var{val} must be a <<bfd_vma>>. If we are on a
740 system without prototypes, the caller is responsible for making
741 sure that is true, with a cast if necessary. We don't cast
742 them in the macro definitions because that would prevent <<lint>>
743 or <<gcc -Wall>> from detecting sins such as passing a pointer.
744 To detect calling these with less than a <<bfd_vma>>, use
745 <<gcc -Wconversion>> on a host with 64 bit <<bfd_vma>>'s.
748 .{* Byte swapping macros for user section data. *}
750 .#define bfd_put_8(abfd, val, ptr) \
751 . (*((unsigned char *)(ptr)) = (unsigned char)(val))
752 .#define bfd_put_signed_8 \
754 .#define bfd_get_8(abfd, ptr) \
755 . (*(unsigned char *)(ptr))
756 .#define bfd_get_signed_8(abfd, ptr) \
757 . ((*(unsigned char *)(ptr) ^ 0x80) - 0x80)
759 .#define bfd_put_16(abfd, val, ptr) \
760 . BFD_SEND(abfd, bfd_putx16, ((val),(ptr)))
761 .#define bfd_put_signed_16 \
763 .#define bfd_get_16(abfd, ptr) \
764 . BFD_SEND(abfd, bfd_getx16, (ptr))
765 .#define bfd_get_signed_16(abfd, ptr) \
766 . BFD_SEND (abfd, bfd_getx_signed_16, (ptr))
768 .#define bfd_put_32(abfd, val, ptr) \
769 . BFD_SEND(abfd, bfd_putx32, ((val),(ptr)))
770 .#define bfd_put_signed_32 \
772 .#define bfd_get_32(abfd, ptr) \
773 . BFD_SEND(abfd, bfd_getx32, (ptr))
774 .#define bfd_get_signed_32(abfd, ptr) \
775 . BFD_SEND(abfd, bfd_getx_signed_32, (ptr))
777 .#define bfd_put_64(abfd, val, ptr) \
778 . BFD_SEND(abfd, bfd_putx64, ((val), (ptr)))
779 .#define bfd_put_signed_64 \
781 .#define bfd_get_64(abfd, ptr) \
782 . BFD_SEND(abfd, bfd_getx64, (ptr))
783 .#define bfd_get_signed_64(abfd, ptr) \
784 . BFD_SEND(abfd, bfd_getx_signed_64, (ptr))
794 These macros have the same function as their <<bfd_get_x>>
795 bretheren, except that they are used for removing information
796 for the header records of object files. Believe it or not,
797 some object files keep their header records in big endian
798 order and their data in little endian order.
800 .{* Byte swapping macros for file header data. *}
802 .#define bfd_h_put_8(abfd, val, ptr) \
803 . bfd_put_8 (abfd, val, ptr)
804 .#define bfd_h_put_signed_8(abfd, val, ptr) \
805 . bfd_put_8 (abfd, val, ptr)
806 .#define bfd_h_get_8(abfd, ptr) \
807 . bfd_get_8 (abfd, ptr)
808 .#define bfd_h_get_signed_8(abfd, ptr) \
809 . bfd_get_signed_8 (abfd, ptr)
811 .#define bfd_h_put_16(abfd, val, ptr) \
812 . BFD_SEND(abfd, bfd_h_putx16,(val,ptr))
813 .#define bfd_h_put_signed_16 \
815 .#define bfd_h_get_16(abfd, ptr) \
816 . BFD_SEND(abfd, bfd_h_getx16,(ptr))
817 .#define bfd_h_get_signed_16(abfd, ptr) \
818 . BFD_SEND(abfd, bfd_h_getx_signed_16, (ptr))
820 .#define bfd_h_put_32(abfd, val, ptr) \
821 . BFD_SEND(abfd, bfd_h_putx32,(val,ptr))
822 .#define bfd_h_put_signed_32 \
824 .#define bfd_h_get_32(abfd, ptr) \
825 . BFD_SEND(abfd, bfd_h_getx32,(ptr))
826 .#define bfd_h_get_signed_32(abfd, ptr) \
827 . BFD_SEND(abfd, bfd_h_getx_signed_32, (ptr))
829 .#define bfd_h_put_64(abfd, val, ptr) \
830 . BFD_SEND(abfd, bfd_h_putx64,(val, ptr))
831 .#define bfd_h_put_signed_64 \
833 .#define bfd_h_get_64(abfd, ptr) \
834 . BFD_SEND(abfd, bfd_h_getx64,(ptr))
835 .#define bfd_h_get_signed_64(abfd, ptr) \
836 . BFD_SEND(abfd, bfd_h_getx_signed_64, (ptr))
840 /* Sign extension to bfd_signed_vma. */
841 #define COERCE16(x) (((bfd_signed_vma) (x) ^ 0x8000) - 0x8000)
842 #define COERCE32(x) (((bfd_signed_vma) (x) ^ 0x80000000) - 0x80000000)
843 #define EIGHT_GAZILLION (((BFD_HOST_64_BIT)0x80000000) << 32)
844 #define COERCE64(x) \
845 (((bfd_signed_vma) (x) ^ EIGHT_GAZILLION) - EIGHT_GAZILLION)
849 register const bfd_byte *addr;
851 return (addr[0] << 8) | addr[1];
856 register const bfd_byte *addr;
858 return (addr[1] << 8) | addr[0];
862 bfd_getb_signed_16 (addr)
863 register const bfd_byte *addr;
865 return COERCE16((addr[0] << 8) | addr[1]);
869 bfd_getl_signed_16 (addr)
870 register const bfd_byte *addr;
872 return COERCE16((addr[1] << 8) | addr[0]);
876 bfd_putb16 (data, addr)
878 register bfd_byte *addr;
880 addr[0] = (bfd_byte)(data >> 8);
881 addr[1] = (bfd_byte )data;
885 bfd_putl16 (data, addr)
887 register bfd_byte *addr;
889 addr[0] = (bfd_byte )data;
890 addr[1] = (bfd_byte)(data >> 8);
895 register const bfd_byte *addr;
897 return (((((bfd_vma)addr[0] << 8) | addr[1]) << 8)
898 | addr[2]) << 8 | addr[3];
903 register const bfd_byte *addr;
905 return (((((bfd_vma)addr[3] << 8) | addr[2]) << 8)
906 | addr[1]) << 8 | addr[0];
910 bfd_getb_signed_32 (addr)
911 register const bfd_byte *addr;
913 return COERCE32((((((bfd_vma)addr[0] << 8) | addr[1]) << 8)
914 | addr[2]) << 8 | addr[3]);
918 bfd_getl_signed_32 (addr)
919 register const bfd_byte *addr;
921 return COERCE32((((((bfd_vma)addr[3] << 8) | addr[2]) << 8)
922 | addr[1]) << 8 | addr[0]);
927 register const bfd_byte *addr;
932 high= ((((((((addr[0]) << 8) |
937 low = (((((((((bfd_vma)addr[4]) << 8) |
942 return high << 32 | low;
951 register const bfd_byte *addr;
955 high= (((((((addr[7] << 8) |
960 low = ((((((((bfd_vma)addr[3] << 8) |
965 return high << 32 | low;
974 bfd_getb_signed_64 (addr)
975 register const bfd_byte *addr;
980 high= ((((((((addr[0]) << 8) |
985 low = (((((((((bfd_vma)addr[4]) << 8) |
990 return COERCE64(high << 32 | low);
998 bfd_getl_signed_64 (addr)
999 register const bfd_byte *addr;
1003 high= (((((((addr[7] << 8) |
1008 low = ((((((((bfd_vma)addr[3] << 8) |
1013 return COERCE64(high << 32 | low);
1021 bfd_putb32 (data, addr)
1023 register bfd_byte *addr;
1025 addr[0] = (bfd_byte)(data >> 24);
1026 addr[1] = (bfd_byte)(data >> 16);
1027 addr[2] = (bfd_byte)(data >> 8);
1028 addr[3] = (bfd_byte)data;
1032 bfd_putl32 (data, addr)
1034 register bfd_byte *addr;
1036 addr[0] = (bfd_byte)data;
1037 addr[1] = (bfd_byte)(data >> 8);
1038 addr[2] = (bfd_byte)(data >> 16);
1039 addr[3] = (bfd_byte)(data >> 24);
1043 bfd_putb64 (data, addr)
1045 register bfd_byte *addr;
1048 addr[0] = (bfd_byte)(data >> (7*8));
1049 addr[1] = (bfd_byte)(data >> (6*8));
1050 addr[2] = (bfd_byte)(data >> (5*8));
1051 addr[3] = (bfd_byte)(data >> (4*8));
1052 addr[4] = (bfd_byte)(data >> (3*8));
1053 addr[5] = (bfd_byte)(data >> (2*8));
1054 addr[6] = (bfd_byte)(data >> (1*8));
1055 addr[7] = (bfd_byte)(data >> (0*8));
1062 bfd_putl64 (data, addr)
1064 register bfd_byte *addr;
1067 addr[7] = (bfd_byte)(data >> (7*8));
1068 addr[6] = (bfd_byte)(data >> (6*8));
1069 addr[5] = (bfd_byte)(data >> (5*8));
1070 addr[4] = (bfd_byte)(data >> (4*8));
1071 addr[3] = (bfd_byte)(data >> (3*8));
1072 addr[2] = (bfd_byte)(data >> (2*8));
1073 addr[1] = (bfd_byte)(data >> (1*8));
1074 addr[0] = (bfd_byte)(data >> (0*8));
1080 /* Default implementation */
1083 _bfd_generic_get_section_contents (abfd, section, location, offset, count)
1088 bfd_size_type count;
1092 if ((bfd_size_type)(offset+count) > section->_raw_size
1093 || bfd_seek(abfd, (file_ptr)(section->filepos + offset), SEEK_SET) == -1
1094 || bfd_read(location, (bfd_size_type)1, count, abfd) != count)
1095 return (false); /* on error */
1100 _bfd_generic_get_section_contents_in_window (abfd, section, w, offset, count)
1105 bfd_size_type count;
1110 if (abfd->xvec->_bfd_get_section_contents != _bfd_generic_get_section_contents)
1112 /* We don't know what changes the bfd's get_section_contents
1113 method may have to make. So punt trying to map the file
1114 window, and let get_section_contents do its thing. */
1115 /* @@ FIXME : If the internal window has a refcount of 1 and was
1116 allocated with malloc instead of mmap, just reuse it. */
1117 bfd_free_window (w);
1118 w->i = (bfd_window_internal *) bfd_zmalloc (sizeof (bfd_window_internal));
1121 w->i->data = (PTR) bfd_malloc ((size_t) count);
1122 if (w->i->data == NULL)
1130 w->size = w->i->size = count;
1131 w->data = w->i->data;
1132 return bfd_get_section_contents (abfd, section, w->data, offset, count);
1134 if ((bfd_size_type) (offset+count) > section->_raw_size
1135 || (bfd_get_file_window (abfd, section->filepos + offset, count, w, true)
1144 /* This generic function can only be used in implementations where creating
1145 NEW sections is disallowed. It is useful in patching existing sections
1146 in read-write files, though. See other set_section_contents functions
1147 to see why it doesn't work for new sections. */
1149 _bfd_generic_set_section_contents (abfd, section, location, offset, count)
1154 bfd_size_type count;
1159 if (bfd_seek (abfd, (file_ptr) (section->filepos + offset), SEEK_SET) == -1
1160 || bfd_write (location, (bfd_size_type) 1, count, abfd) != count)
1171 unsigned int bfd_log2(bfd_vma x);
1174 Return the log base 2 of the value supplied, rounded up. E.g., an
1175 @var{x} of 1025 returns 11.
1182 unsigned result = 0;
1183 while ( (bfd_vma)(1<< result) < x)
1189 bfd_generic_is_local_label (abfd, sym)
1193 char locals_prefix = (bfd_get_symbol_leading_char (abfd) == '_') ? 'L' : '.';
1195 return (sym->name[0] == locals_prefix);