# the shebang line in Linux.
# Use `load-compiled' because `load' (and `-l') doesn't otherwise load our
# .go file (see <http://bugs.gnu.org/12519>).
+# Unset 'GUILE_LOAD_COMPILED_PATH' to make sure we do not stumble upon
+# incompatible .go files. See
+# <https://lists.gnu.org/archive/html/guile-devel/2016-03/msg00000.html>.
+unset GUILE_LOAD_COMPILED_PATH
main="(@ (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 © 2012, 2013, 2014, 2015 Ludovic Courtès <ludo@gnu.org>
+;;; Copyright © 2012, 2013, 2014, 2015, 2016 Ludovic Courtès <ludo@gnu.org>
;;;
;;; This file is part of GNU Guix.
;;;
(string-every (char-set-union (char-set #\.) char-set:digit)
(string-drop file (+ index 3)))))))
-(define (library-files-linked args)
- ;; Return the file names of shared libraries explicitly linked against via
- ;; `-l' or with an absolute file name in ARGS.
- (define path+files
+(define (library-search-path args)
+ ;; Return the library search path as a list of directory names. The GNU ld
+ ;; manual notes that "[a]ll `-L' options apply to all `-l' options,
+ ;; regardless of the order in which the options appear", so we must compute
+ ;; the search path independently of the -l options.
+ (let loop ((args args)
+ (path '()))
+ (match args
+ (()
+ (reverse path))
+ (("-L" directory . rest)
+ (loop rest (cons directory path)))
+ ((argument . rest)
+ (if (string-prefix? "-L" argument) ;augment the search path
+ (loop rest
+ (cons (string-drop argument 2) path))
+ (loop rest path))))))
+
+(define (library-files-linked args library-path)
+ ;; Return the absolute file names of shared libraries explicitly linked
+ ;; against via `-l' or with an absolute file name in ARGS, looking them up
+ ;; in LIBRARY-PATH.
+ (define files+args
(fold (lambda (argument result)
(match result
- ((library-path . library-files)
- (cond ((string-prefix? "-L" argument) ;augment the search path
- (cons (append library-path
- (list (string-drop argument 2)))
- library-files))
- ((string-prefix? "-l" argument) ;add library
+ ((library-files ((and flag
+ (or "-dynamic-linker" "-plugin"))
+ . rest))
+ ;; When passed '-dynamic-linker ld.so', ignore 'ld.so'; when
+ ;; passed '-plugin liblto_plugin.so', ignore
+ ;; 'liblto_plugin.so'. See <http://bugs.gnu.org/20102>.
+ (list library-files
+ (cons* argument flag rest)))
+ ((library-files previous-args)
+ (cond ((string-prefix? "-l" argument) ;add library
(let* ((lib (string-append "lib"
(string-drop argument 2)
".so"))
(full (search-path library-path lib)))
- (if full
- (cons library-path
- (cons full library-files))
- result)))
+ (list (if full
+ (cons full library-files)
+ library-files)
+ (cons argument previous-args))))
((and (string-prefix? %store-directory argument)
(shared-library? argument)) ;add library
- (cons library-path
- (cons argument library-files)))
+ (list (cons argument library-files)
+ (cons argument previous-args)))
(else
- result)))))
- (cons '() '())
+ (list library-files
+ (cons argument previous-args)))))))
+ (list '() '())
args))
- (match path+files
- ((path . files)
+ (match files+args
+ ((files arguments)
(reverse files))))
(define (rpath-arguments library-files)
(define (ld-wrapper . args)
;; Invoke the real `ld' with ARGS, augmented with `-rpath' switches.
- (let* ((libs (library-files-linked args))
+ (let* ((path (library-search-path args))
+ (libs (library-files-linked args path))
(args (append args (rpath-arguments libs))))
(when %debug?
+ (format (current-error-port)
+ "ld-wrapper: library search path: ~s~%" path)
+ (format (current-error-port)
+ "ld-wrapper: libraries linked: ~s~%" libs)
(format (current-error-port)
"ld-wrapper: invoking `~a' with ~s~%"
%real-ld args))