Bug 70464 - [arch64] create a self hosting compiler
Summary: [arch64] create a self hosting compiler
Status: RESOLVED WORKSFORME
Alias: None
Product: gcc
Classification: Unclassified
Component: target (show other bugs)
Version: 5.3.0
: P3 normal
Target Milestone: ---
Assignee: Not yet assigned to anyone
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2016-03-30 16:27 UTC by georg
Modified: 2016-04-02 12:49 UTC (History)
0 users

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


Attachments
script to "cross compile the native compiler" (1.59 KB, application/x-shellscript)
2016-03-30 16:28 UTC, georg
Details
config log of the attempt to compile gcc on the raspberry pi3 (6.95 KB, text/plain)
2016-03-30 17:13 UTC, georg
Details

Note You need to log in before you can comment on or make changes to this bug.
Description georg 2016-03-30 16:27:17 UTC
During our approach to get the raspberry pi3 and gentoo with an aarch64 kernel and userland running i tried to cross compile a "native compiler for aarch64".

Our attempt succedded, as we got the userland cross compiled and the kernel. Both are running and seem to be ok, as far as we can tell currently. There is one core component for gentoo missing: The gcc. 

I tried to cross compile with the added cross compiler script. I used crossdev to create the amd64 to aarch64 cross compiler. With gcc 5.3.0 i could create a toolchain which runs on aarch64 but only supports C. No C++. You can download the folder here:
https://www.schorsch-tech.de/rpi3/cross.tar.bz2

As i got this up, i tried to compile the aarch64 gcc with c++ on the raspberry pi but it failed at a for me very strange point:

checking for unsigned long long int... yes
checking for uintmax_t... yes
checking for uintptr_t... yes
checking for int64_t underlying type... long long
configure: error: error verifying int64_t uses long long
Makefile:4159: recipe for target 'configure-stage1-gcc' failed
make[2]: *** [configure-stage1-gcc] Error 1
make[2]: Leaving directory '/var/tmp/portage/sys-devel/gcc-5.3.0/work/build'
Makefile:19012: recipe for target 'stage1-bubble' failed
make[1]: *** [stage1-bubble] Error 2
make[1]: Leaving directory '/var/tmp/portage/sys-devel/gcc-5.3.0/work/build'
Makefile:19343: recipe for target 'bootstrap-lean' failed
make: *** [bootstrap-lean] Error 2

With this compiler i could compile flex and bison which are a dependency to compile it with the gentoo tools. They seem both running.


As i had this issue, i tried with the added script to get the gcc with c and c++ built. But it always failed at:

In file included from /usr/aarch64-armv8a-linux-gnueabi/usr/include/stdio.h:936:0,
                 from ../../../gcc-5.3.0/libitm/util.cc:27:
/usr/aarch64-armv8a-linux-gnueabi/usr/include/bits/stdio2.h: In function 'void GTM::gtm_verror(const char*, va_list)':
/usr/aarch64-armv8a-linux-gnueabi/usr/include/bits/stdio2.h:124:1: error: inlining failed in call to always_inline 'int vfprintf(FILE*, const char*, __gnuc_va_list)': function body can be overwritten at link time
 vfprintf (FILE *__restrict __stream,
 ^
../../../gcc-5.3.0/libitm/util.cc:35:31: error: called from here
   vfprintf (stderr, fmt, list);
                               ^
Makefile:517: recipe for target 'util.lo' failed
make[4]: *** [util.lo] Error 1

I tried gcc 4.9.3 as cross chain and as target, 5.3.0 cross and target. But i failed .... 

All our attempts are documented in the gentoo forum.
https://forums.gentoo.org/viewtopic-p-7899614.html#7899614
Comment 1 georg 2016-03-30 16:28:06 UTC
Created attachment 38136 [details]
script to "cross compile the native compiler"
Comment 2 georg 2016-03-30 16:30:43 UTC
I also tried various target triplets
aarch64-linux-gnu and aarch64-armv8a-linux-gnueabi. Nut as far as i know aarch64-linux-gnu is right.
Comment 3 georg 2016-03-30 16:56:48 UTC
I tried on the Raspberry pi 64 bit with the "C only gcc":

Pi_3 64_bit ~ # cat main.c 
#include <stdio.h>
#include <stdint.h>

int main(int argc, char** argv)
{
        printf("sizeof int64_t=%d\n",sizeof(int64_t));
        return 0;
}
Pi_3 64_bit ~ # gcc main.c 
Pi_3 64_bit ~ # ./a.out 
sizeof int64_t=8
Pi_3 64_bit ~ # gcc --version
gcc (GCC) 5.3.0
Copyright (C) 2015 Free Software Foundation, Inc.
This is free software; see the source for copying conditions.  There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
Comment 4 georg 2016-03-30 17:01:29 UTC
Pi_3 64_bit ~ # grep int64_t /opt/cross/aarch64-linux-gnu/include/stdint.h 
typedef long int                int64_t;
typedef long long int           int64_t;
typedef unsigned long int       uint64_t;
typedef unsigned long long int  uint64_t;
Comment 5 ktkachov 2016-03-30 17:01:40 UTC
(In reply to georg from comment #0)
> During our approach to get the raspberry pi3 and gentoo with an aarch64
> kernel and userland running i tried to cross compile a "native compiler for
> aarch64".
> 
> Our attempt succedded, as we got the userland cross compiled and the kernel.
> Both are running and seem to be ok, as far as we can tell currently. There
> is one core component for gentoo missing: The gcc. 
> 
> I tried to cross compile with the added cross compiler script. I used
> crossdev to create the amd64 to aarch64 cross compiler. With gcc 5.3.0 i
> could create a toolchain which runs on aarch64 but only supports C. No C++.
> You can download the folder here:
> https://www.schorsch-tech.de/rpi3/cross.tar.bz2
> 

I usually use the target aarch64-none-linux-gnu, but aarch64-linux-gnu should work too.

Note that GCC requires a C++ compiler to build, so trying to use a C-only compiler can't work.

If I understand correctly, you want to build an aarch64-to-aarch64 compiler on an x86_64-linux host, and you've only managed to do that for the C frontend?
What was the gcc configure line passed to that build (by crossdev, or whatever)

Passing "-v" to the C-only gcc would give that information...
Comment 6 georg 2016-03-30 17:13:52 UTC
Created attachment 38137 [details]
config log of the attempt to compile gcc on the raspberry pi3

This is the complete config.log of the attempt to build the native and complete gcc on the raspberry pi 3 using the gentoo tools and the "C only gcc"
Comment 7 georg 2016-03-30 17:17:38 UTC
(In reply to ktkachov from comment #5)
> I usually use the target aarch64-none-linux-gnu, but aarch64-linux-gnu
> should work too.
> 
> Note that GCC requires a C++ compiler to build, so trying to use a C-only
> compiler can't work.
> 
> If I understand correctly, you want to build an aarch64-to-aarch64 compiler
> on an x86_64-linux host, and you've only managed to do that for the C
> frontend?
> What was the gcc configure line passed to that build (by crossdev, or
> whatever)
> 
> Passing "-v" to the C-only gcc would give that information...

Yes, you are right. I want on an amd64 host compile a "aarch64 to aarch64" compiler.

This is the required information. Right from the target

Pi_3 64_bit ~ # gcc -v   
Using built-in specs.
COLLECT_GCC=gcc
COLLECT_LTO_WRAPPER=/opt/cross/libexec/gcc/aarch64-linux-gnu/5.3.0/lto-wrapper
Target: aarch64-linux-gnu
Configured with: ../gcc-5.3.0/configure --prefix=/opt/cross --host=aarch64-linux-gnu --target=aarch64-linux-gnu --enable-languages=c --disable-multilib
Thread model: posix
gcc version 5.3.0 (GCC)
Comment 8 ktkachov 2016-03-30 17:27:26 UTC
So what happens when you try to build a C,C++ compiler from your x86_64 host? i.e. --enable-languages=c,c++

As said, you need a C++ compiler to build gcc (natively or cross)
Comment 9 georg 2016-03-30 17:33:14 UTC
This is the previous result as i tried this:

make[4]: Leaving directory '/home/georg/intern/Dokumente/Entwicklung/rpi3/src/gcc/build-gcc/aarch64-armv8a-linux-gnueabi/libitm/testsuite'
make[4]: Entering directory '/home/georg/intern/Dokumente/Entwicklung/rpi3/src/gcc/build-gcc/aarch64-armv8a-linux-gnueabi/libitm'
/bin/sh ./libtool --tag=CXX   --mode=compile aarch64-armv8a-linux-gnueabi-c++ -B/home/georg/Dokumente/Entwicklung/rpi3/src/gcc/build-gcc/aarch64-armv8a-linux-gnueabi/libstdc++-v3/src/.libs -B/home/georg/Dokumente/Entwicklung/rpi3/src/gcc/build-gcc/aarch64-armv8a-linux-gnueabi/libstdc++-v3/libsupc++/.libs   -DHAVE_CONFIG_H -I. -I../../../gcc-5.3.0/libitm  -I../../../gcc-5.3.0/libitm/config/linux/aarch64 -I../../../gcc-5.3.0/libitm/config/linux -I../../../gcc-5.3.0/libitm/config/aarch64 -I../../../gcc-5.3.0/libitm/config/posix -I../../../gcc-5.3.0/libitm/config/generic -I../../../gcc-5.3.0/libitm  -ftls-model=initial-exec -Wall -Werror  -Wc,-pthread -std=gnu++0x -funwind-tables -fno-exceptions -fno-rtti -fabi-version=4 -g -O2 -D_GNU_SOURCE -MT util.lo -MD -MP -MF .deps/util.Tpo -c -o util.lo ../../../gcc-5.3.0/libitm/util.cc
libtool: compile:  aarch64-armv8a-linux-gnueabi-c++ -B/home/georg/Dokumente/Entwicklung/rpi3/src/gcc/build-gcc/aarch64-armv8a-linux-gnueabi/libstdc++-v3/src/.libs -B/home/georg/Dokumente/Entwicklung/rpi3/src/gcc/build-gcc/aarch64-armv8a-linux-gnueabi/libstdc++-v3/libsupc++/.libs -DHAVE_CONFIG_H -I. -I../../../gcc-5.3.0/libitm -I../../../gcc-5.3.0/libitm/config/linux/aarch64 -I../../../gcc-5.3.0/libitm/config/linux -I../../../gcc-5.3.0/libitm/config/aarch64 -I../../../gcc-5.3.0/libitm/config/posix -I../../../gcc-5.3.0/libitm/config/generic -I../../../gcc-5.3.0/libitm -ftls-model=initial-exec -Wall -pthread -Werror -std=gnu++0x -funwind-tables -fno-exceptions -fno-rtti -fabi-version=4 -g -O2 -D_GNU_SOURCE -MT util.lo -MD -MP -MF .deps/util.Tpo -c ../../../gcc-5.3.0/libitm/util.cc  -fPIC -DPIC -o .libs/util.o
In file included from /usr/aarch64-armv8a-linux-gnueabi/usr/include/stdio.h:936:0,
                 from ../../../gcc-5.3.0/libitm/util.cc:27:
/usr/aarch64-armv8a-linux-gnueabi/usr/include/bits/stdio2.h: In function 'void GTM::gtm_verror(const char*, va_list)':
/usr/aarch64-armv8a-linux-gnueabi/usr/include/bits/stdio2.h:124:1: error: inlining failed in call to always_inline 'int vfprintf(FILE*, const char*, __gnuc_va_list)': function body can be overwritten at link time
 vfprintf (FILE *__restrict __stream,
 ^
../../../gcc-5.3.0/libitm/util.cc:35:31: error: called from here
   vfprintf (stderr, fmt, list);
                               ^
Makefile:517: recipe for target 'util.lo' failed 

Right now i compile the "aarch64-none-linux-gnu" "x64_64-to-aarch64" compiler to follow your advice as close as possible. When this is finished i try it again (with host and target aarch64-none-linux-gnu) and post the exact results + the exact configure line for the gcc.
Comment 10 georg 2016-03-30 18:28:00 UTC
Components to build the "aarch64-to-aarch64" gcc/g++:
-----------------------------------------------------
sha1sum + filename
f10c64e92d9c72ee428df3feaf349c4ecb2493bd  binutils-2.25.tar.gz
2dc70313e8e2c6610b856d627bce9c9c3f848077  cloog-0.18.1.tar.gz
39ebff8a873181728b02db3689215557628eed9d  gcc-5.3.0.tar.gz
5be95334f197121d8b351059a1c6518305d88e2a  glibc-2.22.tar.xz
1aaf78358ab9e34aeb61f3ae08174ee9118ece98  gmp-6.0.0a.tar.xz
c5a2b201bf05229647e73203c0bf2d9679d4d21f  isl-0.16.1.tar.bz2
18d8e415f57a1fe4322faec441e45b6d2383b7d1  linux-4.5.tar.xz
5072d82ab50ec36cc8c0e320b5c377adb48abe70  mpc-1.0.2.tar.gz
cedc0055d55b6ee4cd17e1e6119ed412520ff81a  mpfr-3.1.4.tar.xz
------------------------------------------------------


Used x86_64-to-aarch64 compiler (created with crossdev 20150716):
----------------------------------------------------------------
georg@hammerhead ~ $ whereis aarch64-none-linux-gnu-gcc
aarch64-none-linux-gnu-gcc: /usr/bin/aarch64-none-linux-gnu-gcc
georg@hammerhead ~ $ file /usr/bin/aarch64-none-linux-gnu-gcc
/usr/bin/aarch64-none-linux-gnu-gcc: ELF 64-bit LSB executable, x86-64, version 1 (SYSV), dynamically linked, interpreter /lib64/ld-linux-x86-64.so.2, for GNU/Linux 2.6.32, stripped

georg@hammerhead ~ $ /usr/bin/aarch64-none-linux-gnu-gcc -v
Using built-in specs.
COLLECT_GCC=/usr/x86_64-pc-linux-gnu/aarch64-none-linux-gnu/gcc-bin/5.3.0/aarch64-none-linux-gnu-gcc
COLLECT_LTO_WRAPPER=/usr/libexec/gcc/aarch64-none-linux-gnu/5.3.0/lto-wrapper
Target: aarch64-none-linux-gnu
Configured with: /var/tmp/portage/cross-aarch64-none-linux-gnu/gcc-5.3.0/work/gcc-5.3.0/configure --host=x86_64-pc-linux-gnu --target=aarch64-none-linux-gnu --build=x86_64-pc-linux-gnu --prefix=/usr --bindir=/usr/x86_64-pc-linux-gnu/aarch64-none-linux-gnu/gcc-bin/5.3.0 --includedir=/usr/lib/gcc/aarch64-none-linux-gnu/5.3.0/include --datadir=/usr/share/gcc-data/aarch64-none-linux-gnu/5.3.0 --mandir=/usr/share/gcc-data/aarch64-none-linux-gnu/5.3.0/man --infodir=/usr/share/gcc-data/aarch64-none-linux-gnu/5.3.0/info --with-gxx-include-dir=/usr/lib/gcc/aarch64-none-linux-gnu/5.3.0/include/g++-v5 --with-python-dir=/share/gcc-data/aarch64-none-linux-gnu/5.3.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 5.3.0 p1.0, pie-0.6.5' --enable-libstdcxx-time --enable-poison-system-directories --with-sysroot=/usr/aarch64-none-linux-gnu --disable-bootstrap --enable-__cxa_atexit --enable-clocale=gnu --disable-multilib --disable-altivec --disable-fixed-point --disable-libgcj --enable-libgomp --disable-libmudflap --disable-libssp --disable-libcilkrts --enable-lto --without-isl --enable-libsanitizer
Thread model: posix
gcc version 5.3.0 (Gentoo 5.3.0 p1.0, pie-0.6.5) 


Configure line for the "aarch64-to-aarch64" gcc:
-------------------------------------------------
../gcc-5.3.0/configure --prefix=/opt/cross --host=aarch64-none-linux-gnu --target=aarch64-none-linux-gnu --enable-languages=c,c++ --disable-multilib

Error message:
--------------
libtool: compile:  aarch64-none-linux-gnu-c++ -B/home/georg/Dokumente/Entwicklung/rpi3/src/gcc/build-gcc/aarch64-none-linux-gnu/libstdc++-v3/src/.libs -B/home/georg/Dokumente/Entwicklung/rpi3/src/gcc/build-gcc/aarch64-none-linux-gnu/libstdc++-v3/libsupc++/.libs -DHAVE_CONFIG_H -I. -I../../../gcc-5.3.0/libitm -I../../../gcc-5.3.0/libitm/config/linux/aarch64 -I../../../gcc-5.3.0/libitm/config/linux -I../../../gcc-5.3.0/libitm/config/aarch64 -I../../../gcc-5.3.0/libitm/config/posix -I../../../gcc-5.3.0/libitm/config/generic -I../../../gcc-5.3.0/libitm -ftls-model=initial-exec -Wall -pthread -Werror -std=gnu++0x -funwind-tables -fno-exceptions -fno-rtti -fabi-version=4 -g -O2 -D_GNU_SOURCE -MT util.lo -MD -MP -MF .deps/util.Tpo -c ../../../gcc-5.3.0/libitm/util.cc  -fPIC -DPIC -o .libs/util.o
In file included from /usr/aarch64-none-linux-gnu/usr/include/stdio.h:936:0,
                 from ../../../gcc-5.3.0/libitm/util.cc:27:
/usr/aarch64-none-linux-gnu/usr/include/bits/stdio2.h: In function 'void GTM::gtm_verror(const char*, va_list)':
/usr/aarch64-none-linux-gnu/usr/include/bits/stdio2.h:124:1: error: inlining failed in call to always_inline 'int vfprintf(FILE*, const char*, __gnuc_va_list)': function body can be overwritten at link time
 vfprintf (FILE *__restrict __stream,
 ^
../../../gcc-5.3.0/libitm/util.cc:35:31: error: called from here
   vfprintf (stderr, fmt, list);
                               ^
Makefile:517: recipe for target 'util.lo' failed


As the aarch64-none-linux-gnu-g++ executable got built but the libstdc++3 not, i copied the "partly done" destination folder to the raspberry pi 3 and here is the info about aarch64-none-linux-gnu-gcc and aarch64-none-linux-gnu-g++ from the target:
--------------
Pi_3 64_bit ~ # gcc -v
Using built-in specs.
COLLECT_GCC=gcc
COLLECT_LTO_WRAPPER=/opt/cross/libexec/gcc/aarch64-none-linux-gnu/5.3.0/lto-wrapper
Target: aarch64-none-linux-gnu
Configured with: ../gcc-5.3.0/configure --prefix=/opt/cross --host=aarch64-none-linux-gnu --target=aarch64-none-linux-gnu --enable-languages=c,c++ --disable-multilib
Thread model: posix
gcc version 5.3.0 (GCC) 
Pi_3 64_bit ~ # g++ -v
Using built-in specs.
COLLECT_GCC=g++
COLLECT_LTO_WRAPPER=/opt/cross/libexec/gcc/aarch64-none-linux-gnu/5.3.0/lto-wrapper
Target: aarch64-none-linux-gnu
Configured with: ../gcc-5.3.0/configure --prefix=/opt/cross --host=aarch64-none-linux-gnu --target=aarch64-none-linux-gnu --enable-languages=c,c++ --disable-multilib
Thread model: posix
gcc version 5.3.0 (GCC) 
Pi_3 64_bit ~ #
Comment 11 Andreas Schwab 2016-03-30 18:30:24 UTC
You should use --with-sysroot to configure your cross compiler.
Comment 12 georg 2016-03-30 18:59:39 UTC
I purged all temporary build data, added "--with-sysroot=/opt/aarch64-none-linux-gnu" to the configure line and rebuild again. The same error.

/usr/aarch64-none-linux-gnu/usr/include/bits/stdio2.h: In function 'void GTM::gtm_verror(const char*, va_list)':
/usr/aarch64-none-linux-gnu/usr/include/bits/stdio2.h:124:1: error: inlining failed in call to always_inline 'int vfprintf(FILE*, const char*, __gnuc_va_list)': function body can be overwritten at link time
 vfprintf (FILE *__restrict __stream,
 ^
../../../gcc-5.3.0/libitm/util.cc:35:31: error: called from here
   vfprintf (stderr, fmt, list);
                               ^
Makefile:517: recipe for target 'util.lo' failed
Comment 13 georg 2016-03-30 20:23:48 UTC
Now as i got a c++ compiler but no libstdc++ on the target, i try to use the gentoo tools to emerge (compile) the complete gcc on the target. Let it run over night whatever is needed. It is just a straw .... 

Any suggestions are welcome to build it. Regardless what i need to rebuild ...
Comment 14 georg 2016-03-30 21:08:52 UTC
Is it related to this? 

https://gcc.gnu.org/ml/gcc-patches/2013-04/msg00896.html
Comment 15 georg 2016-04-02 12:49:57 UTC
A gentoo comunity member found the solution. It was related to
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=61164

The solution was found here:
https://gcc.gnu.org/ml/gcc-patches/2014-09/msg02505.html