Giter Club home page Giter Club logo

sysroot's Introduction

Files For Cross-Compilation

To do cross-compiling, "toolchain" has to be used.

Typical toolchain contains:

  • header files for the target platform for "default" libraries like libc, c++ standard library, etc;
  • header files for the libraries related to compiler builtins (known as compiler-rt or libgcc, sometimes including a library for exception handling support);
  • binaries .a, .so and similar for "default" libraries;
  • binaries for "startfiles" like crt1.o that contain entry point, initialization and deinitialization routines relevant to the libc;
  • the binaries of cross-compiler, cross-linker, cross-assembler, ar and ranlib and possibly other binutils - the binaries that run on host platform but generates artifacts for the target platform;

Toolchain is usually distributed as a tarball and is quite large, in order of hundreds MB. It contains an amalgamation of tools, libraries and binaries for all the needs: C, C++, Fortran, CUDA...

We don't really need all of this amalgamation for the following reason:

  • we don't need cross-compiler and other tools, because we use LLVM infrastructure (clang, lld, llvm-ar, ...) and it supports cross-compilation by default;
  • we don't need C++ headers and libraries because we include libc++, libc++abi, LLVM's libunwind as a source code and compile it from sources during build process;
  • we definitely don't need Fortran headers;

The idea is to strip down the "toolchain" as much as possible and provide it as a submodule instead of tarball. Actually it's not longer a "toolchain", it's just a collection of libc-related libraries and a few files for compiler builtins.

This gives us the following advantages:

  • more easy to add new platforms (no need to search for complete toolchain, just copy the relevant files from the OS image);
  • better understanding what's going on - only the relevant files included;
  • avoid risks of supply-chain attacks;
  • allow to use custom sysroot even for default (non-cross) build to get reproducible, hermetic builds;
  • opens up for experiment of building the libc from sources;
  • simplify using musl-libc instead of glibc.

This repository contains some blobs like libc.so. The source:

  • for x86_64 they are from Ubuntu 20.04 image;

  • for aarch64 they are from developer.arm.com

  • for s390x it is extracted from Docker image:

docker run -it s390x/ubuntu:18.04
apt update
apt install gcc

docker export b38a367a8a05 > s390x.tar
  • for powerpc64le it is extracted from Docker image:
docker run -it ppc64le/ubuntu:14.04
apt update
apt install gcc

docker export b38a367a8a05 > ppc64.tar

The ubuntu version 14.04 is selected for better compatibility.

  • for x86_64-musl some headers and libraries come from the ubuntu image, others are built from our musl fork: github.com/ClickHouse/musl (see #28)
  • for riscv they are from Debian Unstable libc6-dev package.
  • for loongarch64 they are from Debian Unstable image

FreeBSD:

https://clickhouse-datasets.s3.yandex.net/toolchains/toolchains/freebsd-11.3-toolchain.tar.xz
http://distcache.FreeBSD.org/local-distfiles/mikael/freebsd-12.2-aarch64-toolchain.tar.xz

TODO:

  • build compiler-rt from sources and remove libgcc.a from here;
  • simplify directory structure even more.

sysroot's People

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

sysroot's Issues

Add Scrt1.o to sysroots

When using the linux-x86_64/libc sysroot with clang 15 it fails to find this file. It's probably because clang switched to use -fpie default on Linux x86_64.

unable to find library -lc++, -lgcc_s

I think i could do something wrong but i wasn't familiar with cross building with clang before. What i did is downloaded this toolchain and libc++. I did not use compiler-rt and libunwind as i do not understand this. Then i executed following command:

clang++ hello.cpp --target=x86_64-v3-linux -isystem stdlib/include --sysroot=C:\cclang\sysroot\linux-x86_64 -s
tdlib=libc++ -fuse-ld="C:\cclang\clang\LLVM\bin\ld.lld" -v

and got the output:

clang version 17.0.5
Target: x86_64-v3-linux
Thread model: posix
InstalledDir: C:\cclang\clang\LLVM\bin
Found candidate GCC installation: C:\cclang\sysroot\linux-x86_64/lib/gcc/x86_64-linux-gnu\9
Selected GCC installation: C:\cclang\sysroot\linux-x86_64/lib/gcc/x86_64-linux-gnu/9
Candidate multilib: .;@m64
Selected multilib: .;@m64
 "C:\\cclang\\clang\\LLVM\\bin\\clang++.exe" -cc1 -triple x86_64-v3-linux -emit-obj -mrelax-all -dumpdir a- -disable-free -clear-ast-before-backend -disable-llvm-verifier -discard-value-names -main-file-name hello.cpp -mrelocation-model pic -pic-level 2 -pic-is-pie -mframe-pointer=all -fmath-errno -ffp-contract=on -fno-rounding-math -mconstructor-aliases -funwind-tables=2 -target-cpu x86-64 -tune-cpu generic -debugger-tuning=gdb -v "-fcoverage-compilation-dir=C:\\cclang" -resource-dir "C:\\cclang\\clang\\LLVM\\lib\\clang\\17" -isystem stdlib/include -isysroot "C:\\cclang\\sysroot\\linux-x86_64" -internal-isystem "C:\\cclang\\clang\\LLVM\\lib\\clang\\17\\include" -internal-isystem "C:\\cclang\\sysroot\\linux-x86_64/usr/local/include" -internal-isystem "C:\\cclang\\sysroot\\linux-x86_64/lib/gcc/x86_64-linux-gnu/9/../../../../x86_64-linux-gnu/include" -internal-externc-isystem "C:\\cclang\\sysroot\\linux-x86_64/usr/include/x86_64-linux-gnu" -internal-externc-isystem "C:\\cclang\\sysroot\\linux-x86_64/include" -internal-externc-isystem "C:\\cclang\\sysroot\\linux-x86_64/usr/include" -fdeprecated-macro "-fdebug-compilation-dir=C:\\cclang" -ferror-limit 19 -fmessage-length=120 -fgnuc-version=4.2.1 -fcxx-exceptions -fexceptions -fcolor-diagnostics -faddrsig -D__GCC_HAVE_DWARF2_CFI_ASM=1 -o "C:\\Users\\Admin\\AppData\\Local\\Temp\\hello-f3784d.o" -x c++ hello.cpp
clang -cc1 version 17.0.5 based upon LLVM 17.0.5 default target x86_64-pc-windows-msvc
ignoring nonexistent directory "C:\cclang\sysroot\linux-x86_64/usr/local/include"
ignoring nonexistent directory "C:\cclang\sysroot\linux-x86_64/lib/gcc/x86_64-linux-gnu/9/../../../../x86_64-linux-gnu/include"
ignoring nonexistent directory "C:\cclang\sysroot\linux-x86_64/include"
#include "..." search starts here:
#include <...> search starts here:
 stdlib/include
 C:\cclang\clang\LLVM\lib\clang\17\include
 C:\cclang\sysroot\linux-x86_64/usr/include/x86_64-linux-gnu
 C:\cclang\sysroot\linux-x86_64/usr/include
End of search list.
 "C:\\cclang\\clang\\LLVM\\bin\\ld.lld" "--sysroot=C:\\cclang\\sysroot\\linux-x86_64" -pie --hash-style=gnu --eh-frame-hdr -m elf_x86_64 -dynamic-linker /lib64/ld-linux-x86-64.so.2 -o a.out "C:\\cclang\\sysroot\\linux-x86_64/lib/gcc/x86_64-linux-gnu/9/../../../../lib64\\Scrt1.o" "C:\\cclang\\sysroot\\linux-x86_64/usr/lib/../lib64\\crti.o" "C:\\cclang\\sysroot\\linux-x86_64/lib/gcc/x86_64-linux-gnu/9\\crtbeginS.o" "-LC:\\cclang\\sysroot\\linux-x86_64/lib/gcc/x86_64-linux-gnu/9" "-LC:\\cclang\\sysroot\\linux-x86_64/lib/gcc/x86_64-linux-gnu/9/../../../../lib64" "-LC:\\cclang\\sysroot\\linux-x86_64/lib/../lib64" "-LC:\\cclang\\sysroot\\linux-x86_64/usr/lib/../lib64" "-LC:\\cclang\\sysroot\\linux-x86_64/lib" "-LC:\\cclang\\sysroot\\linux-x86_64/usr/lib" "C:\\Users\\Admin\\AppData\\Local\\Temp\\hello-f3784d.o" -lc++ -lm -lgcc_s -lgcc -lc -lgcc_s -lgcc "C:\\cclang\\sysroot\\linux-x86_64/lib/gcc/x86_64-linux-gnu/9\\crtendS.o" "C:\\cclang\\sysroot\\linux-x86_64/usr/lib/../lib64\\crtn.o"
ld.lld: error: unable to find library -lc++
ld.lld: error: unable to find library -lgcc_s
ld.lld: error: unable to find library -lgcc_s
clang++: error: linker command failed with exit code 1 (use -v to see invocation)

These libraries are seems removed out but the compiler still want link agains them.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.