~ chicken-core (chicken-5) 7c7980a64ad728352f7145ce722d8003a91ce3b1


commit 7c7980a64ad728352f7145ce722d8003a91ce3b1
Author:     felix <felix@call-with-current-continuation.org>
AuthorDate: Tue Oct 17 14:25:54 2017 +0200
Commit:     Peter Bex <peter@more-magic.net>
CommitDate: Tue Oct 17 15:14:21 2017 +0200

    csc: Don't try to include static .o files when linking dynamically
    
    When collecting object files before linking, ".link" files where
    consulted for all object files involved, but should not be done for .o
    files that resulted from the current compilation; previous builds may
    have generated ".link" files for the currently compiled
    file (e.g. when building an egg in default mode) and would thus be
    picked up, leading to link with static dependencies, even if the
    currently compiled file is not compiled in static mode, resulting in a
    linker error, complaining about non-PIC code being linked.
    
    Signed-off-by: Peter Bex <peter@more-magic.net>

diff --git a/csc.scm b/csc.scm
index 3b4fbf68..296da5df 100644
--- a/csc.scm
+++ b/csc.scm
@@ -915,7 +915,8 @@ EOF
 ;;; Link object files and libraries:
 
 (define (run-linking)
-  (set! object-files (collect-linked-objects object-files))
+  (set! object-files
+    (collect-linked-objects object-files generated-object-files))
   (let* ((files (map quotewrap object-files))
 	 (target (quotewrap target-filename))
 	 (targetdir #f))
@@ -949,20 +950,22 @@ EOF
         (append generated-object-files
                 transient-link-files)))))
 
-(define (collect-linked-objects object-files)
+(define (collect-linked-objects ofiles gen-ofiles)
   (define (locate lst)
     (map (lambda (ofile)
 	   (chicken.load#find-file ofile (repo-path)))
 	 lst))
-  (let loop ((os object-files) (os2 object-files))
-    (if (null? os)
-	(delete-duplicates (reverse os2) string=?)
-	(let* ((o (car os))
-	       (lfile (pathname-replace-extension o "link"))
-	       (newos (if (file-exists? lfile)
-			  (locate (with-input-from-file lfile read))
-			  '())))
-	  (loop (append newos (cdr os)) (append newos os2))))))
+  (let loop ((os ofiles) (os2 ofiles))
+    (cond ((null? os)
+           (delete-duplicates (reverse os2) string=?))
+          ((or static (not (member (car os) gen-ofiles)))
+           (let* ((o (car os))
+                  (lfile (pathname-replace-extension o "link"))
+                  (newos (if (file-exists? lfile)
+                             (locate (with-input-from-file lfile read))
+                             '())))
+             (loop (append newos (cdr os)) (append newos os2))))
+          (else (loop (cdr os) (cons (car os) os2))))))
 
 (define (copy-files from to)
   (command
Trap