gnu: ld-wrapper: Add '-rpath' flag only for libraries that are in the store.

This avoids adding bogus entries to the RUNPATH of installed binaries,
pointing to the build directory or similar.

* gnu/packages/ld-wrapper.scm (store-file-name?): New procedure.
  (rpath-arguments): Add "-rpath" flag on when FILE matches
  'store-file-name?', not when it matches 'pure-file-name?'.
This commit is contained in:
Ludovic Courtès 2015-04-07 10:21:36 +02:00
parent 41fc0eb900
commit 51d0cd9b38
1 changed files with 20 additions and 8 deletions

View File

@ -122,6 +122,10 @@ exec @GUILE@ -c "(load-compiled \"@SELF@.go\") (apply $main (cdr (command-line))
(and %build-directory (and %build-directory
(string-prefix? %build-directory file))))) (string-prefix? %build-directory file)))))
(define (store-file-name? file)
;; Return #t when FILE is a store file, possibly indirectly.
(string-prefix? %store-directory (dereference-symlinks file)))
(define (shared-library? file) (define (shared-library? file)
;; Return #t when FILE denotes a shared library. ;; Return #t when FILE denotes a shared library.
(or (string-suffix? ".so" file) (or (string-suffix? ".so" file)
@ -168,14 +172,22 @@ exec @GUILE@ -c "(load-compiled \"@SELF@.go\") (apply $main (cdr (command-line))
;; Return the `-rpath' argument list for each of LIBRARY-FILES, a list of ;; Return the `-rpath' argument list for each of LIBRARY-FILES, a list of
;; absolute file names. ;; absolute file names.
(fold-right (lambda (file args) (fold-right (lambda (file args)
(if (or %allow-impurities? ;; Add '-rpath' if and only if FILE is in the store; we don't
(pure-file-name? file)) ;; want to add '-rpath' for files under %BUILD-DIRECTORY or
(cons* "-rpath" (dirname file) args) ;; %TEMPORARY-DIRECTORY because that could leak to installed
(begin ;; files.
(format (current-error-port) (cond ((store-file-name? file)
"ld-wrapper: error: attempt to use impure library ~s~%" (cons* "-rpath" (dirname file) args))
file) ((or %allow-impurities?
(exit 1)))) (pure-file-name? file))
args)
(else
(begin
(format (current-error-port)
"ld-wrapper: error: attempt to use \
impure library ~s~%"
file)
(exit 1)))))
'() '()
library-files)) library-files))