+2019-11-18 Alan Modra <amodra@gmail.com>
+
+ * elf-bfd.h (struct elf_backend_data <elf_backend_init_file_header>):
+ Rename from elf_backend_post_process_headers.
+ (_bfd_elf_post_process_headers): Delete.
+ (_bfd_elf_init_file_header): Declare.
+ * elf.c (_bfd_elf_compute_section_file_positions): Call new function
+ in place of prep_headers and elf_backend_post_process_headers.
+ (_bfd_elf_init_file_header): Renamed from prep_headers with
+ updated args and made global. Delete dead code.
+ (_bfd_elf_post_process_headers): Delete.
+ * elf32-arm.c (elf32_arm_init_file_header): Rename from
+ elf32_arm_post_process_headers and call _bfd_elf_init_file_header.
+ Return status.
+ (elf_backend_init_file_header): Define.
+ (elf_backend_post_process_headers): Don't define.
+ * elf32-i386.c (elf_i386_fbsd_init_file_header): Similarly.
+ * elf32-m68hc1x.c (elf32_m68hc11_init_file_header): Similarly.
+ * elf32-metag.c (elf_metag_init_file_header): Similarly.
+ * elf32-spu.c (spu_elf_init_file_header
+ * elf32-visium.c (visium_elf_init_file_header
+ * elf64-alpha.c (elf64_alpha_fbsd_init_file_header
+ * elf64-hppa.c (elf64_hppa_init_file_header
+ * elf64-ia64-vms.c (elf64_vms_init_file_header
+ * elfnn-aarch64.c (elfNN_aarch64_init_file_header
+ * elfnn-ia64.c (elfNN_hpux_init_file_header
+ * elfxx-mips.c (_bfd_mips_init_file_header
+ * elfxx-mips.h (_bfd_mips_post_process_headers): Delete.
+ (_bfd_mips_init_file_header): Declare.
+ (elf_backend_post_process_headers): Delete.
+ (elf_backend_init_file_header): Define.
+ * elfxx-target.h (elf_backend_post_process_headers): Delete.
+ (elf_backend_init_file_header): Define and use.
+ * elf32-m68hc12.c (elf_backend_init_file_header): Define.
+ (elf_backend_post_process_headers): Don't define.
+ * elf32-m68hc1x.h (elf32_m68hc11_post_process_headers): Delete.
+ (elf32_m68hc11_init_file_header): Declare.
+ * elf32-ppc.c (elf_backend_post_process_headers): Remove
+ unnecessary undef.
+
2019-11-18 Alan Modra <amodra@gmail.com>
* elf-bfd.h (struct elf_backend_data <elf_backend_modify_headers>):
bfd_boolean (*gc_mark_extra_sections)
(struct bfd_link_info *, elf_gc_mark_hook_fn);
- /* This function, if defined, is called after the ELF headers have
- been created. This allows for things like the OS and ABI versions
- to be changed. */
- void (*elf_backend_post_process_headers)
+ /* This function is called to initialise ELF file header info.
+ Customised versions can modify things like the OS and ABI version. */
+ bfd_boolean (*elf_backend_init_file_header)
(bfd *, struct bfd_link_info *);
/* This function, if defined, prints a symbol to file and returns the
extern struct bfd_link_hash_entry *bfd_elf_define_start_stop
(struct bfd_link_info *, const char *, asection *);
-extern void _bfd_elf_post_process_headers (bfd *, struct bfd_link_info *);
+extern bfd_boolean _bfd_elf_init_file_header (bfd *, struct bfd_link_info *);
extern bfd_boolean _bfd_elf_final_write_processing (bfd *);
static int elf_sort_sections (const void *, const void *);
static bfd_boolean assign_file_positions_except_relocs (bfd *, struct bfd_link_info *);
-static bfd_boolean prep_headers (bfd *);
static bfd_boolean swap_out_syms (bfd *, struct elf_strtab_hash **, int) ;
static bfd_boolean elf_parse_notes (bfd *abfd, char *buf, size_t size,
file_ptr offset, size_t align);
if (bed->elf_backend_begin_write_processing)
(*bed->elf_backend_begin_write_processing) (abfd, link_info);
- if (! prep_headers (abfd))
+ if (!(*bed->elf_backend_init_file_header) (abfd, link_info))
return FALSE;
- /* Post process the headers if necessary. */
- (*bed->elf_backend_post_process_headers) (abfd, link_info);
-
fsargs.failed = FALSE;
fsargs.link_info = link_info;
bfd_map_over_sections (abfd, elf_fake_sections, &fsargs);
}
shstrtab_hdr = &elf_tdata (abfd)->shstrtab_hdr;
- /* sh_name was set in prep_headers. */
+ /* sh_name was set in init_file_header. */
shstrtab_hdr->sh_type = SHT_STRTAB;
shstrtab_hdr->sh_flags = bed->elf_strtab_flags;
shstrtab_hdr->sh_addr = 0;
return TRUE;
}
-static bfd_boolean
-prep_headers (bfd *abfd)
+bfd_boolean
+_bfd_elf_init_file_header (bfd *abfd,
+ struct bfd_link_info *info ATTRIBUTE_UNUSED)
{
Elf_Internal_Ehdr *i_ehdrp; /* Elf file header, internal form. */
struct elf_strtab_hash *shstrtab;
i_ehdrp->e_entry = bfd_get_start_address (abfd);
i_ehdrp->e_shentsize = bed->s->sizeof_shdr;
- /* If we're building an executable, we'll need a program header table. */
- if (abfd->flags & EXEC_P)
- /* It all happens later. */
- ;
- else
- {
- i_ehdrp->e_phentsize = 0;
- i_ehdrp->e_phoff = 0;
- }
-
elf_tdata (abfd)->symtab_hdr.sh_name =
(unsigned int) _bfd_elf_strtab_add (shstrtab, ".symtab", FALSE);
elf_tdata (abfd)->strtab_hdr.sh_name =
= BFD_FAKE_SECTION (_bfd_elf_large_com_section, &lcomm_sym,
"LARGE_COMMON", 0, SEC_IS_COMMON);
-void
-_bfd_elf_post_process_headers (bfd *abfd ATTRIBUTE_UNUSED,
- struct bfd_link_info *info ATTRIBUTE_UNUSED)
-{
-}
-
bfd_boolean
_bfd_elf_final_write_processing (bfd *abfd)
{
return TRUE;
}
-static void
-elf32_arm_post_process_headers (bfd * abfd, struct bfd_link_info * link_info ATTRIBUTE_UNUSED)
+static bfd_boolean
+elf32_arm_init_file_header (bfd *abfd, struct bfd_link_info *link_info)
{
Elf_Internal_Ehdr * i_ehdrp; /* ELF file header, internal form. */
struct elf32_arm_link_hash_table *globals;
struct elf_segment_map *m;
+ if (!_bfd_elf_init_file_header (abfd, link_info))
+ return FALSE;
+
i_ehdrp = elf_elfheader (abfd);
if (EF_ARM_EABI_VERSION (i_ehdrp->e_flags) == EF_ARM_EABI_UNKNOWN)
i_ehdrp->e_ident[EI_OSABI] = ELFOSABI_ARM;
- else
- _bfd_elf_post_process_headers (abfd, link_info);
i_ehdrp->e_ident[EI_ABIVERSION] = ARM_ELF_ABI_VERSION;
if (link_info)
m->p_flags_valid = 1;
}
}
+ return TRUE;
}
static enum elf_reloc_type_class
#define elf_backend_size_dynamic_sections elf32_arm_size_dynamic_sections
#define elf_backend_always_size_sections elf32_arm_always_size_sections
#define elf_backend_init_index_section _bfd_elf_init_2_index_sections
-#define elf_backend_post_process_headers elf32_arm_post_process_headers
+#define elf_backend_init_file_header elf32_arm_init_file_header
#define elf_backend_reloc_type_class elf32_arm_reloc_type_class
#define elf_backend_object_p elf32_arm_object_p
#define elf_backend_fake_sections elf32_arm_fake_sections
"FreeBSD" label in the ELF header. So we put this label on all
executables and (for simplicity) also all other object files. */
-static void
-elf_i386_fbsd_post_process_headers (bfd *abfd, struct bfd_link_info *info)
+static bfd_boolean
+elf_i386_fbsd_init_file_header (bfd *abfd, struct bfd_link_info *info)
{
- _bfd_elf_post_process_headers (abfd, info);
+ if (!_bfd_elf_init_file_header (abfd, info))
+ return FALSE;
#ifdef OLD_FREEBSD_ABI_LABEL
{
memcpy (&i_ehdrp->e_ident[EI_ABIVERSION], "FreeBSD", 8);
}
#endif
+ return TRUE;
}
-#undef elf_backend_post_process_headers
-#define elf_backend_post_process_headers elf_i386_fbsd_post_process_headers
+#undef elf_backend_init_file_header
+#define elf_backend_init_file_header elf_i386_fbsd_init_file_header
#undef elf32_bed
#define elf32_bed elf32_i386_fbsd_bed
#include "elf32-target.h"
+#undef elf_backend_init_file_header
+
/* Solaris 2. */
#undef TARGET_LITTLE_SYM
#undef elf_backend_arch_data
#define elf_backend_arch_data &elf_i386_solaris_arch_bed
-#undef elf_backend_post_process_headers
-
/* Restore default: we cannot use ELFOSABI_SOLARIS, otherwise ELFOSABI_NONE
objects won't be recognized. */
#undef ELF_OSABI
#undef ELF_OSABI
#undef elf_backend_want_plt_sym
#define elf_backend_want_plt_sym 0
-#undef elf_backend_post_process_headers
#undef elf_backend_static_tls_alignment
/* NaCl uses substantially different PLT entries for the same effects. */
#define elf_backend_object_p m68hc12_elf_set_mach_from_flags
#define elf_backend_can_gc_sections 1
#define elf_backend_special_sections elf32_m68hc12_special_sections
-#define elf_backend_post_process_headers elf32_m68hc11_post_process_headers
+#define elf_backend_init_file_header elf32_m68hc11_init_file_header
#define elf_backend_add_symbol_hook elf32_m68hc11_add_symbol_hook
#define elf_backend_merge_symbol_attribute elf32_m68hc11_merge_symbol_attribute
/* Tweak the OSABI field of the elf header. */
-void
-elf32_m68hc11_post_process_headers (bfd *abfd, struct bfd_link_info *link_info)
+bfd_boolean
+elf32_m68hc11_init_file_header (bfd *abfd, struct bfd_link_info *link_info)
{
struct m68hc11_scan_param param;
struct m68hc11_elf_link_hash_table *htab;
- _bfd_elf_post_process_headers (abfd, link_info);
+ if (!_bfd_elf_init_file_header (abfd, link_info))
+ return FALSE;
if (link_info == NULL)
- return;
+ return TRUE;
htab = m68hc11_elf_hash_table (link_info);
if (htab == NULL)
- return;
+ return TRUE;
m68hc11_elf_get_bank_parameters (link_info);
i_ehdrp = elf_elfheader (abfd);
i_ehdrp->e_flags |= E_M68HC12_BANKS;
}
+ return TRUE;
}
/* Tweak the OSABI field of the elf header. */
-extern void elf32_m68hc11_post_process_headers (bfd*, struct bfd_link_info*);
+extern bfd_boolean elf32_m68hc11_init_file_header (bfd*, struct bfd_link_info*);
int elf32_m68hc11_setup_section_lists (bfd *, struct bfd_link_info *);
/* Set the Meta ELF ABI version. */
-static void
-elf_metag_post_process_headers (bfd * abfd, struct bfd_link_info * link_info)
+static bfd_boolean
+elf_metag_init_file_header (bfd *abfd, struct bfd_link_info *link_info)
{
Elf_Internal_Ehdr * i_ehdrp; /* ELF file header, internal form. */
- _bfd_elf_post_process_headers (abfd, link_info);
+ if (!_bfd_elf_init_file_header (abfd, link_info))
+ return FALSE;
+
i_ehdrp = elf_elfheader (abfd);
i_ehdrp->e_ident[EI_ABIVERSION] = METAG_ELF_ABI_VERSION;
+ return TRUE;
}
/* Used to decide how to sort relocs in an optimal manner for the
#define elf_backend_size_dynamic_sections elf_metag_size_dynamic_sections
#define elf_backend_omit_section_dynsym \
_bfd_elf_omit_section_dynsym_all
-#define elf_backend_post_process_headers elf_metag_post_process_headers
+#define elf_backend_init_file_header elf_metag_init_file_header
#define elf_backend_reloc_type_class elf_metag_reloc_type_class
#define elf_backend_copy_indirect_symbol elf_metag_copy_indirect_symbol
#define elf_backend_plt_sym_val elf_metag_plt_sym_val
#undef elf32_bed
#define elf32_bed ppc_elf_vxworks_bed
-#undef elf_backend_post_process_headers
#include "elf32-target.h"
/* Set ELF header e_type for plugins. */
-static void
-spu_elf_post_process_headers (bfd *abfd, struct bfd_link_info *info)
+static bfd_boolean
+spu_elf_init_file_header (bfd *abfd, struct bfd_link_info *info)
{
+ if (!_bfd_elf_init_file_header (abfd, info))
+ return FALSE;
+
if (spu_plugin)
{
Elf_Internal_Ehdr *i_ehdrp = elf_elfheader (abfd);
i_ehdrp->e_type = ET_DYN;
}
-
- _bfd_elf_post_process_headers (abfd, info);
+ return TRUE;
}
/* We may add an extra PT_LOAD segment for .toe. We also need extra
#define elf_backend_additional_program_headers spu_elf_additional_program_headers
#define elf_backend_modify_segment_map spu_elf_modify_segment_map
#define elf_backend_modify_headers spu_elf_modify_headers
-#define elf_backend_post_process_headers spu_elf_post_process_headers
+#define elf_backend_init_file_header spu_elf_init_file_header
#define elf_backend_fake_sections spu_elf_fake_sections
#define elf_backend_special_sections spu_elf_special_sections
#define bfd_elf32_bfd_final_link spu_elf_final_link
return _bfd_elf_gc_mark_hook (sec, info, rel, h, sym);
}
-static void
-visium_elf_post_process_headers (bfd *abfd,
- struct bfd_link_info *info ATTRIBUTE_UNUSED)
+static bfd_boolean
+visium_elf_init_file_header (bfd *abfd, struct bfd_link_info *info)
{
- Elf_Internal_Ehdr *i_ehdrp = elf_elfheader (abfd);
+ Elf_Internal_Ehdr *i_ehdrp;
+
+ if (!_bfd_elf_init_file_header (abfd, info))
+ return FALSE;
+
+ i_ehdrp = elf_elfheader (abfd);
i_ehdrp->e_ident[EI_ABIVERSION] = 1;
+ return TRUE;
}
/* Function to set the ELF flag bits. */
#define bfd_elf32_bfd_copy_private_bfd_data visium_elf_copy_private_bfd_data
#define bfd_elf32_bfd_merge_private_bfd_data visium_elf_merge_private_bfd_data
#define bfd_elf32_bfd_print_private_bfd_data visium_elf_print_private_bfd_data
-#define elf_backend_post_process_headers visium_elf_post_process_headers
+#define elf_backend_init_file_header visium_elf_init_file_header
#include "elf32-target.h"
"FreeBSD" label in the ELF header. So we put this label on all
executables and (for simplicity) also all other object files. */
-static void
-elf64_alpha_fbsd_post_process_headers (bfd * abfd,
- struct bfd_link_info * link_info ATTRIBUTE_UNUSED)
+static bfd_boolean
+elf64_alpha_fbsd_init_file_header (bfd *abfd, struct bfd_link_info *info)
{
Elf_Internal_Ehdr * i_ehdrp; /* ELF file header, internal form. */
+ if (!_bfd_elf_init_file_header (abfd, info))
+ return FALSE;
+
i_ehdrp = elf_elfheader (abfd);
/* Put an ABI label supported by FreeBSD >= 4.1. */
/* The ABI label supported by FreeBSD <= 4.0 is quite nonstandard. */
memcpy (&i_ehdrp->e_ident[EI_ABIVERSION], "FreeBSD", 8);
#endif
+ return TRUE;
}
-#undef elf_backend_post_process_headers
-#define elf_backend_post_process_headers \
- elf64_alpha_fbsd_post_process_headers
+#undef elf_backend_init_file_header
+#define elf_backend_init_file_header \
+ elf64_alpha_fbsd_init_file_header
#undef elf64_bed
#define elf64_bed elf64_alpha_fbsd_bed
static bfd_boolean elf64_hppa_object_p
(bfd *);
-static void elf64_hppa_post_process_headers
- (bfd *, struct bfd_link_info *);
-
static bfd_boolean elf64_hppa_create_dynamic_sections
(bfd *, struct bfd_link_info *);
/* HP requires the EI_OSABI field to be filled in. The assignment to
EI_ABIVERSION may not be strictly necessary. */
-static void
-elf64_hppa_post_process_headers (bfd *abfd,
- struct bfd_link_info *link_info ATTRIBUTE_UNUSED)
+static bfd_boolean
+elf64_hppa_init_file_header (bfd *abfd, struct bfd_link_info *info)
{
- Elf_Internal_Ehdr * i_ehdrp;
+ Elf_Internal_Ehdr *i_ehdrp;
- i_ehdrp = elf_elfheader (abfd);
+ if (!_bfd_elf_init_file_header (abfd, info))
+ return FALSE;
+ i_ehdrp = elf_elfheader (abfd);
i_ehdrp->e_ident[EI_OSABI] = get_elf_backend_data (abfd)->elf_osabi;
i_ehdrp->e_ident[EI_ABIVERSION] = 1;
+ return TRUE;
}
/* Create function descriptor section (.opd). This section is called .opd
#define elf_backend_create_dynamic_sections \
elf64_hppa_create_dynamic_sections
-#define elf_backend_post_process_headers elf64_hppa_post_process_headers
+#define elf_backend_init_file_header elf64_hppa_init_file_header
#define elf_backend_omit_section_dynsym _bfd_elf_omit_section_dynsym_all
return TRUE;
}
-static void
-elf64_vms_post_process_headers (bfd *abfd,
- struct bfd_link_info *info ATTRIBUTE_UNUSED)
+static bfd_boolean
+elf64_vms_init_file_header (bfd *abfd, struct bfd_link_info *info)
{
- Elf_Internal_Ehdr *i_ehdrp = elf_elfheader (abfd);
+ Elf_Internal_Ehdr *i_ehdrp;
+ if (!_bfd_elf_init_file_header (abfd, info))
+ return FALSE;
+
+ i_ehdrp = elf_elfheader (abfd);
i_ehdrp->e_ident[EI_OSABI] = ELFOSABI_OPENVMS;
i_ehdrp->e_ident[EI_ABIVERSION] = 2;
+ return TRUE;
}
static bfd_boolean
#undef elf_backend_section_from_shdr
#define elf_backend_section_from_shdr elf64_vms_section_from_shdr
-#undef elf_backend_post_process_headers
-#define elf_backend_post_process_headers elf64_vms_post_process_headers
+#undef elf_backend_init_file_header
+#define elf_backend_init_file_header elf64_vms_init_file_header
#undef elf_backend_section_processing
#define elf_backend_section_processing elf64_vms_section_processing
}
-static void
-elfNN_aarch64_post_process_headers (bfd *abfd,
- struct bfd_link_info *link_info)
+static bfd_boolean
+elfNN_aarch64_init_file_header (bfd *abfd, struct bfd_link_info *link_info)
{
Elf_Internal_Ehdr *i_ehdrp; /* ELF file header, internal form. */
+ if (!_bfd_elf_init_file_header (abfd, link_info))
+ return FALSE;
+
i_ehdrp = elf_elfheader (abfd);
i_ehdrp->e_ident[EI_ABIVERSION] = AARCH64_ELF_ABI_VERSION;
-
- _bfd_elf_post_process_headers (abfd, link_info);
+ return TRUE;
}
static enum elf_reloc_type_class
#define elf_backend_plt_sym_val \
elfNN_aarch64_plt_sym_val
-#define elf_backend_post_process_headers \
- elfNN_aarch64_post_process_headers
+#define elf_backend_init_file_header \
+ elfNN_aarch64_init_file_header
#define elf_backend_relocate_section \
elfNN_aarch64_relocate_section
return (vec == &ia64_elfNN_hpux_be_vec);
}
-static void
-elfNN_hpux_post_process_headers (bfd *abfd,
- struct bfd_link_info *info ATTRIBUTE_UNUSED)
+static bfd_boolean
+elfNN_hpux_init_file_header (bfd *abfd, struct bfd_link_info *info)
{
- Elf_Internal_Ehdr *i_ehdrp = elf_elfheader (abfd);
+ Elf_Internal_Ehdr *i_ehdrp;
+ if (!_bfd_elf_init_file_header (abfd, info))
+ return FALSE;
+
+ i_ehdrp = elf_elfheader (abfd);
i_ehdrp->e_ident[EI_OSABI] = get_elf_backend_data (abfd)->elf_osabi;
i_ehdrp->e_ident[EI_ABIVERSION] = 1;
+ return TRUE;
}
static bfd_boolean
/* These are HP-UX specific functions. */
-#undef elf_backend_post_process_headers
-#define elf_backend_post_process_headers elfNN_hpux_post_process_headers
+#undef elf_backend_init_file_header
+#define elf_backend_init_file_header elfNN_hpux_init_file_header
#undef elf_backend_section_from_bfd_section
#define elf_backend_section_from_bfd_section elfNN_hpux_backend_section_from_bfd_section
MIPS_LIBC_ABI_MAX
};
-void
-_bfd_mips_post_process_headers (bfd *abfd, struct bfd_link_info *link_info)
+bfd_boolean
+_bfd_mips_init_file_header (bfd *abfd, struct bfd_link_info *link_info)
{
struct mips_elf_link_hash_table *htab = NULL;
Elf_Internal_Ehdr *i_ehdrp;
+ if (!_bfd_elf_init_file_header (abfd, link_info))
+ return FALSE;
+
i_ehdrp = elf_elfheader (abfd);
if (link_info)
{
if it is the only hash section that will be created. */
if (link_info && link_info->emit_gnu_hash && !link_info->emit_hash)
i_ehdrp->e_ident[EI_ABIVERSION] = MIPS_LIBC_ABI_XHASH;
-
- _bfd_elf_post_process_headers (abfd, link_info);
+ return TRUE;
}
int
(bfd *, long, asymbol **, long, asymbol **, asymbol **);
extern bfd_boolean _bfd_mips_elf_gc_mark_extra_sections
(struct bfd_link_info *, elf_gc_mark_hook_fn);
-extern void _bfd_mips_post_process_headers
+extern bfd_boolean _bfd_mips_init_file_header
(bfd *abfd, struct bfd_link_info *link_info);
extern const struct bfd_elf_special_section _bfd_mips_elf_special_sections [];
#define elf_backend_eh_frame_address_size _bfd_mips_elf_eh_frame_address_size
#define elf_backend_merge_symbol_attribute _bfd_mips_elf_merge_symbol_attribute
#define elf_backend_ignore_undef_symbol _bfd_mips_elf_ignore_undef_symbol
-#define elf_backend_post_process_headers _bfd_mips_post_process_headers
+#define elf_backend_init_file_header _bfd_mips_init_file_header
#define elf_backend_compact_eh_encoding _bfd_mips_elf_compact_eh_encoding
#define elf_backend_cant_unwind_opcode _bfd_mips_elf_cant_unwind_opcode
#define elf_backend_record_xhash_symbol _bfd_mips_elf_record_xhash_symbol
#ifndef elf_backend_static_tls_alignment
#define elf_backend_static_tls_alignment 1
#endif
-#ifndef elf_backend_post_process_headers
-#define elf_backend_post_process_headers _bfd_elf_post_process_headers
+#ifndef elf_backend_init_file_header
+#define elf_backend_init_file_header _bfd_elf_init_file_header
#endif
#ifndef elf_backend_print_symbol_all
#define elf_backend_print_symbol_all NULL
elf_backend_gc_mark_dynamic_ref,
elf_backend_gc_mark_hook,
elf_backend_gc_mark_extra_sections,
- elf_backend_post_process_headers,
+ elf_backend_init_file_header,
elf_backend_print_symbol_all,
elf_backend_output_arch_local_syms,
elf_backend_output_arch_syms,