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 <tom@tromey.com>
2 files changed