Barrelfish
Functions
elf64.c File Reference

Rudimentary ELF64 loader and handling routines. More...

Functions

genvaddr_t elf_virtual_base64 (struct Elf64_Ehdr *ehead)
 Calculates the base of the loadable portion of the elf image in virtual memory.
 
struct Elf64_Shdrelf64_find_section_header_type (struct Elf64_Shdr *shdr, uint32_t entries, uint32_t type)
 Return pointer to relocation section ELF header. More...
 
struct Elf64_Shdrelf64_find_section_header_name (genvaddr_t elf_base, size_t elf_bytes, const char *section_name)
 Return pointer to section header with given name. More...
 
struct Elf64_Symelf64_find_symbol_by_name (genvaddr_t elf_base, size_t elf_bytes, const char *name, uint8_t contains, uint8_t type, uintptr_t *sindex)
 finds the symbol by name More...
 
struct Elf64_Symelf64_find_symbol_by_addr (genvaddr_t elf_base, size_t elf_bytes, lvaddr_t addr, uintptr_t *sindex)
 finds the symbol by its address More...
 
void elf64_relocate (genvaddr_t dst, genvaddr_t src, struct Elf64_Rela *rela, size_t size, struct Elf64_Sym *symtab, size_t symsize, genvaddr_t start, void *vbase)
 Relocates the ELF image from src to dst. More...
 
errval_t elf64_load (uint16_t em_machine, elf_allocator_fn allocate_func, void *state, lvaddr_t base, size_t size, genvaddr_t *retentry, genvaddr_t *ret_tlsbase, size_t *ret_tlsinitlen, size_t *ret_tlstotallen)
 Load ELF64 binary image into memory. More...
 

Detailed Description

Rudimentary ELF64 loader and handling routines.

Note that on 32-bit platforms, this loader is only able to load ELF64 files that it can address (ie. those that are not bigger than what fits into a 32-bit address space).

Function Documentation

struct Elf64_Shdr* elf64_find_section_header_name ( genvaddr_t  elf_base,
size_t  elf_bytes,
const char *  section_name 
)

Return pointer to section header with given name.

Parameters
elf_baseAddress of ELF header
elf_bytesSize of ELF file.
section_nameNamed section to look for.
Returns
Pointer to ELF section header with name, or NULL.
struct Elf64_Shdr* elf64_find_section_header_type ( struct Elf64_Shdr shdr,
uint32_t  entries,
uint32_t  type 
)

Return pointer to relocation section ELF header.

This function finds and returns a pointer to the first ELF section header of type 'type'.

Parameters
shdrPointer to head of ELF section header table.
entriesNumber of entries in the ELF section header table.
typeELF section header type to look for.
Returns
Pointer to first ELF section header of type 'type', or NULL.
struct Elf64_Sym* elf64_find_symbol_by_addr ( genvaddr_t  elf_base,
size_t  elf_bytes,
lvaddr_t  addr,
uintptr_t *  sindex 
)

finds the symbol by its address

Parameters
elf_basevirtual address where the elf image is mapped
elf_bytessize of the mapped elf image
addrvirtual address of the symbol
sindexreturns the index of the symbol
Returns
pointer to the symbol NULL if there is none
struct Elf64_Sym* elf64_find_symbol_by_name ( genvaddr_t  elf_base,
size_t  elf_bytes,
const char *  name,
uint8_t  contains,
uint8_t  type,
uintptr_t *  sindex 
)

finds the symbol by name

Parameters
elf_basevirtual address where the elf image is mapped
elf_bytessize of the mapped elf image
namename of the symbol to look for
containsif non zero, search for containing rather than exact match
typetype of the symbol STT_*
sindexindex where to start and returns the index of the symbol
Returns
pointer to the symbol NULL if there is none
errval_t elf64_load ( uint16_t  em_machine,
elf_allocator_fn  allocate_func,
void *  state,
lvaddr_t  base,
size_t  size,
genvaddr_t *  retentry,
genvaddr_t *  ret_tlsbase,
size_t *  ret_tlsinitlen,
size_t *  ret_tlstotallen 
)

Load ELF64 binary image into memory.

This function loads an ELF64 binary image, based at 'base' and of size 'size' into the memory provided by 'allocate'

Parameters
em_machineELF machine type.
allocateMemory allocation function.
statePointer to state for allocation function.
baseBase address of ELF64 binary image in memory.
sizeSize of ELF64 binary image in bytes.
retentryUsed to return entry point address
ret_tlsbaseUsed to return TLS block base address
ret_tlsinitlenUsed to return length of initialised TLS data block
ret_tlstotallenUsed to return total length of TLS data
void elf64_relocate ( genvaddr_t  dst,
genvaddr_t  src,
struct Elf64_Rela rela,
size_t  size,
struct Elf64_Sym symtab,
size_t  symsize,
genvaddr_t  start,
void *  vbase 
)

Relocates the ELF image from src to dst.

This function processes the ELF relocation section 'rela' of size 'size' of the ELF image, formerly located at 'src', to the new location 'dst'. Relocation is necessary for certain variables that cannot be coded as position-independent code.

Parameters
dstAddress to relocate to.
srcFormer base address of the ELF image.
relaPointer to relocation section of the ELF image.
sizeSize in bytes of the ELF relocation section.
symtabPointer to ELF symbol table.
symsizeSize in bytes of the ELF symbol table.
startOriginal base address of the ELF image (needed for symbol-table-based relocations – we don't touch the symbol table).
vbasePointer to ELF image in virtual memory.