[PATCH 13/17] bfd/PE: make local array in _bfd_XXi_swap_scnhdr_out() static

Jan Beulich jbeulich@suse.com
Mon Aug 4 09:24:00 GMT 2025


... and const. There's no reason to have the compiler copy an anonymous
.rodata object onto the stack. And there's also no reason to allow the
array to be modifiable.
---
Even better would of course be if we could avoid multiple instances of
that array, when multiple PE flavors are configured in.

--- a/bfd/peXXigen.c
+++ b/bfd/peXXigen.c
@@ -998,7 +998,7 @@ _bfd_XXi_swap_scnhdr_out (bfd * abfd, vo
     }
     pe_required_section_flags;
 
-    pe_required_section_flags known_sections [] =
+    static const pe_required_section_flags known_sections [] =
       {
 	{ ".CRT",   IMAGE_SCN_MEM_READ | IMAGE_SCN_CNT_INITIALIZED_DATA },
 	{ ".arch",  IMAGE_SCN_MEM_READ | IMAGE_SCN_CNT_INITIALIZED_DATA | IMAGE_SCN_MEM_DISCARDABLE | IMAGE_SCN_ALIGN_8BYTES },
@@ -1016,7 +1016,7 @@ _bfd_XXi_swap_scnhdr_out (bfd * abfd, vo
 	{ ".xdata", IMAGE_SCN_MEM_READ | IMAGE_SCN_CNT_INITIALIZED_DATA },
       };
 
-    pe_required_section_flags * p;
+    const pe_required_section_flags * p;
 
     /* We have defaulted to adding the IMAGE_SCN_MEM_WRITE flag, but now
        we know exactly what this specific section wants so we remove it



More information about the Binutils mailing list