Racket Binutils
1 Binary Objects
bin:  object
bin:  section
bin:  symbol
bin:  relocation
2 Linking
link-object/  local/  relative
3 Dynamic Loading
dynamic-object<%>
symbols
symbol-ref
load-object
4 ELF Support
4.1 Reading and Writing
read-elf
write-elf
4.2 Conversion
elf->bin:  object
bin:  object->elf
4.3 ELF Data Structures
elf%
repack!
4.4 Utilities
system-elf-class
8.12

Racket Binutils🔗ℹ

This package is not stable, and is likely to break compatibility in the future.

 (require binutils) package: binutils

1 Binary Objects🔗ℹ

struct

(struct bin:object (sections)
    #:extra-constructor-name make-bin:object)
  sections : (listof bin:section?)
Represents a binary object.

struct

(struct bin:section (name
    size
    writable?
    executable?
    data
    symbols
    relocations)
    #:extra-constructor-name make-bin:section)
  name : (or/c bytes? #f)
  size : (or/c exact-nonnegative-integer? #f)
  writable? : boolean?
  executable? : boolean?
  data : (or/c bytes? #f)
  symbols : (listof bin:symbol?)
  relocations : (listof bin:relocation?)
Represents a section of a binary object.

struct

(struct bin:symbol (name value size binding type)
    #:extra-constructor-name make-bin:symbol)
  name : symbol?
  value : exact-integer?
  size : (or/c exact-nonnegative-integer? #f)
  binding : (one-of/c 'local 'global 'weak #f)
  type : (one-of/c 'object 'function #f)
Represents a symbol for linking.

struct

(struct bin:relocation (offset size symbol type addend)
    #:extra-constructor-name make-bin:relocation)
  offset : exact-nonnegative-integer?
  size : exact-nonnegative-integer?
  symbol : symbol?
  type : (one-of/c 'address 'offset 'value 'size)
  addend : exact-integer?
Represents a relocation.

2 Linking🔗ℹ

procedure

(link-object/local/relative obj)  bin:object?

  obj : bin:object?
Resolves local relative references in obj.

3 Dynamic Loading🔗ℹ

This is unsafe (particularly if there are bugs, which is likely) - it could cause crashes or worse!

Represents an object which has been loaded into memory.

method

(send a-dynamic-object symbols)  (listof symbol?)

Returns a list of symbols exported by the object.

method

(send a-dynamic-object symbol-ref name)  cpointer?

  name : symbol?
Returns a pointer to the requested symbol. This may be cast into a function type.

procedure

(load-object obj)  (is-a?/c dynamic-object<%>)

  obj : bin:object?
Loads obj into memory.

4 ELF Support🔗ℹ

 (require binutils/elf) package: binutils

4.1 Reading and Writing🔗ℹ

procedure

(read-elf [in])  (is-a?/c elf%)

  in : input-port? = (current-input-port)
Reads an ELF binary from in.

procedure

(write-elf v [out])  void?

  v : (is-a?/c elf%)
  out : output-port? = (current-output-port)
Writes v as an ELF binary to out.

4.2 Conversion🔗ℹ

procedure

(elf->bin:object elf)  (bin:object?)

  elf : (is-a?/c elf%)
Converts elf to a generic object. Some information will be lost in this process.

procedure

(bin:object->elf obj)  (is-a?/c elf%)

  obj : bin:object?
Converts obj to an ELF object.

4.3 ELF Data Structures🔗ℹ

These classes represent the ELF format. For details, see the ELF specification and the source code of this module.

class

elf% : class?

  superclass: object%

  extends: binary<%>

method

(send an-elf repack!)  void?

Adjusts sizes and offsets to fit the contents of the object.

4.4 Utilities🔗ℹ

procedure

(system-elf-class)  (or/c 'elf32 'elf64)

Returns the appropriate ELF class for the current processor.