2021-06-08 13:14:45 +00:00
%define target aarch64-linux-gnu
%define target_kernel arm64
2021-06-09 17:09:54 +00:00
%define target_qemu_arch aarch64
2021-06-08 13:14:45 +00:00
%define gcc_branch 8
Name : cross-gcc%gcc_branch-%target
Version : 8.4.1
Release : alt1
%define gcc_source_version_timestamp 20200305
%define orig_gcc_release alt0.p9.1
%define binutils_version 2.31.1
%define binutils_evr 1:%binutils_version-alt4
%define glibc_evr 2.27-alt13
%define kernel_version 5.4
2021-06-09 07:59:25 +00:00
%define sysroot %prefix/%target/sys-root
2021-06-09 17:08:54 +00:00
%define target_ld_linux /lib64/ld-linux-aarch64.so.1
2021-06-08 13:14:45 +00:00
Summary : aarch64-targeted GCC cross-toolchain
License : LGPL-2.1-or-later and LGPL-3.0-or-later and GPL-2.0-or-later and GPL-3.0-or-later and GPL-3.0-or-later with GCC-exception-3.1
Group : Development/C
BuildPreReq : gcc-c++
BuildPreReq : libmpc-devel libmpfr-devel libgmp-devel zlib-devel
BuildPreReq : coreutils flex bison makeinfo
BuildRequires : gcc-source = %version-%orig_gcc_release
BuildRequires : binutils-source = %binutils_evr
BuildRequires : glibc-source = %glibc_evr
BuildRequires : kernel-source-%kernel_version
2021-06-09 17:09:54 +00:00
BuildRequires : qemu-user-static-%target_qemu_arch
2021-06-08 13:14:45 +00:00
%define _libexecdir /usr/libexec
%description
aarch64-targeted GCC cross-toolchain
%prep
%setup -cT
tar -xf /usr/src/gcc-source/gcc-%version-%gcc_source_version_timestamp.tar
tar -xf /usr/src/binutils-source/binutils-%binutils_version.tar
tar -xf /usr/src/kernel/sources/kernel-source-%kernel_version.tar
tar -xf /usr/src/glibc-source/glibc-%glibc_evr.tar
2021-06-09 05:57:48 +00:00
rm -rf stage
2021-06-08 13:14:45 +00:00
%build
mkdir -p obj_binutils
mkdir -p obj_gcc
mkdir -p obj_kheaders
mkdir -p obj_glibc
2021-06-09 05:57:48 +00:00
mkdir -p -m755 stage%prefix/bin
export PATH=`pwd`/stage%prefix/bin:$PATH
stagedir=`pwd`/stage
2021-06-08 13:14:45 +00:00
# kernel headers
%_make_bin -j%__nprocs \
-C kernel-source-%kernel_version \
O=`pwd`/obj_kheaders \
ARCH=%target_kernel \
2021-06-09 05:57:48 +00:00
INSTALL_HDR_PATH=${stagedir}%sysroot/usr \
2021-06-08 13:14:45 +00:00
headers_install
# XXX: avoid %%configure for it puts $target libraries into /usr/lib64
cd obj_binutils
../binutils-%binutils_version/configure \
--target=%target \
--host=%{_configure_platform} \
--build=%{_configure_platform} \
--prefix=%prefix \
--disable-bootstrap \
--disable-multiarch \
--disable-multilib \
--disable-werror \
--disable-shared \
--disable-nls \
--with-sysroot=%sysroot \
2021-06-09 05:57:48 +00:00
--with-build-sysroot=${stagedir}%sysroot \
2021-06-08 13:14:45 +00:00
--with-system-zlib \
--enable-plugins \
--enable-gold=yes \
--enable-ld=default \
--enable-64-bit-bfd \
--enable-relro \
--enable-textrel-check=warning
%make_build
# XXX: avoid makeinstall for it puts $target libraries into /usr/lib64
2021-06-09 05:57:48 +00:00
%make_install install DESTDIR=${stagedir}
2021-06-08 13:14:45 +00:00
# N.B.: this builds GCC in a single stage (but not all target at once)
cd ../obj_gcc
# XXX: avoid %%configure puts $target libraries in /usr/lib64
../gcc-%version-%gcc_source_version_timestamp/configure \
--target=%target \
--host=%{_configure_platform} \
--build=%{_configure_platform} \
--prefix=%prefix \
--disable-bootstrap \
--disable-multiarch \
--disable-multilib \
--disable-werror \
--with-sysroot=%sysroot \
2021-06-09 05:57:48 +00:00
--with-build-sysroot=${stagedir}%sysroot \
2021-06-08 13:14:45 +00:00
--with-gcc-major-version-only \
--enable-languages=c,c++ \
2021-06-09 07:01:27 +00:00
--enable-version-specific-runtime-libs \
2021-06-08 13:14:45 +00:00
--disable-nls \
--with-system-zlib
%make_build all-gcc
# XXX: avoid makeinstall for it puts $target libraries into /usr/lib64
2021-06-09 05:57:48 +00:00
%make_install install-gcc DESTDIR=${stagedir}
2021-06-08 13:14:45 +00:00
cd ../obj_glibc
# XXX: avoid %%configure since it puts target libraries/binaries into /usr/lib64
# Note: glibc's is a library, so $host must be the same as $target
../glibc-%glibc_evr/configure \
--host=%target \
--target=%target \
--build=%{_configure_platform} \
--prefix=%prefix \
--with-sysroot=%sysroot \
2021-06-09 05:57:48 +00:00
--with-build-sysroot=${stagedir}%sysroot \
--with-headers=${stagedir}%sysroot/usr/include \
--with-lib=${stagedir}%sysroot/usr/lib \
2021-06-08 13:14:45 +00:00
--disable-multilib \
--disable-crypt \
libc_cv_forced_unwind=yes
# glibc: headers, C runtime
2021-06-09 05:57:48 +00:00
%_make_bin -j%__nprocs install-bootstrap-headers=yes install-headers DESTDIR=${stagedir}%sysroot
2021-06-08 13:14:45 +00:00
%_make_bin -j%__nprocs csu/subdir_lib
2021-06-09 05:57:48 +00:00
install -d -m755 ${stagedir}%sysroot/usr/lib
install csu/crt1.o csu/crti.o csu/crtn.o ${stagedir}%sysroot/usr/lib
%target-gcc -nostdlib -nostartfiles -shared -x c /dev/null -o " $ { s t a g e d i r } % s y s r o o t / u s r / l i b / l i b c . s o "
touch ${stagedir}/%sysroot/usr/include/gnu/stubs.h
touch ${stagedir}/%sysroot/usr/include/bits/stdio_lim.h
2021-06-08 13:14:45 +00:00
# libgcc
cd ../obj_gcc
%make_build all-target-libgcc
# XXX: avoid makeinstall since it puts target libs into /usr/lib64
2021-06-09 05:57:48 +00:00
%make_install install-target-libgcc DESTDIR=${stagedir}
2021-06-08 13:14:45 +00:00
# finish off glibc
cd ../obj_glibc
%make_build
# XXX: avoid makeinstall since it puts target libs into /usr/lib64
# Note: target glibc **must** be installed into sysroot to prevent
# native compilers from using it by default
2021-06-09 05:57:48 +00:00
%make_install install DESTDIR=${stagedir}%sysroot
2021-06-08 13:14:45 +00:00
# finish off gcc (g++, libstdc++, libssp, whatever)
cd ../obj_gcc
%make_build
# XXX: avoid makeinstall since it puts target libs into /usr/lib64
2021-06-09 05:57:48 +00:00
%make_install install DESTDIR=${stagedir}
2021-06-08 13:14:45 +00:00
%install
2021-06-09 05:57:48 +00:00
export PATH=`pwd`/stage%prefix/bin:$PATH
%_make_bin -j%__nprocs \
-C kernel-source-%kernel_version \
O=`pwd`/obj_kheaders \
ARCH=%target_kernel \
INSTALL_HDR_PATH=%buildroot%sysroot/usr \
headers_install
cd obj_binutils
%make_install install DESTDIR=%buildroot
cd ../obj_glibc
%make_install install DESTDIR=%buildroot%sysroot
cd ../obj_gcc
%make_install install DESTDIR=%buildroot
2021-06-09 13:34:52 +00:00
# relocate target libgcc_s
mv %buildroot%prefix/lib/gcc/%target/lib64/libgcc_s.so* %buildroot%prefix/lib/gcc/%target/%gcc_branch/
rmdir %buildroot%prefix/lib/gcc/%target/lib64
2021-06-09 17:08:54 +00:00
# XXX: native compiler sets /lib64/ld-linux-aarch64.so.1 as an ELF interpreter.
# Make sure cross-toolchain we build does the same thing.
%build root%prefix/bin/%target-gcc -dumpspecs > specs
sed -e " s ; / l i b / l d - l i n u x - a a r c h 6 4 ; / l i b 6 4 / l d - l i n u x - a a r c h 6 4 ; g " -i specs
install -m 644 specs %buildroot%prefix/lib/gcc/%target/%gcc_branch/specs
# XXX: ABI: which is correct location of ELF interpreter for aarch64?
# Native glibc provides ld-linux-aarch64.so.1 in both /lib64 and /lib.
# Do the same thing in cross-glibc
install -d -m 755 %buildroot%sysroot/lib
ln -s ../lib64/`basename %target_ld_linux` %buildroot%sysroot/lib/`basename %target_ld_linux`
2021-06-09 13:34:52 +00:00
2021-06-09 07:01:27 +00:00
rm -rf %buildroot%sysroot/etc
rm -rf %buildroot%sysroot/var
rm -rf %buildroot%sysroot/sbin
rm -rf %buildroot%sysroot/usr/share
rm -rf %buildroot%sysroot/usr/bin
rm -rf %buildroot%sysroot/usr/sbin
rm -rf %buildroot%sysroot/usr/libexec
rm -rf %buildroot%sysroot/usr/lib64/audit
rm -rf %buildroot%sysroot/usr/lib64/gconv
2021-06-09 13:34:52 +00:00
# XXX: gcc needs this to locate crt1.o
install -d -m 755 %buildroot%sysroot/usr/lib
2021-06-09 10:53:56 +00:00
# Leave alone $target libraries
2021-06-09 13:34:52 +00:00
%add_verify_elf_skiplist %sysroot/* %prefix/lib/gcc/%target/%gcc_branch/*
%add_findreq_skiplist %sysroot/* %prefix/lib/gcc/%target/%gcc_branch/*
%add_findprov_skiplist %sysroot/* %prefix/lib/gcc/%target/%gcc_branch/*
%add_debuginfo_skiplist %sysroot/* %prefix/lib/gcc/%target/%gcc_branch/*
2021-06-09 10:06:18 +00:00
2021-06-09 14:01:48 +00:00
%check
cat > hello.c <<EOF
#include <stdio.h>
int main(int argc, char** argv) {
printf(" H e l l o , % % s ! \n " , argc > 1 ? argv[1] : " w o r l d " );
return 0;
}
EOF
cat > hello.cpp <<EOF
#include <iostream>
int main(int argc, char** argv) {
std::cout << " H e l l o , " << (argc > 1 ? argv[1] : " w o r l d " ) << " ! " << std::endl;
return 0;
}
EOF
2021-06-09 17:09:54 +00:00
gcc_runtime_libdir=`dirname $(%buildroot%prefix/bin/%target-gcc --print-libgcc-file-name)`
2021-06-09 14:01:48 +00:00
%build root%prefix/bin/%target-gcc -o hello_c hello.c || exit 2
%build root%prefix/bin/%target-g++ -o hello_cpp hello.cpp || exit 3
2021-06-08 13:14:45 +00:00
2021-06-09 17:09:54 +00:00
# Note: LD_LIBRARY_PATH is for **target** ld.so.
# Use qemu-user-static so qemu-user is not affected by LD_LIBRARY_PATH
env LD_LIBRARY_PATH=%buildroot%sysroot/lib64:${gcc_runtime_libdir} \
qemu-%target_qemu_arch-static -L %buildroot%sysroot ./hello_c || exit 5
env LD_LIBRARY_PATH=%buildroot%sysroot/lib64:${gcc_runtime_libdir} \
qemu-%target_qemu_arch-static -L %buildroot%sysroot ./hello_cpp || exit 7
2021-06-08 13:14:45 +00:00
%files
%_bindir /*
2021-06-09 10:06:18 +00:00
%prefix /lib/gcc/%target/%gcc_branch/*
%prefix /libexec/gcc/%target/*
2021-06-08 13:14:45 +00:00
%prefix /%target/bin/*
%prefix /%target/lib/ldscripts/*
%sysroot/usr/include/*
2021-06-09 13:34:52 +00:00
%sysroot/usr/lib
2021-06-08 13:14:45 +00:00
%sysroot/lib64/*
%sysroot/usr/lib64/*
2021-06-09 17:08:54 +00:00
%sysroot/lib/*
2021-06-08 13:14:45 +00:00
%changelog
* Fri Jun 04 2021 Alexey Sheplyakov <asheplyakov@altlinux.org> 8.4.1-alt1
- Initial build