Skip to content

Support response files with quoted args #479

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 2 commits into
base: master
Choose a base branch
from

Conversation

faximan
Copy link

@faximan faximan commented Apr 9, 2025

#245 introduced a regression where clang response files were read and expanded into args on the command line.

This was a regression because response files support quoted args:

$ cat args
"-O3"
"main.cc"
$ clang @args  # success

but cc_wrapper.sh will expand this to

$ clang '"-O3"' '"main.cc"'
clang: error: no such file or directory: '"-O3"'
clang: error: no such file or directory: '"main.cc"'
clang: error: no input files

This is not just a theoretical concern: golang (which is using a c++ linker for its cgo integration) is explicitly quoting its strings in the response files: https://github.com/golang/go/blob/ecc06f0db79193a4fe16138148c7eb26d9af96f1/src/cmd/link/internal/ld/lib.go#L2123-L2124

This PR solves this by processing what's inside the quotes instead of the string as a whole. As a bonus, this will also support multiple (quoted or unquoted) args on a single line, which is something clang supports but toolchains_llvm does not. The fix is inspired by https://stackoverflow.com/a/17346794 but modified to support args starting with $ (need to be passed through).

Note that another related fix is #430, which passes through the response files to clang. That PR would also be great to support very long arg lists, but we still need this PR to properly call sanitize_option for quoted args.

@fmeum fmeum enabled auto-merge (squash) April 9, 2025 19:57
@fmeum fmeum disabled auto-merge April 9, 2025 20:29
@fmeum
Copy link
Member

fmeum commented Apr 9, 2025

CI is red

@faximan
Copy link
Author

faximan commented Apr 9, 2025

CI is red

This was because some args are like $ORIGIN/_solib_k8/_U_A_Atoolchains_Ullvm++llvm+llvm_Utoolchain_S_S_Comp___Ulib with $ORIGIN was now being expanded instead of passed through. I've proposed a fix but I am not super happy with the readability.

dfreese added a commit to dfreese/toolchains_llvm that referenced this pull request Apr 9, 2025
The cc_wrapper.sh scripts inspects response files and sanitizes each
line within them.  How the logic is structured currently causes all of
these arguments to the be directly used later in the script.  This can
run into argument overflows.  It can also run into problems where
quoting in response files and from args is treated differently.

This addresses some of the comments in bazel-contrib#430, namely cleaning up files
and not overwriting the input files.  I have not tried to apply a
threshold here as that is best left up to the tooling that previously
decided to use response files, which can cause difficult to debug
changes in behavior.

This conflicts with bazel-contrib#479, but is trying to address the same underlying
problem of quoted arguments in response files as the result of golang's
link actions.

Fixes bazel-contrib#421
fmeum pushed a commit that referenced this pull request Apr 10, 2025
The cc_wrapper.sh scripts inspects response files and sanitizes each
line within them. How the logic is structured currently causes all of
these arguments to the be directly used later in the script. This can
run into argument overflows. It can also run into problems where quoting
in response files and from args is treated differently.

This addresses some of the comments in #430, namely cleaning up files
and not overwriting the input files. I have not tried to apply a
threshold here as that is best left up to the tooling that previously
decided to use response files, which can cause difficult to debug
changes in behavior.

This conflicts with #479, but is trying to address the same underlying
problem of quoted arguments in response files as the result of golang's
link actions.

Fixes #421
@fmeum
Copy link
Member

fmeum commented Apr 11, 2025

@faximan Could you rebase and resolve the conflict?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants