build-bom icon indicating copy to clipboard operation
build-bom copied to clipboard

build-bom breaks `-cc1`-based compilation commands

Open Ptival opened this issue 4 months ago • 0 comments

I was trying to use build-bom on a fairly simple Rust-driven clang invocation, and it was failing with what seemed like weird messages:

    clang-18: error: unknown argument: '-cc1'
    clang-18: error: unknown argument '-triple'; did you mean '-Xclang -triple'?
    clang-18: error: unknown argument '-emit-obj'; did you mean '-Xclang -emit-obj'?
...

I think I figured out what went wrong:

[2025-08-06T16:12:09Z ERROR bom::bom::bitcode] Error attaching bitcode:
Error Some(1) running command "Executable { exe_file: \"/usr/bin/clang-18\",
base_args: [\"-emit-llvm\", \"-c\"],
inp_file: \"append\", out_file: \"option(-o)\" }"
["-emit-llvm", "-c", "-g", "-O0", "-Wno-error=unused-command-line-argument",
"-Wno-error=implicit-function-declaration", "-cc1", "-triple", "-emit-obj", ...

It turns out that the (poorly documented) -cc1 flag is very special, and needs to be the very first argument clang receives to switch from GCC-compatible CLI args to Clang-only CLI args.

And it seems build-bom inserted its CLI args before -cc1, thus breaking the whole thing.

So I think ideally build-bom should detect -cc1 and make sure to keep it preserved in first position.

Ptival avatar Aug 06 '25 16:08 Ptival