source: trunk/binutils/bfd/doc/libbfd.texi@ 3232

Last change on this file since 3232 was 610, checked in by bird, 22 years ago

This commit was generated by cvs2svn to compensate for changes in r609,
which included commits to RCS files with non-trunk default branches.

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