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

Response files provided by pipes break build-bom

Open travitch opened this issue 3 years ago • 0 comments

Clang supports response files, which are special "file" arguments prefixed by @ that actually contain the command line arguments that clang should be invoked with. This facility is generally used to support long command lines that exceed system capabilities (especially on Windows). In unusual cases, the file containing the arguments could actually be a pipe. In that case, build-bom generate-bitcode runs the original compilation command, which "drains" the pipe. When it re-runs the command to generate bitcode, the pipe is empty and clang receives no arguments, which means that no bitcode is generated.

This has been observed by @kquick on Nix, which has a wrapper script around clang that uses this pattern.

We can fix this by noticing cases where clang is being invoked with a response file that points to a pipe. If we see that, drain the pipe in build-bom before invoking the original command and save the contents of the response file. Then persist the contents to a temporary file and tweak the execve arguments to the original command to point to the temporary file. When we run the bitcode generation command, just reuse that same temporary file. Note that there is a bit of a technical challenge here, as the filename must exist in the process. We will likely need to both allocate storage for the filename and poke the path byte-by-byte (or via /dev/mem) into the process. This isn't conceptually difficult, but will take effort to implement.

travitch avatar Jul 01 '21 04:07 travitch