[2/5] readelf: Use BYTE_GET_SIZE in RELR relocation processing
Checks
| Context |
Check |
Description |
| linaro-tcwg-bot/tcwg_binutils_build--master-aarch64 |
success
|
Build passed
|
| linaro-tcwg-bot/tcwg_binutils_build--master-arm |
success
|
Build passed
|
| linaro-tcwg-bot/tcwg_binutils_check--master-aarch64 |
success
|
Test passed
|
| linaro-tcwg-bot/tcwg_binutils_check--master-arm |
success
|
Test passed
|
Commit Message
Replace
if (relr_entsize == sizeof (Elf32_External_Relr))
entry = BYTE_GET (((Elf32_External_Relr *)relrs)[i].r_data);
else
entry = BYTE_GET (((Elf64_External_Relr *)relrs)[i].r_data);
with
BYTE_GET_SIZE (entry, relrs, relr_entsize);
PR binutils/34356
* readelf.c (count_relr_relocations): Change relrs_p to void **.
Use BYTE_GET_SIZE.
(dump_relr_relocations): Change relrs to void *. Use
BYTE_GET_SIZE.
(display_relocations): Change relrs to void *.
(process_relocs): Likewise.
Signed-off-by: H.J. Lu <hjl.tools@gmail.com>
---
binutils/readelf.c | 21 ++++++++-------------
1 file changed, 8 insertions(+), 13 deletions(-)
Comments
On 09.07.2026 14:40, H.J. Lu wrote:
> Replace
>
> if (relr_entsize == sizeof (Elf32_External_Relr))
> entry = BYTE_GET (((Elf32_External_Relr *)relrs)[i].r_data);
> else
> entry = BYTE_GET (((Elf64_External_Relr *)relrs)[i].r_data);
>
> with
>
> BYTE_GET_SIZE (entry, relrs, relr_entsize);
>
> PR binutils/34356
> * readelf.c (count_relr_relocations): Change relrs_p to void **.
> Use BYTE_GET_SIZE.
> (dump_relr_relocations): Change relrs to void *. Use
> BYTE_GET_SIZE.
> (display_relocations): Change relrs to void *.
> (process_relocs): Likewise.
>
> Signed-off-by: H.J. Lu <hjl.tools@gmail.com>
Other than for patch 1 (and by implication patches 3-5), this one looks
okay to me. Yet of course as presented it has a dependency on patch 1.
Jan
@@ -1856,9 +1856,9 @@ update_all_relocations (size_t nentries)
static uint64_t
count_relr_relocations (Filedata * filedata,
Elf_Internal_Shdr * section,
- uint64_t ** relrs_p)
+ void ** relrs_p)
{
- uint64_t * relrs;
+ void * relrs;
uint64_t nentries;
uint64_t i;
uint64_t count;
@@ -1886,14 +1886,12 @@ count_relr_relocations (Filedata * filedata,
if (relrs == NULL)
return 0;
+ void *ptr = relrs;
for (count = i = 0; i < nentries; i++)
{
uint64_t entry;
- if (entsize == sizeof (Elf32_External_Relr))
- entry = BYTE_GET (((Elf32_External_Relr *)relrs)[i].r_data);
- else
- entry = BYTE_GET (((Elf64_External_Relr *)relrs)[i].r_data);
+ BYTE_GET_SIZE (entry, ptr, entsize);
if ((entry & 1) == 0)
{
@@ -1923,7 +1921,7 @@ dump_relr_relocations (Filedata * filedata,
uint64_t relr_size,
int relr_entsize,
uint64_t relr_offset,
- uint64_t * relrs,
+ void * relrs,
const Elf_Internal_Sym * symtab_p,
uint64_t nsyms,
char * strtab,
@@ -2151,10 +2149,7 @@ dump_relr_relocations (Filedata * filedata,
{
uint64_t entry;
- if (relr_entsize == sizeof (Elf32_External_Relr))
- entry = BYTE_GET (((Elf32_External_Relr *)relrs)[i].r_data);
- else
- entry = BYTE_GET (((Elf64_External_Relr *)relrs)[i].r_data);
+ BYTE_GET_SIZE (entry, relrs, relr_entsize);
if (dump_reloc)
{
@@ -9999,7 +9994,7 @@ display_relocations (Elf_Internal_Shdr * section,
uint64_t rel_offset = section->sh_offset;
uint64_t num_rela = rel_size / section->sh_entsize;
uint64_t num_reloc;
- uint64_t *relrs = NULL;
+ void *relrs = NULL;
if (rel_type == reltype_relr)
{
@@ -10187,7 +10182,7 @@ process_relocs (Filedata * filedata)
/* Count DT_RELR relocations when "-D --got-contents"
is passed to readelf. */
uint64_t num_reloc;
- uint64_t *relrs = NULL;
+ void *relrs = NULL;
Elf_Internal_Shdr section = {};
Elf_Internal_Shdr *orig_section = NULL;
section.sh_offset