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

Fix parsing @args.rsp compiler arguments #25205

Merged
merged 1 commit into from May 1, 2017
Merged

Conversation

orivej
Copy link
Contributor

@orivej orivej commented Apr 25, 2017

I tried to build a copy of llvm with -DBUILD_SHARED_LIBS=ON -DLLVM_BUILD_LLVM_DYLIB=OFF but the build failed because nix incorrectly expanded .rsp file contents: -Wl,-rpath,"\$ORIGIN/../lib" in a .rsp becomes -Wl,-rpath,\/../lib in the arguments.

This patch introduces a parser that follows gcc documentation:

Read command-line options from FILE. The options read are inserted in place of the original @file option. If FILE does not exist, or cannot be read, then the option will be treated literally, and not removed.
Options in FILE are separated by whitespace. A whitespace character may be included in an option by surrounding the entire option in either single or double quotes. Any character (including a backslash) may be included by prefixing the character to be included with a backslash. The FILE may itself contain additional @file options; any such options will be processed recursively.

Related: #11762

@mention-bot
Copy link

@orivej, thanks for your PR! By analyzing the history of the files in this pull request, we identified @edolstra, @corngood and @peti to be potential reviewers.

@edolstra
Copy link
Member

Looks good to me (though bash is not an ideal language for writing parsers...). It should be applied to the staging branch though.

@orivej orivej changed the base branch from master to staging April 25, 2017 13:30
@orivej
Copy link
Contributor Author

orivej commented Apr 25, 2017

Changed target branch to staging. I though of writing in another language, but it seemed to be difficult to integrate with utils.sh/cc-wrapper.sh/ld-wrapper.sh.

@7c6f434c
Copy link
Member

7c6f434c commented May 1, 2017

Looks good for me, too; I can only guess what performance would be, but probably better on average than forking a compiled parser.

@7c6f434c 7c6f434c merged commit f3b45f8 into NixOS:staging May 1, 2017
@orivej
Copy link
Contributor Author

orivej commented May 1, 2017

IMHO performance is acceptable (faster than a subsequent compiler, and .rsp files are rarely used), although a compiled parser would beat it: you can perform a realistic test with

source utils.sh
seq -f argument%.0f 100 > test.rsp
expandResponseParams @test.rsp

On my machine this 1KB file is parsed in 0.13 seconds.

@7c6f434c
Copy link
Member

7c6f434c commented May 1, 2017 via email

@pbogdan
Copy link
Member

pbogdan commented Jun 13, 2017

This seems to be affecting linking times of Haskell projects (which are being linked with gcc and as I understand always linked using response files - https://ghc.haskell.org/trac/ghc/ticket/8596). On a project that otherwise builds in under one minute (not including dependencies) this change adds over a minute of overhead. Would it be worth filing an issue, or would that kind of overhead not be considered substantial enough? Happy to provide an .rsp file I extracted during the build (36KB, ~ 500 lines).

@orivej
Copy link
Contributor Author

orivej commented Jun 13, 2017

Could you upload an .rsp on https://gist.github.com/ ?
I observed that by far the slowest operation in the parser is array extension: rsp+=("$arg"). Maybe there is a simple way to optimize it.

@corngood
Copy link
Contributor

@pbogdan Could you run the timing experiment @orivej described above, using both the synthetic test and your own response file, and post the times?

@pbogdan
Copy link
Member

pbogdan commented Jun 13, 2017

@orivej thanks, uploaded a file to https://gist.github.com/pbogdan/9d6986bf931b58a70d75e14eb40ee8a1 @corngood will run those shortly

@pbogdan
Copy link
Member

pbogdan commented Jun 13, 2017

pbogdan@laptop:~/nixpkgs$ source pkgs/build-support/cc-wrapper/utils.sh
pbogdan@laptop:~/nixpkgs$ seq -f argument%.0f 100 > test.rsp
pbogdan@laptop:~/nixpkgs$ time expandResponseParams @test.rsp

real	0m0.124s
user	0m0.122s
sys	0m0.002s
pbogdan@laptop:~/nixpkgs$ time expandResponseParams @ghc_7.rsp

real	1m3.771s
user	1m0.322s
sys	0m3.320s
pbogdan@laptop:~/nixpkgs$ ls -hal test.rsp ghc_7.rsp
-rw-r--r-- 1 pbogdan users  36K Jun 13 13:21 ghc_7.rsp
-rw-r--r-- 1 pbogdan users 1.1K Jun 13 14:45 test.rsp

@orivej
Copy link
Contributor Author

orivej commented Jun 13, 2017

This patch reduces parse time to 12 seconds. I'm going to see if it can be improved even further:

     local s="$1"
     local state=0
     local arg=''
+    local len="${#s}"
 
-    for (( i=0; i<${#s}; i++ )); do
+    for (( i=0; i<$len; i++ )); do
         local c="${s:$i:1}"
         local cls=1
         case "$c" in

@orivej
Copy link
Contributor Author

orivej commented Jun 13, 2017

#26554 parses your example in one second.

orivej added a commit to orivej/nixpkgs that referenced this pull request Jun 14, 2017
@orivej orivej mentioned this pull request Oct 20, 2021
12 tasks
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.

None yet

6 participants