Skip to content

Unsupported assembly arguments silently select the host assembler #969

Closed

Description

@eas4ai

Classification

Confirmed forbidden silent fallback (audit finding BGO-007). Reproduced at 450733e with -O1 on 2026-09-03.

Source chain

build_graph_assemble_to_object (src/BuildGraphOps.w:162-172) reads only the first argument and sets a cross triple only when it begins triple= with a nonempty suffix. Unknown first arguments, bare triple=, and all additional arguments are silently ignored, selecting the host assembler. Both unsupported-option and triple= fixtures exited green and produced host x86-64 ELF relocatables — compiling for a different target than requested.

Repair boundary

Accept exactly zero args or exactly one nonempty canonical supported triple=<value> argument; reject every other spelling and extra argument before creating output; validate agreement with the target platform authority.

Activity

  1. ehartford commented on Sep 15, 2026

    @ehartford
    Contributor

    Review: reproduced

    Verdict. Established on current main. CompileAsmObject inspects only args[0], and only when it starts with triple= and has a non-empty suffix. Every other spelling (an unknown first argument, a bare triple=, a triple= in the second slot, or trailing extra arguments) is silently ignored and the host assembler runs, producing an object for the wrong target with exit 0. This is the silent-fallback class AGENTS.md forbids.

    Tested revision and compiler

    item value
    source main @ 5809ac1 (2026-09-14), contains the reported 450733e
    compiler out/release/bin/with, self-reports with v0.15.1.7-g66d9b27d8, built from this tree by the last battery (not the seed)
    platform macOS Darwin 25.6.0, arm64 (host objects are Mach-O arm64; the report's host produced x86-64 ELF, same defect)

    Repro

    f.s: .text / .globl _f / _f: / ret.

    use std.build
    pub fn build(ctx: BuildCtx) -> Build:
        var out = ctx.new_build()
        var a = target_new(.CompileAsmObject, "asm-unsupported", "f.s").output("out/unsupported.o")
        a = a.arg("unsupported-option")
        out = out.add_target(move a)
        var b = target_new(.CompileAsmObject, "asm-bare-triple", "f.s").output("out/bare.o")
        b = b.arg("triple=")
        out = out.add_target(move b)
        var c = target_new(.CompileAsmObject, "asm-second-slot", "f.s").output("out/second.o")
        c = c.arg("x").arg("triple=aarch64-unknown-linux-gnu")
        out = out.add_target(move c)
        var d = target_new(.CompileAsmObject, "asm-linux", "f.s").output("out/linux.o")
        d = d.arg("triple=aarch64-unknown-linux-gnu")
        out = out.add_target(move d)
        var e = target_new(.CompileAsmObject, "asm-extra", "f.s").output("out/extra.o")
        e = e.arg("triple=aarch64-unknown-linux-gnu").arg("bogus")
        out = out.add_target(move e)
        out
    
    target rc file out/*.o expected
    :asm-unsupported 0 Mach-O 64-bit object arm64 (host) rejected: unknown argument
    :asm-bare-triple 0 Mach-O arm64 (host) rejected: empty triple
    :asm-second-slot 0 Mach-O arm64 (host) either honour the Linux triple or reject x; never silently host
    :asm-linux (control) 0 ELF 64-bit relocatable, ARM aarch64 correct
    :asm-extra 0 ELF aarch64 triple honoured, but bogus silently dropped; should be rejected

    Root cause (read in source, confirmed by the runs)

    src/BuildGraphOps.w:176-184: the op reads target.args.get(0), tests starts_with("triple="), and falls through to build_graph_rt_assemble_to_object (host) whenever the resulting asm_triple is empty. No branch diagnoses an unrecognised or extra argument. No decision-log entry sanctions a host fallback.

    Spec / docs

    docs/with-build.md line 549 documents the kind only as "Assemble source to an object file"; the triple= argument is documented only by the comment at :174-175 and by its use in build.w:141 and build/wo.w:274. AGENTS.md §No Silent Fallbacks: "'Simplifying' a construct into something that compiles but behaves differently from the source" is forbidden; an object for the wrong target is exactly that.

    Related PRs

    None since 450733e touch this op (git log -S"triple=" on the file is empty). No open PR touches it.

    Would I champion a fix? Yes.

    It is cheap and it guards the cross-target runtime lanes (cross/<tag>/fiber_asm.o), where a typo in build.w would today link a host object into a cross bundle. Acceptance criteria:

    1. Accept exactly zero arguments or exactly one triple=<non-empty> argument; anything else fails before mkdir_p with a diagnostic naming the target and the offending argument.
    2. The triple is validated against the target-platform authority (the same table Target.target(...) uses), so an unknown or unsupported triple is rejected rather than handed to LLVM.
    3. A behaviour test covers the five spellings above and asserts object format for the accepted ones.

    Untested

    Linux and Windows hosts not executed. Whether build_graph_rt_assemble_to_object_for_triple itself rejects a malformed non-empty triple was not probed; criterion 2 covers it.

  2. ehartford commented on Sep 15, 2026

    @ehartford
    Contributor

    Correction to the compiler-identity line above. The binary I ran, out/release/bin/with reporting with v0.15.1.7-g66d9b27d8, was built from commit 66d9b27 (2026-09-05), not from the HEAD I inspected (5809ac1). The source I cited and the behaviour I observed are for the functions in this issue, which are unchanged between those two commits apart from PR #1082's swap of a POSIX path[0] == '/' test for the shared runtime_path_is_absolute predicate (identical for the inputs used here). I verified that with git diff 66d9b27d8 5809ac10 -- src/BuildGraphOps.w src/BuildGraphSupport.w before posting. The verdict stands; the identity line should read: binary built from 66d9b27, source links pinned to 5809ac1.

  3. ehartford commented on Oct 25, 2026

    @ehartford
    Contributor

    Triage 2026-10-25, with v0.15.3.0 (main a261b65): reproduced. build_graph_assemble_to_object (src/BuildGraphOps.w:162) still reads only a nonempty triple= first argument.

    target_new(.CompileAsmObject, "bogus", "f.s").output("out/bogus.o").arg("--unsupported-option")
    target_new(.CompileAsmObject, "emptytriple", "f.s").output("out/empty.o").arg("triple=")
    target_new(.CompileAsmObject, "extra", "f.s").output("out/extra.o").arg("triple=x86_64-apple-macosx").arg("ignored")
    # all three: rc=0
    $ file out/*.o
    out/bogus.o: Mach-O 64-bit object arm64
    out/empty.o: Mach-O 64-bit object arm64
    out/extra.o: Mach-O 64-bit object x86_64
    

    pre-release: a silent fallback that assembles for the wrong target; the fix is argument validation in one function.

  4. ehartford commented on Oct 26, 2026

    @ehartford
    Contributor

    Fixed on main by 47c3633 (#2707), merged through stack 7 whose seed-driven battery was green on its top (gate, uat and survey all green). Regression test: test/behavior/behav_969_asm_object_args_checked.w.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions