Bug 95712 - configure-target-libgcc fails on s390x target because xgcc is not being built
Summary: configure-target-libgcc fails on s390x target because xgcc is not being built
Status: RESOLVED MOVED
Alias: None
Product: gcc
Classification: Unclassified
Component: bootstrap (show other bugs)
Version: 9.3.0
: P3 normal
Target Milestone: ---
Assignee: Not yet assigned to anyone
URL:
Keywords: build
Depends on:
Blocks:
 
Reported: 2020-06-16 19:01 UTC by Alexander Egorenkov
Modified: 2020-06-20 10:52 UTC (History)
0 users

See Also:
Host:
Target:
Build:
Known to work:
Known to fail:
Last reconfirmed:


Attachments
Console output (10.42 KB, text/plain)
2020-06-16 19:01 UTC, Alexander Egorenkov
Details
config.log for configure-target-libgcc (2.86 KB, text/plain)
2020-06-16 19:02 UTC, Alexander Egorenkov
Details
config.log for configure-target-libgcc gcc 9.3.0 (2.88 KB, text/plain)
2020-06-16 19:05 UTC, Alexander Egorenkov
Details
top gcc Makefile (75.68 KB, text/plain)
2020-06-18 06:56 UTC, Alexander Egorenkov
Details

Note You need to log in before you can comment on or make changes to this bug.
Description Alexander Egorenkov 2020-06-16 19:01:46 UTC
Created attachment 48744 [details]
Console output

Hi all,

i'm trying to build buildroot on s390x machine for s390x machine and
the toolchain build step fails. I attached the build.log and the config.log
of the failing target configure-target-libgcc. It seems that xgcc
is not being built prior to configuring the target configure-target-libgcc.
When i build on host x86_64 for s390x target then everything works with the
same configuration.

Regards
Comment 1 Alexander Egorenkov 2020-06-16 19:02:33 UTC
Created attachment 48745 [details]
config.log for configure-target-libgcc
Comment 2 Alexander Egorenkov 2020-06-16 19:05:21 UTC
Created attachment 48746 [details]
config.log for configure-target-libgcc gcc 9.3.0

Sorry attached gcc 8.4.0 log previosuly, but the same issue for gcc 9.3.0
Comment 3 Alexander Egorenkov 2020-06-16 19:08:21 UTC
The config.log of configure-target-libgcc says:

... build/host-gcc-initial-9.3.0/build/./gcc/xgcc: No such file or directory
Comment 4 Alexander Egorenkov 2020-06-16 19:09:35 UTC
I also have the same issue with gcc 8.4.0
Comment 5 Andrew Pinski 2020-06-16 19:16:08 UTC
This is what I do:
${PMAKE} all-gas all-binutils all-ld || return 1
make install-gas install-ld install-binutils || return 1
# glibc will provide ssp as it is new enough
gcc_cv_libc_provides_ssp=yes  ${PMAKE} configure-gcc || return 1
${PMAKE} all-gcc all-target-libgcc || return 1
make install-gcc install-target-libgcc || return 1

I don't trust buildroot to do the right thing.
Comment 6 Alexander Egorenkov 2020-06-17 19:59:54 UTC
Ok, i understand, therefore, i reproduced the problem without buildroot.

My steps:

$ mkdir compiler
$ cd compiler

$ tar xvjf gmp-6.1.0.tar.bz2
$ cd gmp-6.1.0
$ ./configure --prefix=$HOME/compiler/install --disable-shared
$ make -j81
$ make install
$ cd ..

$ tar xvjf mpfr-3.1.4.tar.bz2
$ cd mpfr-3.1.4
$ ./configure --prefix=$HOME/compiler/install --disable-shared --with-gmp=$HOME/compiler/install
$ make -j81
$ make install
$ cd ..

$ tar xvzf mpc-1.0.3.tar.gz
$ cd mpc-1.0.3
$ ./configure --prefix=$HOME/compiler/install --disable-shared --with-gmp=$HOME/compiler/install --with-mpfr=$HOME/compiler/install
$ make -j81
$ make install
$ cd ..


$ tar xvzf gcc-9.3.0.tar.xz
$ mkdir build-gcc
$ cd build-gcc
$ ../gcc-9.3.0/configure --prefix=$HOME/compiler/install --enable-shared --disable-static \
                         --disable-gtk-doc --disable-gtk-doc-html --disable-doc --disable-docs \
                         --disable-documentation --disable-debug --with-xmlto=no --with-fop=no \
                         --disable-nls --disable-dependency-tracking  --target=s390x-buildroot-linux-gnu  \
                         --enable-__cxa_atexit --with-gnu-ld --disable-libssp --disable-multilib \
                         --disable-decimal-float --with-gmp=$HOME/compiler/install \
                         --with-mpc=$HOME/compiler/install --with-mpfr=$HOME/compiler/install \
                         --with-pkgversion="Buildroot 2020.08-git-g2d8407f8ab" \
                         --with-bugurl="http://bugs.buildroot.net/" --disable-libquadmath --enable-tls \
                         --enable-threads --without-isl --without-cloog --with-arch="z196" \
                         --with-long-double-128 --enable-languages=c --disable-shared --without-headers \
                         --disable-threads --with-newlib --disable-largefile

$ make -j81 gcc_cv_libc_provides_ssp=yes all-gcc all-target-libgcc


The above steps were executed manually w/o any buildroot infrastructure. 
And i get the same problem, almost the same commands are executed by buildroot.

Again, xgcc is not being built and libgcc fails. I patched nothing, everything was vanilla.

What i did notice, is that everything seems to work fine and the make commands succeeds, if i drop "-j81" in the last step.
I did all these steps on a s390x machine with 80 cores, it is a highly parallel machine.
So the issue seems to depend on it somehow, my guess is that maybe some dependencies are not correctly
done in libgcc Makefile ? Another workaround i found is to split the last maske command into 2 like this:
$ make -j81 all-gcc
$ make -j81 all-target-libgcc
This seems to fix it also.

I'm ready to do more test if required. I really want to fix it, it is very annoying and blocking me.

Regards
Comment 7 Andrew Pinski 2020-06-18 04:05:50 UTC
@if gcc-no-bootstrap
....
configure-target-libgcc: maybe-all-gcc
...
@endif gcc-no-bootstrap

What version of GNU make are you using?
Can you attach the toplevel Makefile?  I checked the version that is generated for aarch64-linux-gnu that I configured for and it has:

# Generic dependencies for target modules on host stuff, especially gcc
....
configure-target-libgcc: maybe-all-gcc
...
Comment 8 Alexander Egorenkov 2020-06-18 06:55:31 UTC
$ make --version
GNU Make 4.1
Built for s390x-ibm-linux-gnu

In my top Makefile the dependecny on maybe-all-gcc is missing:
....
configure-target-libgcc:
...

I attached the top Makefile.
Comment 9 Alexander Egorenkov 2020-06-18 06:56:07 UTC
Created attachment 48751 [details]
top gcc Makefile
Comment 10 Alexander Egorenkov 2020-06-18 06:57:29 UTC
When i add the dependency in Makefile manually, then the parallel build works.

Regards
Comment 11 Andreas Schwab 2020-06-18 07:19:47 UTC
> generated for aarch64-linux-gnu that I configured for and it has:

You have used --disable-bootstrap.
Comment 12 Alexander Egorenkov 2020-06-18 08:07:05 UTC
Indeed, adding --disable-bootstrap helps also.
Comment 13 Andrew Pinski 2020-06-18 09:08:05 UTC
(In reply to Andreas Schwab from comment #11)
> > generated for aarch64-linux-gnu that I configured for and it has:
> 
> You have used --disable-bootstrap.

No I did not, --disable-bootstrap is the default for the case where we are doing cross.

OH I did not notice it was s390 to s390 cross building but buildroot is not handling that case correctly.  Rather it is thinking it is always building a cross even when build==host==target .

> --build=s390x-ibm-linux-gnu --host=s390x-buildroot-linux-gnu --target=s390x-buildroot-linux-gnu

That is broken.  This is not a cross compiler but rather a build of the native gcc and therefor is not the correct options.

So the problem is rather how buildroot is not doing the right configure options to gcc for building a cross build.  NOT A BUG.
Comment 14 Andrew Pinski 2020-06-18 09:08:11 UTC
.
Comment 15 Andrew Pinski 2020-06-18 09:12:07 UTC
This should have caught it:
case "$have_compiler:$host:$target:$enable_bootstrap" in
  *:*:*:no) ;;

  # Default behavior.  Enable bootstrap if we have a compiler
  # and we are in a native configuration.
  yes:$build:$build:default)
    enable_bootstrap=yes ;;

  *:*:*:default)
    enable_bootstrap=no ;;

  # We have a compiler and we are in a native configuration, bootstrap is ok
  yes:$build:$build:yes)
    ;;

  # Other configurations, but we have a compiler.  Assume the user knows
  # what he's doing.
  yes:*:*:yes)
    AC_MSG_WARN([trying to bootstrap a cross compiler])
    ;;

  # No compiler: if they passed --enable-bootstrap explicitly, fail
  no:*:*:yes)
    AC_MSG_ERROR([cannot bootstrap without a compiler]) ;;

  # Fail if wrong command line
  *)
    AC_MSG_ERROR([invalid option for --enable-bootstrap])
    ;;
esac

It does seem like buildroot does the incorrect thing if the target and the build/host are the same arch.  THIS IS a buildroot issue and not a GCC issue.
Comment 16 Andrew Pinski 2020-06-18 09:17:17 UTC
build_alias=s390x-ibm-linux-gnu
build_vendor=ibm
build_os=linux-gnu
build=s390x-ibm-linux-gnu
host_alias=s390x-ibm-linux-gnu
host_vendor=ibm
host_os=linux-gnu
host=s390x-ibm-linux-gnu
target_alias=s390x-buildroot-linux-gnu
target_vendor=ibm
target_os=linux-gnu
target=s390x-ibm-linux-gnu

If anything this is a config.guess bug and not directly a GCC bug :).
config.guess sets the target_vendor to being ibm for always.
Comment 17 Alexander Egorenkov 2020-06-18 09:23:54 UTC
(In reply to Andrew Pinski from comment #13)
> (In reply to Andreas Schwab from comment #11)
> > > generated for aarch64-linux-gnu that I configured for and it has:
> > 
> > You have used --disable-bootstrap.
> 
> No I did not, --disable-bootstrap is the default for the case where we are
> doing cross.
> 
> OH I did not notice it was s390 to s390 cross building but buildroot is not
> handling that case correctly.  Rather it is thinking it is always building a
> cross even when build==host==target .
> 
> > --build=s390x-ibm-linux-gnu --host=s390x-buildroot-linux-gnu --target=s390x-buildroot-linux-gnu
> 
> That is broken.  This is not a cross compiler but rather a build of the
> native gcc and therefor is not the correct options.
> 
> So the problem is rather how buildroot is not doing the right configure
> options to gcc for building a cross build.  NOT A BUG.

But i did not use those configure options in my test.
And now i also removed option "--target=" in my test and it is still failing with the same problem. I'm not talking about buildroot, i got rid of it. Please see my test.

Thanks
Comment 18 Alexander Egorenkov 2020-06-18 12:35:16 UTC
I reopened the problem because i reproduced this w/o buildroot and --host,--target and --build configure options.
Comment 19 Andrew Pinski 2020-06-18 16:48:59 UTC
This is a config.sub issue where the vendor is always rest/set to ibm. Not directly a gcc issue.  Gcc does not maintain config.sub.
Comment 20 Alexander Egorenkov 2020-06-18 17:15:12 UTC
(In reply to Andrew Pinski from comment #19)
> This is a config.sub issue where the vendor is always rest/set to ibm. Not
> directly a gcc issue.  Gcc does not maintain config.sub.

Ok, sorry, thank you :)
Comment 21 Alexander Egorenkov 2020-06-18 17:31:26 UTC
Could you please point me to the bug report it was moved to ? Thanks
Comment 22 Andrew Pinski 2020-06-18 18:32:25 UTC
(In reply to Alexander Egorenkov from comment #21)
> Could you please point me to the bug report it was moved to ? Thanks

Can you file it?  Well they don't have a bug database, just an email list:
Report bugs and patches to <config-patches@gnu.org>.
Comment 23 Alexander Egorenkov 2020-06-19 04:51:26 UTC
I would gladly if i understood the real problem. Sorry i'm not very familiar with config.guess & config.sub. Could you please elaborate what the problem is and how it should be fixed ? Thanks
Comment 24 Alexander Egorenkov 2020-06-20 10:52:55 UTC
I finally figured it out and fixed buildroot.
This info is for posterity, in case somebody will have the same issue.
If i understood it correctly, then the problem was that buildroot
wrongly tried to build a native compiler on s390x host for s390 target instead
of a cross-compiler due to a problem is config.sub which is fixed by this path:

@@ -1138,14 +1138,6 @@ case $cpu-$vendor in
 		cpu=nsx
 		vendor=tandem
 		;;
-	s390-*)
-		cpu=s390
-		vendor=ibm
-		;;
-	s390x-*)
-		cpu=s390x
-		vendor=ibm
-		;;
 	tile*-*)
 		os=${os:-linux-gnu}
 		;;
@@ -1229,6 +1221,7 @@ case $cpu-$vendor in
 			| pyramid \
 			| riscv | riscv32 | riscv64 \
 			| rl78 | romp | rs6000 | rx \
+			| s390 | s390x \
 			| score \
 			| sh | shl \
 			| sh[1234] | sh[24]a | sh[24]ae[lb] | sh[23]e | she[lb] | sh[lb]e \



After fixing config.sub everything builds just fine and works great :)
I'm going to try to submit this fix to the config mailing list.
Best regard & thank you