Bug 72815 - libmpx on i386
Summary: libmpx on i386
Status: RESOLVED WONTFIX
Alias: None
Product: gcc
Classification: Unclassified
Component: other (show other bugs)
Version: 6.1.0
: P3 normal
Target Milestone: ---
Assignee: Not yet assigned to anyone
URL:
Keywords:
Depends on:
Blocks: CHKP
  Show dependency treegraph
 
Reported: 2016-08-05 12:24 UTC by vicencb
Modified: 2018-06-22 08:37 UTC (History)
1 user (show)

See Also:
Host:
Target: i?86-*-*
Build:
Known to work:
Known to fail:
Last reconfirmed: 2017-04-18 00:00:00


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description vicencb 2016-08-05 12:24:54 UTC
Hello,

'struct _libc_fpstate' is anonymous when getting its 'sizeof' in libmpx/mpxrt/mpxrt.h:52
#define XSAVE_OFFSET_IN_FPMEM    sizeof (struct _libc_fpstate)

Which results in a compilation error.

Thanks!
Comment 1 Martin Liška 2017-04-18 13:37:51 UTC
Hi. The file you are mentioning (libmpx/mpxrt/mpxrt.h) is not installed by GCC and for internal purpose only. Can you please specify how you use the header file?
Comment 2 vicencb 2017-04-18 22:21:51 UTC
I think the bug was triggered with buildroot version
eb1a30a3d92c8ddbcc295cb48226604d6d881e25
following these steps:
cat << EOF > .config
BR2_x86_i686=y
BR2_DL_DIR="/media/sources"
BR2_HOST_DIR="/opt/i686-buildroot-linux-musl/usr"
BR2_TOOLCHAIN_BUILDROOT_MUSL=y
BR2_BINUTILS_VERSION_2_26_X=y
BR2_GCC_VERSION_6_X=y
BR2_TOOLCHAIN_BUILDROOT_CXX=y
BR2_GCC_ENABLE_LTO=y
BR2_GCC_ENABLE_GRAPHITE=y
EOF
make olddefconfig
make toolchain

So, it was triggered while building gcc itself, not after installation.

Regards.
Comment 3 Martin Liška 2017-04-19 08:18:00 UTC
I see, can you please paste configure options for GCC, that would help me so that I can try to reproduce. Apart from that, the problematic GCC invocation command line would be also appreciated.
Comment 4 vicencb 2017-04-19 11:48:42 UTC
I can confirm that with the provided list of steps it is still reproducible.
To obtain the buildroot version use this:
####
cd /tmp
git clone git://git.buildroot.net/buildroot
cd buildroot
git checkout eb1a30a3d92c8ddbcc295cb48226604d6d881e25
####

And then following the steps, this is the error message reported (including the command line invocation):
####
Making all in mpxrt
/bin/sh ../libtool  --tag=CC   --mode=compile /tmp/buildroot/output/build/host-gcc-final-6.1.0/build/./gcc/xgcc -B/tmp/buildroot/output/build/host-gcc-final-6.1.0/build/./gcc/ -B/tmp/i686-buildroot-linux-musl/usr/usr/i686-buildroot-linux-musl/bin/ -B/tmp/i686-buildroot-linux-musl/usr/usr/i686-buildroot-linux-musl/lib/ -isystem /tmp/i686-buildroot-linux-musl/usr/usr/i686-buildroot-linux-musl/include -isystem /tmp/i686-buildroot-linux-musl/usr/usr/i686-buildroot-linux-musl/sys-include    -DHAVE_CONFIG_H -I. -I../../../../libmpx/mpxrt -I..  -I../../../../libmpx/..  -fPIC -D_LARGEFILE_SOURCE -D_LARGEFILE64_SOURCE -D_FILE_OFFSET_BITS=64  -Os  -c -o libmpx_la-mpxrt.lo `test -f 'mpxrt.c' || echo '../../../../libmpx/mpxrt/'`mpxrt.c
libtool: compile:  /tmp/buildroot/output/build/host-gcc-final-6.1.0/build/./gcc/xgcc -B/tmp/buildroot/output/build/host-gcc-final-6.1.0/build/./gcc/ -B/tmp/i686-buildroot-linux-musl/usr/usr/i686-buildroot-linux-musl/bin/ -B/tmp/i686-buildroot-linux-musl/usr/usr/i686-buildroot-linux-musl/lib/ -isystem /tmp/i686-buildroot-linux-musl/usr/usr/i686-buildroot-linux-musl/include -isystem /tmp/i686-buildroot-linux-musl/usr/usr/i686-buildroot-linux-musl/sys-include -DHAVE_CONFIG_H -I. -I../../../../libmpx/mpxrt -I.. -I../../../../libmpx/.. -fPIC -D_LARGEFILE_SOURCE -D_LARGEFILE64_SOURCE -D_FILE_OFFSET_BITS=64 -Os -c ../../../../libmpx/mpxrt/mpxrt.c  -fPIC -DPIC -o .libs/libmpx_la-mpxrt.o
In file included from ../../../../libmpx/mpxrt/mpxrt.c:54:0:
../../../../libmpx/mpxrt/mpxrt.c: In function 'read_mpx_status_sig':
../../../../libmpx/mpxrt/mpxrt.h:52:42: error: invalid application of 'sizeof' to incomplete type 'struct _libc_fpstate'
 #define XSAVE_OFFSET_IN_FPMEM    sizeof (struct _libc_fpstate)
                                          ^
../../../../libmpx/mpxrt/mpxrt.c:132:58: note: in expansion of macro 'XSAVE_OFFSET_IN_FPMEM'
   uint8_t *regs = (uint8_t *)uctxt->uc_mcontext.fpregs + XSAVE_OFFSET_IN_FPMEM;
                                                          ^~~~~~~~~~~~~~~~~~~~~
####

And the gcc configuration from /tmp/buildroot/output/build/host-gcc-final-6.1.0/build/gcc/config.log:
####
  $ /tmp/buildroot/output/build/host-gcc-final-6.1.0/gcc/configure --srcdir=../../gcc --cache-file=./config.cache --prefix=/tmp/i686-buildroot-linux-musl/usr/usr --sysconfdir=/tmp/i686-buildroot-linux-musl/usr/etc --enable-static --with-sysroot=/tmp/i686-buildroot-linux-musl/usr/usr/i686-buildroot-linux-musl/sysroot --disable-__cxa_atexit --with-gnu-ld --disable-libssp --disable-multilib --with-gmp=/tmp/i686-buildroot-linux-musl/usr/usr --with-mpfr=/tmp/i686-buildroot-linux-musl/usr/usr --with-pkgversion=Buildroot 2016.08-git-01592-geb1a30a3d --with-bugurl=http://bugs.buildroot.net/ --enable-libquadmath --disable-libsanitizer --disable-tls --enable-plugins --enable-lto --disable-libmudflap --enable-threads --with-mpc=/tmp/i686-buildroot-linux-musl/usr/usr --with-isl=/tmp/i686-buildroot-linux-musl/usr/usr --disable-decimal-float --with-arch=i686 --with-build-time-tools=/tmp/i686-buildroot-linux-musl/usr/usr/i686-buildroot-linux-musl/bin --enable-shared --disable-libgomp --enable-languages=c,c++,lto --program-transform-name=s&^&i686-buildroot-linux-musl-& --disable-option-checking --build=x86_64-pc-linux-gnu --host=x86_64-pc-linux-gnu --target=i686-buildroot-linux-musl
####

Please, note that this is a crosscompiler.
I hope this helps fixing the bug.
Regards.
Comment 5 Martin Liška 2017-04-19 13:23:20 UTC
Good, looks there's missing definition of the problematic struct.
I've got it defined in "/usr/include/sys/ucontext.h"

Maybe following patch can help you?

diff --git a/libmpx/mpxrt/mpxrt.c b/libmpx/mpxrt/mpxrt.c
index 76d11f71fd1..c9dad67f9df 100644
--- a/libmpx/mpxrt/mpxrt.c
+++ b/libmpx/mpxrt/mpxrt.c
@@ -49,6 +49,7 @@
 #include <stdlib.h>
 #include <sys/mman.h>
 #include <sys/prctl.h>
+#include <sys/ucontext.h>
 #include <cpuid.h>
 #include "mpxrt-utils.h"
 #include "mpxrt.h"

Do you use glibc in your environment?
Comment 6 vicencb 2017-04-19 13:56:33 UTC
Yes, the host (and build) system uses glibc, target system uses musl.
Thanks for the fix!
Should I test it or you already did?
Comment 7 Alexander Monakov 2017-04-19 14:15:23 UTC
Adding the include directive wouldn't help: musl defines the corresponding struct with a different tag, i.e. while glibc does

  typedef struct _libc_fpstate *fpregset_t;

musl does:

  typedef struct _fpstate {
     /* matching fields */
  } *fpregset_t;

On the one hand, it's possible to fix libmpx code to deduce the size of the struct from the public typedef, but on the other hand, it's possible that that is not the only platform-specific assumption in libmpx that will break on musl. I think it's advisable to simply configure gcc with --without-libmpx when targeting musl (unless you're specifically intending to test MPX on musl).
Comment 8 Alexander Monakov 2017-04-19 14:45:33 UTC
Perhaps it's a good idea to adjust libmpx/configure.tgt to build libmpx only for Glibc by default? I'm not sure if there's a particular reason that current code accepts any suffix in the triple.

diff --git a/libmpx/configure.tgt b/libmpx/configure.tgt
index 5060b7e..f24373f 100644
--- a/libmpx/configure.tgt
+++ b/libmpx/configure.tgt
@@ -21,7 +21,7 @@
 # Filter out unsupported systems.
 LIBMPX_SUPPORTED=no
 case "${target}" in
-  x86_64-*-linux* | i?86-*-linux*)
+  x86_64-*-linux-gnu | i?86-*-linux-gnu)
        LIBMPX_SUPPORTED=yes
        ;;
   *)
Comment 9 Martin Liška 2017-04-19 14:54:21 UTC
(In reply to Alexander Monakov from comment #8)
> Perhaps it's a good idea to adjust libmpx/configure.tgt to build libmpx only
> for Glibc by default? I'm not sure if there's a particular reason that
> current code accepts any suffix in the triple.
> 

Me neither, adding MPX people to the PR.
Comment 10 Martin Liška 2018-06-22 08:37:46 UTC
MPX is removed, won't fix then.