Add DW_TAG_compile_unit DIE to Dummy CUs
[binutils-gdb.git] / bfd / libbfd.c
blob747b69ec2c64220a70a96b439dc8a222ebec46a9
1 /* Assorted BFD support routines, only used internally.
2 Copyright (C) 1990-2024 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 3 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., 51 Franklin Street - Fifth Floor, Boston,
20 MA 02110-1301, USA. */
22 #include "sysdep.h"
23 #include "bfd.h"
24 #include "elf-bfd.h"
25 #include "libbfd.h"
26 #include "objalloc.h"
28 #ifndef HAVE_GETPAGESIZE
29 #define getpagesize() 2048
30 #endif
33 SECTION
34 Implementation details
36 SUBSECTION
37 Internal functions
39 DESCRIPTION
40 These routines are used within BFD.
41 They are not intended for export, but are documented here for
42 completeness.
45 bool
46 _bfd_bool_bfd_false (bfd *abfd ATTRIBUTE_UNUSED)
48 return false;
51 bool
52 _bfd_bool_bfd_asymbol_false (bfd *abfd ATTRIBUTE_UNUSED,
53 asymbol *sym ATTRIBUTE_UNUSED)
55 return false;
58 /* A routine which is used in target vectors for unsupported
59 operations. */
61 bool
62 _bfd_bool_bfd_false_error (bfd *ignore ATTRIBUTE_UNUSED)
64 bfd_set_error (bfd_error_invalid_operation);
65 return false;
68 bool
69 _bfd_bool_bfd_link_false_error (bfd *abfd,
70 struct bfd_link_info *info ATTRIBUTE_UNUSED)
72 return _bfd_bool_bfd_false_error (abfd);
75 /* A routine which is used in target vectors for supported operations
76 which do not actually do anything. */
78 bool
79 _bfd_bool_bfd_true (bfd *ignore ATTRIBUTE_UNUSED)
81 return true;
84 bool
85 _bfd_bool_bfd_link_true (bfd *abfd ATTRIBUTE_UNUSED,
86 struct bfd_link_info *info ATTRIBUTE_UNUSED)
88 return true;
91 bool
92 _bfd_bool_bfd_bfd_true (bfd *ibfd ATTRIBUTE_UNUSED,
93 bfd *obfd ATTRIBUTE_UNUSED)
95 return true;
98 bool
99 _bfd_bool_bfd_uint_true (bfd *abfd ATTRIBUTE_UNUSED,
100 unsigned int flags ATTRIBUTE_UNUSED)
102 return true;
105 bool
106 _bfd_bool_bfd_asection_bfd_asection_true (bfd *ibfd ATTRIBUTE_UNUSED,
107 asection *isec ATTRIBUTE_UNUSED,
108 bfd *obfd ATTRIBUTE_UNUSED,
109 asection *osec ATTRIBUTE_UNUSED)
111 return true;
114 bool
115 _bfd_bool_bfd_asymbol_bfd_asymbol_true (bfd *ibfd ATTRIBUTE_UNUSED,
116 asymbol *isym ATTRIBUTE_UNUSED,
117 bfd *obfd ATTRIBUTE_UNUSED,
118 asymbol *osym ATTRIBUTE_UNUSED)
120 return true;
123 bool
124 _bfd_bool_bfd_ptr_true (bfd *abfd ATTRIBUTE_UNUSED,
125 void *ptr ATTRIBUTE_UNUSED)
127 return true;
130 /* A routine which is used in target vectors for unsupported
131 operations which return a pointer value. */
133 void *
134 _bfd_ptr_bfd_null_error (bfd *ignore ATTRIBUTE_UNUSED)
136 bfd_set_error (bfd_error_invalid_operation);
137 return NULL;
141 _bfd_int_bfd_0 (bfd *ignore ATTRIBUTE_UNUSED)
143 return 0;
146 unsigned int
147 _bfd_uint_bfd_0 (bfd *ignore ATTRIBUTE_UNUSED)
149 return 0;
152 long
153 _bfd_long_bfd_0 (bfd *ignore ATTRIBUTE_UNUSED)
155 return 0;
158 /* A routine which is used in target vectors for unsupported
159 operations which return -1 on error. */
161 long
162 _bfd_long_bfd_n1_error (bfd *ignore_abfd ATTRIBUTE_UNUSED)
164 bfd_set_error (bfd_error_invalid_operation);
165 return -1;
168 void
169 _bfd_void_bfd (bfd *ignore ATTRIBUTE_UNUSED)
173 void
174 _bfd_void_bfd_link (bfd *abfd ATTRIBUTE_UNUSED,
175 struct bfd_link_info *info ATTRIBUTE_UNUSED)
179 void
180 _bfd_void_bfd_asection (bfd *abfd ATTRIBUTE_UNUSED,
181 asection *sec ATTRIBUTE_UNUSED)
185 long
186 _bfd_norelocs_get_reloc_upper_bound (bfd *abfd ATTRIBUTE_UNUSED,
187 asection *sec ATTRIBUTE_UNUSED)
189 return sizeof (arelent *);
192 long
193 _bfd_norelocs_canonicalize_reloc (bfd *abfd ATTRIBUTE_UNUSED,
194 asection *sec ATTRIBUTE_UNUSED,
195 arelent **relptr,
196 asymbol **symbols ATTRIBUTE_UNUSED)
198 *relptr = NULL;
199 return 0;
202 void
203 _bfd_norelocs_set_reloc (bfd *abfd ATTRIBUTE_UNUSED,
204 asection *sec ATTRIBUTE_UNUSED,
205 arelent **relptr ATTRIBUTE_UNUSED,
206 unsigned int count ATTRIBUTE_UNUSED)
208 /* Do nothing. */
211 bool
212 _bfd_nocore_core_file_matches_executable_p
213 (bfd *ignore_core_bfd ATTRIBUTE_UNUSED,
214 bfd *ignore_exec_bfd ATTRIBUTE_UNUSED)
216 bfd_set_error (bfd_error_invalid_operation);
217 return false;
220 /* Routine to handle core_file_failing_command entry point for targets
221 without core file support. */
223 char *
224 _bfd_nocore_core_file_failing_command (bfd *ignore_abfd ATTRIBUTE_UNUSED)
226 bfd_set_error (bfd_error_invalid_operation);
227 return NULL;
230 /* Routine to handle core_file_failing_signal entry point for targets
231 without core file support. */
234 _bfd_nocore_core_file_failing_signal (bfd *ignore_abfd ATTRIBUTE_UNUSED)
236 bfd_set_error (bfd_error_invalid_operation);
237 return 0;
240 /* Routine to handle the core_file_pid entry point for targets without
241 core file support. */
244 _bfd_nocore_core_file_pid (bfd *ignore_abfd ATTRIBUTE_UNUSED)
246 bfd_set_error (bfd_error_invalid_operation);
247 return 0;
250 bfd_cleanup
251 _bfd_dummy_target (bfd *ignore_abfd ATTRIBUTE_UNUSED)
253 bfd_set_error (bfd_error_wrong_format);
254 return 0;
257 /* Allocate memory using malloc. */
259 #ifndef SSIZE_MAX
260 #define SSIZE_MAX ((size_t) -1 >> 1)
261 #endif
264 INTERNAL_FUNCTION
265 bfd_malloc
267 SYNOPSIS
268 void *bfd_malloc (bfd_size_type {*size*});
270 DESCRIPTION
271 Returns a pointer to an allocated block of memory that is at least
272 SIZE bytes long. If SIZE is 0 then it will be treated as if it were
273 1. If SIZE is too big then NULL will be returned.
275 Returns NULL upon error and sets bfd_error.
277 void *
278 bfd_malloc (bfd_size_type size)
280 void *ptr;
281 size_t sz = (size_t) size;
283 if (size != sz
284 /* This is to pacify memory checkers like valgrind. */
285 || sz > SSIZE_MAX)
287 bfd_set_error (bfd_error_no_memory);
288 return NULL;
291 ptr = malloc (sz ? sz : 1);
292 if (ptr == NULL)
293 bfd_set_error (bfd_error_no_memory);
295 return ptr;
299 INTERNAL_FUNCTION
300 bfd_realloc
302 SYNOPSIS
303 void *bfd_realloc (void *{*mem*}, bfd_size_type {*size*});
305 DESCRIPTION
306 Returns a pointer to an allocated block of memory that is at least
307 SIZE bytes long. If SIZE is 0 then it will be treated as if it were
308 1. If SIZE is too big then NULL will be returned.
310 If MEM is not NULL then it must point to an allocated block of memory.
311 If this block is large enough then MEM may be used as the return
312 value for this function, but this is not guaranteed.
314 If MEM is not returned then the first N bytes in the returned block
315 will be identical to the first N bytes in region pointed to by MEM,
316 where N is the lessor of SIZE and the length of the region of memory
317 currently addressed by MEM.
319 Returns NULL upon error and sets bfd_error.
321 void *
322 bfd_realloc (void *ptr, bfd_size_type size)
324 void *ret;
325 size_t sz = (size_t) size;
327 if (ptr == NULL)
328 return bfd_malloc (size);
330 if (size != sz
331 /* This is to pacify memory checkers like valgrind. */
332 || sz > SSIZE_MAX)
334 bfd_set_error (bfd_error_no_memory);
335 return NULL;
338 /* The behaviour of realloc(0) is implementation defined,
339 but for this function we always allocate memory. */
340 ret = realloc (ptr, sz ? sz : 1);
342 if (ret == NULL)
343 bfd_set_error (bfd_error_no_memory);
345 return ret;
349 INTERNAL_FUNCTION
350 bfd_realloc_or_free
352 SYNOPSIS
353 void *bfd_realloc_or_free (void *{*mem*}, bfd_size_type {*size*});
355 DESCRIPTION
356 Returns a pointer to an allocated block of memory that is at least
357 SIZE bytes long. If SIZE is 0 then no memory will be allocated,
358 MEM will be freed, and NULL will be returned. This will not cause
359 bfd_error to be set.
361 If SIZE is too big then NULL will be returned and bfd_error will be
362 set.
364 If MEM is not NULL then it must point to an allocated block of memory.
365 If this block is large enough then MEM may be used as the return
366 value for this function, but this is not guaranteed.
368 If MEM is not returned then the first N bytes in the returned block
369 will be identical to the first N bytes in region pointed to by MEM,
370 where N is the lessor of SIZE and the length of the region of memory
371 currently addressed by MEM.
373 void *
374 bfd_realloc_or_free (void *ptr, bfd_size_type size)
376 void *ret;
378 /* The behaviour of realloc(0) is implementation defined, but
379 for this function we treat it is always freeing the memory. */
380 if (size == 0)
382 free (ptr);
383 return NULL;
386 ret = bfd_realloc (ptr, size);
387 if (ret == NULL)
388 free (ptr);
390 return ret;
394 INTERNAL_FUNCTION
395 bfd_zmalloc
397 SYNOPSIS
398 void *bfd_zmalloc (bfd_size_type {*size*});
400 DESCRIPTION
401 Returns a pointer to an allocated block of memory that is at least
402 SIZE bytes long. If SIZE is 0 then it will be treated as if it were
403 1. If SIZE is too big then NULL will be returned.
405 Returns NULL upon error and sets bfd_error.
407 If NULL is not returned then the allocated block of memory will
408 have been cleared.
410 void *
411 bfd_zmalloc (bfd_size_type size)
413 void *ptr = bfd_malloc (size);
415 if (ptr != NULL)
416 memset (ptr, 0, size ? (size_t) size : 1);
418 return ptr;
422 FUNCTION
423 bfd_alloc
425 SYNOPSIS
426 void *bfd_alloc (bfd *abfd, bfd_size_type wanted);
428 DESCRIPTION
429 Allocate a block of @var{wanted} bytes of memory attached to
430 <<abfd>> and return a pointer to it.
433 void *
434 bfd_alloc (bfd *abfd, bfd_size_type size)
436 void *ret;
437 unsigned long ul_size = (unsigned long) size;
439 if (size != ul_size
440 /* Note - although objalloc_alloc takes an unsigned long as its
441 argument, internally the size is treated as a signed long. This can
442 lead to problems where, for example, a request to allocate -1 bytes
443 can result in just 1 byte being allocated, rather than
444 ((unsigned long) -1) bytes. Also memory checkers will often
445 complain about attempts to allocate a negative amount of memory.
446 So to stop these problems we fail if the size is negative. */
447 || ((signed long) ul_size) < 0)
449 bfd_set_error (bfd_error_no_memory);
450 return NULL;
453 ret = objalloc_alloc ((struct objalloc *) abfd->memory, ul_size);
454 if (ret == NULL)
455 bfd_set_error (bfd_error_no_memory);
456 else
457 abfd->alloc_size += size;
458 return ret;
462 FUNCTION
463 bfd_zalloc
465 SYNOPSIS
466 void *bfd_zalloc (bfd *abfd, bfd_size_type wanted);
468 DESCRIPTION
469 Allocate a block of @var{wanted} bytes of zeroed memory
470 attached to <<abfd>> and return a pointer to it.
473 void *
474 bfd_zalloc (bfd *abfd, bfd_size_type size)
476 void *res;
478 res = bfd_alloc (abfd, size);
479 if (res)
480 memset (res, 0, (size_t) size);
481 return res;
485 FUNCTION
486 bfd_release
488 SYNOPSIS
489 void bfd_release (bfd *, void *);
491 DESCRIPTION
492 Free a block allocated for a BFD.
493 Note: Also frees all more recently allocated blocks!
496 void
497 bfd_release (bfd *abfd, void *block)
499 objalloc_free_block ((struct objalloc *) abfd->memory, block);
503 INTERNAL_FUNCTION
504 bfd_write_bigendian_4byte_int
506 SYNOPSIS
507 bool bfd_write_bigendian_4byte_int (bfd *, unsigned int);
509 DESCRIPTION
510 Write a 4 byte integer @var{i} to the output BFD @var{abfd}, in big
511 endian order regardless of what else is going on. This is useful in
512 archives.
515 bool
516 bfd_write_bigendian_4byte_int (bfd *abfd, unsigned int i)
518 bfd_byte buffer[4];
519 bfd_putb32 (i, buffer);
520 return bfd_write (buffer, 4, abfd) == 4;
524 /** The do-it-yourself (byte) sex-change kit */
526 /* The middle letter e.g. get<b>short indicates Big or Little endian
527 target machine. It doesn't matter what the byte order of the host
528 machine is; these routines work for either. */
530 /* FIXME: Should these take a count argument?
531 Answer (gnu@cygnus.com): No, but perhaps they should be inline
532 functions in swap.h #ifdef __GNUC__.
533 Gprof them later and find out. */
536 FUNCTION
537 bfd_put_size
538 FUNCTION
539 bfd_get_size
541 DESCRIPTION
542 These macros as used for reading and writing raw data in
543 sections; each access (except for bytes) is vectored through
544 the target format of the BFD and mangled accordingly. The
545 mangling performs any necessary endian translations and
546 removes alignment restrictions. Note that types accepted and
547 returned by these macros are identical so they can be swapped
548 around in macros---for example, @file{libaout.h} defines <<GET_WORD>>
549 to either <<bfd_get_32>> or <<bfd_get_64>>.
551 In the put routines, @var{val} must be a <<bfd_vma>>. If we are on a
552 system without prototypes, the caller is responsible for making
553 sure that is true, with a cast if necessary. We don't cast
554 them in the macro definitions because that would prevent <<lint>>
555 or <<gcc -Wall>> from detecting sins such as passing a pointer.
556 To detect calling these with less than a <<bfd_vma>>, use
557 <<gcc -Wconversion>> on a host with 64 bit <<bfd_vma>>'s.
560 .{* Byte swapping macros for user section data. *}
562 .#define bfd_put_8(abfd, val, ptr) \
563 . ((void) (*((bfd_byte *) (ptr)) = (val) & 0xff))
564 .#define bfd_put_signed_8 \
565 . bfd_put_8
566 .#define bfd_get_8(abfd, ptr) \
567 . ((bfd_vma) *(const bfd_byte *) (ptr) & 0xff)
568 .#define bfd_get_signed_8(abfd, ptr) \
569 . ((((bfd_signed_vma) *(const bfd_byte *) (ptr) & 0xff) ^ 0x80) - 0x80)
571 .#define bfd_put_16(abfd, val, ptr) \
572 . BFD_SEND (abfd, bfd_putx16, ((val),(ptr)))
573 .#define bfd_put_signed_16 \
574 . bfd_put_16
575 .#define bfd_get_16(abfd, ptr) \
576 . BFD_SEND (abfd, bfd_getx16, (ptr))
577 .#define bfd_get_signed_16(abfd, ptr) \
578 . BFD_SEND (abfd, bfd_getx_signed_16, (ptr))
580 .#define bfd_put_24(abfd, val, ptr) \
581 . do \
582 . if (bfd_big_endian (abfd)) \
583 . bfd_putb24 ((val), (ptr)); \
584 . else \
585 . bfd_putl24 ((val), (ptr)); \
586 . while (0)
588 .bfd_vma bfd_getb24 (const void *p);
589 .bfd_vma bfd_getl24 (const void *p);
591 .#define bfd_get_24(abfd, ptr) \
592 . (bfd_big_endian (abfd) ? bfd_getb24 (ptr) : bfd_getl24 (ptr))
594 .#define bfd_put_32(abfd, val, ptr) \
595 . BFD_SEND (abfd, bfd_putx32, ((val),(ptr)))
596 .#define bfd_put_signed_32 \
597 . bfd_put_32
598 .#define bfd_get_32(abfd, ptr) \
599 . BFD_SEND (abfd, bfd_getx32, (ptr))
600 .#define bfd_get_signed_32(abfd, ptr) \
601 . BFD_SEND (abfd, bfd_getx_signed_32, (ptr))
603 .#define bfd_put_64(abfd, val, ptr) \
604 . BFD_SEND (abfd, bfd_putx64, ((val), (ptr)))
605 .#define bfd_put_signed_64 \
606 . bfd_put_64
607 .#define bfd_get_64(abfd, ptr) \
608 . BFD_SEND (abfd, bfd_getx64, (ptr))
609 .#define bfd_get_signed_64(abfd, ptr) \
610 . BFD_SEND (abfd, bfd_getx_signed_64, (ptr))
612 .#define bfd_get(bits, abfd, ptr) \
613 . ((bits) == 8 ? bfd_get_8 (abfd, ptr) \
614 . : (bits) == 16 ? bfd_get_16 (abfd, ptr) \
615 . : (bits) == 32 ? bfd_get_32 (abfd, ptr) \
616 . : (bits) == 64 ? bfd_get_64 (abfd, ptr) \
617 . : (abort (), (bfd_vma) - 1))
619 .#define bfd_put(bits, abfd, val, ptr) \
620 . ((bits) == 8 ? bfd_put_8 (abfd, val, ptr) \
621 . : (bits) == 16 ? bfd_put_16 (abfd, val, ptr) \
622 . : (bits) == 32 ? bfd_put_32 (abfd, val, ptr) \
623 . : (bits) == 64 ? bfd_put_64 (abfd, val, ptr) \
624 . : (abort (), (void) 0))
629 FUNCTION
630 bfd_h_put_size
631 bfd_h_get_size
633 DESCRIPTION
634 These macros have the same function as their <<bfd_get_x>>
635 brethren, except that they are used for removing information
636 for the header records of object files. Believe it or not,
637 some object files keep their header records in big endian
638 order and their data in little endian order.
640 .{* Byte swapping macros for file header data. *}
642 .#define bfd_h_put_8(abfd, val, ptr) \
643 . bfd_put_8 (abfd, val, ptr)
644 .#define bfd_h_put_signed_8(abfd, val, ptr) \
645 . bfd_put_8 (abfd, val, ptr)
646 .#define bfd_h_get_8(abfd, ptr) \
647 . bfd_get_8 (abfd, ptr)
648 .#define bfd_h_get_signed_8(abfd, ptr) \
649 . bfd_get_signed_8 (abfd, ptr)
651 .#define bfd_h_put_16(abfd, val, ptr) \
652 . BFD_SEND (abfd, bfd_h_putx16, (val, ptr))
653 .#define bfd_h_put_signed_16 \
654 . bfd_h_put_16
655 .#define bfd_h_get_16(abfd, ptr) \
656 . BFD_SEND (abfd, bfd_h_getx16, (ptr))
657 .#define bfd_h_get_signed_16(abfd, ptr) \
658 . BFD_SEND (abfd, bfd_h_getx_signed_16, (ptr))
660 .#define bfd_h_put_32(abfd, val, ptr) \
661 . BFD_SEND (abfd, bfd_h_putx32, (val, ptr))
662 .#define bfd_h_put_signed_32 \
663 . bfd_h_put_32
664 .#define bfd_h_get_32(abfd, ptr) \
665 . BFD_SEND (abfd, bfd_h_getx32, (ptr))
666 .#define bfd_h_get_signed_32(abfd, ptr) \
667 . BFD_SEND (abfd, bfd_h_getx_signed_32, (ptr))
669 .#define bfd_h_put_64(abfd, val, ptr) \
670 . BFD_SEND (abfd, bfd_h_putx64, (val, ptr))
671 .#define bfd_h_put_signed_64 \
672 . bfd_h_put_64
673 .#define bfd_h_get_64(abfd, ptr) \
674 . BFD_SEND (abfd, bfd_h_getx64, (ptr))
675 .#define bfd_h_get_signed_64(abfd, ptr) \
676 . BFD_SEND (abfd, bfd_h_getx_signed_64, (ptr))
678 .{* Aliases for the above, which should eventually go away. *}
680 .#define H_PUT_64 bfd_h_put_64
681 .#define H_PUT_32 bfd_h_put_32
682 .#define H_PUT_16 bfd_h_put_16
683 .#define H_PUT_8 bfd_h_put_8
684 .#define H_PUT_S64 bfd_h_put_signed_64
685 .#define H_PUT_S32 bfd_h_put_signed_32
686 .#define H_PUT_S16 bfd_h_put_signed_16
687 .#define H_PUT_S8 bfd_h_put_signed_8
688 .#define H_GET_64 bfd_h_get_64
689 .#define H_GET_32 bfd_h_get_32
690 .#define H_GET_16 bfd_h_get_16
691 .#define H_GET_8 bfd_h_get_8
692 .#define H_GET_S64 bfd_h_get_signed_64
693 .#define H_GET_S32 bfd_h_get_signed_32
694 .#define H_GET_S16 bfd_h_get_signed_16
695 .#define H_GET_S8 bfd_h_get_signed_8
699 /* Sign extension to bfd_signed_vma. */
700 #define COERCE16(x) (((bfd_vma) (x) ^ 0x8000) - 0x8000)
701 #define COERCE32(x) (((bfd_vma) (x) ^ 0x80000000) - 0x80000000)
702 #define COERCE64(x) \
703 (((uint64_t) (x) ^ ((uint64_t) 1 << 63)) - ((uint64_t) 1 << 63))
706 FUNCTION
707 Byte swapping routines.
709 SYNOPSIS
710 uint64_t bfd_getb64 (const void *);
711 uint64_t bfd_getl64 (const void *);
712 int64_t bfd_getb_signed_64 (const void *);
713 int64_t bfd_getl_signed_64 (const void *);
714 bfd_vma bfd_getb32 (const void *);
715 bfd_vma bfd_getl32 (const void *);
716 bfd_signed_vma bfd_getb_signed_32 (const void *);
717 bfd_signed_vma bfd_getl_signed_32 (const void *);
718 bfd_vma bfd_getb16 (const void *);
719 bfd_vma bfd_getl16 (const void *);
720 bfd_signed_vma bfd_getb_signed_16 (const void *);
721 bfd_signed_vma bfd_getl_signed_16 (const void *);
722 void bfd_putb64 (uint64_t, void *);
723 void bfd_putl64 (uint64_t, void *);
724 void bfd_putb32 (bfd_vma, void *);
725 void bfd_putl32 (bfd_vma, void *);
726 void bfd_putb24 (bfd_vma, void *);
727 void bfd_putl24 (bfd_vma, void *);
728 void bfd_putb16 (bfd_vma, void *);
729 void bfd_putl16 (bfd_vma, void *);
730 uint64_t bfd_get_bits (const void *, int, bool);
731 void bfd_put_bits (uint64_t, void *, int, bool);
733 DESCRIPTION
734 Read and write integers in a particular endian order. getb
735 and putb functions handle big-endian, getl and putl handle
736 little-endian. bfd_get_bits and bfd_put_bits specify
737 big-endian by passing TRUE in the last parameter,
738 little-endian by passing FALSE.
741 bfd_vma
742 bfd_getb16 (const void *p)
744 const bfd_byte *addr = (const bfd_byte *) p;
745 return (addr[0] << 8) | addr[1];
748 bfd_vma
749 bfd_getl16 (const void *p)
751 const bfd_byte *addr = (const bfd_byte *) p;
752 return (addr[1] << 8) | addr[0];
755 bfd_signed_vma
756 bfd_getb_signed_16 (const void *p)
758 const bfd_byte *addr = (const bfd_byte *) p;
759 return COERCE16 ((addr[0] << 8) | addr[1]);
762 bfd_signed_vma
763 bfd_getl_signed_16 (const void *p)
765 const bfd_byte *addr = (const bfd_byte *) p;
766 return COERCE16 ((addr[1] << 8) | addr[0]);
769 void
770 bfd_putb16 (bfd_vma data, void *p)
772 bfd_byte *addr = (bfd_byte *) p;
773 addr[0] = (data >> 8) & 0xff;
774 addr[1] = data & 0xff;
777 void
778 bfd_putl16 (bfd_vma data, void *p)
780 bfd_byte *addr = (bfd_byte *) p;
781 addr[0] = data & 0xff;
782 addr[1] = (data >> 8) & 0xff;
785 void
786 bfd_putb24 (bfd_vma data, void *p)
788 bfd_byte *addr = (bfd_byte *) p;
789 addr[0] = (data >> 16) & 0xff;
790 addr[1] = (data >> 8) & 0xff;
791 addr[2] = data & 0xff;
794 void
795 bfd_putl24 (bfd_vma data, void *p)
797 bfd_byte *addr = (bfd_byte *) p;
798 addr[0] = data & 0xff;
799 addr[1] = (data >> 8) & 0xff;
800 addr[2] = (data >> 16) & 0xff;
803 bfd_vma
804 bfd_getb24 (const void *p)
806 const bfd_byte *addr = (const bfd_byte *) p;
807 uint32_t v;
809 v = (uint32_t) addr[0] << 16;
810 v |= (uint32_t) addr[1] << 8;
811 v |= (uint32_t) addr[2];
812 return v;
815 bfd_vma
816 bfd_getl24 (const void *p)
818 const bfd_byte *addr = (const bfd_byte *) p;
819 uint32_t v;
821 v = (uint32_t) addr[0];
822 v |= (uint32_t) addr[1] << 8;
823 v |= (uint32_t) addr[2] << 16;
824 return v;
827 bfd_vma
828 bfd_getb32 (const void *p)
830 const bfd_byte *addr = (const bfd_byte *) p;
831 uint32_t v;
833 v = (uint32_t) addr[0] << 24;
834 v |= (uint32_t) addr[1] << 16;
835 v |= (uint32_t) addr[2] << 8;
836 v |= (uint32_t) addr[3];
837 return v;
840 bfd_vma
841 bfd_getl32 (const void *p)
843 const bfd_byte *addr = (const bfd_byte *) p;
844 uint32_t v;
846 v = (uint32_t) addr[0];
847 v |= (uint32_t) addr[1] << 8;
848 v |= (uint32_t) addr[2] << 16;
849 v |= (uint32_t) addr[3] << 24;
850 return v;
853 bfd_signed_vma
854 bfd_getb_signed_32 (const void *p)
856 const bfd_byte *addr = (const bfd_byte *) p;
857 uint32_t v;
859 v = (uint32_t) addr[0] << 24;
860 v |= (uint32_t) addr[1] << 16;
861 v |= (uint32_t) addr[2] << 8;
862 v |= (uint32_t) addr[3];
863 return COERCE32 (v);
866 bfd_signed_vma
867 bfd_getl_signed_32 (const void *p)
869 const bfd_byte *addr = (const bfd_byte *) p;
870 uint32_t v;
872 v = (uint32_t) addr[0];
873 v |= (uint32_t) addr[1] << 8;
874 v |= (uint32_t) addr[2] << 16;
875 v |= (uint32_t) addr[3] << 24;
876 return COERCE32 (v);
879 uint64_t
880 bfd_getb64 (const void *p)
882 const bfd_byte *addr = (const bfd_byte *) p;
883 uint64_t v;
885 v = addr[0]; v <<= 8;
886 v |= addr[1]; v <<= 8;
887 v |= addr[2]; v <<= 8;
888 v |= addr[3]; v <<= 8;
889 v |= addr[4]; v <<= 8;
890 v |= addr[5]; v <<= 8;
891 v |= addr[6]; v <<= 8;
892 v |= addr[7];
894 return v;
897 uint64_t
898 bfd_getl64 (const void *p)
900 const bfd_byte *addr = (const bfd_byte *) p;
901 uint64_t v;
903 v = addr[7]; v <<= 8;
904 v |= addr[6]; v <<= 8;
905 v |= addr[5]; v <<= 8;
906 v |= addr[4]; v <<= 8;
907 v |= addr[3]; v <<= 8;
908 v |= addr[2]; v <<= 8;
909 v |= addr[1]; v <<= 8;
910 v |= addr[0];
912 return v;
915 int64_t
916 bfd_getb_signed_64 (const void *p)
918 const bfd_byte *addr = (const bfd_byte *) p;
919 uint64_t v;
921 v = addr[0]; v <<= 8;
922 v |= addr[1]; v <<= 8;
923 v |= addr[2]; v <<= 8;
924 v |= addr[3]; v <<= 8;
925 v |= addr[4]; v <<= 8;
926 v |= addr[5]; v <<= 8;
927 v |= addr[6]; v <<= 8;
928 v |= addr[7];
930 return COERCE64 (v);
933 int64_t
934 bfd_getl_signed_64 (const void *p)
936 const bfd_byte *addr = (const bfd_byte *) p;
937 uint64_t v;
939 v = addr[7]; v <<= 8;
940 v |= addr[6]; v <<= 8;
941 v |= addr[5]; v <<= 8;
942 v |= addr[4]; v <<= 8;
943 v |= addr[3]; v <<= 8;
944 v |= addr[2]; v <<= 8;
945 v |= addr[1]; v <<= 8;
946 v |= addr[0];
948 return COERCE64 (v);
951 void
952 bfd_putb32 (bfd_vma data, void *p)
954 bfd_byte *addr = (bfd_byte *) p;
955 addr[0] = (data >> 24) & 0xff;
956 addr[1] = (data >> 16) & 0xff;
957 addr[2] = (data >> 8) & 0xff;
958 addr[3] = data & 0xff;
961 void
962 bfd_putl32 (bfd_vma data, void *p)
964 bfd_byte *addr = (bfd_byte *) p;
965 addr[0] = data & 0xff;
966 addr[1] = (data >> 8) & 0xff;
967 addr[2] = (data >> 16) & 0xff;
968 addr[3] = (data >> 24) & 0xff;
971 void
972 bfd_putb64 (uint64_t data, void *p)
974 bfd_byte *addr = (bfd_byte *) p;
975 addr[0] = (data >> (7*8)) & 0xff;
976 addr[1] = (data >> (6*8)) & 0xff;
977 addr[2] = (data >> (5*8)) & 0xff;
978 addr[3] = (data >> (4*8)) & 0xff;
979 addr[4] = (data >> (3*8)) & 0xff;
980 addr[5] = (data >> (2*8)) & 0xff;
981 addr[6] = (data >> (1*8)) & 0xff;
982 addr[7] = (data >> (0*8)) & 0xff;
985 void
986 bfd_putl64 (uint64_t data, void *p)
988 bfd_byte *addr = (bfd_byte *) p;
989 addr[7] = (data >> (7*8)) & 0xff;
990 addr[6] = (data >> (6*8)) & 0xff;
991 addr[5] = (data >> (5*8)) & 0xff;
992 addr[4] = (data >> (4*8)) & 0xff;
993 addr[3] = (data >> (3*8)) & 0xff;
994 addr[2] = (data >> (2*8)) & 0xff;
995 addr[1] = (data >> (1*8)) & 0xff;
996 addr[0] = (data >> (0*8)) & 0xff;
999 void
1000 bfd_put_bits (uint64_t data, void *p, int bits, bool big_p)
1002 bfd_byte *addr = (bfd_byte *) p;
1003 int i;
1004 int bytes;
1006 if (bits % 8 != 0)
1007 abort ();
1009 bytes = bits / 8;
1010 for (i = 0; i < bytes; i++)
1012 int addr_index = big_p ? bytes - i - 1 : i;
1014 addr[addr_index] = data & 0xff;
1015 data >>= 8;
1019 uint64_t
1020 bfd_get_bits (const void *p, int bits, bool big_p)
1022 const bfd_byte *addr = (const bfd_byte *) p;
1023 uint64_t data;
1024 int i;
1025 int bytes;
1027 if (bits % 8 != 0)
1028 abort ();
1030 data = 0;
1031 bytes = bits / 8;
1032 for (i = 0; i < bytes; i++)
1034 int addr_index = big_p ? i : bytes - i - 1;
1036 data = (data << 8) | addr[addr_index];
1039 return data;
1042 #ifdef USE_MMAP
1043 /* Allocate a page to track mmapped memory and return the page and
1044 the first entry. Return NULL if mmap fails. */
1046 static struct bfd_mmapped *
1047 bfd_allocate_mmapped_page (bfd *abfd, struct bfd_mmapped_entry **entry)
1049 struct bfd_mmapped * mmapped
1050 = (struct bfd_mmapped *) mmap (NULL, _bfd_pagesize,
1051 PROT_READ | PROT_WRITE,
1052 MAP_PRIVATE | MAP_ANONYMOUS,
1053 -1, 0);
1054 if (mmapped == MAP_FAILED)
1055 return NULL;
1057 mmapped->next = abfd->mmapped;
1058 mmapped->max_entry
1059 = ((_bfd_pagesize - offsetof (struct bfd_mmapped, entries))
1060 / sizeof (struct bfd_mmapped_entry));
1061 mmapped->next_entry = 1;
1062 abfd->mmapped = mmapped;
1063 *entry = mmapped->entries;
1064 return mmapped;
1067 /* Mmap a memory region of RSIZE bytes with PROT at the current offset.
1068 Return mmap address and size in MAP_ADDR and MAP_SIZE. Return NULL
1069 on invalid input and MAP_FAILED for mmap failure. */
1071 static void *
1072 bfd_mmap_local (bfd *abfd, size_t rsize, int prot, void **map_addr,
1073 size_t *map_size)
1075 ufile_ptr filesize = bfd_get_file_size (abfd);
1076 ufile_ptr offset = bfd_tell (abfd);
1077 if (filesize < offset || filesize - offset < rsize)
1079 bfd_set_error (bfd_error_file_truncated);
1080 return NULL;
1083 void *mem;
1084 mem = bfd_mmap (abfd, NULL, rsize, prot, MAP_PRIVATE, offset,
1085 map_addr, map_size);
1086 return mem;
1089 /* Mmap a readonly memory region of RSIZE bytes at the current offset.
1090 Return mmap address and size in MAP_ADDR and MAP_SIZE. Return NULL
1091 on invalid input and MAP_FAILED for mmap failure. */
1093 void *
1094 _bfd_mmap_readonly_temporary (bfd *abfd, size_t rsize, void **map_addr,
1095 size_t *map_size)
1097 /* Use mmap only if section size >= the minimum mmap section size. */
1098 if (rsize < _bfd_minimum_mmap_size)
1100 void *mem = _bfd_malloc_and_read (abfd, rsize, rsize);
1101 /* NB: Set *MAP_ADDR to MEM and *MAP_SIZE to 0 to indicate that
1102 _bfd_malloc_and_read is called. */
1103 *map_addr = mem;
1104 *map_size = 0;
1105 return mem;
1108 return bfd_mmap_local (abfd, rsize, PROT_READ, map_addr, map_size);
1111 /* Munmap RSIZE bytes at PTR. */
1113 void
1114 _bfd_munmap_readonly_temporary (void *ptr, size_t rsize)
1116 /* NB: Since _bfd_munmap_readonly_temporary is called like free, PTR
1117 may be NULL. Otherwise, PTR and RSIZE must be valid. If RSIZE is
1118 0, _bfd_malloc_and_read is called. */
1119 if (ptr == NULL)
1120 return;
1121 if (rsize != 0)
1123 if (munmap (ptr, rsize) != 0)
1124 abort ();
1126 else
1127 free (ptr);
1130 /* Mmap a readonly memory region of RSIZE bytes at the current offset.
1131 Return NULL on invalid input or mmap failure. */
1133 void *
1134 _bfd_mmap_readonly_persistent (bfd *abfd, size_t rsize)
1136 /* Use mmap only if section size >= the minimum mmap section size. */
1137 if (rsize < _bfd_minimum_mmap_size)
1138 return _bfd_alloc_and_read (abfd, rsize, rsize);
1140 void *mem, *map_addr;
1141 size_t map_size;
1142 mem = bfd_mmap_local (abfd, rsize, PROT_READ, &map_addr, &map_size);
1143 if (mem == NULL)
1144 return mem;
1145 if (mem == MAP_FAILED)
1146 return _bfd_alloc_and_read (abfd, rsize, rsize);
1148 struct bfd_mmapped_entry *entry;
1149 unsigned int next_entry;
1150 struct bfd_mmapped *mmapped = abfd->mmapped;
1151 if (mmapped != NULL
1152 && (next_entry = mmapped->next_entry) < mmapped->max_entry)
1154 entry = &mmapped->entries[next_entry];
1155 mmapped->next_entry++;
1157 else
1159 mmapped = bfd_allocate_mmapped_page (abfd, &entry);
1160 if (mmapped == NULL)
1162 munmap (map_addr, map_size);
1163 return NULL;
1167 entry->addr = map_addr;
1168 entry->size = map_size;
1170 return mem;
1172 #endif
1174 /* Attempt to read *SIZE_P bytes from ABFD's iostream to *DATA_P.
1175 Return true if the full the amount has been read. If *DATA_P is
1176 NULL, mmap should be used, return the memory address at the
1177 current offset in *DATA_P as well as return mmap address and size
1178 in *MMAP_BASE and *SIZE_P. Otherwise, return NULL in *MMAP_BASE
1179 and 0 in *SIZE_P. If FINAL_LINK is true, this is called from
1180 elf_link_read_relocs_from_section. */
1182 bool
1183 _bfd_mmap_read_temporary (void **data_p, size_t *size_p,
1184 void **mmap_base, bfd *abfd,
1185 bool final_link ATTRIBUTE_UNUSED)
1187 void *data = *data_p;
1188 size_t size = *size_p;
1190 #ifdef USE_MMAP
1191 /* NB: When FINAL_LINK is true, the size of the preallocated buffer
1192 is _bfd_minimum_mmap_size and use mmap if the data size >=
1193 _bfd_minimum_mmap_size. Otherwise, use mmap if ABFD isn't an IR
1194 input or the data size >= _bfd_minimum_mmap_size. */
1195 bool use_mmmap;
1196 bool mmap_size = size >= _bfd_minimum_mmap_size;
1197 if (final_link)
1198 use_mmmap = mmap_size;
1199 else
1200 use_mmmap = (mmap_size
1201 && data == NULL
1202 && (abfd->flags & BFD_PLUGIN) == 0);
1203 if (use_mmmap)
1205 void *mmaped = _bfd_mmap_readonly_temporary (abfd, size,
1206 mmap_base,
1207 size_p);
1208 /* MAP_FAILED is returned when called from GDB on an object with
1209 opncls_iovec. Use bfd_read in this case. */
1210 if (mmaped != MAP_FAILED)
1212 if (mmaped == NULL)
1213 abort ();
1214 *data_p = mmaped;
1215 return true;
1218 #endif
1220 if (data == NULL)
1222 data = bfd_malloc (size);
1223 if (data == NULL)
1224 return false;
1225 *data_p = data;
1226 /* NB: _bfd_munmap_readonly_temporary will free *MMAP_BASE if
1227 *SIZE_P == 0. */
1228 *mmap_base = data;
1230 else
1231 *mmap_base = NULL;
1232 *size_p = 0;
1233 return bfd_read (data, size, abfd) == size;
1236 /* Default implementation */
1238 bool
1239 _bfd_generic_get_section_contents (bfd *abfd,
1240 sec_ptr section,
1241 void *location,
1242 file_ptr offset,
1243 bfd_size_type count)
1245 bfd_size_type sz;
1246 if (count == 0)
1247 return true;
1249 if (section->compress_status != COMPRESS_SECTION_NONE)
1251 _bfd_error_handler
1252 /* xgettext:c-format */
1253 (_("%pB: unable to get decompressed section %pA"),
1254 abfd, section);
1255 bfd_set_error (bfd_error_invalid_operation);
1256 return false;
1259 #ifdef USE_MMAP
1260 if (section->mmapped_p
1261 && (section->contents != NULL || location != NULL))
1263 _bfd_error_handler
1264 /* xgettext:c-format */
1265 (_("%pB: mapped section %pA has non-NULL buffer"),
1266 abfd, section);
1267 bfd_set_error (bfd_error_invalid_operation);
1268 return false;
1270 #endif
1272 sz = bfd_get_section_limit_octets (abfd, section);
1273 if (offset + count < count
1274 || offset + count > sz
1275 || (abfd->my_archive != NULL
1276 && !bfd_is_thin_archive (abfd->my_archive)
1277 && ((ufile_ptr) section->filepos + offset + count
1278 > arelt_size (abfd))))
1280 bfd_set_error (bfd_error_invalid_operation);
1281 return false;
1284 if (bfd_seek (abfd, section->filepos + offset, SEEK_SET) != 0)
1285 return false;
1287 #ifdef USE_MMAP
1288 if (section->mmapped_p)
1290 if (location != 0
1291 || bfd_get_flavour (abfd) != bfd_target_elf_flavour)
1292 abort ();
1294 int prot = ((section->reloc_count == 0)
1295 ? PROT_READ : PROT_READ | PROT_WRITE);
1297 location = bfd_mmap_local
1298 (abfd, count, prot, &elf_section_data (section)->contents_addr,
1299 &elf_section_data (section)->contents_size);
1301 if (location == NULL)
1302 return false;
1304 /* Check for iovec not supporting mmap. */
1305 if (location != MAP_FAILED)
1307 section->contents = location;
1308 return true;
1311 /* Malloc the buffer and call bfd_read. */
1312 location = (bfd_byte *) bfd_malloc (count);
1313 if (location == NULL)
1315 if (bfd_get_error () == bfd_error_no_memory)
1316 _bfd_error_handler
1317 /* xgettext:c-format */
1318 (_("error: %pB(%pA) is too large (%#" PRIx64 " bytes)"),
1319 abfd, section, (uint64_t) count);
1320 return false;
1322 section->contents = location;
1324 #endif
1326 if (bfd_read (location, count, abfd) != count)
1327 return false;
1329 return true;
1332 /* This generic function can only be used in implementations where creating
1333 NEW sections is disallowed. It is useful in patching existing sections
1334 in read-write files, though. See other set_section_contents functions
1335 to see why it doesn't work for new sections. */
1336 bool
1337 _bfd_generic_set_section_contents (bfd *abfd,
1338 sec_ptr section,
1339 const void *location,
1340 file_ptr offset,
1341 bfd_size_type count)
1343 if (count == 0)
1344 return true;
1346 if (bfd_seek (abfd, section->filepos + offset, SEEK_SET) != 0
1347 || bfd_write (location, count, abfd) != count)
1348 return false;
1350 return true;
1354 INTERNAL_FUNCTION
1355 bfd_log2
1357 SYNOPSIS
1358 unsigned int bfd_log2 (bfd_vma x);
1360 DESCRIPTION
1361 Return the log base 2 of the value supplied, rounded up. E.g., an
1362 @var{x} of 1025 returns 11. A @var{x} of 0 returns 0.
1365 unsigned int
1366 bfd_log2 (bfd_vma x)
1368 unsigned int result = 0;
1370 if (x <= 1)
1371 return result;
1372 --x;
1374 ++result;
1375 while ((x >>= 1) != 0);
1376 return result;
1379 bool
1380 bfd_generic_is_local_label_name (bfd *abfd, const char *name)
1382 char locals_prefix = (bfd_get_symbol_leading_char (abfd) == '_') ? 'L' : '.';
1384 return name[0] == locals_prefix;
1387 /* Helper function for reading uleb128 encoded data. */
1389 bfd_vma
1390 _bfd_read_unsigned_leb128 (bfd *abfd ATTRIBUTE_UNUSED,
1391 bfd_byte *buf,
1392 unsigned int *bytes_read_ptr)
1394 bfd_vma result;
1395 unsigned int num_read;
1396 unsigned int shift;
1397 bfd_byte byte;
1399 result = 0;
1400 shift = 0;
1401 num_read = 0;
1404 byte = bfd_get_8 (abfd, buf);
1405 buf++;
1406 num_read++;
1407 if (shift < 8 * sizeof (result))
1409 result |= (((bfd_vma) byte & 0x7f) << shift);
1410 shift += 7;
1413 while (byte & 0x80);
1414 *bytes_read_ptr = num_read;
1415 return result;
1418 /* Read in a LEB128 encoded value from ABFD starting at *PTR.
1419 If SIGN is true, return a signed LEB128 value.
1420 *PTR is incremented by the number of bytes read.
1421 No bytes will be read at address END or beyond. */
1423 bfd_vma
1424 _bfd_safe_read_leb128 (bfd *abfd ATTRIBUTE_UNUSED,
1425 bfd_byte **ptr,
1426 bool sign,
1427 const bfd_byte * const end)
1429 bfd_vma result = 0;
1430 unsigned int shift = 0;
1431 bfd_byte byte = 0;
1432 bfd_byte *data = *ptr;
1434 while (data < end)
1436 byte = bfd_get_8 (abfd, data);
1437 data++;
1438 if (shift < 8 * sizeof (result))
1440 result |= ((bfd_vma) (byte & 0x7f)) << shift;
1441 shift += 7;
1443 if ((byte & 0x80) == 0)
1444 break;
1447 *ptr = data;
1449 if (sign && (shift < 8 * sizeof (result)) && (byte & 0x40))
1450 result |= -((bfd_vma) 1 << shift);
1452 return result;
1455 /* Helper function for reading sleb128 encoded data. */
1457 bfd_signed_vma
1458 _bfd_read_signed_leb128 (bfd *abfd ATTRIBUTE_UNUSED,
1459 bfd_byte *buf,
1460 unsigned int *bytes_read_ptr)
1462 bfd_vma result;
1463 unsigned int shift;
1464 unsigned int num_read;
1465 bfd_byte byte;
1467 result = 0;
1468 shift = 0;
1469 num_read = 0;
1472 byte = bfd_get_8 (abfd, buf);
1473 buf ++;
1474 num_read ++;
1475 if (shift < 8 * sizeof (result))
1477 result |= (((bfd_vma) byte & 0x7f) << shift);
1478 shift += 7;
1481 while (byte & 0x80);
1482 if (shift < 8 * sizeof (result) && (byte & 0x40))
1483 result |= (((bfd_vma) -1) << shift);
1484 *bytes_read_ptr = num_read;
1485 return result;
1488 /* Write VAL in uleb128 format to P.
1489 END indicates the last byte of allocated space for the uleb128 value to fit
1491 Return a pointer to the byte following the last byte that was written, or
1492 NULL if the uleb128 value does not fit in the allocated space between P and
1493 END. */
1494 bfd_byte *
1495 _bfd_write_unsigned_leb128 (bfd_byte *p, bfd_byte *end, bfd_vma val)
1497 bfd_byte c;
1500 if (p > end)
1501 return NULL;
1502 c = val & 0x7f;
1503 val >>= 7;
1504 if (val)
1505 c |= 0x80;
1506 *(p++) = c;
1508 while (val);
1509 return p;
1512 bool
1513 _bfd_generic_init_private_section_data (bfd *ibfd ATTRIBUTE_UNUSED,
1514 asection *isec ATTRIBUTE_UNUSED,
1515 bfd *obfd ATTRIBUTE_UNUSED,
1516 asection *osec ATTRIBUTE_UNUSED,
1517 struct bfd_link_info *link_info ATTRIBUTE_UNUSED)
1519 return true;
1522 #ifdef HAVE_MMAP
1523 uintptr_t _bfd_pagesize;
1524 uintptr_t _bfd_pagesize_m1;
1525 uintptr_t _bfd_minimum_mmap_size;
1527 __attribute__ ((unused, constructor))
1528 static void
1529 bfd_init_pagesize (void)
1531 _bfd_pagesize = getpagesize ();
1532 if (_bfd_pagesize == 0)
1533 abort ();
1534 _bfd_pagesize_m1 = _bfd_pagesize - 1;
1535 /* The minimum section size to use mmap. */
1536 _bfd_minimum_mmap_size = _bfd_pagesize * 4;
1538 #endif