Skip to content

Commit

Permalink
Merge remote-tracking branch 'upstream/master'
Browse files Browse the repository at this point in the history
  • Loading branch information
kdrag0n committed Nov 9, 2019
2 parents 6f8d1a9 + 439c648 commit fc605e8
Show file tree
Hide file tree
Showing 11 changed files with 745 additions and 798 deletions.
8 changes: 4 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,24 +19,24 @@ These scripts have been tested in a Docker image of the following distributions,
* ### Debian/Ubuntu

```
apt install ca-certificates ccache clang cmake curl file gcc g++ git make ninja-build python3 texinfo zlib1g-dev
apt install bison ca-certificates ccache clang cmake curl file flex gcc g++ git make ninja-build python3 texinfo zlib1g-dev
```

On Debian Buster or Ubuntu Bionic/Cosmic/Disco, `apt install lld` should be added as well for faster compiles.

* ### Fedora

```
dnf install ccache clang cmake gcc gcc-c++ git lld make ninja-build python3 zlib-devel
dnf install bison ccache clang cmake flex gcc gcc-c++ git lld make ninja-build python3 zlib-devel
```

* ### Arch Linux

```
pacman -S base-devel ccache clang cmake git lld ninja python3
pacman -S base-devel bison ccache clang cmake flex git lld ninja python3
```

If you intend to compile with PGO, please ensure that you also have `bc`, `bison`,`flex`, and `libssl-dev` (or equivalent) installed as you will be building some Linux kernels. If you are building for PowerPC (which the script does by default), make sure `mkimage` is available as well; the package is `u-boot-tools` on Debian/Ubuntu.
If you intend to compile with PGO, please ensure that you also have `bc` and `libssl-dev` (or equivalent) installed as you will be building some Linux kernels. If you are building for PowerPC (which the script does by default), make sure `mkimage` is available as well; the package is `u-boot-tools` on Debian/Ubuntu.

Python 3.5.3+ is recommended, as that is what the script has been tested against. These scripts should be distribution agnostic. Please feel free to add different distribution install commands here through a pull request.

Expand Down
18 changes: 13 additions & 5 deletions build-binutils.py
Original file line number Diff line number Diff line change
Expand Up @@ -91,8 +91,7 @@ def parse_parameters(root_folder):
Add -march=ARCH and -mtune=ARCH to CFLAGS to optimize the toolchain for the target
host processor.
""",
type=str,
default="native")
type=str)
return parser.parse_args()


Expand Down Expand Up @@ -148,10 +147,19 @@ def invoke_configure(build_folder, install_folder, root_folder, target,
configure = [
root_folder.joinpath(utils.current_binutils(), "configure").as_posix(),
'--prefix=%s' % install_folder.as_posix(),
'--enable-deterministic-archives', '--enable-plugins', '--quiet',
'CFLAGS=-O2 -march=%s -mtune=%s' % (host_arch, host_arch),
'CXXFLAGS=-O2 -march=%s -mtune=%s' % (host_arch, host_arch)
'--enable-deterministic-archives', '--enable-plugins', '--quiet'
]
if host_arch:
configure += [
'CFLAGS=-O2 -march=%s -mtune=%s' % (host_arch, host_arch),
'CXXFLAGS=-O2 -march=%s -mtune=%s' % (host_arch, host_arch)
]
else:
configure += [
'CFLAGS=-O2',
'CXXFLAGS=-O2'
]

configure_arch_flags = {
"arm-linux-gnueabi": [
'--disable-multilib', '--disable-nls', '--with-gnu-as',
Expand Down
25 changes: 12 additions & 13 deletions build-llvm.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@

# This is a known good revision of LLVM for building the kernel
# To bump this, run 'PATH_OVERRIDE=<path_to_updated_toolchain>/bin kernel/build.sh --allyesconfig'
GOOD_REVISION = '9aeab53eba0a63829a7f6f8ba878a257530a2dd7'
GOOD_REVISION = '957b9cdd2692178b9635cbbbcb94e78a5bc24473'


class Directories:
Expand Down Expand Up @@ -392,39 +392,38 @@ def fetch_llvm_binutils(root_folder, update, ref, shallow=False):
:param ref: The ref to checkout the monorepo to
"""
p = root_folder.joinpath("llvm-project")
cwd = p.as_posix()
if p.is_dir():
if update:
utils.print_header("Updating LLVM")
subprocess.run(
["git", "-C", p.as_posix(), "fetch", "origin"], check=True)
subprocess.run(
["git", "-C", p.as_posix(), "checkout", ref], check=True)
subprocess.run(["git", "fetch", "origin"], check=True, cwd=cwd)
subprocess.run(["git", "checkout", ref], check=True, cwd=cwd)
local_ref = None
try:
local_ref = subprocess.check_output(
["git", "-C",
p.as_posix(), "symbolic-ref", "-q",
"HEAD"]).decode("utf-8")
["git", "symbolic-ref", "-q", "HEAD"],
cwd=cwd).decode("utf-8")
except subprocess.CalledProcessError:
# This is thrown when we're on a revision that cannot be mapped to a symbolic reference, like a tag
# or a git hash. Swallow and move on with the rest of our business.
pass
if local_ref and local_ref.startswith("refs/heads/"):
# This is a branch, pull from remote
subprocess.run([
"git", "-C",
p.as_posix(), "pull", "origin",
local_ref.strip().replace("refs/heads/", ""), "--rebase"
"git", "pull", "--rebase", "origin",
local_ref.strip().replace("refs/heads/", "")
],
check=True)
check=True,
cwd=cwd)
else:
extra_args = ("--depth", "1") if shallow else ()
utils.print_header("Downloading LLVM")
subprocess.run([
"git", "clone", "-b", ref, *extra_args, "git://github.com/llvm/llvm-project",
"git", "clone", *extra_args, "git://github.com/llvm/llvm-project",
p.as_posix()
],
check=True)
subprocess.run(["git", "checkout", ref], check=True, cwd=cwd)

# One might wonder why we are downloading binutils in an LLVM build script :)
# We need it for the LLVMgold plugin, which can be used for LTO with ld.gold,
Expand Down
20 changes: 12 additions & 8 deletions kernel/build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -26,14 +26,15 @@ while (( ${#} )); do
case ${LLVM_TARGET} in
"AArch64") TARGETS=( "${TARGETS[@]}" "aarch64-linux-gnu" ) ;;
"ARM") TARGETS=( "${TARGETS[@]}" "arm-linux-gnueabi" ) ;;
"PowerPC") TARGETS=( "${TARGETS[@]}" "powerpc-linux-gnu" "powerpc64le-linux-gnu" ) ;;
"PowerPC") TARGETS=( "${TARGETS[@]}" "powerpc-linux-gnu" "powerpc64-linux-gnu" "powerpc64le-linux-gnu" ) ;;
"X86") TARGETS=( "${TARGETS[@]}" "x86_64-linux-gnu" ) ;;
esac
done
esac
shift
done
[[ -z ${TARGETS[*]} ]] && TARGETS=( "arm-linux-gnueabi" "aarch64-linux-gnu" "powerpc-linux-gnu" "powerpc64le-linux-gnu" "x86_64-linux-gnu" )
[[ -z ${TARGETS[*]} ]] && TARGETS=( "arm-linux-gnueabi" "aarch64-linux-gnu" "powerpc-linux-gnu" "powerpc64-linux-gnu" "powerpc64le-linux-gnu" "x86_64-linux-gnu" )
[[ -z ${CONFIG_TARGET} ]] && CONFIG_TARGET=defconfig

# Add the default install bin folder to PATH for binutils
# Add the stage 2 bin folder to PATH for the instrumented clang
Expand All @@ -48,9 +49,9 @@ done
if [[ -n ${SRC_FOLDER} ]]; then
cd "${SRC_FOLDER}" || exit 1
else
LINUX=linux-5.2
LINUX=linux-5.3
LINUX_TARBALL=${TC_BLD}/kernel/${LINUX}.tar.xz
LINUX_PATCH=${TC_BLD}/kernel/${LINUX}-${CONFIG_TARGET:=defconfig}.patch
LINUX_PATCH=${TC_BLD}/kernel/${LINUX}-${CONFIG_TARGET}.patch

# If we don't have the source tarball, download and verify it
if [[ ! -f ${LINUX_TARBALL} ]]; then
Expand All @@ -66,7 +67,7 @@ else
[[ -f ${LINUX_PATCH} ]] && rm -rf ${LINUX}
[[ -d ${LINUX} ]] || { tar -xf "${LINUX_TARBALL}" || exit ${?}; }
cd ${LINUX} || exit 1
[[ -f ${LINUX_PATCH} ]] && { git apply "${LINUX_PATCH}" || exit ${?}; }
[[ -f ${LINUX_PATCH} ]] && { patch -p1 < "${LINUX_PATCH}" || exit ${?}; }
fi

# Check for all binutils and build them if necessary
Expand All @@ -84,13 +85,16 @@ done

# SC2191: The = here is literal. To assign by index, use ( [index]=value ) with no spaces. To keep as literal, quote it.
# shellcheck disable=SC2191
MAKE=( make -j"$(nproc)" CC=clang O=out )
MAKE=( make -j"$(nproc)" -s CC=clang O=out )

set -x

for TARGET in "${TARGETS[@]}"; do
case ${TARGET} in
"arm-linux-gnueabi") time "${MAKE[@]}" ARCH=arm CROSS_COMPILE="${TARGET}-" LD=ld.lld distclean "${CONFIG_TARGET}" zImage modules || exit ${?} ;;
"aarch64-linux-gnu") time "${MAKE[@]}" ARCH=arm64 CROSS_COMPILE="${TARGET}-" LD=ld.lld distclean "${CONFIG_TARGET}" Image.gz modules || exit ${?} ;;
"arm-linux-gnueabi") time "${MAKE[@]}" ARCH=arm CROSS_COMPILE="${TARGET}-" KCONFIG_ALLCONFIG=${TC_BLD}/kernel/le.config LD=ld.lld distclean "${CONFIG_TARGET}" zImage modules || exit ${?} ;;
"aarch64-linux-gnu") time "${MAKE[@]}" ARCH=arm64 CROSS_COMPILE="${TARGET}-" KCONFIG_ALLCONFIG=${TC_BLD}/kernel/le.config LD=ld.lld distclean "${CONFIG_TARGET}" Image.gz modules || exit ${?} ;;
"powerpc-linux-gnu") time "${MAKE[@]}" ARCH=powerpc CROSS_COMPILE="${TARGET}-" distclean ppc44x_defconfig zImage modules || exit ${?} ;;
"powerpc64-linux-gnu") time "${MAKE[@]}" ARCH=powerpc CROSS_COMPILE="${TARGET}-" distclean pseries_defconfig vmlinux modules || exit ${?} ;;
"powerpc64le-linux-gnu") time "${MAKE[@]}" ARCH=powerpc CROSS_COMPILE="${TARGET}-" distclean powernv_defconfig zImage.epapr modules || exit ${?} ;;
"x86_64-linux-gnu") time "${MAKE[@]}" LD=ld.lld O=out distclean "${CONFIG_TARGET}" bzImage modules || exit ${?} ;;
esac
Expand Down
1 change: 1 addition & 0 deletions kernel/le.config
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
CONFIG_CPU_BIG_ENDIAN=n
Loading

0 comments on commit fc605e8

Please sign in to comment.