Skip to content

code_size: membrowse link_command crashes the run on non-UTF-8 ninja output #4087

Closed

Description

@hathach

Originating PR: #4086

code_size's membrowse engine crashes the whole run instead of failing per elf when the ninja -t commands output is not UTF-8 (Windows, ninja < 1.11 or a non-UTF-8 ninja -t wincodepage).

Evidence (verified at PR head e538050, severity low):

  • tools/membrowse_cli.py:28 (unchanged by code_size: run report and diff on Windows #4086, present on master c391fe9): subprocess.run([ninja, '-C', build_dir, '-t', 'commands', '-s', rel], capture_output=True, text=True). Under PYTHONUTF8 (required on Windows) text=True decodes strictly as UTF-8.
  • CMake v4.1.2 writes build.ninja in the ANSI code page when ninja < 1.11 or ninja -t wincodepage is not UTF-8 (cmGlobalNinjaGenerator.cxx:814-822, 829-872, 1086-1087). A non-ASCII checkout path (the -T linker script lives under it) then yields non-UTF-8 output.
  • On Windows Popen decodes in a reader thread: the UnicodeDecodeError is printed by threading.excepthook and r.stdout is None, so r.stdout.strip() (line 33) raises AttributeError (UnicodeDecodeError on POSIX). Neither is RuntimeError, so it passes report()'s per-elf except RuntimeError in tools/code_size.py, escapes pool.map, and generate_sizes only catches FileNotFoundError. The whole run ends in a traceback instead of a per-elf error naming the remedy.
  • code_size: run report and diff on Windows #4086 documents the setup as unsupported (code-size SKILL.md: a non-ASCII checkout, CMake or toolchain path needs ninja >= 1.11 whose ninja -t wincodepage reports UTF-8) and gives build.ninja reads an explicit RuntimeError with that remedy. This path in link_command is not covered.

Remaining work: in link_command, turn a decode failure (UnicodeDecodeError/AttributeError, or read bytes and decode explicitly) into a RuntimeError with the same ninja >= 1.11 remedy. No encoding fallback (maintainer decision: Windows requires PYTHONUTF8, no encoding code). Add a unit test.

Why deferred: the line predates #4086 and that PR's scope is the Windows enablement it adds; the setup is documented unsupported, so the impact is a traceback instead of the documented message.

Activity

  1. added
    follow-upDeferred work from a PR or investigation
    on Oct 3, 2026
  2. added a commit that references this issue on Oct 5, 2026
    74f6ffd
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    Prio 📌follow-upDeferred work from a PR or investigation

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions