Bug 28413 - string_view-selftests.c build error on macOS
Summary: string_view-selftests.c build error on macOS
Status: RESOLVED FIXED
Alias: None
Product: gdb
Classification: Unclassified
Component: build (show other bugs)
Version: HEAD
: P2 normal
Target Milestone: 13.1
Assignee: Not yet assigned to anyone
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2021-10-04 08:54 UTC by Enze Li
Modified: 2022-11-15 13:47 UTC (History)
5 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 Enze Li 2021-10-04 08:54:17 UTC
Recently, I noticed that when I use clang/clang++ to compile gdb (master) on macOS, the following error message appears.

  CXX    unittests/vec-utils-selftests.o
In file included from unittests/string_view-selftests.c:34:
/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/../include/c++/v1/fstream:580:17: error:
      The symbol ::fdopen refers to the system function. Use gnulib::fdopen instead.
      [-Werror,-Wuser-defined-warnings]
      __file_ = fdopen(__fd, __mdstr);
                ^
./../gnulib/import/stdio.h:801:1: note: from 'diagnose_if' attribute on 'fdopen':
_GL_CXXALIASWARN (fdopen);
^~~~~~~~~~~~~~~~~~~~~~~~~
./../gnulib/import/stdio.h:450:4: note: expanded from macro '_GL_CXXALIASWARN'
   _GL_CXXALIASWARN_1 (func, GNULIB_NAMESPACE)
   ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
./../gnulib/import/stdio.h:452:4: note: expanded from macro '_GL_CXXALIASWARN_1'
   _GL_CXXALIASWARN_2 (func, namespace)
   ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
./../gnulib/import/stdio.h:457:5: note: expanded from macro '_GL_CXXALIASWARN_2'
    _GL_WARN_ON_USE (func, \
    ^~~~~~~~~~~~~~~~~~~~~~~~
./../gnulib/import/stdio.h:621:19: note: expanded from macro '_GL_WARN_ON_USE'
  __attribute__ ((__diagnose_if__ (1, message, "warning")))
                  ^                ~
  CXX    unittests/xml-utils-selftests.o
1 error generated.
make[2]: *** [unittests/string_view-selftests.o] Error 1
make[2]: *** Waiting for unfinished jobs....
make[1]: *** [all-gdb] Error 2
make: *** [all] Error 2

Here is the command line I executed,
# cd /path/to/binutils-gdb
# ./configure --prefix=/path/to/binutils-gdb/build/
# make

I tested in the following system environment, and this issue exists on both.
macOS Mojave(version 10.14.6)
macOS Catalina(version 10.15.7)

By the way, if I use GCC to compile on macOS, the issue will not occur.
Comment 1 Simon Marchi 2021-10-04 12:18:11 UTC
This happens when building with Clang on Linux too.  Not sure what we can do here.  But as a workaround, you can build with CXXFLAGS=-std=gnu++17.  That will disable the string_view selftest, as GDB will use string_view from C++17.  Or, configure with --disable-unit-tests.
Comment 2 Tom de Vries 2021-10-04 14:33:51 UTC
FTR, patch posted here: https://sourceware.org/pipermail/gdb-patches/2021-October/182366.html
Comment 3 Tom de Vries 2021-10-04 14:46:19 UTC
(In reply to Simon Marchi from comment #1)
> This happens when building with Clang on Linux too.

FWIW, I've tried to reproduce this with Clang on Linux, but didn't manage.
Comment 4 Simon Marchi 2021-10-04 15:13:07 UTC
Well, now I get this, but I have definitely seen the fdopen one in the past:

  CXX    unittests/string_view-selftests.o
In file included from /home/simark/src/binutils-gdb/gdb/unittests/string_view-selftests.c:26:
In file included from /home/simark/src/binutils-gdb/gdb/defs.h:28:
In file included from /home/simark/src/binutils-gdb/gdb/../gdbsupport/common-defs.h:95:
../gnulib/import/string.h:693:1: error: reference to overloaded function could not be resolved; did you mean to call it?
_GL_CXXALIASWARN (memchr);
^~~~~~~~~~~~~~~~~~~~~~~~~
../gnulib/import/sys/select.h:430:4: note: expanded from macro '_GL_CXXALIASWARN'
   _GL_CXXALIASWARN_1 (func, GNULIB_NAMESPACE)
   ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
../gnulib/import/sys/select.h:432:4: note: expanded from macro '_GL_CXXALIASWARN_1'
   _GL_CXXALIASWARN_2 (func, namespace)
   ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
../gnulib/import/sys/select.h:437:5: note: expanded from macro '_GL_CXXALIASWARN_2'
    _GL_WARN_ON_USE (func, \
    ^~~~~~~~~~~~~~~~~~~~~~~~
../gnulib/import/sys/select.h:572:19: note: expanded from macro '_GL_WARN_ON_USE'
extern __typeof__ (function) function \
                  ^~~~~~~~~~
/usr/include/string.h:73:20: note: possible target for call
extern const void *memchr (const void *__s, int __c, size_t __n)
                   ^
/usr/include/string.h:71:14: note: possible target for call
extern void *memchr (void *__s, int __c, size_t __n)
             ^
Comment 5 Bruno Haible 2021-10-06 00:11:14 UTC
(In reply to Simon Marchi from comment #4)
> /home/simark/src/binutils-gdb/gdb/../gdbsupport/common-defs.h:95:
> ../gnulib/import/string.h:693:1: error: reference to overloaded function
> could not be resolved; did you mean to call it?
> _GL_CXXALIASWARN (memchr);
> ^~~~~~~~~~~~~~~~~~~~~~~~~

On which platform do you see this? Gnulib's string.in.h protects this line with

# elif __GLIBC__ >= 2
_GL_CXXALIASWARN (memchr);
# endif

So, on macOS systems, there should be no '_GL_CXXALIASWARN (memchr);' invocation.
Comment 6 Simon Marchi 2021-10-06 00:19:01 UTC
(In reply to Bruno Haible from comment #5)
> (In reply to Simon Marchi from comment #4)
> > /home/simark/src/binutils-gdb/gdb/../gdbsupport/common-defs.h:95:
> > ../gnulib/import/string.h:693:1: error: reference to overloaded function
> > could not be resolved; did you mean to call it?
> > _GL_CXXALIASWARN (memchr);
> > ^~~~~~~~~~~~~~~~~~~~~~~~~
> 
> On which platform do you see this? Gnulib's string.in.h protects this line
> with
> 
> # elif __GLIBC__ >= 2
> _GL_CXXALIASWARN (memchr);
> # endif
> 
> So, on macOS systems, there should be no '_GL_CXXALIASWARN (memchr);'
> invocation.

Sorry that wasn't clear.  This one is on an Arch Linux system, updated a few weeks ago.  It has:

 - gcc 11.1.0-1
 - glibc 2.33-5
Comment 7 Bruno Haible 2021-10-06 12:32:03 UTC
(In reply to Simon Marchi from comment #6)
> This one is on an Arch Linux system, updated a few
> weeks ago.  It has:
> 
>  - gcc 11.1.0-1
>  - glibc 2.33-5

Still more information needed:
  - Do you have Gnulib's c++defs.h, or the one by Enze Li?
  - Do the compiler options that are being passed for this compilation unit include optimization options (-O*)?
Comment 8 Simon Marchi 2021-10-06 13:03:54 UTC
(In reply to Bruno Haible from comment #7)
> (In reply to Simon Marchi from comment #6)
> > This one is on an Arch Linux system, updated a few
> > weeks ago.  It has:
> > 
> >  - gcc 11.1.0-1
> >  - glibc 2.33-5
> 
> Still more information needed:
>   - Do you have Gnulib's c++defs.h, or the one by Enze Li?
>   - Do the compiler options that are being passed for this compilation unit
> include optimization options (-O*)?

 - It's the c++defs.h in GDB's source tree, so the one from gnulib commit 776af40e09b476a41073131a90022572f448c189, unmodified.
 - No optimization.  The full compilation command line is:

   clang++ -x c++    -I. -I/home/simark/src/binutils-gdb/gdb -I/home/simark/src/binutils-gdb/gdb/config -DLOCALEDIR="\"/usr/local/share/locale\"" -DHAVE_CONFIG_H -I/home/simark/src/binutils-gdb/gdb/../include/opcode -I/home/simark/src/binutils-gdb/gdb/../readline/readline/.. -I/home/simark/src/binutils-gdb/gdb/../zlib -I../bfd -I/home/simark/src/binutils-gdb/gdb/../bfd -I/home/simark/src/binutils-gdb/gdb/../include -I../libdecnumber -I/home/simark/src/binutils-gdb/gdb/../libdecnumber  -I/home/simark/src/binutils-gdb/gdb/../gnulib/import -I../gnulib/import -I/home/simark/src/binutils-gdb/gdb/.. -I.. -I/home/simark/src/binutils-gdb/gdb/../libbacktrace/ -I../libbacktrace/  -DTUI=1    -I/usr/include/guile/2.0 -pthread  -I/usr/include/python3.9 -I/usr/include/python3.9   -I/home/simark/src/binutils-gdb/gdb/.. -pthread  -Wall -Wpointer-arith -Wno-unused -Wunused-value -Wunused-function -Wno-switch -Wno-char-subscripts -Wempty-body -Wno-sign-compare -Wno-mismatched-tags -Wno-error=deprecated-register -Wsuggest-override -Wdeprecated-copy -Wdeprecated-copy-dtor -Wredundant-move -Wmissing-declarations -Wmissing-prototypes -Wformat -Wformat-nonliteral -Werror -g3 -O0 -D_GLIBCXX_DEBUG=1 -ferror-limit=1   -c -o unittests/string_view-selftests.o -MT unittests/string_view-selftests.o -MMD -MP -MF unittests/.deps/string_view-selftests.Tpo /home/simark/src/binutils-gdb/gdb/unittests/string_view-selftests.c

I gave the gcc version, but the problem is actually when compiling with clang, so here's the clang version:

$ clang++ --version
clang version 12.0.1
Comment 9 Philippe Blain 2022-02-11 13:11:58 UTC
I can confirm the original build error reported by Enze Li (fdopen on macOS) still occurs for current master with both (macOS 10.11 + clang 13) and (macOS 10.15 + clang 12) [1].

The patch sent to gnulib (link in [2] above) was not well received, and Bruno indicated that gnulib does not support '-Werror' [3], which is automatically applied for GDB builds from Git if I'm not mistaken. 

I'm not sure of what could be done to fix the issue... 

It seems weird that gnulib issues a warning for a system include (here libc++), as this would be outside the control of projects using gnulib, so maybe it could be disabled somehow for system includes ?

[1] https://github.com/phil-blain/binutils-gdb/runs/5145831559?check_suite_focus=true#step:5:4227
[2] https://sourceware.org/bugzilla/show_bug.cgi?id=28413#c2
[3] https://lists.gnu.org/archive/html/bug-gnulib/2021-10/msg00005.html
Comment 10 Enze Li 2022-10-18 13:48:48 UTC
FTR, a proposed patch posted here: https://sourceware.org/pipermail/gdb-patches/2022-September/191861.html
Comment 11 Tsukasa OI 2022-11-15 04:00:38 UTC
A fix to this is upstreamed as commit a5b6e43669b7.
https://sourceware.org/git/?p=binutils-gdb.git;a=commit;h=a5b6e43669b78729d2ef78d668e19bac2b11197d

I hope someone who owns the modern Mac should test it whether this issue is really resolved by this commit.
Comment 12 Enze Li 2022-11-15 13:43:32 UTC
(In reply to Tsukasa OI from comment #11)
> A fix to this is upstreamed as commit a5b6e43669b7.
> https://sourceware.org/git/?p=binutils-gdb.git;a=commit;
> h=a5b6e43669b78729d2ef78d668e19bac2b11197d
> 
> I hope someone who owns the modern Mac should test it whether this issue is
> really resolved by this commit.

It works well!  Thanks for doing this.

I'll mark this bug as RESOLVED.
Comment 13 Enze Li 2022-11-15 13:44:25 UTC
Fixed.