gdb: put user-supplied CFLAGS at the end
authorSimon Marchi <simon.marchi@efficios.com>
Wed, 7 Oct 2020 17:58:57 +0000 (13:58 -0400)
committerSimon Marchi <simon.marchi@efficios.com>
Wed, 7 Oct 2020 17:59:23 +0000 (13:59 -0400)
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.

This patch moves the user-supplied CXXFLAGS at the very end of the
compilation command line, which fixes the problem described above.  This
means moving it out of INTERNAL_CFLAGS and inlining it in the users of
INTERNAL_CFLAGS.

I observed the problem when building GDB, but the same problem could
happen with GDBserver, so the change is done there too.

In GDBserver, INTERNAL_CFLAGS is passed when linking

gdb/ChangeLog:

* Makefile.in (COMPILE): Add CXXFLAGS.
(INTERNAL_CFLAGS_BASE): Remove CXXFLAGS.
(check-headers): Add CXXFLAGS.

gdbserver/ChangeLog:

* Makefile.in (COMPILE): Add CXXFLAGS.
(INTERNAL_CFLAGS_BASE): Remove CXXFLAGS.
(gdbserver$(EXEEXT)): Add CXXFLAGS.
(gdbreplay$(EXEEXT)): Add CXXFLAGS.
($(IPA_LIB)): Add CXXFLAGS.
(IPAGENT_COMPILE): Add CXXFLAGS.

Change-Id: I00e054506695e0e9536095c6d14827e48abd8f69

gdb/ChangeLog
gdb/Makefile.in
gdbserver/ChangeLog
gdbserver/Makefile.in

index 3e72d920ae4ec1e30bf51f1350439d3879d43da7..48ab2e044e5a65d664279eb43260ec4661fc930d 100644 (file)
@@ -1,3 +1,9 @@
+2020-10-07  Simon Marchi  <simon.marchi@efficios.com>
+
+       * Makefile.in (COMPILE): Add CXXFLAGS.
+       (INTERNAL_CFLAGS_BASE): Remove CXXFLAGS.
+       (check-headers): Add CXXFLAGS.
+
 2020-10-07  Anton Kolesov  <anton.kolesov@synopsys.com>
 
        * arc-linux-tdep.h: New file.
index afce26276ecd6c7515600c0f3b0cae27c9e3f7a5..e14d41cef91520a3e4ef41e5e32296656f87ce2e 100644 (file)
@@ -118,9 +118,13 @@ include $(srcdir)/silent-rules.mk
 # GNU make is used.  The overrides implement dependency tracking.
 COMPILE.pre = $(CXX) -x c++ $(CXX_DIALECT)
 COMPILE.post = -c -o $@
-COMPILE = $(ECHO_CXX) $(COMPILE.pre) $(INTERNAL_CFLAGS) $(COMPILE.post)
 POSTCOMPILE = @true
 
+# CXXFLAGS is at the very end on purpose, so that user-supplied flags can
+# override internal flags.
+COMPILE = $(ECHO_CXX) $(COMPILE.pre) $(INTERNAL_CFLAGS) $(CXXFLAGS) \
+       $(COMPILE.post)
+
 YACC = @YACC@
 
 # This is used to rebuild ada-lex.c from ada-lex.l.  If the program is
@@ -598,7 +602,7 @@ 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) \
@@ -1712,7 +1716,7 @@ check-headers:
        @echo Checking headers.
        for i in $(CHECK_HEADERS) ; do \
                $(CXX) $(CXX_DIALECT) -x c++-header -c -fsyntax-only \
-               $(INTERNAL_CFLAGS) -include defs.h $(srcdir)/$$i ; \
+               $(INTERNAL_CFLAGS) $(CXXFLAGS) -include defs.h $(srcdir)/$$i ; \
        done
 .PHONY: check-headers
 
index 5ff195cccf4eaccbca5bc32fbb9cbc63c9681b3d..94f1a75b94da6985a7546f244b61bad1a28aeea2 100644 (file)
@@ -1,3 +1,12 @@
+2020-10-07  Simon Marchi  <simon.marchi@efficios.com>
+
+       * Makefile.in (COMPILE): Add CXXFLAGS.
+       (INTERNAL_CFLAGS_BASE): Remove CXXFLAGS.
+       (gdbserver$(EXEEXT)): Add CXXFLAGS.
+       (gdbreplay$(EXEEXT)): Add CXXFLAGS.
+       ($(IPA_LIB)): Add CXXFLAGS.
+       (IPAGENT_COMPILE): Add CXXFLAGS.
+
 2020-10-07  Anton Kolesov  <anton.kolesov@synopsys.com>
 
        * configure.srv: Support ARC architecture.
index fc68f0683248ca35755dd6dfd1a88bdac67ce278..c8cfed4819b7133a8c701a399490d40b15c83e64 100644 (file)
@@ -83,9 +83,12 @@ include $(srcdir)/../gdb/silent-rules.mk
 # GNU make is used.  The overrides implement dependency tracking.
 COMPILE.pre = $(CXX) $(CXX_DIALECT)
 COMPILE.post = -c -o $@
-COMPILE = $(ECHO_CXX) $(COMPILE.pre) $(INTERNAL_CFLAGS) $(COMPILE.post)
 POSTCOMPILE = @true
 
+# CXXFLAGS is at the very end on purpose, so that user-supplied flags can
+# override internal flags.
+COMPILE = $(ECHO_CXX) $(COMPILE.pre) $(INTERNAL_CFLAGS) $(CXXFLAGS) $(COMPILE.post)
+
 # It is also possible that you will need to add -I/usr/include/sys to the
 # CFLAGS section if your system doesn't have fcntl.h in /usr/include (which
 # is where it should be according to Posix).
@@ -158,7 +161,7 @@ PTHREAD_LIBS = @PTHREAD_LIBS@
 WIN32APILIBS = @WIN32APILIBS@
 
 # INTERNAL_CFLAGS is the aggregate of all other *CFLAGS macros.
-INTERNAL_CFLAGS_BASE = ${CXXFLAGS} ${GLOBAL_CFLAGS} \
+INTERNAL_CFLAGS_BASE = ${GLOBAL_CFLAGS} \
        ${PROFILE_CFLAGS} ${INCLUDE_CFLAGS} ${CPPFLAGS} $(PTHREAD_CFLAGS)
 INTERNAL_WARN_CFLAGS = ${INTERNAL_CFLAGS_BASE} $(WARN_CFLAGS)
 INTERNAL_CFLAGS = ${INTERNAL_WARN_CFLAGS} $(WERROR_CFLAGS) -DGDBSERVER
@@ -355,6 +358,7 @@ gdbserver$(EXEEXT): $(sort $(OBS)) ${CDEPS} $(LIBGNU) $(LIBIBERTY) \
                $(INTL_DEPS) $(GDBSUPPORT)
        $(SILENCE) rm -f gdbserver$(EXEEXT)
        $(ECHO_CXXLD) $(CC_LD) $(INTERNAL_CFLAGS) $(INTERNAL_LDFLAGS) \
+               $(CXXFLAGS) \
                -o gdbserver$(EXEEXT) $(OBS) $(GDBSUPPORT) $(LIBGNU) \
                $(LIBIBERTY) $(INTL) $(GDBSERVER_LIBS) $(XM_CLIBS) \
                $(WIN32APILIBS)
@@ -363,6 +367,7 @@ gdbreplay$(EXEEXT): $(sort $(GDBREPLAY_OBS)) $(LIBGNU) $(LIBIBERTY) \
                $(INTL_DEPS) $(GDBSUPPORT)
        $(SILENCE) rm -f gdbreplay$(EXEEXT)
        $(ECHO_CXXLD) $(CC_LD) $(INTERNAL_CFLAGS) $(INTERNAL_LDFLAGS) \
+               $(CXXFLAGS) \
                -o gdbreplay$(EXEEXT) $(GDBREPLAY_OBS) $(XM_CLIBS) \
                $(GDBSUPPORT) $(LIBGNU) $(LIBIBERTY) $(INTL) \
                $(WIN32APILIBS)
@@ -390,6 +395,7 @@ $(IPA_LIB): $(sort $(IPA_OBJS)) ${CDEPS}
        $(SILENCE) rm -f $(IPA_LIB)
        $(ECHO_CXXLD) $(CC_LD) -shared -fPIC -Wl,--soname=$(IPA_LIB) \
                -Wl,--no-undefined $(INTERNAL_CFLAGS) $(INTERNAL_LDFLAGS) \
+                $(CXXFLAGS) \
                -o $(IPA_LIB) ${IPA_OBJS} -ldl -pthread
 
 # Put the proper machine-specific files first, so M-. on a machine
@@ -485,7 +491,9 @@ IPAGENT_CFLAGS = $(INTERNAL_CFLAGS) $(UST_CFLAGS) \
        -fPIC -DIN_PROCESS_AGENT \
        -fvisibility=hidden
 
-IPAGENT_COMPILE = $(ECHO_CXX) $(COMPILE.pre) $(IPAGENT_CFLAGS) $(COMPILE.post)
+# CXXFLAGS is at the very end on purpose, so that user-supplied flags can
+# override internal flags.
+IPAGENT_COMPILE = $(ECHO_CXX) $(COMPILE.pre) $(IPAGENT_CFLAGS) $(CXXFLAGS) $(COMPILE.post)
 
 # Rules for special cases.
 
This page took 0.043904 seconds and 4 git commands to generate.