[v3,2/3] ld: Cleanup sframe_decoder_init_func_bfdinfo use of reloc cookie
Checks
Context |
Check |
Description |
linaro-tcwg-bot/tcwg_binutils_build--master-arm |
success
|
Build passed
|
linaro-tcwg-bot/tcwg_binutils_build--master-aarch64 |
success
|
Build passed
|
linaro-tcwg-bot/tcwg_binutils_check--master-arm |
success
|
Test passed
|
linaro-tcwg-bot/tcwg_binutils_check--master-aarch64 |
success
|
Test passed
|
Commit Message
The loop did set cookie->rel to the i-th relocation twice. At the
beginning using the loop counter. At the end by incrementing. One
approach is sufficient.
Change cookie to pointer-to-const, replace cookie->rel by rel,
initialize before the loop and increment at the end, and merge the
two assertions (for cookie->rel) into one.
While at it change sec to pointer-to-const.
bfd/
* elf-sframe.c (sframe_decoder_init_func_bfdinfo): Cleanup use
of relocation cookie.
Signed-off-by: Jens Remus <jremus@linux.ibm.com>
---
Notes (jremus):
Changes in V2:
- Replaced "cookie->rel - cookie->rel" by "i". (Jan)
- Merged assertions for cookie->rel. (Andreas)
- Changed cookie into pointer-to-const. (Jan)
- Changed sec into pointer-to-const.
- Reworded commit subject and message and added missing GNU ChangeLog.
bfd/elf-sframe.c | 17 ++++++++---------
1 file changed, 8 insertions(+), 9 deletions(-)
Comments
On 28.02.2025 14:32, Jens Remus wrote:
> The loop did set cookie->rel to the i-th relocation twice. At the
> beginning using the loop counter. At the end by incrementing. One
> approach is sufficient.
>
> Change cookie to pointer-to-const, replace cookie->rel by rel,
> initialize before the loop and increment at the end, and merge the
> two assertions (for cookie->rel) into one.
>
> While at it change sec to pointer-to-const.
>
> bfd/
> * elf-sframe.c (sframe_decoder_init_func_bfdinfo): Cleanup use
> of relocation cookie.
>
> Signed-off-by: Jens Remus <jremus@linux.ibm.com>
Okay.
Jan
@@ -98,12 +98,13 @@ sframe_decoder_set_func_reloc_index (struct sframe_dec_info *sfd_info,
static bool
sframe_decoder_init_func_bfdinfo (bfd *abfd,
- asection *sec,
+ const asection *sec,
struct sframe_dec_info *sfd_info,
- struct elf_reloc_cookie *cookie)
+ const struct elf_reloc_cookie *cookie)
{
unsigned int fde_count;
unsigned int func_bfdinfo_size, i;
+ const Elf_Internal_Rela *rel;
fde_count = sframe_decoder_get_num_fidx (sfd_info->sfd_ctx);
sfd_info->sfd_fde_count = fde_count;
@@ -118,19 +119,17 @@ sframe_decoder_init_func_bfdinfo (bfd *abfd,
if ((sec->flags & SEC_LINKER_CREATED) && cookie->rels == NULL)
return true;
+ BFD_ASSERT (cookie->rels + fde_count == cookie->relend);
+ rel = cookie->rels;
for (i = 0; i < fde_count; i++)
{
- cookie->rel = cookie->rels + i;
- BFD_ASSERT (cookie->rel < cookie->relend);
/* Bookkeep the relocation offset and relocation index of each function
for later use. */
- sframe_decoder_set_func_r_offset (sfd_info, i, cookie->rel->r_offset);
- sframe_decoder_set_func_reloc_index (sfd_info, i,
- (cookie->rel - cookie->rels));
+ sframe_decoder_set_func_r_offset (sfd_info, i, rel->r_offset);
+ sframe_decoder_set_func_reloc_index (sfd_info, i, i);
- cookie->rel++;
+ rel++;
}
- BFD_ASSERT (cookie->rel == cookie->relend);
return true;
}