Skip to content
  • Eldar Abusalimov's avatar
    configure: Fix test for fs_base/gs_base in <sys/user.h> · 6949085e
    Eldar Abusalimov authored
    Make <sys/types.h> be included prior to including <sys/user.h>.
    
    glibc versions older than 2.14 use __uintNN_t types within certain
    structures defined in <sys/user.h> probably assuming these types are
    defined prior to including the header. This results in the following
    `configure` feature test compilation error that makes it think that
    `struct user_regs_struct` doesn't have `fs_base`/`gs_base` fields,
    althouh it does.
    
        configure:13617: checking for struct user_regs_struct.fs_base
        configure:13617: gcc -c -g -O2 -I/linux/include conftest.c >&5
        In file included from conftest.c:158:0:
        /usr/include/sys/user.h:32:3: error: unknown type name '__uint16_t'
           __uint16_t  cwd;
           ^
        /usr/include/sys/user.h:33:3: error: unknown type name '__uint16_t'
           __uint16_t  swd;
           ^
        /usr/include/sys/user.h:34:3: error: unknown type name '__uint16_t'
           __uint16_t  ftw;
           ^
        /usr/include/sys/user.h:35:3: error: unknown type name '__uint16_t'
           __uint16_t  fop;
           ^
        /usr/include/sys/user.h:36:3: error: unknown type name '__uint64_t'
           __uint64_t  rip;
           ^
        /usr/include/sys/user.h:37:3: error: unknown type name '__uint64_t'
           __uint64_t  rdp;
           ^
        /usr/include/sys/user.h:38:3: error: unknown type name '__uint32_t'
           __uint32_t  mxcsr;
           ^
        /usr/include/sys/user.h:39:3: error: unknown type name '__uint32_t'
           __uint32_t  mxcr_mask;
           ^
        /usr/include/sys/user.h:40:3: error: unknown type name '__uint32_t'
           __uint32_t  st_space[32];   /* 8*16 bytes for each FP-reg = 128 bytes */
           ^
        /usr/include/sys/user.h:41:3: error: unknown type name '__uint32_t'
           __uint32_t  xmm_space[64];  /* 16*16 bytes for each XMM-reg = 256 bytes */
           ^
        /usr/include/sys/user.h:42:3: error: unknown type name '__uint32_t'
           __uint32_t  padding[24];
           ^
        configure:13617: $? = 1
        configure: failed program was:
        | /* confdefs.h */
        ...
        | /* end confdefs.h.  */
        | #include <sys/user.h>
        |
        | int
        | main ()
        | {
        | static struct user_regs_struct ac_aggr;
        | if (ac_aggr.fs_base)
        | return 0;
        |   ;
        |   return 0;
        | }
    
    Recent glibc versions don't use typedef'ed int types in <sys/user.h>,
    thus allowing it to be included as is
    (glibc commit d79a9c949c84e7f0ba33e87447c47af833e9f11a).
    However there're still some distros alive that use older glibc,
    for instance, RHEL/CentOS 6 package glibc 2.12.
    
    Also affects PR gdb/21559:
    
        ../../gdb/regcache.c:1087: internal-error: void regcache_raw_supply(regcache, int, const void): Assertion `regnum >= 0 && regnum < regcache->descr->nr_raw_registers' failed.
    
    As noted by Andrew Paprocki, who submitted the PR
    (https://sourceware.org/bugzilla/show_bug.cgi?id=21559#c3):
    
        > It should be noted that modifying `configure` to force on
        > `HAVE_STRUCT_USER_REGS_STRUCT_FS_BASE` and
        > `HAVE_STRUCT_USER_REGS_STRUCT_GS_BASE` fixes this issue. For some
        > reason the `configure` tests for `fs_base` and `gs_base` fail
        > even though `sys/user.h` on RHEL5 has the fields defined in
        > `user_regs_struct`.
    
    Note that this patch does NOT fix the root cause of PR gdb/21559,
    although now that `configure` properly detects the presence of the
    fields and sets HAVE_XXX accordingly, the execution takes another
    path, which doesn't lead to the assertion failure in question.
    
    gdb/ChangeLog:
    2018-01-17  Eldar Abusalimov  <eldar.abusalimov@jetbrains.com>
    
    	PR gdb/21559
    	* configure.ac: Include <sys/types.h> prior to <sys/user.h> when
    	checking for fs_base/gs_base fields in struct user_regs_struct.
    	* configure: Regenerate.
    
    gdb/gdbserver/ChangeLog:
    2018-01-17  Eldar Abusalimov  <eldar.abusalimov@jetbrains.com>
    
    	PR gdb/21559
    	* configure.ac: Include <sys/types.h> prior to <sys/user.h> when
    	checking for fs_base/gs_base fields in struct user_regs_struct.
    	* configure: Regenerate.
    6949085e
To find the state of this project's repository at the time of any of these versions, check out the tags.