Skip to content
Snippets Groups Projects
Commit af937966 authored by NoisyCoil's avatar NoisyCoil
Browse files

Bug 41137: Separate gcc and gcc-cross

Use stretch's glibc and stretch-security's linux to maintain
compatibility with Debian stretch, add linux-aarch64 glibc patches to
avoid build failures
parent e53ab0d3
Branches
Tags
1 merge request!963Bug 41137: Build gcc-cross and tor-expert-bundle for linux-aarch64
#!/bin/sh
[% c("var/set_default_env") -%]
mkdir -p /var/tmp/build
distdir=/var/tmp/dist/[% c("var/distdir") %]
# Install native gcc
mkdir /var/tmp/dist
cd /var/tmp/dist
tar xf $rootdir/[% c('input_files_by_name/gcc-native') %]
export PATH="$distdir/bin:$PATH"
# Install cross binutils (needed for cross-compiling)
cd /var/tmp/dist
tar xf $rootdir/[% c('input_files_by_name/binutils') %]
rsync -a binutils-cross-[% c("arch") %]/* $distdir
rm -rf binutils-cross-[% c("arch") %]
# Install Linux headers, see Step 2 of
# https://preshing.com/20141119/how-to-build-a-gcc-cross-compiler/
# Doing this before gcc configure is intended to solve a limits.h issue
cd /var/tmp/build
mkdir linux
cd linux
tar -xJf $rootdir/linux-[% c("var/linux_version") %].tar.xz
cd linux-[% c("var/linux_version") %]
make ARCH=[% IF c("arch") == "aarch64" %]arm64[% ELSE %][% c("arch") %][% END %] INSTALL_HDR_PATH=$distdir/[% c("var/crosstarget") %] headers_install
cd /var/tmp/build
mkdir gcc-cross
cd gcc-cross
tar -xJf $rootdir/[% c('input_files_by_name/gcc') %]
cd gcc-[% c("version") %]
patch -p1 <$rootdir/gcc-cross.patch
cd /var/tmp/build/gcc-cross
gcc-[% c("version") %]/configure --prefix=$distdir --includedir=$distdir/[% c("var/crosstarget") %]/include [% c("var/configure_opt") %]
# For cross-compiling to work, we need to partially build GCC, then build
# glibc, then come back to finish GCC.
# Build only the components of GCC that don't need glibc, see Step 3 of
# https://preshing.com/20141119/how-to-build-a-gcc-cross-compiler/
cd /var/tmp/build/gcc-cross
make -j[% c("num_procs") %] all-gcc
make install-gcc
# Build glibc headers and startup files, see Step 4 of
# https://preshing.com/20141119/how-to-build-a-gcc-cross-compiler/
cd /var/tmp/build
mkdir glibc
cd glibc
tar -xJf $rootdir/glibc-[% c("var/glibc_version") %].tar.xz
[% IF c("var/linux-aarch64") -%]
# Avoid linking issues by backporting glibc patches
cd glibc-[% c("var/glibc_version") %]
patch -p1 <$rootdir/glibc-cross-linux-aarch64.patch
patch -p1 <$rootdir/glibc-cross-linux-aarch64-2.patch
cd /var/tmp/build/glibc
[% END -%]
# TODO: Remove --disable-werror once glibc is upgraded to a version that's
# designed to work with the GCC version we're using.
glibc-[% c("var/glibc_version") %]/configure --prefix=$distdir/[% c("var/crosstarget") %] --build=$MACHTYPE --host=[% c("var/crosstarget") %] --target=[% c("var/crosstarget") %] --with-headers=$distdir/[% c("var/crosstarget") %]/include --disable-multilib --disable-werror libc_cv_forced_unwind=yes
make install-bootstrap-headers=yes install-headers
make -j[% c("num_procs") %] csu/subdir_lib
install csu/crt1.o csu/crti.o csu/crtn.o $distdir/[% c("var/crosstarget") %]/lib
[% c("var/crosstarget") %]-gcc -nostdlib -nostartfiles -shared -x c /dev/null -o $distdir/[% c("var/crosstarget") %]/lib/libc.so
# stdio_lim.h is intended to solve a limits.h issue
touch $distdir/[% c("var/crosstarget") %]/include/gnu/stubs.h $distdir/[% c("var/crosstarget") %]/include/bits/stdio_lim.h
# Build compiler support library, see Step 5 of
# https://preshing.com/20141119/how-to-build-a-gcc-cross-compiler/
cd /var/tmp/build/gcc-cross
make -j[% c("num_procs") %] all-target-libgcc
make install-target-libgcc
# finish building glibc, see Step 6 of
# https://preshing.com/20141119/how-to-build-a-gcc-cross-compiler/
cd /var/tmp/build/glibc
make -j[% c("num_procs") %]
make install
# We're done with glibc, we can now finish building gcc...
cd /var/tmp/build/gcc-cross
make -j[% c("num_procs") %]
make install
# Include a working version of limits.h
cd gcc-[% c("version") %]
cat gcc/limitx.h gcc/glimits.h gcc/limity.h >$distdir/lib/gcc/[% c("var/crosstarget") %]/[% c("version") %]/include/limits.h
cd /var/tmp/dist
[% c('tar', {
tar_src => [ c('var/distdir') ],
tar_args => '-caf ' _ dest_dir _ '/' _ c('filename'),
}) %]
# vim: filetype=yaml sw=2
filename: '[% project %]-[% c("version") %]-[% c("arch") %]-[% c("var/build_id") %].tar.[% c("compress_tar") %]'
# Note: When updating the gcc version, if this includes a libstdc++
# ABI change we should also update projects/firefox/abicheck.cc to
# require the new version.
version: '[% pc("gcc-source", "version") %]'
container:
use_container: 1
hardened_gcc: 1
var:
distdir: gcc
deps:
- build-essential
- libmpc-dev
setup: |
mkdir -p /var/tmp/dist
tar -C /var/tmp/dist -xf $rootdir/[% c("compiler_tarfile") %]
export PATH="/var/tmp/dist/[% c("var/distdir") %]/bin:$PATH"
export LD_LIBRARY_PATH=/var/tmp/dist/[% c("var/distdir") %]/lib64:/var/tmp/dist/[% c("var/distdir") %]/lib32
[% IF c("hardened_gcc"); GET c("var/set_hardened_build_flags"); END %]
configure_opt: '--target=[% c("var/crosstarget") %] --disable-multilib --enable-languages=c,c++ --with-glibc-version=[% c("var/glibc_version") %]'
# Use stretch's glibc and stretch-security's linux
glibc_version: 2.24
linux_version: 4.19.232
arch_deps:
- libc6-dev-i386
- gawk
- rsync
targets:
linux-arm:
var:
configure_opt: '--target=[% c("var/crosstarget") %] --disable-multilib --enable-languages=c,c++ --with-glibc-version=[% c("var/glibc_version") %] --with-arch=armv7-a --with-fpu=vfpv3-d16 --with-float=hard --with-mode=thumb'
input_files:
- project: container-image
- project: gcc-source
name: gcc
- name: binutils
project: binutils
target_prepend:
- linux-cross
- name: gcc-native
project: gcc
- URL: 'https://ftp.gnu.org/gnu/glibc/glibc-[% c("var/glibc_version") %].tar.xz'
sha256sum: 99d4a3e8efd144d71488e478f62587578c0f4e1fa0b4eed47ee3d4975ebeb5d3
- URL: 'https://www.kernel.org/pub/linux/kernel/v4.x/linux-[% c("var/linux_version") %].tar.xz'
sha256sum: 4fcfe814780d63dc56e907bf41596ff162e9601978bdc1a60eab64cc3903a22c
- filename: 'gcc-cross.patch'
- filename: 'glibc-cross-linux-aarch64.patch'
enable: '[% c("var/linux-aarch64") -%]'
- filename: 'glibc-cross-linux-aarch64-2.patch'
enable: '[% c("var/linux-aarch64") -%]'
Avoids "../../../gcc-10.3.0/libsanitizer/asan/asan_linux.cpp:217:21: error:
'PATH_MAX' was not declared in this scope". PATH_MAX is in /include/linux/limits.h,
which is usually included by /include/limits.h (indirectly, through posix headers,
etc.). For some reason, when cross-compiling, this inclusion chain is broken and
we must include <linux/limits.h> by hand.
Index: gcc-10.3.0/libsanitizer/asan/asan_linux.cpp
===================================================================
--- gcc-10.3.0.orig/libsanitizer/asan/asan_linux.cpp
+++ gcc-10.3.0/libsanitizer/asan/asan_linux.cpp
@@ -32,6 +32,7 @@
#include <dlfcn.h>
#include <fcntl.h>
#include <limits.h>
+#include <linux/limits.h>
#include <pthread.h>
#include <stdio.h>
#include <unistd.h>
From e9177fba13549a8e2a6232f46080e5c6d3e467b1 Mon Sep 17 00:00:00 2001
From: Szabolcs Nagy <szabolcs.nagy@arm.com>
Date: Wed, 21 Jun 2017 13:47:07 +0100
Subject: [PATCH] [AArch64] Use hidden __GI__dl_argv in rtld startup code
We rely on the symbol being locally defined so using extern symbol
is not correct and the linker may complain about the relocations.
---
ChangeLog | 5 +++++
sysdeps/aarch64/dl-machine.h | 4 ++--
2 files changed, 7 insertions(+), 2 deletions(-)
Index: glibc/sysdeps/aarch64/dl-machine.h
===================================================================
--- glibc.orig/sysdeps/aarch64/dl-machine.h
+++ glibc/sysdeps/aarch64/dl-machine.h
@@ -172,8 +172,8 @@ _dl_start_user: \n\
cmp x0, #0 \n\
bne 1b \n\
// Update _dl_argv \n\
- adrp x3, _dl_argv \n\
- str x2, [x3, #:lo12:_dl_argv] \n\
+ adrp x3, __GI__dl_argv \n\
+ str x2, [x3, #:lo12:__GI__dl_argv] \n\
.L_done_stack_adjust: \n\
// compute envp \n\
add x3, x2, x1, lsl #3 \n\
--
2.43.2
From a68ba2f3cd3cbe32c1f31e13c20ed13487727b32 Mon Sep 17 00:00:00 2001
From: Szabolcs Nagy <szabolcs.nagy@arm.com>
Date: Wed, 18 Oct 2017 17:26:23 +0100
Subject: [PATCH] [AARCH64] Rewrite elf_machine_load_address using _DYNAMIC
symbol
This patch rewrites aarch64 elf_machine_load_address to use special _DYNAMIC
symbol instead of _dl_start.
The static address of _DYNAMIC symbol is stored in the first GOT entry.
Here is the change which makes this solution work (part of binutils 2.24):
https://sourceware.org/ml/binutils/2013-06/msg00248.html
i386, x86_64 targets use the same method to do this as well.
The original implementation relies on a trick that R_AARCH64_ABS32 relocation
being resolved at link time and the static address fits in the 32bits.
However, in LP64, normally, the address is defined to be 64 bit.
Here is the C version one which should be portable in all cases.
* sysdeps/aarch64/dl-machine.h (elf_machine_load_address): Use
_DYNAMIC symbol to calculate load address.
---
ChangeLog | 5 +++++
sysdeps/aarch64/dl-machine.h | 39 +++++-------------------------------
2 files changed, 10 insertions(+), 34 deletions(-)
Index: glibc-2.26/sysdeps/aarch64/dl-machine.h
===================================================================
--- glibc-2.26.orig/sysdeps/aarch64/dl-machine.h
+++ glibc-2.26/sysdeps/aarch64/dl-machine.h
@@ -51,26 +51,11 @@ elf_machine_load_address (void)
/* To figure out the load address we use the definition that for any symbol:
dynamic_addr(symbol) = static_addr(symbol) + load_addr
- The choice of symbol is arbitrary. The static address we obtain
- by constructing a non GOT reference to the symbol, the dynamic
- address of the symbol we compute using adrp/add to compute the
- symbol's address relative to the PC.
- This depends on 32bit relocations being resolved at link time
- and that the static address fits in the 32bits. */
+ _DYNAMIC sysmbol is used here as its link-time address stored in
+ the special unrelocated first GOT entry. */
- ElfW(Addr) static_addr;
- ElfW(Addr) dynamic_addr;
-
- asm (" \n"
-" adrp %1, _dl_start; \n"
-" add %1, %1, #:lo12:_dl_start \n"
-" ldr %w0, 1f \n"
-" b 2f \n"
-"1: \n"
-" .word _dl_start \n"
-"2: \n"
- : "=r" (static_addr), "=r" (dynamic_addr));
- return dynamic_addr - static_addr;
+ extern ElfW(Dyn) _DYNAMIC[] attribute_hidden;
+ return (ElfW(Addr)) &_DYNAMIC - elf_machine_dynamic ();
}
/* Set up the loaded object described by L so its unrelocated PLT
#!/bin/sh
[% c("var/set_default_env") -%]
mkdir -p /var/tmp/build
[% IF c("var/linux") && ! c("var/linux-cross") -%]
[% IF c("var/linux") -%]
# Config options for hardening
export DEB_BUILD_HARDENING=1
# Since r223796 landed on GCC master enforcing PIE breaks GCC compilation.
......@@ -19,82 +20,10 @@ mkdir -p /var/tmp/build
[% END -%]
distdir=/var/tmp/dist/[% c("var/distdir") %]
[% IF c("var/linux-cross") -%]
# Install binutils (needed for cross-compiling)
mkdir /var/tmp/dist
cd /var/tmp/dist
tar xf $rootdir/[% c('input_files_by_name/binutils') %]
mv binutils $distdir
export PATH="$distdir/bin:$PATH"
# Install Linux headers, see Step 2 of
# https://preshing.com/20141119/how-to-build-a-gcc-cross-compiler/
# Doing this before gcc configure is intended to solve a limits.h issue
cd /var/tmp/build
mkdir linux
cd linux
tar -xJf $rootdir/linux-[% c("var/linux_version") %].tar.xz
cd linux-[% c("var/linux_version") %]
make ARCH=[% c("arch") %] INSTALL_HDR_PATH=$distdir/[% c("var/crosstarget") %] headers_install
cd /var/tmp/build
mkdir gcc
cd gcc
tar -xJf $rootdir/[% c('input_files_by_name/gcc') %]
# --with-headers is intended to solve a limits.h issue
[% project %]-[% c("version") %]/configure --prefix=$distdir --with-headers=$distdir/[% c("var/crosstarget") %]/include/linux [% c("var/configure_opt") %]
# For cross-compiling to work, we need to partially build GCC, then build
# glibc, then come back to finish GCC.
# Build only the components of GCC that don't need glibc, see Step 3 of
# https://preshing.com/20141119/how-to-build-a-gcc-cross-compiler/
cd /var/tmp/build/gcc
make -j[% c("num_procs") %] all-gcc
make install-gcc
# Removing sys-include is intended to solve a limits.h issue
rm --recursive --force $distdir/[% c("var/crosstarget") %]/sys-include
# Build glibc headers and startup files, see Step 4 of
# https://preshing.com/20141119/how-to-build-a-gcc-cross-compiler/
cd /var/tmp/build
mkdir glibc
cd glibc
tar -xJf $rootdir/glibc-[% c("var/glibc_version") %].tar.xz
# TODO: Remove --disable-werror once glibc is upgraded to a version that's
# designed to work with the GCC version we're using.
glibc-[% c("var/glibc_version") %]/configure --prefix=$distdir/[% c("var/crosstarget") %] --build=$MACHTYPE --host=[% c("var/crosstarget") %] --target=[% c("var/crosstarget") %] --with-headers=$distdir/[% c("var/crosstarget") %]/include --disable-multilib --disable-werror libc_cv_forced_unwind=yes
make install-bootstrap-headers=yes install-headers
make -j[% c("num_procs") %] csu/subdir_lib
install csu/crt1.o csu/crti.o csu/crtn.o $distdir/[% c("var/crosstarget") %]/lib
[% c("var/crosstarget") %]-gcc -nostdlib -nostartfiles -shared -x c /dev/null -o $distdir/[% c("var/crosstarget") %]/lib/libc.so
# stdio_lim.h is intended to solve a limits.h issue
touch $distdir/[% c("var/crosstarget") %]/include/gnu/stubs.h $distdir/[% c("var/crosstarget") %]/include/bits/stdio_lim.h
# Build compiler support library, see Step 5 of
# https://preshing.com/20141119/how-to-build-a-gcc-cross-compiler/
cd /var/tmp/build/gcc
make -j[% c("num_procs") %] all-target-libgcc
make install-target-libgcc
# finish building glibc, see Step 6 of
# https://preshing.com/20141119/how-to-build-a-gcc-cross-compiler/
cd /var/tmp/build/glibc
make -j[% c("num_procs") %]
make install
# We're done with glibc, we can now finish building gcc...
cd /var/tmp/build/gcc
[% ELSE -%]
tar -C /var/tmp/build -xf $rootdir/[% c('input_files_by_name/gcc') %]
cd /var/tmp/build/[% project %]-[% c("version") %]
./configure --prefix=$distdir [% c("var/configure_opt") %]
[% END -%]
make -j[% c("num_procs") %]
make install
# tor-browser-build#31321: we need a link to our GCC, to prevent some projects
......
......
# vim: filetype=yaml sw=2
filename: '[% project %]-[% c("version") %]-[% IF c("var/linux-cross") %][% c("var/osname") %][% ELSE %]x86[% END %]-[% c("var/build_id") %].tar.[% c("compress_tar") %]'
filename: '[% project %]-[% c("version") %]-[% c("var/build_id") %].tar.[% c("compress_tar") %]'
# Note: When updating the gcc version, if this includes a libstdc++
# ABI change we should also update projects/firefox/abicheck.cc to
# require the new version.
......@@ -7,6 +7,7 @@ version: '[% pc("gcc-source", "version") %]'
container:
use_container: 1
var:
no_crosscompile: 1
distdir: gcc
deps:
- build-essential
......@@ -15,9 +16,7 @@ var:
mkdir -p /var/tmp/dist
tar -C /var/tmp/dist -xf $rootdir/[% c("compiler_tarfile") %]
export PATH="/var/tmp/dist/[% c("var/distdir") %]/bin:$PATH"
[% IF ! c("var/linux-cross") -%]
export LD_LIBRARY_PATH=/var/tmp/dist/[% c("var/distdir") %]/lib64:/var/tmp/dist/[% c("var/distdir") %]/lib32
[% END -%]
[% IF c("hardened_gcc"); GET c("var/set_hardened_build_flags"); END %]
targets:
......@@ -33,33 +32,8 @@ targets:
configure_opt: --enable-multilib --enable-languages=c,c++ --with-arch_32=i686
arch_deps:
- libc6-dev-i386
linux-cross:
var:
target_prefix: '[% c("var/crosstarget") %]-'
distdir: gcc-cross
# TODO: Consider upgrading to a glibc that works out of the box with the
# GCC version we use. However, removing our glibc version workarounds may
# not be desirable since we want to be able to easily bump the GCC
# version without worrying about linux-cross breakage.
glibc_version: 2.26
linux_version: 4.10.1
arch_deps:
- libc6-dev-i386
- gawk
linux-arm:
var:
configure_opt: --disable-multilib --enable-languages=c,c++ --target=arm-linux-gnueabihf --with-arch=armv7-a --with-fpu=vfpv3-d16 --with-float=hard --with-mode=thumb
input_files:
- project: container-image
- project: gcc-source
name: gcc
- name: binutils
project: binutils
enable: '[% c("var/linux-cross") -%]'
- URL: 'https://ftp.gnu.org/gnu/glibc/glibc-[% c("var/glibc_version") %].tar.xz'
sha256sum: e54e0a934cd2bc94429be79da5e9385898d2306b9eaf3c92d5a77af96190f6bd
enable: '[% c("var/linux-cross") -%]'
- URL: 'https://www.kernel.org/pub/linux/kernel/v4.x/linux-[% c("var/linux_version") %].tar.xz'
sha256sum: 6ca06bb5faf5f83600d7388bb623dae41df2a257de85ad5d1792e03302bc3543
enable: '[% c("var/linux-cross") -%]'
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please to comment