From 161a9edb57c38ab71686d9a6e3c7920c96713fed Mon Sep 17 00:00:00 2001 From: Matthew Flatt Date: Thu, 31 Mar 2016 14:40:39 -0600 Subject: [PATCH] Windows: another PE update fix Corrects problems with a4d569ae31 to unbreak MinGW-based builds. --- racket/collects/compiler/private/pe-rsrc.rkt | 44 ++++++++++++-------- 1 file changed, 27 insertions(+), 17 deletions(-) diff --git a/racket/collects/compiler/private/pe-rsrc.rkt b/racket/collects/compiler/private/pe-rsrc.rkt index 07b7bbb7b3..b92302d9e0 100644 --- a/racket/collects/compiler/private/pe-rsrc.rkt +++ b/racket/collects/compiler/private/pe-rsrc.rkt @@ -384,7 +384,7 @@ (define rsrcs (read-rsrcs i (section-file-position s) (section-virtual-addr s))) (show-resources rsrcs) - + (values pe rsrcs)) (define (same-alignment orig new) @@ -439,15 +439,18 @@ [else (log-pe-rsrc-debug "moving resources to end") - (define earliest-section-file-position - (for/fold ([p (section-file-position (car (pe-sections pe)))]) ([s (in-list (pe-sections pe))]) - (min p (section-file-position s)))) - (log-pe-rsrc-debug "earliest section at ~x" earliest-section-file-position) + (define (check-extra-header-ok) + (define earliest-section-file-position + (for/fold ([p (section-file-position (car (pe-sections pe)))]) ([s (in-list (pe-sections pe))]) + (if (zero? (section-file-position s)) + p + (min p (section-file-position s))))) + (log-pe-rsrc-debug "earliest section at ~x" earliest-section-file-position) - (unless (> earliest-section-file-position - (+ (* SECTION-HEADER-SIZE (length (pe-sections pe))) - (pe-section-start-pos pe))) - (error 'update-resources "no room for a new section header")) + (unless (> earliest-section-file-position + (+ (* SECTION-HEADER-SIZE (length (pe-sections pe))) + (pe-section-start-pos pe))) + (error 'update-resources "no room for a new section header"))) (define new-virtual-addr (same-alignment @@ -479,15 +482,22 @@ new-virtual-size new-position) + (define need-new-section? + (for/or ([s2 (in-list (pe-sections pe))] + #:unless (eq? s s2)) + ((section-virtual-addr s2) . > . (section-virtual-addr s)))) + (define new-sections - (sort (cons - (section - #".DROPpe\0" - (section-virtual-size s) - (section-virtual-addr s) - (section-file-length s) - (section-file-position s) - (section-characteristics s)) + (sort (append + (if need-new-section? + (list (section + #".DROPpe\0" + (section-virtual-size s) + (section-virtual-addr s) + (section-file-length s) + (section-file-position s) + (section-characteristics s))) + null) (for/list ([s2 (in-list (pe-sections pe))]) (if (eq? s s2) (section (section-name s)