Bug 27535 - amd64-linux-siginfo.c fails to compile after updating to glibc-2.33 headers
Summary: amd64-linux-siginfo.c fails to compile after updating to glibc-2.33 headers
Status: RESOLVED FIXED
Alias: None
Product: gdb
Classification: Unclassified
Component: build (show other bugs)
Version: 10.1
: P2 critical
Target Milestone: 10.2
Assignee: Kevin Buettner
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2021-03-06 16:25 UTC by Kevin Buettner
Modified: 2021-03-07 06:23 UTC (History)
1 user (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 Kevin Buettner 2021-03-06 16:25:09 UTC
GDB no longer builds after updating to glibc-2.33:

g++  -D_GLIBCXX_DEBUG -g3 -O0    -I. -I../../gdbserver -I../../gdbserver/../gdb/regformats -I../../gdbserver/.. -I../../gdbserver/../include -I../../gdbserver/../gdb -I../../gdbserver/../gnulib/import -I../gnulib/import -I../../gdbserver/.. -I..   -pthread -Wall -Wpointer-arith -Wno-unused -Wunused-value -Wunused-variable -Wunused-function -Wno-switch -Wno-char-subscripts -Wempty-body -Wunused-but-set-parameter -Wunused-but-set-variable -Wno-sign-compare -Wno-error=maybe-uninitialized -Wno-mismatched-tags -Wsuggest-override -Wimplicit-fallthrough=3 -Wduplicated-cond -Wshadow=local -Wdeprecated-copy -Wdeprecated-copy-dtor -Wredundant-move -Wmissing-declarations -Wstrict-null-sentinel -Wformat -Wformat-nonliteral  -DGDBSERVER -E -o nat/amd64-linux-siginfo.i  ../../gdbserver/../gdb/nat/amd64-linux-siginfo.c
In file included from /usr/include/bits/sigstksz.h:24,
                 from /usr/include/signal.h:315,
                 from ../gnulib/import/signal.h:52,
                 from ../../gdbserver/../gdb/nat/amd64-linux-siginfo.c:20:
../gnulib/import/unistd.h:637:3: error: #error "Please include config.h first."
  637 |  #error "Please include config.h first."
      |   ^~~~~

The problem is actually gnulib related.  It turns out that the glibc headers now pull in <unistd.h> (from sigstksz.h, which is now included from signal.h). In the gdb build, this causes the gnulib version of unistd.h to be included, but gnulib's config.h had not been included first, which is the cause of the error.

A fix is already on the trunk:

https://sourceware.org/git/?p=binutils-gdb.git;a=commit;h=8488c357ce4fc309d49c7b0224cf9574b68e8116

I'm creating this PR so that it may be backported to gdb-10-branch.
Comment 1 cvs-commit@gcc.gnu.org 2021-03-06 17:58:33 UTC
The gdb-10-branch branch has been updated by Kevin Buettner <kevinb@sourceware.org>:

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

commit aebc4aa2ece0363c16cab5a546df05220227ec31
Author: Kevin Buettner <kevinb@redhat.com>
Date:   Thu Feb 18 22:46:58 2021 -0700

    amd64-linux-siginfo.c: Adjust include order to avoid gnulib error
    
    On Fedora rawhide, after updating to glibc-2.33, I'm seeing the
    following build failure:
    
      CXX    nat/amd64-linux-siginfo.o
    In file included from /usr/include/bits/sigstksz.h:24,
                     from /usr/include/signal.h:315,
                     from ../gnulib/import/signal.h:52,
                     from /ironwood1/sourceware-git/rawhide-gnulib/bld/../../worktree-gnulib/gdbserver/../gdb/nat/amd64-linux-siginfo.c:20:
    ../gnulib/import/unistd.h:663:3: error: #error "Please include config.h first."
      663 |  #error "Please include config.h first."
          |   ^~~~~
    
    glibc-2.33 has changed signal.h to now include <bits/sigstksz.h> which,
    in turn, includes <unistd.h>. For a gdb build, this causes the gnulib
    version of unistd.h to be pulled in first.  The build failure shown
    above happens because gnulib's config.h has not been included before
    the include of <signal.h>.
    
    The fix is simple - we just rearrange the order of the header file
    includes to make sure that gdbsupport/commondefs.h is included before
    attempting to include signal.h.  Note that gdbsupport/commondefs.h
    includes <gnulib/config.h>.
    
    Build and regression tested on Fedora 33.  On Fedora rawhide, GDB
    builds again.
    
    gdb/ChangeLog:
    
            PR build/27535
            * nat/amd64-linux-siginfo.c: Include "gdbsupport/common-defs.h"
            (which in turn includes <gnulib/config.h>) before include
            of <signal.h>.
Comment 2 Kevin Buettner 2021-03-07 06:23:55 UTC
Commit from trunk has been backported to gdb-10-branch.