PS2SDK
PS2 Homebrew Libraries
Loading...
Searching...
No Matches
erl.c File Reference
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include <sys/fcntl.h>
#include <sys/unistd.h>
#include <erl.h>
#include <hashtab.h>
#include <recycle.h>
+ Include dependency graph for erl.c:

Go to the source code of this file.

Data Structures

struct  elf_header_t
 
struct  elf_section_t
 
struct  elf_symbol_t
 
struct  elf_reloc_t
 
struct  elf_rela_t
 
struct  loosy_t
 
struct  dependancy_t
 
union  elf_header_t.e_ident
 
struct  e_ident_t.e_ident.cook
 

Macros

#define DEBUG   1
 
#define STANDALONE   1
 
#define FORCE_ALIGN   1
 
#define dprintf(a...)   do { } while(0)
 
#define rprintf(a...)   do { } while(0)
 
#define REL_TYPE   1
 
#define PROGBITS   1
 
#define NOBITS   8
 
#define REL   9
 
#define RELA   4
 
#define GLOBAL   1
 
#define WEAK   2
 
#define NOTYPE   0
 
#define OBJECT   1
 
#define FUNC   2
 
#define SECTION   3
 
#define R_MIPS_32   2
 
#define R_MIPS_26   4
 
#define R_MIPS_HI16   5
 
#define R_MIPS_LO16   6
 
#define free_and_return(code)
 
#define O_BINARY   0
 

Typedefs

typedef unsigned char u8
 
typedef unsigned short u16
 
typedef unsigned int u32
 
typedef signed char s8
 
typedef signed short s16
 
typedef signed int s32
 
typedef int(* func_t) (void)
 
typedef int(* start_t) (int argc, char **argv)
 

Functions

static u32 align (u32 x, int align)
 
static struct loosy_tcreate_loosy (struct erl_record_t *erl, u8 *reloc, int type)
 
static void destroy_loosy (struct loosy_t *l)
 
static void r_destroy_loosy (struct loosy_t *l)
 
static struct symbol_tcreate_symbol (struct erl_record_t *provider, u32 address)
 
static void destroy_symbol (struct symbol_t *s)
 
static struct erl_record_tallocate_erl_record ()
 
static void destroy_erl_record (struct erl_record_t *erl)
 
static int apply_reloc (u8 *reloc, int type, u32 addr)
 
struct symbol_terl_find_local_symbol (const char *symbol, struct erl_record_t *erl)
 
static struct symbol_tr_find_symbol (const char *symbol, struct erl_record_t *erl)
 
struct symbol_terl_find_symbol (const char *symbol)
 
static struct dependancy_tadd_dependancy (struct erl_record_t *depender, struct erl_record_t *provider)
 
static void destroy_dependancy (struct dependancy_t *d)
 
static void r_destroy_dependancy_r (struct erl_record_t *erl, struct dependancy_t *d)
 
static void destroy_dependancy_r (struct erl_record_t *erl)
 
static void add_loosy (struct erl_record_t *erl, u8 *reloc, int type, const char *symbol)
 
static int fix_loosy (struct erl_record_t *provider, const char *symbol, u32 address)
 
static int is_local (const char *symbol)
 
static int add_symbol (struct erl_record_t *erl, const char *symbol, u32 address)
 
int erl_add_global_symbol (const char *symbol, u32 address)
 
static int read_erl (int elf_handle, u8 *elf_mem, u32 addr, struct erl_record_t **p_erl_record)
 
static struct erl_record_t_init_load_erl_wrapper_from_file (char *erl_id)
 
static struct erl_record_tload_erl (const char *fname, u8 *elf_mem, u32 addr, int argc, char **argv)
 
struct erl_record_t_init_load_erl_from_file (const char *fname, char *erl_id)
 
struct erl_record_tload_erl_from_file (const char *fname, int argc, char **argv)
 
struct erl_record_tload_erl_from_mem (u8 *mem, int argc, char **argv)
 
struct erl_record_tload_erl_from_mem_to_addr (u8 *mem, u32 addr, int argc, char **argv)
 
struct erl_record_tload_erl_from_file_to_addr (const char *fname, u32 addr, int argc, char **argv)
 
struct erl_record_t_init_load_erl_from_file_to_addr (const char *fname, u32 addr, char *erl_id)
 
void r_unload_dependancies (char **d)
 
int unload_erl (struct erl_record_t *erl)
 
struct erl_record_terl_resolve (u32 address)
 
struct erl_record_tfind_erl (const char *name)
 
void erl_flush_symbols (struct erl_record_t *erl)
 

Variables

static const char * local_names []
 
static struct erl_record_terl_record_root = 0
 
static htabglobal_symbols = 0
 
static htabloosy_relocs = 0
 
char _init_erl_prefix [256] = ""
 
static struct dependancy_tdependancy_root = 0
 
static rerootsymbol_recycle = 0
 
erl_loader_t _init_load_erl = _init_load_erl_wrapper_from_file
 

Detailed Description

The relocatable elf loader/linker.

Definition in file erl.c.


Data Structure Documentation

◆ elf_section_t

struct elf_section_t

Definition at line 245 of file erl.c.

Data Fields
u32 sh_name
u32 sh_type
u32 sh_flags
u32 sh_addr
u32 sh_offset
u32 sh_size
u32 sh_link
u32 sh_info
u32 sh_addralign
u32 sh_entsize

◆ elf_symbol_t

struct elf_symbol_t

Definition at line 250 of file erl.c.

Data Fields
u32 st_name
u32 st_value
u32 st_size
u8 st_info
u8 st_other
u16 st_shndx

◆ elf_reloc_t

struct elf_reloc_t

Definition at line 256 of file erl.c.

Data Fields
u32 r_offset
u32 r_info

◆ elf_rela_t

struct elf_rela_t

Definition at line 260 of file erl.c.

Data Fields
u32 r_offset
u32 r_info
u32 r_addend

◆ loosy_t

struct loosy_t

Definition at line 266 of file erl.c.

+ Collaboration diagram for loosy_t:
Data Fields
u8 * reloc
int type
struct loosy_t * next
struct erl_record_t * erl

◆ dependancy_t

struct dependancy_t

Definition at line 273 of file erl.c.

+ Collaboration diagram for dependancy_t:
Data Fields
struct erl_record_t * depender
struct erl_record_t * provider
struct dependancy_t * next
struct dependancy_t * prev

◆ elf_header_t.e_ident

union elf_header_t.e_ident

Definition at line 221 of file erl.c.

Data Fields
u8 raw[16]
struct e_ident_t.e_ident.cook cook

◆ elf_header_t::e_ident_t.e_ident.cook

struct elf_header_t::e_ident_t.e_ident.cook

Definition at line 223 of file erl.c.

Data Fields
u8 ei_magic[4]
u8 ei_class
u8 ei_data
u8 ei_version

Macro Definition Documentation

◆ DEBUG

#define DEBUG   1

Definition at line 16 of file erl.c.

◆ STANDALONE

#define STANDALONE   1

Definition at line 17 of file erl.c.

◆ FORCE_ALIGN

#define FORCE_ALIGN   1

Definition at line 18 of file erl.c.

◆ dprintf

#define dprintf (   a...)    do { } while(0)

Definition at line 33 of file erl.c.

◆ rprintf

#define rprintf (   a...)    do { } while(0)

Definition at line 34 of file erl.c.

◆ REL_TYPE

#define REL_TYPE   1

Definition at line 187 of file erl.c.

◆ PROGBITS

#define PROGBITS   1

Definition at line 188 of file erl.c.

◆ NOBITS

#define NOBITS   8

Definition at line 189 of file erl.c.

◆ REL

#define REL   9

Definition at line 190 of file erl.c.

◆ RELA

#define RELA   4

Definition at line 191 of file erl.c.

◆ GLOBAL

#define GLOBAL   1

Definition at line 192 of file erl.c.

◆ WEAK

#define WEAK   2

Definition at line 193 of file erl.c.

◆ NOTYPE

#define NOTYPE   0

Definition at line 194 of file erl.c.

◆ OBJECT

#define OBJECT   1

Definition at line 195 of file erl.c.

◆ FUNC

#define FUNC   2

Definition at line 196 of file erl.c.

◆ SECTION

#define SECTION   3

Definition at line 197 of file erl.c.

◆ R_MIPS_32

#define R_MIPS_32   2

Definition at line 198 of file erl.c.

◆ R_MIPS_26

#define R_MIPS_26   4

Definition at line 199 of file erl.c.

◆ R_MIPS_HI16

#define R_MIPS_HI16   5

Definition at line 200 of file erl.c.

◆ R_MIPS_LO16

#define R_MIPS_LO16   6

Definition at line 201 of file erl.c.

◆ free_and_return

#define free_and_return (   code)
Value:
if (!elf_mem) { \
if (names) free(names); \
if (strtab_names) free(strtab_names); \
if (sec) free(sec); \
if (sym) free(sym); \
if ((code < 0) && erl_record) destroy_erl_record(erl_record); \
} \
return code

◆ O_BINARY

#define O_BINARY   0

Definition at line 929 of file erl.c.

Typedef Documentation

◆ u8

typedef unsigned char u8

Definition at line 63 of file erl.c.

◆ u16

typedef unsigned short u16

Definition at line 64 of file erl.c.

◆ u32

typedef unsigned int u32

Definition at line 65 of file erl.c.

◆ s8

typedef signed char s8

Definition at line 66 of file erl.c.

◆ s16

typedef signed short s16

Definition at line 67 of file erl.c.

◆ s32

typedef signed int s32

Definition at line 68 of file erl.c.

◆ func_t

typedef int(* func_t) (void)

Definition at line 932 of file erl.c.

◆ start_t

typedef int(* start_t) (int argc, char **argv)

Definition at line 933 of file erl.c.

Function Documentation

◆ align()

static u32 align ( u32  x,
int  align 
)
static

Definition at line 290 of file erl.c.

◆ create_loosy()

static struct loosy_t * create_loosy ( struct erl_record_t erl,
u8 *  reloc,
int  type 
)
static

Definition at line 306 of file erl.c.

◆ destroy_loosy()

static void destroy_loosy ( struct loosy_t l)
static

Definition at line 320 of file erl.c.

◆ r_destroy_loosy()

static void r_destroy_loosy ( struct loosy_t l)
static

Definition at line 324 of file erl.c.

◆ create_symbol()

static struct symbol_t * create_symbol ( struct erl_record_t provider,
u32  address 
)
static

Definition at line 335 of file erl.c.

◆ destroy_symbol()

static void destroy_symbol ( struct symbol_t s)
static

Definition at line 349 of file erl.c.

◆ allocate_erl_record()

static struct erl_record_t * allocate_erl_record ( )
static

Definition at line 353 of file erl.c.

◆ destroy_erl_record()

static void destroy_erl_record ( struct erl_record_t erl)
static

Definition at line 372 of file erl.c.

◆ apply_reloc()

static int apply_reloc ( u8 *  reloc,
int  type,
u32  addr 
)
static

Definition at line 396 of file erl.c.

◆ erl_find_local_symbol()

struct symbol_t * erl_find_local_symbol ( const char *  symbol,
struct erl_record_t erl 
)

Definition at line 431 of file erl.c.

◆ r_find_symbol()

static struct symbol_t * r_find_symbol ( const char *  symbol,
struct erl_record_t erl 
)
static

Definition at line 439 of file erl.c.

◆ erl_find_symbol()

struct symbol_t * erl_find_symbol ( const char *  symbol)

Definition at line 447 of file erl.c.

◆ add_dependancy()

static struct dependancy_t * add_dependancy ( struct erl_record_t depender,
struct erl_record_t provider 
)
static

Definition at line 454 of file erl.c.

◆ destroy_dependancy()

static void destroy_dependancy ( struct dependancy_t d)
static

Definition at line 475 of file erl.c.

◆ r_destroy_dependancy_r()

static void r_destroy_dependancy_r ( struct erl_record_t erl,
struct dependancy_t d 
)
static

Definition at line 487 of file erl.c.

◆ destroy_dependancy_r()

static void destroy_dependancy_r ( struct erl_record_t erl)
static

Definition at line 499 of file erl.c.

◆ add_loosy()

static void add_loosy ( struct erl_record_t erl,
u8 *  reloc,
int  type,
const char *  symbol 
)
static

Definition at line 503 of file erl.c.

◆ fix_loosy()

static int fix_loosy ( struct erl_record_t provider,
const char *  symbol,
u32  address 
)
static

Definition at line 519 of file erl.c.

◆ is_local()

static int is_local ( const char *  symbol)
static

Definition at line 540 of file erl.c.

◆ add_symbol()

static int add_symbol ( struct erl_record_t erl,
const char *  symbol,
u32  address 
)
static

Definition at line 550 of file erl.c.

◆ erl_add_global_symbol()

int erl_add_global_symbol ( const char *  symbol,
u32  address 
)

Definition at line 578 of file erl.c.

◆ read_erl()

static int read_erl ( int  elf_handle,
u8 *  elf_mem,
u32  addr,
struct erl_record_t **  p_erl_record 
)
static

Definition at line 582 of file erl.c.

◆ _init_load_erl_wrapper_from_file()

static struct erl_record_t * _init_load_erl_wrapper_from_file ( char *  erl_id)
static

Definition at line 935 of file erl.c.

◆ load_erl()

static struct erl_record_t * load_erl ( const char *  fname,
u8 *  elf_mem,
u32  addr,
int  argc,
char **  argv 
)
static

Definition at line 944 of file erl.c.

◆ _init_load_erl_from_file()

struct erl_record_t * _init_load_erl_from_file ( const char *  fname,
char *  erl_id 
)

Definition at line 1016 of file erl.c.

◆ load_erl_from_file()

struct erl_record_t * load_erl_from_file ( const char *  fname,
int  argc,
char **  argv 
)

Definition at line 1035 of file erl.c.

◆ load_erl_from_mem()

struct erl_record_t * load_erl_from_mem ( u8 *  mem,
int  argc,
char **  argv 
)

Definition at line 1039 of file erl.c.

◆ load_erl_from_mem_to_addr()

struct erl_record_t * load_erl_from_mem_to_addr ( u8 *  mem,
u32  addr,
int  argc,
char **  argv 
)

Definition at line 1046 of file erl.c.

◆ load_erl_from_file_to_addr()

struct erl_record_t * load_erl_from_file_to_addr ( const char *  fname,
u32  addr,
int  argc,
char **  argv 
)

Definition at line 1053 of file erl.c.

◆ _init_load_erl_from_file_to_addr()

struct erl_record_t * _init_load_erl_from_file_to_addr ( const char *  fname,
u32  addr,
char *  erl_id 
)

Definition at line 1060 of file erl.c.

◆ r_unload_dependancies()

void r_unload_dependancies ( char **  d)

Definition at line 1079 of file erl.c.

◆ unload_erl()

int unload_erl ( struct erl_record_t erl)

Definition at line 1090 of file erl.c.

◆ erl_resolve()

struct erl_record_t * erl_resolve ( u32  address)

Definition at line 1127 of file erl.c.

◆ find_erl()

struct erl_record_t * find_erl ( const char *  name)

Definition at line 1139 of file erl.c.

◆ erl_flush_symbols()

void erl_flush_symbols ( struct erl_record_t erl)

Definition at line 1151 of file erl.c.

Variable Documentation

◆ local_names

const char* local_names[]
static
Initial value:
= {
"_init",
"_fini",
"erl_id",
"erl_dependancies",
"erl_copyright",
"erl_version",
"_start",
0
}

Definition at line 206 of file erl.c.

◆ erl_record_root

struct erl_record_t* erl_record_root = 0
static

Definition at line 280 of file erl.c.

◆ global_symbols

htab* global_symbols = 0
static

Definition at line 282 of file erl.c.

◆ loosy_relocs

htab* loosy_relocs = 0
static

Definition at line 283 of file erl.c.

◆ _init_erl_prefix

char _init_erl_prefix[256] = ""

Definition at line 285 of file erl.c.

◆ dependancy_root

struct dependancy_t* dependancy_root = 0
static

Definition at line 287 of file erl.c.

◆ symbol_recycle

reroot* symbol_recycle = 0
static

Definition at line 333 of file erl.c.

◆ _init_load_erl

erl_loader_t _init_load_erl = _init_load_erl_wrapper_from_file

Definition at line 942 of file erl.c.