[binutils-gdb] gas/COFF: extend use of SEC_ALLOC

Jan Beulich jbeulich@sourceware.org
Fri Oct 10 14:04:56 GMT 2025


https://sourceware.org/git/gitweb.cgi?p=binutils-gdb.git;h=6e870bea5f3d79a63604e1b5141385e011061df7

commit 6e870bea5f3d79a63604e1b5141385e011061df7
Author: Jan Beulich <jbeulich@suse.com>
Date:   Fri Oct 10 15:58:03 2025 +0200

    gas/COFF: extend use of SEC_ALLOC
    
    In line with bfd's styp_to_sec_flags(), set SEC_ALLOC for code/data
    sections. Tie the setting to SEC_LOAD, not avoid inadvertently producing
    a .bss-like section.

Diff:
---
 gas/config/obj-coff.c | 8 +++++---
 1 file changed, 5 insertions(+), 3 deletions(-)

diff --git a/gas/config/obj-coff.c b/gas/config/obj-coff.c
index f4fa9c52c55..590013cf659 100644
--- a/gas/config/obj-coff.c
+++ b/gas/config/obj-coff.c
@@ -43,7 +43,7 @@
    attributes when a directive has no valid flags or the "w" flag is
    used.  This default should be appropriate for most.  */
 #ifndef TC_COFF_SECTION_DEFAULT_ATTRIBUTES
-#define TC_COFF_SECTION_DEFAULT_ATTRIBUTES (SEC_LOAD | SEC_DATA)
+#define TC_COFF_SECTION_DEFAULT_ATTRIBUTES (SEC_ALLOC | SEC_LOAD | SEC_DATA)
 #endif
 
 /* This is used to hold the symbol built by a sequence of pseudo-ops
@@ -1603,6 +1603,8 @@ obj_coff_section (int ignore ATTRIBUTE_UNUSED)
 		case 'n':
 		  /* Section not loaded.  */
 		  flags &=~ SEC_LOAD;
+		  if (!is_bss)
+		    flags &= ~SEC_ALLOC;
 		  flags |= SEC_NEVER_LOAD;
 		  load_removed = 1;
 		  break;
@@ -1615,7 +1617,7 @@ obj_coff_section (int ignore ATTRIBUTE_UNUSED)
 		  /* Data section.  */
 		  flags |= SEC_DATA;
 		  if (! load_removed)
-		    flags |= SEC_LOAD;
+		    flags |= SEC_LOAD | SEC_ALLOC;
 		  flags &=~ SEC_READONLY;
 		  break;
 
@@ -1639,7 +1641,7 @@ obj_coff_section (int ignore ATTRIBUTE_UNUSED)
 		     otherwise set the SEC_DATA flag.  */
 		  flags |= (attr == 'x' || (flags & SEC_CODE) ? SEC_CODE : SEC_DATA);
 		  if (! load_removed)
-		    flags |= SEC_LOAD;
+		    flags |= SEC_LOAD | SEC_ALLOC;
 		  /* Note - the READONLY flag is set here, even for the 'x'
 		     attribute in order to be compatible with the MSVC
 		     linker.  */


More information about the Binutils-cvs mailing list