[PATCH v1 1/1] gas/write.c: add explicitly flag SEC_HAS_CONTENT to object attributes section
Jan Beulich
jbeulich@suse.com
Fri Jun 27 06:55:11 GMT 2025
On 25.06.2025 16:57, Matthieu Longo wrote:
> The object attributes section:
> - is readonly (SEC_READONLY=1).
> - only contains data (SEC_DATA=1).
> - does not require the OS to allocate space at runtime
> (SEC_ALLOC=0).
> - does not require the OS to load the section at runtime
> (SEC_LOAD=0).
> - is written out to the output object if it is not empty
> (SEC_HAS_CONTENT=1).
>
> Today, the setting of SEC_HAS_CONTENT (if not specified by
> bfd_set_section_flags) occurs a few lines below inside
> size_seg (see code below), the last function called in
> create_obj_attrs_section().
>
> // If this section is not empty (size > 0) and this section
> // is not .bss, the flag is set.
> if (size > 0 && ! seginfo->bss)
> flags |= SEC_HAS_CONTENTS;
>
> Setting the flag SEC_HAS_CONTENT via bfd_set_section_flags()
> instead of relying on the hidden side-effect of size_seg()
> seems a more maintainable approach due to its explicitness.
One can also look at this the other way around: It may be undue open-
coding that you suggest to add. Look at maybe_generate_build_notes():
It sets the flag unconditionally, but calls bfd_set_section_contents()
only conditionally. If it (properly) left the setting of the flag to
size_seg(), things would be more consistent overall. (And yes,
create_obj_attrs_section() doesn't have this same issue as it checks
for zero size early on. The more abstract open-coding aspect remains,
though.)
Jan
More information about the Binutils
mailing list