15796c8dcSSimon Schubert /* Assorted BFD support routines, only used internally.
25796c8dcSSimon Schubert Copyright 1990, 1991, 1992, 1993, 1994, 1995, 1996, 1997, 1998, 1999,
3c50c785cSJohn Marino 2000, 2001, 2002, 2003, 2004, 2005, 2007, 2008, 2009, 2010, 2011
45796c8dcSSimon Schubert Free Software Foundation, Inc.
55796c8dcSSimon Schubert Written by Cygnus Support.
65796c8dcSSimon Schubert
75796c8dcSSimon Schubert This file is part of BFD, the Binary File Descriptor library.
85796c8dcSSimon Schubert
95796c8dcSSimon Schubert This program is free software; you can redistribute it and/or modify
105796c8dcSSimon Schubert it under the terms of the GNU General Public License as published by
115796c8dcSSimon Schubert the Free Software Foundation; either version 3 of the License, or
125796c8dcSSimon Schubert (at your option) any later version.
135796c8dcSSimon Schubert
145796c8dcSSimon Schubert This program is distributed in the hope that it will be useful,
155796c8dcSSimon Schubert but WITHOUT ANY WARRANTY; without even the implied warranty of
165796c8dcSSimon Schubert MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
175796c8dcSSimon Schubert GNU General Public License for more details.
185796c8dcSSimon Schubert
195796c8dcSSimon Schubert You should have received a copy of the GNU General Public License
205796c8dcSSimon Schubert along with this program; if not, write to the Free Software
215796c8dcSSimon Schubert Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston,
225796c8dcSSimon Schubert MA 02110-1301, USA. */
235796c8dcSSimon Schubert
245796c8dcSSimon Schubert #include "sysdep.h"
255796c8dcSSimon Schubert #include "bfd.h"
265796c8dcSSimon Schubert #include "libbfd.h"
275796c8dcSSimon Schubert
285796c8dcSSimon Schubert #ifndef HAVE_GETPAGESIZE
295796c8dcSSimon Schubert #define getpagesize() 2048
305796c8dcSSimon Schubert #endif
315796c8dcSSimon Schubert
325796c8dcSSimon Schubert /*
335796c8dcSSimon Schubert SECTION
345796c8dcSSimon Schubert Implementation details
355796c8dcSSimon Schubert
365796c8dcSSimon Schubert SUBSECTION
375796c8dcSSimon Schubert Internal functions
385796c8dcSSimon Schubert
395796c8dcSSimon Schubert DESCRIPTION
405796c8dcSSimon Schubert These routines are used within BFD.
415796c8dcSSimon Schubert They are not intended for export, but are documented here for
425796c8dcSSimon Schubert completeness.
435796c8dcSSimon Schubert */
445796c8dcSSimon Schubert
455796c8dcSSimon Schubert /* A routine which is used in target vectors for unsupported
465796c8dcSSimon Schubert operations. */
475796c8dcSSimon Schubert
485796c8dcSSimon Schubert bfd_boolean
bfd_false(bfd * ignore ATTRIBUTE_UNUSED)495796c8dcSSimon Schubert bfd_false (bfd *ignore ATTRIBUTE_UNUSED)
505796c8dcSSimon Schubert {
515796c8dcSSimon Schubert bfd_set_error (bfd_error_invalid_operation);
525796c8dcSSimon Schubert return FALSE;
535796c8dcSSimon Schubert }
545796c8dcSSimon Schubert
555796c8dcSSimon Schubert /* A routine which is used in target vectors for supported operations
565796c8dcSSimon Schubert which do not actually do anything. */
575796c8dcSSimon Schubert
585796c8dcSSimon Schubert bfd_boolean
bfd_true(bfd * ignore ATTRIBUTE_UNUSED)595796c8dcSSimon Schubert bfd_true (bfd *ignore ATTRIBUTE_UNUSED)
605796c8dcSSimon Schubert {
615796c8dcSSimon Schubert return TRUE;
625796c8dcSSimon Schubert }
635796c8dcSSimon Schubert
645796c8dcSSimon Schubert /* A routine which is used in target vectors for unsupported
655796c8dcSSimon Schubert operations which return a pointer value. */
665796c8dcSSimon Schubert
675796c8dcSSimon Schubert void *
bfd_nullvoidptr(bfd * ignore ATTRIBUTE_UNUSED)685796c8dcSSimon Schubert bfd_nullvoidptr (bfd *ignore ATTRIBUTE_UNUSED)
695796c8dcSSimon Schubert {
705796c8dcSSimon Schubert bfd_set_error (bfd_error_invalid_operation);
715796c8dcSSimon Schubert return NULL;
725796c8dcSSimon Schubert }
735796c8dcSSimon Schubert
745796c8dcSSimon Schubert int
bfd_0(bfd * ignore ATTRIBUTE_UNUSED)755796c8dcSSimon Schubert bfd_0 (bfd *ignore ATTRIBUTE_UNUSED)
765796c8dcSSimon Schubert {
775796c8dcSSimon Schubert return 0;
785796c8dcSSimon Schubert }
795796c8dcSSimon Schubert
805796c8dcSSimon Schubert unsigned int
bfd_0u(bfd * ignore ATTRIBUTE_UNUSED)815796c8dcSSimon Schubert bfd_0u (bfd *ignore ATTRIBUTE_UNUSED)
825796c8dcSSimon Schubert {
835796c8dcSSimon Schubert return 0;
845796c8dcSSimon Schubert }
855796c8dcSSimon Schubert
865796c8dcSSimon Schubert long
bfd_0l(bfd * ignore ATTRIBUTE_UNUSED)875796c8dcSSimon Schubert bfd_0l (bfd *ignore ATTRIBUTE_UNUSED)
885796c8dcSSimon Schubert {
895796c8dcSSimon Schubert return 0;
905796c8dcSSimon Schubert }
915796c8dcSSimon Schubert
925796c8dcSSimon Schubert /* A routine which is used in target vectors for unsupported
935796c8dcSSimon Schubert operations which return -1 on error. */
945796c8dcSSimon Schubert
955796c8dcSSimon Schubert long
_bfd_n1(bfd * ignore_abfd ATTRIBUTE_UNUSED)965796c8dcSSimon Schubert _bfd_n1 (bfd *ignore_abfd ATTRIBUTE_UNUSED)
975796c8dcSSimon Schubert {
985796c8dcSSimon Schubert bfd_set_error (bfd_error_invalid_operation);
995796c8dcSSimon Schubert return -1;
1005796c8dcSSimon Schubert }
1015796c8dcSSimon Schubert
1025796c8dcSSimon Schubert void
bfd_void(bfd * ignore ATTRIBUTE_UNUSED)1035796c8dcSSimon Schubert bfd_void (bfd *ignore ATTRIBUTE_UNUSED)
1045796c8dcSSimon Schubert {
1055796c8dcSSimon Schubert }
1065796c8dcSSimon Schubert
1075796c8dcSSimon Schubert long
_bfd_norelocs_get_reloc_upper_bound(bfd * abfd ATTRIBUTE_UNUSED,asection * sec ATTRIBUTE_UNUSED)1085796c8dcSSimon Schubert _bfd_norelocs_get_reloc_upper_bound (bfd *abfd ATTRIBUTE_UNUSED,
1095796c8dcSSimon Schubert asection *sec ATTRIBUTE_UNUSED)
1105796c8dcSSimon Schubert {
1115796c8dcSSimon Schubert return sizeof (arelent *);
1125796c8dcSSimon Schubert }
1135796c8dcSSimon Schubert
1145796c8dcSSimon Schubert long
_bfd_norelocs_canonicalize_reloc(bfd * abfd ATTRIBUTE_UNUSED,asection * sec ATTRIBUTE_UNUSED,arelent ** relptr,asymbol ** symbols ATTRIBUTE_UNUSED)1155796c8dcSSimon Schubert _bfd_norelocs_canonicalize_reloc (bfd *abfd ATTRIBUTE_UNUSED,
1165796c8dcSSimon Schubert asection *sec ATTRIBUTE_UNUSED,
1175796c8dcSSimon Schubert arelent **relptr,
1185796c8dcSSimon Schubert asymbol **symbols ATTRIBUTE_UNUSED)
1195796c8dcSSimon Schubert {
1205796c8dcSSimon Schubert *relptr = NULL;
1215796c8dcSSimon Schubert return 0;
1225796c8dcSSimon Schubert }
1235796c8dcSSimon Schubert
1245796c8dcSSimon Schubert bfd_boolean
_bfd_nocore_core_file_matches_executable_p(bfd * ignore_core_bfd ATTRIBUTE_UNUSED,bfd * ignore_exec_bfd ATTRIBUTE_UNUSED)1255796c8dcSSimon Schubert _bfd_nocore_core_file_matches_executable_p
1265796c8dcSSimon Schubert (bfd *ignore_core_bfd ATTRIBUTE_UNUSED,
1275796c8dcSSimon Schubert bfd *ignore_exec_bfd ATTRIBUTE_UNUSED)
1285796c8dcSSimon Schubert {
1295796c8dcSSimon Schubert bfd_set_error (bfd_error_invalid_operation);
1305796c8dcSSimon Schubert return FALSE;
1315796c8dcSSimon Schubert }
1325796c8dcSSimon Schubert
1335796c8dcSSimon Schubert /* Routine to handle core_file_failing_command entry point for targets
1345796c8dcSSimon Schubert without core file support. */
1355796c8dcSSimon Schubert
1365796c8dcSSimon Schubert char *
_bfd_nocore_core_file_failing_command(bfd * ignore_abfd ATTRIBUTE_UNUSED)1375796c8dcSSimon Schubert _bfd_nocore_core_file_failing_command (bfd *ignore_abfd ATTRIBUTE_UNUSED)
1385796c8dcSSimon Schubert {
1395796c8dcSSimon Schubert bfd_set_error (bfd_error_invalid_operation);
1405796c8dcSSimon Schubert return NULL;
1415796c8dcSSimon Schubert }
1425796c8dcSSimon Schubert
1435796c8dcSSimon Schubert /* Routine to handle core_file_failing_signal entry point for targets
1445796c8dcSSimon Schubert without core file support. */
1455796c8dcSSimon Schubert
1465796c8dcSSimon Schubert int
_bfd_nocore_core_file_failing_signal(bfd * ignore_abfd ATTRIBUTE_UNUSED)1475796c8dcSSimon Schubert _bfd_nocore_core_file_failing_signal (bfd *ignore_abfd ATTRIBUTE_UNUSED)
1485796c8dcSSimon Schubert {
1495796c8dcSSimon Schubert bfd_set_error (bfd_error_invalid_operation);
1505796c8dcSSimon Schubert return 0;
1515796c8dcSSimon Schubert }
1525796c8dcSSimon Schubert
153c50c785cSJohn Marino /* Routine to handle the core_file_pid entry point for targets without
154c50c785cSJohn Marino core file support. */
155c50c785cSJohn Marino
156c50c785cSJohn Marino int
_bfd_nocore_core_file_pid(bfd * ignore_abfd ATTRIBUTE_UNUSED)157c50c785cSJohn Marino _bfd_nocore_core_file_pid (bfd *ignore_abfd ATTRIBUTE_UNUSED)
158c50c785cSJohn Marino {
159c50c785cSJohn Marino bfd_set_error (bfd_error_invalid_operation);
160c50c785cSJohn Marino return 0;
161c50c785cSJohn Marino }
162c50c785cSJohn Marino
1635796c8dcSSimon Schubert const bfd_target *
_bfd_dummy_target(bfd * ignore_abfd ATTRIBUTE_UNUSED)1645796c8dcSSimon Schubert _bfd_dummy_target (bfd *ignore_abfd ATTRIBUTE_UNUSED)
1655796c8dcSSimon Schubert {
1665796c8dcSSimon Schubert bfd_set_error (bfd_error_wrong_format);
1675796c8dcSSimon Schubert return 0;
1685796c8dcSSimon Schubert }
1695796c8dcSSimon Schubert
1705796c8dcSSimon Schubert /* Allocate memory using malloc. */
1715796c8dcSSimon Schubert
1725796c8dcSSimon Schubert void *
bfd_malloc(bfd_size_type size)1735796c8dcSSimon Schubert bfd_malloc (bfd_size_type size)
1745796c8dcSSimon Schubert {
1755796c8dcSSimon Schubert void *ptr;
1765796c8dcSSimon Schubert
1775796c8dcSSimon Schubert if (size != (size_t) size)
1785796c8dcSSimon Schubert {
1795796c8dcSSimon Schubert bfd_set_error (bfd_error_no_memory);
1805796c8dcSSimon Schubert return NULL;
1815796c8dcSSimon Schubert }
1825796c8dcSSimon Schubert
1835796c8dcSSimon Schubert ptr = malloc ((size_t) size);
1845796c8dcSSimon Schubert if (ptr == NULL && (size_t) size != 0)
1855796c8dcSSimon Schubert bfd_set_error (bfd_error_no_memory);
1865796c8dcSSimon Schubert
1875796c8dcSSimon Schubert return ptr;
1885796c8dcSSimon Schubert }
1895796c8dcSSimon Schubert
1905796c8dcSSimon Schubert /* Allocate memory using malloc, nmemb * size with overflow checking. */
1915796c8dcSSimon Schubert
1925796c8dcSSimon Schubert void *
bfd_malloc2(bfd_size_type nmemb,bfd_size_type size)1935796c8dcSSimon Schubert bfd_malloc2 (bfd_size_type nmemb, bfd_size_type size)
1945796c8dcSSimon Schubert {
1955796c8dcSSimon Schubert void *ptr;
1965796c8dcSSimon Schubert
1975796c8dcSSimon Schubert if ((nmemb | size) >= HALF_BFD_SIZE_TYPE
1985796c8dcSSimon Schubert && size != 0
1995796c8dcSSimon Schubert && nmemb > ~(bfd_size_type) 0 / size)
2005796c8dcSSimon Schubert {
2015796c8dcSSimon Schubert bfd_set_error (bfd_error_no_memory);
2025796c8dcSSimon Schubert return NULL;
2035796c8dcSSimon Schubert }
2045796c8dcSSimon Schubert
2055796c8dcSSimon Schubert size *= nmemb;
2065796c8dcSSimon Schubert
2075796c8dcSSimon Schubert if (size != (size_t) size)
2085796c8dcSSimon Schubert {
2095796c8dcSSimon Schubert bfd_set_error (bfd_error_no_memory);
2105796c8dcSSimon Schubert return NULL;
2115796c8dcSSimon Schubert }
2125796c8dcSSimon Schubert
2135796c8dcSSimon Schubert ptr = malloc ((size_t) size);
2145796c8dcSSimon Schubert if (ptr == NULL && (size_t) size != 0)
2155796c8dcSSimon Schubert bfd_set_error (bfd_error_no_memory);
2165796c8dcSSimon Schubert
2175796c8dcSSimon Schubert return ptr;
2185796c8dcSSimon Schubert }
2195796c8dcSSimon Schubert
2205796c8dcSSimon Schubert /* Reallocate memory using realloc. */
2215796c8dcSSimon Schubert
2225796c8dcSSimon Schubert void *
bfd_realloc(void * ptr,bfd_size_type size)2235796c8dcSSimon Schubert bfd_realloc (void *ptr, bfd_size_type size)
2245796c8dcSSimon Schubert {
2255796c8dcSSimon Schubert void *ret;
2265796c8dcSSimon Schubert
2275796c8dcSSimon Schubert if (size != (size_t) size)
2285796c8dcSSimon Schubert {
2295796c8dcSSimon Schubert bfd_set_error (bfd_error_no_memory);
2305796c8dcSSimon Schubert return NULL;
2315796c8dcSSimon Schubert }
2325796c8dcSSimon Schubert
2335796c8dcSSimon Schubert if (ptr == NULL)
2345796c8dcSSimon Schubert ret = malloc ((size_t) size);
2355796c8dcSSimon Schubert else
2365796c8dcSSimon Schubert ret = realloc (ptr, (size_t) size);
2375796c8dcSSimon Schubert
2385796c8dcSSimon Schubert if (ret == NULL && (size_t) size != 0)
2395796c8dcSSimon Schubert bfd_set_error (bfd_error_no_memory);
2405796c8dcSSimon Schubert
2415796c8dcSSimon Schubert return ret;
2425796c8dcSSimon Schubert }
2435796c8dcSSimon Schubert
2445796c8dcSSimon Schubert /* Reallocate memory using realloc, nmemb * size with overflow checking. */
2455796c8dcSSimon Schubert
2465796c8dcSSimon Schubert void *
bfd_realloc2(void * ptr,bfd_size_type nmemb,bfd_size_type size)2475796c8dcSSimon Schubert bfd_realloc2 (void *ptr, bfd_size_type nmemb, bfd_size_type size)
2485796c8dcSSimon Schubert {
2495796c8dcSSimon Schubert void *ret;
2505796c8dcSSimon Schubert
2515796c8dcSSimon Schubert if ((nmemb | size) >= HALF_BFD_SIZE_TYPE
2525796c8dcSSimon Schubert && size != 0
2535796c8dcSSimon Schubert && nmemb > ~(bfd_size_type) 0 / size)
2545796c8dcSSimon Schubert {
2555796c8dcSSimon Schubert bfd_set_error (bfd_error_no_memory);
2565796c8dcSSimon Schubert return NULL;
2575796c8dcSSimon Schubert }
2585796c8dcSSimon Schubert
2595796c8dcSSimon Schubert size *= nmemb;
2605796c8dcSSimon Schubert
2615796c8dcSSimon Schubert if (size != (size_t) size)
2625796c8dcSSimon Schubert {
2635796c8dcSSimon Schubert bfd_set_error (bfd_error_no_memory);
2645796c8dcSSimon Schubert return NULL;
2655796c8dcSSimon Schubert }
2665796c8dcSSimon Schubert
2675796c8dcSSimon Schubert if (ptr == NULL)
2685796c8dcSSimon Schubert ret = malloc ((size_t) size);
2695796c8dcSSimon Schubert else
2705796c8dcSSimon Schubert ret = realloc (ptr, (size_t) size);
2715796c8dcSSimon Schubert
2725796c8dcSSimon Schubert if (ret == NULL && (size_t) size != 0)
2735796c8dcSSimon Schubert bfd_set_error (bfd_error_no_memory);
2745796c8dcSSimon Schubert
2755796c8dcSSimon Schubert return ret;
2765796c8dcSSimon Schubert }
2775796c8dcSSimon Schubert
2785796c8dcSSimon Schubert /* Reallocate memory using realloc.
2795796c8dcSSimon Schubert If this fails the pointer is freed before returning. */
2805796c8dcSSimon Schubert
2815796c8dcSSimon Schubert void *
bfd_realloc_or_free(void * ptr,bfd_size_type size)2825796c8dcSSimon Schubert bfd_realloc_or_free (void *ptr, bfd_size_type size)
2835796c8dcSSimon Schubert {
2845796c8dcSSimon Schubert size_t amount = (size_t) size;
2855796c8dcSSimon Schubert void *ret;
2865796c8dcSSimon Schubert
2875796c8dcSSimon Schubert if (size != amount)
2885796c8dcSSimon Schubert ret = NULL;
2895796c8dcSSimon Schubert else if (ptr == NULL)
2905796c8dcSSimon Schubert ret = malloc (amount);
2915796c8dcSSimon Schubert else
2925796c8dcSSimon Schubert ret = realloc (ptr, amount);
2935796c8dcSSimon Schubert
2945796c8dcSSimon Schubert if (ret == NULL)
2955796c8dcSSimon Schubert {
2965796c8dcSSimon Schubert if (amount > 0)
2975796c8dcSSimon Schubert bfd_set_error (bfd_error_no_memory);
2985796c8dcSSimon Schubert
2995796c8dcSSimon Schubert if (ptr != NULL)
3005796c8dcSSimon Schubert free (ptr);
3015796c8dcSSimon Schubert }
3025796c8dcSSimon Schubert
3035796c8dcSSimon Schubert return ret;
3045796c8dcSSimon Schubert }
3055796c8dcSSimon Schubert
3065796c8dcSSimon Schubert /* Allocate memory using malloc and clear it. */
3075796c8dcSSimon Schubert
3085796c8dcSSimon Schubert void *
bfd_zmalloc(bfd_size_type size)3095796c8dcSSimon Schubert bfd_zmalloc (bfd_size_type size)
3105796c8dcSSimon Schubert {
3115796c8dcSSimon Schubert void *ptr;
3125796c8dcSSimon Schubert
3135796c8dcSSimon Schubert if (size != (size_t) size)
3145796c8dcSSimon Schubert {
3155796c8dcSSimon Schubert bfd_set_error (bfd_error_no_memory);
3165796c8dcSSimon Schubert return NULL;
3175796c8dcSSimon Schubert }
3185796c8dcSSimon Schubert
3195796c8dcSSimon Schubert ptr = malloc ((size_t) size);
3205796c8dcSSimon Schubert
3215796c8dcSSimon Schubert if ((size_t) size != 0)
3225796c8dcSSimon Schubert {
3235796c8dcSSimon Schubert if (ptr == NULL)
3245796c8dcSSimon Schubert bfd_set_error (bfd_error_no_memory);
3255796c8dcSSimon Schubert else
3265796c8dcSSimon Schubert memset (ptr, 0, (size_t) size);
3275796c8dcSSimon Schubert }
3285796c8dcSSimon Schubert
3295796c8dcSSimon Schubert return ptr;
3305796c8dcSSimon Schubert }
3315796c8dcSSimon Schubert
3325796c8dcSSimon Schubert /* Allocate memory using malloc (nmemb * size) with overflow checking
3335796c8dcSSimon Schubert and clear it. */
3345796c8dcSSimon Schubert
3355796c8dcSSimon Schubert void *
bfd_zmalloc2(bfd_size_type nmemb,bfd_size_type size)3365796c8dcSSimon Schubert bfd_zmalloc2 (bfd_size_type nmemb, bfd_size_type size)
3375796c8dcSSimon Schubert {
3385796c8dcSSimon Schubert void *ptr;
3395796c8dcSSimon Schubert
3405796c8dcSSimon Schubert if ((nmemb | size) >= HALF_BFD_SIZE_TYPE
3415796c8dcSSimon Schubert && size != 0
3425796c8dcSSimon Schubert && nmemb > ~(bfd_size_type) 0 / size)
3435796c8dcSSimon Schubert {
3445796c8dcSSimon Schubert bfd_set_error (bfd_error_no_memory);
3455796c8dcSSimon Schubert return NULL;
3465796c8dcSSimon Schubert }
3475796c8dcSSimon Schubert
3485796c8dcSSimon Schubert size *= nmemb;
3495796c8dcSSimon Schubert
3505796c8dcSSimon Schubert if (size != (size_t) size)
3515796c8dcSSimon Schubert {
3525796c8dcSSimon Schubert bfd_set_error (bfd_error_no_memory);
3535796c8dcSSimon Schubert return NULL;
3545796c8dcSSimon Schubert }
3555796c8dcSSimon Schubert
3565796c8dcSSimon Schubert ptr = malloc ((size_t) size);
3575796c8dcSSimon Schubert
3585796c8dcSSimon Schubert if ((size_t) size != 0)
3595796c8dcSSimon Schubert {
3605796c8dcSSimon Schubert if (ptr == NULL)
3615796c8dcSSimon Schubert bfd_set_error (bfd_error_no_memory);
3625796c8dcSSimon Schubert else
3635796c8dcSSimon Schubert memset (ptr, 0, (size_t) size);
3645796c8dcSSimon Schubert }
3655796c8dcSSimon Schubert
3665796c8dcSSimon Schubert return ptr;
3675796c8dcSSimon Schubert }
3685796c8dcSSimon Schubert
3695796c8dcSSimon Schubert /*
3705796c8dcSSimon Schubert INTERNAL_FUNCTION
3715796c8dcSSimon Schubert bfd_write_bigendian_4byte_int
3725796c8dcSSimon Schubert
3735796c8dcSSimon Schubert SYNOPSIS
3745796c8dcSSimon Schubert bfd_boolean bfd_write_bigendian_4byte_int (bfd *, unsigned int);
3755796c8dcSSimon Schubert
3765796c8dcSSimon Schubert DESCRIPTION
3775796c8dcSSimon Schubert Write a 4 byte integer @var{i} to the output BFD @var{abfd}, in big
3785796c8dcSSimon Schubert endian order regardless of what else is going on. This is useful in
3795796c8dcSSimon Schubert archives.
3805796c8dcSSimon Schubert
3815796c8dcSSimon Schubert */
3825796c8dcSSimon Schubert bfd_boolean
bfd_write_bigendian_4byte_int(bfd * abfd,unsigned int i)3835796c8dcSSimon Schubert bfd_write_bigendian_4byte_int (bfd *abfd, unsigned int i)
3845796c8dcSSimon Schubert {
3855796c8dcSSimon Schubert bfd_byte buffer[4];
3865796c8dcSSimon Schubert bfd_putb32 ((bfd_vma) i, buffer);
3875796c8dcSSimon Schubert return bfd_bwrite (buffer, (bfd_size_type) 4, abfd) == 4;
3885796c8dcSSimon Schubert }
3895796c8dcSSimon Schubert
3905796c8dcSSimon Schubert
3915796c8dcSSimon Schubert /** The do-it-yourself (byte) sex-change kit */
3925796c8dcSSimon Schubert
3935796c8dcSSimon Schubert /* The middle letter e.g. get<b>short indicates Big or Little endian
3945796c8dcSSimon Schubert target machine. It doesn't matter what the byte order of the host
3955796c8dcSSimon Schubert machine is; these routines work for either. */
3965796c8dcSSimon Schubert
3975796c8dcSSimon Schubert /* FIXME: Should these take a count argument?
3985796c8dcSSimon Schubert Answer (gnu@cygnus.com): No, but perhaps they should be inline
3995796c8dcSSimon Schubert functions in swap.h #ifdef __GNUC__.
4005796c8dcSSimon Schubert Gprof them later and find out. */
4015796c8dcSSimon Schubert
4025796c8dcSSimon Schubert /*
4035796c8dcSSimon Schubert FUNCTION
4045796c8dcSSimon Schubert bfd_put_size
4055796c8dcSSimon Schubert FUNCTION
4065796c8dcSSimon Schubert bfd_get_size
4075796c8dcSSimon Schubert
4085796c8dcSSimon Schubert DESCRIPTION
4095796c8dcSSimon Schubert These macros as used for reading and writing raw data in
4105796c8dcSSimon Schubert sections; each access (except for bytes) is vectored through
4115796c8dcSSimon Schubert the target format of the BFD and mangled accordingly. The
4125796c8dcSSimon Schubert mangling performs any necessary endian translations and
4135796c8dcSSimon Schubert removes alignment restrictions. Note that types accepted and
4145796c8dcSSimon Schubert returned by these macros are identical so they can be swapped
4155796c8dcSSimon Schubert around in macros---for example, @file{libaout.h} defines <<GET_WORD>>
4165796c8dcSSimon Schubert to either <<bfd_get_32>> or <<bfd_get_64>>.
4175796c8dcSSimon Schubert
4185796c8dcSSimon Schubert In the put routines, @var{val} must be a <<bfd_vma>>. If we are on a
4195796c8dcSSimon Schubert system without prototypes, the caller is responsible for making
4205796c8dcSSimon Schubert sure that is true, with a cast if necessary. We don't cast
4215796c8dcSSimon Schubert them in the macro definitions because that would prevent <<lint>>
4225796c8dcSSimon Schubert or <<gcc -Wall>> from detecting sins such as passing a pointer.
4235796c8dcSSimon Schubert To detect calling these with less than a <<bfd_vma>>, use
4245796c8dcSSimon Schubert <<gcc -Wconversion>> on a host with 64 bit <<bfd_vma>>'s.
4255796c8dcSSimon Schubert
4265796c8dcSSimon Schubert .
4275796c8dcSSimon Schubert .{* Byte swapping macros for user section data. *}
4285796c8dcSSimon Schubert .
4295796c8dcSSimon Schubert .#define bfd_put_8(abfd, val, ptr) \
4305796c8dcSSimon Schubert . ((void) (*((unsigned char *) (ptr)) = (val) & 0xff))
4315796c8dcSSimon Schubert .#define bfd_put_signed_8 \
4325796c8dcSSimon Schubert . bfd_put_8
4335796c8dcSSimon Schubert .#define bfd_get_8(abfd, ptr) \
434a45ae5f8SJohn Marino . (*(const unsigned char *) (ptr) & 0xff)
4355796c8dcSSimon Schubert .#define bfd_get_signed_8(abfd, ptr) \
436a45ae5f8SJohn Marino . (((*(const unsigned char *) (ptr) & 0xff) ^ 0x80) - 0x80)
4375796c8dcSSimon Schubert .
4385796c8dcSSimon Schubert .#define bfd_put_16(abfd, val, ptr) \
4395796c8dcSSimon Schubert . BFD_SEND (abfd, bfd_putx16, ((val),(ptr)))
4405796c8dcSSimon Schubert .#define bfd_put_signed_16 \
4415796c8dcSSimon Schubert . bfd_put_16
4425796c8dcSSimon Schubert .#define bfd_get_16(abfd, ptr) \
4435796c8dcSSimon Schubert . BFD_SEND (abfd, bfd_getx16, (ptr))
4445796c8dcSSimon Schubert .#define bfd_get_signed_16(abfd, ptr) \
4455796c8dcSSimon Schubert . BFD_SEND (abfd, bfd_getx_signed_16, (ptr))
4465796c8dcSSimon Schubert .
4475796c8dcSSimon Schubert .#define bfd_put_32(abfd, val, ptr) \
4485796c8dcSSimon Schubert . BFD_SEND (abfd, bfd_putx32, ((val),(ptr)))
4495796c8dcSSimon Schubert .#define bfd_put_signed_32 \
4505796c8dcSSimon Schubert . bfd_put_32
4515796c8dcSSimon Schubert .#define bfd_get_32(abfd, ptr) \
4525796c8dcSSimon Schubert . BFD_SEND (abfd, bfd_getx32, (ptr))
4535796c8dcSSimon Schubert .#define bfd_get_signed_32(abfd, ptr) \
4545796c8dcSSimon Schubert . BFD_SEND (abfd, bfd_getx_signed_32, (ptr))
4555796c8dcSSimon Schubert .
4565796c8dcSSimon Schubert .#define bfd_put_64(abfd, val, ptr) \
4575796c8dcSSimon Schubert . BFD_SEND (abfd, bfd_putx64, ((val), (ptr)))
4585796c8dcSSimon Schubert .#define bfd_put_signed_64 \
4595796c8dcSSimon Schubert . bfd_put_64
4605796c8dcSSimon Schubert .#define bfd_get_64(abfd, ptr) \
4615796c8dcSSimon Schubert . BFD_SEND (abfd, bfd_getx64, (ptr))
4625796c8dcSSimon Schubert .#define bfd_get_signed_64(abfd, ptr) \
4635796c8dcSSimon Schubert . BFD_SEND (abfd, bfd_getx_signed_64, (ptr))
4645796c8dcSSimon Schubert .
4655796c8dcSSimon Schubert .#define bfd_get(bits, abfd, ptr) \
4665796c8dcSSimon Schubert . ((bits) == 8 ? (bfd_vma) bfd_get_8 (abfd, ptr) \
4675796c8dcSSimon Schubert . : (bits) == 16 ? bfd_get_16 (abfd, ptr) \
4685796c8dcSSimon Schubert . : (bits) == 32 ? bfd_get_32 (abfd, ptr) \
4695796c8dcSSimon Schubert . : (bits) == 64 ? bfd_get_64 (abfd, ptr) \
4705796c8dcSSimon Schubert . : (abort (), (bfd_vma) - 1))
4715796c8dcSSimon Schubert .
4725796c8dcSSimon Schubert .#define bfd_put(bits, abfd, val, ptr) \
4735796c8dcSSimon Schubert . ((bits) == 8 ? bfd_put_8 (abfd, val, ptr) \
4745796c8dcSSimon Schubert . : (bits) == 16 ? bfd_put_16 (abfd, val, ptr) \
4755796c8dcSSimon Schubert . : (bits) == 32 ? bfd_put_32 (abfd, val, ptr) \
4765796c8dcSSimon Schubert . : (bits) == 64 ? bfd_put_64 (abfd, val, ptr) \
4775796c8dcSSimon Schubert . : (abort (), (void) 0))
4785796c8dcSSimon Schubert .
4795796c8dcSSimon Schubert */
4805796c8dcSSimon Schubert
4815796c8dcSSimon Schubert /*
4825796c8dcSSimon Schubert FUNCTION
4835796c8dcSSimon Schubert bfd_h_put_size
4845796c8dcSSimon Schubert bfd_h_get_size
4855796c8dcSSimon Schubert
4865796c8dcSSimon Schubert DESCRIPTION
4875796c8dcSSimon Schubert These macros have the same function as their <<bfd_get_x>>
4885796c8dcSSimon Schubert brethren, except that they are used for removing information
4895796c8dcSSimon Schubert for the header records of object files. Believe it or not,
4905796c8dcSSimon Schubert some object files keep their header records in big endian
4915796c8dcSSimon Schubert order and their data in little endian order.
4925796c8dcSSimon Schubert .
4935796c8dcSSimon Schubert .{* Byte swapping macros for file header data. *}
4945796c8dcSSimon Schubert .
4955796c8dcSSimon Schubert .#define bfd_h_put_8(abfd, val, ptr) \
4965796c8dcSSimon Schubert . bfd_put_8 (abfd, val, ptr)
4975796c8dcSSimon Schubert .#define bfd_h_put_signed_8(abfd, val, ptr) \
4985796c8dcSSimon Schubert . bfd_put_8 (abfd, val, ptr)
4995796c8dcSSimon Schubert .#define bfd_h_get_8(abfd, ptr) \
5005796c8dcSSimon Schubert . bfd_get_8 (abfd, ptr)
5015796c8dcSSimon Schubert .#define bfd_h_get_signed_8(abfd, ptr) \
5025796c8dcSSimon Schubert . bfd_get_signed_8 (abfd, ptr)
5035796c8dcSSimon Schubert .
5045796c8dcSSimon Schubert .#define bfd_h_put_16(abfd, val, ptr) \
5055796c8dcSSimon Schubert . BFD_SEND (abfd, bfd_h_putx16, (val, ptr))
5065796c8dcSSimon Schubert .#define bfd_h_put_signed_16 \
5075796c8dcSSimon Schubert . bfd_h_put_16
5085796c8dcSSimon Schubert .#define bfd_h_get_16(abfd, ptr) \
5095796c8dcSSimon Schubert . BFD_SEND (abfd, bfd_h_getx16, (ptr))
5105796c8dcSSimon Schubert .#define bfd_h_get_signed_16(abfd, ptr) \
5115796c8dcSSimon Schubert . BFD_SEND (abfd, bfd_h_getx_signed_16, (ptr))
5125796c8dcSSimon Schubert .
5135796c8dcSSimon Schubert .#define bfd_h_put_32(abfd, val, ptr) \
5145796c8dcSSimon Schubert . BFD_SEND (abfd, bfd_h_putx32, (val, ptr))
5155796c8dcSSimon Schubert .#define bfd_h_put_signed_32 \
5165796c8dcSSimon Schubert . bfd_h_put_32
5175796c8dcSSimon Schubert .#define bfd_h_get_32(abfd, ptr) \
5185796c8dcSSimon Schubert . BFD_SEND (abfd, bfd_h_getx32, (ptr))
5195796c8dcSSimon Schubert .#define bfd_h_get_signed_32(abfd, ptr) \
5205796c8dcSSimon Schubert . BFD_SEND (abfd, bfd_h_getx_signed_32, (ptr))
5215796c8dcSSimon Schubert .
5225796c8dcSSimon Schubert .#define bfd_h_put_64(abfd, val, ptr) \
5235796c8dcSSimon Schubert . BFD_SEND (abfd, bfd_h_putx64, (val, ptr))
5245796c8dcSSimon Schubert .#define bfd_h_put_signed_64 \
5255796c8dcSSimon Schubert . bfd_h_put_64
5265796c8dcSSimon Schubert .#define bfd_h_get_64(abfd, ptr) \
5275796c8dcSSimon Schubert . BFD_SEND (abfd, bfd_h_getx64, (ptr))
5285796c8dcSSimon Schubert .#define bfd_h_get_signed_64(abfd, ptr) \
5295796c8dcSSimon Schubert . BFD_SEND (abfd, bfd_h_getx_signed_64, (ptr))
5305796c8dcSSimon Schubert .
5315796c8dcSSimon Schubert .{* Aliases for the above, which should eventually go away. *}
5325796c8dcSSimon Schubert .
5335796c8dcSSimon Schubert .#define H_PUT_64 bfd_h_put_64
5345796c8dcSSimon Schubert .#define H_PUT_32 bfd_h_put_32
5355796c8dcSSimon Schubert .#define H_PUT_16 bfd_h_put_16
5365796c8dcSSimon Schubert .#define H_PUT_8 bfd_h_put_8
5375796c8dcSSimon Schubert .#define H_PUT_S64 bfd_h_put_signed_64
5385796c8dcSSimon Schubert .#define H_PUT_S32 bfd_h_put_signed_32
5395796c8dcSSimon Schubert .#define H_PUT_S16 bfd_h_put_signed_16
5405796c8dcSSimon Schubert .#define H_PUT_S8 bfd_h_put_signed_8
5415796c8dcSSimon Schubert .#define H_GET_64 bfd_h_get_64
5425796c8dcSSimon Schubert .#define H_GET_32 bfd_h_get_32
5435796c8dcSSimon Schubert .#define H_GET_16 bfd_h_get_16
5445796c8dcSSimon Schubert .#define H_GET_8 bfd_h_get_8
5455796c8dcSSimon Schubert .#define H_GET_S64 bfd_h_get_signed_64
5465796c8dcSSimon Schubert .#define H_GET_S32 bfd_h_get_signed_32
5475796c8dcSSimon Schubert .#define H_GET_S16 bfd_h_get_signed_16
5485796c8dcSSimon Schubert .#define H_GET_S8 bfd_h_get_signed_8
5495796c8dcSSimon Schubert .
5505796c8dcSSimon Schubert .*/
5515796c8dcSSimon Schubert
5525796c8dcSSimon Schubert /* Sign extension to bfd_signed_vma. */
5535796c8dcSSimon Schubert #define COERCE16(x) (((bfd_signed_vma) (x) ^ 0x8000) - 0x8000)
5545796c8dcSSimon Schubert #define COERCE32(x) (((bfd_signed_vma) (x) ^ 0x80000000) - 0x80000000)
5555796c8dcSSimon Schubert #define EIGHT_GAZILLION ((bfd_int64_t) 1 << 63)
5565796c8dcSSimon Schubert #define COERCE64(x) \
5575796c8dcSSimon Schubert (((bfd_int64_t) (x) ^ EIGHT_GAZILLION) - EIGHT_GAZILLION)
5585796c8dcSSimon Schubert
5595796c8dcSSimon Schubert bfd_vma
bfd_getb16(const void * p)5605796c8dcSSimon Schubert bfd_getb16 (const void *p)
5615796c8dcSSimon Schubert {
5625796c8dcSSimon Schubert const bfd_byte *addr = (const bfd_byte *) p;
5635796c8dcSSimon Schubert return (addr[0] << 8) | addr[1];
5645796c8dcSSimon Schubert }
5655796c8dcSSimon Schubert
5665796c8dcSSimon Schubert bfd_vma
bfd_getl16(const void * p)5675796c8dcSSimon Schubert bfd_getl16 (const void *p)
5685796c8dcSSimon Schubert {
5695796c8dcSSimon Schubert const bfd_byte *addr = (const bfd_byte *) p;
5705796c8dcSSimon Schubert return (addr[1] << 8) | addr[0];
5715796c8dcSSimon Schubert }
5725796c8dcSSimon Schubert
5735796c8dcSSimon Schubert bfd_signed_vma
bfd_getb_signed_16(const void * p)5745796c8dcSSimon Schubert bfd_getb_signed_16 (const void *p)
5755796c8dcSSimon Schubert {
5765796c8dcSSimon Schubert const bfd_byte *addr = (const bfd_byte *) p;
5775796c8dcSSimon Schubert return COERCE16 ((addr[0] << 8) | addr[1]);
5785796c8dcSSimon Schubert }
5795796c8dcSSimon Schubert
5805796c8dcSSimon Schubert bfd_signed_vma
bfd_getl_signed_16(const void * p)5815796c8dcSSimon Schubert bfd_getl_signed_16 (const void *p)
5825796c8dcSSimon Schubert {
5835796c8dcSSimon Schubert const bfd_byte *addr = (const bfd_byte *) p;
5845796c8dcSSimon Schubert return COERCE16 ((addr[1] << 8) | addr[0]);
5855796c8dcSSimon Schubert }
5865796c8dcSSimon Schubert
5875796c8dcSSimon Schubert void
bfd_putb16(bfd_vma data,void * p)5885796c8dcSSimon Schubert bfd_putb16 (bfd_vma data, void *p)
5895796c8dcSSimon Schubert {
5905796c8dcSSimon Schubert bfd_byte *addr = (bfd_byte *) p;
5915796c8dcSSimon Schubert addr[0] = (data >> 8) & 0xff;
5925796c8dcSSimon Schubert addr[1] = data & 0xff;
5935796c8dcSSimon Schubert }
5945796c8dcSSimon Schubert
5955796c8dcSSimon Schubert void
bfd_putl16(bfd_vma data,void * p)5965796c8dcSSimon Schubert bfd_putl16 (bfd_vma data, void *p)
5975796c8dcSSimon Schubert {
5985796c8dcSSimon Schubert bfd_byte *addr = (bfd_byte *) p;
5995796c8dcSSimon Schubert addr[0] = data & 0xff;
6005796c8dcSSimon Schubert addr[1] = (data >> 8) & 0xff;
6015796c8dcSSimon Schubert }
6025796c8dcSSimon Schubert
6035796c8dcSSimon Schubert bfd_vma
bfd_getb32(const void * p)6045796c8dcSSimon Schubert bfd_getb32 (const void *p)
6055796c8dcSSimon Schubert {
6065796c8dcSSimon Schubert const bfd_byte *addr = (const bfd_byte *) p;
6075796c8dcSSimon Schubert unsigned long v;
6085796c8dcSSimon Schubert
6095796c8dcSSimon Schubert v = (unsigned long) addr[0] << 24;
6105796c8dcSSimon Schubert v |= (unsigned long) addr[1] << 16;
6115796c8dcSSimon Schubert v |= (unsigned long) addr[2] << 8;
6125796c8dcSSimon Schubert v |= (unsigned long) addr[3];
6135796c8dcSSimon Schubert return v;
6145796c8dcSSimon Schubert }
6155796c8dcSSimon Schubert
6165796c8dcSSimon Schubert bfd_vma
bfd_getl32(const void * p)6175796c8dcSSimon Schubert bfd_getl32 (const void *p)
6185796c8dcSSimon Schubert {
6195796c8dcSSimon Schubert const bfd_byte *addr = (const bfd_byte *) p;
6205796c8dcSSimon Schubert unsigned long v;
6215796c8dcSSimon Schubert
6225796c8dcSSimon Schubert v = (unsigned long) addr[0];
6235796c8dcSSimon Schubert v |= (unsigned long) addr[1] << 8;
6245796c8dcSSimon Schubert v |= (unsigned long) addr[2] << 16;
6255796c8dcSSimon Schubert v |= (unsigned long) addr[3] << 24;
6265796c8dcSSimon Schubert return v;
6275796c8dcSSimon Schubert }
6285796c8dcSSimon Schubert
6295796c8dcSSimon Schubert bfd_signed_vma
bfd_getb_signed_32(const void * p)6305796c8dcSSimon Schubert bfd_getb_signed_32 (const void *p)
6315796c8dcSSimon Schubert {
6325796c8dcSSimon Schubert const bfd_byte *addr = (const bfd_byte *) p;
6335796c8dcSSimon Schubert unsigned long v;
6345796c8dcSSimon Schubert
6355796c8dcSSimon Schubert v = (unsigned long) addr[0] << 24;
6365796c8dcSSimon Schubert v |= (unsigned long) addr[1] << 16;
6375796c8dcSSimon Schubert v |= (unsigned long) addr[2] << 8;
6385796c8dcSSimon Schubert v |= (unsigned long) addr[3];
6395796c8dcSSimon Schubert return COERCE32 (v);
6405796c8dcSSimon Schubert }
6415796c8dcSSimon Schubert
6425796c8dcSSimon Schubert bfd_signed_vma
bfd_getl_signed_32(const void * p)6435796c8dcSSimon Schubert bfd_getl_signed_32 (const void *p)
6445796c8dcSSimon Schubert {
6455796c8dcSSimon Schubert const bfd_byte *addr = (const bfd_byte *) p;
6465796c8dcSSimon Schubert unsigned long v;
6475796c8dcSSimon Schubert
6485796c8dcSSimon Schubert v = (unsigned long) addr[0];
6495796c8dcSSimon Schubert v |= (unsigned long) addr[1] << 8;
6505796c8dcSSimon Schubert v |= (unsigned long) addr[2] << 16;
6515796c8dcSSimon Schubert v |= (unsigned long) addr[3] << 24;
6525796c8dcSSimon Schubert return COERCE32 (v);
6535796c8dcSSimon Schubert }
6545796c8dcSSimon Schubert
6555796c8dcSSimon Schubert bfd_uint64_t
bfd_getb64(const void * p ATTRIBUTE_UNUSED)6565796c8dcSSimon Schubert bfd_getb64 (const void *p ATTRIBUTE_UNUSED)
6575796c8dcSSimon Schubert {
6585796c8dcSSimon Schubert #ifdef BFD_HOST_64_BIT
6595796c8dcSSimon Schubert const bfd_byte *addr = (const bfd_byte *) p;
6605796c8dcSSimon Schubert bfd_uint64_t v;
6615796c8dcSSimon Schubert
6625796c8dcSSimon Schubert v = addr[0]; v <<= 8;
6635796c8dcSSimon Schubert v |= addr[1]; v <<= 8;
6645796c8dcSSimon Schubert v |= addr[2]; v <<= 8;
6655796c8dcSSimon Schubert v |= addr[3]; v <<= 8;
6665796c8dcSSimon Schubert v |= addr[4]; v <<= 8;
6675796c8dcSSimon Schubert v |= addr[5]; v <<= 8;
6685796c8dcSSimon Schubert v |= addr[6]; v <<= 8;
6695796c8dcSSimon Schubert v |= addr[7];
6705796c8dcSSimon Schubert
6715796c8dcSSimon Schubert return v;
6725796c8dcSSimon Schubert #else
6735796c8dcSSimon Schubert BFD_FAIL();
6745796c8dcSSimon Schubert return 0;
6755796c8dcSSimon Schubert #endif
6765796c8dcSSimon Schubert }
6775796c8dcSSimon Schubert
6785796c8dcSSimon Schubert bfd_uint64_t
bfd_getl64(const void * p ATTRIBUTE_UNUSED)6795796c8dcSSimon Schubert bfd_getl64 (const void *p ATTRIBUTE_UNUSED)
6805796c8dcSSimon Schubert {
6815796c8dcSSimon Schubert #ifdef BFD_HOST_64_BIT
6825796c8dcSSimon Schubert const bfd_byte *addr = (const bfd_byte *) p;
6835796c8dcSSimon Schubert bfd_uint64_t v;
6845796c8dcSSimon Schubert
6855796c8dcSSimon Schubert v = addr[7]; v <<= 8;
6865796c8dcSSimon Schubert v |= addr[6]; v <<= 8;
6875796c8dcSSimon Schubert v |= addr[5]; v <<= 8;
6885796c8dcSSimon Schubert v |= addr[4]; v <<= 8;
6895796c8dcSSimon Schubert v |= addr[3]; v <<= 8;
6905796c8dcSSimon Schubert v |= addr[2]; v <<= 8;
6915796c8dcSSimon Schubert v |= addr[1]; v <<= 8;
6925796c8dcSSimon Schubert v |= addr[0];
6935796c8dcSSimon Schubert
6945796c8dcSSimon Schubert return v;
6955796c8dcSSimon Schubert #else
6965796c8dcSSimon Schubert BFD_FAIL();
6975796c8dcSSimon Schubert return 0;
6985796c8dcSSimon Schubert #endif
6995796c8dcSSimon Schubert
7005796c8dcSSimon Schubert }
7015796c8dcSSimon Schubert
7025796c8dcSSimon Schubert bfd_int64_t
bfd_getb_signed_64(const void * p ATTRIBUTE_UNUSED)7035796c8dcSSimon Schubert bfd_getb_signed_64 (const void *p ATTRIBUTE_UNUSED)
7045796c8dcSSimon Schubert {
7055796c8dcSSimon Schubert #ifdef BFD_HOST_64_BIT
7065796c8dcSSimon Schubert const bfd_byte *addr = (const bfd_byte *) p;
7075796c8dcSSimon Schubert bfd_uint64_t v;
7085796c8dcSSimon Schubert
7095796c8dcSSimon Schubert v = addr[0]; v <<= 8;
7105796c8dcSSimon Schubert v |= addr[1]; v <<= 8;
7115796c8dcSSimon Schubert v |= addr[2]; v <<= 8;
7125796c8dcSSimon Schubert v |= addr[3]; v <<= 8;
7135796c8dcSSimon Schubert v |= addr[4]; v <<= 8;
7145796c8dcSSimon Schubert v |= addr[5]; v <<= 8;
7155796c8dcSSimon Schubert v |= addr[6]; v <<= 8;
7165796c8dcSSimon Schubert v |= addr[7];
7175796c8dcSSimon Schubert
7185796c8dcSSimon Schubert return COERCE64 (v);
7195796c8dcSSimon Schubert #else
7205796c8dcSSimon Schubert BFD_FAIL();
7215796c8dcSSimon Schubert return 0;
7225796c8dcSSimon Schubert #endif
7235796c8dcSSimon Schubert }
7245796c8dcSSimon Schubert
7255796c8dcSSimon Schubert bfd_int64_t
bfd_getl_signed_64(const void * p ATTRIBUTE_UNUSED)7265796c8dcSSimon Schubert bfd_getl_signed_64 (const void *p ATTRIBUTE_UNUSED)
7275796c8dcSSimon Schubert {
7285796c8dcSSimon Schubert #ifdef BFD_HOST_64_BIT
7295796c8dcSSimon Schubert const bfd_byte *addr = (const bfd_byte *) p;
7305796c8dcSSimon Schubert bfd_uint64_t v;
7315796c8dcSSimon Schubert
7325796c8dcSSimon Schubert v = addr[7]; v <<= 8;
7335796c8dcSSimon Schubert v |= addr[6]; v <<= 8;
7345796c8dcSSimon Schubert v |= addr[5]; v <<= 8;
7355796c8dcSSimon Schubert v |= addr[4]; v <<= 8;
7365796c8dcSSimon Schubert v |= addr[3]; v <<= 8;
7375796c8dcSSimon Schubert v |= addr[2]; v <<= 8;
7385796c8dcSSimon Schubert v |= addr[1]; v <<= 8;
7395796c8dcSSimon Schubert v |= addr[0];
7405796c8dcSSimon Schubert
7415796c8dcSSimon Schubert return COERCE64 (v);
7425796c8dcSSimon Schubert #else
7435796c8dcSSimon Schubert BFD_FAIL();
7445796c8dcSSimon Schubert return 0;
7455796c8dcSSimon Schubert #endif
7465796c8dcSSimon Schubert }
7475796c8dcSSimon Schubert
7485796c8dcSSimon Schubert void
bfd_putb32(bfd_vma data,void * p)7495796c8dcSSimon Schubert bfd_putb32 (bfd_vma data, void *p)
7505796c8dcSSimon Schubert {
7515796c8dcSSimon Schubert bfd_byte *addr = (bfd_byte *) p;
7525796c8dcSSimon Schubert addr[0] = (data >> 24) & 0xff;
7535796c8dcSSimon Schubert addr[1] = (data >> 16) & 0xff;
7545796c8dcSSimon Schubert addr[2] = (data >> 8) & 0xff;
7555796c8dcSSimon Schubert addr[3] = data & 0xff;
7565796c8dcSSimon Schubert }
7575796c8dcSSimon Schubert
7585796c8dcSSimon Schubert void
bfd_putl32(bfd_vma data,void * p)7595796c8dcSSimon Schubert bfd_putl32 (bfd_vma data, void *p)
7605796c8dcSSimon Schubert {
7615796c8dcSSimon Schubert bfd_byte *addr = (bfd_byte *) p;
7625796c8dcSSimon Schubert addr[0] = data & 0xff;
7635796c8dcSSimon Schubert addr[1] = (data >> 8) & 0xff;
7645796c8dcSSimon Schubert addr[2] = (data >> 16) & 0xff;
7655796c8dcSSimon Schubert addr[3] = (data >> 24) & 0xff;
7665796c8dcSSimon Schubert }
7675796c8dcSSimon Schubert
7685796c8dcSSimon Schubert void
bfd_putb64(bfd_uint64_t data ATTRIBUTE_UNUSED,void * p ATTRIBUTE_UNUSED)7695796c8dcSSimon Schubert bfd_putb64 (bfd_uint64_t data ATTRIBUTE_UNUSED, void *p ATTRIBUTE_UNUSED)
7705796c8dcSSimon Schubert {
7715796c8dcSSimon Schubert #ifdef BFD_HOST_64_BIT
7725796c8dcSSimon Schubert bfd_byte *addr = (bfd_byte *) p;
7735796c8dcSSimon Schubert addr[0] = (data >> (7*8)) & 0xff;
7745796c8dcSSimon Schubert addr[1] = (data >> (6*8)) & 0xff;
7755796c8dcSSimon Schubert addr[2] = (data >> (5*8)) & 0xff;
7765796c8dcSSimon Schubert addr[3] = (data >> (4*8)) & 0xff;
7775796c8dcSSimon Schubert addr[4] = (data >> (3*8)) & 0xff;
7785796c8dcSSimon Schubert addr[5] = (data >> (2*8)) & 0xff;
7795796c8dcSSimon Schubert addr[6] = (data >> (1*8)) & 0xff;
7805796c8dcSSimon Schubert addr[7] = (data >> (0*8)) & 0xff;
7815796c8dcSSimon Schubert #else
7825796c8dcSSimon Schubert BFD_FAIL();
7835796c8dcSSimon Schubert #endif
7845796c8dcSSimon Schubert }
7855796c8dcSSimon Schubert
7865796c8dcSSimon Schubert void
bfd_putl64(bfd_uint64_t data ATTRIBUTE_UNUSED,void * p ATTRIBUTE_UNUSED)7875796c8dcSSimon Schubert bfd_putl64 (bfd_uint64_t data ATTRIBUTE_UNUSED, void *p ATTRIBUTE_UNUSED)
7885796c8dcSSimon Schubert {
7895796c8dcSSimon Schubert #ifdef BFD_HOST_64_BIT
7905796c8dcSSimon Schubert bfd_byte *addr = (bfd_byte *) p;
7915796c8dcSSimon Schubert addr[7] = (data >> (7*8)) & 0xff;
7925796c8dcSSimon Schubert addr[6] = (data >> (6*8)) & 0xff;
7935796c8dcSSimon Schubert addr[5] = (data >> (5*8)) & 0xff;
7945796c8dcSSimon Schubert addr[4] = (data >> (4*8)) & 0xff;
7955796c8dcSSimon Schubert addr[3] = (data >> (3*8)) & 0xff;
7965796c8dcSSimon Schubert addr[2] = (data >> (2*8)) & 0xff;
7975796c8dcSSimon Schubert addr[1] = (data >> (1*8)) & 0xff;
7985796c8dcSSimon Schubert addr[0] = (data >> (0*8)) & 0xff;
7995796c8dcSSimon Schubert #else
8005796c8dcSSimon Schubert BFD_FAIL();
8015796c8dcSSimon Schubert #endif
8025796c8dcSSimon Schubert }
8035796c8dcSSimon Schubert
8045796c8dcSSimon Schubert void
bfd_put_bits(bfd_uint64_t data,void * p,int bits,bfd_boolean big_p)8055796c8dcSSimon Schubert bfd_put_bits (bfd_uint64_t data, void *p, int bits, bfd_boolean big_p)
8065796c8dcSSimon Schubert {
8075796c8dcSSimon Schubert bfd_byte *addr = (bfd_byte *) p;
8085796c8dcSSimon Schubert int i;
8095796c8dcSSimon Schubert int bytes;
8105796c8dcSSimon Schubert
8115796c8dcSSimon Schubert if (bits % 8 != 0)
8125796c8dcSSimon Schubert abort ();
8135796c8dcSSimon Schubert
8145796c8dcSSimon Schubert bytes = bits / 8;
8155796c8dcSSimon Schubert for (i = 0; i < bytes; i++)
8165796c8dcSSimon Schubert {
817cf7f2e2dSJohn Marino int addr_index = big_p ? bytes - i - 1 : i;
8185796c8dcSSimon Schubert
819cf7f2e2dSJohn Marino addr[addr_index] = data & 0xff;
8205796c8dcSSimon Schubert data >>= 8;
8215796c8dcSSimon Schubert }
8225796c8dcSSimon Schubert }
8235796c8dcSSimon Schubert
8245796c8dcSSimon Schubert bfd_uint64_t
bfd_get_bits(const void * p,int bits,bfd_boolean big_p)8255796c8dcSSimon Schubert bfd_get_bits (const void *p, int bits, bfd_boolean big_p)
8265796c8dcSSimon Schubert {
8275796c8dcSSimon Schubert const bfd_byte *addr = (const bfd_byte *) p;
8285796c8dcSSimon Schubert bfd_uint64_t data;
8295796c8dcSSimon Schubert int i;
8305796c8dcSSimon Schubert int bytes;
8315796c8dcSSimon Schubert
8325796c8dcSSimon Schubert if (bits % 8 != 0)
8335796c8dcSSimon Schubert abort ();
8345796c8dcSSimon Schubert
8355796c8dcSSimon Schubert data = 0;
8365796c8dcSSimon Schubert bytes = bits / 8;
8375796c8dcSSimon Schubert for (i = 0; i < bytes; i++)
8385796c8dcSSimon Schubert {
839cf7f2e2dSJohn Marino int addr_index = big_p ? i : bytes - i - 1;
8405796c8dcSSimon Schubert
841cf7f2e2dSJohn Marino data = (data << 8) | addr[addr_index];
8425796c8dcSSimon Schubert }
8435796c8dcSSimon Schubert
8445796c8dcSSimon Schubert return data;
8455796c8dcSSimon Schubert }
8465796c8dcSSimon Schubert
8475796c8dcSSimon Schubert /* Default implementation */
8485796c8dcSSimon Schubert
8495796c8dcSSimon Schubert bfd_boolean
_bfd_generic_get_section_contents(bfd * abfd,sec_ptr section,void * location,file_ptr offset,bfd_size_type count)8505796c8dcSSimon Schubert _bfd_generic_get_section_contents (bfd *abfd,
8515796c8dcSSimon Schubert sec_ptr section,
8525796c8dcSSimon Schubert void *location,
8535796c8dcSSimon Schubert file_ptr offset,
8545796c8dcSSimon Schubert bfd_size_type count)
8555796c8dcSSimon Schubert {
8565796c8dcSSimon Schubert bfd_size_type sz;
8575796c8dcSSimon Schubert if (count == 0)
8585796c8dcSSimon Schubert return TRUE;
8595796c8dcSSimon Schubert
860c50c785cSJohn Marino if (section->compress_status != COMPRESS_SECTION_NONE)
861c50c785cSJohn Marino {
862c50c785cSJohn Marino (*_bfd_error_handler)
863c50c785cSJohn Marino (_("%B: unable to get decompressed section %A"),
864c50c785cSJohn Marino abfd, section);
865c50c785cSJohn Marino bfd_set_error (bfd_error_invalid_operation);
866c50c785cSJohn Marino return FALSE;
867c50c785cSJohn Marino }
868c50c785cSJohn Marino
869a45ae5f8SJohn Marino /* We do allow reading of a section after bfd_final_link has
870a45ae5f8SJohn Marino written the contents out to disk. In that situation, rawsize is
871a45ae5f8SJohn Marino just a stale version of size, so ignore it. Otherwise we must be
872a45ae5f8SJohn Marino reading an input section, where rawsize, if different to size,
873a45ae5f8SJohn Marino is the on-disk size. */
874a45ae5f8SJohn Marino if (abfd->direction != write_direction && section->rawsize != 0)
875a45ae5f8SJohn Marino sz = section->rawsize;
876a45ae5f8SJohn Marino else
877a45ae5f8SJohn Marino sz = section->size;
8785796c8dcSSimon Schubert if (offset + count < count
8795796c8dcSSimon Schubert || offset + count > sz)
8805796c8dcSSimon Schubert {
8815796c8dcSSimon Schubert bfd_set_error (bfd_error_invalid_operation);
8825796c8dcSSimon Schubert return FALSE;
8835796c8dcSSimon Schubert }
8845796c8dcSSimon Schubert
8855796c8dcSSimon Schubert if (bfd_seek (abfd, section->filepos + offset, SEEK_SET) != 0
8865796c8dcSSimon Schubert || bfd_bread (location, count, abfd) != count)
8875796c8dcSSimon Schubert return FALSE;
8885796c8dcSSimon Schubert
8895796c8dcSSimon Schubert return TRUE;
8905796c8dcSSimon Schubert }
8915796c8dcSSimon Schubert
8925796c8dcSSimon Schubert bfd_boolean
_bfd_generic_get_section_contents_in_window(bfd * abfd ATTRIBUTE_UNUSED,sec_ptr section ATTRIBUTE_UNUSED,bfd_window * w ATTRIBUTE_UNUSED,file_ptr offset ATTRIBUTE_UNUSED,bfd_size_type count ATTRIBUTE_UNUSED)8935796c8dcSSimon Schubert _bfd_generic_get_section_contents_in_window
8945796c8dcSSimon Schubert (bfd *abfd ATTRIBUTE_UNUSED,
8955796c8dcSSimon Schubert sec_ptr section ATTRIBUTE_UNUSED,
8965796c8dcSSimon Schubert bfd_window *w ATTRIBUTE_UNUSED,
8975796c8dcSSimon Schubert file_ptr offset ATTRIBUTE_UNUSED,
8985796c8dcSSimon Schubert bfd_size_type count ATTRIBUTE_UNUSED)
8995796c8dcSSimon Schubert {
9005796c8dcSSimon Schubert #ifdef USE_MMAP
9015796c8dcSSimon Schubert bfd_size_type sz;
9025796c8dcSSimon Schubert
9035796c8dcSSimon Schubert if (count == 0)
9045796c8dcSSimon Schubert return TRUE;
9055796c8dcSSimon Schubert if (abfd->xvec->_bfd_get_section_contents
9065796c8dcSSimon Schubert != _bfd_generic_get_section_contents)
9075796c8dcSSimon Schubert {
9085796c8dcSSimon Schubert /* We don't know what changes the bfd's get_section_contents
9095796c8dcSSimon Schubert method may have to make. So punt trying to map the file
9105796c8dcSSimon Schubert window, and let get_section_contents do its thing. */
9115796c8dcSSimon Schubert /* @@ FIXME : If the internal window has a refcount of 1 and was
9125796c8dcSSimon Schubert allocated with malloc instead of mmap, just reuse it. */
9135796c8dcSSimon Schubert bfd_free_window (w);
9145796c8dcSSimon Schubert w->i = bfd_zmalloc (sizeof (bfd_window_internal));
9155796c8dcSSimon Schubert if (w->i == NULL)
9165796c8dcSSimon Schubert return FALSE;
9175796c8dcSSimon Schubert w->i->data = bfd_malloc (count);
9185796c8dcSSimon Schubert if (w->i->data == NULL)
9195796c8dcSSimon Schubert {
9205796c8dcSSimon Schubert free (w->i);
9215796c8dcSSimon Schubert w->i = NULL;
9225796c8dcSSimon Schubert return FALSE;
9235796c8dcSSimon Schubert }
9245796c8dcSSimon Schubert w->i->mapped = 0;
9255796c8dcSSimon Schubert w->i->refcount = 1;
9265796c8dcSSimon Schubert w->size = w->i->size = count;
9275796c8dcSSimon Schubert w->data = w->i->data;
9285796c8dcSSimon Schubert return bfd_get_section_contents (abfd, section, w->data, offset, count);
9295796c8dcSSimon Schubert }
930a45ae5f8SJohn Marino if (abfd->direction != write_direction && section->rawsize != 0)
931a45ae5f8SJohn Marino sz = section->rawsize;
932a45ae5f8SJohn Marino else
933a45ae5f8SJohn Marino sz = section->size;
9345796c8dcSSimon Schubert if (offset + count > sz
9355796c8dcSSimon Schubert || ! bfd_get_file_window (abfd, section->filepos + offset, count, w,
9365796c8dcSSimon Schubert TRUE))
9375796c8dcSSimon Schubert return FALSE;
9385796c8dcSSimon Schubert return TRUE;
9395796c8dcSSimon Schubert #else
9405796c8dcSSimon Schubert abort ();
9415796c8dcSSimon Schubert #endif
9425796c8dcSSimon Schubert }
9435796c8dcSSimon Schubert
9445796c8dcSSimon Schubert /* This generic function can only be used in implementations where creating
9455796c8dcSSimon Schubert NEW sections is disallowed. It is useful in patching existing sections
9465796c8dcSSimon Schubert in read-write files, though. See other set_section_contents functions
9475796c8dcSSimon Schubert to see why it doesn't work for new sections. */
9485796c8dcSSimon Schubert bfd_boolean
_bfd_generic_set_section_contents(bfd * abfd,sec_ptr section,const void * location,file_ptr offset,bfd_size_type count)9495796c8dcSSimon Schubert _bfd_generic_set_section_contents (bfd *abfd,
9505796c8dcSSimon Schubert sec_ptr section,
9515796c8dcSSimon Schubert const void *location,
9525796c8dcSSimon Schubert file_ptr offset,
9535796c8dcSSimon Schubert bfd_size_type count)
9545796c8dcSSimon Schubert {
9555796c8dcSSimon Schubert if (count == 0)
9565796c8dcSSimon Schubert return TRUE;
9575796c8dcSSimon Schubert
9585796c8dcSSimon Schubert if (bfd_seek (abfd, section->filepos + offset, SEEK_SET) != 0
9595796c8dcSSimon Schubert || bfd_bwrite (location, count, abfd) != count)
9605796c8dcSSimon Schubert return FALSE;
9615796c8dcSSimon Schubert
9625796c8dcSSimon Schubert return TRUE;
9635796c8dcSSimon Schubert }
9645796c8dcSSimon Schubert
9655796c8dcSSimon Schubert /*
9665796c8dcSSimon Schubert INTERNAL_FUNCTION
9675796c8dcSSimon Schubert bfd_log2
9685796c8dcSSimon Schubert
9695796c8dcSSimon Schubert SYNOPSIS
9705796c8dcSSimon Schubert unsigned int bfd_log2 (bfd_vma x);
9715796c8dcSSimon Schubert
9725796c8dcSSimon Schubert DESCRIPTION
9735796c8dcSSimon Schubert Return the log base 2 of the value supplied, rounded up. E.g., an
9745796c8dcSSimon Schubert @var{x} of 1025 returns 11. A @var{x} of 0 returns 0.
9755796c8dcSSimon Schubert */
9765796c8dcSSimon Schubert
9775796c8dcSSimon Schubert unsigned int
bfd_log2(bfd_vma x)9785796c8dcSSimon Schubert bfd_log2 (bfd_vma x)
9795796c8dcSSimon Schubert {
9805796c8dcSSimon Schubert unsigned int result = 0;
9815796c8dcSSimon Schubert
982a45ae5f8SJohn Marino if (x <= 1)
983a45ae5f8SJohn Marino return result;
984a45ae5f8SJohn Marino --x;
985a45ae5f8SJohn Marino do
9865796c8dcSSimon Schubert ++result;
987a45ae5f8SJohn Marino while ((x >>= 1) != 0);
9885796c8dcSSimon Schubert return result;
9895796c8dcSSimon Schubert }
9905796c8dcSSimon Schubert
9915796c8dcSSimon Schubert bfd_boolean
bfd_generic_is_local_label_name(bfd * abfd,const char * name)9925796c8dcSSimon Schubert bfd_generic_is_local_label_name (bfd *abfd, const char *name)
9935796c8dcSSimon Schubert {
9945796c8dcSSimon Schubert char locals_prefix = (bfd_get_symbol_leading_char (abfd) == '_') ? 'L' : '.';
9955796c8dcSSimon Schubert
9965796c8dcSSimon Schubert return name[0] == locals_prefix;
9975796c8dcSSimon Schubert }
9985796c8dcSSimon Schubert
9995796c8dcSSimon Schubert /* Can be used from / for bfd_merge_private_bfd_data to check that
10005796c8dcSSimon Schubert endianness matches between input and output file. Returns
10015796c8dcSSimon Schubert TRUE for a match, otherwise returns FALSE and emits an error. */
10025796c8dcSSimon Schubert bfd_boolean
_bfd_generic_verify_endian_match(bfd * ibfd,bfd * obfd)10035796c8dcSSimon Schubert _bfd_generic_verify_endian_match (bfd *ibfd, bfd *obfd)
10045796c8dcSSimon Schubert {
10055796c8dcSSimon Schubert if (ibfd->xvec->byteorder != obfd->xvec->byteorder
10065796c8dcSSimon Schubert && ibfd->xvec->byteorder != BFD_ENDIAN_UNKNOWN
10075796c8dcSSimon Schubert && obfd->xvec->byteorder != BFD_ENDIAN_UNKNOWN)
10085796c8dcSSimon Schubert {
10095796c8dcSSimon Schubert const char *msg;
10105796c8dcSSimon Schubert
10115796c8dcSSimon Schubert if (bfd_big_endian (ibfd))
10125796c8dcSSimon Schubert msg = _("%B: compiled for a big endian system and target is little endian");
10135796c8dcSSimon Schubert else
10145796c8dcSSimon Schubert msg = _("%B: compiled for a little endian system and target is big endian");
10155796c8dcSSimon Schubert
10165796c8dcSSimon Schubert (*_bfd_error_handler) (msg, ibfd);
10175796c8dcSSimon Schubert
10185796c8dcSSimon Schubert bfd_set_error (bfd_error_wrong_format);
10195796c8dcSSimon Schubert return FALSE;
10205796c8dcSSimon Schubert }
10215796c8dcSSimon Schubert
10225796c8dcSSimon Schubert return TRUE;
10235796c8dcSSimon Schubert }
10245796c8dcSSimon Schubert
10255796c8dcSSimon Schubert /* Give a warning at runtime if someone compiles code which calls
10265796c8dcSSimon Schubert old routines. */
10275796c8dcSSimon Schubert
10285796c8dcSSimon Schubert void
warn_deprecated(const char * what,const char * file,int line,const char * func)10295796c8dcSSimon Schubert warn_deprecated (const char *what,
10305796c8dcSSimon Schubert const char *file,
10315796c8dcSSimon Schubert int line,
10325796c8dcSSimon Schubert const char *func)
10335796c8dcSSimon Schubert {
10345796c8dcSSimon Schubert /* Poor man's tracking of functions we've already warned about. */
10355796c8dcSSimon Schubert static size_t mask = 0;
10365796c8dcSSimon Schubert
10375796c8dcSSimon Schubert if (~(size_t) func & ~mask)
10385796c8dcSSimon Schubert {
1039c50c785cSJohn Marino fflush (stdout);
10405796c8dcSSimon Schubert /* Note: separate sentences in order to allow
10415796c8dcSSimon Schubert for translation into other languages. */
10425796c8dcSSimon Schubert if (func)
10435796c8dcSSimon Schubert fprintf (stderr, _("Deprecated %s called at %s line %d in %s\n"),
10445796c8dcSSimon Schubert what, file, line, func);
10455796c8dcSSimon Schubert else
10465796c8dcSSimon Schubert fprintf (stderr, _("Deprecated %s called\n"), what);
1047c50c785cSJohn Marino fflush (stderr);
10485796c8dcSSimon Schubert mask |= ~(size_t) func;
10495796c8dcSSimon Schubert }
10505796c8dcSSimon Schubert }
10515796c8dcSSimon Schubert
10525796c8dcSSimon Schubert /* Helper function for reading uleb128 encoded data. */
10535796c8dcSSimon Schubert
10545796c8dcSSimon Schubert bfd_vma
read_unsigned_leb128(bfd * abfd ATTRIBUTE_UNUSED,bfd_byte * buf,unsigned int * bytes_read_ptr)10555796c8dcSSimon Schubert read_unsigned_leb128 (bfd *abfd ATTRIBUTE_UNUSED,
10565796c8dcSSimon Schubert bfd_byte *buf,
10575796c8dcSSimon Schubert unsigned int *bytes_read_ptr)
10585796c8dcSSimon Schubert {
10595796c8dcSSimon Schubert bfd_vma result;
10605796c8dcSSimon Schubert unsigned int num_read;
10615796c8dcSSimon Schubert unsigned int shift;
10625796c8dcSSimon Schubert unsigned char byte;
10635796c8dcSSimon Schubert
10645796c8dcSSimon Schubert result = 0;
10655796c8dcSSimon Schubert shift = 0;
10665796c8dcSSimon Schubert num_read = 0;
10675796c8dcSSimon Schubert do
10685796c8dcSSimon Schubert {
10695796c8dcSSimon Schubert byte = bfd_get_8 (abfd, buf);
10705796c8dcSSimon Schubert buf++;
10715796c8dcSSimon Schubert num_read++;
10725796c8dcSSimon Schubert result |= (((bfd_vma) byte & 0x7f) << shift);
10735796c8dcSSimon Schubert shift += 7;
10745796c8dcSSimon Schubert }
10755796c8dcSSimon Schubert while (byte & 0x80);
10765796c8dcSSimon Schubert *bytes_read_ptr = num_read;
10775796c8dcSSimon Schubert return result;
10785796c8dcSSimon Schubert }
10795796c8dcSSimon Schubert
10805796c8dcSSimon Schubert /* Helper function for reading sleb128 encoded data. */
10815796c8dcSSimon Schubert
10825796c8dcSSimon Schubert bfd_signed_vma
read_signed_leb128(bfd * abfd ATTRIBUTE_UNUSED,bfd_byte * buf,unsigned int * bytes_read_ptr)10835796c8dcSSimon Schubert read_signed_leb128 (bfd *abfd ATTRIBUTE_UNUSED,
10845796c8dcSSimon Schubert bfd_byte *buf,
10855796c8dcSSimon Schubert unsigned int *bytes_read_ptr)
10865796c8dcSSimon Schubert {
10875796c8dcSSimon Schubert bfd_vma result;
10885796c8dcSSimon Schubert unsigned int shift;
10895796c8dcSSimon Schubert unsigned int num_read;
10905796c8dcSSimon Schubert unsigned char byte;
10915796c8dcSSimon Schubert
10925796c8dcSSimon Schubert result = 0;
10935796c8dcSSimon Schubert shift = 0;
10945796c8dcSSimon Schubert num_read = 0;
10955796c8dcSSimon Schubert do
10965796c8dcSSimon Schubert {
10975796c8dcSSimon Schubert byte = bfd_get_8 (abfd, buf);
10985796c8dcSSimon Schubert buf ++;
10995796c8dcSSimon Schubert num_read ++;
11005796c8dcSSimon Schubert result |= (((bfd_vma) byte & 0x7f) << shift);
11015796c8dcSSimon Schubert shift += 7;
11025796c8dcSSimon Schubert }
11035796c8dcSSimon Schubert while (byte & 0x80);
11045796c8dcSSimon Schubert if (shift < 8 * sizeof (result) && (byte & 0x40))
11055796c8dcSSimon Schubert result |= (((bfd_vma) -1) << shift);
11065796c8dcSSimon Schubert *bytes_read_ptr = num_read;
11075796c8dcSSimon Schubert return result;
11085796c8dcSSimon Schubert }
11095796c8dcSSimon Schubert
11105796c8dcSSimon Schubert bfd_boolean
_bfd_generic_find_line(bfd * abfd ATTRIBUTE_UNUSED,asymbol ** symbols ATTRIBUTE_UNUSED,asymbol * symbol ATTRIBUTE_UNUSED,const char ** filename_ptr ATTRIBUTE_UNUSED,unsigned int * linenumber_ptr ATTRIBUTE_UNUSED)11115796c8dcSSimon Schubert _bfd_generic_find_line (bfd *abfd ATTRIBUTE_UNUSED,
11125796c8dcSSimon Schubert asymbol **symbols ATTRIBUTE_UNUSED,
11135796c8dcSSimon Schubert asymbol *symbol ATTRIBUTE_UNUSED,
11145796c8dcSSimon Schubert const char **filename_ptr ATTRIBUTE_UNUSED,
11155796c8dcSSimon Schubert unsigned int *linenumber_ptr ATTRIBUTE_UNUSED)
11165796c8dcSSimon Schubert {
11175796c8dcSSimon Schubert return FALSE;
11185796c8dcSSimon Schubert }
11195796c8dcSSimon Schubert
11205796c8dcSSimon Schubert bfd_boolean
_bfd_generic_find_nearest_line_discriminator(bfd * abfd ATTRIBUTE_UNUSED,asection * section ATTRIBUTE_UNUSED,asymbol ** symbols ATTRIBUTE_UNUSED,bfd_vma offset ATTRIBUTE_UNUSED,const char ** filename_ptr ATTRIBUTE_UNUSED,const char ** functionname_ptr ATTRIBUTE_UNUSED,unsigned int * line_ptr ATTRIBUTE_UNUSED,unsigned int * discriminator_ptr ATTRIBUTE_UNUSED)1121*ef5ccd6cSJohn Marino _bfd_generic_find_nearest_line_discriminator (bfd *abfd ATTRIBUTE_UNUSED,
1122*ef5ccd6cSJohn Marino asection *section ATTRIBUTE_UNUSED,
1123*ef5ccd6cSJohn Marino asymbol **symbols ATTRIBUTE_UNUSED,
1124*ef5ccd6cSJohn Marino bfd_vma offset ATTRIBUTE_UNUSED,
1125*ef5ccd6cSJohn Marino const char **filename_ptr ATTRIBUTE_UNUSED,
1126*ef5ccd6cSJohn Marino const char **functionname_ptr ATTRIBUTE_UNUSED,
1127*ef5ccd6cSJohn Marino unsigned int *line_ptr ATTRIBUTE_UNUSED,
1128*ef5ccd6cSJohn Marino unsigned int *discriminator_ptr ATTRIBUTE_UNUSED)
1129*ef5ccd6cSJohn Marino {
1130*ef5ccd6cSJohn Marino return FALSE;
1131*ef5ccd6cSJohn Marino }
1132*ef5ccd6cSJohn Marino
1133*ef5ccd6cSJohn Marino bfd_boolean
_bfd_generic_init_private_section_data(bfd * ibfd ATTRIBUTE_UNUSED,asection * isec ATTRIBUTE_UNUSED,bfd * obfd ATTRIBUTE_UNUSED,asection * osec ATTRIBUTE_UNUSED,struct bfd_link_info * link_info ATTRIBUTE_UNUSED)11345796c8dcSSimon Schubert _bfd_generic_init_private_section_data (bfd *ibfd ATTRIBUTE_UNUSED,
11355796c8dcSSimon Schubert asection *isec ATTRIBUTE_UNUSED,
11365796c8dcSSimon Schubert bfd *obfd ATTRIBUTE_UNUSED,
11375796c8dcSSimon Schubert asection *osec ATTRIBUTE_UNUSED,
11385796c8dcSSimon Schubert struct bfd_link_info *link_info ATTRIBUTE_UNUSED)
11395796c8dcSSimon Schubert {
11405796c8dcSSimon Schubert return TRUE;
11415796c8dcSSimon Schubert }
1142