section tdata tidy

Any _new_section_hook that is not itself called from another
_new_section_hook will always see used_by_bfd NULL.  Remove those
NULL checks in such hooks, and tidy code a little.
This commit is contained in:
Alan Modra 2024-12-16 15:04:57 +10:30
parent 1c82e1ee93
commit f5a8cdea56
18 changed files with 98 additions and 170 deletions

View File

@ -18535,16 +18535,10 @@ elf32_arm_filter_implib_symbols (bfd *abfd ATTRIBUTE_UNUSED,
static bool
elf32_arm_new_section_hook (bfd *abfd, asection *sec)
{
if (!sec->used_by_bfd)
{
_arm_elf_section_data *sdata;
size_t amt = sizeof (*sdata);
sdata = (_arm_elf_section_data *) bfd_zalloc (abfd, amt);
_arm_elf_section_data *sdata = bfd_zalloc (abfd, sizeof (*sdata));
if (sdata == NULL)
return false;
sec->used_by_bfd = sdata;
}
return _bfd_elf_new_section_hook (abfd, sec);
}

View File

@ -763,17 +763,13 @@ struct elf_avr_section_data
static bool
elf_avr_new_section_hook (bfd *abfd, asection *sec)
{
if (!sec->used_by_bfd)
{
struct elf_avr_section_data *sdata;
size_t amt = sizeof (*sdata);
sdata = bfd_zalloc (abfd, amt);
sdata = bfd_zalloc (abfd, sizeof (*sdata));
if (sdata == NULL)
return false;
sec->used_by_bfd = sdata;
}
return _bfd_elf_new_section_hook (abfd, sec);
}

View File

@ -741,17 +741,13 @@ struct _microblaze_elf_section_data
static bool
microblaze_elf_new_section_hook (bfd *abfd, asection *sec)
{
if (!sec->used_by_bfd)
{
struct _microblaze_elf_section_data *sdata;
size_t amt = sizeof (*sdata);
sdata = bfd_zalloc (abfd, amt);
sdata = bfd_zalloc (abfd, sizeof (*sdata));
if (sdata == NULL)
return false;
sec->used_by_bfd = sdata;
}
return _bfd_elf_new_section_hook (abfd, sec);
}

View File

@ -4056,9 +4056,8 @@ static bool
s3_elf32_score_new_section_hook (bfd *abfd, asection *sec)
{
struct _score_elf_section_data *sdata;
size_t amt = sizeof (*sdata);
sdata = bfd_zalloc (abfd, amt);
sdata = bfd_zalloc (abfd, sizeof (*sdata));
if (sdata == NULL)
return false;
sec->used_by_bfd = sdata;

View File

@ -3863,9 +3863,8 @@ bool
s7_elf32_score_new_section_hook (bfd *abfd, asection *sec)
{
struct _score_elf_section_data *sdata;
size_t amt = sizeof (*sdata);
sdata = bfd_zalloc (abfd, amt);
sdata = bfd_zalloc (abfd, sizeof (*sdata));
if (sdata == NULL)
return false;
sec->used_by_bfd = sdata;

View File

@ -246,8 +246,6 @@ spu_elf_rel9 (bfd *abfd, arelent *reloc_entry, asymbol *symbol,
static bool
spu_elf_new_section_hook (bfd *abfd, asection *sec)
{
if (!sec->used_by_bfd)
{
struct _spu_elf_section_data *sdata;
@ -255,7 +253,6 @@ spu_elf_new_section_hook (bfd *abfd, asection *sec)
if (sdata == NULL)
return false;
sec->used_by_bfd = sdata;
}
return _bfd_elf_new_section_hook (abfd, sec);
}

View File

@ -2083,18 +2083,12 @@ static bool
elf32_tic6x_new_section_hook (bfd *abfd, asection *sec)
{
bool ret;
/* Allocate target specific section data. */
if (!sec->used_by_bfd)
{
_tic6x_elf_section_data *sdata;
size_t amt = sizeof (*sdata);
sdata = (_tic6x_elf_section_data *) bfd_zalloc (abfd, amt);
sdata = bfd_zalloc (abfd, sizeof (*sdata));
if (sdata == NULL)
return false;
sec->used_by_bfd = sdata;
}
ret = _bfd_elf_new_section_hook (abfd, sec);
sec->use_rela_p = elf32_tic6x_tdata (abfd)->use_rela_p;

View File

@ -6100,17 +6100,13 @@ struct elf_xtensa_section_data
static bool
elf_xtensa_new_section_hook (bfd *abfd, asection *sec)
{
if (!sec->used_by_bfd)
{
struct elf_xtensa_section_data *sdata;
size_t amt = sizeof (*sdata);
sdata = bfd_zalloc (abfd, amt);
sdata = bfd_zalloc (abfd, sizeof (*sdata));
if (sdata == NULL)
return false;
sec->used_by_bfd = sdata;
}
return _bfd_elf_new_section_hook (abfd, sec);
}

View File

@ -827,17 +827,13 @@ bfd_elf64_bfd_reloc_name_lookup (bfd *abfd ATTRIBUTE_UNUSED,
static bool
mmix_elf_new_section_hook (bfd *abfd, asection *sec)
{
if (!sec->used_by_bfd)
{
struct _mmix_elf_section_data *sdata;
size_t amt = sizeof (*sdata);
sdata = bfd_zalloc (abfd, amt);
sdata = bfd_zalloc (abfd, sizeof (*sdata));
if (sdata == NULL)
return false;
sec->used_by_bfd = sdata;
}
return _bfd_elf_new_section_hook (abfd, sec);
}

View File

@ -2049,17 +2049,13 @@ struct _ppc64_elf_section_data
static bool
ppc64_elf_new_section_hook (bfd *abfd, asection *sec)
{
if (!sec->used_by_bfd)
{
struct _ppc64_elf_section_data *sdata;
size_t amt = sizeof (*sdata);
sdata = bfd_zalloc (abfd, amt);
sdata = bfd_zalloc (abfd, sizeof (*sdata));
if (sdata == NULL)
return false;
sec->used_by_bfd = sdata;
}
return _bfd_elf_new_section_hook (abfd, sec);
}

View File

@ -8748,19 +8748,14 @@ elfNN_aarch64_output_arch_local_syms (bfd *output_bfd,
static bool
elfNN_aarch64_new_section_hook (bfd *abfd, asection *sec)
{
if (!sec->used_by_bfd)
{
_aarch64_elf_section_data *sdata;
size_t amt = sizeof (*sdata);
sdata = bfd_zalloc (abfd, amt);
record_section_with_aarch64_elf_section_data (sec);
sdata = bfd_zalloc (abfd, sizeof (*sdata));
if (sdata == NULL)
return false;
sec->used_by_bfd = sdata;
}
record_section_with_aarch64_elf_section_data (sec);
return _bfd_elf_new_section_hook (abfd, sec);
}

View File

@ -3687,17 +3687,13 @@ elfNN_kvx_output_arch_local_syms (bfd *output_bfd,
static bool
elfNN_kvx_new_section_hook (bfd *abfd, asection *sec)
{
if (!sec->used_by_bfd)
{
_kvx_elf_section_data *sdata;
bfd_size_type amt = sizeof (*sdata);
sdata = bfd_zalloc (abfd, amt);
sdata = bfd_zalloc (abfd, sizeof (*sdata));
if (sdata == NULL)
return false;
sec->used_by_bfd = sdata;
}
return _bfd_elf_new_section_hook (abfd, sec);
}

View File

@ -151,17 +151,13 @@ struct loongarch_elf_section_data
interactions between DT_RELR and relaxation. */
static bool
loongarch_elf_new_section_hook (bfd *abfd, asection *sec)
{
if (!sec->used_by_bfd)
{
struct loongarch_elf_section_data *sdata;
size_t amt = sizeof (*sdata);
sdata = bfd_zalloc (abfd, amt);
sdata = bfd_zalloc (abfd, sizeof (*sdata));
if (!sdata)
return false;
sec->used_by_bfd = sdata;
}
return _bfd_elf_new_section_hook (abfd, sec);
}

View File

@ -1411,17 +1411,13 @@ _bfd_mips_elf_free_cached_info (bfd *abfd)
bool
_bfd_mips_elf_new_section_hook (bfd *abfd, asection *sec)
{
if (!sec->used_by_bfd)
{
struct _mips_elf_section_data *sdata;
size_t amt = sizeof (*sdata);
sdata = bfd_zalloc (abfd, amt);
sdata = bfd_zalloc (abfd, sizeof (*sdata));
if (sdata == NULL)
return false;
sec->used_by_bfd = sdata;
}
return _bfd_elf_new_section_hook (abfd, sec);
}

View File

@ -2659,17 +2659,13 @@ _bfd_sparc_elf_late_size_sections (bfd *output_bfd,
bool
_bfd_sparc_elf_new_section_hook (bfd *abfd, asection *sec)
{
if (!sec->used_by_bfd)
{
struct _bfd_sparc_elf_section_data *sdata;
size_t amt = sizeof (*sdata);
sdata = bfd_zalloc (abfd, amt);
sdata = bfd_zalloc (abfd, sizeof (*sdata));
if (sdata == NULL)
return false;
sec->used_by_bfd = sdata;
}
return _bfd_elf_new_section_hook (abfd, sec);
}

View File

@ -3520,16 +3520,7 @@ bfd_mach_o_read_header (bfd *abfd, file_ptr hdr_off, bfd_mach_o_header *header)
bool
bfd_mach_o_new_section_hook (bfd *abfd, asection *sec)
{
bfd_mach_o_section *s;
unsigned bfdalign = bfd_section_alignment (sec);
s = bfd_mach_o_get_mach_o_section (sec);
if (s == NULL)
{
flagword bfd_flags;
static const mach_o_section_name_xlat * xlat;
s = (bfd_mach_o_section *) bfd_zalloc (abfd, sizeof (*s));
bfd_mach_o_section *s = bfd_zalloc (abfd, sizeof (*s));
if (s == NULL)
return false;
sec->used_by_bfd = s;
@ -3539,21 +3530,21 @@ bfd_mach_o_new_section_hook (bfd *abfd, asection *sec)
If this is a canonical name for which a specific paiting exists
there will also be defined flags, type, attribute and alignment
values. */
xlat = bfd_mach_o_convert_section_name_to_mach_o (abfd, sec, s);
const mach_o_section_name_xlat *xlat
= bfd_mach_o_convert_section_name_to_mach_o (abfd, sec, s);
if (xlat != NULL)
{
s->flags = xlat->macho_sectype | xlat->macho_secattr;
s->align = xlat->sectalign > bfdalign ? xlat->sectalign
: bfdalign;
unsigned bfdalign = bfd_section_alignment (sec);
s->align = xlat->sectalign > bfdalign ? xlat->sectalign : bfdalign;
bfd_set_section_alignment (sec, s->align);
bfd_flags = bfd_section_flags (sec);
flagword bfd_flags = bfd_section_flags (sec);
if (bfd_flags == SEC_NO_FLAGS)
bfd_set_section_flags (sec, xlat->bfd_flags);
}
else
/* Create default flags. */
bfd_mach_o_set_section_flags_from_bfd (abfd, sec);
}
return _bfd_generic_new_section_hook (abfd, sec);
}

View File

@ -2128,8 +2128,6 @@ mmo_scan (bfd *abfd)
static bool
mmo_new_section_hook (bfd *abfd, asection *newsect)
{
if (!newsect->used_by_bfd)
{
/* We zero-fill all fields and assume NULL is represented by an all
zero-bit pattern. */
@ -2137,7 +2135,6 @@ mmo_new_section_hook (bfd *abfd, asection *newsect)
= bfd_zalloc (abfd, sizeof (struct mmo_section_data_struct));
if (!newsect->used_by_bfd)
return false;
}
/* Always align to at least 32-bit words. */
newsect->alignment_power = 2;

View File

@ -5327,15 +5327,13 @@ extern const bfd_target hppa_som_vec;
static bool
som_new_section_hook (bfd *abfd, asection *newsect)
{
if (!newsect->used_by_bfd)
{
size_t amt = sizeof (struct som_section_data_struct);
newsect->used_by_bfd = bfd_zalloc (abfd, amt);
if (!newsect->used_by_bfd)
return false;
}
newsect->alignment_power = 3;
/* We allow more than three sections internally. */