The _bfd_final_link function must gather all the symbols
in the input files and write them out. It must also write out
all the symbols in the global hash table. This must be
controlled by the strip and discard fields of the
bfd_link_info structure.
The local symbols of the input files will not have been
entered into the linker hash table. The _bfd_final_link
routine must consider each input file and include the symbols
in the output file. It may be convenient to do this when
looking through the link_order structures, or it may be
done by stepping through the input_bfds list.
The _bfd_final_link routine must also traverse the global
hash table to gather all the externally visible symbols. It
is possible that most of the externally visible symbols may be
written out when considering the symbols of each input file,
but it is still necessary to traverse the hash table since the
linker script may have defined some symbols that are not in
any of the input files.
The strip field of the bfd_link_info structure
controls which symbols are written out. The possible values
are listed in bfdlink.h. If the value is strip_some,
then the keep_hash field of the bfd_link_info
structure is a hash table of symbols to keep; each symbol
should be looked up in this hash table, and only symbols which
are present should be included in the output file.
If the strip field of the bfd_link_info structure
permits local symbols to be written out, the discard field
is used to further controls which local symbols are included
in the output file. If the value is discard_l, then all
local symbols which begin with a certain prefix are discarded;
this is controlled by the bfd_is_local_label_name entry point.
The a.out backend handles symbols by calling
aout_link_write_symbols on each input BFD and then
traversing the global hash table with the function
aout_link_write_other_symbol. It builds a string table
while writing out the symbols, which is written to the output
file at the end of NAME(aout,final_link).
_bfd_generic_link_add_one_symbol ¶bool _bfd_generic_link_add_one_symbol (struct bfd_link_info *info, bfd *abfd, const char *name, flagword flags, asection *section, bfd_vma value, const char *string, bool copy, bool collect, struct bfd_link_hash_entry **hashp); ¶Add a symbol to the global hash table. ABFD is the BFD the symbol comes from. NAME is the name of the symbol. FLAGS is the BSF_* bits associated with the symbol. SECTION is the section in which the symbol is defined; this may be bfd_und_section_ptr or bfd_com_section_ptr. VALUE is the value of the symbol, relative to the section. STRING is used for either an indirect symbol, in which case it is the name of the symbol to indirect to, or a warning symbol, in which case it is the warning string. COPY is TRUE if NAME or STRING must be copied into locally allocated memory if they need to be saved. COLLECT is TRUE if we should automatically collect gcc constructor or destructor names as collect2 does. HASHP, if not NULL, is a place to store the created hash table entry; if *HASHP is not NULL, the caller has already looked up the hash table entry, and stored it in *HASHP.
bfd_link_align_section ¶bool bfd_link_align_section (asection *, unsigned int); ¶Increase section alignment if the current section alignment is less than the requested value. Adjust output section alignment too, so that linker layout adjusts for alignment on the current lang_size_sections pass. This is important for lang_size_relro_segment. If the output section alignment isn’t adjusted, the linker will place the output section at an address depending on its current alignment. When sizing the output section, input sections attached transfer any increase in alignment to the output section, which will affect layout for the next sizing pass. Which is all well and good except that lang_size_relro_segment for the current sizing pass uses that possibly increased alignment with a layout that doesn’t suit.
bfd_link_split_section ¶bool bfd_link_split_section (bfd *abfd, asection *sec); ¶Return nonzero if sec should be split during a reloceatable or final link.
#define bfd_link_split_section(abfd, sec) \
BFD_SEND (abfd, _bfd_link_split_section, (abfd, sec))
bfd_section_already_linked ¶bool bfd_section_already_linked (bfd *abfd, asection *sec, struct bfd_link_info *info); ¶Check if data has been already linked during a reloceatable or final link. Return TRUE if it has.
#define bfd_section_already_linked(abfd, sec, info) \
BFD_SEND (abfd, _section_already_linked, (abfd, sec, info))
bfd_generic_define_common_symbol ¶bool bfd_generic_define_common_symbol (bfd *output_bfd, struct bfd_link_info *info, struct bfd_link_hash_entry *h); ¶Convert common symbol h into a defined symbol. Return TRUE on success and FALSE on failure.
#define bfd_define_common_symbol(output_bfd, info, h) \
BFD_SEND (output_bfd, _bfd_define_common_symbol, (output_bfd, info, h))
_bfd_generic_link_hide_symbol ¶void _bfd_generic_link_hide_symbol (bfd *output_bfd, struct bfd_link_info *info, struct bfd_link_hash_entry *h); ¶Hide symbol h. This is an internal function. It should not be called from outside the BFD library.
#define bfd_link_hide_symbol(output_bfd, info, h) \
BFD_SEND (output_bfd, _bfd_link_hide_symbol, (output_bfd, info, h))
bfd_generic_define_start_stop ¶struct bfd_link_hash_entry *bfd_generic_define_start_stop (struct bfd_link_info *info, const char *symbol, asection *sec); ¶Define a __start, __stop, .startof. or .sizeof. symbol. Return the symbol or NULL if no such undefined symbol exists.
#define bfd_define_start_stop(output_bfd, info, symbol, sec) \
BFD_SEND (output_bfd, _bfd_define_start_stop, (info, symbol, sec))
bfd_find_version_for_sym ¶struct bfd_elf_version_tree * bfd_find_version_for_sym (struct bfd_elf_version_tree *verdefs, const char *sym_name, bool *hide); ¶Search an elf version script tree for symbol versioning info and export / don’t-export status for a given symbol. Return non-NULL on success and NULL on failure; also sets the output ‘hide’ boolean parameter.
bfd_hide_sym_by_version ¶bool bfd_hide_sym_by_version (struct bfd_elf_version_tree *verdefs, const char *sym_name); ¶Search an elf version script tree for symbol versioning info for a given symbol. Return TRUE if the symbol is hidden.
bfd_link_check_relocs ¶bool bfd_link_check_relocs (bfd *abfd, struct bfd_link_info *info); ¶Checks the relocs in ABFD for validity. Does not execute the relocs. Return TRUE if everything is OK, FALSE otherwise. This is the external entry point to this code.
_bfd_generic_link_check_relocs ¶bool _bfd_generic_link_check_relocs (bfd *abfd, struct bfd_link_info *info); ¶Stub function for targets that do not implement reloc checking. Return TRUE. This is an internal function. It should not be called from outside the BFD library.
bfd_merge_private_bfd_data ¶Merge private BFD information from the BFD ibfd to the
the output file BFD when linking. Return TRUE on success,
FALSE on error. Possible error returns are:
bfd_error_no_memory -
Not enough memory exists to create private data for obfd.
#define bfd_merge_private_bfd_data(ibfd, info) \
BFD_SEND ((info)->output_bfd, _bfd_merge_private_bfd_data, \
(ibfd, info))
_bfd_generic_verify_endian_match ¶bool _bfd_generic_verify_endian_match (bfd *ibfd, struct bfd_link_info *info); ¶Can be used from / for bfd_merge_private_bfd_data to check that endianness matches between input and output file. Returns TRUE for a match, otherwise returns FALSE and emits an error.