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);
if (arc_htab == NULL)
return false;
if (h->dynindx == -1
|| (h->root.type != bfd_link_hash_defined
&& 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;
htab = elf32_arm_hash_table (info);
if (htab == NULL)
return false;
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;
htab = elf_cris_hash_table (info);
if (htab == NULL)
return false;
/* Adjust the various PLT entry offsets. */
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;
htab = csky_elf_hash_table (info);
if (htab == NULL)
return false;
/* Sanity check to make sure no unexpected symbol reaches here.
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;
htab = hppa_link_hash_table (info);
if (htab == NULL)
return false;
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;
htab = elf_x86_hash_table (info, I386_ELF_DATA);
if (htab == NULL)
return false;
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;
htab = lm32_elf_hash_table (info);
if (htab == NULL)
return false;
if (h->plt.offset != (bfd_vma) -1)
{

View File

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

View File

@ -2451,8 +2451,6 @@ or1k_elf_finish_dynamic_symbol (bfd *output_bfd,
bfd_byte *loc;
htab = or1k_elf_hash_table (info);
if (htab == NULL)
return false;
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
will already have been initialized in the
relocate_section function. */
if (!(h->def_regular || ELF_COMMON_DEF_P (h)))
return false;
BFD_ASSERT (h->def_regular || ELF_COMMON_DEF_P (h));
BFD_ASSERT((h->got.offset & 1) != 0);
rela.r_info = ELF32_R_INFO (0, R_390_RELATIVE);
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? */
if (h->dynindx & 0xffff0000)
return false;
{
_bfd_error_handler
(_("%pB: cannot handle more than %d dynamic symbols"),
output_bfd, 0xffff);
bfd_set_error (bfd_error_bad_value);
return false;
}
/* Fill the 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? */
if (h->dynindx & 0xffff0000)
return false;
{
_bfd_error_handler
(_("%pB: cannot handle more than %d dynamic symbols"),
output_bfd, 0xffff);
bfd_set_error (bfd_error_bad_value);
return false;
}
/* Fill the 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;
htab = sh_elf_hash_table (info);
if (htab == NULL)
return false;
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;
hppa_info = hppa_link_hash_table (info);
if (hppa_info == NULL)
return false;
stub = hppa_info->stub_sec;
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;
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);

View File

@ -18135,8 +18135,6 @@ ppc64_elf_finish_dynamic_symbol (bfd *output_bfd,
struct plt_entry *ent;
htab = ppc_hash_table (info);
if (htab == NULL)
return false;
if (!htab->opd_abi && !h->def_regular)
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;
htab = elf_s390_hash_table (info);
if (htab == NULL)
return false;
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
will already have been initialized in the
relocate_section function. */
if (!(h->def_regular || ELF_COMMON_DEF_P (h)))
return false;
BFD_ASSERT (h->def_regular || ELF_COMMON_DEF_P (h));
BFD_ASSERT((h->got.offset & 1) != 0);
rela.r_info = ELF64_R_INFO (0, R_390_RELATIVE);
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;
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_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)
&& SYMBOL_REFERENCES_LOCAL_P (info, h))
{
if (!SYMBOL_DEFINED_NON_SHARED_P (h))
return false;
BFD_ASSERT (SYMBOL_DEFINED_NON_SHARED_P (h));
BFD_ASSERT((h->got.offset & 1) != 0);
if (info->enable_dt_relr)
generate_dynamic_reloc = false;

View File

@ -9671,7 +9671,7 @@ elfNN_aarch64_finish_dynamic_symbol (bfd *output_bfd,
|| plt == NULL
|| gotplt == NULL
|| relplt == NULL)
return false;
abort ();
elfNN_aarch64_create_small_pltn_entry (h, htab, output_bfd, info);
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))
{
if (!(h->def_regular || ELF_COMMON_DEF_P (h)))
return false;
BFD_ASSERT (h->def_regular || ELF_COMMON_DEF_P (h));
BFD_ASSERT ((h->got.offset & 1) != 0);
rela.r_info = ELFNN_R_INFO (0, AARCH64_R (RELATIVE));
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;
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);

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 (!h->def_regular)
return false;
BFD_ASSERT (h->def_regular);
/* in case of PLT related GOT entry, it is not clear who is
supposed to set the LSB of GOT entry...

View File

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

View File

@ -6842,6 +6842,7 @@ mips_elf_create_dynamic_relocation (bfd *output_bfd,
indx = 0;
else if (sec == NULL || sec->owner == NULL)
{
BFD_ASSERT (0);
bfd_set_error (bfd_error_bad_value);
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
index value. */
if (h->dynindx & ~0x7fffffff)
return false;
{
_bfd_error_handler
(_("%pB: cannot handle more than %d dynamic symbols"),
output_bfd, 0x7fffffff);
bfd_set_error (bfd_error_bad_value);
return false;
}
/* Fill the stub. */
if (micromips_p)