Skip to content
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

gcc-wrapper doesn't handle arguments specified in response files #11762

Closed
peti opened this issue Dec 16, 2015 · 16 comments
Closed

gcc-wrapper doesn't handle arguments specified in response files #11762

peti opened this issue Dec 16, 2015 · 16 comments

Comments

@peti
Copy link
Member

peti commented Dec 16, 2015

According to https://gcc.gnu.org/wiki/Response_Files, gcc reads for every argument of the form @path the file path and inserts its contents in the command-line array as if those flags had been specified directly. This mechanism is supposed to be used to work around system limitations with regard to command-line length.

The Haskell compiler GHC has picked up the habit of using those response files for all its linker arguments, and it's now broken on NixOS as a result, apparently because all kinds of "rpaths" are no longer provided correctly.

My theory is that before that patch, gcc-wrapper would catch the -L/path/... style arguments and handle them correctly, but now it no longer does, because those flags are hidden inside of a response file. Does that sound plausible?

Cc: @vcunat

@vcunat
Copy link
Member

vcunat commented Dec 16, 2015

My guess is that something isn't quoted properly in the wrapper, as @ is certainly a bash-active character.

peti added a commit that referenced this issue Dec 16, 2015
The new GHC version contains a patch [1] that passes linker and compiler flags
to GCC via response files rather than directly on the command-line. This is
supposed to be beneficial on Windows and other platforms that have trouble
dealing with long argument lists. On NixOS, however, this feature breaks the
flag handling provided by gcc-wrapper [2] and therefore causes the entire GHC
build to fail.

This issue has been reported upstream at [3]. It's not clear yet how to remedy
this problem, but until we've figured that out we just don't pass compiler flags
in response files on NixOS to fix #10752.

[1] ghc/ghc@296bc70
[2] #11762
[3] https://ghc.haskell.org/trac/ghc/ticket/11147
@vcunat
Copy link
Member

vcunat commented Dec 30, 2015

So, the ghc issue was worked around but this issue itself probably lasts. (Correct me if I'm wrong.)

@peti
Copy link
Member Author

peti commented Dec 30, 2015

Yes, I've patched ghc to avoid using response files. If it does, however, then the compiler won't work anymore, clearly because our wrapper doesn't cope with response files correctly. The symptom we observe is that glibc libraries like rt are linked without getting their "rpath" hard-coded. The resulting binaries will then fail at run-time.

peti added a commit that referenced this issue Jan 21, 2016
The new GHC version contains a patch [1] that passes linker and compiler flags
to GCC via response files rather than directly on the command-line. This is
supposed to be beneficial on Windows and other platforms that have trouble
dealing with long argument lists. On NixOS, however, this feature breaks the
flag handling provided by gcc-wrapper [2] and therefore causes the entire GHC
build to fail.

This issue has been reported upstream at [3]. It's not clear yet how to remedy
this problem, but until we've figured that out we just don't pass compiler flags
in response files on NixOS to fix #10752.

[1] ghc/ghc@296bc70
[2] #11762
[3] https://ghc.haskell.org/trac/ghc/ticket/11147

(cherry picked from commit a421e7b)
@corngood
Copy link
Contributor

I just ran into this with one of my own projects. It's trivial for me to reproduce:

test.rsp: test.cpp
test.cpp: int main() { return 0; }

$ g++ test.cpp
$ ./a.out
$ g++ @test.rsp
$ ./a.out
./a.out: error while loading shared libraries: libstdc++.so.6: cannot open shared object file: No such file or directory

In the second case the RPATH is missing as you described.

Before I get into fixing it, has anyone done any work on it? I'll probably just start with unpacking the response files into params in ld-wrapper.sh (then probably move it into utils) unless you have a better idea. I don't see anything in there that looks like it's meant to handle @.

@peti
Copy link
Member Author

peti commented Oct 30, 2016 via email

@vcunat vcunat closed this as completed in 1ad1edb Nov 7, 2016
@peti peti changed the title Does gcc-wrapper deal with arguments specified in response files? gcc-wrapper doesn't handle arguments specified in response files Nov 9, 2016
@peti
Copy link
Member Author

peti commented Nov 9, 2016

I tried building ghc without the "no-response-file" patch in d41c660, and the build is still broken even after 1ad1edb: http://hydra.cryp.to/build/2053991/nixlog/2/raw. The error looks like some "-L" argument passed during the build isn't translated into an "rpath" linker argument to hard-code the path.

@peti peti reopened this Nov 9, 2016
@corngood
Copy link
Contributor

@peti It looks like arguments such as -optl-Wl,'$ORIGIN' are causing the problem. It must be evaluating the variable when the response file is read, because it's passing -opt-Wl,'' to the compiler.

I'll see what I can do in cc-wrapper.

Thanks

@corngood corngood mentioned this issue Nov 19, 2016
7 tasks
@corngood
Copy link
Contributor

@peti. I think I have a fix for this. Could you take a look at #20561?

Is it possible to use hydra to check for regressions before merging?

corngood pushed a commit to corngood/nixpkgs that referenced this issue Nov 20, 2016
@peti
Copy link
Member Author

peti commented Nov 25, 2016

@corngood, Hydra is building the new code at http://hydra.nixos.org/jobset/nixpkgs/staging. Unfortunately, the staging branch appears to be in bad shape right now; there're plenty of errors that seem unrelated. 😞

@vcunat
Copy link
Member

vcunat commented Nov 26, 2016

It seems almost all the failures is just a failing guile test on i686-linux which I can't reproduce locally (probably appears randomly).

@vcunat
Copy link
Member

vcunat commented Nov 26, 2016

Hmm, merging master to staging turned out to be a huge rebuild in itself :-/ so I squeezed in a stdenv rebuild.

@peti
Copy link
Member Author

peti commented Dec 19, 2016

I suppose we can close this issue? The ghc binaries on master seem to work fine now even when use of response files is enabled!

@corngood, @vcunat, do you happen to know whether all relevant fixes for gcc-wrapper have been ported to the release-16.09 branch?

@peti peti self-assigned this Dec 19, 2016
@vcunat
Copy link
Member

vcunat commented Dec 23, 2016

I can't say I know.

@corngood
Copy link
Contributor

It's fixed in 175461e, which doesn't seem to be merged to 16.09.

@corngood
Copy link
Contributor

If you do want to cherry-pick, you need 1ad1edb and 175461e, but it's probably not worth doing unless you want the ghc change that depends on it (02668d6).

@peti
Copy link
Member Author

peti commented Jan 9, 2017

I'll merge those fixes to release-16.090 as d59ed53d8e33e4743d5ed9486c54692ed29e289c and 69454bd15339e1ffd81a7a4e8b72c4fd97c7219a soon'ish. I'm just waiting for test build results from http://hydra.nixos.org/jobset/nixpkgs/haskell-updates.

@peti peti closed this as completed Jan 9, 2017
peti pushed a commit to peti/nixpkgs that referenced this issue Jan 9, 2017
Fixes NixOS#11762

(cherry picked from commit 1ad1edb)
blajos pushed a commit to blajos/nixpkgs that referenced this issue Jan 23, 2017
Fixes NixOS#11762

(cherry picked from commit 1ad1edb)
adrianpk added a commit to adrianpk/nixpkgs that referenced this issue May 31, 2024
The new GHC version contains a patch [1] that passes linker and compiler flags
to GCC via response files rather than directly on the command-line. This is
supposed to be beneficial on Windows and other platforms that have trouble
dealing with long argument lists. On NixOS, however, this feature breaks the
flag handling provided by gcc-wrapper [2] and therefore causes the entire GHC
build to fail.

This issue has been reported upstream at [3]. It's not clear yet how to remedy
this problem, but until we've figured that out we just don't pass compiler flags
in response files on NixOS to fix NixOS#10752.

[1] ghc/ghc@296bc70
[2] NixOS#11762
[3] https://ghc.haskell.org/trac/ghc/ticket/11147

(cherry picked from commit a421e7b)
adrianpk added a commit to adrianpk/nixpkgs that referenced this issue May 31, 2024
Fixes NixOS#11762

(cherry picked from commit 1ad1edb)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants