]> git.ipfire.org Git - thirdparty/binutils-gdb.git/commitdiff
gdb/configure: fix string quoting in AC_MSG_WARN and AC_MSG_ERROR
authorAndrew Burgess <aburgess@redhat.com>
Tue, 11 Aug 2026 12:18:02 +0000 (13:18 +0100)
committerAndrew Burgess <aburgess@redhat.com>
Thu, 13 Aug 2026 09:03:41 +0000 (10:03 +0100)
Eli pointed out an issue with --enable-binary-file-formats, when GDB
is built with --enable-binary-file-formats='coff,xcoff,elf,macho' on a
target that doesn't support Mach-O, then GDB would configure
correctly, but then fail to build with an error like:

     CXXLD  gdb.exe
     d:/usr/bin/../lib/gcc/mingw32/9.2.0/../../../../mingw32/bin/ld.exe:
             machoread.o: in function `macho_check_dsym':
     d:\gnu\gdb-18.0.90\gdb/machoread.c:738:(.text+0xb16):
             undefined reference to `bfd_mach_o_lookup_command'
     d:/usr/bin/../lib/gcc/mingw32/9.2.0/../../../../mingw32/bin/ld.exe:
             d:\gnu\gdb-18.0.90\gdb/machoread.c:757:(.text+0xbe6):
                     undefined reference to `bfd_mach_o_lookup_command'
     collect2.exe: error: ld returned 1 exit status

See the original report here:

  https://inbox.sourceware.org/gdb-patches/865x1j1z61.fsf@gnu.org

It turns out the problem was incorrect quoting in an AC_MSG_ERROR call
within the configure script.  The current code is structured like
this:

  if CONDITION_1; then
    AC_MSG_ERROR("some message, some more message")
  elif CONDITION_2; then
    AC_MSG_ERROR("some message, some more message")
  fi

As "..." is not recognized as quoting by m4, the comma inside is
interpreted as an m4 argument separator, so 'some more message"'
including the trailing quote becomes the exit status and '"some
message' becomes the error message.

Configure understands to quote the '"' in the error message, but the
'"' in the exit status is not quoted, which leaves an unbalanced quote
in the configure script.

Luckily the second AC_MSG_ERROR line also has the same problem, which
adds a second unbalanced '"' into the configure script, which closes
the string started by the first unbalanced quote.

The string formed by these two unbalanced quotes just happens to
include the entire CONDITION_2 `if` check.

Fix this by replacing the use of '"..."' with '[...]' instead.

This issue was introduced in commit:

  commit 809c1abc19d487daeed75842da867ce633159210
  Date:   Wed Aug 21 11:10:50 2024 -0300

    gdb, configure: Add enable-binary-file-format option for configure

As well as the two AC_MSG_ERROR calls the above commit introduced an
incorrectly quoted AC_MSG_WARN call, I've fixed that too.

The above commit also added an unnecessary ';' at the end of the two
AC_MSG_ERROR lines, I've removed them in this commit.

While reviewing the above commit I spotted a couple of issues with the
error messages themselves.  First 'elf' should be 'ELF' when talking
about the file format, so I fixed that.  And second, AC_MSG_ERROR
calls normally don't have a trailing period, so I removed these from
the error messages added by 809c1abc19d487da.

Now when configuring with
--enable-binary-file-formats='coff,xcoff,elf,macho' on a target that
doesn't support Mach-O, e.g. GNU/Linux, the configure will stop like
this:

  checking for ELF support in BFD... yes
  checking for library containing dlopen... (cached) none required
  checking for Mach-O support in BFD... no
  configure: error: Mach-O support was requested, but BFD does not support it
  make: *** [Makefile:13461: configure-gdb] Error 1

Finally, during a final review of this patch I spotted another place
in our configure script where we were not quoting the argument to
AC_MSG_WARN correctly.  In this case the error was added in commit
e76c5d173bbf7137.  The problem line is:

  AC_MSG_WARN(disabling guile support, $GUILD fails compiling for $host)

As AC_MSG_WARN expects only a single argument, everything after the
comma will be discarded.  Quote the string with '[...]' to ensure the
full string is printed.

Approved-By: Tom Tromey <tom@tromey.com>
gdb/configure
gdb/configure.ac

index 303d6ea011c40242dae1f6612f5cd8d0fc04efcd..633004d3f70dc0d70aa337db814a4d3a55061c3c 100755 (executable)
@@ -29315,8 +29315,8 @@ $as_echo "$ac_cv_guild_ok" >&6; }
 
     if test "$ac_cv_guild_ok" = no; then
     have_libguile=no
-    { $as_echo "$as_me:${as_lineno-$LINENO}: WARNING: disabling guile support" >&5
-$as_echo "$as_me: WARNING: disabling guile support" >&2;}
+    { $as_echo "$as_me:${as_lineno-$LINENO}: WARNING: disabling guile support, $GUILD fails compiling for $host" >&5
+$as_echo "$as_me: WARNING: disabling guile support, $GUILD fails compiling for $host" >&2;}
   fi
 fi
 
@@ -32080,8 +32080,8 @@ if test "$enable_binary_file_formats" != "all"; then
            # Do nothing.
            ;;
        *)
-           { $as_echo "$as_me:${as_lineno-$LINENO}: WARNING: \"$req is required to support one or more requested targets.  Adding it\"" >&5
-$as_echo "$as_me: WARNING: \"$req is required to support one or more requested targets.  Adding it\"" >&2;}
+           { $as_echo "$as_me:${as_lineno-$LINENO}: WARNING: $req is required to support one or more requested targets.  Adding it" >&5
+$as_echo "$as_me: WARNING: $req is required to support one or more requested targets.  Adding it" >&2;}
            enable_binary_file_formats="${enable_binary_file_formats},$req"
            ;;
        esac
@@ -32101,9 +32101,9 @@ enable_binary_file_formats=$(echo $enable_binary_file_formats | sed 's/,/ /g')
 for format in $enable_binary_file_formats
 do
     if test "$format" = "elf" && test "$bfd_supports_elf" != "yes"; then
-           as_fn_error but BFD does not support it." "\"elf support was requested" "$LINENO" 5;
+           as_fn_error $? "ELF support was requested, but BFD does not support it" "$LINENO" 5
     elif test "$format" = "macho" && test "$bfd_supports_macho" != "yes"; then
-           as_fn_error but BFD does not support it." "\"Mach-O support was requested" "$LINENO" 5;
+           as_fn_error $? "Mach-O support was requested, but BFD does not support it" "$LINENO" 5
     fi
 
     if test "$format" = "all"; then
index e55a733fba7d3d4935c619ea1b72a348f1c1b37b..943b2218a4165ce57073537149248cf0123a746a 100644 (file)
@@ -1298,7 +1298,7 @@ if test "${have_libguile}" != no; then
   dnl If not, disable guile support.
   if test "$ac_cv_guild_ok" = no; then
     have_libguile=no
-    AC_MSG_WARN(disabling guile support, $GUILD fails compiling for $host)
+    AC_MSG_WARN([disabling guile support, $GUILD fails compiling for $host])
   fi
 fi
 
@@ -2080,7 +2080,7 @@ if test "$enable_binary_file_formats" != "all"; then
            # Do nothing.
            ;;
        *)
-           AC_MSG_WARN("$req is required to support one or more requested targets.  Adding it")
+           AC_MSG_WARN([$req is required to support one or more requested targets.  Adding it])
            enable_binary_file_formats="${enable_binary_file_formats},$req"
            ;;
        esac
@@ -2097,9 +2097,9 @@ enable_binary_file_formats=$(echo $enable_binary_file_formats | sed 's/,/ /g')
 for format in $enable_binary_file_formats
 do
     if test "$format" = "elf" && test "$bfd_supports_elf" != "yes"; then
-           AC_MSG_ERROR("elf support was requested, but BFD does not support it.");
+           AC_MSG_ERROR([ELF support was requested, but BFD does not support it])
     elif test "$format" = "macho" && test "$bfd_supports_macho" != "yes"; then
-           AC_MSG_ERROR("Mach-O support was requested, but BFD does not support it.");
+           AC_MSG_ERROR([Mach-O support was requested, but BFD does not support it])
     fi
 
     if test "$format" = "all"; then