[PATCH v9 06/19] bfd: write Object Attributes v2
Jan Beulich
jbeulich@suse.com
Fri Nov 14 07:04:35 GMT 2025
On 13.11.2025 20:51, Matthieu Longo wrote:
> On 07/11/2025 08:23, Jan Beulich wrote:
>> On 05.11.2025 11:18, Matthieu Longo wrote:
>>> On 30/10/2025 15:55, Jan Beulich wrote:
>>>> On 01.09.2025 18:56, Matthieu Longo wrote:
>>>>> --- a/gas/write.c
>>>>> +++ b/gas/write.c
>>>>> @@ -1919,6 +1919,8 @@ create_obj_attrs_section (void)
>>>>> bfd_set_section_flags (s, SEC_READONLY | SEC_DATA);
>>>>> frag_now_fix ();
>>>>> char *p = frag_more (size);
>>>>> +
>>>>> + bfd_elf_obj_attr_finalize_contents (stdoutput);
>>>>> bfd_elf_set_obj_attr_contents (stdoutput, (bfd_byte *)p, size);
>>>>
>>>> Why is another export needed from libbfd? Can't bfd_elf_set_obj_attr_contents()
>>>> simply do whatever it takes? The other caller likely needs doing the same anyway?
>>>
>>> bfd_elf_set_obj_attr_contents() is also used in objcpy, and objcpy
>>> should not change the order of subsections and attributes, but simply
>>> make a copy of the data as they were in the original object.
>>
>> Is this the case already prior to your series? I can't seem to be able to
>> identify the call path for that case. Besides the direct call from gas,
>> bfd_elf_set_obj_attr_contents() is called only from
>> _bfd_elf_write_section_build_attributes(), which in turn is called solely by
>> bfd_elf_final_link(). And I can't see this being used by objcopy.
>>
>
> Sorry, I said something wrong. It is not used for objcopy but by the
> linker in _bfd_elf_write_section_object_attributes().
>
> In the case of the link, all the subsections and attributes are already
> sorted by the merge, so no need to sort them again.
>
>>> Another possibility might be to add a parameter to
>>> bfd_elf_set_obj_attr_contents() to enable/disable the sorting.
>>
>> Can the distinction not be made by what struct bfd_link_info contains?
>>
>> Jan
>
> Here is the new approach after having eliminated
> bfd_elf_obj_attr_finalize_contents(). It relies on is_linker_output
> being set to 1 in the case of the linker. Is it the approach that you
> had in mind ?
>
> /* Write the contents of the object attributes section to CONTENTS. */
> void
> bfd_elf_set_obj_attr_contents (bfd *abfd, bfd_byte *buffer, bfd_vma size)
> {
> if ((! abfd->is_linker_output)
> && elf_obj_attr_version (abfd) == OBJ_ATTR_V2)
> /* Before dumping the data, sort subsections in alphabetical order, and
> attributes according to their tag in numerical order. This is
> useful
> for diagnostic tools so that they dump the same output even if the
> subsections or their attributes were not declared in the same
> order in
> different files.
> This sorting is only performed in the case of the assembler. In the
> case of the linker, the subsections and attributes are already
> sorted
> by the merge process. */
> oav2_sort_subsections (&elf_obj_attr_subsections (abfd));
>
> obj_attr_version_t version = elf_obj_attr_version (abfd);
> if (version == OBJ_ATTR_V1)
> oav1_write_section (abfd, buffer, size);
> else if (version == OBJ_ATTR_V2)
> oav2_write_section (abfd, buffer, size);
> else
> abort ();
> }
Yes, this looks good to me. Thanks.
Jan
More information about the Binutils
mailing list