KallistiOS  ##version##
 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Macros Groups
Data Structures | Macros | Typedefs | Functions
elf.h File Reference

ELF binary loading support. More...

#include <sys/cdefs.h>
#include <arch/types.h>
#include <sys/queue.h>

Go to the source code of this file.

Data Structures

struct  elf_hdr_t
 ELF file header. More...
 
struct  elf_shdr_t
 ELF Section header. More...
 
struct  elf_sym_t
 Symbol table entry. More...
 
struct  elf_rela_t
 ELF Relocation entry (with explicit addend). More...
 
struct  elf_rel_t
 ELF Relocation entry (without explicit addend). More...
 
struct  elf_prog
 Kernel-specific definition of a loaded ELF binary. More...
 

Macros

#define EM_386   3
 x86 (IA32) More...
 
#define EM_ARM   40
 ARM. More...
 
#define EM_SH   42
 SuperH. More...
 
#define SHT_NULL   0
 Inactive section. More...
 
#define SHT_PROGBITS   1
 Program code/data. More...
 
#define SHT_SYMTAB   2
 Full symbol table. More...
 
#define SHT_STRTAB   3
 String table. More...
 
#define SHT_RELA   4
 Relocation table, with addends. More...
 
#define SHT_HASH   5
 Symbol hash table. More...
 
#define SHT_DYNAMIC   6
 Dynamic linking info. More...
 
#define SHT_NOTE   7
 Notes section. More...
 
#define SHT_NOBITS   8
 A section that occupies no space in the file. More...
 
#define SHT_REL   9
 Relocation table, no addends. More...
 
#define SHT_SHLIB   10
 Reserved. More...
 
#define SHT_DYNSYM   11
 Dynamic-only sym tab. More...
 
#define SHT_LOPROC   0x70000000
 Start of processor specific types. More...
 
#define SHT_HIPROC   0x7fffffff
 End of processor specific types. More...
 
#define SHT_LOUSER   0x80000000
 Start of program specific types. More...
 
#define SHT_HIUSER   0xffffffff
 End of program specific types. More...
 
#define SHF_WRITE   1
 Writable data. More...
 
#define SHF_ALLOC   2
 Resident. More...
 
#define SHF_EXECINSTR   4
 Executable instructions. More...
 
#define SHF_MASKPROC   0xf0000000
 Processor specific mask. More...
 
#define SHN_UNDEF   0
 Undefined, missing, irrelevant. More...
 
#define SHN_ABS   0xfff1
 Absolute values. More...
 
#define STB_LOCAL   0
 Local (non-exported) symbol. More...
 
#define STB_GLOBAL   1
 Global (exported) symbol. More...
 
#define STB_WEAK   2
 Weak-linked symbol. More...
 
#define STT_NOTYPE   0
 Symbol has no type. More...
 
#define STT_OBJECT   1
 Symbol is an object. More...
 
#define STT_FUNC   2
 Symbol is a function. More...
 
#define STT_SECTION   3
 Symbol is a section. More...
 
#define STT_FILE   4
 Symbol is a file name. More...
 
#define ELF32_ST_BIND(info)   ((info) >> 4)
 Retrieve the binding type for a symbol. More...
 
#define ELF32_ST_TYPE(info)   ((info) & 0xf)
 Retrieve the symbol type for a symbol. More...
 
#define R_SH_DIR32   1
 SuperH: Rel = Symbol + Addend. More...
 
#define R_386_32   1
 x86: Rel = Symbol + Addend More...
 
#define R_386_PC32   2
 x86: Rel = Symbol + Addend - Value More...
 
#define ELF32_R_SYM(i)   ((i) >> 8)
 Retrieve the symbol index from a relocation entry. More...
 
#define ELF32_R_TYPE(i)   ((uint8)(i))
 Retrieve the relocation type from a relocation entry. More...
 

Typedefs

typedef struct elf_prog elf_prog_t
 Kernel-specific definition of a loaded ELF binary. More...
 

Functions

int elf_load (const char *fn, struct klibrary *shell, elf_prog_t *out)
 Load an ELF binary. More...
 
void elf_free (elf_prog_t *prog)
 Free a loaded ELF program. More...
 

Detailed Description

ELF binary loading support.

This file contains the support functionality for loading ELF binaries in KOS. This includes the various header structures and whatnot that are used in ELF files to store code/data/relocations/etc. This isn't necessarily meant for running multiple processes, but more for loadable library support within KOS.

Author
Dan Potter

Macro Definition Documentation

#define ELF32_R_SYM (   i)    ((i) >> 8)

Retrieve the symbol index from a relocation entry.

Parameters
iThe info field of an elf_rel_t or elf_rela_t.
Returns
The symbol table index from that relocation entry.
#define ELF32_R_TYPE (   i)    ((uint8)(i))

Retrieve the relocation type from a relocation entry.

Parameters
iThe info field of an elf_rel_t or an elf_rela_t.
Returns
The relocation type of that relocation.
See also
ELF relocation types
#define ELF32_ST_BIND (   info)    ((info) >> 4)

Retrieve the binding type for a symbol.

Parameters
infoThe info field of an elf_sym_t.
Returns
The binding type of the symbol.
See also
Symbol binding types.
#define ELF32_ST_TYPE (   info)    ((info) & 0xf)

Retrieve the symbol type for a symbol.

Parameters
infoThe info field of an elf_sym_t.
Returns
The symbol type of the symbol.
See also
Symbol types.

Typedef Documentation

typedef struct elf_prog elf_prog_t

Kernel-specific definition of a loaded ELF binary.

This structure represents the internal representation of a loaded ELF binary in KallistiOS (specifically as a dynamically loaded library).

Function Documentation

void elf_free ( elf_prog_t prog)

Free a loaded ELF program.

This function cleans up an ELF binary that was loaded with elf_load().

Parameters
progThe loaded binary to clean up.
int elf_load ( const char *  fn,
struct klibrary shell,
elf_prog_t out 
)

Load an ELF binary.

This function loads an ELF binary from the VFS and fills in an elf_prog_t for it.

Parameters
fnThe filename of the binary on the VFS.
shellUnused?
outStorage for the binary that will be loaded.
Returns
0 on success, <0 on failure.