[committed] ld: Make separate clauses where a label was before a declaration

Hans-Peter Nilsson hp@axis.com
Sat Jan 24 05:15:21 GMT 2026


My binutils autotester (for cris-elf, cris-linux and mmix) noticed
that a binutils build broke with a recent patch, as indicated in a
previous email to the author, CC:ing the list.  Tested for cross to
cris-elf, committed as obvious.

-- >8 --
The default behavior of gcc changed from gcc-11.  With gcc-10 and
earlier versions, you got:

In file included from ../bfd/bfd.h:45,
                 from /src/ld/ldmisc.c:23:
/src/ld/ldmisc.c: In function 'vfinfo':
/src/ld/ldmisc.c:186:8: error: a label can only be part of a statement and a declaration is not a statement
  186 |        bool ll_type = false;
      |        ^~~~
/src/ld/ldmisc.c:581:8: error: a label can only be part of a statement and a declaration is not a statement
  581 |        bool ll_type = false;
      |        ^~~~
make[4]: *** [Makefile:1606: ldmisc.o] Error 1

Since gcc-10 matches the binutils/README requirement ("a C99 compliant
compiler and library") and as binutils policy is to adjust code to
handle earlier gcc versions, an obvious fix is to make a compound
statement for the code after the case-label.

ld:

	* ldmisc.c (vfinfo) <case 'l' - two cases>: Make separate
	compound statements where case-labels were part of a declaration.
---
 ld/ldmisc.c | 64 ++++++++++++++++++++++++++++-------------------------
 1 file changed, 34 insertions(+), 30 deletions(-)

diff --git a/ld/ldmisc.c b/ld/ldmisc.c
index 3deceb767192..f39e0a3dbe7c 100644
--- a/ld/ldmisc.c
+++ b/ld/ldmisc.c
@@ -183,17 +183,19 @@ vfinfo (FILE *fp, const char *fmt, va_list ap, bool is_warning)
 	      break;
 
 	    case 'l':
-	      bool ll_type = false;
-	      if (*scan == 'l')
-		{
-		  ll_type = true;
-		  ++scan;
-		}
-	      if (*scan == 'd' || *scan == 'u' || *scan == 'x')
-		{
-		  ++scan;
-		  arg_type = (ll_type ? LongLong : Long);
-		}
+	      {
+		bool ll_type = false;
+		if (*scan == 'l')
+		  {
+		    ll_type = true;
+		    ++scan;
+		  }
+		if (*scan == 'd' || *scan == 'u' || *scan == 'x')
+		  {
+		    ++scan;
+		    arg_type = (ll_type ? LongLong : Long);
+		  }
+	      }
 	      break;
 
 	    default:
@@ -578,25 +580,27 @@ vfinfo (FILE *fp, const char *fmt, va_list ap, bool is_warning)
 	      break;
 
 	    case 'l': /* (Unsigned) (long) long integer, like printf().  */
-	      bool ll_type = false;
-	      if (*fmt == 'l')
-		{
-		  fmt++;
-		  ll_type = true;
-		}
-	      if (*fmt == 'd' || *fmt == 'u' || *fmt == 'x')
-		{
-		  unsigned int mods_len = (ll_type ? 2 : 1);
-		  cfmt = make_cfmt (fmt - mods_len - mods, mods + mods_len + 1);
-		  if (ll_type)
-		    fprintf (fp, cfmt, args[arg_no].ll);
-		  else
-		    fprintf (fp, cfmt, args[arg_no].l);
-		  free (cfmt);
-		  ++arg_count;
-		  ++fmt;
-		  break;
-		}
+	      {
+		bool ll_type = false;
+		if (*fmt == 'l')
+		  {
+		    fmt++;
+		    ll_type = true;
+		  }
+		if (*fmt == 'd' || *fmt == 'u' || *fmt == 'x')
+		  {
+		    unsigned int mods_len = (ll_type ? 2 : 1);
+		    cfmt = make_cfmt (fmt - mods_len - mods, mods + mods_len + 1);
+		    if (ll_type)
+		      fprintf (fp, cfmt, args[arg_no].ll);
+		    else
+		      fprintf (fp, cfmt, args[arg_no].l);
+		    free (cfmt);
+		    ++arg_count;
+		    ++fmt;
+		    break;
+		  }
+	      }
 	      /* Fallthru */
 
 	    default:
-- 
2.30.2



More information about the Binutils mailing list