elf_backend_finish_dynamic_symbol returning false

Returning false from elf_backend_finish_dynamic_symbol will not result
in an error being printed unless bfd_error is set but will result in
the linker exiting with a non-zero status.  If just bfd_error is set
then a generic "final link failed" will result, which doesn't help a
user much.  So elf_backend_finish_dynamic_symbol should print its own
error message whenever returning false, or use BFD_ASSERT or abort to
print assertion failures for conditions that shouldn't occur.

This patch does that, and removes unnecessary "htab != NULL" tests in
elf_backend_finish_dynamic_symbol.  Such tests aren't needed in a
function only called via elf_backend_data.
This commit is contained in:
Alan Modra 2024-02-14 14:34:47 +10:30
parent 122d822844
commit cf95b909e2
24 changed files with 29 additions and 51 deletions

View file

@ -2486,9 +2486,6 @@ elf_arc_finish_dynamic_symbol (bfd * output_bfd,
{ {
struct elf_arc_link_hash_table *arc_htab = elf_arc_hash_table (info); struct elf_arc_link_hash_table *arc_htab = elf_arc_hash_table (info);
if (arc_htab == NULL)
return false;
if (h->dynindx == -1 if (h->dynindx == -1
|| (h->root.type != bfd_link_hash_defined || (h->root.type != bfd_link_hash_defined
&& h->root.type != bfd_link_hash_defweak) && h->root.type != bfd_link_hash_defweak)

View file

@ -17199,8 +17199,6 @@ elf32_arm_finish_dynamic_symbol (bfd * output_bfd,
struct elf32_arm_link_hash_entry *eh; struct elf32_arm_link_hash_entry *eh;
htab = elf32_arm_hash_table (info); htab = elf32_arm_hash_table (info);
if (htab == NULL)
return false;
eh = (struct elf32_arm_link_hash_entry *) h; eh = (struct elf32_arm_link_hash_entry *) h;

View file

@ -2082,8 +2082,6 @@ elf_cris_finish_dynamic_symbol (bfd *output_bfd,
const bfd_byte *plt_pic_entry = elf_cris_pic_plt_entry; const bfd_byte *plt_pic_entry = elf_cris_pic_plt_entry;
htab = elf_cris_hash_table (info); htab = elf_cris_hash_table (info);
if (htab == NULL)
return false;
/* Adjust the various PLT entry offsets. */ /* Adjust the various PLT entry offsets. */
if (bfd_get_mach (output_bfd) == bfd_mach_cris_v32) if (bfd_get_mach (output_bfd) == bfd_mach_cris_v32)

View file

@ -2105,8 +2105,6 @@ csky_elf_finish_dynamic_symbol (bfd *output_bfd,
struct csky_elf_link_hash_table *htab; struct csky_elf_link_hash_table *htab;
htab = csky_elf_hash_table (info); htab = csky_elf_hash_table (info);
if (htab == NULL)
return false;
/* Sanity check to make sure no unexpected symbol reaches here. /* Sanity check to make sure no unexpected symbol reaches here.
This matches the test in csky_elf_relocate_section handling This matches the test in csky_elf_relocate_section handling

View file

@ -4139,8 +4139,6 @@ elf32_hppa_finish_dynamic_symbol (bfd *output_bfd,
bfd_byte *loc; bfd_byte *loc;
htab = hppa_link_hash_table (info); htab = hppa_link_hash_table (info);
if (htab == NULL)
return false;
if (eh->plt.offset != (bfd_vma) -1) if (eh->plt.offset != (bfd_vma) -1)
{ {

View file

@ -3581,8 +3581,6 @@ elf_i386_finish_dynamic_symbol (bfd *output_bfd,
bool use_plt_second; bool use_plt_second;
htab = elf_x86_hash_table (info, I386_ELF_DATA); htab = elf_x86_hash_table (info, I386_ELF_DATA);
if (htab == NULL)
return false;
plt_entry_size = htab->plt.plt_entry_size; plt_entry_size = htab->plt.plt_entry_size;

View file

@ -1427,8 +1427,6 @@ lm32_elf_finish_dynamic_symbol (bfd *output_bfd,
bfd_byte *loc; bfd_byte *loc;
htab = lm32_elf_hash_table (info); htab = lm32_elf_hash_table (info);
if (htab == NULL)
return false;
if (h->plt.offset != (bfd_vma) -1) if (h->plt.offset != (bfd_vma) -1)
{ {

View file

@ -2877,8 +2877,6 @@ m32r_elf_finish_dynamic_symbol (bfd *output_bfd,
#endif #endif
htab = m32r_elf_hash_table (info); htab = m32r_elf_hash_table (info);
if (htab == NULL)
return false;
if (h->plt.offset != (bfd_vma) -1) if (h->plt.offset != (bfd_vma) -1)
{ {

View file

@ -3168,8 +3168,6 @@ microblaze_elf_finish_dynamic_symbol (bfd *output_bfd,
struct elf32_mb_link_hash_entry *eh = elf32_mb_hash_entry(h); struct elf32_mb_link_hash_entry *eh = elf32_mb_hash_entry(h);
htab = elf32_mb_hash_table (info); htab = elf32_mb_hash_table (info);
if (htab == NULL)
return false;
if (h->plt.offset != (bfd_vma) -1) if (h->plt.offset != (bfd_vma) -1)
{ {

View file

@ -2451,8 +2451,6 @@ or1k_elf_finish_dynamic_symbol (bfd *output_bfd,
bfd_byte *loc; bfd_byte *loc;
htab = or1k_elf_hash_table (info); htab = or1k_elf_hash_table (info);
if (htab == NULL)
return false;
if (h->plt.offset != (bfd_vma) -1) if (h->plt.offset != (bfd_vma) -1)
{ {

View file

@ -3505,8 +3505,7 @@ elf_s390_finish_dynamic_symbol (bfd *output_bfd,
RELATIVE reloc. The entry in the global offset table RELATIVE reloc. The entry in the global offset table
will already have been initialized in the will already have been initialized in the
relocate_section function. */ relocate_section function. */
if (!(h->def_regular || ELF_COMMON_DEF_P (h))) BFD_ASSERT (h->def_regular || ELF_COMMON_DEF_P (h));
return false;
BFD_ASSERT((h->got.offset & 1) != 0); BFD_ASSERT((h->got.offset & 1) != 0);
rela.r_info = ELF32_R_INFO (0, R_390_RELATIVE); rela.r_info = ELF32_R_INFO (0, R_390_RELATIVE);
rela.r_addend = (h->root.u.def.value rela.r_addend = (h->root.u.def.value

View file

@ -3485,7 +3485,13 @@ s3_bfd_score_elf_finish_dynamic_symbol (bfd *output_bfd,
/* FIXME: Can h->dynindex be more than 64K? */ /* FIXME: Can h->dynindex be more than 64K? */
if (h->dynindx & 0xffff0000) if (h->dynindx & 0xffff0000)
{
_bfd_error_handler
(_("%pB: cannot handle more than %d dynamic symbols"),
output_bfd, 0xffff);
bfd_set_error (bfd_error_bad_value);
return false; return false;
}
/* Fill the stub. */ /* Fill the stub. */
score_bfd_put_32 (output_bfd, STUB_LW, stub); score_bfd_put_32 (output_bfd, STUB_LW, stub);

View file

@ -3296,7 +3296,13 @@ s7_bfd_score_elf_finish_dynamic_symbol (bfd *output_bfd,
/* FIXME: Can h->dynindex be more than 64K? */ /* FIXME: Can h->dynindex be more than 64K? */
if (h->dynindx & 0xffff0000) if (h->dynindx & 0xffff0000)
{
_bfd_error_handler
(_("%pB: cannot handle more than %d dynamic symbols"),
output_bfd, 0xffff);
bfd_set_error (bfd_error_bad_value);
return false; return false;
}
/* Fill the stub. */ /* Fill the stub. */
bfd_put_32 (output_bfd, STUB_LW, stub); bfd_put_32 (output_bfd, STUB_LW, stub);

View file

@ -5945,8 +5945,6 @@ sh_elf_finish_dynamic_symbol (bfd *output_bfd, struct bfd_link_info *info,
struct elf_sh_link_hash_table *htab; struct elf_sh_link_hash_table *htab;
htab = sh_elf_hash_table (info); htab = sh_elf_hash_table (info);
if (htab == NULL)
return false;
if (h->plt.offset != (bfd_vma) -1) if (h->plt.offset != (bfd_vma) -1)
{ {

View file

@ -1898,8 +1898,6 @@ elf64_hppa_finish_dynamic_symbol (bfd *output_bfd,
struct elf64_hppa_link_hash_table *hppa_info; struct elf64_hppa_link_hash_table *hppa_info;
hppa_info = hppa_link_hash_table (info); hppa_info = hppa_link_hash_table (info);
if (hppa_info == NULL)
return false;
stub = hppa_info->stub_sec; stub = hppa_info->stub_sec;
splt = hppa_info->root.splt; splt = hppa_info->root.splt;

View file

@ -4003,8 +4003,6 @@ elf64_ia64_finish_dynamic_symbol (bfd *output_bfd,
struct elf64_ia64_dyn_sym_info *dyn_i; struct elf64_ia64_dyn_sym_info *dyn_i;
ia64_info = elf64_ia64_hash_table (info); ia64_info = elf64_ia64_hash_table (info);
if (ia64_info == NULL)
return false;
dyn_i = get_dyn_sym_info (ia64_info, h, NULL, NULL, false); dyn_i = get_dyn_sym_info (ia64_info, h, NULL, NULL, false);

View file

@ -18135,8 +18135,6 @@ ppc64_elf_finish_dynamic_symbol (bfd *output_bfd,
struct plt_entry *ent; struct plt_entry *ent;
htab = ppc_hash_table (info); htab = ppc_hash_table (info);
if (htab == NULL)
return false;
if (!htab->opd_abi && !h->def_regular) if (!htab->opd_abi && !h->def_regular)
for (ent = h->plt.plist; ent != NULL; ent = ent->next) for (ent = h->plt.plist; ent != NULL; ent = ent->next)

View file

@ -3225,8 +3225,6 @@ elf_s390_finish_dynamic_symbol (bfd *output_bfd,
struct elf_s390_link_hash_entry *eh = (struct elf_s390_link_hash_entry*)h; struct elf_s390_link_hash_entry *eh = (struct elf_s390_link_hash_entry*)h;
htab = elf_s390_hash_table (info); htab = elf_s390_hash_table (info);
if (htab == NULL)
return false;
if (h->plt.offset != (bfd_vma) -1) if (h->plt.offset != (bfd_vma) -1)
{ {
@ -3373,8 +3371,7 @@ elf_s390_finish_dynamic_symbol (bfd *output_bfd,
RELATIVE reloc. The entry in the global offset table RELATIVE reloc. The entry in the global offset table
will already have been initialized in the will already have been initialized in the
relocate_section function. */ relocate_section function. */
if (!(h->def_regular || ELF_COMMON_DEF_P (h))) BFD_ASSERT (h->def_regular || ELF_COMMON_DEF_P (h));
return false;
BFD_ASSERT((h->got.offset & 1) != 0); BFD_ASSERT((h->got.offset & 1) != 0);
rela.r_info = ELF64_R_INFO (0, R_390_RELATIVE); rela.r_info = ELF64_R_INFO (0, R_390_RELATIVE);
rela.r_addend = (h->root.u.def.value rela.r_addend = (h->root.u.def.value

View file

@ -4581,8 +4581,6 @@ elf_x86_64_finish_dynamic_symbol (bfd *output_bfd,
bool local_undefweak; bool local_undefweak;
htab = elf_x86_hash_table (info, X86_64_ELF_DATA); htab = elf_x86_hash_table (info, X86_64_ELF_DATA);
if (htab == NULL)
return false;
/* Use the second PLT section only if there is .plt section. */ /* Use the second PLT section only if there is .plt section. */
use_plt_second = htab->elf.splt != NULL && htab->plt_second != NULL; use_plt_second = htab->elf.splt != NULL && htab->plt_second != NULL;
@ -4923,8 +4921,7 @@ elf_x86_64_finish_dynamic_symbol (bfd *output_bfd,
else if (bfd_link_pic (info) else if (bfd_link_pic (info)
&& SYMBOL_REFERENCES_LOCAL_P (info, h)) && SYMBOL_REFERENCES_LOCAL_P (info, h))
{ {
if (!SYMBOL_DEFINED_NON_SHARED_P (h)) BFD_ASSERT (SYMBOL_DEFINED_NON_SHARED_P (h));
return false;
BFD_ASSERT((h->got.offset & 1) != 0); BFD_ASSERT((h->got.offset & 1) != 0);
if (info->enable_dt_relr) if (info->enable_dt_relr)
generate_dynamic_reloc = false; generate_dynamic_reloc = false;

View file

@ -9671,7 +9671,7 @@ elfNN_aarch64_finish_dynamic_symbol (bfd *output_bfd,
|| plt == NULL || plt == NULL
|| gotplt == NULL || gotplt == NULL
|| relplt == NULL) || relplt == NULL)
return false; abort ();
elfNN_aarch64_create_small_pltn_entry (h, htab, output_bfd, info); elfNN_aarch64_create_small_pltn_entry (h, htab, output_bfd, info);
if (!h->def_regular) if (!h->def_regular)
@ -9739,9 +9739,7 @@ elfNN_aarch64_finish_dynamic_symbol (bfd *output_bfd,
} }
else if (bfd_link_pic (info) && SYMBOL_REFERENCES_LOCAL (info, h)) else if (bfd_link_pic (info) && SYMBOL_REFERENCES_LOCAL (info, h))
{ {
if (!(h->def_regular || ELF_COMMON_DEF_P (h))) BFD_ASSERT (h->def_regular || ELF_COMMON_DEF_P (h));
return false;
BFD_ASSERT ((h->got.offset & 1) != 0); BFD_ASSERT ((h->got.offset & 1) != 0);
rela.r_info = ELFNN_R_INFO (0, AARCH64_R (RELATIVE)); rela.r_info = ELFNN_R_INFO (0, AARCH64_R (RELATIVE));
rela.r_addend = (h->root.u.def.value rela.r_addend = (h->root.u.def.value

View file

@ -4517,8 +4517,6 @@ elfNN_ia64_finish_dynamic_symbol (bfd *output_bfd,
struct elfNN_ia64_dyn_sym_info *dyn_i; struct elfNN_ia64_dyn_sym_info *dyn_i;
ia64_info = elfNN_ia64_hash_table (info); ia64_info = elfNN_ia64_hash_table (info);
if (ia64_info == NULL)
return false;
dyn_i = get_dyn_sym_info (ia64_info, h, NULL, NULL, false); dyn_i = get_dyn_sym_info (ia64_info, h, NULL, NULL, false);

View file

@ -4479,8 +4479,7 @@ elfNN_kvx_finish_dynamic_symbol (bfd *output_bfd,
if (bfd_link_pic (info) && SYMBOL_REFERENCES_LOCAL (info, h)) if (bfd_link_pic (info) && SYMBOL_REFERENCES_LOCAL (info, h))
{ {
if (!h->def_regular) BFD_ASSERT (h->def_regular);
return false;
/* in case of PLT related GOT entry, it is not clear who is /* in case of PLT related GOT entry, it is not clear who is
supposed to set the LSB of GOT entry... supposed to set the LSB of GOT entry...

View file

@ -3136,7 +3136,7 @@ riscv_elf_finish_dynamic_symbol (bfd *output_bfd,
|| plt == NULL || plt == NULL
|| gotplt == NULL || gotplt == NULL
|| relplt == NULL) || relplt == NULL)
return false; abort ();
/* Calculate the address of the PLT header. */ /* Calculate the address of the PLT header. */
header_address = sec_addr (plt); header_address = sec_addr (plt);

View file

@ -6842,6 +6842,7 @@ mips_elf_create_dynamic_relocation (bfd *output_bfd,
indx = 0; indx = 0;
else if (sec == NULL || sec->owner == NULL) else if (sec == NULL || sec->owner == NULL)
{ {
BFD_ASSERT (0);
bfd_set_error (bfd_error_bad_value); bfd_set_error (bfd_error_bad_value);
return false; return false;
} }
@ -11186,7 +11187,13 @@ _bfd_mips_elf_finish_dynamic_symbol (bfd *output_bfd,
sign extension at runtime in the stub, resulting in a negative sign extension at runtime in the stub, resulting in a negative
index value. */ index value. */
if (h->dynindx & ~0x7fffffff) if (h->dynindx & ~0x7fffffff)
{
_bfd_error_handler
(_("%pB: cannot handle more than %d dynamic symbols"),
output_bfd, 0x7fffffff);
bfd_set_error (bfd_error_bad_value);
return false; return false;
}
/* Fill the stub. */ /* Fill the stub. */
if (micromips_p) if (micromips_p)