1DOLLY 72TOOLCHAIN llvm-cc3REQUIRES HOST runtime@04REQUIRES HOST display@05REQUIRES HOST dso@06REQUIRES HOST http@07REQUIRES HOST input@08REQUIRES HOST sockets@09REQUIRES HOST threads@01011# Clang and LLD linked inside Dolly from llvm-build's archives, checked against12# the seed compiler and installed in its place: this image's cc is built by Dolly.13# The archives come by COPY, so the rest of LLVM that llvm-build installed for14# the llvm package stays out of this image.15FROM /v0.1.4/demos/llvm/Dollyfile-llvm-tablegen 522b41c3855d7661815d77e27505f943a285462a26d3996f2150d27f880fb59d16COPY /v0.1.4/demos/llvm/Dollyfile-llvm-build b241183051a4ad49a2e6daa7fe76817394eb94267179893571cae9106dc90dcd /usr/lib/llvm-build /usr/lib/llvm-build17REQUIRES TOOL cc18REQUIRES TOOL c++19REQUIRES TOOL gzip20REQUIRES TOOL tar21REQUIRES TOOL time22REQUIRES TOOL cmp23REQUIRES TOOL diff24REQUIRES TOOL grep25REQUIRES TOOL cp26REQUIRES TOOL mv27REQUIRES TOOL mkdir28REQUIRES TOOL rm2930# LLVM's source headers again; llvm-build kept the configured and generated ones.31SOURCE /v0.1.4/dist/static/llvm/llvm-project.tar.gz 033390c4520e51f261eb7572f0a1b4a1592121a1c8c1fc0c3db4845b079a8882 /tmp/llvm-project.tar.gz32SLOP slop -c 'gzip -dc /tmp/llvm-project.tar.gz | tar -xf - -C /'33SLOP rm /tmp/llvm-project.tar.gz34# The driver the seed compiler is (src/compiler.cpp), with the two contract35# digests the runtime build generates.36SOURCE /v0.1.4/dist/static/llvm/compiler.cpp db6c22afa29050ec24f5ab1cf3c922de8295b7a7be7e1026b4c86cd931cf6b3b /tmp/dolly-compiler/compiler.cpp37SOURCE /v0.1.4/dist/static/llvm/compiler-main.c 104ebf5d2862d51f9a67d4e7dd6a71e0f5beb1898310f74d6b331e9f154a2f8c /tmp/dolly-compiler/compiler-main.c38SOURCE /v0.1.4/dist/static/llvm/dolly-process-abi-digest.h 0dfaf81a2cc01e99546209201baf82d7e19438e070ba71c719c680ae91a3b066 /tmp/dolly-compiler/dolly-process-abi-digest.h39SOURCE /v0.1.4/dist/static/llvm/dolly-kernel-plugin-abi-digest.h a680157985ef34465efdfce079749799bb3cc7e1c119867c34730d8669bc669e /tmp/dolly-compiler/dolly-kernel-plugin-abi-digest.h4041# Compiles the driver and links ./compiler without its names: the seed's42# compiler (docs/sources.md). ROOT holds lib/*.a and the generated headers by43# build-tree path. The link needs 32 MiB at start: its 8 MiB stack and its data44# pass cc's 16 MiB.45FILE /usr/lib/llvm-build/link-compiler.slop46    # usage, in the driver's directory: slop -e link-compiler.slop ROOT47    llvm=/tmp/llvm-project48    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"49    c++ -O2 -DNDEBUG -std=gnu++17 -fno-exceptions -fno-rtti -include endian.h -DCLANG_BUILD_STATIC $include -c compiler.cpp -o compiler.o50    cc -O2 -DNDEBUG -c compiler-main.c -o compiler-main.o51    c++ compiler.o compiler-main.o -o compiler -Wl,--initial-memory=33554432 -Wl,--strip-all $1/lib/*.a52SLOP CWD /tmp/dolly-compiler time slop -e /usr/lib/llvm-build/link-compiler.slop /usr/lib/llvm-build5354# The resource headers generated here are the seed's.55SLOP diff -r /usr/lib/llvm-build/lib/clang/24/include /usr/lib/clang/24/include5657FILE /tmp/dolly-compiler/check.c58    #include <math.h>59    #include <stdio.h>60    #include <stdlib.h>61    #include <string.h>62    int main(int argc, char **argv) {63      char *copy = strdup(argv[0]);64      FILE *file = fopen("/tmp/dolly-compiler/check.txt", "w");65      fprintf(file, "%.6f %zu\n", sqrt(2.0), strlen(copy) ? (size_t)42 : 0);66      fclose(file);67      free(copy);68      return argc != 1;69    }70FILE /tmp/dolly-compiler/check.cpp71    #include <iostream>72    #include <map>73    #include <stdexcept>74    #include <string>75    #include <vector>76    struct Shape { virtual ~Shape() = default; virtual int sides() const = 0; };77    struct Square : Shape { int sides() const override { return 4; } };78    int main() {79      std::map<std::string, std::vector<int>> table;80      table["a"] = {1, 2, 3};81      Square square;82      const Shape &shape = square;83      int total = shape.sides();84      for (int value : table["a"]) total += value;85      try { throw std::runtime_error("thrown"); }86      catch (const std::exception &error) { std::cout << "CXX-OK " << total << " " << error.what() << "\n"; }87      return total != 10;88    }89# The new compiler against the seed's: the same arguments must give the same90# bytes. wasm-ld records an input's scratch name, which cc derives from the91# output path, so both write out/unit.92FILE /tmp/dolly-compiler/check.slop93    # usage, in the driver's directory: slop -e check.slop94    llvm=/tmp/llvm-project95    root=/usr/lib/llvm-build96    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"97    clang="$unit -I$llvm/clang/include -I$root/tools/clang/include"98    mkdir out seed99    same() {100      mode=$1101      shift102      /usr/libexec/dolly/process-bin/compiler --dolly-toolchain-mode=$mode "$@" -o out/unit103      mv out/unit seed/unit104      ./compiler --dolly-toolchain-mode=$mode "$@" -o out/unit105      cmp out/unit seed/unit106    }107    same c check.c108    out/unit109    grep -q '^1.414214 42$' check.txt110    same c++ check.cpp111    out/unit | grep -q '^CXX-OK 10 thrown$'112    same c -O0 -g -c check.c113    same c -O2 -DNDEBUG -c compiler-main.c114    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.cpp115    same c -std=gnu17 -fPIC -w -O3 -DNDEBUG -I$root/include -I$llvm/llvm/include -c $llvm/llvm/lib/Support/regcomp.c116    same c++ $unit -I$llvm/libc -c $llvm/llvm/lib/Support/APFloat.cpp117    same c++ $unit -c $llvm/llvm/lib/Demangle/ItaniumDemangle.cpp118    same c++ $unit -c $llvm/llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp119    same c++ $clang -I$llvm/clang/lib/Driver -c $llvm/clang/lib/Driver/ToolChains/MSP430.cpp120    same c++ $clang -I$llvm/clang/lib/Sema -c $llvm/clang/lib/Sema/SemaARM.cpp121    same c++ $clang -I$llvm/clang/lib/Sema -c $llvm/clang/lib/Sema/SemaExpr.cpp122SLOP CWD /tmp/dolly-compiler time slop -e check.slop123124SLOP cp /tmp/dolly-compiler/compiler /usr/libexec/dolly/process-bin/compiler125EXPORTS FILE compiler /usr/libexec/dolly/process-bin/compiler126# cc, c++ and ar now run the compiler built here.127SLOP CWD /tmp/dolly-compiler slop -c 'c++ check.cpp -o check && ./check && ar rcs check.a compiler.o && cc --version'128129ENTRY /bin/foreground -i /bin/slop130