{"record":{"id":"79fc1a42284ad3ad","repo":"rust-lang/rust","slug":"llvm-readelf-failed-for-binary-binary-with-outpu","errorCode":null,"errorMessage":"llvm-readelf failed for binary {binary} with output {stdout}","messagePattern":"llvm-readelf failed for binary (.+?) with output (.+?)","errorType":"exception","errorClass":"Exception","httpStatus":null,"severity":"critical","filePath":"src/ci/docker/scripts/fuchsia-test-runner.py","lineNumber":198,"sourceCode":"                verbose=test_env[\"verbose\"],\n            )\n\n    def build_id(self, binary):\n        llvm_readelf = Path(self.toolchain_dir).joinpath(\"bin\", \"llvm-readelf\")\n        process = subprocess.run(\n            args=[\n                llvm_readelf,\n                \"-n\",\n                \"--elf-output-style=JSON\",\n                binary,\n            ],\n            stdout=subprocess.PIPE,\n            stderr=subprocess.STDOUT,\n        )\n        if process.returncode:\n            e = f\"llvm-readelf failed for binary {binary} with output {process.stdout}\"\n            self.env_logger.error(e)\n            raise Exception(e)\n\n        try:\n            elf_output = json.loads(process.stdout)\n        except Exception as e:\n            e.add_note(f\"Failed to read JSON from llvm-readelf for binary {binary}\")\n            e.add_note(f\"stdout: {process.stdout}\")\n            raise\n\n        try:\n            note_sections = elf_output[0][\"NoteSections\"]\n        except Exception as e:\n            e.add_note(\n                f'Failed to read \"NoteSections\" from llvm-readelf for binary {binary}'\n            )\n            e.add_note(f\"elf_output: {elf_output}\")\n            raise\n\n        for entry in note_sections:","sourceCodeStart":180,"sourceCodeEnd":216,"githubUrl":"https://github.com/rust-lang/rust/blob/7088e4b63a9516ebfbfe2ab2d999cf01a528ac14/src/ci/docker/scripts/fuchsia-test-runner.py#L180-L216","documentation":"Raised by TestEnvironment.build_id() when the llvm-readelf subprocess returns a non-zero exit code while extracting ELF notes from a binary. The runner shells out to {toolchain_dir}/bin/llvm-readelf -n --elf-output-style=JSON to read the GNU build-id, and any non-zero returncode is treated as fatal because the build-id is required to name and locate the stripped test package. The message echoes the captured stdout so the underlying llvm-readelf diagnostic is visible.","triggerScenarios":"Calling TestEnvironment.build_id(binary) (indirectly via the 'run' subcommand, fuchsia-test-runner.py:696) where {toolchain_dir}/bin/llvm-readelf is missing, not executable, the wrong architecture, or the passed binary is not a valid ELF object (corrupt, truncated, wrong format). process.returncode being truthy at line 195 is the sole condition.","commonSituations":"Pointing --toolchain-dir at a build that lacks llvm-readelf; passing a host x86 binary to an arm64 llvm-readelf (or vice versa); the Rust build produced a partially-linked or non-ELF artifact; llvm-readelf version mismatch where the JSON style flag is unsupported.","solutions":["Verify the binary is a valid ELF for the target: run `llvm-readelf -n {binary}` manually and confirm it prints a .note.gnu.build-id section.","Confirm {toolchain_dir}/bin/llvm-readelf exists and is executable, and that --toolchain-dir on the 'start' subcommand points at a complete LLVM toolchain bin dir.","Rebuild the Rust toolchain so the test binary is fully linked (look for partial link / LTO failures in the build log).","Upgrade or align the LLVM version so `--elf-output-style=JSON` is supported and emits valid JSON."],"exampleFix":"// before\n$ fuchsia-test-runner.py run <n> <bin_path> <shared_libs...>\n# llvm-readelf failed for binary ... with output b'...'\n\n// after - run llvm-readelf manually first to confirm the binary is valid\n$ $TOOLCHAIN_DIR/bin/llvm-readelf -n --elf-output-style=JSON <bin_path> | head\n# then, if it prints valid JSON with a build-id, re-run the test runner","handlingStrategy":"validation","validationCode":"import os, subprocess\nfrom pathlib import Path\n\ndef validate_for_build_id(toolchain_dir, binary):\n    readelf = Path(toolchain_dir) / \"bin\" / \"llvm-readelf\"\n    if not readelf.is_file() or not os.access(readelf, os.X_OK):\n        return False, f\"llvm-readelf missing/not executable at {readelf}\"\n    if not Path(binary).is_file():\n        return False, f\"binary missing: {binary}\"\n    proc = subprocess.run([str(readelf), \"-n\", str(binary)],\n                          stdout=subprocess.PIPE, stderr=subprocess.STDOUT)\n    return proc.returncode == 0, (proc.stdout.decode(errors=\"replace\") if proc.returncode else \"ok\")\n\nok, msg = validate_for_build_id(env.toolchain_dir, bin_path)\nif not ok:\n    raise SystemExit(f\"refusing to run: {msg}\")\nenv.build_id(bin_path)","typeGuard":"null","tryCatchPattern":"try:\n    build_id = test_env.build_id(bin_path)\nexcept Exception as e:\n    # log and surface the llvm-readelf output already embedded in the message\n    logging.error(\"build_id extraction failed: %s\", e)\n    raise","preventionTips":["Always point --toolchain-dir at a complete LLVM bin directory containing llvm-readelf.","Validate the test binary is a full ELF for the target before invoking run.","Pin the LLVM/llvm-readelf version so --elf-output-style=JSON output stays stable."],"tags":["fuchsia","llvm","elf","subprocess","toolchain"],"backgroundTag":null,"analyzedSha":"7088e4b63a9516ebfbfe2ab2d999cf01a528ac14","analyzedAt":"2026-08-10T14:17:03.603Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-14T00:17:10.932Z"}