-
Notifications
You must be signed in to change notification settings - Fork 4.1k
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
Be less aggressive in interpreting flags as response files #13044
Conversation
Both -Xlinker and -install_name will often receive flags starting with `@`, specifically `@loader_path` or `@rpath`. Bazel 4.0 started interpreting those as response files which broke our build. This PR addresses this by hardcoding those flags. This is a pretty ugly solution so I’m very open to better ideas. That said, there is some precedence for doing that in [rules-haskell](https://github.com/tweag/rules_haskell/blob/e8623a8c5ea502fbe6286d8ae5fb58f4915e92c5/haskell/private/cc_wrapper.py.tpl#L448).
The thought at the time we made this decision was that this form of linker flag should be replaced with -Wl,-install_name,@foo |
Those flags are not under our control. In this case, it is the Haskell compiler GHC that is passing them https://gitlab.haskell.org/ghc/ghc/-/blob/ab1b49108e2665eb9ccdccffde0099d1785315ee/compiler/main/SysTools.hs#L376 I do agree that in an ideal world, changing the flags would be preferable but I think this is a good example that this isn’t really feasible for users in a lot of cases. |
I guess one option would be for rules_haskell’s cc wrapper to do the rewriting but I’m not sure that’s better than handling it in Bazel itself. |
Ah interesting. I do think it would be safe to make that compiler change, but that wouldn't solve this in the short term. At least 1 problem with this change is that there are a few other places that also duplicate this logic, see the original change and conversation for details #12265 |
@keith GHC's reasoning for preferring
|
ugh!! thanks for the link. I've never heard that buck could produce commas in paths, any idea where I can see more details on that? FWIW I think a change like this would be accepted as long as it covered all the cases (although I'm not a googler so I can't make that call overall), it's just we didn't have a compelling reason to do the extra work in the previous case, so we didn't want to enumerate a list of all possible flags that could have a |
@keith I'm not familiar with Buck myself. What I understand, Buck can append comma separated flavors to targets and file names, e.g.
The ones I'm aware of are |
I actually meant which scripts not which args. There are 3 scripts which have similar logic for this unfortunately. But it depends on what rules_haskell calls through how much of an issue that will be. I believe I solved this for wrapped_clang already with this logic bazel/tools/osx/crosstool/wrapped_clang.cc Lines 275 to 278 in caf1355
You should be able to implement something similar in tools/cpp/osx_cc_wrapper.sh.tpl and tools/cpp/osx_cc_wrapper.sh (both are used in different places unfortunately) Instead of specifying the flags that can have arguments starting with diff --git i/tools/cpp/osx_cc_wrapper.sh w/tools/cpp/osx_cc_wrapper.sh
index 8c9c111a75..23604c7c7e 100755
--- i/tools/cpp/osx_cc_wrapper.sh
+++ w/tools/cpp/osx_cc_wrapper.sh
@@ -53,7 +53,7 @@ function parse_option() {
# let parse the option list
for i in "$@"; do
- if [[ "$i" = @* ]]; then
+ if [[ "$i" = @* && -r "$i" ]]; then
while IFS= read -r opt
do
parse_option "$opt" |
Oh, I see, sorry, misread.
Just for completeness, rules_haskell doesn't call any of these scripts explicitly. It calls the C compiler provided by Bazel's cc toolchain. I.e.
That may be one of Bazel's cc-wrappers. So far
Looks good to me. |
@keith @cocreature I've opened #13148 to replace this PR with @keith's suggestions from above applied. |
Closes #13044 Applies the changes suggested in #13044 (comment) Not all arguments starting with `@` represent response files, e.g. `-install_name @rpath/...` or `-Xlinker -rpath -Xlinker @loader_path/...` do not refer to response files and attempting to read them as such will fail the build. Users don't always have control over these arguments, meaning transforming them to `-Wl,-install_name,@rpath/...` or `-Wl,-rpath,@loader_path/...` is not always an option. E.g. as described in #13044 (comment) where these flags are emitted by the Haskell compiler GHC (see #13044 (comment) for their reasoning). With this change `osx_cc_wrapper` will only interpret arguments starting with `@` as response files if the corresponding file exists and is readable. This is analogous to the behavior defined in `wrapped_clang.cc`. See #13044 (comment) for discussion. Closes #13148. PiperOrigin-RevId: 436207868
@bazel-io fork 5.1 |
Closes bazelbuild#13044 Applies the changes suggested in bazelbuild#13044 (comment) Not all arguments starting with `@` represent response files, e.g. `-install_name @rpath/...` or `-Xlinker -rpath -Xlinker @loader_path/...` do not refer to response files and attempting to read them as such will fail the build. Users don't always have control over these arguments, meaning transforming them to `-Wl,-install_name,@rpath/...` or `-Wl,-rpath,@loader_path/...` is not always an option. E.g. as described in bazelbuild#13044 (comment) where these flags are emitted by the Haskell compiler GHC (see bazelbuild#13044 (comment) for their reasoning). With this change `osx_cc_wrapper` will only interpret arguments starting with `@` as response files if the corresponding file exists and is readable. This is analogous to the behavior defined in `wrapped_clang.cc`. See bazelbuild#13044 (comment) for discussion. Closes bazelbuild#13148. PiperOrigin-RevId: 436207868 (cherry picked from commit efb2b80)
Closes #13044 Applies the changes suggested in #13044 (comment) Not all arguments starting with `@` represent response files, e.g. `-install_name @rpath/...` or `-Xlinker -rpath -Xlinker @loader_path/...` do not refer to response files and attempting to read them as such will fail the build. Users don't always have control over these arguments, meaning transforming them to `-Wl,-install_name,@rpath/...` or `-Wl,-rpath,@loader_path/...` is not always an option. E.g. as described in #13044 (comment) where these flags are emitted by the Haskell compiler GHC (see #13044 (comment) for their reasoning). With this change `osx_cc_wrapper` will only interpret arguments starting with `@` as response files if the corresponding file exists and is readable. This is analogous to the behavior defined in `wrapped_clang.cc`. See #13044 (comment) for discussion. Closes #13148. PiperOrigin-RevId: 436207868 (cherry picked from commit efb2b80) Co-authored-by: Andreas Herrmann <[email protected]>
Both -Xlinker and -install_name will often receive flags starting with
@
, specifically@loader_path
or@rpath
. Bazel 4.0 startedinterpreting those as response files which broke our build.
This PR addresses this by hardcoding those flags. This is a pretty
ugly solution so I’m very open to better ideas. That said, there is
some precedence for doing that in
rules-haskell.