Bug 17104 - CFLAGS="-Wall -Wextra" gdb/confgure --with-babeltrace fails
Summary: CFLAGS="-Wall -Wextra" gdb/confgure --with-babeltrace fails
Status: RESOLVED FIXED
Alias: None
Product: gdb
Classification: Unclassified
Component: build (show other bugs)
Version: 7.7
: P2 normal
Target Milestone: ---
Assignee: Not yet assigned to anyone
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2014-06-30 20:29 UTC by dilyan.palauzov@aegee.org
Modified: 2014-08-13 10:36 UTC (History)
2 users (show)

See Also:
Host:
Target:
Build:
Last reconfirmed:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description dilyan.palauzov@aegee.org 2014-06-30 20:29:03 UTC
My config.site contains

export CFLAGS='-pipe -O3 -flto -Wl,-S -Wl,--hash-style=gnu -Wl,-O1 -Wl,-z,relro -Wall -Wextra'

so when I run gdb-7.7.1/configure the CFLAGS are filled accordingly.  When I do gdb-7.7.1/gdb/configure --with-babeltrace, the effectively executed code from gdb/configure.ac is (as in gdb-7.7.1 and currently on master):

2401 if test "x$with_babeltrace" = "xno"; then
2402   AC_MSG_WARN([babletrace support disabled; GDB is unable to read CTF data.])
2403 else
2404   # Append -Werror to CFLAGS so that configure can catch the warning
2405   # "assignment from incompatible pointer type", which is related to
2406   # the babeltrace change from 1.0.3 to 1.1.0.  Babeltrace 1.1.0 works
2407   # in GDB, while babeltrace 1.0.3 is broken.
2408   # AC_LIB_HAVE_LINKFLAGS may modify CPPFLAGS in it, so it should be
2409   # safe to save and restore CFLAGS here.
2410   saved_CFLAGS=$CFLAGS
2411   CFLAGS="$CFLAGS -Werror"
2412   AC_LIB_HAVE_LINKFLAGS([babeltrace], [babeltrace-ctf],
2413                         [#include <babeltrace/babeltrace.h>
2414                          #include <babeltrace/ctf/events.h>
2415                          #include <babeltrace/ctf/iterator.h>],
2416                         [struct bt_iter_pos *pos = bt_iter_get_pos (bt_ctf_get_iter (NULL));
2417                         struct bt_ctf_event *event = NULL;
2418                         const struct bt_definition *scope;
2419
2420                         scope = bt_ctf_get_top_level_scope (event,
2421                                                            BT_STREAM_EVENT_HEADER);
2422                         bt_ctf_get_uint64 (bt_ctf_get_field (event, scope, "id"));
2423                         ])
2424   CFLAGS=$saved_CFLAGS

and config.log contains accordingly:

configure:14369: checking whether to use babeltrace
configure:14371: result: yes
configure:14796: checking for libbabeltrace
configure:14824: gcc -o conftest -pipe -O3 -flto -Wl,-S -Wl,--hash-style=gnu -Wl,-O1 -Wl,-z,relro -Wall -Wextra -Werror   -L/usr/lib64 -L/lib64 conftest.c -ldl -ldl -lncurses -lz -lm    /usr/lib64/libbabeltrace.so /usr/lib64/libbabeltrace-ctf.so /usr/lib64/libpopt.so /usr/lib64/libgmodule-2.0.so /lib64/libdl.so /usr/lib64/libglib-2.0.so /usr/lib64/libiconv.so /usr/lib64/libpcre.so /lib64/libpthread.so /usr/lib64/libuuid.so -Wl,-rpath -Wl,/usr/lib64 -Wl,-rpath -Wl,/lib64 >&5
conftest.c: In function 'main':
conftest.c:191:21: error: unused variable 'pos' [-Werror=unused-variable]
 struct bt_iter_pos *pos = bt_iter_get_pos (bt_ctf_get_iter (NULL));
                     ^
cc1: all warnings being treated as errors
configure:14824: $? = 1
configure: failed program was:


What I want to say is that CFLAGS at the end has -Wall -Wextra -Werror and check fails, because the pos variable is unused, which is normally a warning, but in this case also an error (-Werror).

Please ensure that running ./configure with CFLAGS='-Wall -Wextra' and gcc483 does not cause "error: unused variable 'pos' ", so that babeltrace is detected correctly.
Comment 1 Yao Qi 2014-07-01 03:46:00 UTC
I can reproduce it with gcc 4.8.2 (shipped on Fedora 20).

configure:15245: gcc -o conftest -Wall -Wextra -Werror   -I/home/yao/Source/lttng/babeltrace/1.1.0/install/include   conftest.c -ldl -lncurses -lz -lm    /home/yao/Source/lttng/babeltrace/1.1.0/install/lib/libbabeltrace.so /home/yao/Source/lttng/babeltrace/1.1.0/install/lib/libbabeltrace-ctf.so -lpopt -lgmodule-2.0 -lrt -lglib-2.0 -luuid -Wl,-rpath -Wl,/home/yao/Source/lttng/babeltrace/1.1.0/install/lib >&5
conftest.c: In function 'main':
conftest.c:192:21: error: unused variable 'pos' [-Werror=unused-variable]
 struct bt_iter_pos *pos = bt_iter_get_pos (bt_ctf_get_iter (NULL));
                     ^
cc1: all warnings being treated as errors

and this can be fixed by the following patch.  However, I suspect whether GDB can be built with '-Wall -Wextra -Werror', because even with the patch, I still get build failure in libiberty and gdb later.

2014-07-01  Yao Qi  <yao@codesourcery.com>

	build/17104
	* configure.ac: Use local variable 'pos'.
	* configure: Regenerated.
---
 gdb/configure    | 1 +
 gdb/configure.ac | 1 +
 2 files changed, 2 insertions(+)

diff --git a/gdb/configure b/gdb/configure
index a4c0a8c..7956aa7 100755
--- a/gdb/configure
+++ b/gdb/configure
@@ -15234,6 +15234,7 @@ struct bt_iter_pos *pos = bt_iter_get_pos (bt_ctf_get_iter (NULL));
 			struct bt_ctf_event *event = NULL;
 			const struct bt_definition *scope;
 
+			bt_iter_set_pos (bt_ctf_get_iter (NULL), pos);
 			scope = bt_ctf_get_top_level_scope (event,
 			      				   BT_STREAM_EVENT_HEADER);
 		        bt_ctf_get_uint64 (bt_ctf_get_field (event, scope, "id"));
diff --git a/gdb/configure.ac b/gdb/configure.ac
index a2ac15f..fc1d8bc 100644
--- a/gdb/configure.ac
+++ b/gdb/configure.ac
@@ -2417,6 +2417,7 @@ else
 			struct bt_ctf_event *event = NULL;
 			const struct bt_definition *scope;
 
+			bt_iter_set_pos (bt_ctf_get_iter (NULL), pos);
 			scope = bt_ctf_get_top_level_scope (event,
 			      				   BT_STREAM_EVENT_HEADER);
 		        bt_ctf_get_uint64 (bt_ctf_get_field (event, scope, "id"));
-- 
1.9.0
Comment 2 Jan Kratochvil 2014-08-12 19:23:04 UTC
[patch+7.8?] Fix --with-babeltrace with gcc-4.9.1
https://sourceware.org/ml/gdb-patches/2014-08/msg00198.html
Comment 3 cvs-commit@gcc.gnu.org 2014-08-13 09:48:15 UTC
This is an automated email from the git hooks/post-receive script. It was
generated because a ref change was pushed to the repository containing
the project "gdb and binutils".

The branch, master has been updated
       via  65c749e7c049f9bf944c5fbe9e727b7a8b4ccc7c (commit)
      from  e20e2464f8ae8803869d788b187cffc522c26155 (commit)

Those revisions listed above that are new to this repository have
not appeared on any other notification email; so we list those
revisions in full, below.

- Log -----------------------------------------------------------------
https://sourceware.org/git/gitweb.cgi?p=binutils-gdb.git;h=65c749e7c049f9bf944c5fbe9e727b7a8b4ccc7c

commit 65c749e7c049f9bf944c5fbe9e727b7a8b4ccc7c
Author: Yao Qi <yao@codesourcery.com>
Date:   Tue Jul 1 08:53:41 2014 +0800

    Fix build/17104
    
    This patch is to fix the build error when GDB is configured as:
    
      CFLAGS=-Wall ./configure --with-babeltrace; make
    
    This patch adds one line of code in configure test to use local
    variable 'pos'.
    
    Note that we append -Werror to CFLAGS to catch the warning related to
    assignment to scope.  See more in this thread
    https://sourceware.org/ml/gdb-patches/2014-08/msg00045.html
    
    2014-08-13  Yao Qi  <yao@codesourcery.com>
    
    	PR build/17104
    	* configure.ac: Use local variable 'pos'.
    	* configure: Regenerated.

-----------------------------------------------------------------------

Summary of changes:
 gdb/ChangeLog    |    6 ++++++
 gdb/configure    |    1 +
 gdb/configure.ac |    1 +
 3 files changed, 8 insertions(+), 0 deletions(-)
Comment 4 cvs-commit@gcc.gnu.org 2014-08-13 09:52:13 UTC
This is an automated email from the git hooks/post-receive script. It was
generated because a ref change was pushed to the repository containing
the project "gdb and binutils".

The branch, gdb-7.8-branch has been updated
       via  7dafc7fa56467d04d280156fa05cc95fad704e0c (commit)
      from  af7df923a190f4bcf65d09f2515e8aafee8403b5 (commit)

Those revisions listed above that are new to this repository have
not appeared on any other notification email; so we list those
revisions in full, below.

- Log -----------------------------------------------------------------
https://sourceware.org/git/gitweb.cgi?p=binutils-gdb.git;h=7dafc7fa56467d04d280156fa05cc95fad704e0c

commit 7dafc7fa56467d04d280156fa05cc95fad704e0c
Author: Yao Qi <yao@codesourcery.com>
Date:   Tue Jul 1 08:53:41 2014 +0800

    Fix build/17104
    
    This patch is to fix the build error when GDB is configured as:
    
      CFLAGS=-Wall ./configure --with-babeltrace; make
    
    This patch adds one line of code in configure test to use local
    variable 'pos'.
    
    Note that we append -Werror to CFLAGS to catch the warning related to
    assignment to scope.  See more in this thread
    https://sourceware.org/ml/gdb-patches/2014-08/msg00045.html
    
    2014-08-13  Yao Qi  <yao@codesourcery.com>
    
    	PR build/17104
    	* configure.ac: Use local variable 'pos'.
    	* configure: Regenerated.

-----------------------------------------------------------------------

Summary of changes:
 gdb/ChangeLog    |    6 ++++++
 gdb/configure    |    1 +
 gdb/configure.ac |    1 +
 3 files changed, 8 insertions(+), 0 deletions(-)
Comment 5 Yao Qi 2014-08-13 10:36:07 UTC
Patch is committed.