diff --git a/basis/images/pbm/pbm.factor b/basis/images/pbm/pbm.factor index 7db7ccedc6..9b8c7c11f9 100644 --- a/basis/images/pbm/pbm.factor +++ b/basis/images/pbm/pbm.factor @@ -58,8 +58,6 @@ SINGLETON: pbm-image read-token :> type read-number :> width read-number :> height - width height * :> npixels - width 8 mod :> leftover type { { "P1" [ [ [ read-ascii-bits ] ignore-errors ] B{ } make ] } diff --git a/extra/elf/elf.factor b/extra/elf/elf.factor index bf4de754d1..b2fe7db8a4 100644 --- a/extra/elf/elf.factor +++ b/extra/elf/elf.factor @@ -1,8 +1,8 @@ ! Copyright (C) 2010 Erik Charlebois. ! See http://factorcode.org/license.txt for BSD license. USING: accessors alien alien.c-types alien.strings alien.syntax arrays -classes.struct io.encodings.ascii kernel locals math math.intervals -sequences specialized-arrays strings typed ; +classes.struct fry io.encodings.ascii kernel locals math +math.intervals sequences specialized-arrays strings typed ; IN: elf ! FFI data @@ -609,4 +609,6 @@ M:: segment sections ( segment -- sections ) symbol sym>> st_value>> segment p_vaddr>> - segment p_offset>> + :> faddress faddress symbol elf-header>> >c-ptr symbol sym>> st_size>> ; - + +: find-section ( sections name -- section/f ) + '[ name>> _ = ] find nip ; diff --git a/extra/elf/nm/authors.txt b/extra/elf/nm/authors.txt new file mode 100644 index 0000000000..6f03a12101 --- /dev/null +++ b/extra/elf/nm/authors.txt @@ -0,0 +1 @@ +Erik Charlebois diff --git a/extra/elf/nm/nm-docs.factor b/extra/elf/nm/nm-docs.factor new file mode 100644 index 0000000000..f07af890c8 --- /dev/null +++ b/extra/elf/nm/nm-docs.factor @@ -0,0 +1,22 @@ +! Copyright (C) 2010 Erik Charlebois. +! See http://factorcode.org/license.txt for BSD license. +USING: elf help.markup help.syntax ; +IN: elf.nm + +HELP: nm +{ $values + { "path" "a pathname string" } +} +{ $description "Prints information about the symbols in the ELF object at the given path." } ; + +HELP: print-symbol +{ $values + { "sections" "sequence of section" } { "symbol" symbol } +} +{ $description "Prints the value, section and name of the given symbol." } ; + +ARTICLE: "elf.nm" "ELF nm" +{ $description "Utility to print the values, sections and names of the symbols in a given ELF file. In an ELF executable or shared library, the symbol values are typically their virtual addresses. In a relocatable ELF object, they are section-relative offsets." } +; + +ABOUT: "elf.nm" diff --git a/extra/elf/nm/nm.factor b/extra/elf/nm/nm.factor new file mode 100644 index 0000000000..f9df61249d --- /dev/null +++ b/extra/elf/nm/nm.factor @@ -0,0 +1,25 @@ +! Copyright (C) 2010 Erik Charlebois. +! See http://factorcode.org/license.txt for BSD license. +USING: accessors combinators elf formatting io.mmap kernel sequences ; +IN: elf.nm + +: print-symbol ( sections symbol -- ) + [ sym>> st_value>> "%016d " printf ] + [ + sym>> st_shndx>> + { + { SHN_UNDEF [ drop "undefined" ] } + { SHN_ABS [ drop "absolute" ] } + { SHN_COMMON [ drop "common" ] } + [ swap nth name>> ] + } case "%-16s " printf + ] + [ name>> "%s\n" printf ] tri ; + +: nm ( path -- ) + [ + address>> sections + dup ".symtab" find-section + symbols [ name>> empty? not ] filter + [ print-symbol ] with each + ] with-mapped-file ; diff --git a/extra/elf/nm/summary.txt b/extra/elf/nm/summary.txt new file mode 100644 index 0000000000..7d378d3c38 --- /dev/null +++ b/extra/elf/nm/summary.txt @@ -0,0 +1 @@ +UNIX nm-like utility.