1 /* Generic BFD library interface and support routines.
2 Copyright (C) 1990-2015 Free Software Foundation, Inc.
3 Written by Cygnus Support.
5 This file is part of BFD, the Binary File Descriptor library.
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
9 the Free Software Foundation; either version 3 of the License, or
10 (at your option) any later version.
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.
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
19 Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston,
20 MA 02110-1301, USA. */
24 typedef bfd, Error reporting, BFD front end, BFD front end
29 A BFD has type <<bfd>>; objects of this type are the
30 cornerstone of any application using BFD. Using BFD
31 consists of making references though the BFD and to data in the BFD.
33 Here is the structure that defines the type <<bfd>>. It
34 contains the major data about the file and pointers
35 to the rest of the data.
43 . write_direction = 2,
47 .enum bfd_plugin_format
49 . bfd_plugin_uknown = 0,
56 . {* The filename the application opened the BFD with. *}
57 . const char *filename;
59 . {* A pointer to the target jump table. *}
60 . const struct bfd_target *xvec;
62 . {* The IOSTREAM, and corresponding IO vector that provide access
63 . to the file backing the BFD. *}
65 . const struct bfd_iovec *iovec;
67 . {* The caching routines use these to maintain a
68 . least-recently-used list of BFDs. *}
69 . struct bfd *lru_prev, *lru_next;
71 . {* When a file is closed by the caching routines, BFD retains
72 . state information on the file here... *}
75 . {* File modified time, if mtime_set is TRUE. *}
78 . {* A unique identifier of the BFD *}
81 . {* The format which belongs to the BFD. (object, core, etc.) *}
82 . ENUM_BITFIELD (bfd_format) format : 3;
84 . {* The direction with which the BFD was opened. *}
85 . ENUM_BITFIELD (bfd_direction) direction : 2;
87 . {* Format_specific flags. *}
88 . flagword flags : 18;
90 . {* Values that may appear in the flags field of a BFD. These also
91 . appear in the object_flags field of the bfd_target structure, where
92 . they indicate the set of flags used by that backend (not all flags
93 . are meaningful for all object file formats) (FIXME: at the moment,
94 . the object_flags values have mostly just been copied from backend
95 . to another, and are not necessarily correct). *}
97 .#define BFD_NO_FLAGS 0x00
99 . {* BFD contains relocation entries. *}
100 .#define HAS_RELOC 0x01
102 . {* BFD is directly executable. *}
105 . {* BFD has line number information (basically used for F_LNNO in a
107 .#define HAS_LINENO 0x04
109 . {* BFD has debugging information. *}
110 .#define HAS_DEBUG 0x08
112 . {* BFD has symbols. *}
113 .#define HAS_SYMS 0x10
115 . {* BFD has local symbols (basically used for F_LSYMS in a COFF
117 .#define HAS_LOCALS 0x20
119 . {* BFD is a dynamic object. *}
120 .#define DYNAMIC 0x40
122 . {* Text section is write protected (if D_PAGED is not set, this is
123 . like an a.out NMAGIC file) (the linker sets this by default, but
124 . clears it for -r or -N). *}
125 .#define WP_TEXT 0x80
127 . {* BFD is dynamically paged (this is like an a.out ZMAGIC file) (the
128 . linker sets this by default, but clears it for -r or -n or -N). *}
129 .#define D_PAGED 0x100
131 . {* BFD is relaxable (this means that bfd_relax_section may be able to
132 . do something) (sometimes bfd_relax_section can do something even if
133 . this is not set). *}
134 .#define BFD_IS_RELAXABLE 0x200
136 . {* This may be set before writing out a BFD to request using a
137 . traditional format. For example, this is used to request that when
138 . writing out an a.out object the symbols not be hashed to eliminate
140 .#define BFD_TRADITIONAL_FORMAT 0x400
142 . {* This flag indicates that the BFD contents are actually cached
143 . in memory. If this is set, iostream points to a bfd_in_memory
145 .#define BFD_IN_MEMORY 0x800
147 . {* This BFD has been created by the linker and doesn't correspond
148 . to any input file. *}
149 .#define BFD_LINKER_CREATED 0x1000
151 . {* This may be set before writing out a BFD to request that it
152 . be written using values for UIDs, GIDs, timestamps, etc. that
153 . will be consistent from run to run. *}
154 .#define BFD_DETERMINISTIC_OUTPUT 0x2000
156 . {* Compress sections in this BFD. *}
157 .#define BFD_COMPRESS 0x4000
159 . {* Decompress sections in this BFD. *}
160 .#define BFD_DECOMPRESS 0x8000
162 . {* BFD is a dummy, for plugins. *}
163 .#define BFD_PLUGIN 0x10000
165 . {* Compress sections in this BFD with SHF_COMPRESSED from gABI. *}
166 .#define BFD_COMPRESS_GABI 0x20000
168 . {* Flags bits to be saved in bfd_preserve_save. *}
169 .#define BFD_FLAGS_SAVED \
170 . (BFD_IN_MEMORY | BFD_COMPRESS | BFD_DECOMPRESS | BFD_PLUGIN \
171 . | BFD_COMPRESS_GABI)
173 . {* Flags bits which are for BFD use only. *}
174 .#define BFD_FLAGS_FOR_BFD_USE_MASK \
175 . (BFD_IN_MEMORY | BFD_COMPRESS | BFD_DECOMPRESS | BFD_LINKER_CREATED \
176 . | BFD_PLUGIN | BFD_TRADITIONAL_FORMAT | BFD_DETERMINISTIC_OUTPUT \
177 . | BFD_COMPRESS_GABI)
179 . {* Is the file descriptor being cached? That is, can it be closed as
180 . needed, and re-opened when accessed later? *}
181 . unsigned int cacheable : 1;
183 . {* Marks whether there was a default target specified when the
184 . BFD was opened. This is used to select which matching algorithm
185 . to use to choose the back end. *}
186 . unsigned int target_defaulted : 1;
188 . {* ... and here: (``once'' means at least once). *}
189 . unsigned int opened_once : 1;
191 . {* Set if we have a locally maintained mtime value, rather than
192 . getting it from the file each time. *}
193 . unsigned int mtime_set : 1;
195 . {* Flag set if symbols from this BFD should not be exported. *}
196 . unsigned int no_export : 1;
198 . {* Remember when output has begun, to stop strange things
200 . unsigned int output_has_begun : 1;
202 . {* Have archive map. *}
203 . unsigned int has_armap : 1;
205 . {* Set if this is a thin archive. *}
206 . unsigned int is_thin_archive : 1;
208 . {* Set if only required symbols should be added in the link hash table for
209 . this object. Used by VMS linkers. *}
210 . unsigned int selective_search : 1;
212 . {* Set if this is the linker output BFD. *}
213 . unsigned int is_linker_output : 1;
215 . {* Set if this is the linker input BFD. *}
216 . unsigned int is_linker_input : 1;
218 . {* If this is an input for a compiler plug-in library. *}
219 . ENUM_BITFIELD (bfd_plugin_format) plugin_format : 2;
221 . {* Set if this is a plugin output file. *}
222 . unsigned int lto_output : 1;
224 . {* Set to dummy BFD created when claimed by a compiler plug-in
226 . bfd *plugin_dummy_bfd;
228 . {* Currently my_archive is tested before adding origin to
229 . anything. I believe that this can become always an add of
230 . origin, with origin set to 0 for non archive files. *}
233 . {* The origin in the archive of the proxy entry. This will
234 . normally be the same as origin, except for thin archives,
235 . when it will contain the current offset of the proxy in the
236 . thin archive rather than the offset of the bfd in its actual
238 . ufile_ptr proxy_origin;
240 . {* A hash table for section names. *}
241 . struct bfd_hash_table section_htab;
243 . {* Pointer to linked list of sections. *}
244 . struct bfd_section *sections;
246 . {* The last section on the section list. *}
247 . struct bfd_section *section_last;
249 . {* The number of sections. *}
250 . unsigned int section_count;
252 . {* A field used by _bfd_generic_link_add_archive_symbols. This will
253 . be used only for archive elements. *}
256 . {* Stuff only useful for object files:
257 . The start address. *}
258 . bfd_vma start_address;
260 . {* Symbol table for output BFD (with symcount entries).
261 . Also used by the linker to cache input BFD symbols. *}
262 . struct bfd_symbol **outsymbols;
264 . {* Used for input and output. *}
265 . unsigned int symcount;
267 . {* Used for slurped dynamic symbol tables. *}
268 . unsigned int dynsymcount;
270 . {* Pointer to structure which contains architecture information. *}
271 . const struct bfd_arch_info *arch_info;
273 . {* Stuff only useful for archives. *}
275 . struct bfd *my_archive; {* The containing archive BFD. *}
276 . struct bfd *archive_next; {* The next BFD in the archive. *}
277 . struct bfd *archive_head; {* The first BFD in the archive. *}
278 . struct bfd *nested_archives; {* List of nested archive in a flattened
282 . {* For input BFDs, a chain of BFDs involved in a link. *}
284 . {* For output BFD, the linker hash table. *}
285 . struct bfd_link_hash_table *hash;
288 . {* Used by the back end to hold private data. *}
291 . struct aout_data_struct *aout_data;
292 . struct artdata *aout_ar_data;
293 . struct _oasys_data *oasys_obj_data;
294 . struct _oasys_ar_data *oasys_ar_data;
295 . struct coff_tdata *coff_obj_data;
296 . struct pe_tdata *pe_obj_data;
297 . struct xcoff_tdata *xcoff_obj_data;
298 . struct ecoff_tdata *ecoff_obj_data;
299 . struct ieee_data_struct *ieee_data;
300 . struct ieee_ar_data_struct *ieee_ar_data;
301 . struct srec_data_struct *srec_data;
302 . struct verilog_data_struct *verilog_data;
303 . struct ihex_data_struct *ihex_data;
304 . struct tekhex_data_struct *tekhex_data;
305 . struct elf_obj_tdata *elf_obj_data;
306 . struct nlm_obj_tdata *nlm_obj_data;
307 . struct bout_data_struct *bout_data;
308 . struct mmo_data_struct *mmo_data;
309 . struct sun_core_struct *sun_core_data;
310 . struct sco5_core_struct *sco5_core_data;
311 . struct trad_core_struct *trad_core_data;
312 . struct som_data_struct *som_data;
313 . struct hpux_core_struct *hpux_core_data;
314 . struct hppabsd_core_struct *hppabsd_core_data;
315 . struct sgi_core_struct *sgi_core_data;
316 . struct lynx_core_struct *lynx_core_data;
317 . struct osf_core_struct *osf_core_data;
318 . struct cisco_core_struct *cisco_core_data;
319 . struct versados_data_struct *versados_data;
320 . struct netbsd_core_struct *netbsd_core_data;
321 . struct mach_o_data_struct *mach_o_data;
322 . struct mach_o_fat_data_struct *mach_o_fat_data;
323 . struct plugin_data_struct *plugin_data;
324 . struct bfd_pef_data_struct *pef_data;
325 . struct bfd_pef_xlib_data_struct *pef_xlib_data;
326 . struct bfd_sym_data_struct *sym_data;
331 . {* Used by the application to hold private data. *}
334 . {* Where all the allocated stuff under this BFD goes. This is a
335 . struct objalloc *, but we use void * to avoid requiring the inclusion
340 .{* See note beside bfd_set_section_userdata. *}
341 .static inline bfd_boolean
342 .bfd_set_cacheable (bfd * abfd, bfd_boolean val)
344 . abfd->cacheable = val;
354 #include "libiberty.h"
355 #include "demangle.h"
356 #include "safe-ctype.h"
359 #include "coff/internal.h"
360 #include "coff/sym.h"
362 #include "libecoff.h"
367 #define EXIT_FAILURE 1
371 /* provide storage for subsystem, stack and heap data which may have been
372 passed in on the command line. Ld puts this data into a bfd_link_info
373 struct which ultimately gets passed in to the bfd. When it arrives, copy
374 it to the following struct so that the data will be available in coffcode.h
375 where it is needed. The typedef's used are defined in bfd.h */
379 Error reporting, Miscellaneous, typedef bfd, BFD front end
384 Most BFD functions return nonzero on success (check their
385 individual documentation for precise semantics). On an error,
386 they call <<bfd_set_error>> to set an error condition that callers
387 can check by calling <<bfd_get_error>>.
388 If that returns <<bfd_error_system_call>>, then check
391 The easiest way to report a BFD error to the user is to
395 Type <<bfd_error_type>>
397 The values returned by <<bfd_get_error>> are defined by the
398 enumerated type <<bfd_error_type>>.
402 .typedef enum bfd_error
404 . bfd_error_no_error = 0,
405 . bfd_error_system_call,
406 . bfd_error_invalid_target,
407 . bfd_error_wrong_format,
408 . bfd_error_wrong_object_format,
409 . bfd_error_invalid_operation,
410 . bfd_error_no_memory,
411 . bfd_error_no_symbols,
412 . bfd_error_no_armap,
413 . bfd_error_no_more_archived_files,
414 . bfd_error_malformed_archive,
415 . bfd_error_missing_dso,
416 . bfd_error_file_not_recognized,
417 . bfd_error_file_ambiguously_recognized,
418 . bfd_error_no_contents,
419 . bfd_error_nonrepresentable_section,
420 . bfd_error_no_debug_section,
421 . bfd_error_bad_value,
422 . bfd_error_file_truncated,
423 . bfd_error_file_too_big,
424 . bfd_error_on_input,
425 . bfd_error_invalid_error_code
431 static bfd_error_type bfd_error = bfd_error_no_error;
432 static bfd *input_bfd = NULL;
433 static bfd_error_type input_error = bfd_error_no_error;
435 const char *const bfd_errmsgs[] =
438 N_("System call error"),
439 N_("Invalid bfd target"),
440 N_("File in wrong format"),
441 N_("Archive object file in wrong format"),
442 N_("Invalid operation"),
443 N_("Memory exhausted"),
445 N_("Archive has no index; run ranlib to add one"),
446 N_("No more archived files"),
447 N_("Malformed archive"),
448 N_("DSO missing from command line"),
449 N_("File format not recognized"),
450 N_("File format is ambiguous"),
451 N_("Section has no contents"),
452 N_("Nonrepresentable section on output"),
453 N_("Symbol needs debug section which does not exist"),
455 N_("File truncated"),
457 N_("Error reading %s: %s"),
458 N_("#<Invalid error code>")
466 bfd_error_type bfd_get_error (void);
469 Return the current BFD error condition.
483 void bfd_set_error (bfd_error_type error_tag, ...);
486 Set the BFD error condition to be @var{error_tag}.
487 If @var{error_tag} is bfd_error_on_input, then this function
488 takes two more parameters, the input bfd where the error
489 occurred, and the bfd_error_type error.
493 bfd_set_error (bfd_error_type error_tag, ...)
495 bfd_error = error_tag;
496 if (error_tag == bfd_error_on_input)
498 /* This is an error that occurred during bfd_close when
499 writing an archive, but on one of the input files. */
502 va_start (ap, error_tag);
503 input_bfd = va_arg (ap, bfd *);
504 input_error = (bfd_error_type) va_arg (ap, int);
505 if (input_error >= bfd_error_on_input)
516 const char *bfd_errmsg (bfd_error_type error_tag);
519 Return a string describing the error @var{error_tag}, or
520 the system error if @var{error_tag} is <<bfd_error_system_call>>.
524 bfd_errmsg (bfd_error_type error_tag)
529 if (error_tag == bfd_error_on_input)
532 const char *msg = bfd_errmsg (input_error);
534 if (asprintf (&buf, _(bfd_errmsgs [error_tag]), input_bfd->filename, msg)
538 /* Ick, what to do on out of memory? */
542 if (error_tag == bfd_error_system_call)
543 return xstrerror (errno);
545 if (error_tag > bfd_error_invalid_error_code)
546 error_tag = bfd_error_invalid_error_code; /* sanity check */
548 return _(bfd_errmsgs [error_tag]);
556 void bfd_perror (const char *message);
559 Print to the standard error stream a string describing the
560 last BFD error that occurred, or the last system error if
561 the last BFD error was a system call failure. If @var{message}
562 is non-NULL and non-empty, the error string printed is preceded
563 by @var{message}, a colon, and a space. It is followed by a newline.
567 bfd_perror (const char *message)
570 if (message == NULL || *message == '\0')
571 fprintf (stderr, "%s\n", bfd_errmsg (bfd_get_error ()));
573 fprintf (stderr, "%s: %s\n", message, bfd_errmsg (bfd_get_error ()));
581 Some BFD functions want to print messages describing the
582 problem. They call a BFD error handler function. This
583 function may be overridden by the program.
585 The BFD error handler acts like printf.
589 .typedef void (*bfd_error_handler_type) (const char *, ...);
593 /* The program name used when printing BFD error messages. */
595 static const char *_bfd_error_program_name;
597 /* This is the default routine to handle BFD error messages.
598 Like fprintf (stderr, ...), but also handles some extra format specifiers.
600 %A section name from section. For group components, print group name too.
601 %B file name from bfd. For archive components, prints archive too.
603 Note - because these two extra format specifiers require special handling
604 they are scanned for and processed in this function, before calling
605 vfprintf. This means that the *arguments* for these format specifiers
606 must be the first ones in the variable argument list, regardless of where
607 the specifiers appear in the format string. Thus for example calling
608 this function with a format string of:
610 "blah %s blah %A blah %d blah %B"
612 would involve passing the arguments as:
614 "blah %s blah %A blah %d blah %B",
622 _bfd_default_error_handler (const char *fmt, ...)
626 const char *new_fmt, *p;
630 /* PR 4992: Don't interrupt output being sent to stdout. */
633 if (_bfd_error_program_name != NULL)
634 fprintf (stderr, "%s: ", _bfd_error_program_name);
636 fprintf (stderr, "BFD: ");
642 /* Reserve enough space for the existing format string. */
643 avail -= strlen (fmt) + 1;
645 _exit (EXIT_FAILURE);
651 size_t len, extra, trim;
654 if (p == NULL || p[1] == '\0')
659 memcpy (bufp, fmt, len + 1);
664 if (p[1] == 'A' || p[1] == 'B')
667 memcpy (bufp, fmt, len);
672 /* If we run out of space, tough, you lose your ridiculously
673 long file or section name. It's not safe to try to alloc
674 memory here; We might be printing an out of memory message. */
685 bfd *abfd = va_arg (ap, bfd *);
688 /* Invoking %B with a null bfd pointer is an internal error. */
690 else if (abfd->my_archive)
691 snprintf (bufp, avail, "%s(%s)",
692 abfd->my_archive->filename, abfd->filename);
694 snprintf (bufp, avail, "%s", abfd->filename);
698 asection *sec = va_arg (ap, asection *);
700 const char *group = NULL;
701 struct coff_comdat_info *ci;
704 /* Invoking %A with a null section pointer is an internal error. */
708 && bfd_get_flavour (abfd) == bfd_target_elf_flavour
709 && elf_next_in_group (sec) != NULL
710 && (sec->flags & SEC_GROUP) == 0)
711 group = elf_group_name (sec);
712 else if (abfd != NULL
713 && bfd_get_flavour (abfd) == bfd_target_coff_flavour
714 && (ci = bfd_coff_get_comdat_section (sec->owner,
718 snprintf (bufp, avail, "%s[%s]", sec->name, group);
720 snprintf (bufp, avail, "%s", sec->name);
723 avail = avail - len + 2;
725 /* We need to replace any '%' we printed by "%%".
726 First count how many. */
730 while ((q = strchr (q, '%')) != NULL)
736 /* If there isn't room, trim off the end of the string. */
741 trim = extra - avail;
754 /* Now double all '%' chars, shuffling the string as we go. */
757 while ((q[extra] = *q) != '%')
767 vfprintf (stderr, new_fmt, ap);
770 /* On AIX, putc is implemented as a macro that triggers a -Wunused-value
771 warning, so use the fputc function to avoid it. */
772 fputc ('\n', stderr);
776 /* This is a function pointer to the routine which should handle BFD
777 error messages. It is called when a BFD routine encounters an
778 error for which it wants to print a message. Going through a
779 function pointer permits a program linked against BFD to intercept
780 the messages and deal with them itself. */
782 bfd_error_handler_type _bfd_error_handler = _bfd_default_error_handler;
786 bfd_set_error_handler
789 bfd_error_handler_type bfd_set_error_handler (bfd_error_handler_type);
792 Set the BFD error handler function. Returns the previous
796 bfd_error_handler_type
797 bfd_set_error_handler (bfd_error_handler_type pnew)
799 bfd_error_handler_type pold;
801 pold = _bfd_error_handler;
802 _bfd_error_handler = pnew;
808 bfd_set_error_program_name
811 void bfd_set_error_program_name (const char *);
814 Set the program name to use when printing a BFD error. This
815 is printed before the error message followed by a colon and
816 space. The string must not be changed after it is passed to
821 bfd_set_error_program_name (const char *name)
823 _bfd_error_program_name = name;
828 bfd_get_error_handler
831 bfd_error_handler_type bfd_get_error_handler (void);
834 Return the BFD error handler function.
837 bfd_error_handler_type
838 bfd_get_error_handler (void)
840 return _bfd_error_handler;
847 If BFD finds an internal inconsistency, the bfd assert
848 handler is called with information on the BFD version, BFD
849 source file and line. If this happens, most programs linked
850 against BFD are expected to want to exit with an error, or mark
851 the current BFD operation as failed, so it is recommended to
852 override the default handler, which just calls
853 _bfd_error_handler and continues.
857 .typedef void (*bfd_assert_handler_type) (const char *bfd_formatmsg,
858 . const char *bfd_version,
859 . const char *bfd_file,
864 /* Note the use of bfd_ prefix on the parameter names above: we want to
865 show which one is the message and which is the version by naming the
866 parameters, but avoid polluting the program-using-bfd namespace as
867 the typedef is visible in the exported headers that the program
868 includes. Below, it's just for consistency. */
871 _bfd_default_assert_handler (const char *bfd_formatmsg,
872 const char *bfd_version,
873 const char *bfd_file,
877 (*_bfd_error_handler) (bfd_formatmsg, bfd_version, bfd_file, bfd_line);
880 /* Similar to _bfd_error_handler, a program can decide to exit on an
881 internal BFD error. We use a non-variadic type to simplify passing
882 on parameters to other functions, e.g. _bfd_error_handler. */
884 bfd_assert_handler_type _bfd_assert_handler = _bfd_default_assert_handler;
888 bfd_set_assert_handler
891 bfd_assert_handler_type bfd_set_assert_handler (bfd_assert_handler_type);
894 Set the BFD assert handler function. Returns the previous
898 bfd_assert_handler_type
899 bfd_set_assert_handler (bfd_assert_handler_type pnew)
901 bfd_assert_handler_type pold;
903 pold = _bfd_assert_handler;
904 _bfd_assert_handler = pnew;
910 bfd_get_assert_handler
913 bfd_assert_handler_type bfd_get_assert_handler (void);
916 Return the BFD assert handler function.
919 bfd_assert_handler_type
920 bfd_get_assert_handler (void)
922 return _bfd_assert_handler;
927 Miscellaneous, Memory Usage, Error reporting, BFD front end
933 Miscellaneous functions
938 bfd_get_reloc_upper_bound
941 long bfd_get_reloc_upper_bound (bfd *abfd, asection *sect);
944 Return the number of bytes required to store the
945 relocation information associated with section @var{sect}
946 attached to bfd @var{abfd}. If an error occurs, return -1.
951 bfd_get_reloc_upper_bound (bfd *abfd, sec_ptr asect)
953 if (abfd->format != bfd_object)
955 bfd_set_error (bfd_error_invalid_operation);
959 return BFD_SEND (abfd, _get_reloc_upper_bound, (abfd, asect));
964 bfd_canonicalize_reloc
967 long bfd_canonicalize_reloc
968 (bfd *abfd, asection *sec, arelent **loc, asymbol **syms);
971 Call the back end associated with the open BFD
972 @var{abfd} and translate the external form of the relocation
973 information attached to @var{sec} into the internal canonical
974 form. Place the table into memory at @var{loc}, which has
975 been preallocated, usually by a call to
976 <<bfd_get_reloc_upper_bound>>. Returns the number of relocs, or
979 The @var{syms} table is also needed for horrible internal magic
984 bfd_canonicalize_reloc (bfd *abfd,
989 if (abfd->format != bfd_object)
991 bfd_set_error (bfd_error_invalid_operation);
995 return BFD_SEND (abfd, _bfd_canonicalize_reloc,
996 (abfd, asect, location, symbols));
1005 (bfd *abfd, asection *sec, arelent **rel, unsigned int count);
1008 Set the relocation pointer and count within
1009 section @var{sec} to the values @var{rel} and @var{count}.
1010 The argument @var{abfd} is ignored.
1015 bfd_set_reloc (bfd *ignore_abfd ATTRIBUTE_UNUSED,
1020 asect->orelocation = location;
1021 asect->reloc_count = count;
1029 bfd_boolean bfd_set_file_flags (bfd *abfd, flagword flags);
1032 Set the flag word in the BFD @var{abfd} to the value @var{flags}.
1034 Possible errors are:
1035 o <<bfd_error_wrong_format>> - The target bfd was not of object format.
1036 o <<bfd_error_invalid_operation>> - The target bfd was open for reading.
1037 o <<bfd_error_invalid_operation>> -
1038 The flag word contained a bit which was not applicable to the
1039 type of file. E.g., an attempt was made to set the <<D_PAGED>> bit
1040 on a BFD format which does not support demand paging.
1045 bfd_set_file_flags (bfd *abfd, flagword flags)
1047 if (abfd->format != bfd_object)
1049 bfd_set_error (bfd_error_wrong_format);
1053 if (bfd_read_p (abfd))
1055 bfd_set_error (bfd_error_invalid_operation);
1059 bfd_get_file_flags (abfd) = flags;
1060 if ((flags & bfd_applicable_file_flags (abfd)) != flags)
1062 bfd_set_error (bfd_error_invalid_operation);
1070 bfd_assert (const char *file, int line)
1072 (*_bfd_assert_handler) (_("BFD %s assertion fail %s:%d"),
1073 BFD_VERSION_STRING, file, line);
1076 /* A more or less friendly abort message. In libbfd.h abort is
1077 defined to call this function. */
1080 _bfd_abort (const char *file, int line, const char *fn)
1083 (*_bfd_error_handler)
1084 (_("BFD %s internal error, aborting at %s line %d in %s\n"),
1085 BFD_VERSION_STRING, file, line, fn);
1087 (*_bfd_error_handler)
1088 (_("BFD %s internal error, aborting at %s line %d\n"),
1089 BFD_VERSION_STRING, file, line);
1090 (*_bfd_error_handler) (_("Please report this bug.\n"));
1091 _exit (EXIT_FAILURE);
1099 int bfd_get_arch_size (bfd *abfd);
1102 Returns the normalized architecture address size, in bits, as
1103 determined by the object file's format. By normalized, we mean
1104 either 32 or 64. For ELF, this information is included in the
1105 header. Use bfd_arch_bits_per_address for number of bits in
1106 the architecture address.
1109 Returns the arch size in bits if known, <<-1>> otherwise.
1113 bfd_get_arch_size (bfd *abfd)
1115 if (abfd->xvec->flavour == bfd_target_elf_flavour)
1116 return get_elf_backend_data (abfd)->s->arch_size;
1118 return bfd_arch_bits_per_address (abfd) > 32 ? 64 : 32;
1123 bfd_get_sign_extend_vma
1126 int bfd_get_sign_extend_vma (bfd *abfd);
1129 Indicates if the target architecture "naturally" sign extends
1130 an address. Some architectures implicitly sign extend address
1131 values when they are converted to types larger than the size
1132 of an address. For instance, bfd_get_start_address() will
1133 return an address sign extended to fill a bfd_vma when this is
1137 Returns <<1>> if the target architecture is known to sign
1138 extend addresses, <<0>> if the target architecture is known to
1139 not sign extend addresses, and <<-1>> otherwise.
1143 bfd_get_sign_extend_vma (bfd *abfd)
1147 if (bfd_get_flavour (abfd) == bfd_target_elf_flavour)
1148 return get_elf_backend_data (abfd)->sign_extend_vma;
1150 name = bfd_get_target (abfd);
1152 /* Return a proper value for DJGPP & PE COFF.
1153 This function is required for DWARF2 support, but there is
1154 no place to store this information in the COFF back end.
1155 Should enough other COFF targets add support for DWARF2,
1156 a place will have to be found. Until then, this hack will do. */
1157 if (CONST_STRNEQ (name, "coff-go32")
1158 || strcmp (name, "pe-i386") == 0
1159 || strcmp (name, "pei-i386") == 0
1160 || strcmp (name, "pe-x86-64") == 0
1161 || strcmp (name, "pei-x86-64") == 0
1162 || strcmp (name, "pe-arm-wince-little") == 0
1163 || strcmp (name, "pei-arm-wince-little") == 0
1164 || strcmp (name, "aixcoff-rs6000") == 0)
1167 if (CONST_STRNEQ (name, "mach-o"))
1170 bfd_set_error (bfd_error_wrong_format);
1176 bfd_set_start_address
1179 bfd_boolean bfd_set_start_address (bfd *abfd, bfd_vma vma);
1182 Make @var{vma} the entry point of output BFD @var{abfd}.
1185 Returns <<TRUE>> on success, <<FALSE>> otherwise.
1189 bfd_set_start_address (bfd *abfd, bfd_vma vma)
1191 abfd->start_address = vma;
1200 unsigned int bfd_get_gp_size (bfd *abfd);
1203 Return the maximum size of objects to be optimized using the GP
1204 register under MIPS ECOFF. This is typically set by the <<-G>>
1205 argument to the compiler, assembler or linker.
1209 bfd_get_gp_size (bfd *abfd)
1211 if (abfd->format == bfd_object)
1213 if (abfd->xvec->flavour == bfd_target_ecoff_flavour)
1214 return ecoff_data (abfd)->gp_size;
1215 else if (abfd->xvec->flavour == bfd_target_elf_flavour)
1216 return elf_gp_size (abfd);
1226 void bfd_set_gp_size (bfd *abfd, unsigned int i);
1229 Set the maximum size of objects to be optimized using the GP
1230 register under ECOFF or MIPS ELF. This is typically set by
1231 the <<-G>> argument to the compiler, assembler or linker.
1235 bfd_set_gp_size (bfd *abfd, unsigned int i)
1237 /* Don't try to set GP size on an archive or core file! */
1238 if (abfd->format != bfd_object)
1241 if (abfd->xvec->flavour == bfd_target_ecoff_flavour)
1242 ecoff_data (abfd)->gp_size = i;
1243 else if (abfd->xvec->flavour == bfd_target_elf_flavour)
1244 elf_gp_size (abfd) = i;
1247 /* Get the GP value. This is an internal function used by some of the
1248 relocation special_function routines on targets which support a GP
1252 _bfd_get_gp_value (bfd *abfd)
1256 if (abfd->format != bfd_object)
1259 if (abfd->xvec->flavour == bfd_target_ecoff_flavour)
1260 return ecoff_data (abfd)->gp;
1261 else if (abfd->xvec->flavour == bfd_target_elf_flavour)
1262 return elf_gp (abfd);
1267 /* Set the GP value. */
1270 _bfd_set_gp_value (bfd *abfd, bfd_vma v)
1274 if (abfd->format != bfd_object)
1277 if (abfd->xvec->flavour == bfd_target_ecoff_flavour)
1278 ecoff_data (abfd)->gp = v;
1279 else if (abfd->xvec->flavour == bfd_target_elf_flavour)
1288 bfd_vma bfd_scan_vma (const char *string, const char **end, int base);
1291 Convert, like <<strtoul>>, a numerical expression
1292 @var{string} into a <<bfd_vma>> integer, and return that integer.
1293 (Though without as many bells and whistles as <<strtoul>>.)
1294 The expression is assumed to be unsigned (i.e., positive).
1295 If given a @var{base}, it is used as the base for conversion.
1296 A base of 0 causes the function to interpret the string
1297 in hex if a leading "0x" or "0X" is found, otherwise
1298 in octal if a leading zero is found, otherwise in decimal.
1300 If the value would overflow, the maximum <<bfd_vma>> value is
1305 bfd_scan_vma (const char *string, const char **end, int base)
1309 unsigned int cutlim;
1312 /* Let the host do it if possible. */
1313 if (sizeof (bfd_vma) <= sizeof (unsigned long))
1314 return strtoul (string, (char **) end, base);
1316 #ifdef HAVE_STRTOULL
1317 if (sizeof (bfd_vma) <= sizeof (unsigned long long))
1318 return strtoull (string, (char **) end, base);
1323 if (string[0] == '0')
1325 if ((string[1] == 'x') || (string[1] == 'X'))
1332 if ((base < 2) || (base > 36))
1337 && (string[1] == 'x' || string[1] == 'X')
1338 && ISXDIGIT (string[2]))
1343 cutoff = (~ (bfd_vma) 0) / (bfd_vma) base;
1344 cutlim = (~ (bfd_vma) 0) % (bfd_vma) base;
1352 if (ISDIGIT (digit))
1353 digit = digit - '0';
1354 else if (ISALPHA (digit))
1355 digit = TOUPPER (digit) - 'A' + 10;
1358 if (digit >= (unsigned int) base)
1360 if (value > cutoff || (value == cutoff && digit > cutlim))
1362 value = value * base + digit;
1367 value = ~ (bfd_vma) 0;
1377 bfd_copy_private_header_data
1380 bfd_boolean bfd_copy_private_header_data (bfd *ibfd, bfd *obfd);
1383 Copy private BFD header information from the BFD @var{ibfd} to the
1384 the BFD @var{obfd}. This copies information that may require
1385 sections to exist, but does not require symbol tables. Return
1386 <<true>> on success, <<false>> on error.
1387 Possible error returns are:
1389 o <<bfd_error_no_memory>> -
1390 Not enough memory exists to create private data for @var{obfd}.
1392 .#define bfd_copy_private_header_data(ibfd, obfd) \
1393 . BFD_SEND (obfd, _bfd_copy_private_header_data, \
1400 bfd_copy_private_bfd_data
1403 bfd_boolean bfd_copy_private_bfd_data (bfd *ibfd, bfd *obfd);
1406 Copy private BFD information from the BFD @var{ibfd} to the
1407 the BFD @var{obfd}. Return <<TRUE>> on success, <<FALSE>> on error.
1408 Possible error returns are:
1410 o <<bfd_error_no_memory>> -
1411 Not enough memory exists to create private data for @var{obfd}.
1413 .#define bfd_copy_private_bfd_data(ibfd, obfd) \
1414 . BFD_SEND (obfd, _bfd_copy_private_bfd_data, \
1421 bfd_merge_private_bfd_data
1424 bfd_boolean bfd_merge_private_bfd_data (bfd *ibfd, bfd *obfd);
1427 Merge private BFD information from the BFD @var{ibfd} to the
1428 the output file BFD @var{obfd} when linking. Return <<TRUE>>
1429 on success, <<FALSE>> on error. Possible error returns are:
1431 o <<bfd_error_no_memory>> -
1432 Not enough memory exists to create private data for @var{obfd}.
1434 .#define bfd_merge_private_bfd_data(ibfd, obfd) \
1435 . BFD_SEND (obfd, _bfd_merge_private_bfd_data, \
1442 bfd_set_private_flags
1445 bfd_boolean bfd_set_private_flags (bfd *abfd, flagword flags);
1448 Set private BFD flag information in the BFD @var{abfd}.
1449 Return <<TRUE>> on success, <<FALSE>> on error. Possible error
1452 o <<bfd_error_no_memory>> -
1453 Not enough memory exists to create private data for @var{obfd}.
1455 .#define bfd_set_private_flags(abfd, flags) \
1456 . BFD_SEND (abfd, _bfd_set_private_flags, (abfd, flags))
1465 The following functions exist but have not yet been documented.
1467 .#define bfd_sizeof_headers(abfd, info) \
1468 . BFD_SEND (abfd, _bfd_sizeof_headers, (abfd, info))
1470 .#define bfd_find_nearest_line(abfd, sec, syms, off, file, func, line) \
1471 . BFD_SEND (abfd, _bfd_find_nearest_line, \
1472 . (abfd, syms, sec, off, file, func, line, NULL))
1474 .#define bfd_find_nearest_line_discriminator(abfd, sec, syms, off, file, func, \
1476 . BFD_SEND (abfd, _bfd_find_nearest_line, \
1477 . (abfd, syms, sec, off, file, func, line, disc))
1479 .#define bfd_find_line(abfd, syms, sym, file, line) \
1480 . BFD_SEND (abfd, _bfd_find_line, \
1481 . (abfd, syms, sym, file, line))
1483 .#define bfd_find_inliner_info(abfd, file, func, line) \
1484 . BFD_SEND (abfd, _bfd_find_inliner_info, \
1485 . (abfd, file, func, line))
1487 .#define bfd_debug_info_start(abfd) \
1488 . BFD_SEND (abfd, _bfd_debug_info_start, (abfd))
1490 .#define bfd_debug_info_end(abfd) \
1491 . BFD_SEND (abfd, _bfd_debug_info_end, (abfd))
1493 .#define bfd_debug_info_accumulate(abfd, section) \
1494 . BFD_SEND (abfd, _bfd_debug_info_accumulate, (abfd, section))
1496 .#define bfd_stat_arch_elt(abfd, stat) \
1497 . BFD_SEND (abfd, _bfd_stat_arch_elt,(abfd, stat))
1499 .#define bfd_update_armap_timestamp(abfd) \
1500 . BFD_SEND (abfd, _bfd_update_armap_timestamp, (abfd))
1502 .#define bfd_set_arch_mach(abfd, arch, mach)\
1503 . BFD_SEND ( abfd, _bfd_set_arch_mach, (abfd, arch, mach))
1505 .#define bfd_relax_section(abfd, section, link_info, again) \
1506 . BFD_SEND (abfd, _bfd_relax_section, (abfd, section, link_info, again))
1508 .#define bfd_gc_sections(abfd, link_info) \
1509 . BFD_SEND (abfd, _bfd_gc_sections, (abfd, link_info))
1511 .#define bfd_lookup_section_flags(link_info, flag_info, section) \
1512 . BFD_SEND (abfd, _bfd_lookup_section_flags, (link_info, flag_info, section))
1514 .#define bfd_merge_sections(abfd, link_info) \
1515 . BFD_SEND (abfd, _bfd_merge_sections, (abfd, link_info))
1517 .#define bfd_is_group_section(abfd, sec) \
1518 . BFD_SEND (abfd, _bfd_is_group_section, (abfd, sec))
1520 .#define bfd_discard_group(abfd, sec) \
1521 . BFD_SEND (abfd, _bfd_discard_group, (abfd, sec))
1523 .#define bfd_link_hash_table_create(abfd) \
1524 . BFD_SEND (abfd, _bfd_link_hash_table_create, (abfd))
1526 .#define bfd_link_add_symbols(abfd, info) \
1527 . BFD_SEND (abfd, _bfd_link_add_symbols, (abfd, info))
1529 .#define bfd_link_just_syms(abfd, sec, info) \
1530 . BFD_SEND (abfd, _bfd_link_just_syms, (sec, info))
1532 .#define bfd_final_link(abfd, info) \
1533 . BFD_SEND (abfd, _bfd_final_link, (abfd, info))
1535 .#define bfd_free_cached_info(abfd) \
1536 . BFD_SEND (abfd, _bfd_free_cached_info, (abfd))
1538 .#define bfd_get_dynamic_symtab_upper_bound(abfd) \
1539 . BFD_SEND (abfd, _bfd_get_dynamic_symtab_upper_bound, (abfd))
1541 .#define bfd_print_private_bfd_data(abfd, file)\
1542 . BFD_SEND (abfd, _bfd_print_private_bfd_data, (abfd, file))
1544 .#define bfd_canonicalize_dynamic_symtab(abfd, asymbols) \
1545 . BFD_SEND (abfd, _bfd_canonicalize_dynamic_symtab, (abfd, asymbols))
1547 .#define bfd_get_synthetic_symtab(abfd, count, syms, dyncount, dynsyms, ret) \
1548 . BFD_SEND (abfd, _bfd_get_synthetic_symtab, (abfd, count, syms, \
1549 . dyncount, dynsyms, ret))
1551 .#define bfd_get_dynamic_reloc_upper_bound(abfd) \
1552 . BFD_SEND (abfd, _bfd_get_dynamic_reloc_upper_bound, (abfd))
1554 .#define bfd_canonicalize_dynamic_reloc(abfd, arels, asyms) \
1555 . BFD_SEND (abfd, _bfd_canonicalize_dynamic_reloc, (abfd, arels, asyms))
1557 .extern bfd_byte *bfd_get_relocated_section_contents
1558 . (bfd *, struct bfd_link_info *, struct bfd_link_order *, bfd_byte *,
1559 . bfd_boolean, asymbol **);
1565 bfd_get_relocated_section_contents (bfd *abfd,
1566 struct bfd_link_info *link_info,
1567 struct bfd_link_order *link_order,
1569 bfd_boolean relocatable,
1573 bfd_byte *(*fn) (bfd *, struct bfd_link_info *, struct bfd_link_order *,
1574 bfd_byte *, bfd_boolean, asymbol **);
1576 if (link_order->type == bfd_indirect_link_order)
1578 abfd2 = link_order->u.indirect.section->owner;
1585 fn = abfd2->xvec->_bfd_get_relocated_section_contents;
1587 return (*fn) (abfd, link_info, link_order, data, relocatable, symbols);
1590 /* Record information about an ELF program header. */
1593 bfd_record_phdr (bfd *abfd,
1595 bfd_boolean flags_valid,
1597 bfd_boolean at_valid,
1599 bfd_boolean includes_filehdr,
1600 bfd_boolean includes_phdrs,
1604 struct elf_segment_map *m, **pm;
1607 if (bfd_get_flavour (abfd) != bfd_target_elf_flavour)
1610 amt = sizeof (struct elf_segment_map);
1611 amt += ((bfd_size_type) count - 1) * sizeof (asection *);
1612 m = (struct elf_segment_map *) bfd_zalloc (abfd, amt);
1619 m->p_flags_valid = flags_valid;
1620 m->p_paddr_valid = at_valid;
1621 m->includes_filehdr = includes_filehdr;
1622 m->includes_phdrs = includes_phdrs;
1625 memcpy (m->sections, secs, count * sizeof (asection *));
1627 for (pm = &elf_seg_map (abfd); *pm != NULL; pm = &(*pm)->next)
1635 /* Return true iff this target is 32-bit. */
1640 if (bfd_get_flavour (abfd) == bfd_target_elf_flavour)
1642 const struct elf_backend_data *bed = get_elf_backend_data (abfd);
1643 return bed->s->elfclass == ELFCLASS32;
1646 /* For non-ELF targets, use architecture information. */
1647 return bfd_arch_bits_per_address (abfd) <= 32;
1651 /* bfd_sprintf_vma and bfd_fprintf_vma display an address in the
1652 target's address size. */
1655 bfd_sprintf_vma (bfd *abfd ATTRIBUTE_UNUSED, char *buf, bfd_vma value)
1660 sprintf (buf, "%08lx", (unsigned long) value & 0xffffffff);
1664 sprintf_vma (buf, value);
1668 bfd_fprintf_vma (bfd *abfd ATTRIBUTE_UNUSED, void *stream, bfd_vma value)
1673 fprintf ((FILE *) stream, "%08lx", (unsigned long) value & 0xffffffff);
1677 fprintf_vma ((FILE *) stream, value);
1685 bfd_boolean bfd_alt_mach_code (bfd *abfd, int alternative);
1689 When more than one machine code number is available for the
1690 same machine type, this function can be used to switch between
1691 the preferred one (alternative == 0) and any others. Currently,
1692 only ELF supports this feature, with up to two alternate
1697 bfd_alt_mach_code (bfd *abfd, int alternative)
1699 if (bfd_get_flavour (abfd) == bfd_target_elf_flavour)
1703 switch (alternative)
1706 code = get_elf_backend_data (abfd)->elf_machine_code;
1710 code = get_elf_backend_data (abfd)->elf_machine_alt1;
1716 code = get_elf_backend_data (abfd)->elf_machine_alt2;
1725 elf_elfheader (abfd)->e_machine = code;
1735 bfd_emul_get_maxpagesize
1738 bfd_vma bfd_emul_get_maxpagesize (const char *);
1741 Returns the maximum page size, in bytes, as determined by
1745 Returns the maximum page size in bytes for ELF, 0 otherwise.
1749 bfd_emul_get_maxpagesize (const char *emul)
1751 const bfd_target *target;
1753 target = bfd_find_target (emul, NULL);
1755 && target->flavour == bfd_target_elf_flavour)
1756 return xvec_get_elf_backend_data (target)->maxpagesize;
1762 bfd_elf_set_pagesize (const bfd_target *target, bfd_vma size,
1763 int offset, const bfd_target *orig_target)
1765 if (target->flavour == bfd_target_elf_flavour)
1767 const struct elf_backend_data *bed;
1769 bed = xvec_get_elf_backend_data (target);
1770 *((bfd_vma *) ((char *) bed + offset)) = size;
1773 if (target->alternative_target
1774 && target->alternative_target != orig_target)
1775 bfd_elf_set_pagesize (target->alternative_target, size, offset,
1781 bfd_emul_set_maxpagesize
1784 void bfd_emul_set_maxpagesize (const char *, bfd_vma);
1787 For ELF, set the maximum page size for the emulation. It is
1788 a no-op for other formats.
1793 bfd_emul_set_maxpagesize (const char *emul, bfd_vma size)
1795 const bfd_target *target;
1797 target = bfd_find_target (emul, NULL);
1799 bfd_elf_set_pagesize (target, size,
1800 offsetof (struct elf_backend_data,
1801 maxpagesize), target);
1806 bfd_emul_get_commonpagesize
1809 bfd_vma bfd_emul_get_commonpagesize (const char *);
1812 Returns the common page size, in bytes, as determined by
1816 Returns the common page size in bytes for ELF, 0 otherwise.
1820 bfd_emul_get_commonpagesize (const char *emul)
1822 const bfd_target *target;
1824 target = bfd_find_target (emul, NULL);
1826 && target->flavour == bfd_target_elf_flavour)
1827 return xvec_get_elf_backend_data (target)->commonpagesize;
1834 bfd_emul_set_commonpagesize
1837 void bfd_emul_set_commonpagesize (const char *, bfd_vma);
1840 For ELF, set the common page size for the emulation. It is
1841 a no-op for other formats.
1846 bfd_emul_set_commonpagesize (const char *emul, bfd_vma size)
1848 const bfd_target *target;
1850 target = bfd_find_target (emul, NULL);
1852 bfd_elf_set_pagesize (target, size,
1853 offsetof (struct elf_backend_data,
1854 commonpagesize), target);
1862 char *bfd_demangle (bfd *, const char *, int);
1865 Wrapper around cplus_demangle. Strips leading underscores and
1866 other such chars that would otherwise confuse the demangler.
1867 If passed a g++ v3 ABI mangled name, returns a buffer allocated
1868 with malloc holding the demangled name. Returns NULL otherwise
1869 and on memory alloc failure.
1873 bfd_demangle (bfd *abfd, const char *name, int options)
1876 const char *pre, *suf;
1878 bfd_boolean skip_lead;
1880 skip_lead = (abfd != NULL
1882 && bfd_get_symbol_leading_char (abfd) == *name);
1886 /* This is a hack for better error reporting on XCOFF, PowerPC64-ELF
1887 or the MS PE format. These formats have a number of leading '.'s
1888 on at least some symbols, so we remove all dots to avoid
1889 confusing the demangler. */
1891 while (*name == '.' || *name == '$')
1893 pre_len = name - pre;
1895 /* Strip off @plt and suchlike too. */
1897 suf = strchr (name, '@');
1900 alloc = (char *) bfd_malloc (suf - name + 1);
1903 memcpy (alloc, name, suf - name);
1904 alloc[suf - name] = '\0';
1908 res = cplus_demangle (name, options);
1917 size_t len = strlen (pre) + 1;
1918 alloc = (char *) bfd_malloc (len);
1921 memcpy (alloc, pre, len);
1927 /* Put back any prefix or suffix. */
1928 if (pre_len != 0 || suf != NULL)
1937 suf_len = strlen (suf) + 1;
1938 final = (char *) bfd_malloc (pre_len + len + suf_len);
1941 memcpy (final, pre, pre_len);
1942 memcpy (final + pre_len, res, len);
1943 memcpy (final + pre_len + len, suf, suf_len);
1954 bfd_update_compression_header
1957 void bfd_update_compression_header
1958 (bfd *abfd, bfd_byte *contents, asection *sec);
1961 Set the compression header at CONTENTS of SEC in ABFD and update
1962 elf_section_flags for compression.
1966 bfd_update_compression_header (bfd *abfd, bfd_byte *contents,
1969 if ((abfd->flags & BFD_COMPRESS) != 0)
1971 if (bfd_get_flavour (abfd) == bfd_target_elf_flavour)
1973 if ((abfd->flags & BFD_COMPRESS_GABI) != 0)
1975 const struct elf_backend_data *bed
1976 = get_elf_backend_data (abfd);
1978 /* Set the SHF_COMPRESSED bit. */
1979 elf_section_flags (sec) |= SHF_COMPRESSED;
1981 if (bed->s->elfclass == ELFCLASS32)
1983 Elf32_External_Chdr *echdr
1984 = (Elf32_External_Chdr *) contents;
1985 bfd_put_32 (abfd, ELFCOMPRESS_ZLIB, &echdr->ch_type);
1986 bfd_put_32 (abfd, sec->size, &echdr->ch_size);
1987 bfd_put_32 (abfd, 1 << sec->alignment_power,
1988 &echdr->ch_addralign);
1992 Elf64_External_Chdr *echdr
1993 = (Elf64_External_Chdr *) contents;
1994 bfd_put_64 (abfd, ELFCOMPRESS_ZLIB, &echdr->ch_type);
1995 bfd_put_64 (abfd, sec->size, &echdr->ch_size);
1996 bfd_put_64 (abfd, 1 << sec->alignment_power,
1997 &echdr->ch_addralign);
2001 /* Clear the SHF_COMPRESSED bit. */
2002 elf_section_flags (sec) &= ~SHF_COMPRESSED;
2011 bfd_check_compression_header
2014 bfd_boolean bfd_check_compression_header
2015 (bfd *abfd, bfd_byte *contents, asection *sec,
2016 bfd_size_type uncompressed_size);
2019 Check the compression header at CONTENTS of SEC in ABFD with
2020 the uncompressed size UNCOMPRESSED_SIZE.
2023 Return TRUE if the compression header is valid.
2027 bfd_check_compression_header (bfd *abfd, bfd_byte *contents,
2029 bfd_size_type uncompressed_size)
2031 if (bfd_get_flavour (abfd) == bfd_target_elf_flavour
2032 && (elf_section_flags (sec) & SHF_COMPRESSED) != 0)
2034 Elf_Internal_Chdr chdr;
2035 const struct elf_backend_data *bed = get_elf_backend_data (abfd);
2036 if (bed->s->elfclass == ELFCLASS32)
2038 Elf32_External_Chdr *echdr = (Elf32_External_Chdr *) contents;
2039 chdr.ch_type = bfd_get_32 (abfd, &echdr->ch_type);
2040 chdr.ch_size = bfd_get_32 (abfd, &echdr->ch_size);
2041 chdr.ch_addralign = bfd_get_32 (abfd, &echdr->ch_addralign);
2045 Elf64_External_Chdr *echdr = (Elf64_External_Chdr *) contents;
2046 chdr.ch_type = bfd_get_64 (abfd, &echdr->ch_type);
2047 chdr.ch_size = bfd_get_64 (abfd, &echdr->ch_size);
2048 chdr.ch_addralign = bfd_get_64 (abfd, &echdr->ch_addralign);
2050 return (chdr.ch_type == ELFCOMPRESS_ZLIB
2051 && chdr.ch_size == uncompressed_size
2052 && chdr.ch_addralign == 1U << sec->alignment_power);
2060 bfd_get_compression_header_size
2063 int bfd_get_compression_header_size (bfd *abfd, asection *sec);
2066 Return the size of the compression header of SEC in ABFD.
2069 Return the size of the compression header in bytes.
2073 bfd_get_compression_header_size (bfd *abfd, asection *sec)
2075 if (bfd_get_flavour (abfd) == bfd_target_elf_flavour)
2079 if (!(abfd->flags & BFD_COMPRESS_GABI))
2082 else if (!(elf_section_flags (sec) & SHF_COMPRESSED))
2085 if (get_elf_backend_data (abfd)->s->elfclass == ELFCLASS32)
2086 return sizeof (Elf32_External_Chdr);
2088 return sizeof (Elf64_External_Chdr);