raco dist: unbreak ELF size update
This commit is contained in:
parent
304904da50
commit
0a9c70e95a
|
@ -338,6 +338,11 @@
|
||||||
|
|
||||||
(define (patch-stub-exe-paths b exe shared-lib-dir)
|
(define (patch-stub-exe-paths b exe shared-lib-dir)
|
||||||
;; Adjust paths to executable and DLL that is embedded in the executable
|
;; 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)
|
(let-values ([(config-pos all-start start end prog-len dll-len rest)
|
||||||
(with-input-from-file b
|
(with-input-from-file b
|
||||||
(lambda ()
|
(lambda ()
|
||||||
|
@ -351,7 +356,7 @@
|
||||||
(read-one-int i) ; start of program
|
(read-one-int i) ; start of program
|
||||||
(let ([start (read-one-int i)] ; start of data
|
(let ([start (read-one-int i)] ; start of data
|
||||||
[end (read-one-int i)]) ; end 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)]
|
(let ([prog-len (next-bytes-length i)]
|
||||||
[dll-len (next-bytes-length i)])
|
[dll-len (next-bytes-length i)])
|
||||||
(values (+ (cdar m) 1) ; position after "cOnFiG:[" tag
|
(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
|
(file-position o (+ config-pos 12)) ; update the end of the program data
|
||||||
(write-one-int (- end delta) o)
|
(write-one-int (- end delta) o)
|
||||||
(flush-output o)
|
(flush-output o)
|
||||||
(file-position o start)
|
(file-position o (+ start section-offset))
|
||||||
(write-bytes exe-bytes o)
|
(write-bytes exe-bytes o)
|
||||||
(write-bytes #"\0" o)
|
(write-bytes #"\0" o)
|
||||||
(write-bytes shared-lib-bytes o)
|
(write-bytes shared-lib-bytes o)
|
||||||
|
@ -385,7 +390,7 @@
|
||||||
;; May need to fix the size of the ELF section:
|
;; May need to fix the size of the ELF section:
|
||||||
(adjust-racket-section-size
|
(adjust-racket-section-size
|
||||||
b
|
b
|
||||||
#rx#"^[.]rack(?:cmdl|prog)\0"
|
rx:rackprog
|
||||||
(- (- end all-start) delta))))))
|
(- (- end all-start) delta))))))
|
||||||
|
|
||||||
(define (copy-and-patch-binaries copy? magic
|
(define (copy-and-patch-binaries copy? magic
|
||||||
|
|
|
@ -1,6 +1,7 @@
|
||||||
#lang racket/base
|
#lang racket/base
|
||||||
|
|
||||||
(provide add-racket-section
|
(provide add-racket-section
|
||||||
|
get-racket-section-offset+size
|
||||||
adjust-racket-section-size
|
adjust-racket-section-size
|
||||||
get-rpath
|
get-rpath
|
||||||
set-rpath)
|
set-rpath)
|
||||||
|
@ -504,6 +505,24 @@
|
||||||
;; Any final writes:
|
;; Any final writes:
|
||||||
(finish out adjust adjust*))))))))
|
(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 (adjust-racket-section-size src-file name-regexp new-size)
|
||||||
(define fixup
|
(define fixup
|
||||||
(call-with-input-file*
|
(call-with-input-file*
|
||||||
|
|
|
@ -308,7 +308,7 @@ int main(int argc, char **argv)
|
||||||
{
|
{
|
||||||
int expected_length = end - prog_end;
|
int expected_length = end - prog_end;
|
||||||
if (expected_length != read(fd, data, expected_length)) {
|
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();
|
abort();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue
Block a user