From 82d5b468191de4b43fbe2404c3924b4b0aa7333b Mon Sep 17 00:00:00 2001 From: Matthew Flatt Date: Wed, 27 Mar 2019 15:07:08 -0600 Subject: [PATCH] ELF tools: don't treat non-allocated section as allocated For example, don't fail in shifting file offsets by misinterpreting an unallocated section's null address as requiring a shift of virtual addresses. --- racket/collects/compiler/private/elf.rkt | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/racket/collects/compiler/private/elf.rkt b/racket/collects/compiler/private/elf.rkt index 690d64cf97..70c9ed5d1e 100644 --- a/racket/collects/compiler/private/elf.rkt +++ b/racket/collects/compiler/private/elf.rkt @@ -48,7 +48,7 @@ sh-offset sh-esize sh-ecount class format sh-str-index) #:transparent) -(struct section (name-offset addr offset size type) +(struct section (name-offset addr offset size type alloc?) #:transparent) (struct program (offset vaddr paddr size) #:transparent) @@ -206,7 +206,8 @@ [info (read-word)] [align (read-xword)] [esize (read-xword)]) - (section name-offset addr offset size type)))]) + (define alloc? (bitwise-bit-set? flags 1)) + (section name-offset addr offset size type alloc?)))]) ;; Read program headers ------------------------ (let ([programs (for/list ([i (in-range ph-ecount)]) @@ -253,7 +254,8 @@ (define (find-section-by-offset offset sections) (for/or ([s (in-list sections)]) - (and (offset . >= . (section-offset s)) + (and (section-alloc? s) + (offset . >= . (section-offset s)) (offset . < . (+ (section-offset s) (section-size s))) s)))