From 112b617f5921c67b4b2c45aae39f54cccd34d7ef Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ludovic=20Court=C3=A8s?= Date: Tue, 16 Apr 2024 00:34:01 +0200 Subject: [PATCH] linker: Create a sparse file only when writing to a file port. MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Fixes a regression introduced in 4a0c2433d97be9d995b3be74d90bc074d8efb5a7: the strategy wouldn’t work when writing to, say, a bytevector output port. * module/system/vm/linker.scm (link-elf)[write-padding]: Reintroduce loop for when PORT is not a file port. Remove first argument. --- module/system/vm/linker.scm | 21 ++++++++++++++++----- 1 file changed, 16 insertions(+), 5 deletions(-) diff --git a/module/system/vm/linker.scm b/module/system/vm/linker.scm index 952e85c30..7f3a625a1 100644 --- a/module/system/vm/linker.scm +++ b/module/system/vm/linker.scm @@ -769,10 +769,21 @@ Returns a bytevector." objects) bv) (lambda (port) - (define (write-padding port size) - ;; Write SIZE bytes of padding to PORT. Use 'seek' to - ;; create a sparse file. - (seek port size SEEK_CUR)) + (define write-padding + ;; Write SIZE bytes of padding to PORT. + (if (file-port? port) + (lambda (size) + ;; Use 'seek' to create a sparse file. + (seek port size SEEK_CUR)) + (let ((blank (make-bytevector 4096 0))) + (lambda (size) + ;; Write SIZE zeros. + (let loop ((size size)) + (unless (zero? size) + (let ((count (min size + (bytevector-length blank)))) + (put-bytevector port blank 0 count) + (loop (- size count))))))))) (define (compute-padding objects) ;; Return the list of padding in between OBJECTS--the list @@ -796,7 +807,7 @@ Returns a bytevector." (for-each (lambda (object padding) (let ((bv (make-bytevector (linker-object-size object) 0))) - (write-padding port padding) + (write-padding padding) (write-linker-object bv object symtab endianness) (put-bytevector port bv))) objects