[binutils-gdb/binutils-2_44-branch] Support broken gcc test for gas string merge support

Alan Modra amodra@sourceware.org
Tue Jan 21 21:09:26 GMT 2025


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

commit 08ff112d536e49dfb89c636937cf5a4a725bedf2
Author: Alan Modra <amodra@gmail.com>
Date:   Sat Jan 18 22:39:05 2025 +1030

    Support broken gcc test for gas string merge support
    
    On casual reading of older gcc configure scripts it might be supposed
    that the test for gas string merge support tries with %progbits after
    a fail on ARM with @progbits.  It doesn't succeed due to a bug.  So to
    support building of older gcc's for ARM without users having to edit
    gcc sources, add a hack to gas.  The hack can disappear in a few years
    when building older gcc's likely requires other work too.
    
    I've changed the docs to reflect what we actually allow for .section
    syntax prior to this patch.  (No way should this hack be documented as
    allowed!)
    
            PR 32491
            * config/obj-elf.c (obj_elf_section): Allow missing entsize
            for ARM gcc configure bug.
            * doc/as.texi: Correct syntax of ELF .section directive.
            * testsuite/gas/elf/string.s,
            * testsuite/gas/elf/string.d: Test it.
    
    (cherry picked from commit 6427e777b99ec6505509a68de6d460ff772bee6a)

Diff:
---
 gas/config/obj-elf.c           | 26 ++++++++++++++++++++------
 gas/doc/as.texi                |  2 +-
 gas/testsuite/gas/elf/string.d |  2 ++
 gas/testsuite/gas/elf/string.s |  4 ++++
 4 files changed, 27 insertions(+), 7 deletions(-)

diff --git a/gas/config/obj-elf.c b/gas/config/obj-elf.c
index b5e1c1371b2..1aa4f404c87 100644
--- a/gas/config/obj-elf.c
+++ b/gas/config/obj-elf.c
@@ -1324,13 +1324,27 @@ obj_elf_section (int push)
 		  && (bfd_section_flags (now_seg)
 		      & (SEC_MERGE | SEC_STRINGS)) != 0)
 		goto fetch_entsize;
-	      entsize = get_absolute_expression ();
-	      SKIP_WHITESPACE ();
-	      if (entsize <= 0)
+	      if (is_end_of_line[(unsigned char) *input_line_pointer])
+		{
+		  /* ??? This is here for older versions of gcc that
+		     test for gas string merge support with
+		     '.section .rodata.str, "aMS", @progbits, 1'
+		     Unfortunately '@' begins a comment on arm.
+		     This isn't as_warn because gcc tests with
+		     --fatal-warnings. */
+		  as_tsktsk (_("missing merge / string entity size, 1 assumed"));
+		  entsize = 1;
+		}
+	      else
 		{
-		  as_warn (_("invalid merge / string entity size"));
-		  attr &= ~(SHF_MERGE | SHF_STRINGS);
-		  entsize = 0;
+		  entsize = get_absolute_expression ();
+		  SKIP_WHITESPACE ();
+		  if (entsize <= 0)
+		    {
+		      as_warn (_("invalid merge / string entity size"));
+		      attr &= ~(SHF_MERGE | SHF_STRINGS);
+		      entsize = 0;
+		    }
 		}
 	    }
 	  else if ((attr & (SHF_MERGE | SHF_STRINGS)) != 0 && inherit
diff --git a/gas/doc/as.texi b/gas/doc/as.texi
index d95ce9cf714..afe1737f4ce 100644
--- a/gas/doc/as.texi
+++ b/gas/doc/as.texi
@@ -6884,7 +6884,7 @@ This is one of the ELF section stack manipulation directives.  The others are
 For ELF targets, the @code{.section} directive is used like this:
 
 @smallexample
-.section @var{name} [, "@var{flags}"[, @@@var{type}[,@var{flag_specific_arguments}]]]
+.section @var{name} [, "@var{flags}"[, @@@var{type}][,@var{flag_specific_arguments}]]
 @end smallexample
 
 @anchor{Section Name Substitutions}
diff --git a/gas/testsuite/gas/elf/string.d b/gas/testsuite/gas/elf/string.d
index 6fcfe468af5..6dbd2d5dace 100644
--- a/gas/testsuite/gas/elf/string.d
+++ b/gas/testsuite/gas/elf/string.d
@@ -1,9 +1,11 @@
 #readelf: -SW
 #name: string sections
+#warning: (.*missing merge / string entity size, 1 assumed)?
 
 #...
 [ 	]*\[.*\][ 	]+\.str1[ 	]+PROGBITS[ 	]+0+[ 	]+[0-9a-f]+[ 	]+[0-9a-f]+[ 	]+01[ 	]+S[ 	]+.*
 [ 	]*\[.*\][ 	]+\.str2[ 	]+PROGBITS[ 	]+0+[ 	]+[0-9a-f]+[ 	]+[0-9a-f]+[ 	]+01[ 	]+S[ 	]+.*
 [ 	]*\[.*\][ 	]+\.str3[ 	]+PROGBITS[ 	]+0+[ 	]+[0-9a-f]+[ 	]+[0-9a-f]+[ 	]+01[ 	]+S[ 	]+.*
 [ 	]*\[.*\][ 	]+\.str4[ 	]+PROGBITS[ 	]+0+[ 	]+[0-9a-f]+[ 	]+[0-9a-f]+[ 	]+02[ 	]+S[ 	]+.*
+[ 	]*\[.*\][ 	]+\.rodata\.str[ 	]+PROGBITS[ 	]+0+[ 	]+[0-9a-f]+[ 	]+[0-9a-f]+[ 	]+01[ 	]+AMS[ 	]+.*
 #pass
diff --git a/gas/testsuite/gas/elf/string.s b/gas/testsuite/gas/elf/string.s
index 78c22f7496c..7733cfb31c2 100644
--- a/gas/testsuite/gas/elf/string.s
+++ b/gas/testsuite/gas/elf/string.s
@@ -8,3 +8,7 @@
 	.asciz "ghi"
 	.section .str4,"S",%progbits,2
 	.short 32, 0
+# The following is used in older versions of gcc to test for gas
+# string merge support.  On arm, @ begins a comment.
+	.section .rodata.str, "aMS", @progbits, 1
+	.asciz "jkl"


More information about the Binutils-cvs mailing list