Whitespace and other aspects of style(9). No functional changes.
MFC after: 3 days
This commit is contained in:
parent
13e25cb7a5
commit
2f22b3ffe6
Notes:
svn2git
2020-12-20 02:59:44 +00:00
svn path=/head/; revision=215013
@ -80,26 +80,26 @@ typedef struct elf_file {
|
||||
#ifdef SPARSE_MAPPING
|
||||
vm_object_t object; /* VM object to hold file pages */
|
||||
#endif
|
||||
Elf_Dyn* dynamic; /* Symbol table etc. */
|
||||
Elf_Dyn *dynamic; /* Symbol table etc. */
|
||||
Elf_Hashelt nbuckets; /* DT_HASH info */
|
||||
Elf_Hashelt nchains;
|
||||
const Elf_Hashelt* buckets;
|
||||
const Elf_Hashelt* chains;
|
||||
const Elf_Hashelt *buckets;
|
||||
const Elf_Hashelt *chains;
|
||||
caddr_t hash;
|
||||
caddr_t strtab; /* DT_STRTAB */
|
||||
int strsz; /* DT_STRSZ */
|
||||
const Elf_Sym* symtab; /* DT_SYMTAB */
|
||||
Elf_Addr* got; /* DT_PLTGOT */
|
||||
const Elf_Rel* pltrel; /* DT_JMPREL */
|
||||
const Elf_Sym *symtab; /* DT_SYMTAB */
|
||||
Elf_Addr *got; /* DT_PLTGOT */
|
||||
const Elf_Rel *pltrel; /* DT_JMPREL */
|
||||
int pltrelsize; /* DT_PLTRELSZ */
|
||||
const Elf_Rela* pltrela; /* DT_JMPREL */
|
||||
const Elf_Rela *pltrela; /* DT_JMPREL */
|
||||
int pltrelasize; /* DT_PLTRELSZ */
|
||||
const Elf_Rel* rel; /* DT_REL */
|
||||
const Elf_Rel *rel; /* DT_REL */
|
||||
int relsize; /* DT_RELSZ */
|
||||
const Elf_Rela* rela; /* DT_RELA */
|
||||
const Elf_Rela *rela; /* DT_RELA */
|
||||
int relasize; /* DT_RELASZ */
|
||||
caddr_t modptr;
|
||||
const Elf_Sym* ddbsymtab; /* The symbol table we are using */
|
||||
const Elf_Sym *ddbsymtab; /* The symbol table we are using */
|
||||
long ddbsymcnt; /* Number of symbols */
|
||||
caddr_t ddbstrtab; /* String table */
|
||||
long ddbstrcnt; /* number of bytes in string table */
|
||||
@ -127,29 +127,29 @@ typedef struct elf_file {
|
||||
|
||||
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*);
|
||||
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 value,
|
||||
c_linker_sym_t* sym, long* diffp);
|
||||
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 *);
|
||||
int (*)(const char *, void *), void *);
|
||||
static int link_elf_each_function_nameval(linker_file_t,
|
||||
linker_function_nameval_callback_t,
|
||||
void *);
|
||||
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 lf, Elf_Size symidx, int deps);
|
||||
static Elf_Addr elf_lookup(linker_file_t, Elf_Size, int);
|
||||
|
||||
static kobj_method_t link_elf_methods[] = {
|
||||
KOBJMETHOD(linker_lookup_symbol, link_elf_lookup_symbol),
|
||||
@ -177,20 +177,21 @@ static struct linker_class link_elf_class = {
|
||||
link_elf_methods, sizeof(struct elf_file)
|
||||
};
|
||||
|
||||
static int parse_dynamic(elf_file_t ef);
|
||||
static int relocate_file(elf_file_t ef);
|
||||
static int link_elf_preload_parse_symbols(elf_file_t ef);
|
||||
static int parse_dynamic(elf_file_t);
|
||||
static int relocate_file(elf_file_t);
|
||||
static int link_elf_preload_parse_symbols(elf_file_t);
|
||||
|
||||
#ifdef GDB
|
||||
static void r_debug_state(struct r_debug *dummy_one,
|
||||
struct link_map *dummy_two);
|
||||
static void r_debug_state(struct r_debug *, struct link_map *);
|
||||
|
||||
/*
|
||||
* A list of loaded modules for GDB to use for loading symbols.
|
||||
*/
|
||||
struct r_debug r_debug;
|
||||
|
||||
#define GDB_STATE(s) r_debug.r_state = s; r_debug_state(NULL, NULL);
|
||||
#define GDB_STATE(s) do { \
|
||||
r_debug.r_state = s; r_debug_state(NULL, NULL); \
|
||||
} while (0)
|
||||
|
||||
/*
|
||||
* Function for the debugger to set a breakpoint on to gain control.
|
||||
@ -214,7 +215,9 @@ link_elf_add_gdb(struct link_map *l)
|
||||
r_debug.r_map = l;
|
||||
} else {
|
||||
/* Append to list. */
|
||||
for (prev = r_debug.r_map; prev->l_next != NULL; prev = prev->l_next)
|
||||
for (prev = r_debug.r_map;
|
||||
prev->l_next != NULL;
|
||||
prev = prev->l_next)
|
||||
;
|
||||
l->l_prev = prev;
|
||||
prev->l_next = l;
|
||||
@ -269,7 +272,7 @@ link_elf_link_common_finish(linker_file_t lf)
|
||||
|
||||
/* Notify MD code that a module is being loaded. */
|
||||
error = elf_cpu_load_file(lf);
|
||||
if (error)
|
||||
if (error != 0)
|
||||
return (error);
|
||||
|
||||
#ifdef GDB
|
||||
@ -296,18 +299,19 @@ link_elf_init(void* arg)
|
||||
|
||||
linker_add_class(&link_elf_class);
|
||||
|
||||
dp = (Elf_Dyn*) &_DYNAMIC;
|
||||
dp = (Elf_Dyn *)&_DYNAMIC;
|
||||
modname = NULL;
|
||||
modptr = preload_search_by_type("elf" __XSTRING(__ELF_WORD_SIZE) " kernel");
|
||||
if (modptr == NULL)
|
||||
modptr = preload_search_by_type("elf kernel");
|
||||
if (modptr)
|
||||
if (modptr != NULL)
|
||||
modname = (char *)preload_search_info(modptr, MODINFO_NAME);
|
||||
if (modname == NULL)
|
||||
modname = "kernel";
|
||||
linker_kernel_file = linker_make_file(modname, &link_elf_class);
|
||||
if (linker_kernel_file == NULL)
|
||||
panic("link_elf_init: Can't create linker structures for kernel");
|
||||
panic("%s: Can't create linker structures for kernel",
|
||||
__func__);
|
||||
|
||||
ef = (elf_file_t) linker_kernel_file;
|
||||
ef->preloaded = 1;
|
||||
@ -317,18 +321,18 @@ link_elf_init(void* arg)
|
||||
#endif
|
||||
ef->dynamic = dp;
|
||||
|
||||
if (dp)
|
||||
if (dp != NULL)
|
||||
parse_dynamic(ef);
|
||||
linker_kernel_file->address = (caddr_t) KERNBASE;
|
||||
linker_kernel_file->size = -(intptr_t)linker_kernel_file->address;
|
||||
|
||||
if (modptr) {
|
||||
if (modptr != NULL) {
|
||||
ef->modptr = modptr;
|
||||
baseptr = preload_search_info(modptr, MODINFO_ADDR);
|
||||
if (baseptr)
|
||||
if (baseptr != NULL)
|
||||
linker_kernel_file->address = *(caddr_t *)baseptr;
|
||||
sizeptr = preload_search_info(modptr, MODINFO_SIZE);
|
||||
if (sizeptr)
|
||||
if (sizeptr != NULL)
|
||||
linker_kernel_file->size = *(size_t *)sizeptr;
|
||||
}
|
||||
(void)link_elf_preload_parse_symbols(ef);
|
||||
@ -352,18 +356,20 @@ link_elf_preload_parse_symbols(elf_file_t ef)
|
||||
caddr_t ssym, esym, base;
|
||||
caddr_t strtab;
|
||||
int strcnt;
|
||||
Elf_Sym* symtab;
|
||||
Elf_Sym *symtab;
|
||||
int symcnt;
|
||||
|
||||
if (ef->modptr == NULL)
|
||||
return 0;
|
||||
pointer = preload_search_info(ef->modptr, MODINFO_METADATA|MODINFOMD_SSYM);
|
||||
return (0);
|
||||
pointer = preload_search_info(ef->modptr,
|
||||
MODINFO_METADATA | MODINFOMD_SSYM);
|
||||
if (pointer == NULL)
|
||||
return 0;
|
||||
return (0);
|
||||
ssym = *(caddr_t *)pointer;
|
||||
pointer = preload_search_info(ef->modptr, MODINFO_METADATA|MODINFOMD_ESYM);
|
||||
pointer = preload_search_info(ef->modptr,
|
||||
MODINFO_METADATA | MODINFOMD_ESYM);
|
||||
if (pointer == NULL)
|
||||
return 0;
|
||||
return (0);
|
||||
esym = *(caddr_t *)pointer;
|
||||
|
||||
base = ssym;
|
||||
@ -375,7 +381,7 @@ link_elf_preload_parse_symbols(elf_file_t ef)
|
||||
|
||||
if (base > esym || base < ssym) {
|
||||
printf("Symbols are corrupt!\n");
|
||||
return EINVAL;
|
||||
return (EINVAL);
|
||||
}
|
||||
|
||||
strcnt = *(long *)base;
|
||||
@ -385,7 +391,7 @@ link_elf_preload_parse_symbols(elf_file_t ef)
|
||||
|
||||
if (base > esym || base < ssym) {
|
||||
printf("Symbols are corrupt!\n");
|
||||
return EINVAL;
|
||||
return (EINVAL);
|
||||
}
|
||||
|
||||
ef->ddbsymtab = symtab;
|
||||
@ -393,7 +399,7 @@ link_elf_preload_parse_symbols(elf_file_t ef)
|
||||
ef->ddbstrtab = strtab;
|
||||
ef->ddbstrcnt = strcnt;
|
||||
|
||||
return 0;
|
||||
return (0);
|
||||
}
|
||||
|
||||
static int
|
||||
@ -426,7 +432,7 @@ parse_dynamic(elf_file_t ef)
|
||||
break;
|
||||
case DT_SYMENT:
|
||||
if (dp->d_un.d_val != sizeof(Elf_Sym))
|
||||
return ENOEXEC;
|
||||
return (ENOEXEC);
|
||||
break;
|
||||
case DT_PLTGOT:
|
||||
ef->got = (Elf_Addr *) (ef->address + dp->d_un.d_ptr);
|
||||
@ -439,7 +445,7 @@ parse_dynamic(elf_file_t ef)
|
||||
break;
|
||||
case DT_RELENT:
|
||||
if (dp->d_un.d_val != sizeof(Elf_Rel))
|
||||
return ENOEXEC;
|
||||
return (ENOEXEC);
|
||||
break;
|
||||
case DT_JMPREL:
|
||||
ef->pltrel = (const Elf_Rel *) (ef->address + dp->d_un.d_ptr);
|
||||
@ -455,23 +461,23 @@ parse_dynamic(elf_file_t ef)
|
||||
break;
|
||||
case DT_RELAENT:
|
||||
if (dp->d_un.d_val != sizeof(Elf_Rela))
|
||||
return ENOEXEC;
|
||||
return (ENOEXEC);
|
||||
break;
|
||||
case DT_PLTREL:
|
||||
plttype = dp->d_un.d_val;
|
||||
if (plttype != DT_REL && plttype != DT_RELA)
|
||||
return ENOEXEC;
|
||||
return (ENOEXEC);
|
||||
break;
|
||||
#ifdef GDB
|
||||
case DT_DEBUG:
|
||||
dp->d_un.d_ptr = (Elf_Addr) &r_debug;
|
||||
dp->d_un.d_ptr = (Elf_Addr)&r_debug;
|
||||
break;
|
||||
#endif
|
||||
}
|
||||
}
|
||||
|
||||
if (plttype == DT_RELA) {
|
||||
ef->pltrela = (const Elf_Rela *) ef->pltrel;
|
||||
ef->pltrela = (const Elf_Rela *)ef->pltrel;
|
||||
ef->pltrel = NULL;
|
||||
ef->pltrelasize = ef->pltrelsize;
|
||||
ef->pltrelsize = 0;
|
||||
@ -482,7 +488,7 @@ parse_dynamic(elf_file_t ef)
|
||||
ef->ddbstrtab = ef->strtab;
|
||||
ef->ddbstrcnt = ef->strsz;
|
||||
|
||||
return 0;
|
||||
return (0);
|
||||
}
|
||||
|
||||
static int
|
||||
@ -496,16 +502,16 @@ parse_dpcpu(elf_file_t ef)
|
||||
error = link_elf_lookup_set(&ef->lf, "pcpu", (void ***)&ef->pcpu_start,
|
||||
(void ***)&ef->pcpu_stop, &count);
|
||||
/* Error just means there is no pcpu set to relocate. */
|
||||
if (error)
|
||||
if (error != 0)
|
||||
return (0);
|
||||
count *= sizeof(void *);
|
||||
/*
|
||||
* Allocate space in the primary pcpu area. Copy in our initialization
|
||||
* from the data section and then initialize all per-cpu storage from
|
||||
* that.
|
||||
* Allocate space in the primary pcpu area. Copy in our
|
||||
* initialization from the data section and then initialize
|
||||
* all per-cpu storage from that.
|
||||
*/
|
||||
ef->pcpu_base = (Elf_Addr)(uintptr_t)dpcpu_alloc(count);
|
||||
if (ef->pcpu_base == (Elf_Addr)NULL)
|
||||
if (ef->pcpu_base == 0)
|
||||
return (ENOSPC);
|
||||
memcpy((void *)ef->pcpu_base, (void *)ef->pcpu_start, count);
|
||||
dpcpu_copy((void *)ef->pcpu_base, count);
|
||||
@ -525,16 +531,16 @@ parse_vnet(elf_file_t ef)
|
||||
error = link_elf_lookup_set(&ef->lf, "vnet", (void ***)&ef->vnet_start,
|
||||
(void ***)&ef->vnet_stop, &count);
|
||||
/* Error just means there is no vnet data set to relocate. */
|
||||
if (error)
|
||||
if (error != 0)
|
||||
return (0);
|
||||
count *= sizeof(void *);
|
||||
/*
|
||||
* Allocate space in the primary vnet area. Copy in our initialization
|
||||
* from the data section and then initialize all per-vnet storage from
|
||||
* that.
|
||||
* Allocate space in the primary vnet area. Copy in our
|
||||
* initialization from the data section and then initialize
|
||||
* all per-vnet storage from that.
|
||||
*/
|
||||
ef->vnet_base = (Elf_Addr)(uintptr_t)vnet_data_alloc(count);
|
||||
if (ef->vnet_base == (Elf_Addr)NULL)
|
||||
if (ef->vnet_base == 0)
|
||||
return (ENOSPC);
|
||||
memcpy((void *)ef->vnet_base, (void *)ef->vnet_start, count);
|
||||
vnet_data_copy((void *)ef->vnet_base, count);
|
||||
@ -557,12 +563,13 @@ link_elf_link_preload(linker_class_t cls,
|
||||
/* Look to see if we have the file preloaded */
|
||||
modptr = preload_search_by_name(filename);
|
||||
if (modptr == NULL)
|
||||
return ENOENT;
|
||||
return (ENOENT);
|
||||
|
||||
type = (char *)preload_search_info(modptr, MODINFO_TYPE);
|
||||
baseptr = preload_search_info(modptr, MODINFO_ADDR);
|
||||
sizeptr = preload_search_info(modptr, MODINFO_SIZE);
|
||||
dynptr = preload_search_info(modptr, MODINFO_METADATA|MODINFOMD_DYNAMIC);
|
||||
dynptr = preload_search_info(modptr,
|
||||
MODINFO_METADATA | MODINFOMD_DYNAMIC);
|
||||
if (type == NULL ||
|
||||
(strcmp(type, "elf" __XSTRING(__ELF_WORD_SIZE) " module") != 0 &&
|
||||
strcmp(type, "elf module") != 0))
|
||||
@ -571,9 +578,8 @@ link_elf_link_preload(linker_class_t cls,
|
||||
return (EINVAL);
|
||||
|
||||
lf = linker_make_file(filename, &link_elf_class);
|
||||
if (lf == NULL) {
|
||||
return ENOMEM;
|
||||
}
|
||||
if (lf == NULL)
|
||||
return (ENOMEM);
|
||||
|
||||
ef = (elf_file_t) lf;
|
||||
ef->preloaded = 1;
|
||||
@ -594,9 +600,9 @@ link_elf_link_preload(linker_class_t cls,
|
||||
if (error == 0)
|
||||
error = parse_vnet(ef);
|
||||
#endif
|
||||
if (error) {
|
||||
if (error != 0) {
|
||||
linker_file_unload(lf, LINKER_UNLOAD_FORCE);
|
||||
return error;
|
||||
return (error);
|
||||
}
|
||||
link_elf_reloc_local(lf);
|
||||
*result = lf;
|
||||
@ -616,13 +622,13 @@ link_elf_link_preload_finish(linker_file_t lf)
|
||||
continue;
|
||||
modname = ef->strtab + dp->d_un.d_val;
|
||||
error = linker_load_module(modname, lf);
|
||||
if (error)
|
||||
if (error != 0)
|
||||
goto out;
|
||||
}
|
||||
#endif
|
||||
error = relocate_file(ef);
|
||||
if (error)
|
||||
return error;
|
||||
if (error != 0)
|
||||
return (error);
|
||||
(void)link_elf_preload_parse_symbols(ef);
|
||||
|
||||
return (link_elf_link_common_finish(lf));
|
||||
@ -665,8 +671,8 @@ link_elf_load_file(linker_class_t cls, const char* filename,
|
||||
NDINIT(&nd, LOOKUP, FOLLOW | MPSAFE, UIO_SYSSPACE, filename, td);
|
||||
flags = FREAD;
|
||||
error = vn_open(&nd, &flags, 0, NULL);
|
||||
if (error)
|
||||
return error;
|
||||
if (error != 0)
|
||||
return (error);
|
||||
vfslocked = NDHASGIANT(&nd);
|
||||
NDFREE(&nd, NDF_ONLY_PNBUF);
|
||||
if (nd.ni_vp->v_type != VREG) {
|
||||
@ -676,7 +682,7 @@ link_elf_load_file(linker_class_t cls, const char* filename,
|
||||
}
|
||||
#ifdef MAC
|
||||
error = mac_kld_check_load(curthread->td_ucred, nd.ni_vp);
|
||||
if (error) {
|
||||
if (error != 0) {
|
||||
firstpage = NULL;
|
||||
goto out;
|
||||
}
|
||||
@ -695,7 +701,7 @@ link_elf_load_file(linker_class_t cls, const char* filename,
|
||||
UIO_SYSSPACE, IO_NODELOCKED, td->td_ucred, NOCRED,
|
||||
&resid, td);
|
||||
nbytes = PAGE_SIZE - resid;
|
||||
if (error)
|
||||
if (error != 0)
|
||||
goto out;
|
||||
|
||||
if (!IS_ELF(*hdr)) {
|
||||
@ -703,14 +709,14 @@ link_elf_load_file(linker_class_t cls, const char* filename,
|
||||
goto out;
|
||||
}
|
||||
|
||||
if (hdr->e_ident[EI_CLASS] != ELF_TARG_CLASS
|
||||
|| hdr->e_ident[EI_DATA] != ELF_TARG_DATA) {
|
||||
if (hdr->e_ident[EI_CLASS] != ELF_TARG_CLASS ||
|
||||
hdr->e_ident[EI_DATA] != ELF_TARG_DATA) {
|
||||
link_elf_error(filename, "Unsupported file layout");
|
||||
error = ENOEXEC;
|
||||
goto out;
|
||||
}
|
||||
if (hdr->e_ident[EI_VERSION] != EV_CURRENT
|
||||
|| hdr->e_version != EV_CURRENT) {
|
||||
if (hdr->e_ident[EI_VERSION] != EV_CURRENT ||
|
||||
hdr->e_version != EV_CURRENT) {
|
||||
link_elf_error(filename, "Unsupported file version");
|
||||
error = ENOEXEC;
|
||||
goto out;
|
||||
@ -726,9 +732,10 @@ link_elf_load_file(linker_class_t cls, const char* filename,
|
||||
}
|
||||
|
||||
/*
|
||||
* We rely on the program header being in the first page. This is
|
||||
* not strictly required by the ABI specification, but it seems to
|
||||
* always true in practice. And, it simplifies things considerably.
|
||||
* We rely on the program header being in the first page.
|
||||
* This is not strictly required by the ABI specification, but
|
||||
* it seems to always true in practice. And, it simplifies
|
||||
* things considerably.
|
||||
*/
|
||||
if (!((hdr->e_phentsize == sizeof(Elf_Phdr)) &&
|
||||
(hdr->e_phoff + hdr->e_phnum*sizeof(Elf_Phdr) <= PAGE_SIZE) &&
|
||||
@ -748,7 +755,6 @@ link_elf_load_file(linker_class_t cls, const char* filename,
|
||||
phphdr = NULL;
|
||||
while (phdr < phlimit) {
|
||||
switch (phdr->p_type) {
|
||||
|
||||
case PT_LOAD:
|
||||
if (nsegs == MAXSEGS) {
|
||||
link_elf_error(filename, "Too many sections");
|
||||
@ -789,8 +795,9 @@ link_elf_load_file(linker_class_t cls, const char* filename,
|
||||
}
|
||||
|
||||
/*
|
||||
* Allocate the entire address space of the object, to stake out our
|
||||
* contiguous region, and to establish the base address for relocation.
|
||||
* Allocate the entire address space of the object, to stake
|
||||
* out our contiguous region, and to establish the base
|
||||
* address for relocation.
|
||||
*/
|
||||
base_offset = trunc_page(segs[0]->p_offset);
|
||||
base_vaddr = trunc_page(segs[0]->p_vaddr);
|
||||
@ -799,7 +806,7 @@ link_elf_load_file(linker_class_t cls, const char* filename,
|
||||
mapsize = base_vlimit - base_vaddr;
|
||||
|
||||
lf = linker_make_file(filename, &link_elf_class);
|
||||
if (!lf) {
|
||||
if (lf == NULL) {
|
||||
error = ENOMEM;
|
||||
goto out;
|
||||
}
|
||||
@ -813,17 +820,16 @@ link_elf_load_file(linker_class_t cls, const char* filename,
|
||||
}
|
||||
ef->address = (caddr_t) vm_map_min(kernel_map);
|
||||
error = vm_map_find(kernel_map, ef->object, 0,
|
||||
(vm_offset_t *) &ef->address,
|
||||
mapsize, 1,
|
||||
(vm_offset_t *) &ef->address, mapsize, 1,
|
||||
VM_PROT_ALL, VM_PROT_ALL, 0);
|
||||
if (error) {
|
||||
if (error != 0) {
|
||||
vm_object_deallocate(ef->object);
|
||||
ef->object = 0;
|
||||
goto out;
|
||||
}
|
||||
#else
|
||||
ef->address = malloc(mapsize, M_LINKER, M_WAITOK);
|
||||
if (!ef->address) {
|
||||
if (ef->address == NULL) {
|
||||
error = ENOMEM;
|
||||
goto out;
|
||||
}
|
||||
@ -839,9 +845,8 @@ link_elf_load_file(linker_class_t cls, const char* filename,
|
||||
segbase, segs[i]->p_filesz, segs[i]->p_offset,
|
||||
UIO_SYSSPACE, IO_NODELOCKED, td->td_ucred, NOCRED,
|
||||
&resid, td);
|
||||
if (error) {
|
||||
if (error != 0)
|
||||
goto out;
|
||||
}
|
||||
bzero(segbase + segs[i]->p_filesz,
|
||||
segs[i]->p_memsz - segs[i]->p_filesz);
|
||||
|
||||
@ -874,14 +879,14 @@ link_elf_load_file(linker_class_t cls, const char* filename,
|
||||
lf->size = mapsize;
|
||||
|
||||
error = parse_dynamic(ef);
|
||||
if (error)
|
||||
if (error != 0)
|
||||
goto out;
|
||||
error = parse_dpcpu(ef);
|
||||
if (error)
|
||||
if (error != 0)
|
||||
goto out;
|
||||
#ifdef VIMAGE
|
||||
error = parse_vnet(ef);
|
||||
if (error)
|
||||
if (error != 0)
|
||||
goto out;
|
||||
#endif
|
||||
link_elf_reloc_local(lf);
|
||||
@ -889,7 +894,7 @@ link_elf_load_file(linker_class_t cls, const char* filename,
|
||||
VOP_UNLOCK(nd.ni_vp, 0);
|
||||
error = linker_load_dependencies(lf);
|
||||
vn_lock(nd.ni_vp, LK_EXCLUSIVE | LK_RETRY);
|
||||
if (error)
|
||||
if (error != 0)
|
||||
goto out;
|
||||
#if 0 /* this will be more trouble than it's worth for now */
|
||||
for (dp = ef->dynamic; dp->d_tag != DT_NULL; dp++) {
|
||||
@ -897,15 +902,18 @@ link_elf_load_file(linker_class_t cls, const char* filename,
|
||||
continue;
|
||||
modname = ef->strtab + dp->d_un.d_val;
|
||||
error = linker_load_module(modname, lf);
|
||||
if (error)
|
||||
if (error != 0)
|
||||
goto out;
|
||||
}
|
||||
#endif
|
||||
error = relocate_file(ef);
|
||||
if (error)
|
||||
if (error != 0)
|
||||
goto out;
|
||||
|
||||
/* Try and load the symbol table if it's present. (you can strip it!) */
|
||||
/*
|
||||
* Try and load the symbol table if it's present. (you can
|
||||
* strip it!)
|
||||
*/
|
||||
nbytes = hdr->e_shnum * hdr->e_shentsize;
|
||||
if (nbytes == 0 || hdr->e_shoff == 0)
|
||||
goto nosyms;
|
||||
@ -918,7 +926,7 @@ link_elf_load_file(linker_class_t cls, const char* filename,
|
||||
(caddr_t)shdr, nbytes, hdr->e_shoff,
|
||||
UIO_SYSSPACE, IO_NODELOCKED, td->td_ucred, NOCRED,
|
||||
&resid, td);
|
||||
if (error)
|
||||
if (error != 0)
|
||||
goto out;
|
||||
symtabindex = -1;
|
||||
symstrindex = -1;
|
||||
@ -944,13 +952,13 @@ link_elf_load_file(linker_class_t cls, const char* filename,
|
||||
ef->symbase, symcnt, shdr[symtabindex].sh_offset,
|
||||
UIO_SYSSPACE, IO_NODELOCKED, td->td_ucred, NOCRED,
|
||||
&resid, td);
|
||||
if (error)
|
||||
if (error != 0)
|
||||
goto out;
|
||||
error = vn_rdwr(UIO_READ, nd.ni_vp,
|
||||
ef->strbase, strcnt, shdr[symstrindex].sh_offset,
|
||||
UIO_SYSSPACE, IO_NODELOCKED, td->td_ucred, NOCRED,
|
||||
&resid, td);
|
||||
if (error)
|
||||
if (error != 0)
|
||||
goto out;
|
||||
|
||||
ef->ddbsymcnt = symcnt / sizeof(Elf_Sym);
|
||||
@ -959,25 +967,24 @@ link_elf_load_file(linker_class_t cls, const char* filename,
|
||||
ef->ddbstrtab = ef->strbase;
|
||||
|
||||
error = link_elf_link_common_finish(lf);
|
||||
if (error)
|
||||
if (error != 0)
|
||||
goto out;
|
||||
|
||||
nosyms:
|
||||
|
||||
*result = lf;
|
||||
|
||||
out:
|
||||
VOP_UNLOCK(nd.ni_vp, 0);
|
||||
vn_close(nd.ni_vp, FREAD, td->td_ucred, td);
|
||||
VFS_UNLOCK_GIANT(vfslocked);
|
||||
if (error && lf)
|
||||
if (error != 0 && lf != NULL)
|
||||
linker_file_unload(lf, LINKER_UNLOAD_FORCE);
|
||||
if (shdr)
|
||||
if (shdr != NULL)
|
||||
free(shdr, M_LINKER);
|
||||
if (firstpage)
|
||||
if (firstpage != NULL)
|
||||
free(firstpage, M_LINKER);
|
||||
|
||||
return error;
|
||||
return (error);
|
||||
}
|
||||
|
||||
Elf_Addr
|
||||
@ -1001,16 +1008,18 @@ link_elf_unload_file(linker_file_t file)
|
||||
{
|
||||
elf_file_t ef = (elf_file_t) file;
|
||||
|
||||
if (ef->pcpu_base) {
|
||||
dpcpu_free((void *)ef->pcpu_base, ef->pcpu_stop - ef->pcpu_start);
|
||||
if (ef->pcpu_base != 0) {
|
||||
dpcpu_free((void *)ef->pcpu_base,
|
||||
ef->pcpu_stop - ef->pcpu_start);
|
||||
}
|
||||
#ifdef VIMAGE
|
||||
if (ef->vnet_base) {
|
||||
vnet_data_free((void *)ef->vnet_base, ef->vnet_stop - ef->vnet_start);
|
||||
if (ef->vnet_base != 0) {
|
||||
vnet_data_free((void *)ef->vnet_base,
|
||||
ef->vnet_stop - ef->vnet_start);
|
||||
}
|
||||
#endif
|
||||
#ifdef GDB
|
||||
if (ef->gdb.l_ld) {
|
||||
if (ef->gdb.l_ld != NULL) {
|
||||
GDB_STATE(RT_DELETE);
|
||||
free((void *)(uintptr_t)ef->gdb.l_name, M_LINKER);
|
||||
link_elf_delete_gdb(&ef->gdb);
|
||||
@ -1027,31 +1036,31 @@ link_elf_unload_file(linker_file_t file)
|
||||
}
|
||||
|
||||
#ifdef SPARSE_MAPPING
|
||||
if (ef->object) {
|
||||
if (ef->object != NULL) {
|
||||
vm_map_remove(kernel_map, (vm_offset_t) ef->address,
|
||||
(vm_offset_t) ef->address
|
||||
+ (ef->object->size << PAGE_SHIFT));
|
||||
}
|
||||
#else
|
||||
if (ef->address)
|
||||
if (ef->address != NULL)
|
||||
free(ef->address, M_LINKER);
|
||||
#endif
|
||||
if (ef->symbase)
|
||||
if (ef->symbase != NULL)
|
||||
free(ef->symbase, M_LINKER);
|
||||
if (ef->strbase)
|
||||
if (ef->strbase != NULL)
|
||||
free(ef->strbase, M_LINKER);
|
||||
if (ef->ctftab)
|
||||
if (ef->ctftab != NULL)
|
||||
free(ef->ctftab, M_LINKER);
|
||||
if (ef->ctfoff)
|
||||
if (ef->ctfoff != NULL)
|
||||
free(ef->ctfoff, M_LINKER);
|
||||
if (ef->typoff)
|
||||
if (ef->typoff != NULL)
|
||||
free(ef->typoff, M_LINKER);
|
||||
}
|
||||
|
||||
static void
|
||||
link_elf_unload_preload(linker_file_t file)
|
||||
{
|
||||
if (file->filename)
|
||||
if (file->filename != NULL)
|
||||
preload_delete_name(file->filename);
|
||||
}
|
||||
|
||||
@ -1062,9 +1071,9 @@ symbol_name(elf_file_t ef, Elf_Size r_info)
|
||||
|
||||
if (ELF_R_SYM(r_info)) {
|
||||
ref = ef->symtab + ELF_R_SYM(r_info);
|
||||
return ef->strtab + ref->st_name;
|
||||
} else
|
||||
return NULL;
|
||||
return (ef->strtab + ref->st_name);
|
||||
}
|
||||
return (NULL);
|
||||
}
|
||||
|
||||
static int
|
||||
@ -1078,14 +1087,15 @@ relocate_file(elf_file_t ef)
|
||||
|
||||
/* Perform relocations without addend if there are any: */
|
||||
rel = ef->rel;
|
||||
if (rel) {
|
||||
rellim = (const Elf_Rel *)((const char *)ef->rel + ef->relsize);
|
||||
if (rel != NULL) {
|
||||
rellim = (const Elf_Rel *)
|
||||
((const char *)ef->rel + ef->relsize);
|
||||
while (rel < rellim) {
|
||||
if (elf_reloc(&ef->lf, (Elf_Addr)ef->address, rel, ELF_RELOC_REL,
|
||||
elf_lookup)) {
|
||||
if (elf_reloc(&ef->lf, (Elf_Addr)ef->address, rel,
|
||||
ELF_RELOC_REL, elf_lookup)) {
|
||||
symname = symbol_name(ef, rel->r_info);
|
||||
printf("link_elf: symbol %s undefined\n", symname);
|
||||
return ENOENT;
|
||||
return (ENOENT);
|
||||
}
|
||||
rel++;
|
||||
}
|
||||
@ -1093,14 +1103,16 @@ relocate_file(elf_file_t ef)
|
||||
|
||||
/* Perform relocations with addend if there are any: */
|
||||
rela = ef->rela;
|
||||
if (rela) {
|
||||
relalim = (const Elf_Rela *)((const char *)ef->rela + ef->relasize);
|
||||
if (rela != NULL) {
|
||||
relalim = (const Elf_Rela *)
|
||||
((const char *)ef->rela + ef->relasize);
|
||||
while (rela < relalim) {
|
||||
if (elf_reloc(&ef->lf, (Elf_Addr)ef->address, rela, ELF_RELOC_RELA,
|
||||
elf_lookup)) {
|
||||
if (elf_reloc(&ef->lf, (Elf_Addr)ef->address, rela,
|
||||
ELF_RELOC_RELA, elf_lookup)) {
|
||||
symname = symbol_name(ef, rela->r_info);
|
||||
printf("link_elf: symbol %s undefined\n", symname);
|
||||
return ENOENT;
|
||||
printf("link_elf: symbol %s undefined\n",
|
||||
symname);
|
||||
return (ENOENT);
|
||||
}
|
||||
rela++;
|
||||
}
|
||||
@ -1108,14 +1120,16 @@ relocate_file(elf_file_t ef)
|
||||
|
||||
/* Perform PLT relocations without addend if there are any: */
|
||||
rel = ef->pltrel;
|
||||
if (rel) {
|
||||
rellim = (const Elf_Rel *)((const char *)ef->pltrel + ef->pltrelsize);
|
||||
if (rel != NULL) {
|
||||
rellim = (const Elf_Rel *)
|
||||
((const char *)ef->pltrel + ef->pltrelsize);
|
||||
while (rel < rellim) {
|
||||
if (elf_reloc(&ef->lf, (Elf_Addr)ef->address, rel, ELF_RELOC_REL,
|
||||
elf_lookup)) {
|
||||
if (elf_reloc(&ef->lf, (Elf_Addr)ef->address, rel,
|
||||
ELF_RELOC_REL, elf_lookup)) {
|
||||
symname = symbol_name(ef, rel->r_info);
|
||||
printf("link_elf: symbol %s undefined\n", symname);
|
||||
return ENOENT;
|
||||
printf("link_elf: symbol %s undefined\n",
|
||||
symname);
|
||||
return (ENOENT);
|
||||
}
|
||||
rel++;
|
||||
}
|
||||
@ -1123,20 +1137,22 @@ relocate_file(elf_file_t ef)
|
||||
|
||||
/* Perform relocations with addend if there are any: */
|
||||
rela = ef->pltrela;
|
||||
if (rela) {
|
||||
relalim = (const Elf_Rela *)((const char *)ef->pltrela + ef->pltrelasize);
|
||||
if (rela != NULL) {
|
||||
relalim = (const Elf_Rela *)
|
||||
((const char *)ef->pltrela + ef->pltrelasize);
|
||||
while (rela < relalim) {
|
||||
if (elf_reloc(&ef->lf, (Elf_Addr)ef->address, rela, ELF_RELOC_RELA,
|
||||
elf_lookup)) {
|
||||
if (elf_reloc(&ef->lf, (Elf_Addr)ef->address, rela,
|
||||
ELF_RELOC_RELA, elf_lookup)) {
|
||||
symname = symbol_name(ef, rela->r_info);
|
||||
printf("link_elf: symbol %s undefined\n", symname);
|
||||
return ENOENT;
|
||||
printf("link_elf: symbol %s undefined\n",
|
||||
symname);
|
||||
return (ENOENT);
|
||||
}
|
||||
rela++;
|
||||
}
|
||||
}
|
||||
|
||||
return 0;
|
||||
return (0);
|
||||
}
|
||||
|
||||
/*
|
||||
@ -1156,7 +1172,7 @@ elf_hash(const char *name)
|
||||
h ^= g >> 24;
|
||||
h &= ~g;
|
||||
}
|
||||
return h;
|
||||
return (h);
|
||||
}
|
||||
|
||||
static int
|
||||
@ -1172,7 +1188,7 @@ link_elf_lookup_symbol(linker_file_t lf, const char* name, c_linker_sym_t* sym)
|
||||
/* If we don't have a hash, bail. */
|
||||
if (ef->buckets == NULL || ef->nbuckets == 0) {
|
||||
printf("link_elf_lookup_symbol: missing symbol hash table\n");
|
||||
return ENOENT;
|
||||
return (ENOENT);
|
||||
}
|
||||
|
||||
/* First, search hashed global symbols */
|
||||
@ -1181,14 +1197,14 @@ link_elf_lookup_symbol(linker_file_t lf, const char* name, c_linker_sym_t* sym)
|
||||
|
||||
while (symnum != STN_UNDEF) {
|
||||
if (symnum >= ef->nchains) {
|
||||
printf("link_elf_lookup_symbol: corrupt symbol table\n");
|
||||
return ENOENT;
|
||||
printf("%s: corrupt symbol table\n", __func__);
|
||||
return (ENOENT);
|
||||
}
|
||||
|
||||
symp = ef->symtab + symnum;
|
||||
if (symp->st_name == 0) {
|
||||
printf("link_elf_lookup_symbol: corrupt symbol table\n");
|
||||
return ENOENT;
|
||||
printf("%s: corrupt symbol table\n", __func__);
|
||||
return (ENOENT);
|
||||
}
|
||||
|
||||
strp = ef->strtab + symp->st_name;
|
||||
@ -1198,9 +1214,9 @@ link_elf_lookup_symbol(linker_file_t lf, const char* name, c_linker_sym_t* sym)
|
||||
(symp->st_value != 0 &&
|
||||
ELF_ST_TYPE(symp->st_info) == STT_FUNC)) {
|
||||
*sym = (c_linker_sym_t) symp;
|
||||
return 0;
|
||||
} else
|
||||
return ENOENT;
|
||||
return (0);
|
||||
}
|
||||
return (ENOENT);
|
||||
}
|
||||
|
||||
symnum = ef->chains[symnum];
|
||||
@ -1208,7 +1224,7 @@ link_elf_lookup_symbol(linker_file_t lf, const char* name, c_linker_sym_t* sym)
|
||||
|
||||
/* If we have not found it, look at the full table (if loaded) */
|
||||
if (ef->symtab == ef->ddbsymtab)
|
||||
return ENOENT;
|
||||
return (ENOENT);
|
||||
|
||||
/* Exhaustive search */
|
||||
for (i = 0, symp = ef->ddbsymtab; i < ef->ddbsymcnt; i++, symp++) {
|
||||
@ -1218,17 +1234,18 @@ link_elf_lookup_symbol(linker_file_t lf, const char* name, c_linker_sym_t* sym)
|
||||
(symp->st_value != 0 &&
|
||||
ELF_ST_TYPE(symp->st_info) == STT_FUNC)) {
|
||||
*sym = (c_linker_sym_t) symp;
|
||||
return 0;
|
||||
} else
|
||||
return ENOENT;
|
||||
return (0);
|
||||
}
|
||||
return (ENOENT);
|
||||
}
|
||||
}
|
||||
|
||||
return ENOENT;
|
||||
return (ENOENT);
|
||||
}
|
||||
|
||||
static int
|
||||
link_elf_symbol_values(linker_file_t lf, c_linker_sym_t sym, linker_symval_t* symval)
|
||||
link_elf_symbol_values(linker_file_t lf, c_linker_sym_t sym,
|
||||
linker_symval_t *symval)
|
||||
{
|
||||
elf_file_t ef = (elf_file_t) lf;
|
||||
const Elf_Sym* es = (const Elf_Sym*) sym;
|
||||
@ -1237,22 +1254,22 @@ link_elf_symbol_values(linker_file_t lf, c_linker_sym_t sym, linker_symval_t* sy
|
||||
symval->name = ef->strtab + es->st_name;
|
||||
symval->value = (caddr_t) ef->address + es->st_value;
|
||||
symval->size = es->st_size;
|
||||
return 0;
|
||||
return (0);
|
||||
}
|
||||
if (ef->symtab == ef->ddbsymtab)
|
||||
return ENOENT;
|
||||
return (ENOENT);
|
||||
if (es >= ef->ddbsymtab && es < (ef->ddbsymtab + ef->ddbsymcnt)) {
|
||||
symval->name = ef->ddbstrtab + es->st_name;
|
||||
symval->value = (caddr_t) ef->address + es->st_value;
|
||||
symval->size = es->st_size;
|
||||
return 0;
|
||||
return (0);
|
||||
}
|
||||
return ENOENT;
|
||||
return (ENOENT);
|
||||
}
|
||||
|
||||
static int
|
||||
link_elf_search_symbol(linker_file_t lf, caddr_t value,
|
||||
c_linker_sym_t* sym, long* diffp)
|
||||
c_linker_sym_t *sym, long *diffp)
|
||||
{
|
||||
elf_file_t ef = (elf_file_t) lf;
|
||||
u_long off = (uintptr_t) (void *) value;
|
||||
@ -1283,7 +1300,7 @@ link_elf_search_symbol(linker_file_t lf, caddr_t value,
|
||||
*diffp = diff;
|
||||
*sym = (c_linker_sym_t) best;
|
||||
|
||||
return 0;
|
||||
return (0);
|
||||
}
|
||||
|
||||
/*
|
||||
@ -1302,12 +1319,12 @@ link_elf_lookup_set(linker_file_t lf, const char *name,
|
||||
len = strlen(name) + sizeof("__start_set_"); /* sizeof includes \0 */
|
||||
setsym = malloc(len, M_LINKER, M_WAITOK);
|
||||
if (setsym == NULL)
|
||||
return ENOMEM;
|
||||
return (ENOMEM);
|
||||
|
||||
/* get address of first entry */
|
||||
snprintf(setsym, len, "%s%s", "__start_set_", name);
|
||||
error = link_elf_lookup_symbol(lf, setsym, &sym);
|
||||
if (error)
|
||||
if (error != 0)
|
||||
goto out;
|
||||
link_elf_symbol_values(lf, sym, &symval);
|
||||
if (symval.value == 0) {
|
||||
@ -1319,7 +1336,7 @@ link_elf_lookup_set(linker_file_t lf, const char *name,
|
||||
/* get address of last entry */
|
||||
snprintf(setsym, len, "%s%s", "__stop_set_", name);
|
||||
error = link_elf_lookup_symbol(lf, setsym, &sym);
|
||||
if (error)
|
||||
if (error != 0)
|
||||
goto out;
|
||||
link_elf_symbol_values(lf, sym, &symval);
|
||||
if (symval.value == 0) {
|
||||
@ -1332,23 +1349,24 @@ link_elf_lookup_set(linker_file_t lf, const char *name,
|
||||
count = stop - start;
|
||||
|
||||
/* and copy out */
|
||||
if (startp)
|
||||
if (startp != NULL)
|
||||
*startp = start;
|
||||
if (stopp)
|
||||
if (stopp != NULL)
|
||||
*stopp = stop;
|
||||
if (countp)
|
||||
if (countp != NULL)
|
||||
*countp = count;
|
||||
|
||||
out:
|
||||
free(setsym, M_LINKER);
|
||||
return error;
|
||||
return (error);
|
||||
}
|
||||
|
||||
static int
|
||||
link_elf_each_function_name(linker_file_t file,
|
||||
int (*callback)(const char *, void *), void *opaque) {
|
||||
int (*callback)(const char *, void *), void *opaque)
|
||||
{
|
||||
elf_file_t ef = (elf_file_t)file;
|
||||
const Elf_Sym* symp;
|
||||
const Elf_Sym *symp;
|
||||
int i, error;
|
||||
|
||||
/* Exhaustive search */
|
||||
@ -1356,7 +1374,7 @@ link_elf_each_function_name(linker_file_t file,
|
||||
if (symp->st_value != 0 &&
|
||||
ELF_ST_TYPE(symp->st_info) == STT_FUNC) {
|
||||
error = callback(ef->ddbstrtab + symp->st_name, opaque);
|
||||
if (error)
|
||||
if (error != 0)
|
||||
return (error);
|
||||
}
|
||||
}
|
||||
@ -1376,11 +1394,12 @@ link_elf_each_function_nameval(linker_file_t file,
|
||||
for (i = 0, symp = ef->ddbsymtab; i < ef->ddbsymcnt; i++, symp++) {
|
||||
if (symp->st_value != 0 &&
|
||||
ELF_ST_TYPE(symp->st_info) == STT_FUNC) {
|
||||
error = link_elf_symbol_values(file, (c_linker_sym_t) symp, &symval);
|
||||
if (error)
|
||||
error = link_elf_symbol_values(file,
|
||||
(c_linker_sym_t) symp, &symval);
|
||||
if (error != 0)
|
||||
return (error);
|
||||
error = callback(file, i, &symval, opaque);
|
||||
if (error)
|
||||
if (error != 0)
|
||||
return (error);
|
||||
}
|
||||
}
|
||||
@ -1398,7 +1417,7 @@ Elf_Addr
|
||||
link_elf_get_gp(linker_file_t lf)
|
||||
{
|
||||
elf_file_t ef = (elf_file_t)lf;
|
||||
return (Elf_Addr)ef->got;
|
||||
return ((Elf_Addr)ef->got);
|
||||
}
|
||||
#endif
|
||||
|
||||
@ -1484,18 +1503,19 @@ link_elf_reloc_local(linker_file_t lf)
|
||||
if ((rel = ef->rel) != NULL) {
|
||||
rellim = (const Elf_Rel *)((const char *)ef->rel + ef->relsize);
|
||||
while (rel < rellim) {
|
||||
elf_reloc_local(lf, (Elf_Addr)ef->address, rel, ELF_RELOC_REL,
|
||||
elf_lookup);
|
||||
elf_reloc_local(lf, (Elf_Addr)ef->address, rel,
|
||||
ELF_RELOC_REL, elf_lookup);
|
||||
rel++;
|
||||
}
|
||||
}
|
||||
|
||||
/* Perform relocations with addend if there are any: */
|
||||
if ((rela = ef->rela) != NULL) {
|
||||
relalim = (const Elf_Rela *)((const char *)ef->rela + ef->relasize);
|
||||
relalim = (const Elf_Rela *)
|
||||
((const char *)ef->rela + ef->relasize);
|
||||
while (rela < relalim) {
|
||||
elf_reloc_local(lf, (Elf_Addr)ef->address, rela, ELF_RELOC_RELA,
|
||||
elf_lookup);
|
||||
elf_reloc_local(lf, (Elf_Addr)ef->address, rela,
|
||||
ELF_RELOC_RELA, elf_lookup);
|
||||
rela++;
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user