]> git.ipfire.org Git - thirdparty/binutils-gdb.git/blame - bfd/libbfd.c
Update year range in copyright notice of binutils files
[thirdparty/binutils-gdb.git] / bfd / libbfd.c
CommitLineData
252b5132 1/* Assorted BFD support routines, only used internally.
d87bef3a 2 Copyright (C) 1990-2023 Free Software Foundation, Inc.
252b5132
RH
3 Written by Cygnus Support.
4
ca09e32b 5 This file is part of BFD, the Binary File Descriptor library.
252b5132 6
ca09e32b
NC
7 This program is free software; you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by
cd123cb7 9 the Free Software Foundation; either version 3 of the License, or
ca09e32b 10 (at your option) any later version.
252b5132 11
ca09e32b
NC
12 This program is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
252b5132 16
ca09e32b
NC
17 You should have received a copy of the GNU General Public License
18 along with this program; if not, write to the Free Software
cd123cb7
NC
19 Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston,
20 MA 02110-1301, USA. */
252b5132 21
252b5132 22#include "sysdep.h"
3db64b00 23#include "bfd.h"
252b5132
RH
24#include "libbfd.h"
25
26#ifndef HAVE_GETPAGESIZE
27#define getpagesize() 2048
28#endif
29
252b5132
RH
30/*
31SECTION
1b74d094
BW
32 Implementation details
33
34SUBSECTION
252b5132
RH
35 Internal functions
36
37DESCRIPTION
38 These routines are used within BFD.
39 They are not intended for export, but are documented here for
40 completeness.
41*/
42
0a1b45a2 43bool
d00dd7dc
AM
44_bfd_bool_bfd_false (bfd *abfd ATTRIBUTE_UNUSED)
45{
0a1b45a2 46 return false;
d00dd7dc
AM
47}
48
0a1b45a2 49bool
d00dd7dc
AM
50_bfd_bool_bfd_asymbol_false (bfd *abfd ATTRIBUTE_UNUSED,
51 asymbol *sym ATTRIBUTE_UNUSED)
52{
0a1b45a2 53 return false;
d00dd7dc
AM
54}
55
252b5132
RH
56/* A routine which is used in target vectors for unsupported
57 operations. */
58
0a1b45a2 59bool
d00dd7dc 60_bfd_bool_bfd_false_error (bfd *ignore ATTRIBUTE_UNUSED)
252b5132
RH
61{
62 bfd_set_error (bfd_error_invalid_operation);
0a1b45a2 63 return false;
252b5132
RH
64}
65
0a1b45a2 66bool
d00dd7dc
AM
67_bfd_bool_bfd_link_false_error (bfd *abfd,
68 struct bfd_link_info *info ATTRIBUTE_UNUSED)
69{
70 return _bfd_bool_bfd_false_error (abfd);
71}
72
252b5132
RH
73/* A routine which is used in target vectors for supported operations
74 which do not actually do anything. */
75
0a1b45a2 76bool
d00dd7dc
AM
77_bfd_bool_bfd_true (bfd *ignore ATTRIBUTE_UNUSED)
78{
0a1b45a2 79 return true;
d00dd7dc
AM
80}
81
0a1b45a2 82bool
d00dd7dc
AM
83_bfd_bool_bfd_link_true (bfd *abfd ATTRIBUTE_UNUSED,
84 struct bfd_link_info *info ATTRIBUTE_UNUSED)
85{
0a1b45a2 86 return true;
d00dd7dc
AM
87}
88
0a1b45a2 89bool
d00dd7dc
AM
90_bfd_bool_bfd_bfd_true (bfd *ibfd ATTRIBUTE_UNUSED,
91 bfd *obfd ATTRIBUTE_UNUSED)
92{
0a1b45a2 93 return true;
d00dd7dc
AM
94}
95
0a1b45a2 96bool
d00dd7dc
AM
97_bfd_bool_bfd_uint_true (bfd *abfd ATTRIBUTE_UNUSED,
98 unsigned int flags ATTRIBUTE_UNUSED)
99{
0a1b45a2 100 return true;
d00dd7dc
AM
101}
102
0a1b45a2 103bool
d00dd7dc
AM
104_bfd_bool_bfd_asection_bfd_asection_true (bfd *ibfd ATTRIBUTE_UNUSED,
105 asection *isec ATTRIBUTE_UNUSED,
106 bfd *obfd ATTRIBUTE_UNUSED,
107 asection *osec ATTRIBUTE_UNUSED)
108{
0a1b45a2 109 return true;
d00dd7dc
AM
110}
111
0a1b45a2 112bool
d00dd7dc
AM
113_bfd_bool_bfd_asymbol_bfd_asymbol_true (bfd *ibfd ATTRIBUTE_UNUSED,
114 asymbol *isym ATTRIBUTE_UNUSED,
115 bfd *obfd ATTRIBUTE_UNUSED,
116 asymbol *osym ATTRIBUTE_UNUSED)
117{
0a1b45a2 118 return true;
d00dd7dc
AM
119}
120
0a1b45a2 121bool
d00dd7dc
AM
122_bfd_bool_bfd_ptr_true (bfd *abfd ATTRIBUTE_UNUSED,
123 void *ptr ATTRIBUTE_UNUSED)
252b5132 124{
0a1b45a2 125 return true;
252b5132
RH
126}
127
128/* A routine which is used in target vectors for unsupported
129 operations which return a pointer value. */
130
c58b9523 131void *
d00dd7dc 132_bfd_ptr_bfd_null_error (bfd *ignore ATTRIBUTE_UNUSED)
252b5132
RH
133{
134 bfd_set_error (bfd_error_invalid_operation);
135 return NULL;
136}
137
509945ae 138int
d00dd7dc 139_bfd_int_bfd_0 (bfd *ignore ATTRIBUTE_UNUSED)
252b5132
RH
140{
141 return 0;
142}
143
509945ae 144unsigned int
d00dd7dc 145_bfd_uint_bfd_0 (bfd *ignore ATTRIBUTE_UNUSED)
252b5132
RH
146{
147 return 0;
148}
149
252b5132 150long
d00dd7dc 151_bfd_long_bfd_0 (bfd *ignore ATTRIBUTE_UNUSED)
252b5132 152{
d00dd7dc 153 return 0;
68d20676
NC
154}
155
252b5132
RH
156/* A routine which is used in target vectors for unsupported
157 operations which return -1 on error. */
158
252b5132 159long
d00dd7dc 160_bfd_long_bfd_n1_error (bfd *ignore_abfd ATTRIBUTE_UNUSED)
252b5132
RH
161{
162 bfd_set_error (bfd_error_invalid_operation);
163 return -1;
164}
165
509945ae 166void
d00dd7dc
AM
167_bfd_void_bfd (bfd *ignore ATTRIBUTE_UNUSED)
168{
169}
170
171void
172_bfd_void_bfd_link (bfd *abfd ATTRIBUTE_UNUSED,
173 struct bfd_link_info *info ATTRIBUTE_UNUSED)
174{
175}
176
177void
178_bfd_void_bfd_asection (bfd *abfd ATTRIBUTE_UNUSED,
179 asection *sec ATTRIBUTE_UNUSED)
252b5132
RH
180{
181}
182
72f6ea61
AM
183long
184_bfd_norelocs_get_reloc_upper_bound (bfd *abfd ATTRIBUTE_UNUSED,
185 asection *sec ATTRIBUTE_UNUSED)
186{
187 return sizeof (arelent *);
188}
189
190long
191_bfd_norelocs_canonicalize_reloc (bfd *abfd ATTRIBUTE_UNUSED,
192 asection *sec ATTRIBUTE_UNUSED,
193 arelent **relptr,
194 asymbol **symbols ATTRIBUTE_UNUSED)
195{
196 *relptr = NULL;
197 return 0;
198}
199
23186865
JM
200void
201_bfd_norelocs_set_reloc (bfd *abfd ATTRIBUTE_UNUSED,
07d6d2b8
AM
202 asection *sec ATTRIBUTE_UNUSED,
203 arelent **relptr ATTRIBUTE_UNUSED,
204 unsigned int count ATTRIBUTE_UNUSED)
23186865
JM
205{
206 /* Do nothing. */
207}
208
0a1b45a2 209bool
c58b9523
AM
210_bfd_nocore_core_file_matches_executable_p
211 (bfd *ignore_core_bfd ATTRIBUTE_UNUSED,
212 bfd *ignore_exec_bfd ATTRIBUTE_UNUSED)
252b5132
RH
213{
214 bfd_set_error (bfd_error_invalid_operation);
0a1b45a2 215 return false;
252b5132
RH
216}
217
218/* Routine to handle core_file_failing_command entry point for targets
219 without core file support. */
220
252b5132 221char *
c58b9523 222_bfd_nocore_core_file_failing_command (bfd *ignore_abfd ATTRIBUTE_UNUSED)
252b5132
RH
223{
224 bfd_set_error (bfd_error_invalid_operation);
c58b9523 225 return NULL;
252b5132
RH
226}
227
228/* Routine to handle core_file_failing_signal entry point for targets
229 without core file support. */
230
252b5132 231int
c58b9523 232_bfd_nocore_core_file_failing_signal (bfd *ignore_abfd ATTRIBUTE_UNUSED)
252b5132
RH
233{
234 bfd_set_error (bfd_error_invalid_operation);
235 return 0;
236}
237
261b8d08
PA
238/* Routine to handle the core_file_pid entry point for targets without
239 core file support. */
240
241int
242_bfd_nocore_core_file_pid (bfd *ignore_abfd ATTRIBUTE_UNUSED)
243{
244 bfd_set_error (bfd_error_invalid_operation);
245 return 0;
246}
247
cb001c0d 248bfd_cleanup
c58b9523 249_bfd_dummy_target (bfd *ignore_abfd ATTRIBUTE_UNUSED)
252b5132
RH
250{
251 bfd_set_error (bfd_error_wrong_format);
252 return 0;
253}
254\f
255/* Allocate memory using malloc. */
256
cb87d9f1
AM
257#ifndef SSIZE_MAX
258#define SSIZE_MAX ((size_t) -1 >> 1)
259#endif
260
bd6d8601
NC
261/*
262INTERNAL_FUNCTION
263 bfd_malloc
264
265SYNOPSIS
266 extern void * bfd_malloc (bfd_size_type SIZE) ATTRIBUTE_HIDDEN;
267
268DESCRIPTION
269 Returns a pointer to an allocated block of memory that is at least
270 SIZE bytes long. If SIZE is 0 then it will be treated as if it were
271 1. If SIZE is too big then NULL will be returned.
272
273 Returns NULL upon error and sets bfd_error.
274*/
c58b9523
AM
275void *
276bfd_malloc (bfd_size_type size)
252b5132 277{
c58b9523 278 void *ptr;
db6b071a 279 size_t sz = (size_t) size;
252b5132 280
db6b071a
NC
281 if (size != sz
282 /* This is to pacify memory checkers like valgrind. */
cb87d9f1 283 || sz > SSIZE_MAX)
dc810e39
AM
284 {
285 bfd_set_error (bfd_error_no_memory);
286 return NULL;
287 }
288
bd6d8601
NC
289 ptr = malloc (sz ? sz : 1);
290 if (ptr == NULL)
252b5132 291 bfd_set_error (bfd_error_no_memory);
dc810e39 292
252b5132
RH
293 return ptr;
294}
295
bd6d8601
NC
296/*
297INTERNAL_FUNCTION
298 bfd_realloc
299
300SYNOPSIS
301 extern void * bfd_realloc (void * MEM, bfd_size_type SIZE) ATTRIBUTE_HIDDEN;
302
303DESCRIPTION
304 Returns a pointer to an allocated block of memory that is at least
305 SIZE bytes long. If SIZE is 0 then it will be treated as if it were
306 1. If SIZE is too big then NULL will be returned.
307
308 If MEM is not NULL then it must point to an allocated block of memory.
309 If this block is large enough then MEM may be used as the return
310 value for this function, but this is not guaranteed.
311
312 If MEM is not returned then the first N bytes in the returned block
313 will be identical to the first N bytes in region pointed to by MEM,
314 where N is the lessor of SIZE and the length of the region of memory
315 currently addressed by MEM.
316
317 Returns NULL upon error and sets bfd_error.
318*/
c58b9523
AM
319void *
320bfd_realloc (void *ptr, bfd_size_type size)
252b5132 321{
c58b9523 322 void *ret;
db6b071a 323 size_t sz = (size_t) size;
252b5132 324
db6b071a
NC
325 if (ptr == NULL)
326 return bfd_malloc (size);
327
328 if (size != sz
329 /* This is to pacify memory checkers like valgrind. */
cb87d9f1 330 || sz > SSIZE_MAX)
dc810e39
AM
331 {
332 bfd_set_error (bfd_error_no_memory);
333 return NULL;
334 }
335
bd6d8601
NC
336 /* The behaviour of realloc(0) is implementation defined,
337 but for this function we always allocate memory. */
338 ret = realloc (ptr, sz ? sz : 1);
252b5132 339
bd6d8601 340 if (ret == NULL)
252b5132
RH
341 bfd_set_error (bfd_error_no_memory);
342
343 return ret;
344}
345
bd6d8601
NC
346/*
347INTERNAL_FUNCTION
348 bfd_realloc_or_free
349
350SYNOPSIS
351 extern void * bfd_realloc_or_free (void * MEM, bfd_size_type SIZE) ATTRIBUTE_HIDDEN;
515ef31d 352
bd6d8601
NC
353DESCRIPTION
354 Returns a pointer to an allocated block of memory that is at least
355 SIZE bytes long. If SIZE is 0 then no memory will be allocated,
356 MEM will be freed, and NULL will be returned. This will not cause
357 bfd_error to be set.
358
359 If SIZE is too big then NULL will be returned and bfd_error will be
360 set.
361
362 If MEM is not NULL then it must point to an allocated block of memory.
363 If this block is large enough then MEM may be used as the return
364 value for this function, but this is not guaranteed.
365
366 If MEM is not returned then the first N bytes in the returned block
367 will be identical to the first N bytes in region pointed to by MEM,
368 where N is the lessor of SIZE and the length of the region of memory
369 currently addressed by MEM.
370*/
515ef31d
NC
371void *
372bfd_realloc_or_free (void *ptr, bfd_size_type size)
373{
bd6d8601 374 void *ret;
515ef31d 375
bd6d8601
NC
376 /* The behaviour of realloc(0) is implementation defined, but
377 for this function we treat it is always freeing the memory. */
378 if (size == 0)
379 {
380 free (ptr);
381 return NULL;
382 }
383
384 ret = bfd_realloc (ptr, size);
385 if (ret == NULL)
db6b071a 386 free (ptr);
515ef31d
NC
387
388 return ret;
389}
390
bd6d8601
NC
391/*
392INTERNAL_FUNCTION
393 bfd_zmalloc
252b5132 394
bd6d8601
NC
395SYNOPSIS
396 extern void * bfd_zmalloc (bfd_size_type SIZE) ATTRIBUTE_HIDDEN;
397
398DESCRIPTION
399 Returns a pointer to an allocated block of memory that is at least
400 SIZE bytes long. If SIZE is 0 then it will be treated as if it were
401 1. If SIZE is too big then NULL will be returned.
402
403 Returns NULL upon error and sets bfd_error.
404
405 If NULL is not returned then the allocated block of memory will
406 have been cleared.
407*/
c58b9523
AM
408void *
409bfd_zmalloc (bfd_size_type size)
252b5132 410{
db6b071a 411 void *ptr = bfd_malloc (size);
252b5132 412
bd6d8601
NC
413 if (ptr != NULL)
414 memset (ptr, 0, size ? (size_t) size : 1);
252b5132
RH
415
416 return ptr;
417}
d0fb9a8d 418
252b5132
RH
419/*
420INTERNAL_FUNCTION
421 bfd_write_bigendian_4byte_int
422
423SYNOPSIS
0a1b45a2 424 bool bfd_write_bigendian_4byte_int (bfd *, unsigned int);
252b5132
RH
425
426DESCRIPTION
427 Write a 4 byte integer @var{i} to the output BFD @var{abfd}, in big
428 endian order regardless of what else is going on. This is useful in
429 archives.
430
431*/
0a1b45a2 432bool
c58b9523 433bfd_write_bigendian_4byte_int (bfd *abfd, unsigned int i)
252b5132
RH
434{
435 bfd_byte buffer[4];
dc810e39 436 bfd_putb32 ((bfd_vma) i, buffer);
c58b9523 437 return bfd_bwrite (buffer, (bfd_size_type) 4, abfd) == 4;
252b5132
RH
438}
439
252b5132
RH
440\f
441/** The do-it-yourself (byte) sex-change kit */
442
443/* The middle letter e.g. get<b>short indicates Big or Little endian
444 target machine. It doesn't matter what the byte order of the host
445 machine is; these routines work for either. */
446
447/* FIXME: Should these take a count argument?
448 Answer (gnu@cygnus.com): No, but perhaps they should be inline
07d6d2b8
AM
449 functions in swap.h #ifdef __GNUC__.
450 Gprof them later and find out. */
252b5132
RH
451
452/*
453FUNCTION
454 bfd_put_size
455FUNCTION
456 bfd_get_size
457
458DESCRIPTION
459 These macros as used for reading and writing raw data in
460 sections; each access (except for bytes) is vectored through
461 the target format of the BFD and mangled accordingly. The
462 mangling performs any necessary endian translations and
463 removes alignment restrictions. Note that types accepted and
464 returned by these macros are identical so they can be swapped
465 around in macros---for example, @file{libaout.h} defines <<GET_WORD>>
466 to either <<bfd_get_32>> or <<bfd_get_64>>.
467
468 In the put routines, @var{val} must be a <<bfd_vma>>. If we are on a
469 system without prototypes, the caller is responsible for making
470 sure that is true, with a cast if necessary. We don't cast
471 them in the macro definitions because that would prevent <<lint>>
472 or <<gcc -Wall>> from detecting sins such as passing a pointer.
473 To detect calling these with less than a <<bfd_vma>>, use
474 <<gcc -Wconversion>> on a host with 64 bit <<bfd_vma>>'s.
475
476.
477.{* Byte swapping macros for user section data. *}
478.
479.#define bfd_put_8(abfd, val, ptr) \
edeb6e24 480. ((void) (*((unsigned char *) (ptr)) = (val) & 0xff))
252b5132 481.#define bfd_put_signed_8 \
c58b9523 482. bfd_put_8
252b5132 483.#define bfd_get_8(abfd, ptr) \
09c78487 484. ((bfd_vma) *(const unsigned char *) (ptr) & 0xff)
252b5132 485.#define bfd_get_signed_8(abfd, ptr) \
09c78487 486. ((((bfd_signed_vma) *(const unsigned char *) (ptr) & 0xff) ^ 0x80) - 0x80)
252b5132
RH
487.
488.#define bfd_put_16(abfd, val, ptr) \
c58b9523 489. BFD_SEND (abfd, bfd_putx16, ((val),(ptr)))
252b5132 490.#define bfd_put_signed_16 \
c58b9523 491. bfd_put_16
252b5132 492.#define bfd_get_16(abfd, ptr) \
c58b9523 493. BFD_SEND (abfd, bfd_getx16, (ptr))
252b5132 494.#define bfd_get_signed_16(abfd, ptr) \
c58b9523 495. BFD_SEND (abfd, bfd_getx_signed_16, (ptr))
252b5132 496.
370e4b50
JD
497.#define bfd_put_24(abfd, val, ptr) \
498. do \
499. if (bfd_big_endian (abfd)) \
500. bfd_putb24 ((val), (ptr)); \
501. else \
502. bfd_putl24 ((val), (ptr)); \
503. while (0)
504.
505.bfd_vma bfd_getb24 (const void *p);
506.bfd_vma bfd_getl24 (const void *p);
507.
508.#define bfd_get_24(abfd, ptr) \
509. (bfd_big_endian (abfd) ? bfd_getb24 (ptr) : bfd_getl24 (ptr))
510.
252b5132 511.#define bfd_put_32(abfd, val, ptr) \
c58b9523 512. BFD_SEND (abfd, bfd_putx32, ((val),(ptr)))
252b5132 513.#define bfd_put_signed_32 \
c58b9523 514. bfd_put_32
252b5132 515.#define bfd_get_32(abfd, ptr) \
c58b9523 516. BFD_SEND (abfd, bfd_getx32, (ptr))
252b5132 517.#define bfd_get_signed_32(abfd, ptr) \
c58b9523 518. BFD_SEND (abfd, bfd_getx_signed_32, (ptr))
252b5132
RH
519.
520.#define bfd_put_64(abfd, val, ptr) \
c58b9523 521. BFD_SEND (abfd, bfd_putx64, ((val), (ptr)))
252b5132 522.#define bfd_put_signed_64 \
c58b9523 523. bfd_put_64
252b5132 524.#define bfd_get_64(abfd, ptr) \
c58b9523 525. BFD_SEND (abfd, bfd_getx64, (ptr))
252b5132 526.#define bfd_get_signed_64(abfd, ptr) \
c58b9523 527. BFD_SEND (abfd, bfd_getx_signed_64, (ptr))
252b5132 528.
c58b9523 529.#define bfd_get(bits, abfd, ptr) \
199d46be 530. ((bits) == 8 ? bfd_get_8 (abfd, ptr) \
c58b9523
AM
531. : (bits) == 16 ? bfd_get_16 (abfd, ptr) \
532. : (bits) == 32 ? bfd_get_32 (abfd, ptr) \
533. : (bits) == 64 ? bfd_get_64 (abfd, ptr) \
534. : (abort (), (bfd_vma) - 1))
c7ac6ff8 535.
c58b9523
AM
536.#define bfd_put(bits, abfd, val, ptr) \
537. ((bits) == 8 ? bfd_put_8 (abfd, val, ptr) \
07d6d2b8
AM
538. : (bits) == 16 ? bfd_put_16 (abfd, val, ptr) \
539. : (bits) == 32 ? bfd_put_32 (abfd, val, ptr) \
540. : (bits) == 64 ? bfd_put_64 (abfd, val, ptr) \
c58b9523 541. : (abort (), (void) 0))
c7ac6ff8 542.
509945ae 543*/
252b5132
RH
544
545/*
546FUNCTION
547 bfd_h_put_size
548 bfd_h_get_size
549
550DESCRIPTION
551 These macros have the same function as their <<bfd_get_x>>
dc810e39 552 brethren, except that they are used for removing information
252b5132
RH
553 for the header records of object files. Believe it or not,
554 some object files keep their header records in big endian
555 order and their data in little endian order.
556.
557.{* Byte swapping macros for file header data. *}
558.
559.#define bfd_h_put_8(abfd, val, ptr) \
dc810e39 560. bfd_put_8 (abfd, val, ptr)
252b5132 561.#define bfd_h_put_signed_8(abfd, val, ptr) \
dc810e39 562. bfd_put_8 (abfd, val, ptr)
252b5132 563.#define bfd_h_get_8(abfd, ptr) \
dc810e39 564. bfd_get_8 (abfd, ptr)
252b5132 565.#define bfd_h_get_signed_8(abfd, ptr) \
dc810e39 566. bfd_get_signed_8 (abfd, ptr)
252b5132
RH
567.
568.#define bfd_h_put_16(abfd, val, ptr) \
dc810e39 569. BFD_SEND (abfd, bfd_h_putx16, (val, ptr))
252b5132 570.#define bfd_h_put_signed_16 \
dc810e39 571. bfd_h_put_16
252b5132 572.#define bfd_h_get_16(abfd, ptr) \
dc810e39 573. BFD_SEND (abfd, bfd_h_getx16, (ptr))
252b5132 574.#define bfd_h_get_signed_16(abfd, ptr) \
dc810e39 575. BFD_SEND (abfd, bfd_h_getx_signed_16, (ptr))
252b5132
RH
576.
577.#define bfd_h_put_32(abfd, val, ptr) \
dc810e39 578. BFD_SEND (abfd, bfd_h_putx32, (val, ptr))
252b5132 579.#define bfd_h_put_signed_32 \
dc810e39 580. bfd_h_put_32
252b5132 581.#define bfd_h_get_32(abfd, ptr) \
dc810e39 582. BFD_SEND (abfd, bfd_h_getx32, (ptr))
252b5132 583.#define bfd_h_get_signed_32(abfd, ptr) \
dc810e39 584. BFD_SEND (abfd, bfd_h_getx_signed_32, (ptr))
252b5132
RH
585.
586.#define bfd_h_put_64(abfd, val, ptr) \
dc810e39 587. BFD_SEND (abfd, bfd_h_putx64, (val, ptr))
252b5132 588.#define bfd_h_put_signed_64 \
dc810e39 589. bfd_h_put_64
252b5132 590.#define bfd_h_get_64(abfd, ptr) \
dc810e39 591. BFD_SEND (abfd, bfd_h_getx64, (ptr))
252b5132 592.#define bfd_h_get_signed_64(abfd, ptr) \
dc810e39 593. BFD_SEND (abfd, bfd_h_getx_signed_64, (ptr))
252b5132 594.
edeb6e24 595.{* Aliases for the above, which should eventually go away. *}
dc810e39 596.
edeb6e24
AM
597.#define H_PUT_64 bfd_h_put_64
598.#define H_PUT_32 bfd_h_put_32
599.#define H_PUT_16 bfd_h_put_16
600.#define H_PUT_8 bfd_h_put_8
601.#define H_PUT_S64 bfd_h_put_signed_64
602.#define H_PUT_S32 bfd_h_put_signed_32
603.#define H_PUT_S16 bfd_h_put_signed_16
604.#define H_PUT_S8 bfd_h_put_signed_8
605.#define H_GET_64 bfd_h_get_64
606.#define H_GET_32 bfd_h_get_32
607.#define H_GET_16 bfd_h_get_16
608.#define H_GET_8 bfd_h_get_8
609.#define H_GET_S64 bfd_h_get_signed_64
610.#define H_GET_S32 bfd_h_get_signed_32
611.#define H_GET_S16 bfd_h_get_signed_16
612.#define H_GET_S8 bfd_h_get_signed_8
dc810e39
AM
613.
614.*/
252b5132
RH
615
616/* Sign extension to bfd_signed_vma. */
65879393
AM
617#define COERCE16(x) (((bfd_vma) (x) ^ 0x8000) - 0x8000)
618#define COERCE32(x) (((bfd_vma) (x) ^ 0x80000000) - 0x80000000)
252b5132 619#define COERCE64(x) \
0e3c1eeb 620 (((uint64_t) (x) ^ ((uint64_t) 1 << 63)) - ((uint64_t) 1 << 63))
252b5132
RH
621
622bfd_vma
edeb6e24 623bfd_getb16 (const void *p)
252b5132 624{
a50b1753 625 const bfd_byte *addr = (const bfd_byte *) p;
252b5132
RH
626 return (addr[0] << 8) | addr[1];
627}
628
629bfd_vma
edeb6e24 630bfd_getl16 (const void *p)
252b5132 631{
a50b1753 632 const bfd_byte *addr = (const bfd_byte *) p;
252b5132
RH
633 return (addr[1] << 8) | addr[0];
634}
635
636bfd_signed_vma
edeb6e24 637bfd_getb_signed_16 (const void *p)
252b5132 638{
a50b1753 639 const bfd_byte *addr = (const bfd_byte *) p;
c58b9523 640 return COERCE16 ((addr[0] << 8) | addr[1]);
252b5132
RH
641}
642
643bfd_signed_vma
edeb6e24 644bfd_getl_signed_16 (const void *p)
252b5132 645{
a50b1753 646 const bfd_byte *addr = (const bfd_byte *) p;
c58b9523 647 return COERCE16 ((addr[1] << 8) | addr[0]);
252b5132
RH
648}
649
650void
edeb6e24 651bfd_putb16 (bfd_vma data, void *p)
252b5132 652{
a50b1753 653 bfd_byte *addr = (bfd_byte *) p;
edeb6e24
AM
654 addr[0] = (data >> 8) & 0xff;
655 addr[1] = data & 0xff;
252b5132
RH
656}
657
658void
edeb6e24 659bfd_putl16 (bfd_vma data, void *p)
252b5132 660{
a50b1753 661 bfd_byte *addr = (bfd_byte *) p;
edeb6e24
AM
662 addr[0] = data & 0xff;
663 addr[1] = (data >> 8) & 0xff;
252b5132
RH
664}
665
7b4ae824
JD
666void
667bfd_putb24 (bfd_vma data, void *p)
668{
669 bfd_byte *addr = (bfd_byte *) p;
670 addr[0] = (data >> 16) & 0xff;
671 addr[1] = (data >> 8) & 0xff;
672 addr[2] = data & 0xff;
673}
674
7b4ae824
JD
675void
676bfd_putl24 (bfd_vma data, void *p)
677{
678 bfd_byte *addr = (bfd_byte *) p;
679 addr[0] = data & 0xff;
680 addr[1] = (data >> 8) & 0xff;
681 addr[2] = (data >> 16) & 0xff;
682}
683
370e4b50
JD
684bfd_vma
685bfd_getb24 (const void *p)
686{
687 const bfd_byte *addr = (const bfd_byte *) p;
688 unsigned long v;
689
690 v = (unsigned long) addr[0] << 16;
691 v |= (unsigned long) addr[1] << 8;
692 v |= (unsigned long) addr[2];
693 return v;
694}
695
696bfd_vma
697bfd_getl24 (const void *p)
698{
699 const bfd_byte *addr = (const bfd_byte *) p;
700 unsigned long v;
701
702 v = (unsigned long) addr[0];
703 v |= (unsigned long) addr[1] << 8;
704 v |= (unsigned long) addr[2] << 16;
705 return v;
706}
7b4ae824 707
252b5132 708bfd_vma
edeb6e24 709bfd_getb32 (const void *p)
252b5132 710{
a50b1753 711 const bfd_byte *addr = (const bfd_byte *) p;
252b5132
RH
712 unsigned long v;
713
714 v = (unsigned long) addr[0] << 24;
715 v |= (unsigned long) addr[1] << 16;
716 v |= (unsigned long) addr[2] << 8;
717 v |= (unsigned long) addr[3];
c58b9523 718 return v;
252b5132
RH
719}
720
721bfd_vma
edeb6e24 722bfd_getl32 (const void *p)
252b5132 723{
a50b1753 724 const bfd_byte *addr = (const bfd_byte *) p;
252b5132
RH
725 unsigned long v;
726
727 v = (unsigned long) addr[0];
728 v |= (unsigned long) addr[1] << 8;
729 v |= (unsigned long) addr[2] << 16;
730 v |= (unsigned long) addr[3] << 24;
c58b9523 731 return v;
252b5132
RH
732}
733
734bfd_signed_vma
edeb6e24 735bfd_getb_signed_32 (const void *p)
252b5132 736{
a50b1753 737 const bfd_byte *addr = (const bfd_byte *) p;
252b5132
RH
738 unsigned long v;
739
740 v = (unsigned long) addr[0] << 24;
741 v |= (unsigned long) addr[1] << 16;
742 v |= (unsigned long) addr[2] << 8;
743 v |= (unsigned long) addr[3];
744 return COERCE32 (v);
745}
746
747bfd_signed_vma
edeb6e24 748bfd_getl_signed_32 (const void *p)
252b5132 749{
a50b1753 750 const bfd_byte *addr = (const bfd_byte *) p;
252b5132
RH
751 unsigned long v;
752
753 v = (unsigned long) addr[0];
754 v |= (unsigned long) addr[1] << 8;
755 v |= (unsigned long) addr[2] << 16;
756 v |= (unsigned long) addr[3] << 24;
757 return COERCE32 (v);
758}
759
0e3c1eeb
AM
760uint64_t
761bfd_getb64 (const void *p)
252b5132 762{
a50b1753 763 const bfd_byte *addr = (const bfd_byte *) p;
0e3c1eeb 764 uint64_t v;
c58b9523
AM
765
766 v = addr[0]; v <<= 8;
767 v |= addr[1]; v <<= 8;
768 v |= addr[2]; v <<= 8;
769 v |= addr[3]; v <<= 8;
770 v |= addr[4]; v <<= 8;
771 v |= addr[5]; v <<= 8;
772 v |= addr[6]; v <<= 8;
773 v |= addr[7];
774
775 return v;
252b5132
RH
776}
777
0e3c1eeb
AM
778uint64_t
779bfd_getl64 (const void *p)
252b5132 780{
a50b1753 781 const bfd_byte *addr = (const bfd_byte *) p;
0e3c1eeb 782 uint64_t v;
c58b9523
AM
783
784 v = addr[7]; v <<= 8;
785 v |= addr[6]; v <<= 8;
786 v |= addr[5]; v <<= 8;
787 v |= addr[4]; v <<= 8;
788 v |= addr[3]; v <<= 8;
789 v |= addr[2]; v <<= 8;
790 v |= addr[1]; v <<= 8;
791 v |= addr[0];
792
793 return v;
252b5132
RH
794}
795
0e3c1eeb
AM
796int64_t
797bfd_getb_signed_64 (const void *p)
252b5132 798{
a50b1753 799 const bfd_byte *addr = (const bfd_byte *) p;
0e3c1eeb 800 uint64_t v;
c58b9523
AM
801
802 v = addr[0]; v <<= 8;
803 v |= addr[1]; v <<= 8;
804 v |= addr[2]; v <<= 8;
805 v |= addr[3]; v <<= 8;
806 v |= addr[4]; v <<= 8;
807 v |= addr[5]; v <<= 8;
808 v |= addr[6]; v <<= 8;
809 v |= addr[7];
810
811 return COERCE64 (v);
252b5132
RH
812}
813
0e3c1eeb
AM
814int64_t
815bfd_getl_signed_64 (const void *p)
252b5132 816{
a50b1753 817 const bfd_byte *addr = (const bfd_byte *) p;
0e3c1eeb 818 uint64_t v;
c58b9523
AM
819
820 v = addr[7]; v <<= 8;
821 v |= addr[6]; v <<= 8;
822 v |= addr[5]; v <<= 8;
823 v |= addr[4]; v <<= 8;
824 v |= addr[3]; v <<= 8;
825 v |= addr[2]; v <<= 8;
826 v |= addr[1]; v <<= 8;
827 v |= addr[0];
828
829 return COERCE64 (v);
252b5132
RH
830}
831
832void
edeb6e24 833bfd_putb32 (bfd_vma data, void *p)
252b5132 834{
a50b1753 835 bfd_byte *addr = (bfd_byte *) p;
edeb6e24
AM
836 addr[0] = (data >> 24) & 0xff;
837 addr[1] = (data >> 16) & 0xff;
838 addr[2] = (data >> 8) & 0xff;
839 addr[3] = data & 0xff;
252b5132
RH
840}
841
842void
edeb6e24 843bfd_putl32 (bfd_vma data, void *p)
252b5132 844{
a50b1753 845 bfd_byte *addr = (bfd_byte *) p;
edeb6e24
AM
846 addr[0] = data & 0xff;
847 addr[1] = (data >> 8) & 0xff;
848 addr[2] = (data >> 16) & 0xff;
849 addr[3] = (data >> 24) & 0xff;
252b5132
RH
850}
851
852void
0e3c1eeb 853bfd_putb64 (uint64_t data, void *p)
252b5132 854{
a50b1753 855 bfd_byte *addr = (bfd_byte *) p;
edeb6e24
AM
856 addr[0] = (data >> (7*8)) & 0xff;
857 addr[1] = (data >> (6*8)) & 0xff;
858 addr[2] = (data >> (5*8)) & 0xff;
859 addr[3] = (data >> (4*8)) & 0xff;
860 addr[4] = (data >> (3*8)) & 0xff;
861 addr[5] = (data >> (2*8)) & 0xff;
862 addr[6] = (data >> (1*8)) & 0xff;
863 addr[7] = (data >> (0*8)) & 0xff;
252b5132
RH
864}
865
866void
0e3c1eeb 867bfd_putl64 (uint64_t data, void *p)
252b5132 868{
a50b1753 869 bfd_byte *addr = (bfd_byte *) p;
edeb6e24
AM
870 addr[7] = (data >> (7*8)) & 0xff;
871 addr[6] = (data >> (6*8)) & 0xff;
872 addr[5] = (data >> (5*8)) & 0xff;
873 addr[4] = (data >> (4*8)) & 0xff;
874 addr[3] = (data >> (3*8)) & 0xff;
875 addr[2] = (data >> (2*8)) & 0xff;
876 addr[1] = (data >> (1*8)) & 0xff;
877 addr[0] = (data >> (0*8)) & 0xff;
252b5132 878}
8c603c85
NC
879
880void
0e3c1eeb 881bfd_put_bits (uint64_t data, void *p, int bits, bool big_p)
8c603c85 882{
a50b1753 883 bfd_byte *addr = (bfd_byte *) p;
8c603c85
NC
884 int i;
885 int bytes;
886
887 if (bits % 8 != 0)
888 abort ();
889
890 bytes = bits / 8;
891 for (i = 0; i < bytes; i++)
892 {
91d6fa6a 893 int addr_index = big_p ? bytes - i - 1 : i;
8c603c85 894
91d6fa6a 895 addr[addr_index] = data & 0xff;
8c603c85
NC
896 data >>= 8;
897 }
898}
899
0e3c1eeb 900uint64_t
0a1b45a2 901bfd_get_bits (const void *p, int bits, bool big_p)
8c603c85 902{
a50b1753 903 const bfd_byte *addr = (const bfd_byte *) p;
0e3c1eeb 904 uint64_t data;
8c603c85
NC
905 int i;
906 int bytes;
907
908 if (bits % 8 != 0)
909 abort ();
910
911 data = 0;
912 bytes = bits / 8;
913 for (i = 0; i < bytes; i++)
914 {
91d6fa6a 915 int addr_index = big_p ? i : bytes - i - 1;
509945ae 916
91d6fa6a 917 data = (data << 8) | addr[addr_index];
8c603c85
NC
918 }
919
920 return data;
921}
252b5132
RH
922\f
923/* Default implementation */
924
0a1b45a2 925bool
c58b9523
AM
926_bfd_generic_get_section_contents (bfd *abfd,
927 sec_ptr section,
928 void *location,
929 file_ptr offset,
930 bfd_size_type count)
252b5132 931{
eea6121a 932 bfd_size_type sz;
0bff3f4b 933 if (count == 0)
0a1b45a2 934 return true;
0bff3f4b 935
4a114e3e
L
936 if (section->compress_status != COMPRESS_SECTION_NONE)
937 {
4eca0228 938 _bfd_error_handler
695344c0 939 /* xgettext:c-format */
871b3ab2 940 (_("%pB: unable to get decompressed section %pA"),
4a114e3e
L
941 abfd, section);
942 bfd_set_error (bfd_error_invalid_operation);
0a1b45a2 943 return false;
4a114e3e
L
944 }
945
20d8836e 946 sz = bfd_get_section_limit_octets (abfd, section);
e62071b6 947 if (offset + count < count
0630b49c 948 || offset + count > sz
328ce951
L
949 || (abfd->my_archive != NULL
950 && !bfd_is_thin_archive (abfd->my_archive)
951 && ((ufile_ptr) section->filepos + offset + count
952 > arelt_size (abfd))))
0bff3f4b
ILT
953 {
954 bfd_set_error (bfd_error_invalid_operation);
0a1b45a2 955 return false;
0bff3f4b
ILT
956 }
957
958 if (bfd_seek (abfd, section->filepos + offset, SEEK_SET) != 0
dc810e39 959 || bfd_bread (location, count, abfd) != count)
0a1b45a2 960 return false;
0bff3f4b 961
0a1b45a2 962 return true;
252b5132
RH
963}
964
0a1b45a2 965bool
c58b9523
AM
966_bfd_generic_get_section_contents_in_window
967 (bfd *abfd ATTRIBUTE_UNUSED,
968 sec_ptr section ATTRIBUTE_UNUSED,
969 bfd_window *w ATTRIBUTE_UNUSED,
970 file_ptr offset ATTRIBUTE_UNUSED,
971 bfd_size_type count ATTRIBUTE_UNUSED)
252b5132
RH
972{
973#ifdef USE_MMAP
eea6121a
AM
974 bfd_size_type sz;
975
252b5132 976 if (count == 0)
0a1b45a2 977 return true;
c58b9523
AM
978 if (abfd->xvec->_bfd_get_section_contents
979 != _bfd_generic_get_section_contents)
252b5132
RH
980 {
981 /* We don't know what changes the bfd's get_section_contents
982 method may have to make. So punt trying to map the file
983 window, and let get_section_contents do its thing. */
984 /* @@ FIXME : If the internal window has a refcount of 1 and was
985 allocated with malloc instead of mmap, just reuse it. */
986 bfd_free_window (w);
c58b9523 987 w->i = bfd_zmalloc (sizeof (bfd_window_internal));
252b5132 988 if (w->i == NULL)
0a1b45a2 989 return false;
c58b9523 990 w->i->data = bfd_malloc (count);
252b5132
RH
991 if (w->i->data == NULL)
992 {
993 free (w->i);
994 w->i = NULL;
0a1b45a2 995 return false;
252b5132
RH
996 }
997 w->i->mapped = 0;
998 w->i->refcount = 1;
999 w->size = w->i->size = count;
1000 w->data = w->i->data;
1001 return bfd_get_section_contents (abfd, section, w->data, offset, count);
1002 }
e57278ef
AM
1003 if (abfd->direction != write_direction && section->rawsize != 0)
1004 sz = section->rawsize;
1005 else
1006 sz = section->size;
328ce951
L
1007 if (offset + count < count
1008 || offset + count > sz
1009 || (abfd->my_archive != NULL
1010 && !bfd_is_thin_archive (abfd->my_archive)
1011 && ((ufile_ptr) section->filepos + offset + count
1012 > arelt_size (abfd)))
82e51918 1013 || ! bfd_get_file_window (abfd, section->filepos + offset, count, w,
0a1b45a2
AM
1014 true))
1015 return false;
1016 return true;
252b5132
RH
1017#else
1018 abort ();
1019#endif
1020}
1021
1022/* This generic function can only be used in implementations where creating
1023 NEW sections is disallowed. It is useful in patching existing sections
1024 in read-write files, though. See other set_section_contents functions
1025 to see why it doesn't work for new sections. */
0a1b45a2 1026bool
c58b9523
AM
1027_bfd_generic_set_section_contents (bfd *abfd,
1028 sec_ptr section,
0f867abe 1029 const void *location,
c58b9523
AM
1030 file_ptr offset,
1031 bfd_size_type count)
252b5132
RH
1032{
1033 if (count == 0)
0a1b45a2 1034 return true;
252b5132 1035
dc810e39
AM
1036 if (bfd_seek (abfd, section->filepos + offset, SEEK_SET) != 0
1037 || bfd_bwrite (location, count, abfd) != count)
0a1b45a2 1038 return false;
252b5132 1039
0a1b45a2 1040 return true;
252b5132
RH
1041}
1042
1043/*
1044INTERNAL_FUNCTION
1045 bfd_log2
1046
1047SYNOPSIS
dc810e39 1048 unsigned int bfd_log2 (bfd_vma x);
252b5132
RH
1049
1050DESCRIPTION
1051 Return the log base 2 of the value supplied, rounded up. E.g., an
dc810e39 1052 @var{x} of 1025 returns 11. A @var{x} of 0 returns 0.
252b5132
RH
1053*/
1054
1055unsigned int
c58b9523 1056bfd_log2 (bfd_vma x)
252b5132
RH
1057{
1058 unsigned int result = 0;
1059
9e6619e2
AM
1060 if (x <= 1)
1061 return result;
1062 --x;
1063 do
252b5132 1064 ++result;
9e6619e2 1065 while ((x >>= 1) != 0);
252b5132
RH
1066 return result;
1067}
1068
0a1b45a2 1069bool
c58b9523 1070bfd_generic_is_local_label_name (bfd *abfd, const char *name)
252b5132
RH
1071{
1072 char locals_prefix = (bfd_get_symbol_leading_char (abfd) == '_') ? 'L' : '.';
1073
b34976b6 1074 return name[0] == locals_prefix;
252b5132
RH
1075}
1076
dc810e39
AM
1077/* Give a warning at runtime if someone compiles code which calls
1078 old routines. */
ca09e32b 1079
dc810e39 1080void
8c8402cc
PA
1081_bfd_warn_deprecated (const char *what,
1082 const char *file,
1083 int line,
1084 const char *func)
dc810e39
AM
1085{
1086 /* Poor man's tracking of functions we've already warned about. */
1087 static size_t mask = 0;
1088
1089 if (~(size_t) func & ~mask)
1090 {
4a97a0e5 1091 fflush (stdout);
73722af0 1092 /* Note: separate sentences in order to allow
ca09e32b 1093 for translation into other languages. */
dc810e39 1094 if (func)
695344c0 1095 /* xgettext:c-format */
ca09e32b
NC
1096 fprintf (stderr, _("Deprecated %s called at %s line %d in %s\n"),
1097 what, file, line, func);
dc810e39 1098 else
ca09e32b 1099 fprintf (stderr, _("Deprecated %s called\n"), what);
4a97a0e5 1100 fflush (stderr);
dc810e39
AM
1101 mask |= ~(size_t) func;
1102 }
1103}
c0c28ab8
L
1104
1105/* Helper function for reading uleb128 encoded data. */
1106
1107bfd_vma
4265548c
PA
1108_bfd_read_unsigned_leb128 (bfd *abfd ATTRIBUTE_UNUSED,
1109 bfd_byte *buf,
1110 unsigned int *bytes_read_ptr)
c0c28ab8
L
1111{
1112 bfd_vma result;
1113 unsigned int num_read;
f075ee0c 1114 unsigned int shift;
c0c28ab8
L
1115 unsigned char byte;
1116
1117 result = 0;
1118 shift = 0;
1119 num_read = 0;
1120 do
1121 {
f075ee0c 1122 byte = bfd_get_8 (abfd, buf);
c0c28ab8
L
1123 buf++;
1124 num_read++;
7b54cadd
AM
1125 if (shift < 8 * sizeof (result))
1126 {
1127 result |= (((bfd_vma) byte & 0x7f) << shift);
1128 shift += 7;
1129 }
c0c28ab8
L
1130 }
1131 while (byte & 0x80);
1132 *bytes_read_ptr = num_read;
1133 return result;
1134}
1135
574ec108 1136/* Read in a LEB128 encoded value from ABFD starting at *PTR.
f64e188b 1137 If SIGN is true, return a signed LEB128 value.
574ec108 1138 *PTR is incremented by the number of bytes read.
f64e188b
NC
1139 No bytes will be read at address END or beyond. */
1140
1141bfd_vma
4265548c 1142_bfd_safe_read_leb128 (bfd *abfd ATTRIBUTE_UNUSED,
574ec108 1143 bfd_byte **ptr,
0a1b45a2 1144 bool sign,
4265548c 1145 const bfd_byte * const end)
f64e188b
NC
1146{
1147 bfd_vma result = 0;
f64e188b
NC
1148 unsigned int shift = 0;
1149 unsigned char byte = 0;
574ec108 1150 bfd_byte *data = *ptr;
f64e188b
NC
1151
1152 while (data < end)
1153 {
1154 byte = bfd_get_8 (abfd, data);
1155 data++;
7b54cadd
AM
1156 if (shift < 8 * sizeof (result))
1157 {
1158 result |= ((bfd_vma) (byte & 0x7f)) << shift;
1159 shift += 7;
1160 }
f64e188b
NC
1161 if ((byte & 0x80) == 0)
1162 break;
1163 }
1164
574ec108 1165 *ptr = data;
f64e188b
NC
1166
1167 if (sign && (shift < 8 * sizeof (result)) && (byte & 0x40))
29f628db 1168 result |= -((bfd_vma) 1 << shift);
f64e188b
NC
1169
1170 return result;
1171}
1172
c0c28ab8
L
1173/* Helper function for reading sleb128 encoded data. */
1174
1175bfd_signed_vma
4265548c
PA
1176_bfd_read_signed_leb128 (bfd *abfd ATTRIBUTE_UNUSED,
1177 bfd_byte *buf,
1178 unsigned int *bytes_read_ptr)
c0c28ab8
L
1179{
1180 bfd_vma result;
f075ee0c
AM
1181 unsigned int shift;
1182 unsigned int num_read;
c0c28ab8
L
1183 unsigned char byte;
1184
1185 result = 0;
1186 shift = 0;
1187 num_read = 0;
1188 do
1189 {
f075ee0c 1190 byte = bfd_get_8 (abfd, buf);
c0c28ab8
L
1191 buf ++;
1192 num_read ++;
7b54cadd
AM
1193 if (shift < 8 * sizeof (result))
1194 {
1195 result |= (((bfd_vma) byte & 0x7f) << shift);
1196 shift += 7;
1197 }
c0c28ab8
L
1198 }
1199 while (byte & 0x80);
f075ee0c 1200 if (shift < 8 * sizeof (result) && (byte & 0x40))
c0c28ab8
L
1201 result |= (((bfd_vma) -1) << shift);
1202 *bytes_read_ptr = num_read;
1203 return result;
1204}
5420f73d 1205
7d81bc93
JL
1206/* Write VAL in uleb128 format to P.
1207 END indicates the last byte of allocated space for the uleb128 value to fit
1208 in.
1209 Return a pointer to the byte following the last byte that was written, or
1210 NULL if the uleb128 value does not fit in the allocated space between P and
1211 END. */
1212bfd_byte *
1213_bfd_write_unsigned_leb128 (bfd_byte *p, bfd_byte *end, bfd_vma val)
1214{
1215 bfd_byte c;
1216 do
1217 {
1218 if (p > end)
1219 return NULL;
1220 c = val & 0x7f;
1221 val >>= 7;
1222 if (val)
1223 c |= 0x80;
1224 *(p++) = c;
1225 }
1226 while (val);
1227 return p;
1228}
1229
0a1b45a2 1230bool
ccd2ec6a
L
1231_bfd_generic_init_private_section_data (bfd *ibfd ATTRIBUTE_UNUSED,
1232 asection *isec ATTRIBUTE_UNUSED,
1233 bfd *obfd ATTRIBUTE_UNUSED,
1234 asection *osec ATTRIBUTE_UNUSED,
1235 struct bfd_link_info *link_info ATTRIBUTE_UNUSED)
1236{
0a1b45a2 1237 return true;
ccd2ec6a 1238}