[PATCH] readelf: Don't change the symbol table

Jan Beulich jbeulich@suse.com
Wed Sep 3 13:13:30 GMT 2025


On 03.09.2025 15:08, H.J. Lu wrote:
> On Tue, Sep 2, 2025 at 11:09 PM Jan Beulich <jbeulich@suse.com> wrote:
>>
>> On 02.09.2025 23:30, H.J. Lu wrote:
>>> 1. Update dump_relr_relocations not to change the symbol table.
>>
>> I think it would nice to make such more explicit, by ...
>>
>>> @@ -1880,13 +1879,13 @@ dump_relr_relocations (Filedata *          filedata,
>>>                      uint64_t            relr_size,
>>>                      int                 relr_entsize,
>>>                      uint64_t            relr_offset,
>>> +                    uint64_t          * relrs,
>>>                      Elf_Internal_Sym *  symtab,
>>
>> ... making both of these pointer-to-const. That'll require some adjustment
>> further down afaict. (For relrs the freeing then may want leaving to the
>> caller when non-NULL was passed in, as casting away const-ness is awkward.)
> 
> I changed to
> 
> static bool
> dump_relr_relocations (Filedata *          filedata,
>                        uint64_t            relr_size,
>                        int                 relr_entsize,
>                        uint64_t            relr_offset,
>                        uint64_t *          relrs,
>                        const Elf_Internal_Sym * symtab_p,
>                        uint64_t            nsyms,
>                        char *              strtab,
>                        uint64_t            strtablen,
>                        bool                dump_reloc)
> 
> in the v2 patch.   I kept "free (relrs)" in dump_relr_relocations since
> it may be malloced in dump_relr_relocations.

As you say - may. Freeing what the caller passed in may be unexpected to the
caller (or anything higher up / running later).

Jan


More information about the Binutils mailing list