From mboxrd@z Thu Jan 1 00:00:00 1970 From: ludo@gnu.org (Ludovic =?UTF-8?Q?Court=C3=A8s?=) Subject: bug#25882: gcc-wrapper doesn't handle response files Date: Sat, 11 Mar 2017 14:47:38 +0100 Message-ID: <87shmk6i2t.fsf@gnu.org> References: <87o9xepe7l.fsf@gnu.org> <871suajpfh.fsf@lupo.i-did-not-set--mail-host-address--so-tickle-me> <87r329fjcq.fsf@gnu.org> <878togudsp.fsf@lupo.i-did-not-set--mail-host-address--so-tickle-me> Mime-Version: 1.0 Content-Type: multipart/mixed; boundary="=-=-=" Return-path: Received: from eggs.gnu.org ([2001:4830:134:3::10]:35242) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1cmhNN-00006p-4m for bug-guix@gnu.org; Sat, 11 Mar 2017 08:48:06 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1cmhNK-000535-3v for bug-guix@gnu.org; Sat, 11 Mar 2017 08:48:05 -0500 Received: from debbugs.gnu.org ([208.118.235.43]:52186) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1cmhNK-00052w-07 for bug-guix@gnu.org; Sat, 11 Mar 2017 08:48:02 -0500 Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1cmhNJ-0003Pe-Pm for bug-guix@gnu.org; Sat, 11 Mar 2017 08:48:01 -0500 Sender: "Debbugs-submit" Resent-Message-ID: In-Reply-To: <878togudsp.fsf@lupo.i-did-not-set--mail-host-address--so-tickle-me> (Federico Beffa's message of "Wed, 08 Mar 2017 13:57:10 +0100") List-Id: Bug reports for GNU Guix List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: bug-guix-bounces+gcggb-bug-guix=m.gmane.org@gnu.org Sender: "bug-Guix" To: Federico Beffa Cc: 25882@debbugs.gnu.org --=-=-= Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable Federico Beffa skribis: > ludo@gnu.org (Ludovic Court=C3=A8s) writes: > >> On closer inspection, it=E2=80=99s an easy change to make. >> >> Could you test the attached patch with GHC? > > Thanks for the patch. I've tested it with GHC 8.0.2 and seems to work > for it. However, this is an excerpt of the description of the use of > response files from the GCC manual: > > '@FILE' > 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. Oh, nice, I hadn=E2=80=99t seen this doc. The attached version adds handling of unreadable files and recursion. It does not address parsing of quote-delimited options though, but I=E2=80= =99m tempted to punt on that one. Thoughts? Thanks, Ludo=E2=80=99. --=-=-= Content-Type: text/x-patch; charset=utf-8 Content-Disposition: inline Content-Transfer-Encoding: quoted-printable diff --git a/gnu/packages/ld-wrapper.in b/gnu/packages/ld-wrapper.in index ebfd8332c..82bd2196c 100644 --- a/gnu/packages/ld-wrapper.in +++ b/gnu/packages/ld-wrapper.in @@ -15,7 +15,7 @@ main=3D"(@ (gnu build-support ld-wrapper) ld-wrapper)" exec @GUILE@ -c "(load-compiled \"@SELF@.go\") (apply $main (cdr (command-= line)))" "$@" !# ;;; GNU Guix --- Functional package management for GNU -;;; Copyright =C2=A9 2012, 2013, 2014, 2015, 2016 Ludovic Court=C3=A8s +;;; Copyright =C2=A9 2012, 2013, 2014, 2015, 2016, 2017 Ludovic Court=C3= =A8s ;;; ;;; This file is part of GNU Guix. ;;; @@ -35,6 +35,7 @@ exec @GUILE@ -c "(load-compiled \"@SELF@.go\") (apply $ma= in (cdr (command-line)) (define-module (gnu build-support ld-wrapper) #:use-module (srfi srfi-1) #:use-module (ice-9 match) + #:autoload (ice-9 rdelim) (read-string) #:export (ld-wrapper)) =20 ;;; Commentary: @@ -222,9 +223,44 @@ impure library ~s~%" '() library-files)) =20 +(define (expand-arguments args) + ;; Expand ARGS such that "response file" arguments, such as "@args.txt",= are + ;; expanded (info "(gcc) Overall Options"). + (define (response-file-arguments file) + (when %debug? + (format (current-error-port) + "ld-wrapper: attempting to read arguments from '~a'~%" file)) + + ;; FIXME: Options can contain whitespace if they are protected by sing= le + ;; or double quotes; this is not implemented here. + (string-tokenize (call-with-input-file file read-string))) + + (define result + (fold-right (lambda (arg result) + (if (string-prefix? "@" arg) + (let ((file (string-drop arg 1))) + (append (catch 'system-error + (lambda () + (response-file-arguments file)) + (lambda args + ;; FILE doesn't exist or cannot be rea= d so + ;; leave ARG as is. + (list arg))) + result)) + (cons arg result))) + '() + args)) + + ;; If there are "@" arguments in RESULT *and* we can expand them (they d= on't + ;; refer to nonexistent files), then recurse. + (if (equal? result args) + result + (expand-arguments result))) + (define (ld-wrapper . args) ;; Invoke the real `ld' with ARGS, augmented with `-rpath' switches. - (let* ((path (library-search-path args)) + (let* ((args (expand-arguments args)) + (path (library-search-path args)) (libs (library-files-linked args path)) (args (append args (rpath-arguments libs)))) (when %debug? --=-=-=--