FreeBSD kernel kern code
link_elf_obj.c File Reference
#include <sys/cdefs.h>
#include "opt_ddb.h"
#include <sys/param.h>
#include <sys/systm.h>
#include <sys/fcntl.h>
#include <sys/kernel.h>
#include <sys/lock.h>
#include <sys/malloc.h>
#include <sys/linker.h>
#include <sys/mutex.h>
#include <sys/mount.h>
#include <sys/namei.h>
#include <sys/proc.h>
#include <sys/rwlock.h>
#include <sys/sysctl.h>
#include <sys/vnode.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_extern.h>
#include <vm/vm_kern.h>
#include <vm/vm_map.h>
#include <vm/vm_object.h>
#include <vm/vm_page.h>
#include <vm/vm_pager.h>
#include <sys/link_elf.h>
#include "linker_if.h"
#include <kern/kern_ctf.c>
Include dependency graph for link_elf_obj.c:

Go to the source code of this file.

Data Structures

struct  Elf_progent
 
struct  Elf_relent
 
struct  Elf_relaent
 
struct  elf_file
 

Typedefs

typedef struct elf_fileelf_file_t
 

Functions

 __FBSDID ("$FreeBSD$")
 
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_lookup_debug_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_debug_symbol_values (linker_file_t, c_linker_sym_t, linker_symval_t *)
 
static int link_elf_search_symbol (linker_file_t, caddr_t value, c_linker_sym_t *sym, long *diffp)
 
static void link_elf_unload_file (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 int link_elf_reloc_local (linker_file_t, bool)
 
static long link_elf_symtab_get (linker_file_t, const Elf_Sym **)
 
static long link_elf_strtab_get (linker_file_t, caddr_t *)
 
static int elf_obj_lookup (linker_file_t lf, Elf_Size symidx, int deps, Elf_Addr *)
 
 SYSCTL_BOOL (_debug, OID_AUTO, link_elf_obj_leak_locals, CTLFLAG_RWTUN, &link_elf_obj_leak_locals, 0, "Allow local symbols to participate in global module symbol resolution")
 
static int relocate_file (elf_file_t ef)
 
static void elf_obj_cleanup_globals_cache (elf_file_t)
 
static void link_elf_error (const char *filename, const char *s)
 
static void link_elf_init (void *arg)
 
 SYSINIT (link_elf_obj, SI_SUB_KLD, SI_ORDER_SECOND, link_elf_init, NULL)
 
static void link_elf_protect_range (elf_file_t ef, vm_offset_t start, vm_offset_t end, vm_prot_t prot)
 
static void link_elf_protect (elf_file_t ef)
 
static void link_elf_invoke_cbs (caddr_t addr, size_t size)
 
static const char * symbol_name (elf_file_t ef, Elf_Size r_info)
 
static Elf_Addr findbase (elf_file_t ef, int sec)
 
static int relocate_file1 (elf_file_t ef, bool ifuncs)
 
static int link_elf_lookup_symbol1 (linker_file_t lf, const char *name, c_linker_sym_t *sym, bool see_local)
 
static int link_elf_symbol_values1 (linker_file_t lf, c_linker_sym_t sym, linker_symval_t *symval, bool see_local)
 
static void link_elf_fix_link_set (elf_file_t ef)
 

Variables

static kobj_method_t link_elf_methods []
 
static struct linker_class link_elf_class
 
static bool link_elf_obj_leak_locals = true
 

Typedef Documentation

◆ elf_file_t

typedef struct elf_file * elf_file_t

Function Documentation

◆ __FBSDID()

__FBSDID ( "$FreeBSD$"  )

◆ elf_obj_cleanup_globals_cache()

static void elf_obj_cleanup_globals_cache ( elf_file_t  ef)
static

Definition at line 1629 of file link_elf_obj.c.

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

Referenced by relocate_file1().

Here is the caller graph for this function:

◆ elf_obj_lookup()

static int elf_obj_lookup ( linker_file_t  lf,
Elf_Size  symidx,
int  deps,
Elf_Addr *  res 
)
static

Definition at line 1651 of file link_elf_obj.c.

References elf_file::ddbstrtab, elf_file::ddbsymcnt, elf_file::ddbsymtab, linker_file_lookup_symbol(), res, and sym.

Referenced by link_elf_reloc_local(), and relocate_file1().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ findbase()

static Elf_Addr findbase ( elf_file_t  ef,
int  sec 
)
static

Definition at line 1321 of file link_elf_obj.c.

References Elf_progent::addr, elf_file::nprogtab, elf_file::progtab, and Elf_progent::sec.

Referenced by link_elf_reloc_local(), and relocate_file1().

Here is the caller graph for this function:

◆ link_elf_debug_symbol_values()

static int link_elf_debug_symbol_values ( linker_file_t  lf,
c_linker_sym_t  sym,
linker_symval_t *  symval 
)
static

Definition at line 1509 of file link_elf_obj.c.

References link_elf_symbol_values1(), and sym.

Referenced by link_elf_each_function_nameval().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ link_elf_each_function_name()

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

Definition at line 1583 of file link_elf_obj.c.

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

◆ link_elf_each_function_nameval()

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

Definition at line 1604 of file link_elf_obj.c.

References callback, elf_file::ddbsymtab, link_elf_debug_symbol_values(), opaque, and symp.

Here is the call graph for this function:

◆ link_elf_error()

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

Definition at line 196 of file link_elf_obj.c.

References filename, and printf().

Referenced by link_elf_load_file(), link_elf_reloc_local(), and relocate_file1().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ link_elf_fix_link_set()

static void link_elf_fix_link_set ( elf_file_t  ef)
static

◆ link_elf_init()

static void link_elf_init ( void *  arg)
static

Definition at line 205 of file link_elf_obj.c.

References link_elf_class, and linker_add_class().

Here is the call graph for this function:

◆ link_elf_invoke_cbs()

static void link_elf_invoke_cbs ( caddr_t  addr,
size_t  size 
)
static

Definition at line 638 of file link_elf_obj.c.

References addr.

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

Here is the caller graph for this function:

◆ link_elf_link_preload()

◆ link_elf_link_preload_finish()

static int link_elf_link_preload_finish ( linker_file_t  lf)
static

Definition at line 654 of file link_elf_obj.c.

References elf_file::lf, link_elf_invoke_cbs(), link_elf_protect(), link_elf_reloc_local(), and relocate_file().

Here is the call graph for this function:

◆ link_elf_load_file()

◆ link_elf_lookup_debug_symbol()

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

Definition at line 1469 of file link_elf_obj.c.

References link_elf_lookup_symbol1(), name, and sym.

Here is the call graph for this function:

◆ link_elf_lookup_set()

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

◆ link_elf_lookup_symbol()

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

Definition at line 1462 of file link_elf_obj.c.

References link_elf_lookup_symbol1(), link_elf_obj_leak_locals, name, and sym.

Here is the call graph for this function:

◆ link_elf_lookup_symbol1()

static int link_elf_lookup_symbol1 ( linker_file_t  lf,
const char *  name,
c_linker_sym_t *  sym,
bool  see_local 
)
static

Definition at line 1439 of file link_elf_obj.c.

References elf_file::ddbstrtab, elf_file::ddbsymtab, name, sym, and symp.

Referenced by link_elf_lookup_debug_symbol(), and link_elf_lookup_symbol().

Here is the caller graph for this function:

◆ link_elf_protect()

static void link_elf_protect ( elf_file_t  ef)
static

Definition at line 245 of file link_elf_obj.c.

References Elf_progent::addr, elf_file::address, Elf_progent::flags, elf_file::lf, link_elf_protect_range(), Elf_progent::name, elf_file::nprogtab, elf_file::preloaded, elf_file::progtab, Elf_progent::size, and start.

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:

◆ link_elf_protect_range()

static void link_elf_protect_range ( elf_file_t  ef,
vm_offset_t  start,
vm_offset_t  end,
vm_prot_t  prot 
)
static

Definition at line 213 of file link_elf_obj.c.

References elf_file::address, elf_file::lf, elf_file::preloaded, and start.

Referenced by link_elf_link_preload(), and link_elf_protect().

Here is the caller graph for this function:

◆ link_elf_reloc_local()

static int link_elf_reloc_local ( linker_file_t  lf,
bool  ifuncs 
)
static

◆ link_elf_search_symbol()

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

Definition at line 1516 of file link_elf_obj.c.

References elf_file::ddbsymtab, diffp, sym, and value.

◆ link_elf_strtab_get()

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

Definition at line 1855 of file link_elf_obj.c.

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

◆ link_elf_symbol_values()

static int link_elf_symbol_values ( linker_file_t  lf,
c_linker_sym_t  sym,
linker_symval_t *  symval 
)
static

Definition at line 1501 of file link_elf_obj.c.

References link_elf_obj_leak_locals, link_elf_symbol_values1(), and sym.

Here is the call graph for this function:

◆ link_elf_symbol_values1()

static int link_elf_symbol_values1 ( linker_file_t  lf,
c_linker_sym_t  sym,
linker_symval_t *  symval,
bool  see_local 
)
static

Definition at line 1476 of file link_elf_obj.c.

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

Referenced by link_elf_debug_symbol_values(), and link_elf_symbol_values().

Here is the caller graph for this function:

◆ link_elf_symtab_get()

static long link_elf_symtab_get ( linker_file_t  lf,
const Elf_Sym **  symtab 
)
static

Definition at line 1844 of file link_elf_obj.c.

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

◆ link_elf_unload_file()

◆ relocate_file()

static int relocate_file ( elf_file_t  ef)
static

Definition at line 1428 of file link_elf_obj.c.

References relocate_file1().

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:

◆ relocate_file1()

static int relocate_file1 ( elf_file_t  ef,
bool  ifuncs 
)
static

◆ symbol_name()

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

Definition at line 1309 of file link_elf_obj.c.

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

Referenced by relocate_file1().

Here is the caller graph for this function:

◆ SYSCTL_BOOL()

SYSCTL_BOOL ( _debug  ,
OID_AUTO  ,
link_elf_obj_leak_locals  ,
CTLFLAG_RWTUN  ,
link_elf_obj_leak_locals,
,
"Allow local symbols to participate in global module symbol resolution"   
)

◆ SYSINIT()

SYSINIT ( link_elf_obj  ,
SI_SUB_KLD  ,
SI_ORDER_SECOND  ,
link_elf_init  ,
NULL   
)

Variable Documentation

◆ link_elf_class

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

Definition at line 178 of file link_elf_obj.c.

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

◆ link_elf_methods

kobj_method_t link_elf_methods[]
static
Initial value:
= {
KOBJMETHOD(linker_lookup_symbol, link_elf_lookup_symbol),
KOBJMETHOD(linker_lookup_debug_symbol, link_elf_lookup_debug_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),
KOBJMETHOD_END
}
static int link_elf_ctf_get(linker_file_t lf, linker_ctf_t *lc)
Definition: kern_ctf.c:42
int linker_ctf_get(linker_file_t file, linker_ctf_t *lc)
Definition: kern_linker.c:777
static int linker_debug_symbol_values(c_linker_sym_t sym, linker_symval_t *symval)
Definition: kern_linker.c:969
static int linker_load_file(const char *filename, linker_file_t *result)
Definition: kern_linker.c:432

Definition at line 159 of file link_elf_obj.c.

◆ link_elf_obj_leak_locals

bool link_elf_obj_leak_locals = true
static

Definition at line 187 of file link_elf_obj.c.

Referenced by link_elf_lookup_symbol(), and link_elf_symbol_values().