1*3d8817e4Smiod@section Implementation details 2*3d8817e4Smiod 3*3d8817e4Smiod 4*3d8817e4Smiod@subsection Internal functions 5*3d8817e4Smiod 6*3d8817e4Smiod 7*3d8817e4Smiod@strong{Description}@* 8*3d8817e4SmiodThese routines are used within BFD. 9*3d8817e4SmiodThey are not intended for export, but are documented here for 10*3d8817e4Smiodcompleteness. 11*3d8817e4Smiod 12*3d8817e4Smiod@findex bfd_write_bigendian_4byte_int 13*3d8817e4Smiod@subsubsection @code{bfd_write_bigendian_4byte_int} 14*3d8817e4Smiod@strong{Synopsis} 15*3d8817e4Smiod@example 16*3d8817e4Smiodbfd_boolean bfd_write_bigendian_4byte_int (bfd *, unsigned int); 17*3d8817e4Smiod@end example 18*3d8817e4Smiod@strong{Description}@* 19*3d8817e4SmiodWrite a 4 byte integer @var{i} to the output BFD @var{abfd}, in big 20*3d8817e4Smiodendian order regardless of what else is going on. This is useful in 21*3d8817e4Smiodarchives. 22*3d8817e4Smiod 23*3d8817e4Smiod@findex bfd_put_size 24*3d8817e4Smiod@subsubsection @code{bfd_put_size} 25*3d8817e4Smiod@findex bfd_get_size 26*3d8817e4Smiod@subsubsection @code{bfd_get_size} 27*3d8817e4Smiod@strong{Description}@* 28*3d8817e4SmiodThese macros as used for reading and writing raw data in 29*3d8817e4Smiodsections; each access (except for bytes) is vectored through 30*3d8817e4Smiodthe target format of the BFD and mangled accordingly. The 31*3d8817e4Smiodmangling performs any necessary endian translations and 32*3d8817e4Smiodremoves alignment restrictions. Note that types accepted and 33*3d8817e4Smiodreturned by these macros are identical so they can be swapped 34*3d8817e4Smiodaround in macros---for example, @file{libaout.h} defines @code{GET_WORD} 35*3d8817e4Smiodto either @code{bfd_get_32} or @code{bfd_get_64}. 36*3d8817e4Smiod 37*3d8817e4SmiodIn the put routines, @var{val} must be a @code{bfd_vma}. If we are on a 38*3d8817e4Smiodsystem without prototypes, the caller is responsible for making 39*3d8817e4Smiodsure that is true, with a cast if necessary. We don't cast 40*3d8817e4Smiodthem in the macro definitions because that would prevent @code{lint} 41*3d8817e4Smiodor @code{gcc -Wall} from detecting sins such as passing a pointer. 42*3d8817e4SmiodTo detect calling these with less than a @code{bfd_vma}, use 43*3d8817e4Smiod@code{gcc -Wconversion} on a host with 64 bit @code{bfd_vma}'s. 44*3d8817e4Smiod@example 45*3d8817e4Smiod 46*3d8817e4Smiod/* Byte swapping macros for user section data. */ 47*3d8817e4Smiod 48*3d8817e4Smiod#define bfd_put_8(abfd, val, ptr) \ 49*3d8817e4Smiod ((void) (*((unsigned char *) (ptr)) = (val) & 0xff)) 50*3d8817e4Smiod#define bfd_put_signed_8 \ 51*3d8817e4Smiod bfd_put_8 52*3d8817e4Smiod#define bfd_get_8(abfd, ptr) \ 53*3d8817e4Smiod (*(unsigned char *) (ptr) & 0xff) 54*3d8817e4Smiod#define bfd_get_signed_8(abfd, ptr) \ 55*3d8817e4Smiod (((*(unsigned char *) (ptr) & 0xff) ^ 0x80) - 0x80) 56*3d8817e4Smiod 57*3d8817e4Smiod#define bfd_put_16(abfd, val, ptr) \ 58*3d8817e4Smiod BFD_SEND (abfd, bfd_putx16, ((val),(ptr))) 59*3d8817e4Smiod#define bfd_put_signed_16 \ 60*3d8817e4Smiod bfd_put_16 61*3d8817e4Smiod#define bfd_get_16(abfd, ptr) \ 62*3d8817e4Smiod BFD_SEND (abfd, bfd_getx16, (ptr)) 63*3d8817e4Smiod#define bfd_get_signed_16(abfd, ptr) \ 64*3d8817e4Smiod BFD_SEND (abfd, bfd_getx_signed_16, (ptr)) 65*3d8817e4Smiod 66*3d8817e4Smiod#define bfd_put_32(abfd, val, ptr) \ 67*3d8817e4Smiod BFD_SEND (abfd, bfd_putx32, ((val),(ptr))) 68*3d8817e4Smiod#define bfd_put_signed_32 \ 69*3d8817e4Smiod bfd_put_32 70*3d8817e4Smiod#define bfd_get_32(abfd, ptr) \ 71*3d8817e4Smiod BFD_SEND (abfd, bfd_getx32, (ptr)) 72*3d8817e4Smiod#define bfd_get_signed_32(abfd, ptr) \ 73*3d8817e4Smiod BFD_SEND (abfd, bfd_getx_signed_32, (ptr)) 74*3d8817e4Smiod 75*3d8817e4Smiod#define bfd_put_64(abfd, val, ptr) \ 76*3d8817e4Smiod BFD_SEND (abfd, bfd_putx64, ((val), (ptr))) 77*3d8817e4Smiod#define bfd_put_signed_64 \ 78*3d8817e4Smiod bfd_put_64 79*3d8817e4Smiod#define bfd_get_64(abfd, ptr) \ 80*3d8817e4Smiod BFD_SEND (abfd, bfd_getx64, (ptr)) 81*3d8817e4Smiod#define bfd_get_signed_64(abfd, ptr) \ 82*3d8817e4Smiod BFD_SEND (abfd, bfd_getx_signed_64, (ptr)) 83*3d8817e4Smiod 84*3d8817e4Smiod#define bfd_get(bits, abfd, ptr) \ 85*3d8817e4Smiod ((bits) == 8 ? (bfd_vma) bfd_get_8 (abfd, ptr) \ 86*3d8817e4Smiod : (bits) == 16 ? bfd_get_16 (abfd, ptr) \ 87*3d8817e4Smiod : (bits) == 32 ? bfd_get_32 (abfd, ptr) \ 88*3d8817e4Smiod : (bits) == 64 ? bfd_get_64 (abfd, ptr) \ 89*3d8817e4Smiod : (abort (), (bfd_vma) - 1)) 90*3d8817e4Smiod 91*3d8817e4Smiod#define bfd_put(bits, abfd, val, ptr) \ 92*3d8817e4Smiod ((bits) == 8 ? bfd_put_8 (abfd, val, ptr) \ 93*3d8817e4Smiod : (bits) == 16 ? bfd_put_16 (abfd, val, ptr) \ 94*3d8817e4Smiod : (bits) == 32 ? bfd_put_32 (abfd, val, ptr) \ 95*3d8817e4Smiod : (bits) == 64 ? bfd_put_64 (abfd, val, ptr) \ 96*3d8817e4Smiod : (abort (), (void) 0)) 97*3d8817e4Smiod 98*3d8817e4Smiod@end example 99*3d8817e4Smiod 100*3d8817e4Smiod@findex bfd_h_put_size 101*3d8817e4Smiod@subsubsection @code{bfd_h_put_size} 102*3d8817e4Smiod@strong{Description}@* 103*3d8817e4SmiodThese macros have the same function as their @code{bfd_get_x} 104*3d8817e4Smiodbrethren, except that they are used for removing information 105*3d8817e4Smiodfor the header records of object files. Believe it or not, 106*3d8817e4Smiodsome object files keep their header records in big endian 107*3d8817e4Smiodorder and their data in little endian order. 108*3d8817e4Smiod@example 109*3d8817e4Smiod 110*3d8817e4Smiod/* Byte swapping macros for file header data. */ 111*3d8817e4Smiod 112*3d8817e4Smiod#define bfd_h_put_8(abfd, val, ptr) \ 113*3d8817e4Smiod bfd_put_8 (abfd, val, ptr) 114*3d8817e4Smiod#define bfd_h_put_signed_8(abfd, val, ptr) \ 115*3d8817e4Smiod bfd_put_8 (abfd, val, ptr) 116*3d8817e4Smiod#define bfd_h_get_8(abfd, ptr) \ 117*3d8817e4Smiod bfd_get_8 (abfd, ptr) 118*3d8817e4Smiod#define bfd_h_get_signed_8(abfd, ptr) \ 119*3d8817e4Smiod bfd_get_signed_8 (abfd, ptr) 120*3d8817e4Smiod 121*3d8817e4Smiod#define bfd_h_put_16(abfd, val, ptr) \ 122*3d8817e4Smiod BFD_SEND (abfd, bfd_h_putx16, (val, ptr)) 123*3d8817e4Smiod#define bfd_h_put_signed_16 \ 124*3d8817e4Smiod bfd_h_put_16 125*3d8817e4Smiod#define bfd_h_get_16(abfd, ptr) \ 126*3d8817e4Smiod BFD_SEND (abfd, bfd_h_getx16, (ptr)) 127*3d8817e4Smiod#define bfd_h_get_signed_16(abfd, ptr) \ 128*3d8817e4Smiod BFD_SEND (abfd, bfd_h_getx_signed_16, (ptr)) 129*3d8817e4Smiod 130*3d8817e4Smiod#define bfd_h_put_32(abfd, val, ptr) \ 131*3d8817e4Smiod BFD_SEND (abfd, bfd_h_putx32, (val, ptr)) 132*3d8817e4Smiod#define bfd_h_put_signed_32 \ 133*3d8817e4Smiod bfd_h_put_32 134*3d8817e4Smiod#define bfd_h_get_32(abfd, ptr) \ 135*3d8817e4Smiod BFD_SEND (abfd, bfd_h_getx32, (ptr)) 136*3d8817e4Smiod#define bfd_h_get_signed_32(abfd, ptr) \ 137*3d8817e4Smiod BFD_SEND (abfd, bfd_h_getx_signed_32, (ptr)) 138*3d8817e4Smiod 139*3d8817e4Smiod#define bfd_h_put_64(abfd, val, ptr) \ 140*3d8817e4Smiod BFD_SEND (abfd, bfd_h_putx64, (val, ptr)) 141*3d8817e4Smiod#define bfd_h_put_signed_64 \ 142*3d8817e4Smiod bfd_h_put_64 143*3d8817e4Smiod#define bfd_h_get_64(abfd, ptr) \ 144*3d8817e4Smiod BFD_SEND (abfd, bfd_h_getx64, (ptr)) 145*3d8817e4Smiod#define bfd_h_get_signed_64(abfd, ptr) \ 146*3d8817e4Smiod BFD_SEND (abfd, bfd_h_getx_signed_64, (ptr)) 147*3d8817e4Smiod 148*3d8817e4Smiod/* Aliases for the above, which should eventually go away. */ 149*3d8817e4Smiod 150*3d8817e4Smiod#define H_PUT_64 bfd_h_put_64 151*3d8817e4Smiod#define H_PUT_32 bfd_h_put_32 152*3d8817e4Smiod#define H_PUT_16 bfd_h_put_16 153*3d8817e4Smiod#define H_PUT_8 bfd_h_put_8 154*3d8817e4Smiod#define H_PUT_S64 bfd_h_put_signed_64 155*3d8817e4Smiod#define H_PUT_S32 bfd_h_put_signed_32 156*3d8817e4Smiod#define H_PUT_S16 bfd_h_put_signed_16 157*3d8817e4Smiod#define H_PUT_S8 bfd_h_put_signed_8 158*3d8817e4Smiod#define H_GET_64 bfd_h_get_64 159*3d8817e4Smiod#define H_GET_32 bfd_h_get_32 160*3d8817e4Smiod#define H_GET_16 bfd_h_get_16 161*3d8817e4Smiod#define H_GET_8 bfd_h_get_8 162*3d8817e4Smiod#define H_GET_S64 bfd_h_get_signed_64 163*3d8817e4Smiod#define H_GET_S32 bfd_h_get_signed_32 164*3d8817e4Smiod#define H_GET_S16 bfd_h_get_signed_16 165*3d8817e4Smiod#define H_GET_S8 bfd_h_get_signed_8 166*3d8817e4Smiod 167*3d8817e4Smiod 168*3d8817e4Smiod@end example 169*3d8817e4Smiod 170*3d8817e4Smiod@findex bfd_log2 171*3d8817e4Smiod@subsubsection @code{bfd_log2} 172*3d8817e4Smiod@strong{Synopsis} 173*3d8817e4Smiod@example 174*3d8817e4Smiodunsigned int bfd_log2 (bfd_vma x); 175*3d8817e4Smiod@end example 176*3d8817e4Smiod@strong{Description}@* 177*3d8817e4SmiodReturn the log base 2 of the value supplied, rounded up. E.g., an 178*3d8817e4Smiod@var{x} of 1025 returns 11. A @var{x} of 0 returns 0. 179*3d8817e4Smiod 180