Commit | Line | Data |
---|---|---|
252b5132 | 1 | /* Assorted BFD support routines, only used internally. |
7898deda | 2 | Copyright 1990, 1991, 1992, 1993, 1994, 1995, 1996, 1997, 1998, 1999, |
72f6ea61 | 3 | 2000, 2001, 2002, 2003, 2004, 2005, 2007 |
252b5132 RH |
4 | Free Software Foundation, Inc. |
5 | Written by Cygnus Support. | |
6 | ||
ca09e32b | 7 | This file is part of BFD, the Binary File Descriptor library. |
252b5132 | 8 | |
ca09e32b NC |
9 | This program is free software; you can redistribute it and/or modify |
10 | it under the terms of the GNU General Public License as published by | |
cd123cb7 | 11 | the Free Software Foundation; either version 3 of the License, or |
ca09e32b | 12 | (at your option) any later version. |
252b5132 | 13 | |
ca09e32b NC |
14 | This program is distributed in the hope that it will be useful, |
15 | but WITHOUT ANY WARRANTY; without even the implied warranty of | |
16 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
17 | GNU General Public License for more details. | |
252b5132 | 18 | |
ca09e32b NC |
19 | You should have received a copy of the GNU General Public License |
20 | along with this program; if not, write to the Free Software | |
cd123cb7 NC |
21 | Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston, |
22 | MA 02110-1301, USA. */ | |
252b5132 | 23 | |
252b5132 | 24 | #include "sysdep.h" |
3db64b00 | 25 | #include "bfd.h" |
252b5132 RH |
26 | #include "libbfd.h" |
27 | ||
28 | #ifndef HAVE_GETPAGESIZE | |
29 | #define getpagesize() 2048 | |
30 | #endif | |
31 | ||
252b5132 RH |
32 | /* |
33 | SECTION | |
1b74d094 BW |
34 | Implementation details |
35 | ||
36 | SUBSECTION | |
252b5132 RH |
37 | Internal functions |
38 | ||
39 | DESCRIPTION | |
40 | These routines are used within BFD. | |
41 | They are not intended for export, but are documented here for | |
42 | completeness. | |
43 | */ | |
44 | ||
45 | /* A routine which is used in target vectors for unsupported | |
46 | operations. */ | |
47 | ||
b34976b6 | 48 | bfd_boolean |
c58b9523 | 49 | bfd_false (bfd *ignore ATTRIBUTE_UNUSED) |
252b5132 RH |
50 | { |
51 | bfd_set_error (bfd_error_invalid_operation); | |
b34976b6 | 52 | return FALSE; |
252b5132 RH |
53 | } |
54 | ||
55 | /* A routine which is used in target vectors for supported operations | |
56 | which do not actually do anything. */ | |
57 | ||
b34976b6 | 58 | bfd_boolean |
c58b9523 | 59 | bfd_true (bfd *ignore ATTRIBUTE_UNUSED) |
252b5132 | 60 | { |
b34976b6 | 61 | return TRUE; |
252b5132 RH |
62 | } |
63 | ||
64 | /* A routine which is used in target vectors for unsupported | |
65 | operations which return a pointer value. */ | |
66 | ||
c58b9523 AM |
67 | void * |
68 | bfd_nullvoidptr (bfd *ignore ATTRIBUTE_UNUSED) | |
252b5132 RH |
69 | { |
70 | bfd_set_error (bfd_error_invalid_operation); | |
71 | return NULL; | |
72 | } | |
73 | ||
509945ae | 74 | int |
c58b9523 | 75 | bfd_0 (bfd *ignore ATTRIBUTE_UNUSED) |
252b5132 RH |
76 | { |
77 | return 0; | |
78 | } | |
79 | ||
509945ae | 80 | unsigned int |
c58b9523 | 81 | bfd_0u (bfd *ignore ATTRIBUTE_UNUSED) |
252b5132 RH |
82 | { |
83 | return 0; | |
84 | } | |
85 | ||
252b5132 | 86 | long |
c58b9523 | 87 | bfd_0l (bfd *ignore ATTRIBUTE_UNUSED) |
252b5132 RH |
88 | { |
89 | return 0; | |
90 | } | |
91 | ||
92 | /* A routine which is used in target vectors for unsupported | |
93 | operations which return -1 on error. */ | |
94 | ||
252b5132 | 95 | long |
c58b9523 | 96 | _bfd_n1 (bfd *ignore_abfd ATTRIBUTE_UNUSED) |
252b5132 RH |
97 | { |
98 | bfd_set_error (bfd_error_invalid_operation); | |
99 | return -1; | |
100 | } | |
101 | ||
509945ae | 102 | void |
c58b9523 | 103 | bfd_void (bfd *ignore ATTRIBUTE_UNUSED) |
252b5132 RH |
104 | { |
105 | } | |
106 | ||
72f6ea61 AM |
107 | long |
108 | _bfd_norelocs_get_reloc_upper_bound (bfd *abfd ATTRIBUTE_UNUSED, | |
109 | asection *sec ATTRIBUTE_UNUSED) | |
110 | { | |
111 | return sizeof (arelent *); | |
112 | } | |
113 | ||
114 | long | |
115 | _bfd_norelocs_canonicalize_reloc (bfd *abfd ATTRIBUTE_UNUSED, | |
116 | asection *sec ATTRIBUTE_UNUSED, | |
117 | arelent **relptr, | |
118 | asymbol **symbols ATTRIBUTE_UNUSED) | |
119 | { | |
120 | *relptr = NULL; | |
121 | return 0; | |
122 | } | |
123 | ||
b34976b6 | 124 | bfd_boolean |
c58b9523 AM |
125 | _bfd_nocore_core_file_matches_executable_p |
126 | (bfd *ignore_core_bfd ATTRIBUTE_UNUSED, | |
127 | bfd *ignore_exec_bfd ATTRIBUTE_UNUSED) | |
252b5132 RH |
128 | { |
129 | bfd_set_error (bfd_error_invalid_operation); | |
b34976b6 | 130 | return FALSE; |
252b5132 RH |
131 | } |
132 | ||
133 | /* Routine to handle core_file_failing_command entry point for targets | |
134 | without core file support. */ | |
135 | ||
252b5132 | 136 | char * |
c58b9523 | 137 | _bfd_nocore_core_file_failing_command (bfd *ignore_abfd ATTRIBUTE_UNUSED) |
252b5132 RH |
138 | { |
139 | bfd_set_error (bfd_error_invalid_operation); | |
c58b9523 | 140 | return NULL; |
252b5132 RH |
141 | } |
142 | ||
143 | /* Routine to handle core_file_failing_signal entry point for targets | |
144 | without core file support. */ | |
145 | ||
252b5132 | 146 | int |
c58b9523 | 147 | _bfd_nocore_core_file_failing_signal (bfd *ignore_abfd ATTRIBUTE_UNUSED) |
252b5132 RH |
148 | { |
149 | bfd_set_error (bfd_error_invalid_operation); | |
150 | return 0; | |
151 | } | |
152 | ||
252b5132 | 153 | const bfd_target * |
c58b9523 | 154 | _bfd_dummy_target (bfd *ignore_abfd ATTRIBUTE_UNUSED) |
252b5132 RH |
155 | { |
156 | bfd_set_error (bfd_error_wrong_format); | |
157 | return 0; | |
158 | } | |
159 | \f | |
160 | /* Allocate memory using malloc. */ | |
161 | ||
c58b9523 AM |
162 | void * |
163 | bfd_malloc (bfd_size_type size) | |
252b5132 | 164 | { |
c58b9523 | 165 | void *ptr; |
252b5132 | 166 | |
dc810e39 AM |
167 | if (size != (size_t) size) |
168 | { | |
169 | bfd_set_error (bfd_error_no_memory); | |
170 | return NULL; | |
171 | } | |
172 | ||
c58b9523 | 173 | ptr = malloc ((size_t) size); |
dc810e39 | 174 | if (ptr == NULL && (size_t) size != 0) |
252b5132 | 175 | bfd_set_error (bfd_error_no_memory); |
dc810e39 | 176 | |
252b5132 RH |
177 | return ptr; |
178 | } | |
179 | ||
d0fb9a8d JJ |
180 | /* Allocate memory using malloc, nmemb * size with overflow checking. */ |
181 | ||
182 | void * | |
183 | bfd_malloc2 (bfd_size_type nmemb, bfd_size_type size) | |
184 | { | |
185 | void *ptr; | |
186 | ||
187 | if ((nmemb | size) >= HALF_BFD_SIZE_TYPE | |
188 | && size != 0 | |
189 | && nmemb > ~(bfd_size_type) 0 / size) | |
190 | { | |
191 | bfd_set_error (bfd_error_no_memory); | |
192 | return NULL; | |
193 | } | |
194 | ||
195 | size *= nmemb; | |
196 | ||
197 | if (size != (size_t) size) | |
198 | { | |
199 | bfd_set_error (bfd_error_no_memory); | |
200 | return NULL; | |
201 | } | |
202 | ||
203 | ptr = malloc ((size_t) size); | |
204 | if (ptr == NULL && (size_t) size != 0) | |
205 | bfd_set_error (bfd_error_no_memory); | |
206 | ||
207 | return ptr; | |
208 | } | |
209 | ||
252b5132 RH |
210 | /* Reallocate memory using realloc. */ |
211 | ||
c58b9523 AM |
212 | void * |
213 | bfd_realloc (void *ptr, bfd_size_type size) | |
252b5132 | 214 | { |
c58b9523 | 215 | void *ret; |
252b5132 | 216 | |
dc810e39 AM |
217 | if (size != (size_t) size) |
218 | { | |
219 | bfd_set_error (bfd_error_no_memory); | |
220 | return NULL; | |
221 | } | |
222 | ||
252b5132 | 223 | if (ptr == NULL) |
c58b9523 | 224 | ret = malloc ((size_t) size); |
252b5132 | 225 | else |
c58b9523 | 226 | ret = realloc (ptr, (size_t) size); |
252b5132 | 227 | |
dc810e39 | 228 | if (ret == NULL && (size_t) size != 0) |
252b5132 RH |
229 | bfd_set_error (bfd_error_no_memory); |
230 | ||
231 | return ret; | |
232 | } | |
233 | ||
d0fb9a8d JJ |
234 | /* Reallocate memory using realloc, nmemb * size with overflow checking. */ |
235 | ||
236 | void * | |
237 | bfd_realloc2 (void *ptr, bfd_size_type nmemb, bfd_size_type size) | |
238 | { | |
239 | void *ret; | |
240 | ||
241 | if ((nmemb | size) >= HALF_BFD_SIZE_TYPE | |
242 | && size != 0 | |
243 | && nmemb > ~(bfd_size_type) 0 / size) | |
244 | { | |
245 | bfd_set_error (bfd_error_no_memory); | |
246 | return NULL; | |
247 | } | |
248 | ||
249 | size *= nmemb; | |
250 | ||
251 | if (size != (size_t) size) | |
252 | { | |
253 | bfd_set_error (bfd_error_no_memory); | |
254 | return NULL; | |
255 | } | |
256 | ||
257 | if (ptr == NULL) | |
258 | ret = malloc ((size_t) size); | |
259 | else | |
260 | ret = realloc (ptr, (size_t) size); | |
261 | ||
262 | if (ret == NULL && (size_t) size != 0) | |
263 | bfd_set_error (bfd_error_no_memory); | |
264 | ||
265 | return ret; | |
266 | } | |
267 | ||
252b5132 RH |
268 | /* Allocate memory using malloc and clear it. */ |
269 | ||
c58b9523 AM |
270 | void * |
271 | bfd_zmalloc (bfd_size_type size) | |
252b5132 | 272 | { |
c58b9523 | 273 | void *ptr; |
252b5132 | 274 | |
dc810e39 AM |
275 | if (size != (size_t) size) |
276 | { | |
277 | bfd_set_error (bfd_error_no_memory); | |
278 | return NULL; | |
279 | } | |
252b5132 | 280 | |
c58b9523 | 281 | ptr = malloc ((size_t) size); |
dc810e39 AM |
282 | |
283 | if ((size_t) size != 0) | |
252b5132 RH |
284 | { |
285 | if (ptr == NULL) | |
286 | bfd_set_error (bfd_error_no_memory); | |
287 | else | |
dc810e39 | 288 | memset (ptr, 0, (size_t) size); |
252b5132 RH |
289 | } |
290 | ||
291 | return ptr; | |
292 | } | |
d0fb9a8d JJ |
293 | |
294 | /* Allocate memory using malloc (nmemb * size) with overflow checking | |
295 | and clear it. */ | |
296 | ||
297 | void * | |
298 | bfd_zmalloc2 (bfd_size_type nmemb, bfd_size_type size) | |
299 | { | |
300 | void *ptr; | |
301 | ||
302 | if ((nmemb | size) >= HALF_BFD_SIZE_TYPE | |
303 | && size != 0 | |
304 | && nmemb > ~(bfd_size_type) 0 / size) | |
305 | { | |
306 | bfd_set_error (bfd_error_no_memory); | |
307 | return NULL; | |
308 | } | |
309 | ||
310 | size *= nmemb; | |
311 | ||
312 | if (size != (size_t) size) | |
313 | { | |
314 | bfd_set_error (bfd_error_no_memory); | |
315 | return NULL; | |
316 | } | |
317 | ||
318 | ptr = malloc ((size_t) size); | |
319 | ||
320 | if ((size_t) size != 0) | |
321 | { | |
322 | if (ptr == NULL) | |
323 | bfd_set_error (bfd_error_no_memory); | |
324 | else | |
325 | memset (ptr, 0, (size_t) size); | |
326 | } | |
327 | ||
328 | return ptr; | |
329 | } | |
330 | ||
252b5132 RH |
331 | /* |
332 | INTERNAL_FUNCTION | |
333 | bfd_write_bigendian_4byte_int | |
334 | ||
335 | SYNOPSIS | |
b34976b6 | 336 | bfd_boolean bfd_write_bigendian_4byte_int (bfd *, unsigned int); |
252b5132 RH |
337 | |
338 | DESCRIPTION | |
339 | Write a 4 byte integer @var{i} to the output BFD @var{abfd}, in big | |
340 | endian order regardless of what else is going on. This is useful in | |
341 | archives. | |
342 | ||
343 | */ | |
b34976b6 | 344 | bfd_boolean |
c58b9523 | 345 | bfd_write_bigendian_4byte_int (bfd *abfd, unsigned int i) |
252b5132 RH |
346 | { |
347 | bfd_byte buffer[4]; | |
dc810e39 | 348 | bfd_putb32 ((bfd_vma) i, buffer); |
c58b9523 | 349 | return bfd_bwrite (buffer, (bfd_size_type) 4, abfd) == 4; |
252b5132 RH |
350 | } |
351 | ||
252b5132 RH |
352 | \f |
353 | /** The do-it-yourself (byte) sex-change kit */ | |
354 | ||
355 | /* The middle letter e.g. get<b>short indicates Big or Little endian | |
356 | target machine. It doesn't matter what the byte order of the host | |
357 | machine is; these routines work for either. */ | |
358 | ||
359 | /* FIXME: Should these take a count argument? | |
360 | Answer (gnu@cygnus.com): No, but perhaps they should be inline | |
509945ae | 361 | functions in swap.h #ifdef __GNUC__. |
252b5132 RH |
362 | Gprof them later and find out. */ |
363 | ||
364 | /* | |
365 | FUNCTION | |
366 | bfd_put_size | |
367 | FUNCTION | |
368 | bfd_get_size | |
369 | ||
370 | DESCRIPTION | |
371 | These macros as used for reading and writing raw data in | |
372 | sections; each access (except for bytes) is vectored through | |
373 | the target format of the BFD and mangled accordingly. The | |
374 | mangling performs any necessary endian translations and | |
375 | removes alignment restrictions. Note that types accepted and | |
376 | returned by these macros are identical so they can be swapped | |
377 | around in macros---for example, @file{libaout.h} defines <<GET_WORD>> | |
378 | to either <<bfd_get_32>> or <<bfd_get_64>>. | |
379 | ||
380 | In the put routines, @var{val} must be a <<bfd_vma>>. If we are on a | |
381 | system without prototypes, the caller is responsible for making | |
382 | sure that is true, with a cast if necessary. We don't cast | |
383 | them in the macro definitions because that would prevent <<lint>> | |
384 | or <<gcc -Wall>> from detecting sins such as passing a pointer. | |
385 | To detect calling these with less than a <<bfd_vma>>, use | |
386 | <<gcc -Wconversion>> on a host with 64 bit <<bfd_vma>>'s. | |
387 | ||
388 | . | |
389 | .{* Byte swapping macros for user section data. *} | |
390 | . | |
391 | .#define bfd_put_8(abfd, val, ptr) \ | |
edeb6e24 | 392 | . ((void) (*((unsigned char *) (ptr)) = (val) & 0xff)) |
252b5132 | 393 | .#define bfd_put_signed_8 \ |
c58b9523 | 394 | . bfd_put_8 |
252b5132 | 395 | .#define bfd_get_8(abfd, ptr) \ |
c58b9523 | 396 | . (*(unsigned char *) (ptr) & 0xff) |
252b5132 | 397 | .#define bfd_get_signed_8(abfd, ptr) \ |
c58b9523 | 398 | . (((*(unsigned char *) (ptr) & 0xff) ^ 0x80) - 0x80) |
252b5132 RH |
399 | . |
400 | .#define bfd_put_16(abfd, val, ptr) \ | |
c58b9523 | 401 | . BFD_SEND (abfd, bfd_putx16, ((val),(ptr))) |
252b5132 | 402 | .#define bfd_put_signed_16 \ |
c58b9523 | 403 | . bfd_put_16 |
252b5132 | 404 | .#define bfd_get_16(abfd, ptr) \ |
c58b9523 | 405 | . BFD_SEND (abfd, bfd_getx16, (ptr)) |
252b5132 | 406 | .#define bfd_get_signed_16(abfd, ptr) \ |
c58b9523 | 407 | . BFD_SEND (abfd, bfd_getx_signed_16, (ptr)) |
252b5132 RH |
408 | . |
409 | .#define bfd_put_32(abfd, val, ptr) \ | |
c58b9523 | 410 | . BFD_SEND (abfd, bfd_putx32, ((val),(ptr))) |
252b5132 | 411 | .#define bfd_put_signed_32 \ |
c58b9523 | 412 | . bfd_put_32 |
252b5132 | 413 | .#define bfd_get_32(abfd, ptr) \ |
c58b9523 | 414 | . BFD_SEND (abfd, bfd_getx32, (ptr)) |
252b5132 | 415 | .#define bfd_get_signed_32(abfd, ptr) \ |
c58b9523 | 416 | . BFD_SEND (abfd, bfd_getx_signed_32, (ptr)) |
252b5132 RH |
417 | . |
418 | .#define bfd_put_64(abfd, val, ptr) \ | |
c58b9523 | 419 | . BFD_SEND (abfd, bfd_putx64, ((val), (ptr))) |
252b5132 | 420 | .#define bfd_put_signed_64 \ |
c58b9523 | 421 | . bfd_put_64 |
252b5132 | 422 | .#define bfd_get_64(abfd, ptr) \ |
c58b9523 | 423 | . BFD_SEND (abfd, bfd_getx64, (ptr)) |
252b5132 | 424 | .#define bfd_get_signed_64(abfd, ptr) \ |
c58b9523 | 425 | . BFD_SEND (abfd, bfd_getx_signed_64, (ptr)) |
252b5132 | 426 | . |
c58b9523 AM |
427 | .#define bfd_get(bits, abfd, ptr) \ |
428 | . ((bits) == 8 ? (bfd_vma) bfd_get_8 (abfd, ptr) \ | |
429 | . : (bits) == 16 ? bfd_get_16 (abfd, ptr) \ | |
430 | . : (bits) == 32 ? bfd_get_32 (abfd, ptr) \ | |
431 | . : (bits) == 64 ? bfd_get_64 (abfd, ptr) \ | |
432 | . : (abort (), (bfd_vma) - 1)) | |
c7ac6ff8 | 433 | . |
c58b9523 AM |
434 | .#define bfd_put(bits, abfd, val, ptr) \ |
435 | . ((bits) == 8 ? bfd_put_8 (abfd, val, ptr) \ | |
436 | . : (bits) == 16 ? bfd_put_16 (abfd, val, ptr) \ | |
437 | . : (bits) == 32 ? bfd_put_32 (abfd, val, ptr) \ | |
438 | . : (bits) == 64 ? bfd_put_64 (abfd, val, ptr) \ | |
439 | . : (abort (), (void) 0)) | |
c7ac6ff8 | 440 | . |
509945ae | 441 | */ |
252b5132 RH |
442 | |
443 | /* | |
444 | FUNCTION | |
445 | bfd_h_put_size | |
446 | bfd_h_get_size | |
447 | ||
448 | DESCRIPTION | |
449 | These macros have the same function as their <<bfd_get_x>> | |
dc810e39 | 450 | brethren, except that they are used for removing information |
252b5132 RH |
451 | for the header records of object files. Believe it or not, |
452 | some object files keep their header records in big endian | |
453 | order and their data in little endian order. | |
454 | . | |
455 | .{* Byte swapping macros for file header data. *} | |
456 | . | |
457 | .#define bfd_h_put_8(abfd, val, ptr) \ | |
dc810e39 | 458 | . bfd_put_8 (abfd, val, ptr) |
252b5132 | 459 | .#define bfd_h_put_signed_8(abfd, val, ptr) \ |
dc810e39 | 460 | . bfd_put_8 (abfd, val, ptr) |
252b5132 | 461 | .#define bfd_h_get_8(abfd, ptr) \ |
dc810e39 | 462 | . bfd_get_8 (abfd, ptr) |
252b5132 | 463 | .#define bfd_h_get_signed_8(abfd, ptr) \ |
dc810e39 | 464 | . bfd_get_signed_8 (abfd, ptr) |
252b5132 RH |
465 | . |
466 | .#define bfd_h_put_16(abfd, val, ptr) \ | |
dc810e39 | 467 | . BFD_SEND (abfd, bfd_h_putx16, (val, ptr)) |
252b5132 | 468 | .#define bfd_h_put_signed_16 \ |
dc810e39 | 469 | . bfd_h_put_16 |
252b5132 | 470 | .#define bfd_h_get_16(abfd, ptr) \ |
dc810e39 | 471 | . BFD_SEND (abfd, bfd_h_getx16, (ptr)) |
252b5132 | 472 | .#define bfd_h_get_signed_16(abfd, ptr) \ |
dc810e39 | 473 | . BFD_SEND (abfd, bfd_h_getx_signed_16, (ptr)) |
252b5132 RH |
474 | . |
475 | .#define bfd_h_put_32(abfd, val, ptr) \ | |
dc810e39 | 476 | . BFD_SEND (abfd, bfd_h_putx32, (val, ptr)) |
252b5132 | 477 | .#define bfd_h_put_signed_32 \ |
dc810e39 | 478 | . bfd_h_put_32 |
252b5132 | 479 | .#define bfd_h_get_32(abfd, ptr) \ |
dc810e39 | 480 | . BFD_SEND (abfd, bfd_h_getx32, (ptr)) |
252b5132 | 481 | .#define bfd_h_get_signed_32(abfd, ptr) \ |
dc810e39 | 482 | . BFD_SEND (abfd, bfd_h_getx_signed_32, (ptr)) |
252b5132 RH |
483 | . |
484 | .#define bfd_h_put_64(abfd, val, ptr) \ | |
dc810e39 | 485 | . BFD_SEND (abfd, bfd_h_putx64, (val, ptr)) |
252b5132 | 486 | .#define bfd_h_put_signed_64 \ |
dc810e39 | 487 | . bfd_h_put_64 |
252b5132 | 488 | .#define bfd_h_get_64(abfd, ptr) \ |
dc810e39 | 489 | . BFD_SEND (abfd, bfd_h_getx64, (ptr)) |
252b5132 | 490 | .#define bfd_h_get_signed_64(abfd, ptr) \ |
dc810e39 | 491 | . BFD_SEND (abfd, bfd_h_getx_signed_64, (ptr)) |
252b5132 | 492 | . |
edeb6e24 | 493 | .{* Aliases for the above, which should eventually go away. *} |
dc810e39 | 494 | . |
edeb6e24 AM |
495 | .#define H_PUT_64 bfd_h_put_64 |
496 | .#define H_PUT_32 bfd_h_put_32 | |
497 | .#define H_PUT_16 bfd_h_put_16 | |
498 | .#define H_PUT_8 bfd_h_put_8 | |
499 | .#define H_PUT_S64 bfd_h_put_signed_64 | |
500 | .#define H_PUT_S32 bfd_h_put_signed_32 | |
501 | .#define H_PUT_S16 bfd_h_put_signed_16 | |
502 | .#define H_PUT_S8 bfd_h_put_signed_8 | |
503 | .#define H_GET_64 bfd_h_get_64 | |
504 | .#define H_GET_32 bfd_h_get_32 | |
505 | .#define H_GET_16 bfd_h_get_16 | |
506 | .#define H_GET_8 bfd_h_get_8 | |
507 | .#define H_GET_S64 bfd_h_get_signed_64 | |
508 | .#define H_GET_S32 bfd_h_get_signed_32 | |
509 | .#define H_GET_S16 bfd_h_get_signed_16 | |
510 | .#define H_GET_S8 bfd_h_get_signed_8 | |
dc810e39 AM |
511 | . |
512 | .*/ | |
252b5132 RH |
513 | |
514 | /* Sign extension to bfd_signed_vma. */ | |
515 | #define COERCE16(x) (((bfd_signed_vma) (x) ^ 0x8000) - 0x8000) | |
c58b9523 | 516 | #define COERCE32(x) (((bfd_signed_vma) (x) ^ 0x80000000) - 0x80000000) |
8ce8c090 | 517 | #define EIGHT_GAZILLION ((bfd_int64_t) 1 << 63) |
252b5132 | 518 | #define COERCE64(x) \ |
8ce8c090 | 519 | (((bfd_int64_t) (x) ^ EIGHT_GAZILLION) - EIGHT_GAZILLION) |
252b5132 RH |
520 | |
521 | bfd_vma | |
edeb6e24 | 522 | bfd_getb16 (const void *p) |
252b5132 | 523 | { |
edeb6e24 | 524 | const bfd_byte *addr = p; |
252b5132 RH |
525 | return (addr[0] << 8) | addr[1]; |
526 | } | |
527 | ||
528 | bfd_vma | |
edeb6e24 | 529 | bfd_getl16 (const void *p) |
252b5132 | 530 | { |
edeb6e24 | 531 | const bfd_byte *addr = p; |
252b5132 RH |
532 | return (addr[1] << 8) | addr[0]; |
533 | } | |
534 | ||
535 | bfd_signed_vma | |
edeb6e24 | 536 | bfd_getb_signed_16 (const void *p) |
252b5132 | 537 | { |
edeb6e24 | 538 | const bfd_byte *addr = p; |
c58b9523 | 539 | return COERCE16 ((addr[0] << 8) | addr[1]); |
252b5132 RH |
540 | } |
541 | ||
542 | bfd_signed_vma | |
edeb6e24 | 543 | bfd_getl_signed_16 (const void *p) |
252b5132 | 544 | { |
edeb6e24 | 545 | const bfd_byte *addr = p; |
c58b9523 | 546 | return COERCE16 ((addr[1] << 8) | addr[0]); |
252b5132 RH |
547 | } |
548 | ||
549 | void | |
edeb6e24 | 550 | bfd_putb16 (bfd_vma data, void *p) |
252b5132 | 551 | { |
edeb6e24 AM |
552 | bfd_byte *addr = p; |
553 | addr[0] = (data >> 8) & 0xff; | |
554 | addr[1] = data & 0xff; | |
252b5132 RH |
555 | } |
556 | ||
557 | void | |
edeb6e24 | 558 | bfd_putl16 (bfd_vma data, void *p) |
252b5132 | 559 | { |
edeb6e24 AM |
560 | bfd_byte *addr = p; |
561 | addr[0] = data & 0xff; | |
562 | addr[1] = (data >> 8) & 0xff; | |
252b5132 RH |
563 | } |
564 | ||
565 | bfd_vma | |
edeb6e24 | 566 | bfd_getb32 (const void *p) |
252b5132 | 567 | { |
edeb6e24 | 568 | const bfd_byte *addr = p; |
252b5132 RH |
569 | unsigned long v; |
570 | ||
571 | v = (unsigned long) addr[0] << 24; | |
572 | v |= (unsigned long) addr[1] << 16; | |
573 | v |= (unsigned long) addr[2] << 8; | |
574 | v |= (unsigned long) addr[3]; | |
c58b9523 | 575 | return v; |
252b5132 RH |
576 | } |
577 | ||
578 | bfd_vma | |
edeb6e24 | 579 | bfd_getl32 (const void *p) |
252b5132 | 580 | { |
edeb6e24 | 581 | const bfd_byte *addr = p; |
252b5132 RH |
582 | unsigned long v; |
583 | ||
584 | v = (unsigned long) addr[0]; | |
585 | v |= (unsigned long) addr[1] << 8; | |
586 | v |= (unsigned long) addr[2] << 16; | |
587 | v |= (unsigned long) addr[3] << 24; | |
c58b9523 | 588 | return v; |
252b5132 RH |
589 | } |
590 | ||
591 | bfd_signed_vma | |
edeb6e24 | 592 | bfd_getb_signed_32 (const void *p) |
252b5132 | 593 | { |
edeb6e24 | 594 | const bfd_byte *addr = p; |
252b5132 RH |
595 | unsigned long v; |
596 | ||
597 | v = (unsigned long) addr[0] << 24; | |
598 | v |= (unsigned long) addr[1] << 16; | |
599 | v |= (unsigned long) addr[2] << 8; | |
600 | v |= (unsigned long) addr[3]; | |
601 | return COERCE32 (v); | |
602 | } | |
603 | ||
604 | bfd_signed_vma | |
edeb6e24 | 605 | bfd_getl_signed_32 (const void *p) |
252b5132 | 606 | { |
edeb6e24 | 607 | const bfd_byte *addr = p; |
252b5132 RH |
608 | unsigned long v; |
609 | ||
610 | v = (unsigned long) addr[0]; | |
611 | v |= (unsigned long) addr[1] << 8; | |
612 | v |= (unsigned long) addr[2] << 16; | |
613 | v |= (unsigned long) addr[3] << 24; | |
614 | return COERCE32 (v); | |
615 | } | |
616 | ||
8ce8c090 | 617 | bfd_uint64_t |
edeb6e24 | 618 | bfd_getb64 (const void *p ATTRIBUTE_UNUSED) |
252b5132 | 619 | { |
8ce8c090 | 620 | #ifdef BFD_HOST_64_BIT |
edeb6e24 | 621 | const bfd_byte *addr = p; |
8ce8c090 | 622 | bfd_uint64_t v; |
c58b9523 AM |
623 | |
624 | v = addr[0]; v <<= 8; | |
625 | v |= addr[1]; v <<= 8; | |
626 | v |= addr[2]; v <<= 8; | |
627 | v |= addr[3]; v <<= 8; | |
628 | v |= addr[4]; v <<= 8; | |
629 | v |= addr[5]; v <<= 8; | |
630 | v |= addr[6]; v <<= 8; | |
631 | v |= addr[7]; | |
632 | ||
633 | return v; | |
252b5132 RH |
634 | #else |
635 | BFD_FAIL(); | |
636 | return 0; | |
637 | #endif | |
638 | } | |
639 | ||
8ce8c090 | 640 | bfd_uint64_t |
edeb6e24 | 641 | bfd_getl64 (const void *p ATTRIBUTE_UNUSED) |
252b5132 | 642 | { |
8ce8c090 | 643 | #ifdef BFD_HOST_64_BIT |
edeb6e24 | 644 | const bfd_byte *addr = p; |
8ce8c090 | 645 | bfd_uint64_t v; |
c58b9523 AM |
646 | |
647 | v = addr[7]; v <<= 8; | |
648 | v |= addr[6]; v <<= 8; | |
649 | v |= addr[5]; v <<= 8; | |
650 | v |= addr[4]; v <<= 8; | |
651 | v |= addr[3]; v <<= 8; | |
652 | v |= addr[2]; v <<= 8; | |
653 | v |= addr[1]; v <<= 8; | |
654 | v |= addr[0]; | |
655 | ||
656 | return v; | |
252b5132 RH |
657 | #else |
658 | BFD_FAIL(); | |
659 | return 0; | |
660 | #endif | |
661 | ||
662 | } | |
663 | ||
8ce8c090 | 664 | bfd_int64_t |
edeb6e24 | 665 | bfd_getb_signed_64 (const void *p ATTRIBUTE_UNUSED) |
252b5132 | 666 | { |
8ce8c090 | 667 | #ifdef BFD_HOST_64_BIT |
edeb6e24 | 668 | const bfd_byte *addr = p; |
8ce8c090 | 669 | bfd_uint64_t v; |
c58b9523 AM |
670 | |
671 | v = addr[0]; v <<= 8; | |
672 | v |= addr[1]; v <<= 8; | |
673 | v |= addr[2]; v <<= 8; | |
674 | v |= addr[3]; v <<= 8; | |
675 | v |= addr[4]; v <<= 8; | |
676 | v |= addr[5]; v <<= 8; | |
677 | v |= addr[6]; v <<= 8; | |
678 | v |= addr[7]; | |
679 | ||
680 | return COERCE64 (v); | |
252b5132 RH |
681 | #else |
682 | BFD_FAIL(); | |
683 | return 0; | |
684 | #endif | |
685 | } | |
686 | ||
8ce8c090 | 687 | bfd_int64_t |
edeb6e24 | 688 | bfd_getl_signed_64 (const void *p ATTRIBUTE_UNUSED) |
252b5132 | 689 | { |
8ce8c090 | 690 | #ifdef BFD_HOST_64_BIT |
edeb6e24 | 691 | const bfd_byte *addr = p; |
8ce8c090 | 692 | bfd_uint64_t v; |
c58b9523 AM |
693 | |
694 | v = addr[7]; v <<= 8; | |
695 | v |= addr[6]; v <<= 8; | |
696 | v |= addr[5]; v <<= 8; | |
697 | v |= addr[4]; v <<= 8; | |
698 | v |= addr[3]; v <<= 8; | |
699 | v |= addr[2]; v <<= 8; | |
700 | v |= addr[1]; v <<= 8; | |
701 | v |= addr[0]; | |
702 | ||
703 | return COERCE64 (v); | |
252b5132 RH |
704 | #else |
705 | BFD_FAIL(); | |
706 | return 0; | |
707 | #endif | |
708 | } | |
709 | ||
710 | void | |
edeb6e24 | 711 | bfd_putb32 (bfd_vma data, void *p) |
252b5132 | 712 | { |
edeb6e24 AM |
713 | bfd_byte *addr = p; |
714 | addr[0] = (data >> 24) & 0xff; | |
715 | addr[1] = (data >> 16) & 0xff; | |
716 | addr[2] = (data >> 8) & 0xff; | |
717 | addr[3] = data & 0xff; | |
252b5132 RH |
718 | } |
719 | ||
720 | void | |
edeb6e24 | 721 | bfd_putl32 (bfd_vma data, void *p) |
252b5132 | 722 | { |
edeb6e24 AM |
723 | bfd_byte *addr = p; |
724 | addr[0] = data & 0xff; | |
725 | addr[1] = (data >> 8) & 0xff; | |
726 | addr[2] = (data >> 16) & 0xff; | |
727 | addr[3] = (data >> 24) & 0xff; | |
252b5132 RH |
728 | } |
729 | ||
730 | void | |
8ce8c090 | 731 | bfd_putb64 (bfd_uint64_t data ATTRIBUTE_UNUSED, void *p ATTRIBUTE_UNUSED) |
252b5132 | 732 | { |
8ce8c090 | 733 | #ifdef BFD_HOST_64_BIT |
edeb6e24 AM |
734 | bfd_byte *addr = p; |
735 | addr[0] = (data >> (7*8)) & 0xff; | |
736 | addr[1] = (data >> (6*8)) & 0xff; | |
737 | addr[2] = (data >> (5*8)) & 0xff; | |
738 | addr[3] = (data >> (4*8)) & 0xff; | |
739 | addr[4] = (data >> (3*8)) & 0xff; | |
740 | addr[5] = (data >> (2*8)) & 0xff; | |
741 | addr[6] = (data >> (1*8)) & 0xff; | |
742 | addr[7] = (data >> (0*8)) & 0xff; | |
252b5132 RH |
743 | #else |
744 | BFD_FAIL(); | |
745 | #endif | |
746 | } | |
747 | ||
748 | void | |
8ce8c090 | 749 | bfd_putl64 (bfd_uint64_t data ATTRIBUTE_UNUSED, void *p ATTRIBUTE_UNUSED) |
252b5132 | 750 | { |
8ce8c090 | 751 | #ifdef BFD_HOST_64_BIT |
edeb6e24 AM |
752 | bfd_byte *addr = p; |
753 | addr[7] = (data >> (7*8)) & 0xff; | |
754 | addr[6] = (data >> (6*8)) & 0xff; | |
755 | addr[5] = (data >> (5*8)) & 0xff; | |
756 | addr[4] = (data >> (4*8)) & 0xff; | |
757 | addr[3] = (data >> (3*8)) & 0xff; | |
758 | addr[2] = (data >> (2*8)) & 0xff; | |
759 | addr[1] = (data >> (1*8)) & 0xff; | |
760 | addr[0] = (data >> (0*8)) & 0xff; | |
252b5132 RH |
761 | #else |
762 | BFD_FAIL(); | |
763 | #endif | |
764 | } | |
8c603c85 NC |
765 | |
766 | void | |
8ce8c090 | 767 | bfd_put_bits (bfd_uint64_t data, void *p, int bits, bfd_boolean big_p) |
8c603c85 | 768 | { |
edeb6e24 | 769 | bfd_byte *addr = p; |
8c603c85 NC |
770 | int i; |
771 | int bytes; | |
772 | ||
773 | if (bits % 8 != 0) | |
774 | abort (); | |
775 | ||
776 | bytes = bits / 8; | |
777 | for (i = 0; i < bytes; i++) | |
778 | { | |
779 | int index = big_p ? bytes - i - 1 : i; | |
780 | ||
edeb6e24 | 781 | addr[index] = data & 0xff; |
8c603c85 NC |
782 | data >>= 8; |
783 | } | |
784 | } | |
785 | ||
8ce8c090 | 786 | bfd_uint64_t |
edeb6e24 | 787 | bfd_get_bits (const void *p, int bits, bfd_boolean big_p) |
8c603c85 | 788 | { |
edeb6e24 | 789 | const bfd_byte *addr = p; |
8ce8c090 | 790 | bfd_uint64_t data; |
8c603c85 NC |
791 | int i; |
792 | int bytes; | |
793 | ||
794 | if (bits % 8 != 0) | |
795 | abort (); | |
796 | ||
797 | data = 0; | |
798 | bytes = bits / 8; | |
799 | for (i = 0; i < bytes; i++) | |
800 | { | |
801 | int index = big_p ? i : bytes - i - 1; | |
509945ae | 802 | |
8c603c85 NC |
803 | data = (data << 8) | addr[index]; |
804 | } | |
805 | ||
806 | return data; | |
807 | } | |
252b5132 RH |
808 | \f |
809 | /* Default implementation */ | |
810 | ||
b34976b6 | 811 | bfd_boolean |
c58b9523 AM |
812 | _bfd_generic_get_section_contents (bfd *abfd, |
813 | sec_ptr section, | |
814 | void *location, | |
815 | file_ptr offset, | |
816 | bfd_size_type count) | |
252b5132 | 817 | { |
eea6121a | 818 | bfd_size_type sz; |
0bff3f4b | 819 | if (count == 0) |
b34976b6 | 820 | return TRUE; |
0bff3f4b | 821 | |
eea6121a AM |
822 | sz = section->rawsize ? section->rawsize : section->size; |
823 | if (offset + count > sz) | |
0bff3f4b ILT |
824 | { |
825 | bfd_set_error (bfd_error_invalid_operation); | |
b34976b6 | 826 | return FALSE; |
0bff3f4b ILT |
827 | } |
828 | ||
829 | if (bfd_seek (abfd, section->filepos + offset, SEEK_SET) != 0 | |
dc810e39 | 830 | || bfd_bread (location, count, abfd) != count) |
b34976b6 | 831 | return FALSE; |
0bff3f4b | 832 | |
b34976b6 | 833 | return TRUE; |
252b5132 RH |
834 | } |
835 | ||
b34976b6 | 836 | bfd_boolean |
c58b9523 AM |
837 | _bfd_generic_get_section_contents_in_window |
838 | (bfd *abfd ATTRIBUTE_UNUSED, | |
839 | sec_ptr section ATTRIBUTE_UNUSED, | |
840 | bfd_window *w ATTRIBUTE_UNUSED, | |
841 | file_ptr offset ATTRIBUTE_UNUSED, | |
842 | bfd_size_type count ATTRIBUTE_UNUSED) | |
252b5132 RH |
843 | { |
844 | #ifdef USE_MMAP | |
eea6121a AM |
845 | bfd_size_type sz; |
846 | ||
252b5132 | 847 | if (count == 0) |
b34976b6 | 848 | return TRUE; |
c58b9523 AM |
849 | if (abfd->xvec->_bfd_get_section_contents |
850 | != _bfd_generic_get_section_contents) | |
252b5132 RH |
851 | { |
852 | /* We don't know what changes the bfd's get_section_contents | |
853 | method may have to make. So punt trying to map the file | |
854 | window, and let get_section_contents do its thing. */ | |
855 | /* @@ FIXME : If the internal window has a refcount of 1 and was | |
856 | allocated with malloc instead of mmap, just reuse it. */ | |
857 | bfd_free_window (w); | |
c58b9523 | 858 | w->i = bfd_zmalloc (sizeof (bfd_window_internal)); |
252b5132 | 859 | if (w->i == NULL) |
b34976b6 | 860 | return FALSE; |
c58b9523 | 861 | w->i->data = bfd_malloc (count); |
252b5132 RH |
862 | if (w->i->data == NULL) |
863 | { | |
864 | free (w->i); | |
865 | w->i = NULL; | |
b34976b6 | 866 | return FALSE; |
252b5132 RH |
867 | } |
868 | w->i->mapped = 0; | |
869 | w->i->refcount = 1; | |
870 | w->size = w->i->size = count; | |
871 | w->data = w->i->data; | |
872 | return bfd_get_section_contents (abfd, section, w->data, offset, count); | |
873 | } | |
eea6121a AM |
874 | sz = section->rawsize ? section->rawsize : section->size; |
875 | if (offset + count > sz | |
82e51918 | 876 | || ! bfd_get_file_window (abfd, section->filepos + offset, count, w, |
b34976b6 AM |
877 | TRUE)) |
878 | return FALSE; | |
879 | return TRUE; | |
252b5132 RH |
880 | #else |
881 | abort (); | |
882 | #endif | |
883 | } | |
884 | ||
885 | /* This generic function can only be used in implementations where creating | |
886 | NEW sections is disallowed. It is useful in patching existing sections | |
887 | in read-write files, though. See other set_section_contents functions | |
888 | to see why it doesn't work for new sections. */ | |
b34976b6 | 889 | bfd_boolean |
c58b9523 AM |
890 | _bfd_generic_set_section_contents (bfd *abfd, |
891 | sec_ptr section, | |
0f867abe | 892 | const void *location, |
c58b9523 AM |
893 | file_ptr offset, |
894 | bfd_size_type count) | |
252b5132 RH |
895 | { |
896 | if (count == 0) | |
b34976b6 | 897 | return TRUE; |
252b5132 | 898 | |
dc810e39 AM |
899 | if (bfd_seek (abfd, section->filepos + offset, SEEK_SET) != 0 |
900 | || bfd_bwrite (location, count, abfd) != count) | |
b34976b6 | 901 | return FALSE; |
252b5132 | 902 | |
b34976b6 | 903 | return TRUE; |
252b5132 RH |
904 | } |
905 | ||
906 | /* | |
907 | INTERNAL_FUNCTION | |
908 | bfd_log2 | |
909 | ||
910 | SYNOPSIS | |
dc810e39 | 911 | unsigned int bfd_log2 (bfd_vma x); |
252b5132 RH |
912 | |
913 | DESCRIPTION | |
914 | Return the log base 2 of the value supplied, rounded up. E.g., an | |
dc810e39 | 915 | @var{x} of 1025 returns 11. A @var{x} of 0 returns 0. |
252b5132 RH |
916 | */ |
917 | ||
918 | unsigned int | |
c58b9523 | 919 | bfd_log2 (bfd_vma x) |
252b5132 RH |
920 | { |
921 | unsigned int result = 0; | |
922 | ||
86b21447 | 923 | while ((x = (x >> 1)) != 0) |
252b5132 RH |
924 | ++result; |
925 | return result; | |
926 | } | |
927 | ||
b34976b6 | 928 | bfd_boolean |
c58b9523 | 929 | bfd_generic_is_local_label_name (bfd *abfd, const char *name) |
252b5132 RH |
930 | { |
931 | char locals_prefix = (bfd_get_symbol_leading_char (abfd) == '_') ? 'L' : '.'; | |
932 | ||
b34976b6 | 933 | return name[0] == locals_prefix; |
252b5132 RH |
934 | } |
935 | ||
875f7f69 JR |
936 | /* Can be used from / for bfd_merge_private_bfd_data to check that |
937 | endianness matches between input and output file. Returns | |
b34976b6 AM |
938 | TRUE for a match, otherwise returns FALSE and emits an error. */ |
939 | bfd_boolean | |
c58b9523 | 940 | _bfd_generic_verify_endian_match (bfd *ibfd, bfd *obfd) |
875f7f69 JR |
941 | { |
942 | if (ibfd->xvec->byteorder != obfd->xvec->byteorder | |
1fe494a5 | 943 | && ibfd->xvec->byteorder != BFD_ENDIAN_UNKNOWN |
875f7f69 JR |
944 | && obfd->xvec->byteorder != BFD_ENDIAN_UNKNOWN) |
945 | { | |
1fe494a5 NC |
946 | const char *msg; |
947 | ||
948 | if (bfd_big_endian (ibfd)) | |
d003868e | 949 | msg = _("%B: compiled for a big endian system and target is little endian"); |
1fe494a5 | 950 | else |
d003868e | 951 | msg = _("%B: compiled for a little endian system and target is big endian"); |
1fe494a5 | 952 | |
d003868e | 953 | (*_bfd_error_handler) (msg, ibfd); |
875f7f69 JR |
954 | |
955 | bfd_set_error (bfd_error_wrong_format); | |
b34976b6 | 956 | return FALSE; |
875f7f69 JR |
957 | } |
958 | ||
b34976b6 | 959 | return TRUE; |
875f7f69 | 960 | } |
dc810e39 AM |
961 | |
962 | /* Give a warning at runtime if someone compiles code which calls | |
963 | old routines. */ | |
ca09e32b | 964 | |
dc810e39 | 965 | void |
c58b9523 AM |
966 | warn_deprecated (const char *what, |
967 | const char *file, | |
968 | int line, | |
969 | const char *func) | |
dc810e39 AM |
970 | { |
971 | /* Poor man's tracking of functions we've already warned about. */ | |
972 | static size_t mask = 0; | |
973 | ||
974 | if (~(size_t) func & ~mask) | |
975 | { | |
73722af0 | 976 | /* Note: separate sentences in order to allow |
ca09e32b | 977 | for translation into other languages. */ |
dc810e39 | 978 | if (func) |
ca09e32b NC |
979 | fprintf (stderr, _("Deprecated %s called at %s line %d in %s\n"), |
980 | what, file, line, func); | |
dc810e39 | 981 | else |
ca09e32b | 982 | fprintf (stderr, _("Deprecated %s called\n"), what); |
dc810e39 AM |
983 | mask |= ~(size_t) func; |
984 | } | |
985 | } | |
c0c28ab8 L |
986 | |
987 | /* Helper function for reading uleb128 encoded data. */ | |
988 | ||
989 | bfd_vma | |
990 | read_unsigned_leb128 (bfd *abfd ATTRIBUTE_UNUSED, | |
f075ee0c | 991 | bfd_byte *buf, |
c0c28ab8 L |
992 | unsigned int *bytes_read_ptr) |
993 | { | |
994 | bfd_vma result; | |
995 | unsigned int num_read; | |
f075ee0c | 996 | unsigned int shift; |
c0c28ab8 L |
997 | unsigned char byte; |
998 | ||
999 | result = 0; | |
1000 | shift = 0; | |
1001 | num_read = 0; | |
1002 | do | |
1003 | { | |
f075ee0c | 1004 | byte = bfd_get_8 (abfd, buf); |
c0c28ab8 L |
1005 | buf++; |
1006 | num_read++; | |
1007 | result |= (((bfd_vma) byte & 0x7f) << shift); | |
1008 | shift += 7; | |
1009 | } | |
1010 | while (byte & 0x80); | |
1011 | *bytes_read_ptr = num_read; | |
1012 | return result; | |
1013 | } | |
1014 | ||
1015 | /* Helper function for reading sleb128 encoded data. */ | |
1016 | ||
1017 | bfd_signed_vma | |
1018 | read_signed_leb128 (bfd *abfd ATTRIBUTE_UNUSED, | |
f075ee0c AM |
1019 | bfd_byte *buf, |
1020 | unsigned int *bytes_read_ptr) | |
c0c28ab8 L |
1021 | { |
1022 | bfd_vma result; | |
f075ee0c AM |
1023 | unsigned int shift; |
1024 | unsigned int num_read; | |
c0c28ab8 L |
1025 | unsigned char byte; |
1026 | ||
1027 | result = 0; | |
1028 | shift = 0; | |
1029 | num_read = 0; | |
1030 | do | |
1031 | { | |
f075ee0c | 1032 | byte = bfd_get_8 (abfd, buf); |
c0c28ab8 L |
1033 | buf ++; |
1034 | num_read ++; | |
1035 | result |= (((bfd_vma) byte & 0x7f) << shift); | |
1036 | shift += 7; | |
1037 | } | |
1038 | while (byte & 0x80); | |
f075ee0c | 1039 | if (shift < 8 * sizeof (result) && (byte & 0x40)) |
c0c28ab8 L |
1040 | result |= (((bfd_vma) -1) << shift); |
1041 | *bytes_read_ptr = num_read; | |
1042 | return result; | |
1043 | } | |
5420f73d L |
1044 | |
1045 | bfd_boolean | |
1046 | _bfd_generic_find_line (bfd *abfd ATTRIBUTE_UNUSED, | |
1047 | asymbol **symbols ATTRIBUTE_UNUSED, | |
1048 | asymbol *symbol ATTRIBUTE_UNUSED, | |
1049 | const char **filename_ptr ATTRIBUTE_UNUSED, | |
1050 | unsigned int *linenumber_ptr ATTRIBUTE_UNUSED) | |
1051 | { | |
1052 | return FALSE; | |
1053 | } | |
ecca9871 | 1054 | |
ccd2ec6a L |
1055 | bfd_boolean |
1056 | _bfd_generic_init_private_section_data (bfd *ibfd ATTRIBUTE_UNUSED, | |
1057 | asection *isec ATTRIBUTE_UNUSED, | |
1058 | bfd *obfd ATTRIBUTE_UNUSED, | |
1059 | asection *osec ATTRIBUTE_UNUSED, | |
1060 | struct bfd_link_info *link_info ATTRIBUTE_UNUSED) | |
1061 | { | |
1062 | return TRUE; | |
1063 | } |