summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAndy Wingo <wingo@pobox.com>2013-05-01 22:17:51 +0200
committerAndy Wingo <wingo@pobox.com>2013-05-17 22:24:02 +0200
commitfd899af33d84a1263f68c066c2bbb612cdba9606 (patch)
treeacc4957d68c7174c48af62904614d50a31bcba54
parent825ca5201fa5584a8912d790ce9d0b9183e4756f (diff)
downloadguile-fd899af33d84a1263f68c066c2bbb612cdba9606.tar.gz
new helpers in elf.scm
* module/system/vm/elf.scm (elf-section-by-name): New helper. (elf-symbol-table-len): New helper.
-rw-r--r--module/system/vm/elf.scm22
1 files changed, 20 insertions, 2 deletions
diff --git a/module/system/vm/elf.scm b/module/system/vm/elf.scm
index 2f4dee66c..516745913 100644
--- a/module/system/vm/elf.scm
+++ b/module/system/vm/elf.scm
@@ -123,8 +123,8 @@
parse-elf
elf-segment elf-segments
- elf-section elf-sections elf-sections-by-name
- elf-symbol-table-ref
+ elf-section elf-sections elf-section-by-name elf-sections-by-name
+ elf-symbol-table-len elf-symbol-table-ref
parse-elf-note
elf-note-name elf-note-desc elf-note-type))
@@ -796,6 +796,17 @@
(utf8->string out))
(lp (1+ end)))))
+(define (elf-section-by-name elf name)
+ (let ((off (elf-section-offset (elf-section elf (elf-shstrndx elf)))))
+ (let lp ((n (elf-shnum elf)))
+ (and (> n 0)
+ (let ((section (elf-section elf (1- n))))
+ (if (equal? (string-table-ref (elf-bytes elf)
+ (+ off (elf-section-name section)))
+ name)
+ section
+ (lp (1- n))))))))
+
(define (elf-sections-by-name elf)
(let* ((sections (elf-sections elf))
(off (elf-section-offset (list-ref sections (elf-shstrndx elf)))))
@@ -895,6 +906,13 @@
(else (error "invalid word size" word-size)))
bv offset byte-order sym))
+(define (elf-symbol-table-len section)
+ (let ((len (elf-section-size section))
+ (entsize (elf-section-entsize section)))
+ (unless (and (not (zero? entsize)) (zero? (modulo len entsize)))
+ (error "bad symbol table" section))
+ (/ len entsize)))
+
(define* (elf-symbol-table-ref elf section n #:optional strtab)
(let ((bv (elf-bytes elf))
(byte-order (elf-byte-order elf))