From: Andrew Burgess Date: Tue, 11 Aug 2026 12:18:02 +0000 (+0100) Subject: gdb/configure: fix string quoting in AC_MSG_WARN and AC_MSG_ERROR X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=015bb5e104ec2bbd7ce7a3b7650431927be0cb38;p=thirdparty%2Fbinutils-gdb.git gdb/configure: fix string quoting in AC_MSG_WARN and AC_MSG_ERROR 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 --- diff --git a/gdb/configure b/gdb/configure index 303d6ea011c..633004d3f70 100755 --- a/gdb/configure +++ b/gdb/configure @@ -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 diff --git a/gdb/configure.ac b/gdb/configure.ac index e55a733fba7..943b2218a41 100644 --- a/gdb/configure.ac +++ b/gdb/configure.ac @@ -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