[PATCH 2/4] objdump: don't compare sections by name

Jan Beulich jbeulich@suse.com
Thu Mar 6 17:04:22 GMT 2025


On 06.03.2025 18:00, Jan Beulich wrote:
> On 28.02.2025 09:14, Alan Modra wrote:
>> On Fri, Feb 28, 2025 at 09:00:27AM +1030, Alan Modra wrote:
>>> Yes, the commit 660df28acfa1 change to compare_symbols should have
>>> used the same logic as that in sym_ok.  Ideally both places would not
>>> compare section names.  Exactly how to match a section in the real
>>> object file with a section in a debug file might be a little tricky,
>>> which is probably why commit 39f0547e554d used names.  Binutils
>>> objcopy tries to keep as much section info intact as possible when
>>> creating debug-only files, for example vma and size match for
>>> corresponding sections.
>>
>> Like this, which works for your testcase.
>>
>> diff --git a/binutils/objdump.c b/binutils/objdump.c
>> index 5ab29a719bc..e31da826c44 100644
>> --- a/binutils/objdump.c
>> +++ b/binutils/objdump.c
>> @@ -1107,6 +1107,28 @@ remove_useless_symbols (asymbol **symbols, long count)
>>    return out_ptr - symbols;
>>  }
>>  
>> +/* Return true iff SEC1 and SEC2 are the same section.
>> +   This would just be a simple pointer comparison except that one of
>> +   the sections might be from a separate debug info file.  */
>> +
>> +static bool
>> +is_same_section (const asection *sec1, const asection *sec2)
>> +{
>> +  if (sec1 == sec2)
>> +    return true;
>> +  if (sec1->owner == sec2->owner
>> +      || sec1->owner == NULL
>> +      || sec2->owner == NULL)
>> +    return false;
> 
> For my own education: In which situation may ->owner be NULL?
> 
> Other than that I'd like to integrate this into my patch then, mentioning
> you as co-author (perhaps even the main one). Provided that's okay with
> you.

Should have checked the tree first - I see you put this in already. Thanks!

Jan


More information about the Binutils mailing list