[PATCH core-updates] gnu: ld-wrapper: Preserve quoted arguments from response files.

  • Done
  • quality assurance status badge
Details
2 participants
  • Ludovic Courtès
  • Marius Bakke
Owner
unassigned
Submitted by
Marius Bakke
Severity
normal
M
M
Marius Bakke wrote on 24 Feb 2020 17:01
(address . guix-patches@gnu.org)
20200224160132.21037-1-mbakke@fastmail.com
* gnu/packages/ld-wrapper.in (expand-arguments): Add TOKENIZE procedure, and
use that to parse the response file.
---
gnu/packages/ld-wrapper.in | 24 ++++++++++++++++++++----
1 file changed, 20 insertions(+), 4 deletions(-)

Guix,

Currently the ld-wrapper will fail inscrutably if a response file
contains double quotes. This patch fixes that, and also preserves
whitespaces between quotes.

Toggle diff (55 lines)
diff --git a/gnu/packages/ld-wrapper.in b/gnu/packages/ld-wrapper.in
index 16780c58f6..5d5756f6a3 100644
--- a/gnu/packages/ld-wrapper.in
+++ b/gnu/packages/ld-wrapper.in
@@ -16,6 +16,7 @@ exec @GUILE@ -c "(load-compiled \"@SELF@.go\") (apply $main (cdr (command-line))
!#
;;; GNU Guix --- Functional package management for GNU
;;; Copyright © 2012, 2013, 2014, 2015, 2016, 2017, 2018 Ludovic Courtès <ludo@gnu.org>
+;;; Copyright © 2020 Marius Bakke <mbakke@fastmail.com>
;;;
;;; This file is part of GNU Guix.
;;;
@@ -35,7 +36,7 @@ exec @GUILE@ -c "(load-compiled \"@SELF@.go\") (apply $main (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)
+ #:autoload (ice-9 rdelim) (read-delimited)
#:export (ld-wrapper))
;;; Commentary:
@@ -239,13 +240,28 @@ library outside of ~a: ~s~%"
;; Expand ARGS such that "response file" arguments, such as "@args.txt", are
;; expanded (info "(gcc) Overall Options").
(define (response-file-arguments file)
+ (define (tokenize port)
+ ;; Return a list of all strings found in PORT. Quote characters are removed,
+ ;; but whitespaces within quoted strings are preserved.
+ (let loop ((words '()))
+ (let* ((word (read-delimited " '\"" port 'split))
+ (token (car word))
+ (delim (cdr word)))
+ (if (eof-object? delim)
+ (reverse words)
+ (case delim
+ ((#\") (loop (cons (read-delimited "\"" port) words)))
+ ((#\') (loop (cons (read-delimited "'" port) words)))
+ ((#\ ) (if (> 0 (string-length token))
+ (loop (cons token words))
+ (loop words)))
+ (else (loop words)))))))
+
(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 single
- ;; or double quotes; this is not implemented here.
- (string-tokenize (call-with-input-file file read-string)))
+ (call-with-input-file file tokenize))
(define result
(fold-right (lambda (arg result)
--
2.25.0
L
L
Ludovic Courtès wrote on 24 Feb 2020 22:01
(name . Marius Bakke)(address . mbakke@fastmail.com)(address . 39767@debbugs.gnu.org)
87zhd7em2i.fsf@gnu.org
Hi Marius!

Marius Bakke <mbakke@fastmail.com> skribis:

Toggle quote (3 lines)
> * gnu/packages/ld-wrapper.in (expand-arguments): Add TOKENIZE procedure, and
> use that to parse the response file.

LGTM!

Toggle quote (4 lines)
> Currently the ld-wrapper will fail inscrutably if a response file
> contains double quotes. This patch fixes that, and also preserves
> whitespaces between quotes.

Out of curiosity, where did you stumble upon response files with quotes?
Was it GHC?

Thanks,
Ludo’.
M
M
Marius Bakke wrote on 24 Feb 2020 22:14
(name . Ludovic Courtès)(address . ludo@gnu.org)(address . 39767@debbugs.gnu.org)
87blpn4ric.fsf@devup.no
Ludovic Courtès <ludo@gnu.org> writes:

Toggle quote (16 lines)
> Hi Marius!
>
> Marius Bakke <mbakke@fastmail.com> skribis:
>
>> * gnu/packages/ld-wrapper.in (expand-arguments): Add TOKENIZE procedure, and
>> use that to parse the response file.
>
> LGTM!
>
>> Currently the ld-wrapper will fail inscrutably if a response file
>> contains double quotes. This patch fixes that, and also preserves
>> whitespaces between quotes.
>
> Out of curiosity, where did you stumble upon response files with quotes?
> Was it GHC?

A variant of this wrapper will (hopefully!) soon show up on the 'master'
branch, required for version 80 of ungoogled-chromium. It generates
response files where all "-lfoo" "-lbar" arguments are quoted, even
though they contain no spaces.

Thanks for the quick review, will merge it on core-updates after it hits
'master'. :-)
-----BEGIN PGP SIGNATURE-----

iQEzBAEBCgAdFiEEu7At3yzq9qgNHeZDoqBt8qM6VPoFAl5UPLsACgkQoqBt8qM6
VPpIsQf9Fp51cJnm9O68dnVAnyQEpbZeiTRlBut5BaIirnUuQzGD2LyF1dWqbo+V
dJLy1ydj5hqUAOvyd+SNQFnDOJRcLnpfj199ksOcUG6+/Qh395eYDd9niulNu8og
OLr2y9M5QBGzcClOXLaHkQKEF/yb2PStOWEocziLh7+bTTJvwWMW16uazYbPbIH1
e2xqYYdykLfWiVsy01sz1TqF4/RZ4qlMK6SHyIWd+/QUe+sDeecsrrOFLYZJVYNg
sCphT+Dq1cMXYH6Ys9wwQGY4udExxN07YmewAyfH1/Xws033fcfGBsJ+G0FkMS4h
pQbeInGGGDQHbXoWa8bnuODNNDaZwg==
=k0Ny
-----END PGP SIGNATURE-----

M
M
Marius Bakke wrote on 6 Mar 2020 13:26
(address . 39767-done@debbugs.gnu.org)
87wo7xlldd.fsf@devup.no
Marius Bakke <mbakke@fastmail.com> writes:

Toggle quote (3 lines)
> * gnu/packages/ld-wrapper.in (expand-arguments): Add TOKENIZE procedure, and
> use that to parse the response file.

I simplified it a bit and also discarded newlines and pushed to
core-updates in feb8c5dac30294d72205ee21b3afcf1cf7a04675.
-----BEGIN PGP SIGNATURE-----

iQEzBAEBCgAdFiEEu7At3yzq9qgNHeZDoqBt8qM6VPoFAl5iQY4ACgkQoqBt8qM6
VPpHZQgAogmb+ddwxd61vUqmXFqqpQMbscqGc/Kef7Y9srObcFWl7hjEITJrDy/l
iD8F5GYDuEb9uUfbh1ugaWxZrimcMERO0deSWXwdtfyqmoNDGjisxdpsD5OrWdAx
sQkTF0AAyA5cGxq6WlQBRuiTOCCX+tg8/R9zwqAvbaCJ1cFhQp8lyhxTHw+Ij//o
oVLTWln5i+/1EYmB/a+WlkhQAZabEgGVlsHOfyU6RrEkXnSIvnp4EPfQ295xymCR
9r7Hi0SWvu7Iykuy7S6XJP85cBBBE0OUqjnikSvPO/YmukvuqXjzj63ZQc/N2c8v
Fw/rAjXagxcBpYp7xpGnIeWD9Gbc/A==
=2tud
-----END PGP SIGNATURE-----

Closed
?