[PATCH] gdb: put user-supplied CFLAGS at the end

Pedro Alves pedro@palves.net
Wed Oct 7 12:10:52 GMT 2020


On 10/5/20 5:40 PM, Simon Marchi via Gdb-patches wrote:
> GDB currently doesn't build cleanly with clang (a -Wdeprecated-copy-dtor
> error).  I configured my clang-based GDB build with
> CXXFLAGS="-Wno-error=deprecated-copy-dtor", so I can use it despite that
> problem.  However, I found that it had no effect.  This is because my
> -Wno-error=Wdeprecated-copy-dtor switch is followed by -Werror in the
> command line, which switches back all warnings to be errors.
> 
> If we want the user-supplied C(XX)FLAGS to be able to override flags
> added by our configure script, the user-supplied C(XX)FLAGS should
> appear after the configure-supplied flags.
> 

Agreed.

> This patch moves the user-supplied flags at the very end of the command
> line, which fixes the problem described above.
> 

> gdb/ChangeLog:
> 
> 	* Makefile (INTERNAL_CFLAGS_BASE): Move CXXFLAGS at the end.

Typo: Makefile.in.

> 	(INTERNAL_WARN_CFLAGS): Move INTERNAL_CFLAGS_BASE at the end.
> 	(INTERNAL_CFLAGS): Move INTERNAL_WARN_CFLAGS at the end.
> 
> Change-Id: I00e054506695e0e9536095c6d14827e48abd8f69
> ---
>  gdb/Makefile.in | 8 ++++----
>  1 file changed, 4 insertions(+), 4 deletions(-)
> 
> diff --git a/gdb/Makefile.in b/gdb/Makefile.in
> index afce26276ecd..6f4b299452d5 100644
> --- a/gdb/Makefile.in
> +++ b/gdb/Makefile.in
> @@ -598,14 +598,14 @@ INTERNAL_CPPFLAGS = $(CPPFLAGS) @GUILE_CPPFLAGS@ @PYTHON_CPPFLAGS@ \
>  
>  # INTERNAL_CFLAGS is the aggregate of all other *CFLAGS macros.
>  INTERNAL_CFLAGS_BASE = \
> -	$(CXXFLAGS) $(GLOBAL_CFLAGS) $(PROFILE_CFLAGS) \
> +	$(GLOBAL_CFLAGS) $(PROFILE_CFLAGS) \
>  	$(GDB_CFLAGS) $(OPCODES_CFLAGS) $(READLINE_CFLAGS) $(ZLIBINC) \
>  	$(BFD_CFLAGS) $(INCLUDE_CFLAGS) $(LIBDECNUMBER_CFLAGS) \
>  	$(INTL_CFLAGS) $(INCGNU) $(INCSUPPORT) $(ENABLE_CFLAGS) \
>  	$(INTERNAL_CPPFLAGS) $(SRCHIGH_CFLAGS) $(TOP_CFLAGS) $(PTHREAD_CFLAGS) \
> -	$(DEBUGINFOD_CFLAGS)
> -INTERNAL_WARN_CFLAGS = $(INTERNAL_CFLAGS_BASE) $(GDB_WARN_CFLAGS)
> -INTERNAL_CFLAGS = $(INTERNAL_WARN_CFLAGS) $(GDB_WERROR_CFLAGS)
> +	$(DEBUGINFOD_CFLAGS) $(CXXFLAGS)
> +INTERNAL_WARN_CFLAGS = $(GDB_WARN_CFLAGS) $(INTERNAL_CFLAGS_BASE)
> +INTERNAL_CFLAGS = $(GDB_WERROR_CFLAGS) $(INTERNAL_WARN_CFLAGS)
>  

$(CXXFLAGS) in INTERNAL_CFLAGS_BASE looks a little bit buried, IMHO.
The intent that CXXFLAGS must be last isn't very explicit.

Also, while compiling python files, CXXFLAGS won't be at the end:

 # Python files need special flags.
 python/%.o: INTERNAL_CFLAGS += $(PYTHON_CFLAGS)


Maybe it would be better to tweak the two spots to use INTERNAL_CFLAGS
and add CXXFLAGS there explicitly:

 + # Add comment about wanting CXXFLAGS to remain last.
 -COMPILE = $(ECHO_CXX) $(COMPILE.pre) $(INTERNAL_CFLAGS) $(COMPILE.post)
 +COMPILE = $(ECHO_CXX) $(COMPILE.pre) $(INTERNAL_CFLAGS) $CXXFLAGS $(COMPILE.post)

Which would be kind of similar to what automake outputs in gdbsupport/Makefile.in :

  CXXCOMPILE = $(CXX) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) \
  	$(AM_CPPFLAGS) $(CPPFLAGS) $(AM_CXXFLAGS) $(CXXFLAGS)


Also, I think gdbserver/Makefile.in needs the same tweak?


More information about the Gdb-patches mailing list