[gdb/build] Fix adding -DNDEBUG to python flags of release build

In gdb/configure the line:
...
    $development || tentative_python_cflags="$tentative_python_cflags -DNDEBUG"
...
intends to ensure that -DNDEBUG is added to the python flags of a release
build.

However, when building gdb-14-branch we have:
...
configure:22024: checking compiler flags for python code
  ...
configure:22047: result:  -fno-strict-aliasing -fwrapv
...

This is a regression since commit db6878ac55 ("Move sourcing of development.sh
to GDB_AC_COMMON"), which introduced a reference before assignment:
...
    $development || tentative_python_cflags="$tentative_python_cflags -DNDEBUG"
  ...
. $srcdir/../bfd/development.sh
...
and consequently -DNDEBUG is never added.

[ This was not obvious to me, but apparently evaluating an empty or undefined
variable in this context is similar to using ':' or 'true', so the line is
evaluated as:
...
    true || tentative_python_cflags="$tentative_python_cflags -DNDEBUG"
... ]

Fix this by moving GDB_AC_COMMON up in gdb/configure.ac, similar to how that
was done for gdbserver/configure.ac in commit db6878ac55.

[ Unfortunately, the move might introduce issues similar to the one we're
fixing, and I'm not sure how to check for this.  Shellcheck doesn't detect
this type of problem.  FWIW, I did run shellcheck (using arguments -xa, in the
src/gdb directory to make sure ../bfd/development.sh is taken into account)
before and after and observed that the number of lines/words/chars in the
shellcheck output is identical. ]

Build & tested on top of trunk.

Also build on top of gdb-14-branch, and observed this in gdb/config.log:
...
configure:25214: checking compiler flags for python code
  ...
configure:25237: result:  -fno-strict-aliasing -fwrapv -DNDEBUG
...

Approved-By: Tom Tromey <tom@tromey.com>

PR build/31099
Bug: https://sourceware.org/bugzilla/show_bug.cgi?id=31099
This commit is contained in:
Tom de Vries 2023-11-30 21:31:46 +01:00
parent 946df73fa0
commit d5835df2ee
2 changed files with 3565 additions and 3563 deletions

7125
gdb/configure vendored

File diff suppressed because it is too large Load diff

View file

@ -57,6 +57,8 @@ LT_OUTPUT
# necessary, set CXX_DIALECT to some -std=xxx switch.
AX_CXX_COMPILE_STDCXX(17, , mandatory)
GDB_AC_COMMON
# Dependency checking.
ZW_CREATE_DEPDIR
ZW_PROG_COMPILER_DEPENDENCIES([CC])
@ -1353,7 +1355,6 @@ AC_CHECK_FUNCS([getuid getgid \
setrlimit getrlimit posix_madvise waitpid \
use_default_colors])
AM_LANGINFO_CODESET
GDB_AC_COMMON
# Check the return and argument types of ptrace.
GDB_AC_PTRACE