#!/usr/bin/env bash # Step 7: the integration hazard nobody asks about until the link fails. # # Today runtime/flan_rt.c, runtime/flan_dev.c and vendor/agent/flan_agent.c are # compiled into the *program*, and lib/dynload_stubs.c into the *compiler*. # Merging the processes puts all four and the OCaml runtime in one link. This # checks, symbol by symbol, whether anything collides. set -u here=$(cd "$(dirname "$0")" && pwd) root=$(cd "$here/../.." && pwd) out=$(mktemp -d) trap 'rm -rf "$out"' EXIT cd "$root" || exit 1 defs() { nm --defined-only "$@" 2>/dev/null | awk 'NF==3 {print $3}' | sort -u; } clang -c runtime/flan_rt.c -o "$out/rt.o" || exit 1 clang -c runtime/flan_dev.c -o "$out/dev.o" || exit 1 clang -c vendor/agent/flan_agent.c -o "$out/ag.o" || exit 1 clang -c -I"$(ocamlopt -where)" "$here/dynload_stubs.c" -o "$out/dl.o" || exit 1 defs "$out/rt.o" "$out/dev.o" "$out/ag.o" "$out/dl.o" > "$out/flan.syms" defs /home/joe/.opam/default/lib/ocaml/libasmrun.a > "$out/ml.syms" 2>/dev/null [ -s "$out/ml.syms" ] || defs "$(ocamlopt -where)/libasmrun.a" > "$out/ml.syms" echo "Flan's own C defines $(wc -l < "$out/flan.syms") symbols;" \ "libasmrun defines $(wc -l < "$out/ml.syms")." echo "collisions between Flan's C and the OCaml runtime:" if comm -12 "$out/flan.syms" "$out/ml.syms" | grep . ; then echo " ^^ those would have to be renamed" else echo " none" fi echo "collisions among Flan's own four .c files:" for a in rt dev ag dl; do defs "$out/$a.o" > "$out/$a.syms"; done found=0 for a in rt dev ag dl; do for b in rt dev ag dl; do [ "$a" \< "$b" ] || continue c=$(comm -12 "$out/$a.syms" "$out/$b.syms") [ -n "$c" ] && { echo " $a vs $b:"; echo "$c" | sed 's/^/ /'; found=1; } done done [ $found -eq 0 ] && echo " none" echo "what Flan's C needs that the OCaml runtime also exports (shared libc etc):" nm --undefined-only "$out/rt.o" "$out/ag.o" 2>/dev/null | awk 'NF==2{print $2}' \ | sort -u > "$out/need.syms" comm -12 "$out/need.syms" "$out/ml.syms" | sed 's/^/ /' | head -20