Output Modules
This chapter describes the output modules included with Sassy.
8.1 Flat Binaries
-- procedure: sassy-make-bin file sassy-output . opts
Dumps the raw contents of the text section of sassy-output to file followed by the data section, if any. If there is no text section and only a data section, then the data section will be dumped. If the file exists, it will be overwritten. opts is a set of zero, one or more of the following quoted symbols:
'boot
Creates a flat binary with the text section first, then the data section, then zero bytes until byte 510 at whichaa55
is written. The resultant size of the assembled binary will be exactly 512 bytes-the common size of a boot sector.
'stats
Emits to stdout the size of the text segment in bytes, the size of the data section in bytes, and the number of bytes consumed by alignment requirements.
8.2 ELF Output
-- procedure: sassy-make-elf file sassy-output
Constructs a GNU/Linux x86 ELF object-file based on the contents of the sassy-output and writes it to file. If the file exists it will be overwritten.If you are creating an executable, you'll need to
export
the symbol_start
, or useentry
.If you are writing shared libraries:
You must write
(export _global_offset_table_)
import
any labels in other libraries you want to use.To call or branch to a procedure in another library, instead of writing the label ``foo'', you write.
(call (plt foo)) (jmp (plt foo))
To access local data in your library, you use the following sequence to get the address of the data into a register via
(lea ...)
. (in this example the address of foo is loaded into eax).:(begin get-got (lea eax (& ebx (got-offset foo))))The important thing is to load the global offset table into ebx via the
get-got
macro, and use the(got-offset ...)
macro to load the data.
To access data in another library, you do something slightly different to obtain its address. You load the GOT with
get-got
, but instead you use the(got ...)
macro.(begin get-got (mov eax (& ebx (got foo))))