FreeBSD kernel kern code
link_elf.c File Reference
#include <sys/cdefs.h>
#include "opt_ddb.h"
#include "opt_gdb.h"
#include <sys/param.h>
#include <sys/systm.h>
#include <sys/kernel.h>
#include <sys/lock.h>
#include <sys/malloc.h>
#include <sys/mutex.h>
#include <sys/mount.h>
#include <sys/pcpu.h>
#include <sys/proc.h>
#include <sys/namei.h>
#include <sys/fcntl.h>
#include <sys/vnode.h>
#include <sys/linker.h>
#include <machine/elf.h>
#include <net/vnet.h>
#include <security/mac/mac_framework.h>
#include <vm/vm.h>
#include <vm/vm_param.h>
#include <vm/pmap.h>
#include <vm/vm_map.h>
#include <sys/link_elf.h>
#include "linker_if.h"
#include <kern/kern_ctf.c>
Include dependency graph for link_elf.c:

Go to the source code of this file.

Data Structures

struct  elf_file
 
struct  elf_set
 

Macros

#define MAXSEGS   4
 

Typedefs

typedef struct elf_fileelf_file_t
 

Functions

 __FBSDID ("$BSDSUniX$")
 
 TAILQ_HEAD (elf_set_head, elf_set)
 
static int link_elf_link_common_finish (linker_file_t)
 
static int link_elf_link_preload (linker_class_t cls, const char *, linker_file_t *)
 
static int link_elf_link_preload_finish (linker_file_t)
 
static int link_elf_load_file (linker_class_t, const char *, linker_file_t *)
 
static int link_elf_lookup_symbol (linker_file_t, const char *, c_linker_sym_t *)
 
static int link_elf_symbol_values (linker_file_t, c_linker_sym_t, linker_symval_t *)
 
static int link_elf_search_symbol (linker_file_t, caddr_t, c_linker_sym_t *, long *)
 
static void link_elf_unload_file (linker_file_t)
 
static void link_elf_unload_preload (linker_file_t)
 
static int link_elf_lookup_set (linker_file_t, const char *, void ***, void ***, int *)
 
static int link_elf_each_function_name (linker_file_t, int(*)(const char *, void *), void *)
 
static int link_elf_each_function_nameval (linker_file_t, linker_function_nameval_callback_t, void *)
 
static void link_elf_reloc_local (linker_file_t)
 
static long link_elf_symtab_get (linker_file_t, const Elf_Sym **)
 
static long link_elf_strtab_get (linker_file_t, caddr_t *)
 
static Elf_Addr elf_lookup (linker_file_t, Elf_Size, int)
 
static int parse_dynamic (elf_file_t)
 
static int relocate_file (elf_file_t)
 
static int link_elf_preload_parse_symbols (elf_file_t)
 
static void elf_set_add (struct elf_set_head *list, Elf_Addr start, Elf_Addr stop, Elf_Addr base)
 
static int elf_set_find (struct elf_set_head *list, Elf_Addr addr, Elf_Addr *start, Elf_Addr *base)
 
static void elf_set_delete (struct elf_set_head *list, Elf_Addr start)
 
static void link_elf_error (const char *filename, const char *s)
 
static void link_elf_init (void *arg)
 
 SYSINIT (link_elf, SI_SUB_KLD, SI_ORDER_THIRD, link_elf_init, 0)
 
static int parse_dpcpu (elf_file_t ef)
 
Elf_Addr elf_relocaddr (linker_file_t lf, Elf_Addr x)
 
static const char * symbol_name (elf_file_t ef, Elf_Size r_info)
 
static unsigned long elf_hash (const char *name)
 
const Elf_Sym * elf_get_sym (linker_file_t lf, Elf_Size symidx)
 
const char * elf_get_symname (linker_file_t lf, Elf_Size symidx)
 

Variables

static kobj_method_t link_elf_methods []
 
static struct linker_class link_elf_class
 
static struct elf_set_head set_pcpu_list
 
struct _dynamic _DYNAMIC
 

Macro Definition Documentation

#define MAXSEGS   4

Definition at line 74 of file link_elf.c.

Referenced by link_elf_load_file().

Typedef Documentation

typedef struct elf_file * elf_file_t

Function Documentation

__FBSDID ( "$BSDSUniX$"  )
const Elf_Sym* elf_get_sym ( linker_file_t  lf,
Elf_Size  symidx 
)

Definition at line 1496 of file link_elf.c.

References elf_file::nchains, and elf_file::symtab.

const char* elf_get_symname ( linker_file_t  lf,
Elf_Size  symidx 
)

Definition at line 1506 of file link_elf.c.

References elf_file::nchains, elf_file::strtab, sym, and elf_file::symtab.

static unsigned long elf_hash ( const char *  name)
static

Definition at line 1236 of file link_elf.c.

Referenced by link_elf_lookup_symbol().

Here is the caller graph for this function:

static Elf_Addr elf_lookup ( linker_file_t  lf,
Elf_Size  symidx,
int  deps 
)
static

Definition at line 1525 of file link_elf.c.

References elf_file::address, elf_set_find(), linker_file_lookup_symbol(), elf_file::nchains, set_pcpu_list, start, elf_file::strtab, sym, and elf_file::symtab.

Referenced by link_elf_reloc_local(), and relocate_file().

Here is the call graph for this function:

Here is the caller graph for this function:

Elf_Addr elf_relocaddr ( linker_file_t  lf,
Elf_Addr  x 
)

Definition at line 1062 of file link_elf.c.

References elf_file::pcpu_base, and elf_file::pcpu_start.

static void elf_set_add ( struct elf_set_head *  list,
Elf_Addr  start,
Elf_Addr  stop,
Elf_Addr  base 
)
static

Definition at line 199 of file link_elf.c.

References elf_set::es_base, elf_set::es_start, elf_set::es_stop, malloc(), set, start, and stop.

Referenced by parse_dpcpu().

Here is the call graph for this function:

Here is the caller graph for this function:

static void elf_set_delete ( struct elf_set_head *  list,
Elf_Addr  start 
)
static

Definition at line 245 of file link_elf.c.

References elf_set::es_start, free(), and set.

Referenced by link_elf_unload_file().

Here is the call graph for this function:

Here is the caller graph for this function:

static int elf_set_find ( struct elf_set_head *  list,
Elf_Addr  addr,
Elf_Addr *  start,
Elf_Addr *  base 
)
static

Definition at line 227 of file link_elf.c.

References elf_set::es_base, elf_set::es_start, and set.

Referenced by elf_lookup().

Here is the caller graph for this function:

static int link_elf_each_function_name ( linker_file_t  file,
int(*)(const char *, void *)  callback,
void *  opaque 
)
static

Definition at line 1436 of file link_elf.c.

References callback, elf_file::ddbstrtab, elf_file::ddbsymtab, and symp.

static int link_elf_each_function_nameval ( linker_file_t  file,
linker_function_nameval_callback_t  callback,
void *  opaque 
)
static

Definition at line 1456 of file link_elf.c.

References callback, elf_file::ddbsymtab, link_elf_symbol_values(), and symp.

Here is the call graph for this function:

static void link_elf_error ( const char *  filename,
const char *  s 
)
static

Definition at line 330 of file link_elf.c.

References printf().

Referenced by link_elf_load_file().

Here is the call graph for this function:

Here is the caller graph for this function:

static int link_elf_link_common_finish ( linker_file_t  lf)
static

Definition at line 343 of file link_elf.c.

References elf_file::address, elf_file::dynamic, and malloc().

Referenced by link_elf_init(), link_elf_link_preload_finish(), and link_elf_load_file().

Here is the call graph for this function:

Here is the caller graph for this function:

static int link_elf_link_preload ( linker_class_t  cls,
const char *  filename,
linker_file_t *  result 
)
static
static int link_elf_link_preload_finish ( linker_file_t  lf)
static

Definition at line 699 of file link_elf.c.

References elf_file::dynamic, link_elf_link_common_finish(), link_elf_preload_parse_symbols(), linker_load_module(), relocate_file(), and elf_file::strtab.

Here is the call graph for this function:

static int link_elf_lookup_set ( linker_file_t  lf,
const char *  name,
void ***  startp,
void ***  stopp,
int *  countp 
)
static

Definition at line 1383 of file link_elf.c.

References count, free(), link_elf_lookup_symbol(), link_elf_symbol_values(), malloc(), snprintf(), start, stop, and sym.

Referenced by parse_dpcpu().

Here is the call graph for this function:

Here is the caller graph for this function:

static int link_elf_lookup_symbol ( linker_file_t  lf,
const char *  name,
c_linker_sym_t *  sym 
)
static

Definition at line 1252 of file link_elf.c.

References elf_file::buckets, elf_file::chains, elf_file::ddbstrtab, elf_file::ddbsymtab, elf_hash(), elf_file::nbuckets, elf_file::nchains, printf(), elf_file::strtab, symp, and elf_file::symtab.

Referenced by link_elf_lookup_set().

Here is the call graph for this function:

Here is the caller graph for this function:

static int link_elf_preload_parse_symbols ( elf_file_t  ef)
static

Definition at line 435 of file link_elf.c.

References elf_file::ddbstrcnt, elf_file::ddbstrtab, elf_file::ddbsymcnt, elf_file::ddbsymtab, elf_file::modptr, preload_search_info(), printf(), strtab, and symtab.

Referenced by link_elf_init(), and link_elf_link_preload_finish().

Here is the call graph for this function:

Here is the caller graph for this function:

static void link_elf_reloc_local ( linker_file_t  lf)
static

Definition at line 1574 of file link_elf.c.

References elf_file::address, elf_lookup(), elf_file::rel, elf_file::rela, elf_file::relasize, and elf_file::relsize.

Referenced by link_elf_link_preload(), and link_elf_load_file().

Here is the call graph for this function:

Here is the caller graph for this function:

static int link_elf_search_symbol ( linker_file_t  lf,
caddr_t  value,
c_linker_sym_t *  sym,
long *  diffp 
)
static

Definition at line 1344 of file link_elf.c.

References elf_file::address, elf_file::ddbsymtab, and value.

static long link_elf_strtab_get ( linker_file_t  lf,
caddr_t *  strtab 
)
static

Definition at line 1618 of file link_elf.c.

References elf_file::ddbstrcnt, and elf_file::ddbstrtab.

static int link_elf_symbol_values ( linker_file_t  lf,
c_linker_sym_t  sym,
linker_symval_t *  symval 
)
static
static long link_elf_symtab_get ( linker_file_t  lf,
const Elf_Sym **  symtab 
)
static

Definition at line 1605 of file link_elf.c.

References elf_file::ddbsymcnt, and elf_file::ddbsymtab.

static void link_elf_unload_preload ( linker_file_t  file)
static

Definition at line 1134 of file link_elf.c.

References preload_delete_name().

Referenced by link_elf_unload_file().

Here is the call graph for this function:

Here is the caller graph for this function:

static int parse_dpcpu ( elf_file_t  ef)
static

Definition at line 577 of file link_elf.c.

References count, dpcpu_alloc(), dpcpu_copy(), elf_set_add(), elf_file::lf, link_elf_lookup_set(), elf_file::pcpu_base, elf_file::pcpu_start, elf_file::pcpu_stop, and set_pcpu_list.

Referenced by link_elf_link_preload(), and link_elf_load_file().

Here is the call graph for this function:

Here is the caller graph for this function:

static int relocate_file ( elf_file_t  ef)
static

Definition at line 1153 of file link_elf.c.

References elf_file::address, elf_lookup(), elf_file::lf, elf_file::pltrel, elf_file::pltrela, elf_file::pltrelasize, elf_file::pltrelsize, printf(), elf_file::rel, elf_file::rela, elf_file::relasize, elf_file::relsize, and symbol_name().

Referenced by link_elf_link_preload_finish(), and link_elf_load_file().

Here is the call graph for this function:

Here is the caller graph for this function:

static const char* symbol_name ( elf_file_t  ef,
Elf_Size  r_info 
)
static

Definition at line 1141 of file link_elf.c.

References elf_file::strtab, and elf_file::symtab.

Referenced by mi_startup(), and relocate_file().

Here is the caller graph for this function:

SYSINIT ( link_elf  ,
SI_SUB_KLD  ,
SI_ORDER_THIRD  ,
link_elf_init  ,
 
)
TAILQ_HEAD ( elf_set_head  ,
elf_set   
)

Variable Documentation

struct _dynamic _DYNAMIC

Referenced by link_elf_init().

struct linker_class link_elf_class
static
Initial value:
= {
"elf32",
link_elf_methods, sizeof(struct elf_file)
}

Definition at line 180 of file link_elf.c.

kobj_method_t link_elf_methods[]
static
Initial value:
= {
KOBJMETHOD(linker_lookup_symbol, link_elf_lookup_symbol),
KOBJMETHOD(linker_symbol_values, link_elf_symbol_values),
KOBJMETHOD(linker_search_symbol, link_elf_search_symbol),
KOBJMETHOD(linker_unload, link_elf_unload_file),
KOBJMETHOD(linker_link_preload, link_elf_link_preload),
KOBJMETHOD(linker_link_preload_finish, link_elf_link_preload_finish),
KOBJMETHOD(linker_lookup_set, link_elf_lookup_set),
KOBJMETHOD(linker_each_function_name, link_elf_each_function_name),
KOBJMETHOD(linker_each_function_nameval, link_elf_each_function_nameval),
KOBJMETHOD(linker_symtab_get, link_elf_symtab_get),
KOBJMETHOD(linker_strtab_get, link_elf_strtab_get),
{ 0, 0 }
}
int linker_ctf_get(linker_file_t file, linker_ctf_t *lc)
Definition: kern_linker.c:725
static int link_elf_ctf_get(linker_file_t lf, linker_ctf_t *lc)
Definition: kern_ctf.c:59
static int linker_load_file(const char *filename, linker_file_t *result)
Definition: kern_linker.c:388

Definition at line 163 of file link_elf.c.

struct elf_set_head set_pcpu_list
static

Definition at line 193 of file link_elf.c.

Referenced by elf_lookup(), link_elf_init(), link_elf_unload_file(), and parse_dpcpu().