1DOLLY 82TOOLCHAIN 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 /demos/llvm/Dollyfile-llvm-tablegen e9bd8f94e0ca5728375d55763158837387a7cb9a09b380fe6a563a231369f5a516COPY /demos/llvm/Dollyfile-llvm-build 1457ffcf01316d33881927984dc2584f37fd4a93cd66df862cb2219331984c5f /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 /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 (programs/compiler.cpp), with the two contract35# digests the runtime build generates.36SOURCE /dist/static/llvm/compiler.cpp c55c820a2a2332805765e99a1474a2a4163315e9196da90df0822181579033df /tmp/dolly-compiler/compiler.cpp37SOURCE /dist/static/llvm/compiler-main.c 45b15780c4df81b895c7dc7cf6135ba8c6f40659682e841d2ea95dc69268dd34 /tmp/dolly-compiler/compiler-main.c38SOURCE /dist/static/llvm/toolchain.h e3e12fa1eabbf433c25bc3db0ef71256667f21669a93ee2dcb0ac20ce18f6fa5 /tmp/dolly-compiler/commands/toolchain.h39SOURCE /dist/static/llvm/dolly-process-abi-digest.h cf7a584634c1310446d9f988d1c321be90159ca68fb3e1fd505b83a59e21fe85 /tmp/dolly-compiler/dolly-process-abi-digest.h40SOURCE /dist/static/llvm/dolly-kernel-plugin-abi-digest.h a680157985ef34465efdfce079749799bb3cc7e1c119867c34730d8669bc669e /tmp/dolly-compiler/dolly-kernel-plugin-abi-digest.h4142# Compiles the driver and links ./compiler without its names: the seed's43# compiler (docs/sources.md). ROOT holds lib/*.a and the generated headers by44# build-tree path. The link needs 32 MiB at start: its 8 MiB stack and its data45# pass cc's 16 MiB.46FILE /usr/lib/llvm-build/link-compiler.slop47    # usage, in the driver's directory: slop -e link-compiler.slop ROOT48    llvm=/tmp/llvm-project49    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"50    c++ -O2 -DNDEBUG -std=gnu++17 -fno-exceptions -fno-rtti -include endian.h -DCLANG_BUILD_STATIC $include -c compiler.cpp -o compiler.o51    cc -O2 -DNDEBUG -c compiler-main.c -o compiler-main.o52    c++ compiler.o compiler-main.o -o compiler -Wl,--initial-memory=33554432 -Wl,--strip-all $1/lib/*.a53SLOP CWD /tmp/dolly-compiler time slop -e /usr/lib/llvm-build/link-compiler.slop /usr/lib/llvm-build5455# The resource headers generated here are the seed's.56SLOP diff -r /usr/lib/llvm-build/lib/clang/24/include /usr/lib/clang/24/include5758FILE /tmp/dolly-compiler/check.c59    #include <math.h>60    #include <stdio.h>61    #include <stdlib.h>62    #include <string.h>63    int main(int argc, char **argv) {64      char *copy = strdup(argv[0]);65      FILE *file = fopen("/tmp/dolly-compiler/check.txt", "w");66      fprintf(file, "%.6f %zu\n", sqrt(2.0), strlen(copy) ? (size_t)42 : 0);67      fclose(file);68      free(copy);69      return argc != 1;70    }71FILE /tmp/dolly-compiler/check.cpp72    #include <iostream>73    #include <map>74    #include <stdexcept>75    #include <string>76    #include <vector>77    struct Shape { virtual ~Shape() = default; virtual int sides() const = 0; };78    struct Square : Shape { int sides() const override { return 4; } };79    int main() {80      std::map<std::string, std::vector<int>> table;81      table["a"] = {1, 2, 3};82      Square square;83      const Shape &shape = square;84      int total = shape.sides();85      for (int value : table["a"]) total += value;86      try { throw std::runtime_error("thrown"); }87      catch (const std::exception &error) { std::cout << "CXX-OK " << total << " " << error.what() << "\n"; }88      return total != 10;89    }90# The new compiler against the seed's: the same arguments must compile the91# same bytes. Linking is the driver's, and a round that changes the driver92# links differently by design, so the two programs are linked by the new93# compiler alone and run; that it links the same bytes again is the round's94# fixed point (llvm-cc built by this compiler, docs/sources.md).95FILE /tmp/dolly-compiler/check.slop96    # usage, in the driver's directory: slop -e check.slop97    llvm=/tmp/llvm-project98    root=/usr/lib/llvm-build99    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"100    clang="$unit -I$llvm/clang/include -I$root/tools/clang/include"101    mkdir out seed102    same() {103      mode=$1104      shift105      /usr/libexec/dolly/process-bin/compiler --dolly-toolchain-mode=$mode "$@" -o out/unit106      mv out/unit seed/unit107      ./compiler --dolly-toolchain-mode=$mode "$@" -o out/unit108      cmp out/unit seed/unit109    }110    same c -c check.c111    ./compiler --dolly-toolchain-mode=c out/unit -o check-c112    ./check-c113    grep -q '^1.414214 42$' check.txt114    same c++ -c check.cpp115    ./compiler --dolly-toolchain-mode=c++ out/unit -o check-cpp116    ./check-cpp | grep -q '^CXX-OK 10 thrown$'117    same c -O0 -g -c check.c118    same c -O2 -DNDEBUG -c compiler-main.c119    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.cpp120    same c -std=gnu17 -fPIC -w -O3 -DNDEBUG -I$root/include -I$llvm/llvm/include -c $llvm/llvm/lib/Support/regcomp.c121    same c++ $unit -I$llvm/libc -c $llvm/llvm/lib/Support/APFloat.cpp122    same c++ $unit -c $llvm/llvm/lib/Demangle/ItaniumDemangle.cpp123    same c++ $unit -c $llvm/llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp124    same c++ $clang -I$llvm/clang/lib/Driver -c $llvm/clang/lib/Driver/ToolChains/MSP430.cpp125    same c++ $clang -I$llvm/clang/lib/Sema -c $llvm/clang/lib/Sema/SemaARM.cpp126    same c++ $clang -I$llvm/clang/lib/Sema -c $llvm/clang/lib/Sema/SemaExpr.cpp127SLOP CWD /tmp/dolly-compiler time slop -e check.slop128129SLOP cp /tmp/dolly-compiler/compiler /usr/libexec/dolly/process-bin/compiler130EXPORTS FILE compiler /usr/libexec/dolly/process-bin/compiler131# cc, c++ and ar now run the compiler built here.132SLOP CWD /tmp/dolly-compiler slop -c 'c++ check.cpp -o check && ./check && ar rcs check.a compiler.o && cc --version'133134ENTRY /bin/foreground -i /bin/slop135