|
| 1 | +name: "[temp] probe: the Windows unit fault, under a debugger" |
| 2 | + |
| 3 | +# A measurement, not a check; this branch is not merged. A freshly built |
| 4 | +# compat.xz faults in PackCompress/AStatedLevelIsHonoured at the image base |
| 5 | +# (the passing runs took its objects from the global cache). This asks the |
| 6 | +# debugger where the call came from. |
| 7 | +on: |
| 8 | + push: |
| 9 | + branches: [ probe/win-unit-av ] |
| 10 | + |
| 11 | +jobs: |
| 12 | + probe: |
| 13 | + runs-on: windows-latest |
| 14 | + timeout-minutes: 60 |
| 15 | + steps: |
| 16 | + - uses: actions/checkout@v4 |
| 17 | + - uses: ./.github/actions/bootstrap-mcpp |
| 18 | + - name: this tree's engine, built by the pinned one |
| 19 | + shell: bash |
| 20 | + run: | |
| 21 | + set +e +o pipefail |
| 22 | + export MCPP_VENDORED_XLINGS=$(cygpath -w "$USERPROFILE/.xlings/subos/default/bin/xlings.exe") |
| 23 | + mcpp --version |
| 24 | + mcpp build > build.log 2>&1; echo "build: $?"; tail -3 build.log |
| 25 | + built=$(find target -name mcpp.exe | head -1); echo "built=$built" |
| 26 | + mkdir -p "$RUNNER_TEMP/new" && cp "$(dirname "$built")"/* "$RUNNER_TEMP/new/" 2>/dev/null |
| 27 | + "$RUNNER_TEMP/new/mcpp.exe" --version |
| 28 | + mv target target.boot |
| 29 | + - name: build the test with it and see what it does |
| 30 | + shell: bash |
| 31 | + continue-on-error: true |
| 32 | + run: | |
| 33 | + set +e +o pipefail |
| 34 | + export MCPP_VENDORED_XLINGS=$(cygpath -w "$USERPROFILE/.xlings/subos/default/bin/xlings.exe") |
| 35 | + new="$RUNNER_TEMP/new/mcpp.exe" |
| 36 | + map=$(cygpath -w "$RUNNER_TEMP/unit.map") |
| 37 | + export _LINK_="/map:$map" |
| 38 | + "$new" test test_pack_distribution > test.log 2>&1 |
| 39 | + grep -a -E 'Compiling compat|Cached compat|FAIL|test result|fault' test.log | head -12 |
| 40 | + ls -la "$RUNNER_TEMP/unit.map" 2>/dev/null |
| 41 | + "$new" test test_pack_distribution --print-launch > launch.json 2> launch.err |
| 42 | + exit 0 |
| 43 | + - name: which C library model each part was compiled for, and what the link says |
| 44 | + shell: bash |
| 45 | + continue-on-error: true |
| 46 | + run: | |
| 47 | + set +e +o pipefail |
| 48 | + export MCPP_VENDORED_XLINGS=$(cygpath -w "$USERPROFILE/.xlings/subos/default/bin/xlings.exe") |
| 49 | + llvm="$USERPROFILE/.mcpp/registry/data/xpkgs/xim-x-llvm/23.1.3/bin" |
| 50 | + exe=$(find target -name unit.exe | grep -v target.boot | head -1) |
| 51 | + dir=$(dirname "$(dirname "$exe")") |
| 52 | + echo "dir=$dir"; ls "$dir" | head -30 |
| 53 | + for n in $(find "$dir" -maxdepth 2 -name '*.ninja' | head -5); do |
| 54 | + echo "== $n"; grep -o 'fms-runtime-lib=[a-z_]*' "$n" | sort | uniq -c |
| 55 | + grep -o -E '(/|-)(MD|MT)d?\b' "$n" | sort | uniq -c | head |
| 56 | + done |
| 57 | + echo "== the C flags of the file and of one xz unit" |
| 58 | + grep -n -E '^(cflags|cxxflags|cc|cxx) ' "$dir/build.ninja" | cut -c1-700 |
| 59 | + grep -n -B1 -A6 'crc32_fast.o' "$dir/build.ninja" | cut -c1-900 | head -30 |
| 60 | + grep -n -A8 '^rule c_object' "$dir/build.ninja" | cut -c1-400 |
| 61 | + python - "$dir/compile_commands.json" <<'PY' |
| 62 | + import json, sys |
| 63 | + for e in json.load(open(sys.argv[1], encoding="utf-8")): |
| 64 | + f = e.get("file", "") |
| 65 | + if "crc32_fast" in f or f.endswith("compress_codecs.cpp"): |
| 66 | + c = e.get("command") or " ".join(e.get("arguments", [])) |
| 67 | + print("CDB", f); print(" ", c[:1500]) |
| 68 | + PY |
| 69 | + echo "== the default libraries each object names" |
| 70 | + for pat in 'compat_xz/.*crc32_fast' 'compat_zstd' 'compat_zlib' 'mcpplibs_os' 'mcpplibs_mtest' 'nlohmann' 'test_pack_distribution' 'compress_codecs' 'mwrap'; do |
| 71 | + o=$(find "$dir" -type f \( -name '*.o' -o -name '*.obj' \) | grep -E "$pat" | head -1) |
| 72 | + [ -n "$o" ] || { echo "$pat: no object"; continue; } |
| 73 | + echo "$pat: $o" |
| 74 | + "$llvm/llvm-readobj.exe" --coff-directives "$o" 2>/dev/null | tr ' ' '\n' | grep -i -E 'defaultlib|alternatename|failifmismatch' | sort -u | head -12 |
| 75 | + done |
| 76 | + echo "== every default library and mismatch statement of the build" |
| 77 | + find "$dir" -type f \( -name '*.o' -o -name '*.obj' \) > objs.txt; wc -l objs.txt |
| 78 | + while read -r o; do "$llvm/llvm-readobj.exe" --coff-directives "$o" 2>/dev/null | tr ' ' '\n' | grep -i -E 'defaultlib|failifmismatch.*RuntimeLibrary|alternatename' ; done < objs.txt | sort | uniq -c | sort -rn | head -40 |
| 79 | + echo "== the link, again, with what the linker says" |
| 80 | + rm -f "$exe" |
| 81 | + "$RUNNER_TEMP/new/mcpp.exe" test test_pack_distribution --no-run --verbose > relink.log 2>&1 |
| 82 | + grep -a -i -E 'warning|locally defined|lld-link' relink.log | cut -c1-300 | head -60 |
| 83 | + grep -a -c . relink.log; tail -5 relink.log | cut -c1-300 |
| 84 | + - name: where the call came from |
| 85 | + shell: bash |
| 86 | + continue-on-error: true |
| 87 | + run: | |
| 88 | + set +e +o pipefail |
| 89 | + exe=$(find target -name unit.exe | grep -v target.boot | head -1) |
| 90 | + echo "exe=$exe" |
| 91 | + cdb="" |
| 92 | + for c in "/c/Program Files (x86)/Windows Kits/10/Debuggers/x64/cdb.exe" "/c/Program Files/Windows Kits/10/Debuggers/x64/cdb.exe"; do |
| 93 | + [ -f "$c" ] && cdb="$c" |
| 94 | + done |
| 95 | + echo "cdb=$cdb" |
| 96 | + python - "$exe" <<'PY' > run.txt |
| 97 | + import json, sys |
| 98 | + text = open("launch.json", encoding="utf-8", errors="replace").read() |
| 99 | + start = text.find("{") |
| 100 | + argv = [] |
| 101 | + try: |
| 102 | + d = json.JSONDecoder().raw_decode(text[start:])[0] |
| 103 | + def walk(o): |
| 104 | + if isinstance(o, dict): |
| 105 | + for k, v in o.items(): |
| 106 | + if k in ("argv", "args", "command") and isinstance(v, list) and all(isinstance(x, str) for x in v): |
| 107 | + argv.append((k, v)) |
| 108 | + walk(v) |
| 109 | + elif isinstance(o, list): |
| 110 | + for v in o: walk(v) |
| 111 | + walk(d) |
| 112 | + except Exception as e: |
| 113 | + print("#", e) |
| 114 | + for k, v in argv: print(k, json.dumps(v)) |
| 115 | + PY |
| 116 | + cat run.txt |
| 117 | + cat > cdb.txt <<'CDB' |
| 118 | + sxe -c ".echo ==AV==; r; .echo ==STACK==; kn 12; .echo ==CALLER==; ub poi(@rsp) L3; .echo ==END==; q" av |
| 119 | + g |
| 120 | + q |
| 121 | + CDB |
| 122 | + sed -i 's/^ //' cdb.txt |
| 123 | + args=$(python - <<'PY' |
| 124 | + import json |
| 125 | + for line in open("run.txt"): |
| 126 | + if line.startswith(("argv ", "args ")): |
| 127 | + v = json.loads(line.split(" ", 1)[1]) |
| 128 | + print(" ".join(a for a in v if not a.lower().endswith("unit.exe"))) |
| 129 | + break |
| 130 | + PY |
| 131 | + ) |
| 132 | + echo "args=$args" |
| 133 | + w=$(cygpath -w "$exe") |
| 134 | + # The cases of this program, by the protocol's listing; then the one that faults. |
| 135 | + rm -f list.ndjson; MTEST_PROTOCOL=1 MTEST_REPORT="$(cygpath -w "$PWD/list.ndjson")" MTEST_MODE=list "$w" > /dev/null 2>&1 |
| 136 | + grep -a 'AStatedLevelIsHonoured' list.ndjson | head -3 |
| 137 | + python - <<'PY' |
| 138 | + import json |
| 139 | + ids = set() |
| 140 | + for line in open("list.ndjson", encoding="utf-8", errors="replace"): |
| 141 | + try: e = json.loads(line) |
| 142 | + except Exception: continue |
| 143 | + for k in ("id", "case", "name"): |
| 144 | + v = e.get(k) |
| 145 | + if isinstance(v, str) and "AStatedLevelIsHonoured" in v: ids.add(v) |
| 146 | + open("select.txt", "w", newline="\n").write("\n".join(sorted(ids)) + "\n") |
| 147 | + print("selected:", sorted(ids)) |
| 148 | + PY |
| 149 | + export MTEST_PROTOCOL=1 MTEST_REPORT="$(cygpath -w "$PWD/run.ndjson")" MTEST_SELECT="$(cygpath -w "$PWD/select.txt")" |
| 150 | + "$w" > direct.log 2>&1; echo "direct exit: $?"; tail -4 direct.log |
| 151 | + "$cdb" -cf cdb.txt "$w" > cdb1.log 2>&1 |
| 152 | + echo "cdb exit: $?"; wc -l cdb1.log |
| 153 | + slot=$(grep -a -o 'call qword ptr \[unit+0x[0-9a-f]*' cdb1.log | tail -1 | grep -o '0x[0-9a-f]*$'); echo "slot=$slot" |
| 154 | + n=$(grep -a -n '^==AV==' cdb1.log | head -1 | cut -d: -f1) |
| 155 | + echo "AV at line ${n:-none}" |
| 156 | + if [ -n "$n" ]; then |
| 157 | + sed -n "$((n > 12 ? n - 12 : 1)),$((n + 140))p" cdb1.log |
| 158 | + else |
| 159 | + tail -40 cdb1.log |
| 160 | + fi |
| 161 | + - name: the bytes around the caller, and what the objects leave undefined |
| 162 | + shell: bash |
| 163 | + continue-on-error: true |
| 164 | + run: | |
| 165 | + llvm="$USERPROFILE/.mcpp/registry/data/xpkgs/xim-x-llvm/23.1.3/bin" |
| 166 | + exe=$(find target -name unit.exe | grep -v target.boot | head -1) |
| 167 | + "$llvm/llvm-readobj.exe" --file-headers "$exe" | grep -i -E 'ImageBase|AddressOfEntryPoint|Characteristics' | head |
| 168 | + "$llvm/llvm-readobj.exe" --sections "$exe" | grep -E 'Name:|VirtualAddress|VirtualSize' | paste - - - | head -20 |
| 169 | + "$llvm/llvm-readobj.exe" --file-headers "$exe" | grep -A1 -E 'ImportTableRVA|ImportAddressTableRVA|DelayImport' | head -12 |
| 170 | + "$llvm/llvm-readobj.exe" --coff-imports "$exe" > imports.txt 2>&1 |
| 171 | + grep -c Symbol imports.txt; grep -n -E 'Name:|ImportAddressTableRVA' imports.txt | head -60 |
| 172 | + grep -n -i -E 'Symbol: (strlen|wcslen|memchr|memcmp|strchr|strcmp)' imports.txt | head |
| 173 | + # Who defines a C library name among the objects of the build. |
| 174 | + objs=$(find target -type f \( -name '*.o' -o -name '*.obj' \) | head -4000) |
| 175 | + echo "$objs" | wc -l |
| 176 | + "$llvm/llvm-nm.exe" -A $objs 2>/dev/null | grep -E ' [TtWwVvAaCcDdBbRr] (strlen|wcslen|memcpy|memset|memmove|memcmp|memchr|strcmp|strchr|__imp_strlen)$' | head -40 |
| 177 | + echo "--- weak or undefined-weak references to strlen" |
| 178 | + "$llvm/llvm-nm.exe" -A $objs 2>/dev/null | grep -E ' [wWvV] ' | grep -E 'strlen|__imp_' | head -20 |
| 179 | + - name: the names at the slots, by the link's map |
| 180 | + shell: bash |
| 181 | + continue-on-error: true |
| 182 | + run: | |
| 183 | + set +e +o pipefail |
| 184 | + map="$RUNNER_TEMP/unit.map" |
| 185 | + ls -la "$map" || exit 0 |
| 186 | + head -30 "$map" | cut -c1-200 |
| 187 | + grep -a -n -i '__imp_' "$map" | grep -a -v -i '\.dll\|\.lib:' | head -60 | cut -c1-220 |
| 188 | + echo "--- symbols the map places at the image's first byte or without a place" |
| 189 | + grep -a -n -E ' 0+140000000 | 00000000 ' "$map" | head -40 | cut -c1-220 |
0 commit comments