]>
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, |
4a97a0e5 | 3 | 2000, 2001, 2002, 2003, 2004, 2005, 2007, 2008, 2009, 2010, 2011 |
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 | ||
261b8d08 PA |
153 | /* Routine to handle the core_file_pid entry point for targets without |
154 | core file support. */ | |
155 | ||
156 | int | |
157 | _bfd_nocore_core_file_pid (bfd *ignore_abfd ATTRIBUTE_UNUSED) | |
158 | { | |
159 | bfd_set_error (bfd_error_invalid_operation); | |
160 | return 0; | |
161 | } | |
162 | ||
252b5132 | 163 | const bfd_target * |
c58b9523 | 164 | _bfd_dummy_target (bfd *ignore_abfd ATTRIBUTE_UNUSED) |
252b5132 RH |
165 | { |
166 | bfd_set_error (bfd_error_wrong_format); | |
167 | return 0; | |
168 | } | |
169 | \f | |
170 | /* Allocate memory using malloc. */ | |
171 | ||
c58b9523 AM |
172 | void * |
173 | bfd_malloc (bfd_size_type size) | |
252b5132 | 174 | { |
c58b9523 | 175 | void *ptr; |
252b5132 | 176 | |
dc810e39 AM |
177 | if (size != (size_t) size) |
178 | { | |
179 | bfd_set_error (bfd_error_no_memory); | |
180 | return NULL; | |
181 | } | |
182 | ||
c58b9523 | 183 | ptr = malloc ((size_t) size); |
dc810e39 | 184 | if (ptr == NULL && (size_t) size != 0) |
252b5132 | 185 | bfd_set_error (bfd_error_no_memory); |
dc810e39 | 186 | |
252b5132 RH |
187 | return ptr; |
188 | } | |
189 | ||
d0fb9a8d JJ |
190 | /* Allocate memory using malloc, nmemb * size with overflow checking. */ |
191 | ||
192 | void * | |
193 | bfd_malloc2 (bfd_size_type nmemb, bfd_size_type size) | |
194 | { | |
195 | void *ptr; | |
196 | ||
197 | if ((nmemb | size) >= HALF_BFD_SIZE_TYPE | |
198 | && size != 0 | |
199 | && nmemb > ~(bfd_size_type) 0 / size) | |
200 | { | |
201 | bfd_set_error (bfd_error_no_memory); | |
202 | return NULL; | |
203 | } | |
204 | ||
205 | size *= nmemb; | |
206 | ||
207 | if (size != (size_t) size) | |
208 | { | |
209 | bfd_set_error (bfd_error_no_memory); | |
210 | return NULL; | |
211 | } | |
212 | ||
213 | ptr = malloc ((size_t) size); | |
214 | if (ptr == NULL && (size_t) size != 0) | |
215 | bfd_set_error (bfd_error_no_memory); | |
216 | ||
217 | return ptr; | |
218 | } | |
219 | ||
252b5132 RH |
220 | /* Reallocate memory using realloc. */ |
221 | ||
c58b9523 AM |
222 | void * |
223 | bfd_realloc (void *ptr, bfd_size_type size) | |
252b5132 | 224 | { |
c58b9523 | 225 | void *ret; |
252b5132 | 226 | |
dc810e39 AM |
227 | if (size != (size_t) size) |
228 | { | |
229 | bfd_set_error (bfd_error_no_memory); | |
230 | return NULL; | |
231 | } | |
232 | ||
252b5132 | 233 | if (ptr == NULL) |
c58b9523 | 234 | ret = malloc ((size_t) size); |
252b5132 | 235 | else |
c58b9523 | 236 | ret = realloc (ptr, (size_t) size); |
252b5132 | 237 | |
dc810e39 | 238 | if (ret == NULL && (size_t) size != 0) |
252b5132 RH |
239 | bfd_set_error (bfd_error_no_memory); |
240 | ||
241 | return ret; | |
242 | } | |
243 | ||
d0fb9a8d JJ |
244 | /* Reallocate memory using realloc, nmemb * size with overflow checking. */ |
245 | ||
246 | void * | |
247 | bfd_realloc2 (void *ptr, bfd_size_type nmemb, bfd_size_type size) | |
248 | { | |
249 | void *ret; | |
250 | ||
251 | if ((nmemb | size) >= HALF_BFD_SIZE_TYPE | |
252 | && size != 0 | |
253 | && nmemb > ~(bfd_size_type) 0 / size) | |
254 | { | |
255 | bfd_set_error (bfd_error_no_memory); | |
256 | return NULL; | |
257 | } | |
258 | ||
259 | size *= nmemb; | |
260 | ||
261 | if (size != (size_t) size) | |
262 | { | |
263 | bfd_set_error (bfd_error_no_memory); | |
264 | return NULL; | |
265 | } | |
266 | ||
267 | if (ptr == NULL) | |
268 | ret = malloc ((size_t) size); | |
269 | else | |
270 | ret = realloc (ptr, (size_t) size); | |
271 | ||
272 | if (ret == NULL && (size_t) size != 0) | |
273 | bfd_set_error (bfd_error_no_memory); | |
274 | ||
275 | return ret; | |
276 | } | |
277 | ||
515ef31d NC |
278 | /* Reallocate memory using realloc. |
279 | If this fails the pointer is freed before returning. */ | |
280 | ||
281 | void * | |
282 | bfd_realloc_or_free (void *ptr, bfd_size_type size) | |
283 | { | |
284 | size_t amount = (size_t) size; | |
285 | void *ret; | |
286 | ||
287 | if (size != amount) | |
288 | ret = NULL; | |
289 | else if (ptr == NULL) | |
290 | ret = malloc (amount); | |
291 | else | |
292 | ret = realloc (ptr, amount); | |
293 | ||
294 | if (ret == NULL) | |
295 | { | |
296 | if (amount > 0) | |
297 | bfd_set_error (bfd_error_no_memory); | |
298 | ||
299 | if (ptr != NULL) | |
300 | free (ptr); | |
301 | } | |
302 | ||
303 | return ret; | |
304 | } | |
305 | ||
252b5132 RH |
306 | /* Allocate memory using malloc and clear it. */ |
307 | ||
c58b9523 AM |
308 | void * |
309 | bfd_zmalloc (bfd_size_type size) | |
252b5132 | 310 | { |
c58b9523 | 311 | void *ptr; |
252b5132 | 312 | |
dc810e39 AM |
313 | if (size != (size_t) size) |
314 | { | |
315 | bfd_set_error (bfd_error_no_memory); | |
316 | return NULL; | |
317 | } | |
252b5132 | 318 | |
c58b9523 | 319 | ptr = malloc ((size_t) size); |
dc810e39 AM |
320 | |
321 | if ((size_t) size != 0) | |
252b5132 RH |
322 | { |
323 | if (ptr == NULL) | |
324 | bfd_set_error (bfd_error_no_memory); | |
325 | else | |
dc810e39 | 326 | memset (ptr, 0, (size_t) size); |
252b5132 RH |
327 | } |
328 | ||
329 | return ptr; | |
330 | } | |
d0fb9a8d JJ |
331 | |
332 | /* Allocate memory using malloc (nmemb * size) with overflow checking | |
333 | and clear it. */ | |
334 | ||
335 | void * | |
336 | bfd_zmalloc2 (bfd_size_type nmemb, bfd_size_type size) | |
337 | { | |
338 | void *ptr; | |
339 | ||
340 | if ((nmemb | size) >= HALF_BFD_SIZE_TYPE | |
341 | && size != 0 | |
342 | && nmemb > ~(bfd_size_type) 0 / size) | |
343 | { | |
344 | bfd_set_error (bfd_error_no_memory); | |
345 | return NULL; | |
346 | } | |
347 | ||
348 | size *= nmemb; | |
349 | ||
350 | if (size != (size_t) size) | |
351 | { | |
352 | bfd_set_error (bfd_error_no_memory); | |
353 | return NULL; | |
354 | } | |
355 | ||
356 | ptr = malloc ((size_t) size); | |
357 | ||
358 | if ((size_t) size != 0) | |
359 | { | |
360 | if (ptr == NULL) | |
361 | bfd_set_error (bfd_error_no_memory); | |
362 | else | |
363 | memset (ptr, 0, (size_t) size); | |
364 | } | |
365 | ||
366 | return ptr; | |
367 | } | |
368 | ||
252b5132 RH |
369 | /* |
370 | INTERNAL_FUNCTION | |
371 | bfd_write_bigendian_4byte_int | |
372 | ||
373 | SYNOPSIS | |
b34976b6 | 374 | bfd_boolean bfd_write_bigendian_4byte_int (bfd *, unsigned int); |
252b5132 RH |
375 | |
376 | DESCRIPTION | |
377 | Write a 4 byte integer @var{i} to the output BFD @var{abfd}, in big | |
378 | endian order regardless of what else is going on. This is useful in | |
379 | archives. | |
380 | ||
381 | */ | |
b34976b6 | 382 | bfd_boolean |
c58b9523 | 383 | bfd_write_bigendian_4byte_int (bfd *abfd, unsigned int i) |
252b5132 RH |
384 | { |
385 | bfd_byte buffer[4]; | |
dc810e39 | 386 | bfd_putb32 ((bfd_vma) i, buffer); |
c58b9523 | 387 | return bfd_bwrite (buffer, (bfd_size_type) 4, abfd) == 4; |
252b5132 RH |
388 | } |
389 | ||
252b5132 RH |
390 | \f |
391 | /** The do-it-yourself (byte) sex-change kit */ | |
392 | ||
393 | /* The middle letter e.g. get<b>short indicates Big or Little endian | |
394 | target machine. It doesn't matter what the byte order of the host | |
395 | machine is; these routines work for either. */ | |
396 | ||
397 | /* FIXME: Should these take a count argument? | |
398 | Answer ([email protected]): No, but perhaps they should be inline | |
509945ae | 399 | functions in swap.h #ifdef __GNUC__. |
252b5132 RH |
400 | Gprof them later and find out. */ |
401 | ||
402 | /* | |
403 | FUNCTION | |
404 | bfd_put_size | |
405 | FUNCTION | |
406 | bfd_get_size | |
407 | ||
408 | DESCRIPTION | |
409 | These macros as used for reading and writing raw data in | |
410 | sections; each access (except for bytes) is vectored through | |
411 | the target format of the BFD and mangled accordingly. The | |
412 | mangling performs any necessary endian translations and | |
413 | removes alignment restrictions. Note that types accepted and | |
414 | returned by these macros are identical so they can be swapped | |
415 | around in macros---for example, @file{libaout.h} defines <<GET_WORD>> | |
416 | to either <<bfd_get_32>> or <<bfd_get_64>>. | |
417 | ||
418 | In the put routines, @var{val} must be a <<bfd_vma>>. If we are on a | |
419 | system without prototypes, the caller is responsible for making | |
420 | sure that is true, with a cast if necessary. We don't cast | |
421 | them in the macro definitions because that would prevent <<lint>> | |
422 | or <<gcc -Wall>> from detecting sins such as passing a pointer. | |
423 | To detect calling these with less than a <<bfd_vma>>, use | |
424 | <<gcc -Wconversion>> on a host with 64 bit <<bfd_vma>>'s. | |
425 | ||
426 | . | |
427 | .{* Byte swapping macros for user section data. *} | |
428 | . | |
429 | .#define bfd_put_8(abfd, val, ptr) \ | |
edeb6e24 | 430 | . ((void) (*((unsigned char *) (ptr)) = (val) & 0xff)) |
252b5132 | 431 | .#define bfd_put_signed_8 \ |
c58b9523 | 432 | . bfd_put_8 |
252b5132 | 433 | .#define bfd_get_8(abfd, ptr) \ |
70778fc7 | 434 | . (*(const unsigned char *) (ptr) & 0xff) |
252b5132 | 435 | .#define bfd_get_signed_8(abfd, ptr) \ |
70778fc7 | 436 | . (((*(const unsigned char *) (ptr) & 0xff) ^ 0x80) - 0x80) |
252b5132 RH |
437 | . |
438 | .#define bfd_put_16(abfd, val, ptr) \ | |
c58b9523 | 439 | . BFD_SEND (abfd, bfd_putx16, ((val),(ptr))) |
252b5132 | 440 | .#define bfd_put_signed_16 \ |
c58b9523 | 441 | . bfd_put_16 |
252b5132 | 442 | .#define bfd_get_16(abfd, ptr) \ |
c58b9523 | 443 | . BFD_SEND (abfd, bfd_getx16, (ptr)) |
252b5132 | 444 | .#define bfd_get_signed_16(abfd, ptr) \ |
c58b9523 | 445 | . BFD_SEND (abfd, bfd_getx_signed_16, (ptr)) |
252b5132 RH |
446 | . |
447 | .#define bfd_put_32(abfd, val, ptr) \ | |
c58b9523 | 448 | . BFD_SEND (abfd, bfd_putx32, ((val),(ptr))) |
252b5132 | 449 | .#define bfd_put_signed_32 \ |
c58b9523 | 450 | . bfd_put_32 |
252b5132 | 451 | .#define bfd_get_32(abfd, ptr) \ |
c58b9523 | 452 | . BFD_SEND (abfd, bfd_getx32, (ptr)) |
252b5132 | 453 | .#define bfd_get_signed_32(abfd, ptr) \ |
c58b9523 | 454 | . BFD_SEND (abfd, bfd_getx_signed_32, (ptr)) |
252b5132 RH |
455 | . |
456 | .#define bfd_put_64(abfd, val, ptr) \ | |
c58b9523 | 457 | . BFD_SEND (abfd, bfd_putx64, ((val), (ptr))) |
252b5132 | 458 | .#define bfd_put_signed_64 \ |
c58b9523 | 459 | . bfd_put_64 |
252b5132 | 460 | .#define bfd_get_64(abfd, ptr) \ |
c58b9523 | 461 | . BFD_SEND (abfd, bfd_getx64, (ptr)) |
252b5132 | 462 | .#define bfd_get_signed_64(abfd, ptr) \ |
c58b9523 | 463 | . BFD_SEND (abfd, bfd_getx_signed_64, (ptr)) |
252b5132 | 464 | . |
c58b9523 AM |
465 | .#define bfd_get(bits, abfd, ptr) \ |
466 | . ((bits) == 8 ? (bfd_vma) bfd_get_8 (abfd, ptr) \ | |
467 | . : (bits) == 16 ? bfd_get_16 (abfd, ptr) \ | |
468 | . : (bits) == 32 ? bfd_get_32 (abfd, ptr) \ | |
469 | . : (bits) == 64 ? bfd_get_64 (abfd, ptr) \ | |
470 | . : (abort (), (bfd_vma) - 1)) | |
c7ac6ff8 | 471 | . |
c58b9523 AM |
472 | .#define bfd_put(bits, abfd, val, ptr) \ |
473 | . ((bits) == 8 ? bfd_put_8 (abfd, val, ptr) \ | |
474 | . : (bits) == 16 ? bfd_put_16 (abfd, val, ptr) \ | |
475 | . : (bits) == 32 ? bfd_put_32 (abfd, val, ptr) \ | |
476 | . : (bits) == 64 ? bfd_put_64 (abfd, val, ptr) \ | |
477 | . : (abort (), (void) 0)) | |
c7ac6ff8 | 478 | . |
509945ae | 479 | */ |
252b5132 RH |
480 | |
481 | /* | |
482 | FUNCTION | |
483 | bfd_h_put_size | |
484 | bfd_h_get_size | |
485 | ||
486 | DESCRIPTION | |
487 | These macros have the same function as their <<bfd_get_x>> | |
dc810e39 | 488 | brethren, except that they are used for removing information |
252b5132 RH |
489 | for the header records of object files. Believe it or not, |
490 | some object files keep their header records in big endian | |
491 | order and their data in little endian order. | |
492 | . | |
493 | .{* Byte swapping macros for file header data. *} | |
494 | . | |
495 | .#define bfd_h_put_8(abfd, val, ptr) \ | |
dc810e39 | 496 | . bfd_put_8 (abfd, val, ptr) |
252b5132 | 497 | .#define bfd_h_put_signed_8(abfd, val, ptr) \ |
dc810e39 | 498 | . bfd_put_8 (abfd, val, ptr) |
252b5132 | 499 | .#define bfd_h_get_8(abfd, ptr) \ |
dc810e39 | 500 | . bfd_get_8 (abfd, ptr) |
252b5132 | 501 | .#define bfd_h_get_signed_8(abfd, ptr) \ |
dc810e39 | 502 | . bfd_get_signed_8 (abfd, ptr) |
252b5132 RH |
503 | . |
504 | .#define bfd_h_put_16(abfd, val, ptr) \ | |
dc810e39 | 505 | . BFD_SEND (abfd, bfd_h_putx16, (val, ptr)) |
252b5132 | 506 | .#define bfd_h_put_signed_16 \ |
dc810e39 | 507 | . bfd_h_put_16 |
252b5132 | 508 | .#define bfd_h_get_16(abfd, ptr) \ |
dc810e39 | 509 | . BFD_SEND (abfd, bfd_h_getx16, (ptr)) |
252b5132 | 510 | .#define bfd_h_get_signed_16(abfd, ptr) \ |
dc810e39 | 511 | . BFD_SEND (abfd, bfd_h_getx_signed_16, (ptr)) |
252b5132 RH |
512 | . |
513 | .#define bfd_h_put_32(abfd, val, ptr) \ | |
dc810e39 | 514 | . BFD_SEND (abfd, bfd_h_putx32, (val, ptr)) |
252b5132 | 515 | .#define bfd_h_put_signed_32 \ |
dc810e39 | 516 | . bfd_h_put_32 |
252b5132 | 517 | .#define bfd_h_get_32(abfd, ptr) \ |
dc810e39 | 518 | . BFD_SEND (abfd, bfd_h_getx32, (ptr)) |
252b5132 | 519 | .#define bfd_h_get_signed_32(abfd, ptr) \ |
dc810e39 | 520 | . BFD_SEND (abfd, bfd_h_getx_signed_32, (ptr)) |
252b5132 RH |
521 | . |
522 | .#define bfd_h_put_64(abfd, val, ptr) \ | |
dc810e39 | 523 | . BFD_SEND (abfd, bfd_h_putx64, (val, ptr)) |
252b5132 | 524 | .#define bfd_h_put_signed_64 \ |
dc810e39 | 525 | . bfd_h_put_64 |
252b5132 | 526 | .#define bfd_h_get_64(abfd, ptr) \ |
dc810e39 | 527 | . BFD_SEND (abfd, bfd_h_getx64, (ptr)) |
252b5132 | 528 | .#define bfd_h_get_signed_64(abfd, ptr) \ |
dc810e39 | 529 | . BFD_SEND (abfd, bfd_h_getx_signed_64, (ptr)) |
252b5132 | 530 | . |
edeb6e24 | 531 | .{* Aliases for the above, which should eventually go away. *} |
dc810e39 | 532 | . |
edeb6e24 AM |
533 | .#define H_PUT_64 bfd_h_put_64 |
534 | .#define H_PUT_32 bfd_h_put_32 | |
535 | .#define H_PUT_16 bfd_h_put_16 | |
536 | .#define H_PUT_8 bfd_h_put_8 | |
537 | .#define H_PUT_S64 bfd_h_put_signed_64 | |
538 | .#define H_PUT_S32 bfd_h_put_signed_32 | |
539 | .#define H_PUT_S16 bfd_h_put_signed_16 | |
540 | .#define H_PUT_S8 bfd_h_put_signed_8 | |
541 | .#define H_GET_64 bfd_h_get_64 | |
542 | .#define H_GET_32 bfd_h_get_32 | |
543 | .#define H_GET_16 bfd_h_get_16 | |
544 | .#define H_GET_8 bfd_h_get_8 | |
545 | .#define H_GET_S64 bfd_h_get_signed_64 | |
546 | .#define H_GET_S32 bfd_h_get_signed_32 | |
547 | .#define H_GET_S16 bfd_h_get_signed_16 | |
548 | .#define H_GET_S8 bfd_h_get_signed_8 | |
dc810e39 AM |
549 | . |
550 | .*/ | |
252b5132 RH |
551 | |
552 | /* Sign extension to bfd_signed_vma. */ | |
553 | #define COERCE16(x) (((bfd_signed_vma) (x) ^ 0x8000) - 0x8000) | |
c58b9523 | 554 | #define COERCE32(x) (((bfd_signed_vma) (x) ^ 0x80000000) - 0x80000000) |
8ce8c090 | 555 | #define EIGHT_GAZILLION ((bfd_int64_t) 1 << 63) |
252b5132 | 556 | #define COERCE64(x) \ |
8ce8c090 | 557 | (((bfd_int64_t) (x) ^ EIGHT_GAZILLION) - EIGHT_GAZILLION) |
252b5132 RH |
558 | |
559 | bfd_vma | |
edeb6e24 | 560 | bfd_getb16 (const void *p) |
252b5132 | 561 | { |
a50b1753 | 562 | const bfd_byte *addr = (const bfd_byte *) p; |
252b5132 RH |
563 | return (addr[0] << 8) | addr[1]; |
564 | } | |
565 | ||
566 | bfd_vma | |
edeb6e24 | 567 | bfd_getl16 (const void *p) |
252b5132 | 568 | { |
a50b1753 | 569 | const bfd_byte *addr = (const bfd_byte *) p; |
252b5132 RH |
570 | return (addr[1] << 8) | addr[0]; |
571 | } | |
572 | ||
573 | bfd_signed_vma | |
edeb6e24 | 574 | bfd_getb_signed_16 (const void *p) |
252b5132 | 575 | { |
a50b1753 | 576 | const bfd_byte *addr = (const bfd_byte *) p; |
c58b9523 | 577 | return COERCE16 ((addr[0] << 8) | addr[1]); |
252b5132 RH |
578 | } |
579 | ||
580 | bfd_signed_vma | |
edeb6e24 | 581 | bfd_getl_signed_16 (const void *p) |
252b5132 | 582 | { |
a50b1753 | 583 | const bfd_byte *addr = (const bfd_byte *) p; |
c58b9523 | 584 | return COERCE16 ((addr[1] << 8) | addr[0]); |
252b5132 RH |
585 | } |
586 | ||
587 | void | |
edeb6e24 | 588 | bfd_putb16 (bfd_vma data, void *p) |
252b5132 | 589 | { |
a50b1753 | 590 | bfd_byte *addr = (bfd_byte *) p; |
edeb6e24 AM |
591 | addr[0] = (data >> 8) & 0xff; |
592 | addr[1] = data & 0xff; | |
252b5132 RH |
593 | } |
594 | ||
595 | void | |
edeb6e24 | 596 | bfd_putl16 (bfd_vma data, void *p) |
252b5132 | 597 | { |
a50b1753 | 598 | bfd_byte *addr = (bfd_byte *) p; |
edeb6e24 AM |
599 | addr[0] = data & 0xff; |
600 | addr[1] = (data >> 8) & 0xff; | |
252b5132 RH |
601 | } |
602 | ||
603 | bfd_vma | |
edeb6e24 | 604 | bfd_getb32 (const void *p) |
252b5132 | 605 | { |
a50b1753 | 606 | const bfd_byte *addr = (const bfd_byte *) p; |
252b5132 RH |
607 | unsigned long v; |
608 | ||
609 | v = (unsigned long) addr[0] << 24; | |
610 | v |= (unsigned long) addr[1] << 16; | |
611 | v |= (unsigned long) addr[2] << 8; | |
612 | v |= (unsigned long) addr[3]; | |
c58b9523 | 613 | return v; |
252b5132 RH |
614 | } |
615 | ||
616 | bfd_vma | |
edeb6e24 | 617 | bfd_getl32 (const void *p) |
252b5132 | 618 | { |
a50b1753 | 619 | const bfd_byte *addr = (const bfd_byte *) p; |
252b5132 RH |
620 | unsigned long v; |
621 | ||
622 | v = (unsigned long) addr[0]; | |
623 | v |= (unsigned long) addr[1] << 8; | |
624 | v |= (unsigned long) addr[2] << 16; | |
625 | v |= (unsigned long) addr[3] << 24; | |
c58b9523 | 626 | return v; |
252b5132 RH |
627 | } |
628 | ||
629 | bfd_signed_vma | |
edeb6e24 | 630 | bfd_getb_signed_32 (const void *p) |
252b5132 | 631 | { |
a50b1753 | 632 | const bfd_byte *addr = (const bfd_byte *) p; |
252b5132 RH |
633 | unsigned long v; |
634 | ||
635 | v = (unsigned long) addr[0] << 24; | |
636 | v |= (unsigned long) addr[1] << 16; | |
637 | v |= (unsigned long) addr[2] << 8; | |
638 | v |= (unsigned long) addr[3]; | |
639 | return COERCE32 (v); | |
640 | } | |
641 | ||
642 | bfd_signed_vma | |
edeb6e24 | 643 | bfd_getl_signed_32 (const void *p) |
252b5132 | 644 | { |
a50b1753 | 645 | const bfd_byte *addr = (const bfd_byte *) p; |
252b5132 RH |
646 | unsigned long v; |
647 | ||
648 | v = (unsigned long) addr[0]; | |
649 | v |= (unsigned long) addr[1] << 8; | |
650 | v |= (unsigned long) addr[2] << 16; | |
651 | v |= (unsigned long) addr[3] << 24; | |
652 | return COERCE32 (v); | |
653 | } | |
654 | ||
8ce8c090 | 655 | bfd_uint64_t |
edeb6e24 | 656 | bfd_getb64 (const void *p ATTRIBUTE_UNUSED) |
252b5132 | 657 | { |
8ce8c090 | 658 | #ifdef BFD_HOST_64_BIT |
a50b1753 | 659 | const bfd_byte *addr = (const bfd_byte *) p; |
8ce8c090 | 660 | bfd_uint64_t v; |
c58b9523 AM |
661 | |
662 | v = addr[0]; v <<= 8; | |
663 | v |= addr[1]; v <<= 8; | |
664 | v |= addr[2]; v <<= 8; | |
665 | v |= addr[3]; v <<= 8; | |
666 | v |= addr[4]; v <<= 8; | |
667 | v |= addr[5]; v <<= 8; | |
668 | v |= addr[6]; v <<= 8; | |
669 | v |= addr[7]; | |
670 | ||
671 | return v; | |
252b5132 RH |
672 | #else |
673 | BFD_FAIL(); | |
674 | return 0; | |
675 | #endif | |
676 | } | |
677 | ||
8ce8c090 | 678 | bfd_uint64_t |
edeb6e24 | 679 | bfd_getl64 (const void *p ATTRIBUTE_UNUSED) |
252b5132 | 680 | { |
8ce8c090 | 681 | #ifdef BFD_HOST_64_BIT |
a50b1753 | 682 | const bfd_byte *addr = (const bfd_byte *) p; |
8ce8c090 | 683 | bfd_uint64_t v; |
c58b9523 AM |
684 | |
685 | v = addr[7]; v <<= 8; | |
686 | v |= addr[6]; v <<= 8; | |
687 | v |= addr[5]; v <<= 8; | |
688 | v |= addr[4]; v <<= 8; | |
689 | v |= addr[3]; v <<= 8; | |
690 | v |= addr[2]; v <<= 8; | |
691 | v |= addr[1]; v <<= 8; | |
692 | v |= addr[0]; | |
693 | ||
694 | return v; | |
252b5132 RH |
695 | #else |
696 | BFD_FAIL(); | |
697 | return 0; | |
698 | #endif | |
699 | ||
700 | } | |
701 | ||
8ce8c090 | 702 | bfd_int64_t |
edeb6e24 | 703 | bfd_getb_signed_64 (const void *p ATTRIBUTE_UNUSED) |
252b5132 | 704 | { |
8ce8c090 | 705 | #ifdef BFD_HOST_64_BIT |
a50b1753 | 706 | const bfd_byte *addr = (const bfd_byte *) p; |
8ce8c090 | 707 | bfd_uint64_t v; |
c58b9523 AM |
708 | |
709 | v = addr[0]; v <<= 8; | |
710 | v |= addr[1]; v <<= 8; | |
711 | v |= addr[2]; v <<= 8; | |
712 | v |= addr[3]; v <<= 8; | |
713 | v |= addr[4]; v <<= 8; | |
714 | v |= addr[5]; v <<= 8; | |
715 | v |= addr[6]; v <<= 8; | |
716 | v |= addr[7]; | |
717 | ||
718 | return COERCE64 (v); | |
252b5132 RH |
719 | #else |
720 | BFD_FAIL(); | |
721 | return 0; | |
722 | #endif | |
723 | } | |
724 | ||
8ce8c090 | 725 | bfd_int64_t |
edeb6e24 | 726 | bfd_getl_signed_64 (const void *p ATTRIBUTE_UNUSED) |
252b5132 | 727 | { |
8ce8c090 | 728 | #ifdef BFD_HOST_64_BIT |
a50b1753 | 729 | const bfd_byte *addr = (const bfd_byte *) p; |
8ce8c090 | 730 | bfd_uint64_t v; |
c58b9523 AM |
731 | |
732 | v = addr[7]; v <<= 8; | |
733 | v |= addr[6]; v <<= 8; | |
734 | v |= addr[5]; v <<= 8; | |
735 | v |= addr[4]; v <<= 8; | |
736 | v |= addr[3]; v <<= 8; | |
737 | v |= addr[2]; v <<= 8; | |
738 | v |= addr[1]; v <<= 8; | |
739 | v |= addr[0]; | |
740 | ||
741 | return COERCE64 (v); | |
252b5132 RH |
742 | #else |
743 | BFD_FAIL(); | |
744 | return 0; | |
745 | #endif | |
746 | } | |
747 | ||
748 | void | |
edeb6e24 | 749 | bfd_putb32 (bfd_vma data, void *p) |
252b5132 | 750 | { |
a50b1753 | 751 | bfd_byte *addr = (bfd_byte *) p; |
edeb6e24 AM |
752 | addr[0] = (data >> 24) & 0xff; |
753 | addr[1] = (data >> 16) & 0xff; | |
754 | addr[2] = (data >> 8) & 0xff; | |
755 | addr[3] = data & 0xff; | |
252b5132 RH |
756 | } |
757 | ||
758 | void | |
edeb6e24 | 759 | bfd_putl32 (bfd_vma data, void *p) |
252b5132 | 760 | { |
a50b1753 | 761 | bfd_byte *addr = (bfd_byte *) p; |
edeb6e24 AM |
762 | addr[0] = data & 0xff; |
763 | addr[1] = (data >> 8) & 0xff; | |
764 | addr[2] = (data >> 16) & 0xff; | |
765 | addr[3] = (data >> 24) & 0xff; | |
252b5132 RH |
766 | } |
767 | ||
768 | void | |
8ce8c090 | 769 | bfd_putb64 (bfd_uint64_t data ATTRIBUTE_UNUSED, void *p ATTRIBUTE_UNUSED) |
252b5132 | 770 | { |
8ce8c090 | 771 | #ifdef BFD_HOST_64_BIT |
a50b1753 | 772 | bfd_byte *addr = (bfd_byte *) p; |
edeb6e24 AM |
773 | addr[0] = (data >> (7*8)) & 0xff; |
774 | addr[1] = (data >> (6*8)) & 0xff; | |
775 | addr[2] = (data >> (5*8)) & 0xff; | |
776 | addr[3] = (data >> (4*8)) & 0xff; | |
777 | addr[4] = (data >> (3*8)) & 0xff; | |
778 | addr[5] = (data >> (2*8)) & 0xff; | |
779 | addr[6] = (data >> (1*8)) & 0xff; | |
780 | addr[7] = (data >> (0*8)) & 0xff; | |
252b5132 RH |
781 | #else |
782 | BFD_FAIL(); | |
783 | #endif | |
784 | } | |
785 | ||
786 | void | |
8ce8c090 | 787 | bfd_putl64 (bfd_uint64_t data ATTRIBUTE_UNUSED, void *p ATTRIBUTE_UNUSED) |
252b5132 | 788 | { |
8ce8c090 | 789 | #ifdef BFD_HOST_64_BIT |
a50b1753 | 790 | bfd_byte *addr = (bfd_byte *) p; |
edeb6e24 AM |
791 | addr[7] = (data >> (7*8)) & 0xff; |
792 | addr[6] = (data >> (6*8)) & 0xff; | |
793 | addr[5] = (data >> (5*8)) & 0xff; | |
794 | addr[4] = (data >> (4*8)) & 0xff; | |
795 | addr[3] = (data >> (3*8)) & 0xff; | |
796 | addr[2] = (data >> (2*8)) & 0xff; | |
797 | addr[1] = (data >> (1*8)) & 0xff; | |
798 | addr[0] = (data >> (0*8)) & 0xff; | |
252b5132 RH |
799 | #else |
800 | BFD_FAIL(); | |
801 | #endif | |
802 | } | |
8c603c85 NC |
803 | |
804 | void | |
8ce8c090 | 805 | bfd_put_bits (bfd_uint64_t data, void *p, int bits, bfd_boolean big_p) |
8c603c85 | 806 | { |
a50b1753 | 807 | bfd_byte *addr = (bfd_byte *) p; |
8c603c85 NC |
808 | int i; |
809 | int bytes; | |
810 | ||
811 | if (bits % 8 != 0) | |
812 | abort (); | |
813 | ||
814 | bytes = bits / 8; | |
815 | for (i = 0; i < bytes; i++) | |
816 | { | |
91d6fa6a | 817 | int addr_index = big_p ? bytes - i - 1 : i; |
8c603c85 | 818 | |
91d6fa6a | 819 | addr[addr_index] = data & 0xff; |
8c603c85 NC |
820 | data >>= 8; |
821 | } | |
822 | } | |
823 | ||
8ce8c090 | 824 | bfd_uint64_t |
edeb6e24 | 825 | bfd_get_bits (const void *p, int bits, bfd_boolean big_p) |
8c603c85 | 826 | { |
a50b1753 | 827 | const bfd_byte *addr = (const bfd_byte *) p; |
8ce8c090 | 828 | bfd_uint64_t data; |
8c603c85 NC |
829 | int i; |
830 | int bytes; | |
831 | ||
832 | if (bits % 8 != 0) | |
833 | abort (); | |
834 | ||
835 | data = 0; | |
836 | bytes = bits / 8; | |
837 | for (i = 0; i < bytes; i++) | |
838 | { | |
91d6fa6a | 839 | int addr_index = big_p ? i : bytes - i - 1; |
509945ae | 840 | |
91d6fa6a | 841 | data = (data << 8) | addr[addr_index]; |
8c603c85 NC |
842 | } |
843 | ||
844 | return data; | |
845 | } | |
252b5132 RH |
846 | \f |
847 | /* Default implementation */ | |
848 | ||
b34976b6 | 849 | bfd_boolean |
c58b9523 AM |
850 | _bfd_generic_get_section_contents (bfd *abfd, |
851 | sec_ptr section, | |
852 | void *location, | |
853 | file_ptr offset, | |
854 | bfd_size_type count) | |
252b5132 | 855 | { |
eea6121a | 856 | bfd_size_type sz; |
0bff3f4b | 857 | if (count == 0) |
b34976b6 | 858 | return TRUE; |
0bff3f4b | 859 | |
4a114e3e L |
860 | if (section->compress_status != COMPRESS_SECTION_NONE) |
861 | { | |
862 | (*_bfd_error_handler) | |
863 | (_("%B: unable to get decompressed section %A"), | |
864 | abfd, section); | |
865 | bfd_set_error (bfd_error_invalid_operation); | |
866 | return FALSE; | |
867 | } | |
868 | ||
e57278ef AM |
869 | /* We do allow reading of a section after bfd_final_link has |
870 | written the contents out to disk. In that situation, rawsize is | |
871 | just a stale version of size, so ignore it. Otherwise we must be | |
872 | reading an input section, where rawsize, if different to size, | |
873 | is the on-disk size. */ | |
874 | if (abfd->direction != write_direction && section->rawsize != 0) | |
875 | sz = section->rawsize; | |
876 | else | |
877 | sz = section->size; | |
e62071b6 AM |
878 | if (offset + count < count |
879 | || offset + count > sz) | |
0bff3f4b ILT |
880 | { |
881 | bfd_set_error (bfd_error_invalid_operation); | |
b34976b6 | 882 | return FALSE; |
0bff3f4b ILT |
883 | } |
884 | ||
885 | if (bfd_seek (abfd, section->filepos + offset, SEEK_SET) != 0 | |
dc810e39 | 886 | || bfd_bread (location, count, abfd) != count) |
b34976b6 | 887 | return FALSE; |
0bff3f4b | 888 | |
b34976b6 | 889 | return TRUE; |
252b5132 RH |
890 | } |
891 | ||
b34976b6 | 892 | bfd_boolean |
c58b9523 AM |
893 | _bfd_generic_get_section_contents_in_window |
894 | (bfd *abfd ATTRIBUTE_UNUSED, | |
895 | sec_ptr section ATTRIBUTE_UNUSED, | |
896 | bfd_window *w ATTRIBUTE_UNUSED, | |
897 | file_ptr offset ATTRIBUTE_UNUSED, | |
898 | bfd_size_type count ATTRIBUTE_UNUSED) | |
252b5132 RH |
899 | { |
900 | #ifdef USE_MMAP | |
eea6121a AM |
901 | bfd_size_type sz; |
902 | ||
252b5132 | 903 | if (count == 0) |
b34976b6 | 904 | return TRUE; |
c58b9523 AM |
905 | if (abfd->xvec->_bfd_get_section_contents |
906 | != _bfd_generic_get_section_contents) | |
252b5132 RH |
907 | { |
908 | /* We don't know what changes the bfd's get_section_contents | |
909 | method may have to make. So punt trying to map the file | |
910 | window, and let get_section_contents do its thing. */ | |
911 | /* @@ FIXME : If the internal window has a refcount of 1 and was | |
912 | allocated with malloc instead of mmap, just reuse it. */ | |
913 | bfd_free_window (w); | |
c58b9523 | 914 | w->i = bfd_zmalloc (sizeof (bfd_window_internal)); |
252b5132 | 915 | if (w->i == NULL) |
b34976b6 | 916 | return FALSE; |
c58b9523 | 917 | w->i->data = bfd_malloc (count); |
252b5132 RH |
918 | if (w->i->data == NULL) |
919 | { | |
920 | free (w->i); | |
921 | w->i = NULL; | |
b34976b6 | 922 | return FALSE; |
252b5132 RH |
923 | } |
924 | w->i->mapped = 0; | |
925 | w->i->refcount = 1; | |
926 | w->size = w->i->size = count; | |
927 | w->data = w->i->data; | |
928 | return bfd_get_section_contents (abfd, section, w->data, offset, count); | |
929 | } | |
e57278ef AM |
930 | if (abfd->direction != write_direction && section->rawsize != 0) |
931 | sz = section->rawsize; | |
932 | else | |
933 | sz = section->size; | |
eea6121a | 934 | if (offset + count > sz |
82e51918 | 935 | || ! bfd_get_file_window (abfd, section->filepos + offset, count, w, |
b34976b6 AM |
936 | TRUE)) |
937 | return FALSE; | |
938 | return TRUE; | |
252b5132 RH |
939 | #else |
940 | abort (); | |
941 | #endif | |
942 | } | |
943 | ||
944 | /* This generic function can only be used in implementations where creating | |
945 | NEW sections is disallowed. It is useful in patching existing sections | |
946 | in read-write files, though. See other set_section_contents functions | |
947 | to see why it doesn't work for new sections. */ | |
b34976b6 | 948 | bfd_boolean |
c58b9523 AM |
949 | _bfd_generic_set_section_contents (bfd *abfd, |
950 | sec_ptr section, | |
0f867abe | 951 | const void *location, |
c58b9523 AM |
952 | file_ptr offset, |
953 | bfd_size_type count) | |
252b5132 RH |
954 | { |
955 | if (count == 0) | |
b34976b6 | 956 | return TRUE; |
252b5132 | 957 | |
dc810e39 AM |
958 | if (bfd_seek (abfd, section->filepos + offset, SEEK_SET) != 0 |
959 | || bfd_bwrite (location, count, abfd) != count) | |
b34976b6 | 960 | return FALSE; |
252b5132 | 961 | |
b34976b6 | 962 | return TRUE; |
252b5132 RH |
963 | } |
964 | ||
965 | /* | |
966 | INTERNAL_FUNCTION | |
967 | bfd_log2 | |
968 | ||
969 | SYNOPSIS | |
dc810e39 | 970 | unsigned int bfd_log2 (bfd_vma x); |
252b5132 RH |
971 | |
972 | DESCRIPTION | |
973 | Return the log base 2 of the value supplied, rounded up. E.g., an | |
dc810e39 | 974 | @var{x} of 1025 returns 11. A @var{x} of 0 returns 0. |
252b5132 RH |
975 | */ |
976 | ||
977 | unsigned int | |
c58b9523 | 978 | bfd_log2 (bfd_vma x) |
252b5132 RH |
979 | { |
980 | unsigned int result = 0; | |
981 | ||
9e6619e2 AM |
982 | if (x <= 1) |
983 | return result; | |
984 | --x; | |
985 | do | |
252b5132 | 986 | ++result; |
9e6619e2 | 987 | while ((x >>= 1) != 0); |
252b5132 RH |
988 | return result; |
989 | } | |
990 | ||
b34976b6 | 991 | bfd_boolean |
c58b9523 | 992 | bfd_generic_is_local_label_name (bfd *abfd, const char *name) |
252b5132 RH |
993 | { |
994 | char locals_prefix = (bfd_get_symbol_leading_char (abfd) == '_') ? 'L' : '.'; | |
995 | ||
b34976b6 | 996 | return name[0] == locals_prefix; |
252b5132 RH |
997 | } |
998 | ||
875f7f69 JR |
999 | /* Can be used from / for bfd_merge_private_bfd_data to check that |
1000 | endianness matches between input and output file. Returns | |
b34976b6 AM |
1001 | TRUE for a match, otherwise returns FALSE and emits an error. */ |
1002 | bfd_boolean | |
c58b9523 | 1003 | _bfd_generic_verify_endian_match (bfd *ibfd, bfd *obfd) |
875f7f69 JR |
1004 | { |
1005 | if (ibfd->xvec->byteorder != obfd->xvec->byteorder | |
1fe494a5 | 1006 | && ibfd->xvec->byteorder != BFD_ENDIAN_UNKNOWN |
875f7f69 JR |
1007 | && obfd->xvec->byteorder != BFD_ENDIAN_UNKNOWN) |
1008 | { | |
1fe494a5 NC |
1009 | const char *msg; |
1010 | ||
1011 | if (bfd_big_endian (ibfd)) | |
d003868e | 1012 | msg = _("%B: compiled for a big endian system and target is little endian"); |
1fe494a5 | 1013 | else |
d003868e | 1014 | msg = _("%B: compiled for a little endian system and target is big endian"); |
1fe494a5 | 1015 | |
d003868e | 1016 | (*_bfd_error_handler) (msg, ibfd); |
875f7f69 JR |
1017 | |
1018 | bfd_set_error (bfd_error_wrong_format); | |
b34976b6 | 1019 | return FALSE; |
875f7f69 JR |
1020 | } |
1021 | ||
b34976b6 | 1022 | return TRUE; |
875f7f69 | 1023 | } |
dc810e39 AM |
1024 | |
1025 | /* Give a warning at runtime if someone compiles code which calls | |
1026 | old routines. */ | |
ca09e32b | 1027 | |
dc810e39 | 1028 | void |
c58b9523 AM |
1029 | warn_deprecated (const char *what, |
1030 | const char *file, | |
1031 | int line, | |
1032 | const char *func) | |
dc810e39 AM |
1033 | { |
1034 | /* Poor man's tracking of functions we've already warned about. */ | |
1035 | static size_t mask = 0; | |
1036 | ||
1037 | if (~(size_t) func & ~mask) | |
1038 | { | |
4a97a0e5 | 1039 | fflush (stdout); |
73722af0 | 1040 | /* Note: separate sentences in order to allow |
ca09e32b | 1041 | for translation into other languages. */ |
dc810e39 | 1042 | if (func) |
ca09e32b NC |
1043 | fprintf (stderr, _("Deprecated %s called at %s line %d in %s\n"), |
1044 | what, file, line, func); | |
dc810e39 | 1045 | else |
ca09e32b | 1046 | fprintf (stderr, _("Deprecated %s called\n"), what); |
4a97a0e5 | 1047 | fflush (stderr); |
dc810e39 AM |
1048 | mask |= ~(size_t) func; |
1049 | } | |
1050 | } | |
c0c28ab8 L |
1051 | |
1052 | /* Helper function for reading uleb128 encoded data. */ | |
1053 | ||
1054 | bfd_vma | |
1055 | read_unsigned_leb128 (bfd *abfd ATTRIBUTE_UNUSED, | |
f075ee0c | 1056 | bfd_byte *buf, |
c0c28ab8 L |
1057 | unsigned int *bytes_read_ptr) |
1058 | { | |
1059 | bfd_vma result; | |
1060 | unsigned int num_read; | |
f075ee0c | 1061 | unsigned int shift; |
c0c28ab8 L |
1062 | unsigned char byte; |
1063 | ||
1064 | result = 0; | |
1065 | shift = 0; | |
1066 | num_read = 0; | |
1067 | do | |
1068 | { | |
f075ee0c | 1069 | byte = bfd_get_8 (abfd, buf); |
c0c28ab8 L |
1070 | buf++; |
1071 | num_read++; | |
1072 | result |= (((bfd_vma) byte & 0x7f) << shift); | |
1073 | shift += 7; | |
1074 | } | |
1075 | while (byte & 0x80); | |
1076 | *bytes_read_ptr = num_read; | |
1077 | return result; | |
1078 | } | |
1079 | ||
1080 | /* Helper function for reading sleb128 encoded data. */ | |
1081 | ||
1082 | bfd_signed_vma | |
1083 | read_signed_leb128 (bfd *abfd ATTRIBUTE_UNUSED, | |
f075ee0c AM |
1084 | bfd_byte *buf, |
1085 | unsigned int *bytes_read_ptr) | |
c0c28ab8 L |
1086 | { |
1087 | bfd_vma result; | |
f075ee0c AM |
1088 | unsigned int shift; |
1089 | unsigned int num_read; | |
c0c28ab8 L |
1090 | unsigned char byte; |
1091 | ||
1092 | result = 0; | |
1093 | shift = 0; | |
1094 | num_read = 0; | |
1095 | do | |
1096 | { | |
f075ee0c | 1097 | byte = bfd_get_8 (abfd, buf); |
c0c28ab8 L |
1098 | buf ++; |
1099 | num_read ++; | |
1100 | result |= (((bfd_vma) byte & 0x7f) << shift); | |
1101 | shift += 7; | |
1102 | } | |
1103 | while (byte & 0x80); | |
f075ee0c | 1104 | if (shift < 8 * sizeof (result) && (byte & 0x40)) |
c0c28ab8 L |
1105 | result |= (((bfd_vma) -1) << shift); |
1106 | *bytes_read_ptr = num_read; | |
1107 | return result; | |
1108 | } | |
5420f73d L |
1109 | |
1110 | bfd_boolean | |
1111 | _bfd_generic_find_line (bfd *abfd ATTRIBUTE_UNUSED, | |
1112 | asymbol **symbols ATTRIBUTE_UNUSED, | |
1113 | asymbol *symbol ATTRIBUTE_UNUSED, | |
1114 | const char **filename_ptr ATTRIBUTE_UNUSED, | |
1115 | unsigned int *linenumber_ptr ATTRIBUTE_UNUSED) | |
1116 | { | |
1117 | return FALSE; | |
1118 | } | |
ecca9871 | 1119 | |
9b8d1a36 CC |
1120 | bfd_boolean |
1121 | _bfd_generic_find_nearest_line_discriminator (bfd *abfd ATTRIBUTE_UNUSED, | |
1122 | asection *section ATTRIBUTE_UNUSED, | |
1123 | asymbol **symbols ATTRIBUTE_UNUSED, | |
1124 | bfd_vma offset ATTRIBUTE_UNUSED, | |
1125 | const char **filename_ptr ATTRIBUTE_UNUSED, | |
1126 | const char **functionname_ptr ATTRIBUTE_UNUSED, | |
1127 | unsigned int *line_ptr ATTRIBUTE_UNUSED, | |
1128 | unsigned int *discriminator_ptr ATTRIBUTE_UNUSED) | |
1129 | { | |
1130 | return FALSE; | |
1131 | } | |
1132 | ||
ccd2ec6a L |
1133 | bfd_boolean |
1134 | _bfd_generic_init_private_section_data (bfd *ibfd ATTRIBUTE_UNUSED, | |
1135 | asection *isec ATTRIBUTE_UNUSED, | |
1136 | bfd *obfd ATTRIBUTE_UNUSED, | |
1137 | asection *osec ATTRIBUTE_UNUSED, | |
1138 | struct bfd_link_info *link_info ATTRIBUTE_UNUSED) | |
1139 | { | |
1140 | return TRUE; | |
1141 | } |