]> git.ipfire.org Git - thirdparty/binutils-gdb.git/commitdiff
ld: Make separate clauses where a label was before a declaration
authorHans-Peter Nilsson <hp@axis.com>
Sat, 24 Jan 2026 03:53:41 +0000 (04:53 +0100)
committerHans-Peter Nilsson <hp@bitrange.com>
Sat, 24 Jan 2026 05:12:56 +0000 (06:12 +0100)
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

index 3deceb76719240320c49c3cbd63bfa339d763e08..f39e0a3dbe7c3cbce08a8985b3724bd9b66b3b94 100644 (file)
@@ -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: