tidy elf_backend calls

Function pointers in elfNN_bed that are initialized by elfxx-target.h
to non-zero values generally don't need a non-NULL test before calling
them.  Targets don't set a non-NULL function to NULL.  The one
exception being elfnn-ia64.c and that exception is removed here.

	* elf.c (_bfd_elf_setup_sections): Don't test known non-NULL
	backend functions for NULL before calling.
	(copy_special_section_fields, _bfd_elf_copy_private_bfd_data),
	(bfd_section_from_shdr, assign_section_numbers): Likewise.
	* elfcode.h (elf_write_relocs, elf_slurp_reloc_table): Likewise.
	* elfnn-ia64.c (ignore_errors): New function.
	(elf_backend_link_order_error_handler): Redefine as ignore_errors.
This commit is contained in:
Alan Modra
2020-03-18 07:31:47 +10:30
parent ce2ea1c7e0
commit a859124df2
4 changed files with 37 additions and 27 deletions

View File

@ -1,3 +1,13 @@
2020-03-20 Alan Modra <amodra@gmail.com>
* elf.c (_bfd_elf_setup_sections): Don't test known non-NULL
backend functions for NULL before calling.
(copy_special_section_fields, _bfd_elf_copy_private_bfd_data),
(bfd_section_from_shdr, assign_section_numbers): Likewise.
* elfcode.h (elf_write_relocs, elf_slurp_reloc_table): Likewise.
* elfnn-ia64.c (ignore_errors): New function.
(elf_backend_link_order_error_handler): Redefine as ignore_errors.
2020-03-19 Nick Clifton <nickc@redhat.com> 2020-03-19 Nick Clifton <nickc@redhat.com>
PR 25676 PR 25676

View File

@ -857,7 +857,6 @@ _bfd_elf_setup_sections (bfd *abfd)
if (elfsec == 0) if (elfsec == 0)
{ {
const struct elf_backend_data *bed = get_elf_backend_data (abfd); const struct elf_backend_data *bed = get_elf_backend_data (abfd);
if (bed->link_order_error_handler)
bed->link_order_error_handler bed->link_order_error_handler
/* xgettext:c-format */ /* xgettext:c-format */
(_("%pB: warning: sh_link not set for section `%pA'"), (_("%pB: warning: sh_link not set for section `%pA'"),
@ -1424,9 +1423,8 @@ copy_special_section_fields (const bfd *ibfd,
} }
/* Allow the target a chance to decide how these fields should be set. */ /* Allow the target a chance to decide how these fields should be set. */
if (bed->elf_backend_copy_special_section_fields != NULL if (bed->elf_backend_copy_special_section_fields (ibfd, obfd,
&& bed->elf_backend_copy_special_section_fields iheader, oheader))
(ibfd, obfd, iheader, oheader))
return TRUE; return TRUE;
/* We have an iheader which might match oheader, and which has non-zero /* We have an iheader which might match oheader, and which has non-zero
@ -1610,8 +1608,8 @@ _bfd_elf_copy_private_bfd_data (bfd *ibfd, bfd *obfd)
{ {
/* Final attempt. Call the backend copy function /* Final attempt. Call the backend copy function
with a NULL input section. */ with a NULL input section. */
if (bed->elf_backend_copy_special_section_fields != NULL) (void) bed->elf_backend_copy_special_section_fields (ibfd, obfd,
(void) bed->elf_backend_copy_special_section_fields (ibfd, obfd, NULL, oheader); NULL, oheader);
} }
} }
@ -2462,12 +2460,12 @@ bfd_section_from_shdr (bfd *abfd, unsigned int shindex)
sections. */ sections. */
if (*p_hdr != NULL) if (*p_hdr != NULL)
{ {
if (bed->init_secondary_reloc_section == NULL if (!bed->init_secondary_reloc_section (abfd, hdr, name, shindex))
|| ! bed->init_secondary_reloc_section (abfd, hdr, name, shindex))
{ {
_bfd_error_handler _bfd_error_handler
/* xgettext:c-format */ /* xgettext:c-format */
(_("%pB: warning: secondary relocation section '%s' for section %pA found - ignoring"), (_("%pB: warning: secondary relocation section '%s' "
"for section %pA found - ignoring"),
abfd, name, target_sect); abfd, name, target_sect);
} }
goto success; goto success;
@ -3940,7 +3938,6 @@ assign_section_numbers (bfd *abfd, struct bfd_link_info *link_info)
where s is NULL. */ where s is NULL. */
const struct elf_backend_data *bed const struct elf_backend_data *bed
= get_elf_backend_data (abfd); = get_elf_backend_data (abfd);
if (bed->link_order_error_handler)
bed->link_order_error_handler bed->link_order_error_handler
/* xgettext:c-format */ /* xgettext:c-format */
(_("%pB: warning: sh_link not set for section `%pA'"), (_("%pB: warning: sh_link not set for section `%pA'"),

View File

@ -987,8 +987,7 @@ elf_write_relocs (bfd *abfd, asection *sec, void *data)
(*swap_out) (abfd, &src_rela, dst_rela); (*swap_out) (abfd, &src_rela, dst_rela);
} }
if (bed->write_secondary_relocs != NULL) if (!bed->write_secondary_relocs (abfd, sec))
if (! bed->write_secondary_relocs (abfd, sec))
{ {
*failedp = TRUE; *failedp = TRUE;
return; return;
@ -1596,8 +1595,7 @@ elf_slurp_reloc_table (bfd *abfd,
symbols, dynamic)) symbols, dynamic))
return FALSE; return FALSE;
if (bed->slurp_secondary_relocs != NULL if (!bed->slurp_secondary_relocs (abfd, asect, symbols))
&& ! bed->slurp_secondary_relocs (abfd, asect, symbols))
return FALSE; return FALSE;
asect->relocation = relents; asect->relocation = relents;

View File

@ -5015,6 +5015,11 @@ elfNN_hpux_backend_symbol_processing (bfd *abfd ATTRIBUTE_UNUSED,
break; break;
} }
} }
static void
ignore_errors (const char *fmt ATTRIBUTE_UNUSED, ...)
{
}
#define TARGET_LITTLE_SYM ia64_elfNN_le_vec #define TARGET_LITTLE_SYM ia64_elfNN_le_vec
#define TARGET_LITTLE_NAME "elfNN-ia64-little" #define TARGET_LITTLE_NAME "elfNN-ia64-little"
@ -5112,7 +5117,7 @@ elfNN_hpux_backend_symbol_processing (bfd *abfd ATTRIBUTE_UNUSED,
We don't want to flood users with so many error messages. We turn We don't want to flood users with so many error messages. We turn
off the warning for now. It will be turned on later when the Intel off the warning for now. It will be turned on later when the Intel
compiler is fixed. */ compiler is fixed. */
#define elf_backend_link_order_error_handler NULL #define elf_backend_link_order_error_handler ignore_errors
#include "elfNN-target.h" #include "elfNN-target.h"