This is the mail archive of the gcc-help@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: GCC fails to build.


Hello,

On Tue, Jan 14, 2020 at 11:53 PM DAVID STUMPH <DSTUMPH1144@smail.pcd.edu> wrote:
>
> Hello,
>
> I found from the emails that you referenced earlier that there is a open source project for building cross compilers: crosstools-ng. I used it to build a toolchain with the --with-sysroot option, and here
> is the result:

Thanks for sharing your result.  Below are some comments:

> $ arm-linux-gnueabihf-gcc -v
> Using built-in specs.
> COLLECT_GCC=arm-linux-gnueabihf-gcc
> COLLECT_LTO_WRAPPER=/home/david/pi/arm-linux-gnueabihf/bin/../libexec/gcc/arm-linux-
> gnueabihf/9.2.0/lto-wrapper
> Target: arm-linux-gnueabihf
> Configured with: /home/david/cross-gcc/crosstool-ng/.build/arm-linux-gnueabihf/src/gcc/
> configure
> --build=x86_64-build_pc-linux-gnu
> --host=x86_64-build_pc-linux-gnu
> --target=arm-linux-gnueabihf
> --prefix=/home/david/x-tools/arm-linux-gnueabihf
> --with-sysroot=/home/david/x-tools/arm-linux-gnueabihf/arm-linux-gnueabihf/sysroot

Right, that is why I was surprised with the MinGW-w64's setting for
the sysroot you wrote earlier, which in this setting would result in
--with-sysroot=/home/david/x-tools/arm-linux-gnueabihf.

> --enable-languages=c,c++
> --with-float=hard
> --with-pkgversion='crosstool-NG 1.24.0.55-7bd6bb0'
> --disable-sjlj-exceptions
> --enable-__cxa_atexit
> --disable-libmudflap
> --disable-libgomp
> --disable-libssp
> --disable-libquadmath
> --disable-libquadmath-support
> --disable-libsanitizer

This setting, which disables the building of asan_linux.o of
libsanitizer, prevents the PATH_MAX problem from cropping up.

> --disable-libmpx
> --with-gmp=/home/david/cross-gcc/crosstool-ng/.build/arm-linux-gnueabihf/buildtools
> --with-mpfr=/home/david/cross-gcc/crosstool-ng/.build/arm-linux-gnueabihf/buildtools
> --with-mpc=/home/david/cross-gcc/crosstool-ng/.build/arm-linux-gnueabihf/buildtools
> --with-isl=/home/david/cross-gcc/crosstool-ng/.build/arm-linux-gnueabihf/buildtools
> --disable-lto

I think that this setting, which disables LTO, means that zstd is not
used (BTW, you are right that Cloog is no longer used).

> --with-host-libstdcxx='-static-libgcc -Wl,-Bstatic,-lstdc++ -lm'
> --enable-threads=posix
> --enable-target-optspace
> --disable-plugin
> --disable-nls
> --disable-multilib
> --with-local-prefix=/home/david/x-tools/arm-linux-gnueabihf/arm-linux-gnueabihf/sysroot
> --enable-long-long
> Thread model: posix
> gcc version 9.2.0 (crosstool-NG 1.24.0.55-7bd6bb0)
>
> As you can see, it uses a subdirectory of the prefix, $PREFIX/arm-linux-gnueabihf/sysroot.

Yes, and as I said earlier, I would like to reproduce your case by
following http://preshing.com/20141119/how-to-build-a-gcc-cross-compiler
with some modifications (for your setting, I use the host libzstd and
let binutils build the isl on its own, which is also the case for GCC
as shown in Step 0 below).

Below is the final result where I have perfected my modifications that
I sent earlier (note that I was wrong in using Bash aliases because
configure scripts ignore them; consequently, I use symbolic links
instead as shown in Step 0 below):

[0. Preliminaries]

$ echo $PATH
/home/eus/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games:/snap/bin
$ export PATH=$HOME/cross-gcc/install/bin:$PATH

$ which gcc
/home/eus/bin/gcc
$ file /home/eus/bin/gcc
/home/eus/bin/gcc: symbolic link to /usr/bin/gcc-8
$ gcc -v
Using built-in specs.
COLLECT_GCC=gcc
COLLECT_LTO_WRAPPER=/usr/lib/gcc/x86_64-linux-gnu/8/lto-wrapper
Target: x86_64-linux-gnu
Configured with: ../src/configure -v --with-pkgversion='Ubuntu
8.3.0-16ubuntu3~16.04'
--with-bugurl=file:///usr/share/doc/gcc-8/README.Bugs
--enable-languages=c,ada,c++,go,brig,d,fortran,objc,obj-c++
--prefix=/usr --with-gcc-major-version-only --program-suffix=-8
--program-prefix=x86_64-linux-gnu- --enable-shared
--enable-linker-build-id --libexecdir=/usr/lib
--without-included-gettext --enable-threads=posix --libdir=/usr/lib
--enable-nls --enable-clocale=gnu --enable-libstdcxx-debug
--enable-libstdcxx-time=yes --with-default-libstdcxx-abi=new
--enable-gnu-unique-object --disable-vtable-verify --enable-libmpx
--enable-plugin --with-system-zlib --with-target-system-zlib
--enable-objc-gc=auto --enable-multiarch --disable-werror
--with-arch-32=i686 --with-abi=m64 --with-multilib-list=m32,m64,mx32
--enable-multilib --with-tune=generic --enable-checking=release
--build=x86_64-linux-gnu --host=x86_64-linux-gnu
--target=x86_64-linux-gnu
Thread model: posix
gcc version 8.3.0 (Ubuntu 8.3.0-16ubuntu3~16.04)

$ which g++
/home/eus/bin/g++
$ file /home/eus/bin/g++
/home/eus/bin/g++: symbolic link to /usr/bin/g++-8
$ g++ -v
Using built-in specs.
COLLECT_GCC=g++
COLLECT_LTO_WRAPPER=/usr/lib/gcc/x86_64-linux-gnu/8/lto-wrapper
Target: x86_64-linux-gnu
Configured with: ../src/configure -v --with-pkgversion='Ubuntu
8.3.0-16ubuntu3~16.04'
--with-bugurl=file:///usr/share/doc/gcc-8/README.Bugs
--enable-languages=c,ada,c++,go,brig,d,fortran,objc,obj-c++
--prefix=/usr --with-gcc-major-version-only --program-suffix=-8
--program-prefix=x86_64-linux-gnu- --enable-shared
--enable-linker-build-id --libexecdir=/usr/lib
--without-included-gettext --enable-threads=posix --libdir=/usr/lib
--enable-nls --enable-clocale=gnu --enable-libstdcxx-debug
--enable-libstdcxx-time=yes --with-default-libstdcxx-abi=new
--enable-gnu-unique-object --disable-vtable-verify --enable-libmpx
--enable-plugin --with-system-zlib --with-target-system-zlib
--enable-objc-gc=auto --enable-multiarch --disable-werror
--with-arch-32=i686 --with-abi=m64 --with-multilib-list=m32,m64,mx32
--enable-multilib --with-tune=generic --enable-checking=release
--build=x86_64-linux-gnu --host=x86_64-linux-gnu
--target=x86_64-linux-gnu
Thread model: posix
gcc version 8.3.0 (Ubuntu 8.3.0-16ubuntu3~16.04)

[1. Binutils]

$ tar xf binutils-2.33.1.tar.xz
$ tar xf isl-0.22.tar.xz
$ ln -s ../isl-0.22 binutils-2.33.1/isl
$ mkdir build-binutils
$ cd build-binutils
$ ../binutils-2.33.1/configure \
--prefix=$HOME/cross-gcc/install \
--target=arm-linux-gnueabihf \
--disable-multilib \
--host=$MACHTYPE \
--build=$MACHTYPE \
--with-sysroot=$HOME/cross-gcc/install/arm-linux-gnueabihf \
--with-isl
$ time make -j16
real    2m52.716s
user    7m6.530s
sys    0m44.738s

$ make install
$ cd ..

[2. Linux Kernel Headers]

$ tar xf linux-5.4.8.tar.xz
$ cd linux-5.4.8
$ make \
ARCH=arm \
INSTALL_HDR_PATH=$HOME/cross-gcc/install/arm-linux-gnueabihf \
headers_install
$ cd ..

[3. C/C++ Compilers]

$ tar xf gmp-6.1.2.tar.xz
$ tar xf mpc-1.1.0.tar.gz
$ tar xf mpfr-4.0.2.tar.xz
$ tar xf gcc-9.2.0.tar.xz
$ ln -s ../isl-0.22 gcc-9.2.0/isl
$ ln -s ../gmp-6.1.2 gcc-9.2.0/gmp
$ ln -s ../mpc-1.1.0 gcc-9.2.0/mpc
$ ln -s ../mpfr-4.0.2 gcc-9.2.0/mpfr
$ aptitude search -F%p '~i zstd'
libzstd1
libzstd1-dev
zstd
$ aptitude show libzstd1-dev
Package: libzstd1-dev
New: yes
State: installed
Automatically installed: no
Version: 1.3.1+dfsg-1~ubuntu0.16.04.1
Priority: optional
Section: universe/libdevel
Maintainer: Ubuntu Developers <ubuntu-devel-discuss@lists.ubuntu.com>
Architecture: amd64
Uncompressed Size: 642 k
Depends: libzstd1 (= 1.3.1+dfsg-1~ubuntu0.16.04.1)
Conflicts: libzstd-dev, libzstd-dev:i386, libzstd1-dev:i386
Provides: libzstd-dev
Description: fast lossless compression algorithm -- development files
 Zstd, short for Zstandard, is a fast lossless compression algorithm,
targeting real-time compression scenarios at zlib-level compression
ratio.

 This package contains the headers and static library.
Homepage: https://github.com/facebook/zstd
$ mkdir build-gcc
$ cd build-gcc
$ # --with-sysroot finds the libc correctly after installation
# --with-build-sysroot fixes the PATH_MAX problem
# --with-native-system-header-dir (relative to sysroot) to avoid
/usr/include problem
../gcc-9.2.0/configure \
--prefix=$HOME/cross-gcc/install \
--target=arm-linux-gnueabihf \
--host=$MACHTYPE \
--build=$MACHTYPE \
--enable-languages=c,c++ \
--disable-multilib \
--with-sysroot=$HOME/cross-gcc/install/arm-linux-gnueabihf \
--with-build-sysroot=$HOME/cross-gcc/install/arm-linux-gnueabihf \
--with-native-system-header-dir=/include \
--with-zstd
$ time make -j16 all-gcc
real    15m16.249s
user    52m14.005s
sys    2m50.789s

$ make install-gcc
$ cd ..

[4. Standard C Library Headers and Startup Files]

$ tar xf glibc-2.30.tar.xz
$ mkdir build-glibc
$ cd build-glibc
$ # No sysroot
../glibc-2.30/configure \
--prefix=/ \
--build=$MACHTYPE \
--host=arm-linux-gnueabihf \
--target=arm-linux-gnueabihf \
--with-headers=$HOME/cross-gcc/install/arm-linux-gnueabihf/include \
--disable-multilib \
libc_cv_forced_unwind=yes
$ make DESTDIR=$HOME/cross-gcc/install/arm-linux-gnueabihf
install-bootstrap-headers=yes install-headers
$ make -j16 csu/subdir_lib
$ install csu/crt1.o csu/crti.o csu/crtn.o
$HOME/cross-gcc/install/arm-linux-gnueabihf/lib
$ arm-linux-gnueabihf-gcc -nostdlib -nostartfiles -shared -x c
/dev/null -o $HOME/cross-gcc/install/arm-linux-gnueabihf/lib/libc.so
$ touch $HOME/cross-gcc/install/arm-linux-gnueabihf/include/gnu/stubs.h
$ cd ..

[5. Compiler Support Library]

$ cd build-gcc
$ rm gcc/stmp-fixinc # Fix the PATH_MAX problem at Step 7
$ time make -j16 all-target-libgcc
real    2m9.048s
user    5m52.969s
sys    1m40.113s

$ make install-target-libgcc
$ cd ..

[6. Standard C Library]

$ cd build-glibc
$ time make -j16
real    6m11.895s
user    18m59.766s
sys    2m44.554s

$ make DESTDIR=$HOME/cross-gcc/install/arm-linux-gnueabihf install
$ cd ..

[7. Standard C++ Library]

$ cd build-gcc
$ time make -j16
real    8m44.296s
user    18m22.151s
sys    3m10.522s

$ make install
$ cd ..

[Testing the Cross-Compiler]

$ arm-linux-gnueabihf-g++ -v
Using built-in specs.
COLLECT_GCC=arm-linux-gnueabihf-g++
COLLECT_LTO_WRAPPER=/home/eus/cross-gcc/install/libexec/gcc/arm-linux-gnueabihf/9.2.0/lto-wrapper
Target: arm-linux-gnueabihf
Configured with: ../gcc-9.2.0/configure
--prefix=/home/eus/cross-gcc/install --target=arm-linux-gnueabihf
--host=x86_64-pc-linux-gnu --build=x86_64-pc-linux-gnu
--enable-languages=c,c++ --disable-multilib
--with-sysroot=/home/eus/cross-gcc/install/arm-linux-gnueabihf
--with-build-sysroot=/home/eus/cross-gcc/install/arm-linux-gnueabihf
--with-native-system-header-dir=/include --with-zstd
Thread model: posix
gcc version 9.2.0 (GCC)

$ cat test.cpp
#include <iostream>

int main()
{
    auto lambda = [](auto x){ return x; };
    std::cout << lambda("Hello generic lambda!\n");
    return 0;
}
$ arm-linux-gnueabihf-g++ -std=c++14 test.cpp
$ arm-linux-gnueabihf-objdump -d a.out > test.txt # attached

$ cat testlib.cpp
#include <iostream>
#include <thread>

int main()
{
  std::thread t([]() { std::cout << "In thread\n";});
  t.join();
  return 0;
}
$ arm-linux-gnueabihf-g++ -std=c++14 testlib.cpp -pthread
$ arm-linux-gnueabihf-objdump -d a.out > testlib.txt # attached

Perhaps you can send me your test.txt and testlib.txt that are
produced using your cross compiler (I suspect some differences exist
because your GCC is configured using --disable-libssp)?

Thank you.

> Thank you for all of your help, Tadeus,

My pleasure.

> David

-- 
Best regards,
Tadeus

Attachment: test.txt
Description: Text document

Attachment: testlib.txt
Description: Text document


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]