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.5/demos/llvm/Dollyfile-llvm-tablegen ea7fedd02ed27db50b5ff5a54395655183fe9d6a5879f4efa8e4a8ca5d87bf9d16COPY /v0.1.5/demos/llvm/Dollyfile-llvm-build 0e435dff476c20f5a4a2f10dfd0b32015be89f49460ad7460ba86bb1deb2bf73 /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.5/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.5/dist/static/llvm/compiler.cpp 36a1b101c09778ad226de3828d708f96481207f59dd6d63bd993964d6b3e6b07 /tmp/dolly-compiler/compiler.cpp37SOURCE /v0.1.5/dist/static/llvm/compiler-main.c 104ebf5d2862d51f9a67d4e7dd6a71e0f5beb1898310f74d6b331e9f154a2f8c /tmp/dolly-compiler/compiler-main.c38SOURCE /v0.1.5/dist/static/llvm/dolly-process-abi-digest.h b4e679e98d73388d193504b6cb5ff82dfd4d37ea6f60232d464a144b97ca2aa9 /tmp/dolly-compiler/dolly-process-abi-digest.h39SOURCE /v0.1.5/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 compile the90# same bytes. Linking is the driver's, and a round that changes the driver91# links differently by design, so the two programs are linked by the new92# compiler alone and run; that it links the same bytes again is the round's93# fixed point (llvm-cc built by this compiler, docs/sources.md).94FILE /tmp/dolly-compiler/check.slop95    # usage, in the driver's directory: slop -e check.slop96    llvm=/tmp/llvm-project97    root=/usr/lib/llvm-build98    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"99    clang="$unit -I$llvm/clang/include -I$root/tools/clang/include"100    mkdir out seed101    same() {102      mode=$1103      shift104      /usr/libexec/dolly/process-bin/compiler --dolly-toolchain-mode=$mode "$@" -o out/unit105      mv out/unit seed/unit106      ./compiler --dolly-toolchain-mode=$mode "$@" -o out/unit107      cmp out/unit seed/unit108    }109    same c -c check.c110    ./compiler --dolly-toolchain-mode=c out/unit -o check-c111    ./check-c112    grep -q '^1.414214 42$' check.txt113    same c++ -c check.cpp114    ./compiler --dolly-toolchain-mode=c++ out/unit -o check-cpp115    ./check-cpp | grep -q '^CXX-OK 10 thrown$'116    same c -O0 -g -c check.c117    same c -O2 -DNDEBUG -c compiler-main.c118    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.cpp119    same c -std=gnu17 -fPIC -w -O3 -DNDEBUG -I$root/include -I$llvm/llvm/include -c $llvm/llvm/lib/Support/regcomp.c120    same c++ $unit -I$llvm/libc -c $llvm/llvm/lib/Support/APFloat.cpp121    same c++ $unit -c $llvm/llvm/lib/Demangle/ItaniumDemangle.cpp122    same c++ $unit -c $llvm/llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp123    same c++ $clang -I$llvm/clang/lib/Driver -c $llvm/clang/lib/Driver/ToolChains/MSP430.cpp124    same c++ $clang -I$llvm/clang/lib/Sema -c $llvm/clang/lib/Sema/SemaARM.cpp125    same c++ $clang -I$llvm/clang/lib/Sema -c $llvm/clang/lib/Sema/SemaExpr.cpp126SLOP CWD /tmp/dolly-compiler time slop -e check.slop127128SLOP cp /tmp/dolly-compiler/compiler /usr/libexec/dolly/process-bin/compiler129EXPORTS FILE compiler /usr/libexec/dolly/process-bin/compiler130# cc, c++ and ar now run the compiler built here.131SLOP CWD /tmp/dolly-compiler slop -c 'c++ check.cpp -o check && ./check && ar rcs check.a compiler.o && cc --version'132133ENTRY /bin/foreground -i /bin/slop134