Skip to content

Commit 2870439

Browse files
author
Jens Remus
committed
ld: Cleanup sframe_decoder_init_func_bfdinfo use of reloc cookie
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 <[email protected]>
1 parent 768a8d3 commit 2870439

File tree

1 file changed

+8
-9
lines changed

1 file changed

+8
-9
lines changed

bfd/elf-sframe.c

+8-9
Original file line numberDiff line numberDiff line change
@@ -98,12 +98,13 @@ sframe_decoder_set_func_reloc_index (struct sframe_dec_info *sfd_info,
9898

9999
static bool
100100
sframe_decoder_init_func_bfdinfo (bfd *abfd,
101-
asection *sec,
101+
const asection *sec,
102102
struct sframe_dec_info *sfd_info,
103-
struct elf_reloc_cookie *cookie)
103+
const struct elf_reloc_cookie *cookie)
104104
{
105105
unsigned int fde_count;
106106
unsigned int func_bfdinfo_size, i;
107+
const Elf_Internal_Rela *rel;
107108

108109
fde_count = sframe_decoder_get_num_fidx (sfd_info->sfd_ctx);
109110
sfd_info->sfd_fde_count = fde_count;
@@ -118,19 +119,17 @@ sframe_decoder_init_func_bfdinfo (bfd *abfd,
118119
if ((sec->flags & SEC_LINKER_CREATED) && cookie->rels == NULL)
119120
return true;
120121

122+
BFD_ASSERT (cookie->rels + fde_count == cookie->relend);
123+
rel = cookie->rels;
121124
for (i = 0; i < fde_count; i++)
122125
{
123-
cookie->rel = cookie->rels + i;
124-
BFD_ASSERT (cookie->rel < cookie->relend);
125126
/* Bookkeep the relocation offset and relocation index of each function
126127
for later use. */
127-
sframe_decoder_set_func_r_offset (sfd_info, i, cookie->rel->r_offset);
128-
sframe_decoder_set_func_reloc_index (sfd_info, i,
129-
(cookie->rel - cookie->rels));
128+
sframe_decoder_set_func_r_offset (sfd_info, i, rel->r_offset);
129+
sframe_decoder_set_func_reloc_index (sfd_info, i, i);
130130

131-
cookie->rel++;
131+
rel++;
132132
}
133-
BFD_ASSERT (cookie->rel == cookie->relend);
134133

135134
return true;
136135
}

0 commit comments

Comments
 (0)