From bb93dcef44a29c3f396f1176f6e22ecfad40d442 Mon Sep 17 00:00:00 2001 From: "Justin C. Miller" Date: Fri, 5 Jul 2019 17:26:24 -0700 Subject: [PATCH] Remove sysroot binutils dependency * Link host-targeted binaries with lld * Add peru script for getting prebuilt sysroot * Add readme for prebuilt sysroots * Remove non-working build_sysroot_gcc.sh, rename clang version to just build_sysroot.sh --- peru.yaml | 7 + ...uild_sysroot_clang.sh => build_sysroot.sh} | 40 +--- scripts/build_sysroot_gcc.sh | 186 ------------------ scripts/readme_for_prebuilt_sysroots.md | 47 +++++ scripts/templates/target.host.j2 | 5 +- scripts/templates/target.user.j2 | 7 +- src/arch/x86_64/kernel.ld | 17 +- 7 files changed, 72 insertions(+), 237 deletions(-) create mode 100644 peru.yaml rename scripts/{build_sysroot_clang.sh => build_sysroot.sh} (84%) delete mode 100755 scripts/build_sysroot_gcc.sh create mode 100644 scripts/readme_for_prebuilt_sysroots.md diff --git a/peru.yaml b/peru.yaml new file mode 100644 index 0000000..f5452d8 --- /dev/null +++ b/peru.yaml @@ -0,0 +1,7 @@ +imports: + sysroot: ./sysroot + +curl module sysroot: + url: https://f000.backblazeb2.com/file/jsix-os/sysroot-llvm8-20190705.tar.bz2 + unpack: tar + export: sysroot/ diff --git a/scripts/build_sysroot_clang.sh b/scripts/build_sysroot.sh similarity index 84% rename from scripts/build_sysroot_clang.sh rename to scripts/build_sysroot.sh index b3f4057..6d62a90 100755 --- a/scripts/build_sysroot_clang.sh +++ b/scripts/build_sysroot.sh @@ -2,15 +2,15 @@ TARGET="x86_64-elf" NASM_VERSION="2.13.03" -BINUTILS_VERSION="2.31.1" LLVM_BRANCH="release_80" -TOOLS="clang" # lld libunwind libcxxabi libcxx" +TOOLS="clang lld" # lld libunwind libcxxabi libcxx" PROJECTS="compiler-rt libcxxabi libcxx libunwind" #RUNTIMES="compiler-rt libcxxabi libcxx libunwind" set -e +README=$(realpath "$(dirname $0)/readme_for_prebuilt_sysroots.md") SYSROOT=$(realpath "$(dirname $0)/../sysroot") WORK=$(realpath "$(dirname $0)/sysroot") mkdir -p "${SYSROOT}" @@ -45,35 +45,6 @@ function build_nasm() { popd } -function build_binutils() { - if [[ ! -d "${WORK}/binutils-${BINUTILS_VERSION}" ]]; then - echo "Downloading binutils..." - tarball="binutils-${BINUTILS_VERSION}.tar.gz" - curl -sSOL "https://ftp.gnu.org/gnu/binutils/${tarball}" - tar xzf "${tarball}" -C "${WORK}" && rm "${tarball}" - fi - - mkdir -p "${WORK}/build/binutils" - pushd "${WORK}/build/binutils" - - if [[ ! -f "${WORK}/build/binutils/config.cache" ]]; then - echo "Configuring binutils..." - "${WORK}/binutils-${BINUTILS_VERSION}/configure" \ - --quiet \ - --config-cache \ - --target="${TARGET}" \ - --prefix="${SYSROOT}" \ - --with-sysroot="${SYSROOT}" \ - --with-lib-path="${SYSROOT}/lib" \ - --disable-nls \ - --disable-werror - fi - - echo "Building binutils..." - (make -j && make install) > "${WORK}/build/binutils_build.log" - popd -} - function build_llvm() { if [[ ! -d "${WORK}/llvm" ]]; then echo "Downloading LLVM..." @@ -160,6 +131,7 @@ function build_llvm() { -DLLVM_CONFIG_PATH="${SYSROOT}/bin/llvm-config" \ -DLLVM_DEFAULT_TARGET_TRIPLE="x86_64-unknown-elf" \ -DLLVM_ENABLE_LIBCXX=ON \ + -DLLVM_ENABLE_LLD=ON \ -DLLVM_ENABLE_PIC=OFF \ -DLLVM_ENABLE_THREADS=OFF \ -DLLVM_INSTALL_BINUTILS_SYMLINKS=ON \ @@ -173,7 +145,6 @@ function build_llvm() { # -DLIBCXX_ENABLE_STATIC_UNWINDER=ON \ # -DLIBCXXABI_ENABLE_LLD=ON \ # -DLIBUNWIND_ENABLE_LLD=ON \ - # -DLLVM_ENABLE_LLD=ON \ # -DLLVM_ENABLE_PROJECTS="libcxx;libcxxabi;libunwind;compiler-rt" \ # -DCOMPILER_RT_BAREMETAL_BUILD=ON \ # -DLIBCXXABI_BAREMETAL=ON \ @@ -198,7 +169,7 @@ function build_libc() { pushd "${WORK}/poplibc" echo "Building poplibc..." - make install PREFIX="${SYSROOT}" + pb prefix="${SYSROOT}" && ninja -C build install popd } @@ -210,7 +181,6 @@ function update_links() { } build_nasm -build_binutils build_libc build_llvm update_links @@ -219,3 +189,5 @@ export CC="${SYSROOT}/bin/clang" export CXX="${SYSROOT}/bin/clang++" export LD="${SYSROOT}/bin/ld" build_libc + +cp "${README}" "${SYSROOT}/README.md" diff --git a/scripts/build_sysroot_gcc.sh b/scripts/build_sysroot_gcc.sh deleted file mode 100755 index bfd4db3..0000000 --- a/scripts/build_sysroot_gcc.sh +++ /dev/null @@ -1,186 +0,0 @@ -#!/usr/bin/env bash - -TARGET="x86_64-elf" -NASM_VERSION="2.14.02" -GCC_VERSION="7.4.0" -BINUTILS_VERSION="2.31.1" - -SYSROOT=$(realpath "$(dirname $0)/../sysroot") -WORK=$(realpath "$(dirname $0)/sysroot") - -echo "Not currently supported" -exit 1 - -set -e -mkdir -p "${SYSROOT}" -mkdir -p "${WORK}" - - -function build_nasm() { - if [[ ! -d "${WORK}/nasm-${NASM_VERSION}" ]]; then - echo "Downloading NASM..." - tarball="nasm-${NASM_VERSION}.tar.gz" - curl -sSOL "https://www.nasm.us/pub/nasm/releasebuilds/${NASM_VERSION}/${tarball}" - tar xzf "${tarball}" -C "${WORK}" && rm "${tarball}" - fi - - mkdir -p "${WORK}/build/nasm" - pushd "${WORK}/build/nasm" - - if [[ ! -f "${WORK}/build/nasm/config.cache" ]]; then - echo "Configuring NASM..." - "${WORK}/nasm-${NASM_VERSION}/configure" \ - --quiet \ - --config-cache \ - --disable-werror \ - --prefix="${SYSROOT}" \ - --srcdir="${WORK}/nasm-${NASM_VERSION}" - fi - - echo "Building NASM..." - (make -j && make install) > "${WORK}/build/nasm_build.log" - popd -} - -function build_binutils() { - if [[ ! -d "${WORK}/binutils-${BINUTILS_VERSION}" ]]; then - echo "Downloading binutils..." - tarball="binutils-${BINUTILS_VERSION}.tar.gz" - curl -sSOL "https://ftp.gnu.org/gnu/binutils/${tarball}" - tar xzf "${tarball}" -C "${WORK}" && rm "${tarball}" - fi - - mkdir -p "${WORK}/build/binutils" - pushd "${WORK}/build/binutils" - - if [[ ! -f "${WORK}/build/binutils/config.cache" ]]; then - echo "Configuring binutils..." - "${WORK}/binutils-${BINUTILS_VERSION}/configure" \ - --quiet \ - --config-cache \ - --target="${TARGET}" \ - --prefix="${SYSROOT}" \ - --with-sysroot="${SYSROOT}" \ - --with-lib-path="${SYSROOT}/lib" \ - --disable-nls \ - --disable-werror - fi - - echo "Building binutils..." - (make -j && make install) > "${WORK}/build/binutils_build.log" - popd -} - -function build_gcc() { - if [[ ! -d "${WORK}/gcc-${GCC_VERSION}" ]]; then - echo "Downloading GCC..." - tarball="gcc-${GCC_VERSION}.tar.gz" - curl -sSOL "https://ftp.gnu.org/gnu/gcc/gcc-${GCC_VERSION}/${tarball}" - tar xzf "${tarball}" -C "${WORK}" && rm "${tarball}" - - # no-red-zone support version of libgcc - echo "MULTILIB_OPTIONS += mno-red-zone" > "${WORK}/gcc-${GCC_VERSION}/gcc/config/i386/t-${TARGET}" - echo "MULTILIB_DIRNAMES += no-red-zone" >> "${WORK}/gcc-${GCC_VERSION}/gcc/config/i386/t-${TARGET}" - -cat <> "${WORK}/gcc-${GCC_VERSION}/gcc/config.gcc" -case \${target} in - ${TARGET}) - tmake_file="\${tmake_file} i386/t-${TARGET}" - ;; -esac -EOF - fi - - mkdir -p "${WORK}/build/gcc" - pushd "${WORK}/build/gcc" - - if [[ ! -f "${WORK}/build/gcc/config.cache" ]]; then - echo "Configuring GCC..." - "${WORK}/gcc-${GCC_VERSION}/configure" \ - --quiet \ - --config-cache \ - --target="${TARGET}" \ - --prefix="${SYSROOT}" \ - --with-sysroot="${SYSROOT}" \ - --with-native-system-header-dir="${SYSROOT}/include" \ - --with-newlib \ - --without-headers \ - --disable-nls \ - --enable-languages=c,c++ \ - --disable-shared \ - --disable-multilib \ - --disable-decimal-float \ - --disable-threads \ - --disable-libatomic \ - --disable-libgomp \ - --disable-libmpx \ - --disable-libquadmath \ - --disable-libssp \ - --disable-libvtv \ - --disable-libstdcxx - fi - - echo "Building GCC..." - (make -j all-gcc && make -j all-target-libgcc && \ - make install-gcc && make install-target-libgcc) > "${WORK}/build/gcc_build.log" - popd -} - -function build_libstdcxx() { - mkdir -p "${WORK}/build/libstdcxx" - pushd "${WORK}/build/libstdcxx" - - if [[ ! -f "${WORK}/build/libstdcxx/config.cache" ]]; then - echo "Configuring libstdc++..." - CFLAGS="-I${SYSROOT}/include" \ - CXXFLAGS="-I${SYSROOT}/include" \ - "${WORK}/gcc-${GCC_VERSION}/libstdc++-v3/configure" \ - --config-cache \ - --host="${TARGET}" \ - --target="${TARGET}" \ - --prefix="${SYSROOT}" \ - --disable-nls \ - --disable-multilib \ - --with-newlib \ - --disable-libstdcxx-threads \ - --disable-libstdcxx-pch \ - --with-gxx-include-dir="${SYSROOT}/include/c++" - fi - - echo "Building libstdc++..." - (make -j && make install) > "${WORK}/build/libstdcxx_build.log" - popd -} - -function build_libc() { - if [[ ! -d "${WORK}/poplibc" ]]; then - echo "Downloading poplibc..." - git clone \ - "https://github.com/justinian/poplibc.git" \ - "${WORK}/poplibc" - else - echo "Updating poplibc..." - git -C "${WORK}/poplibc" pull - fi - - pushd "${WORK}/poplibc" - echo "Building poplibc..." - make install PREFIX="${SYSROOT}" - popd -} - -function update_links() { - for exe in `ls "${SYSROOT}/bin/${TARGET}-"*`; do - base=$(echo "$exe" | sed -e "s/${TARGET}-//") - ln -fs "${exe}" "${base}" - done -} - -build_nasm -build_binutils -build_gcc - -update_links -export PATH="${SYSROOT}/bin:${PATH}" -build_libc -build_libstdcxx diff --git a/scripts/readme_for_prebuilt_sysroots.md b/scripts/readme_for_prebuilt_sysroots.md new file mode 100644 index 0000000..4b8797f --- /dev/null +++ b/scripts/readme_for_prebuilt_sysroots.md @@ -0,0 +1,47 @@ +# jsix OS sysroot + +This is a pre-built sysroot for building the jsix operating system kernel, +bootloader, and utilities. This package is provided as a convenience, and +contains software from the following repositories. + +## NASM, the Netwide Assembler + +As downloaded from [the NASM website][nasm] under the following license: + + Copyright 1996-2010 the NASM Authors - All rights reserved. + + Redistribution and use in source and binary forms, with or without + modification, are permitted provided that the following + conditions are met: + + * Redistributions of source code must retain the above copyright + notice, this list of conditions and the following disclaimer. + * Redistributions in binary form must reproduce the above + copyright notice, this list of conditions and the following + disclaimer in the documentation and/or other materials provided + with the distribution. + + THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND + CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, + INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF + MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR + CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT + NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; + LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR + OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, + EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + +[nasm]: https://www.nasm.us + +## The LLVM toolchain + +The LLVM sources as downloaded via git from [llvm.org][llvm] under the terms of +the [Apache License v2.0][apache2], modified [as described here][llvmlic]. + +[llvm]: https://llvm.org +[apache2]: https://www.apache.org/licenses/LICENSE-2.0 +[llvmlic]: https://llvm.org/docs/DeveloperPolicy.html#new-llvm-project-license-framework diff --git a/scripts/templates/target.host.j2 b/scripts/templates/target.host.j2 index e7cdf08..03310e8 100644 --- a/scripts/templates/target.host.j2 +++ b/scripts/templates/target.host.j2 @@ -3,8 +3,8 @@ {% block binaries %} cc = ${srcroot}/sysroot/bin/clang cxx = ${srcroot}/sysroot/bin/clang++ -ld = ${srcroot}/sysroot/bin/x86_64-elf-ld -ar = ${srcroot}/sysroot/bin/x86_64-elf-ar +ld = ${srcroot}/sysroot/bin/ld.lld +ar = ${srcroot}/sysroot/bin/ar nasm = ${srcroot}/sysroot/bin/nasm objcopy = ${srcroot}/sysroot/bin/x86_64-elf-objcopy {% endblock %} @@ -36,7 +36,6 @@ ldflags = $ldflags $ -nostdlib $ -znocombreloc $ -Bsymbolic $ - -nostartfiles $ -Bstatic {% endblock %} diff --git a/scripts/templates/target.user.j2 b/scripts/templates/target.user.j2 index 8a9a7af..0551b84 100644 --- a/scripts/templates/target.user.j2 +++ b/scripts/templates/target.user.j2 @@ -3,10 +3,10 @@ {% block binaries %} cc = ${srcroot}/sysroot/bin/clang cxx = ${srcroot}/sysroot/bin/clang++ -ld = ${srcroot}/sysroot/bin/x86_64-elf-ld -ar = ${srcroot}/sysroot/bin/x86_64-elf-ar +ld = ${srcroot}/sysroot/bin/ld.lld +ar = ${srcroot}/sysroot/bin/ar nasm = ${srcroot}/sysroot/bin/nasm -objcopy = ${srcroot}/sysroot/bin/x86_64-elf-objcopy +objcopy = ${srcroot}/sysroot/bin/objcopy {% endblock %} {% block variables %} @@ -35,7 +35,6 @@ ldflags = $ldflags $ -nostdlib $ -znocombreloc $ -Bsymbolic $ - -nostartfiles $ -Bstatic $ --sysroot="${srcroot}/sysroot" $ -L "${srcroot}/sysroot/lib" $ diff --git a/src/arch/x86_64/kernel.ld b/src/arch/x86_64/kernel.ld index af058af..8bd6796 100755 --- a/src/arch/x86_64/kernel.ld +++ b/src/arch/x86_64/kernel.ld @@ -10,29 +10,26 @@ SECTIONS __header_end = .; } - .text : { + .text ALIGN(4096) : { *(.text) + *(.isrs) } - .data : { + .data ALIGN(4096) : { *(.data) *(.rodata) } - .isrs : { - *(.isrs) + .bss ALIGN(4096) : { + __bss_start = .; + *(.bss) + __bss_end = .; } .note : { *(.note.*) } - .bss ALIGN(16) : { - __bss_start = .; - *(.bss) - __bss_end = .; - } - .eh_frame : { __eh_frame_start = .; KEEP(*(.eh_frame))