Bug 85663 - [9 Regression]: sanitizer fails to build on mips-unknown-linux-gnu
Summary: [9 Regression]: sanitizer fails to build on mips-unknown-linux-gnu
Status: RESOLVED INVALID
Alias: None
Product: gcc
Classification: Unclassified
Component: sanitizer (show other bugs)
Version: unknown
: P2 normal
Target Milestone: ---
Assignee: Not yet assigned to anyone
URL:
Keywords: build, patch
Depends on:
Blocks:
 
Reported: 2018-05-05 08:51 UTC by Sergei Trofimovich
Modified: 2019-02-03 23:12 UTC (History)
5 users (show)

See Also:
Host:
Target: mips
Build:
Known to work:
Known to fail:
Last reconfirmed: 2018-11-27 00:00:00


Attachments
gcc-8.1.0-mips-o32-asan.patch (555 bytes, patch)
2018-05-05 09:25 UTC, Sergei Trofimovich
Details | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Sergei Trofimovich 2018-05-05 08:51:33 UTC
In file included from /tmp/portage/cross-mips-unknown-linux-gnu/gcc-8.1.0-r1/work/gcc-8.1.0/libsanitizer/sanitizer_common/sanitizer_platform_limits_linux.cc:20:
/tmp/portage/cross-mips-unknown-linux-gnu/gcc-8.1.0-r1/work/gcc-8.1.0/libsanitizer/sanitizer_common/sanitizer_internal_defs.h:317:72: error: size of array ‘assertion_failed__71’ is negative
     typedef char IMPL_PASTE(assertion_failed_##_, line)[2*(int)(pred)-1]
                                                                        ^
/tmp/portage/cross-mips-unknown-linux-gnu/gcc-8.1.0-r1/work/gcc-8.1.0/libsanitizer/sanitizer_common/sanitizer_internal_defs.h:311:30: note: in expansion of macro ‘IMPL_COMPILER_ASSERT’
 #define COMPILER_CHECK(pred) IMPL_COMPILER_ASSERT(pred, __LINE__)
                              ^~~~~~~~~~~~~~~~~~~~
/tmp/portage/cross-mips-unknown-linux-gnu/gcc-8.1.0-r1/work/gcc-8.1.0/libsanitizer/sanitizer_common/sanitizer_platform_limits_linux.cc:71:1: note: in expansion of macro ‘COMPILER_CHECK’
 COMPILER_CHECK(struct_kernel_stat_sz == sizeof(struct stat));
 ^~~~~~~~~~~~~~

I think it is caused by this patch:

https://github.com/gcc-mirror/gcc/commit/36093749ff955d9e8cf208b04724c3a1a2ac9b04

libsanitizer/sanitizer_common/sanitizer_platform_limits_posix.h

 #elif defined(__mips__)
   const unsigned struct_kernel_stat_sz =
                  SANITIZER_ANDROID ? FIRST_32_SECOND_64(104, 128) :
-                                     FIRST_32_SECOND_64(144, 216);
+                                     FIRST_32_SECOND_64(160, 216);
Comment 1 Sergei Trofimovich 2018-05-05 08:54:06 UTC
GCC was configures as:

/tmp/portage/cross-mips-unknown-linux-gnu/gcc-8.1.0-r1/work/gcc-8.1.0/configure --host=x86_64-pc-linux-gnu --target=mips-unknown-linux-gnu --build=x86_64-pc-linux-gnu --prefix=/usr --bindir=/usr/x86_64-pc-linux-gnu/mips-unknown-linux-gnu/gcc-bin/8.1.0 --includedir=/usr/lib/gcc/mips-unknown-linux-gnu/8.1.0/include --datadir=/usr/share/gcc-data/mips-unknown-linux-gnu/8.1.0 --mandir=/usr/share/gcc-data/mips-unknown-linux-gnu/8.1.0/man --infodir=/usr/share/gcc-data/mips-unknown-linux-gnu/8.1.0/info --with-gxx-include-dir=/usr/lib/gcc/mips-unknown-linux-gnu/8.1.0/include/g++-v8 --with-python-dir=/share/gcc-data/mips-unknown-linux-gnu/8.1.0/python --enable-languages=c,c++,fortran --enable-obsolete --enable-secureplt --disable-werror --with-system-zlib --enable-nls --without-included-gettext --enable-checking=release --with-bugurl=https://bugs.gentoo.org/ --with-pkgversion=Gentoo 8.1.0-r1 p1.1 --disable-esp --enable-libstdcxx-time --enable-poison-system-directories --with-sysroot=/usr/mips-unknown-linux-gnu --disable-bootstrap --enable-__cxa_atexit --enable-clocale=gnu --disable-multilib --disable-altivec --disable-fixed-point --with-abi= --disable-libgcj --enable-libgomp --disable-libmudflap --disable-libssp --disable-libmpx --enable-vtable-verify --enable-libvtv --enable-lto --without-isl --enable-libsanitizer --enable-default-pie --enable-default-ssp
Comment 2 Sergei Trofimovich 2018-05-05 09:06:51 UTC
> -                                     FIRST_32_SECOND_64(144, 216);
> +                                     FIRST_32_SECOND_64(160, 216);

I think mips has really 3 stat values:
  32 ABI: 144
 n32 ABI: 160
  64 ABI: 216

  $ cat a.c
  #include <sys/types.h>
  #include <sys/stat.h>
  #include <unistd.h>

  int main() {
    return sizeof(struct stat);
  }

  $ mips-unknown-linux-gnu-gcc -E -dM - </dev/null | fgrep MIPS_SIM
  #define _MIPS_SIM _ABIO32
  $ mips-unknown-linux-gnu-gcc -S -O2 a.c && grep '[^a]li' a.s
          li      $2,144                  # 0x90

  $ mips64-unknown-linux-gnu-gcc -E -dM - </dev/null | fgrep MIPS_SIM
  #define _MIPS_SIM _ABIN32
  $ mips64-unknown-linux-gnu-gcc -S -O2 a.c && grep '[^a]li' a.s
          li      $2,160                  # 0xa0
Comment 3 Sergei Trofimovich 2018-05-05 09:25:37 UTC
Created attachment 44077 [details]
gcc-8.1.0-mips-o32-asan.patch

gcc-8.1.0-mips-o32-asan.patch is enough to get asan cross-compiled on o32 ABI.
Comment 4 Jakub Jelinek 2018-07-26 11:22:44 UTC
GCC 8.2 has been released.
Comment 5 Jakub Jelinek 2018-11-27 16:42:12 UTC
CCing Hans-Peter, who has enabled libsanitizer on mips*.  If this needs to be done, it should be ideally pushed upstream first and then cherry-picked.
Comment 6 Jakub Jelinek 2019-02-01 12:19:34 UTC
Hans-Peter, any comments on this?
Comment 7 Hans-Peter Nilsson 2019-02-03 20:51:51 UTC
(In reply to Jakub Jelinek from comment #6)
> Hans-Peter, any comments on this?

(In reply to Sergei Trofimovich from comment #2)
> > -                                     FIRST_32_SECOND_64(144, 216);
> > +                                     FIRST_32_SECOND_64(160, 216);
> 
> I think mips has really 3 stat values:
>   32 ABI: 144
>  n32 ABI: 160
>   64 ABI: 216
> 
>   $ cat a.c
>   #include <sys/types.h>
>   #include <sys/stat.h>
>   #include <unistd.h>
> 
>   int main() {
>     return sizeof(struct stat);
>   }

This is misleading.  What needs to be checked is the size of the *kernel* stat.
See https://gcc.gnu.org/ml/gcc-patches/2018-03/msg01263.html where I fixed it correctly and explained the issue.  I'm guessing a later import unfixed it, but I'll go check.

I'm changing the related version (8.0.1 -> 8.1.0), as from the comments it seems obvious that this is 8.1.0 (and later, presumably?), not 8.0.1.
Comment 8 Hans-Peter Nilsson 2019-02-03 21:46:13 UTC
The report is misleading regarding version, thus I'm resetting the versions.  For mips, sanitizer support was neither in gcc-8.0.1 nor gcc-8.1.0 nor gcc-8.2.0.  I suppose the reporter meant "trunk after gcc-8.0.1", but is confused by the change in versioning scheme.
(As was I, trying to correct the information in the report.  I'm not sure I have it correct even now...)

Reporter, please confirm or correct.
Comment 9 Sergei Trofimovich 2019-02-03 22:04:58 UTC
(In reply to Hans-Peter Nilsson from comment #8)
> The report is misleading regarding version, thus I'm resetting the versions.
> For mips, sanitizer support was neither in gcc-8.0.1 nor gcc-8.1.0 nor
> gcc-8.2.0.  I suppose the reporter meant "trunk after gcc-8.0.1", but is
> confused by the change in versioning scheme.
> (As was I, trying to correct the information in the report.  I'm not sure I
> have it correct even now...)
> 
> Reporter, please confirm or correct.

Original bug was reported against gcc-8.1.0. Apologies for the confusion.

gcc-8.2.0 has the same problem. With workaround it manages to build and install asan libraries:

  /usr/lib/gcc/mips-unknown-linux-gnu/8.2.0/include/sanitizer/asan_interface.h
  /usr/lib/gcc/mips-unknown-linux-gnu/8.2.0/plugin/include/asan.h
  /usr/lib/gcc/mips-unknown-linux-gnu/8.2.0/libasan.a
  /usr/lib/gcc/mips-unknown-linux-gnu/8.2.0/libasan.so
  /usr/lib/gcc/mips-unknown-linux-gnu/8.2.0/libasan.so.5
  /usr/lib/gcc/mips-unknown-linux-gnu/8.2.0/libasan.so.5.0.0
  /usr/lib/gcc/mips-unknown-linux-gnu/8.2.0/libasan_preinit.o

I'm a bit confused by lack of sanitizer support.

I guess you mean that  libsanitizer/configure.tgt has no mips entry and should fail ./configure or silently skip sanitizer build/install.
Comment 10 Jakub Jelinek 2019-02-03 22:19:06 UTC
That is not really possible, as libsanitizer/configure.tgt in 8.x doesn't support mips at all, only GCC 9 has added:
+  mips*64*-*-linux*)
+	# This clause is only here to not match the supported mips*-*-linux*.
+	UNSUPPORTED=1
+	;;
+  mips*-*-linux*)
+	;;
lines to libsanitizer/configure.tgt, before that it would fall through to:
  *)
        UNSUPPORTED=1
        ;;
which then means the toplevel configury doesn't build libsanitizer at all:
# Disable libsanitizer on unsupported systems.
if test -d ${srcdir}/libsanitizer; then
    if test x$enable_libsanitizer = x; then
        AC_MSG_CHECKING([for libsanitizer support])
        if (srcdir=${srcdir}/libsanitizer; \
                . ${srcdir}/configure.tgt; \
                test -n "$UNSUPPORTED")
        then
            AC_MSG_RESULT([no])
            noconfigdirs="$noconfigdirs target-libsanitizer"
        else
            AC_MSG_RESULT([yes])
        fi
    fi
fi

Of course, unless you are patching this in gcc 8.x somehow, but then you are on your own.
Comment 11 Jakub Jelinek 2019-02-03 22:21:10 UTC
Ah, no, you are forcing it to ignore that through --enable-libsanitizer.  Don't do that for unsupported targets.
Comment 12 Hans-Peter Nilsson 2019-02-03 22:31:25 UTC
(In reply to Sergei Trofimovich from comment #9)
> (In reply to Hans-Peter Nilsson from comment #8)
> > The report is misleading regarding version, thus I'm resetting the versions.
> > For mips, sanitizer support was neither in gcc-8.0.1 nor gcc-8.1.0 nor
> > gcc-8.2.0.  I suppose the reporter meant "trunk after gcc-8.0.1", but is
> > confused by the change in versioning scheme.
> > (As was I, trying to correct the information in the report.  I'm not sure I
> > have it correct even now...)
> > 
> > Reporter, please confirm or correct.
> 
> Original bug was reported against gcc-8.1.0. Apologies for the confusion.
> 
> gcc-8.2.0 has the same problem.

Oh, I missed the --enable-libsanitizer option.  You really have a *huge* list of configure options there.

> With workaround it manages to build and
> install asan libraries:
> 
>  
> /usr/lib/gcc/mips-unknown-linux-gnu/8.2.0/include/sanitizer/asan_interface.h
>   /usr/lib/gcc/mips-unknown-linux-gnu/8.2.0/plugin/include/asan.h
>   /usr/lib/gcc/mips-unknown-linux-gnu/8.2.0/libasan.a
>   /usr/lib/gcc/mips-unknown-linux-gnu/8.2.0/libasan.so
>   /usr/lib/gcc/mips-unknown-linux-gnu/8.2.0/libasan.so.5
>   /usr/lib/gcc/mips-unknown-linux-gnu/8.2.0/libasan.so.5.0.0
>   /usr/lib/gcc/mips-unknown-linux-gnu/8.2.0/libasan_preinit.o
> 
> I'm a bit confused by lack of sanitizer support.

I was too, but that's (supposedly) fixed on trunk, modulo effects from later sanitizer imports.  Care to try it out on a 9.0 snapshot?

We can keep this PR open if you notice issues, otherwise I think it's time to close it as invalid.

> I guess you mean that  libsanitizer/configure.tgt has no mips entry and
> should fail ./configure or silently skip sanitizer build/install.

As Jakub says; by default, yes.
Comment 13 Sergei Trofimovich 2019-02-03 23:12:04 UTC
I didn't realize --enable-sanitizer has such an overriding effect. Having looked at top-level configure.ac I now see that similar behaviour is applied to other libraries.

We'll change downstream and stop passing explicit --enable-sanitizer flag at least on mips.

I'll open a new bug if gcc-9's sanitizer fails on mips.

Thanks all!