1DOLLY 72TOOLCHAIN llvm-cc3REQUIRES HOST runtime@04REQUIRES HOST display@05REQUIRES HOST download@06REQUIRES HOST dso@07REQUIRES HOST http@08REQUIRES HOST input@09REQUIRES HOST sockets@010REQUIRES HOST upload@01112# Clang and LLD linked inside Dolly from llvm-build's archives, checked against13# the seed compiler and installed in its place: this image's cc is built by Dolly.14FROM /v0.1.2/demos/llvm/Dollyfile-llvm-build aab36628f2bc371a590b546c1ff3a0954a33cc6b8c3fdbea6ac973b62654e5d115REQUIRES TOOL cc16REQUIRES TOOL c++17REQUIRES TOOL gzip18REQUIRES TOOL tar19REQUIRES TOOL time20REQUIRES TOOL cmp21REQUIRES TOOL diff22REQUIRES TOOL grep23REQUIRES TOOL cp24REQUIRES TOOL mv25REQUIRES TOOL mkdir26REQUIRES TOOL rm2728# LLVM's source headers again; llvm-build kept the configured and generated ones.29SOURCE /v0.1.2/dist/static/llvm/llvm-project.tar.gz 033390c4520e51f261eb7572f0a1b4a1592121a1c8c1fc0c3db4845b079a8882 /tmp/llvm-project.tar.gz30SLOP slop -c 'gzip -dc /tmp/llvm-project.tar.gz | tar -xf - -C /'31SLOP rm /tmp/llvm-project.tar.gz32# The driver the seed compiler is (src/compiler.cpp), with the two contract33# digests the runtime build generates.34SOURCE /v0.1.2/dist/static/llvm/compiler.cpp 7e2e415d53b4ef64d68e9c6aef3a4a5cc963ea97549969282ef0dce815b67984 /tmp/dolly-compiler/compiler.cpp35SOURCE /v0.1.2/dist/static/llvm/compiler-main.c 104ebf5d2862d51f9a67d4e7dd6a71e0f5beb1898310f74d6b331e9f154a2f8c /tmp/dolly-compiler/compiler-main.c36SOURCE /v0.1.2/dist/static/llvm/dolly-process-abi-digest.h a9086eddb238582885298ab36c68c8eb7a58c5133e59d1c277f46417205b3720 /tmp/dolly-compiler/dolly-process-abi-digest.h37SOURCE /v0.1.2/dist/static/llvm/dolly-kernel-plugin-abi-digest.h a680157985ef34465efdfce079749799bb3cc7e1c119867c34730d8669bc669e /tmp/dolly-compiler/dolly-kernel-plugin-abi-digest.h3839# Compiles the driver as toolchain/CMakeLists.txt does and links ./compiler.40# ROOT holds lib/*.a and the generated headers by build-tree path. The seed's41# link needs 32 MiB at start: its 8 MiB stack and its data pass cc's 16 MiB.42FILE /usr/lib/llvm-build/link-compiler.slop43    # usage, in the driver's directory: slop -e link-compiler.slop ROOT44    llvm=/tmp/llvm-project45    include="-I. -I$llvm/llvm/include -I$1/include -I$llvm/clang/include -I$1/tools/clang/include -I$llvm/lld/include -I$1/tools/lld/include"46    c++ -O2 -DNDEBUG -std=gnu++17 -fno-exceptions -fno-rtti -include endian.h -DCLANG_BUILD_STATIC $include -c compiler.cpp -o compiler.o47    cc -O2 -DNDEBUG -c compiler-main.c -o compiler-main.o48    c++ compiler.o compiler-main.o -o compiler -Wl,--initial-memory=33554432 $1/lib/*.a49SLOP CWD /tmp/dolly-compiler time slop -e /usr/lib/llvm-build/link-compiler.slop /usr/lib/llvm-build5051# The resource headers generated here are the seed's.52SLOP diff -r /usr/lib/llvm-build/lib/clang/24/include /usr/lib/clang/24/include5354FILE /tmp/dolly-compiler/check.c55    #include <math.h>56    #include <stdio.h>57    #include <stdlib.h>58    #include <string.h>59    int main(int argc, char **argv) {60      char *copy = strdup(argv[0]);61      FILE *file = fopen("/tmp/dolly-compiler/check.txt", "w");62      fprintf(file, "%.6f %zu\n", sqrt(2.0), strlen(copy) ? (size_t)42 : 0);63      fclose(file);64      free(copy);65      return argc != 1;66    }67FILE /tmp/dolly-compiler/check.cpp68    #include <iostream>69    #include <map>70    #include <stdexcept>71    #include <string>72    #include <vector>73    struct Shape { virtual ~Shape() = default; virtual int sides() const = 0; };74    struct Square : Shape { int sides() const override { return 4; } };75    int main() {76      std::map<std::string, std::vector<int>> table;77      table["a"] = {1, 2, 3};78      Square square;79      const Shape &shape = square;80      int total = shape.sides();81      for (int value : table["a"]) total += value;82      try { throw std::runtime_error("thrown"); }83      catch (const std::exception &error) { std::cout << "CXX-OK " << total << " " << error.what() << "\n"; }84      return total != 10;85    }86# The new compiler against the seed's: the same arguments must give the same87# bytes. wasm-ld records an input's scratch name, which cc derives from the88# output path, so both write out/unit.89FILE /tmp/dolly-compiler/check.slop90    # usage, in the driver's directory: slop -e check.slop91    llvm=/tmp/llvm-project92    root=/usr/lib/llvm-build93    unit="-D__STDC_CONSTANT_MACROS -D__STDC_FORMAT_MACROS -D__STDC_LIMIT_MACROS -include endian.h -DCLANG_BUILD_STATIC -fPIC -fvisibility-inlines-hidden -w -ffunction-sections -fdata-sections -fno-common -O3 -DNDEBUG -std=c++17 -fno-exceptions -funwind-tables -fno-rtti -I$root/include -I$llvm/llvm/include"94    clang="$unit -I$llvm/clang/include -I$root/tools/clang/include"95    mkdir out seed96    same() {97      mode=$198      shift99      /usr/libexec/dolly/process-bin/compiler --dolly-toolchain-mode=$mode "$@" -o out/unit100      mv out/unit seed/unit101      ./compiler --dolly-toolchain-mode=$mode "$@" -o out/unit102      cmp out/unit seed/unit103    }104    same c check.c105    out/unit106    grep -q '^1.414214 42$' check.txt107    same c++ check.cpp108    out/unit | grep -q '^CXX-OK 10 thrown$'109    same c -O0 -g -c check.c110    same c -O2 -DNDEBUG -c compiler-main.c111    same c++ -O2 -DNDEBUG -std=gnu++17 -fno-exceptions -fno-rtti -include endian.h -DCLANG_BUILD_STATIC -I. -I$llvm/llvm/include -I$root/include -I$llvm/clang/include -I$root/tools/clang/include -I$llvm/lld/include -I$root/tools/lld/include -c compiler.cpp112    same c -std=gnu17 -fPIC -w -O3 -DNDEBUG -I$root/include -I$llvm/llvm/include -c $llvm/llvm/lib/Support/regcomp.c113    same c++ $unit -I$llvm/libc -c $llvm/llvm/lib/Support/APFloat.cpp114    same c++ $unit -c $llvm/llvm/lib/Demangle/ItaniumDemangle.cpp115    same c++ $unit -c $llvm/llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp116    same c++ $clang -I$llvm/clang/lib/Driver -c $llvm/clang/lib/Driver/ToolChains/MSP430.cpp117    same c++ $clang -I$llvm/clang/lib/Sema -c $llvm/clang/lib/Sema/SemaARM.cpp118    same c++ $clang -I$llvm/clang/lib/Sema -c $llvm/clang/lib/Sema/SemaExpr.cpp119SLOP CWD /tmp/dolly-compiler time slop -e check.slop120121SLOP cp /tmp/dolly-compiler/compiler /usr/libexec/dolly/process-bin/compiler122EXPORTS FILE compiler /usr/libexec/dolly/process-bin/compiler123# cc, c++ and ar now run the compiler built here.124SLOP CWD /tmp/dolly-compiler slop -c 'c++ check.cpp -o check && ./check && ar rcs check.a compiler.o && cc --version'125126ENTRY /bin/foreground -i /bin/slop127