PS2SDK
PS2 Homebrew Libraries
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]
e_ident 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

◆ 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

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.