raco dist: unbreak ELF size update

This commit is contained in:
Matthew Flatt 2021-05-15 15:20:28 -06:00
parent 304904da50
commit 0a9c70e95a
3 changed files with 28 additions and 4 deletions

View File

@ -338,6 +338,11 @@
(define (patch-stub-exe-paths b exe shared-lib-dir)
;; Adjust paths to executable and DLL that is embedded in the executable
(define rx:rackprog #rx#"^[.]rackprog\0")
(define section-offset+size (get-racket-section-offset+size b rx:rackprog))
(define section-offset (if section-offset+size
(car section-offset+size)
0))
(let-values ([(config-pos all-start start end prog-len dll-len rest)
(with-input-from-file b
(lambda ()
@ -351,7 +356,7 @@
(read-one-int i) ; start of program
(let ([start (read-one-int i)] ; start of data
[end (read-one-int i)]) ; end of data
(file-position i start)
(file-position i (+ start section-offset))
(let ([prog-len (next-bytes-length i)]
[dll-len (next-bytes-length i)])
(values (+ (cdar m) 1) ; position after "cOnFiG:[" tag
@ -375,7 +380,7 @@
(file-position o (+ config-pos 12)) ; update the end of the program data
(write-one-int (- end delta) o)
(flush-output o)
(file-position o start)
(file-position o (+ start section-offset))
(write-bytes exe-bytes o)
(write-bytes #"\0" o)
(write-bytes shared-lib-bytes o)
@ -385,7 +390,7 @@
;; May need to fix the size of the ELF section:
(adjust-racket-section-size
b
#rx#"^[.]rack(?:cmdl|prog)\0"
rx:rackprog
(- (- end all-start) delta))))))
(define (copy-and-patch-binaries copy? magic

View File

@ -1,6 +1,7 @@
#lang racket/base
(provide add-racket-section
get-racket-section-offset+size
adjust-racket-section-size
get-rpath
set-rpath)
@ -504,6 +505,24 @@
;; Any final writes:
(finish out adjust adjust*))))))))
(define (get-racket-section-offset+size src-file name-regexp)
(call-with-input-file*
src-file
(lambda (in)
(read-elf
in
(lambda () #f)
(lambda (elf sections programs str-section strs)
(and elf
(for/or ([s (in-list sections)]
[i (in-naturals)])
(and (regexp-match? name-regexp
strs
(min (section-name-offset s)
(bytes-length strs)))
(cons (section-offset s)
(section-size s))))))))))
(define (adjust-racket-section-size src-file name-regexp new-size)
(define fixup
(call-with-input-file*

View File

@ -308,7 +308,7 @@ int main(int argc, char **argv)
{
int expected_length = end - prog_end;
if (expected_length != read(fd, data, expected_length)) {
printf("read failed to read all %i bytes from file %s\n", expected_length, embedding_me);
printf("read failed to read all %i bytes from file %s at offset %d\n", expected_length, embedding_me, prog_end);
abort();
}
}