[PATCH v1 1/1] gas/write.c: add explicitly flag SEC_HAS_CONTENT to object attributes section

Matthieu Longo matthieu.longo@arm.com
Wed Jun 25 14:57:41 GMT 2025


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.
---
 gas/write.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/gas/write.c b/gas/write.c
index 8ccd996089c..43237132a15 100644
--- a/gas/write.c
+++ b/gas/write.c
@@ -1916,7 +1916,7 @@ create_obj_attrs_section (void)
   segT s = subseg_new (name, 0);
   elf_section_type (s)
     = get_elf_backend_data (stdoutput)->obj_attrs_section_type;
-  bfd_set_section_flags (s, SEC_READONLY | SEC_DATA);
+  bfd_set_section_flags (s, SEC_READONLY | SEC_HAS_CONTENTS | SEC_DATA);
   frag_now_fix ();
   char *p = frag_more (size);
   bfd_elf_set_obj_attr_contents (stdoutput, (bfd_byte *)p, size);
-- 
2.50.0



More information about the Binutils mailing list