[PATCH v2 1/1] readelf: invalid error message triggered when last tag is an empty string

Richard Earnshaw (lists) Richard.Earnshaw@arm.com
Mon Jun 23 15:54:11 GMT 2025


On 23/06/2025 15:15, Jan Beulich wrote:
> On 23.06.2025 12:50, Richard Earnshaw (lists) wrote:
>> On 23/06/2025 10:48, Jan Beulich wrote:
>>> On 23.06.2025 11:23, Matthieu Longo wrote:
>>>> On 2025-06-23 06:53, Jan Beulich wrote:
>>>>> On 20.06.2025 17:13, Matthieu Longo wrote:
>>>>>> On 2025-06-20 09:40, Jan Beulich wrote:
>>>>>>> On 19.06.2025 10:43, Matthieu Longo wrote:
>>>>>>>> +	    print_symbol_name ((int) maxlen, (const char *) p);
>>>>>>>
>>>>>>> ... the function will bail early if passed 0.
>>>>>>>
>>>>>>> However - is using print_symbol_name() actually correct here? Surely it
>>>>>>> is bogus to demangle this string, in the (however unlikely) event that it
>>>>>>> turns out demanglable?
>>>>>>
>>>>>> I think that it is correct. It will print "[...]" for a string finishing
>>>>>> with no null terminator, but you can trigger the printing of the string
>>>>>> until a maximum of maxlen if you pass -T (--silent-truncation) to readelf.
>>>>>
>>>>> You don't touch on the demangling aspect at all?
>>>>
>>>> Demangling should not be needed for object attributes, but 
>>>> print_symbol_name() has been working up until now, I don't have plan to 
>>>> change it unless there is a good reason.
>>>>
>>>> Do you mean by bogus here that a demangling could mistakenly be applied 
>>>> on a non-mangled string starting with chance with _Z for instance ?
>>>
>>> Yes, that's what I mean. Imo the function should be used only for what
>>> truly is a symbol name. (It's likely even wrong to call it for e.g.
>>> section names, for the same reason.)
>>
>> Well looking through readelf there are /many/ places where print_symbol_name is called with something that is obviously not a symbol:
>>
>>         print_symbol_name (22, sec_name);
>>
>>         print_symbol_name (-17, printable_section_name (filedata, section));
>>
>> Are a couple of obvious ones.
>>
>> ISTM that it's probably the name of this function that is now misleading rather than this use that is especially incorrect and really the name should reflect that it is a general output routine with some formatting assistance (padding or length limiting).
> 
> Except that then the function would need to have a boolean added indicating whether
> to try demangling in the first place.
> 
> Jan

print_symbol_name (signed int width, const char *str) 
{
  print_string_1 (width, str, do_demangle);
}

print_string (signed int width, const char *str)
{
  print_string_1 (width, str, false);
}

and then rename the existing print_symbol_name implementation as print_string_1, changing the direct use of do_demangle to use the new argument.

Finally update callers as needed.

R.


More information about the Binutils mailing list