[PATCH] ld: aarch64: Fix scanning of GNU properties for AARCH64_FEATURE_1_AND

Matthieu Longo matthieu.longo@arm.com
Tue Apr 1 09:58:02 GMT 2025


On 2025-04-01 10:29, Yury Khrustalev wrote:
> On Tue, Apr 01, 2025 at 10:21:19AM +0100, Matthieu Longo wrote:
>> On 2025-03-27 17:09, Yury Khrustalev wrote:
>>> Fixes [1]. Previously iteration over GNU properties of an input file
>>
>> ...
>>
>> This loop is run after _bfd_elf_link_setup_gnu_properties which should
>> already have merged and sorted the GNU properties.
>>
>> Consequently, GNU_PROPERTY_MEMORY_SEAL (=0x3) should be located before
>> GNU_PROPERTY_AARCH64_FEATURE_1_AND (=0xc0000000), and the shortcut exit
>> condition of the loop should still be valid.
> 
> Why do we need this condition in the first place?
> 
> ```
> GNU_PROPERTY_AARCH64_FEATURE_1_AND <= p->property.pr_type
> ```
> 
> Why do we need to stop the loop as soon as we reach the property with the
> number more than `AARCH64_FEATURE_1_AND` (thus depending on the order of
> properties)?
> 

This exit condition is only an optimization. Since the collection of GNU 
properties is assumed to be sorted at this stage, it makes sense to 
apply a shortcut if the current properties is greater than 
GNU_PROPERTY_AARCH64_FEATURE_1_AND. Otherwise what is the point of 
sorting the GNU properties in the first place ?
The issue you experienced is a symptom of a bug in the sorting of the 
GNU properties.

Minor note: replacing this for-loop by a find that returns a pointer on 
the GNU property would make the code more explicit regarding the intent. 
I am sure there are plenty of places where we use a raw for-loop search, 
and mix other unrelated logic into it. It would be nice to clean this up.


More information about the Binutils mailing list