Bug 21206 - gdb-7.12.1 for arm-rtems4.12 fails to build on FreeBSD 11.0
Summary: gdb-7.12.1 for arm-rtems4.12 fails to build on FreeBSD 11.0
Status: RESOLVED INVALID
Alias: None
Product: gdb
Classification: Unclassified
Component: corefiles (show other bugs)
Version: 7.12.1
: P2 critical
Target Milestone: ---
Assignee: Not yet assigned to anyone
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2017-02-28 21:15 UTC by Chris Johns
Modified: 2017-03-08 16:21 UTC (History)
3 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 Chris Johns 2017-02-28 21:15:22 UTC
Note, HEAD is also broken.

The arm-rtems4.12 target is broken in gdb-7.12.1 and binutils-gdb.git HEAD on FreeBSD 11.0.

Configure command is:

  $ ../binutils-gdb/configure --build=x86_64-freebsd11.0 --host=x86_64-freebsd11.0 --target=arm-rtems4.12 --verbose --disable-nls --without-included-gettext --disable-win32-registry --disable-werror --enable-sim --without-zlib --with-expat --with-python --prefix=/opt/work/rtems/4.12 --bindir=/opt/work/rtems/4.12/bin --exec-prefix=/opt/work/rtems/4.12 --includedir=/opt/work/rtems/4.12/include --libdir=/opt/work/rtems/4.12/lib --mandir=/opt/work/rtems/4.12/share/man --infodir=/opt/work/rtems/4.12/share/info

Host compiler is /usr/bin/c++. 

It looks like something in the recent gnulib updates breaks on FreeBSD 11.0.

The error from building on HEAD is:

/usr/bin/c++ -O2 -pipe -fbracket-depth=1024 -I/opt/work/chris/rtems/rsb/rtems-source-builder.git/rtems/build/tmp/sb-chris/4.12/rtems-arm/opt/work/rtems/4.12/include -std=gnu++11    -I. -I../../binutils-gdb/gdb -I../../binutils-gdb/gdb/common -I../../binutils-gdb/gdb/config -DLOCALEDIR="\"/opt/work/rtems/4.12/share/locale\"" -DHAVE_CONFIG_H -I../../binutils-gdb/gdb/../include/
opcode -I../../binutils-gdb/gdb/../opcodes/.. -I../../binutils-gdb/gdb/../readline/.. -I../../binutils-gdb/gdb/../zlib -I../bfd -I../../binutils-gdb/gdb/../bfd -I../../binutils-gdb/gdb/../include -I../libdecnumber -I../../binutils-gdb/gdb/../libdecnumber  -I../../binutils-gdb/gdb/gnulib/import -Ibuild-gnulib/import   -DTUI=1  -I/opt/work/rtems/4.12/include  -I/usr/local/inclu
de/python2.7 -I/usr/local/include/python2.7 -Wall -Wpointer-arith -Wno-unused -Wunused-value -Wunused-function -Wno-switch -Wno-char-subscripts -Wempty-body -Wunused-but-set-parameter -Wunused-but-set-variable -Wno-sign-compare -Wno-write-strings -Wno-narrowing -Wformat-nonliteral  -c -o gdb.o -MT gdb.o -MMD -MP -MF .deps/gdb.Tpo ../../binutils-gdb/gdb/gdb.c
c++: warning: treating 'c' input as 'c++' when in C++ mode, this behavior is deprecated
warning: unknown warning option '-Wunused-but-set-parameter'; did you mean '-Wunused-parameter'? [-Wunknown-warning-option]
warning: unknown warning option '-Wunused-but-set-variable'; did you mean '-Wunused-const-variable'? [-Wunknown-warning-option]
In file included from ../../binutils-gdb/gdb/gdb.c:19:
In file included from ../../binutils-gdb/gdb/defs.h:28:
In file included from ../../binutils-gdb/gdb/common/common-defs.h:52:
In file included from build-gnulib/import/stdio.h:53:
build-gnulib/import/stddef.h:106:3: error: typedef redefinition with different types ('union max_align_t' vs 'long double')
} max_align_t;
  ^
/usr/include/c++/v1/stddef.h:57:21: note: previous definition is here
typedef long double max_align_t;
                    ^
In file included from ../../binutils-gdb/gdb/gdb.c:19:
In file included from ../../binutils-gdb/gdb/defs.h:53:
../../binutils-gdb/gdb/ui-file.h:93:28: warning: struct 'ui_file' was previously declared as a class [-Wmismatched-tags]
extern int ui_file_isatty (struct ui_file *);
                           ^
../../binutils-gdb/gdb/ui-file.h:26:7: note: previous use is here
class ui_file
      ^
../../binutils-gdb/gdb/ui-file.h:93:28: note: did you mean class here?
extern int ui_file_isatty (struct ui_file *);
                           ^~~~~~
                           class
../../binutils-gdb/gdb/ui-file.h:95:28: warning: struct 'ui_file' was previously declared as a class [-Wmismatched-tags]
extern void ui_file_write (struct ui_file *file, const char *buf,
                           ^
../../binutils-gdb/gdb/ui-file.h:26:7: note: previous use is here
class ui_file
      ^
../../binutils-gdb/gdb/ui-file.h:95:28: note: did you mean class here?
extern void ui_file_write (struct ui_file *file, const char *buf,
                           ^~~~~~
                           class
../../binutils-gdb/gdb/ui-file.h:98:39: warning: struct 'ui_file' was previously declared as a class [-Wmismatched-tags]
extern void ui_file_write_async_safe (struct ui_file *file, const char *buf,
                                      ^
../../binutils-gdb/gdb/ui-file.h:26:7: note: previous use is here
class ui_file
      ^
../../binutils-gdb/gdb/ui-file.h:98:39: note: did you mean class here?
extern void ui_file_write_async_safe (struct ui_file *file, const char *buf,
                                      ^~~~~~
                                      class
../../binutils-gdb/gdb/ui-file.h:101:27: warning: struct 'ui_file' was previously declared as a class [-Wmismatched-tags]
extern long ui_file_read (struct ui_file *file, char *buf, long length_buf);
                          ^
../../binutils-gdb/gdb/ui-file.h:26:7: note: previous use is here
class ui_file
      ^
../../binutils-gdb/gdb/ui-file.h:101:27: note: did you mean class here?
extern long ui_file_read (struct ui_file *file, char *buf, long length_buf);
                          ^~~~~~
                          class
In file included from ../../binutils-gdb/gdb/gdb.c:19:
../../binutils-gdb/gdb/defs.h:327:8: warning: struct 'ui_file' was previously declared as a class [-Wmismatched-tags]
                                   struct ui_file *, int, char *);
                                   ^
../../binutils-gdb/gdb/ui-file.h:26:7: note: previous use is here
class ui_file
      ^
../../binutils-gdb/gdb/defs.h:327:8: note: did you mean class here?
                                   struct ui_file *, int, char *);
                                   ^~~~~~
                                   class
../../binutils-gdb/gdb/defs.h:338:57: warning: struct 'ui_file' was previously declared as a class [-Wmismatched-tags]
extern void print_address (struct gdbarch *, CORE_ADDR, struct ui_file *);
                                                        ^
../../binutils-gdb/gdb/ui-file.h:26:7: note: previous use is here
class ui_file
      ^
Comment 1 Yao Qi 2017-03-02 22:04:04 UTC
Is your compiler clang?  I have no problem building gdb with clang++-3.6 on Linux.
Comment 2 Chris Johns 2017-03-02 22:19:37 UTC
(In reply to Yao Qi from comment #1)
> Is your compiler clang?  I have no problem building gdb with clang++-3.6 on
> Linux.

Yes, this is the default compiler for FreeBSD 11.0:

$ /usr/bin/c++ --version
FreeBSD clang version 3.8.0 (tags/RELEASE_380/final 262564) (based on LLVM 3.8.0)
Target: x86_64-unknown-freebsd11.0
Thread model: posix
InstalledDir: /usr/bin

I was just looking into this on gdb's git HEAD branch and it seems gnulib's configure is using the default CPP which is a C compiler however GDB is not C++ and so the generated header file 'stddef.h' is not really suitable. The top of config.log for gnulib has 'CPP=' I suspect this needs to be the C++ compiler.

I hacked gnulib/configure adding to the top something like:

 CPP="/usr/bin/c++ -E"

and 'stddef.h' was correctly created. I could not figure out how to specify 'CPP=$CXX' to gnulib's configure. I did try setting CPP to CXX when calling the top level configure however building the binutils parts fails which is to be expected.

The build did fail on further on with:

In file included from ../../binutils-gdb/gdb/dwarf2read.c:72:
../../binutils-gdb/gdb/common/gdb_unlinker.h:35:35: error: '__nonnull__' attribute is invalid for the implicit this argument
  unlinker (const char *filename) ATTRIBUTE_NONNULL (1)
                                  ^                  ~
../../binutils-gdb/gdb/../include/ansidecl.h:169:48: note: expanded from macro 'ATTRIBUTE_NONNULL'
#  define ATTRIBUTE_NONNULL(m) __attribute__ ((__nonnull__ (m)))

So it looks like there are other issues.

FYI this issue is currently a blocker for RTEMS's 4.12 release.
Comment 3 Chris Johns 2017-03-02 22:21:40 UTC
(In reply to Chris Johns from comment #2)
> I was just looking into this on gdb's git HEAD branch and it seems gnulib's
> configure is using the default CPP which is a C compiler however GDB is not
> C++

Sorry I meant GDB *is* a C++ program.
Comment 4 jhb 2017-03-07 17:48:43 UTC
The issue is that the gnulib test checks for max_align_t using the C compiler but gdb is then compiled as C++.  On FreeBSD 11.0, max_align_t is not defined in C, but is defined by libc++ when using C++.  Thus, the configure tests gnulib runs don't find max_align_t, but when compiling with C++ the definition in libc++'s <stddef> triggers the error.

I've fixed this in FreeBSD upstream by defining a proper max_align_t (the one in libc++ doesn't match the ABI of the one GCC uses) in both C and C++ in the base OS <stddef.h>.  Additionally, in the port of gdb in the FreeBSD ports tree I use a local patch to disable the use of max_align_t from the gnulib header as a workaround for FreeBSD versions without max_align_t defined in C.

The relevant commits to FreeBSD are:

https://svnweb.freebsd.org/base?view=revision&revision=307756
https://svnweb.freebsd.org/base?view=revision&revision=309274

(both of which are merged to 11 and will be present in 11.1 when it is released).

The hacky patch I use in the gdb port on FreeBSD is:

https://svnweb.freebsd.org/ports/head/devel/gdb/files/patch-gdb-gnulib-import-stddef.in.h?view=co

(The irony is that neither GDB nor binutils even use max_align_t.)

I chose to fix the issue in this was as I considered the lack of max_align_t (which C11 requires) when compiling C in FreeBSD the bug.
Comment 5 Chris Johns 2017-03-07 21:44:45 UTC
Thanks John, the patches resolve the issue for me. I will close this bug as invalid as it does not effect GDB.
Comment 6 Yao Qi 2017-03-08 07:47:46 UTC
(In reply to Chris Johns from comment #2)
> 
> The build did fail on further on with:
> 
> In file included from ../../binutils-gdb/gdb/dwarf2read.c:72:
> ../../binutils-gdb/gdb/common/gdb_unlinker.h:35:35: error: '__nonnull__'
> attribute is invalid for the implicit this argument
>   unlinker (const char *filename) ATTRIBUTE_NONNULL (1)
>                                   ^                  ~
> ../../binutils-gdb/gdb/../include/ansidecl.h:169:48: note: expanded from
> macro 'ATTRIBUTE_NONNULL'
> #  define ATTRIBUTE_NONNULL(m) __attribute__ ((__nonnull__ (m)))
> 

Yes, I saw this fail in my Linux build too.
Comment 7 Pedro Alves 2017-03-08 15:48:55 UTC
I've reported a GCC bug for the missing diagnostic:
 https://gcc.gnu.org/bugzilla/show_bug.cgi?id=79961
Comment 8 Sourceware Commits 2017-03-08 16:21:41 UTC
The master branch has been updated by Pedro Alves <palves@sourceware.org>:

https://sourceware.org/git/gitweb.cgi?p=binutils-gdb.git;h=15c22686d0e33d87262bc9075296eeddd7d955f7

commit 15c22686d0e33d87262bc9075296eeddd7d955f7
Author: Pedro Alves <palves@redhat.com>
Date:   Wed Mar 8 15:52:16 2017 +0000

    gdb: Fix ATTRIBUTE_NONNULL usage
    
    Should fix the build failure with Clang mentioned at
    	<https://sourceware.org/bugzilla/show_bug.cgi?id=21206#c2>:
    
     In file included from ../../binutils-gdb/gdb/dwarf2read.c:72:
     ../../binutils-gdb/gdb/common/gdb_unlinker.h:35:35: error: '__nonnull__' attribute is invalid for the implicit this argument
       unlinker (const char *filename) ATTRIBUTE_NONNULL (1)
    				   ^                  ~
     ../../binutils-gdb/gdb/../include/ansidecl.h:169:48: note: expanded from macro 'ATTRIBUTE_NONNULL'
     #  define ATTRIBUTE_NONNULL(m) __attribute__ ((__nonnull__ (m)))
    
    gdb/ChangeLog:
    2017-03-08  Pedro Alves  <palves@redhat.com>
    
    	PR 21206
    	* common/gdb_unlinker.h (unlinker::unlinker): Attribute nonnull
    	goes to argument 2, not 1.