diff options
author | Theo de Raadt <deraadt@cvs.openbsd.org> | 2013-11-13 05:41:44 +0000 |
---|---|---|
committer | Theo de Raadt <deraadt@cvs.openbsd.org> | 2013-11-13 05:41:44 +0000 |
commit | 64e2ca634009a39af00fa6e5899486eb4c908d14 (patch) | |
tree | cef2d572173462c79dbd7ff746c699e2b812d746 /libexec/ld.so | |
parent | 695b6efeb842435ade3da185213bd05c967868c5 (diff) |
prototype & void * math cleanup
ok guenther
Diffstat (limited to 'libexec/ld.so')
-rw-r--r-- | libexec/ld.so/dl_prebind.c | 42 | ||||
-rw-r--r-- | libexec/ld.so/dlfcn.c | 6 | ||||
-rw-r--r-- | libexec/ld.so/ldconfig/ldconfig.c | 4 | ||||
-rw-r--r-- | libexec/ld.so/ldconfig/library.c | 13 | ||||
-rw-r--r-- | libexec/ld.so/ldconfig/prebind.c | 14 | ||||
-rw-r--r-- | libexec/ld.so/ldconfig/prebind_path.c | 3 | ||||
-rw-r--r-- | libexec/ld.so/library_subr.c | 10 | ||||
-rw-r--r-- | libexec/ld.so/resolve.c | 114 | ||||
-rw-r--r-- | libexec/ld.so/resolve.h | 3 | ||||
-rw-r--r-- | libexec/ld.so/util.c | 10 |
10 files changed, 113 insertions, 106 deletions
diff --git a/libexec/ld.so/dl_prebind.c b/libexec/ld.so/dl_prebind.c index ad9d66fda7b..d35993e4bf7 100644 --- a/libexec/ld.so/dl_prebind.c +++ b/libexec/ld.so/dl_prebind.c @@ -1,4 +1,4 @@ -/* $OpenBSD: dl_prebind.c,v 1.12 2013/06/04 00:59:00 brad Exp $ */ +/* $OpenBSD: dl_prebind.c,v 1.13 2013/11/13 05:41:41 deraadt Exp $ */ /* * Copyright (c) 2006 Dale Rahn <drahn@dalerahn.com> * @@ -43,7 +43,7 @@ void prebind_dump_fixup(struct fixup *fixup, u_int32_t numfixups); void prebind_dump_libmap(u_int32_t *libmap, u_int32_t numlibs); struct prebind_footer *_dl_prebind_data_to_footer(void *data); -void *_dl_prog_prebind_map; +char *_dl_prog_prebind_map; struct prebind_footer *prog_footer; extern char *_dl_noprebind; extern char *_dl_prebind_validate; @@ -135,8 +135,8 @@ prebind_load_fd(int fd, const char *name) MAP_FILE, fd, footer.prebind_base); DL_DEB(("prebind_load_fd for lib %s\n", name)); - nameidx = _dl_prog_prebind_map + prog_footer->nameidx_idx; - nametab = _dl_prog_prebind_map + prog_footer->nametab_idx; + nameidx = (void *)(_dl_prog_prebind_map + prog_footer->nameidx_idx); + nametab = (void *)(_dl_prog_prebind_map + prog_footer->nametab_idx); /* libraries are loaded in random order, so we just have * to look thru the list to find ourselves @@ -174,7 +174,7 @@ prebind_symcache(elf_object_t *object, int plt) struct symcachetab *symcachetab; struct prebind_footer *footer; int i = 0, cur_obj = -1, idx; - void *prebind_map; + char *prebind_map; char *c; struct fixup *fixup; elf_object_t *obj; @@ -221,17 +221,17 @@ prebind_symcache(elf_object_t *object, int plt) prebind_map = (void *)object->prebind_data; if (plt) { - symcachetab = prebind_map + footer->pltsymcache_idx; + symcachetab = (void *)(prebind_map + footer->pltsymcache_idx); symcache_cnt = footer->pltsymcache_cnt; // DL_DEB(("loading plt %d\n", symcache_cnt)); } else { - symcachetab = prebind_map + footer->symcache_idx; + symcachetab = (void *)(prebind_map + footer->symcache_idx); symcache_cnt = footer->symcache_cnt; // DL_DEB(("loading got %d\n", symcache_cnt)); } - libmap = _dl_prog_prebind_map + prog_footer->libmap_idx; - idxtolib = _dl_prog_prebind_map + libmap[cur_obj]; + libmap = (void *)(_dl_prog_prebind_map + prog_footer->libmap_idx); + idxtolib = (void *)(_dl_prog_prebind_map + libmap[cur_obj]); for (i = 0; i < symcache_cnt; i++) { struct elf_object *tobj; @@ -270,9 +270,12 @@ prebind_symcache(elf_object_t *object, int plt) } if (!plt) { - fixupidx = _dl_prog_prebind_map + prog_footer->fixup_idx; - fixup = _dl_prog_prebind_map + fixupidx[2*cur_obj]; - fixupcnt = _dl_prog_prebind_map + prog_footer->fixupcnt_idx; + fixupidx = (void *)(_dl_prog_prebind_map + + prog_footer->fixup_idx); + fixup = (void *)(_dl_prog_prebind_map + + fixupidx[2*cur_obj]); + fixupcnt = (void *)(_dl_prog_prebind_map + + prog_footer->fixupcnt_idx); for (i = 0; i < fixupcnt[2*cur_obj]; i++) { struct fixup *f; @@ -303,9 +306,12 @@ prebind_symcache(elf_object_t *object, int plt) } } else { - fixupidx = _dl_prog_prebind_map + prog_footer->fixup_idx; - fixup = _dl_prog_prebind_map + fixupidx[2*cur_obj+1]; - fixupcnt = _dl_prog_prebind_map + prog_footer->fixupcnt_idx; + fixupidx = (void *)(_dl_prog_prebind_map + + prog_footer->fixup_idx); + fixup = (void *)(_dl_prog_prebind_map + + fixupidx[2*cur_obj+1]); + fixupcnt = (void *)(_dl_prog_prebind_map + + prog_footer->fixupcnt_idx); #if 0 DL_DEB(("prebind loading symbols fixup plt %s\n", @@ -387,8 +393,10 @@ _dl_prebind_pre_resolve() int idx; if (_dl_prog_prebind_map != NULL) { - nameidx = _dl_prog_prebind_map + prog_footer->nameidx_idx; - nametab = _dl_prog_prebind_map + prog_footer->nametab_idx; + nameidx = (void *)(_dl_prog_prebind_map + + prog_footer->nameidx_idx); + nametab = (void *)(_dl_prog_prebind_map + + prog_footer->nametab_idx); for (idx = 1, object = _dl_objects->next; object != NULL; object = object->next, idx++) { if (object->prebind_data == NULL) { diff --git a/libexec/ld.so/dlfcn.c b/libexec/ld.so/dlfcn.c index 8ce0c12345f..16d8e8afb89 100644 --- a/libexec/ld.so/dlfcn.c +++ b/libexec/ld.so/dlfcn.c @@ -1,4 +1,4 @@ -/* $OpenBSD: dlfcn.c,v 1.88 2013/03/24 01:37:23 deraadt Exp $ */ +/* $OpenBSD: dlfcn.c,v 1.89 2013/11/13 05:41:41 deraadt Exp $ */ /* * Copyright (c) 1998 Per Fogelstrom, Opsycon AB @@ -149,7 +149,7 @@ dlsym(void *handle, const char *name) elf_object_t *object; elf_object_t *dynobj; const elf_object_t *pobj; - void *retval; + char *retval; const Elf_Sym *sym = NULL; int flags; @@ -366,7 +366,7 @@ dlerror(void) return (errmsg); } -void +static void _dl_tracefmt(int fd, elf_object_t *object, const char *fmt1, const char *fmt2, const char *objtypename) { diff --git a/libexec/ld.so/ldconfig/ldconfig.c b/libexec/ld.so/ldconfig/ldconfig.c index 01b3fd00383..96c7601f098 100644 --- a/libexec/ld.so/ldconfig/ldconfig.c +++ b/libexec/ld.so/ldconfig/ldconfig.c @@ -1,4 +1,4 @@ -/* $OpenBSD: ldconfig.c,v 1.30 2013/10/18 14:44:39 deraadt Exp $ */ +/* $OpenBSD: ldconfig.c,v 1.31 2013/11/13 05:41:42 deraadt Exp $ */ /* * Copyright (c) 1993,1995 Paul Kranenburg @@ -89,7 +89,7 @@ static int buildhints(void); static int readhints(void); static void listhints(void); -void +static void usage(void) { fprintf(stderr, diff --git a/libexec/ld.so/ldconfig/library.c b/libexec/ld.so/ldconfig/library.c index f5de94257c3..96db2a84f6e 100644 --- a/libexec/ld.so/ldconfig/library.c +++ b/libexec/ld.so/ldconfig/library.c @@ -1,4 +1,4 @@ -/* $OpenBSD: library.c,v 1.4 2013/03/20 21:49:59 kurt Exp $ */ +/* $OpenBSD: library.c,v 1.5 2013/11/13 05:41:43 deraadt Exp $ */ /* * Copyright (c) 2006 Dale Rahn <drahn@dalerahn.com> * @@ -34,13 +34,14 @@ #include "prebind.h" #include "prebind_struct.h" -char * _dl_default_path[2] = { "/usr/lib", NULL }; +char *_dl_default_path[2] = { "/usr/lib", NULL }; -elf_object_t * elf_load_shlib_hint(struct sod *sod, struct sod *req_sod, - int ignore_hints, char **libpath); -char * elf_find_shlib(struct sod *sodp, char **searchpath, int nohints); +elf_object_t *elf_load_shlib_hint(struct sod *sod, struct sod *req_sod, + int ignore_hints, char **libpath); +char *elf_find_shlib(struct sod *sodp, char **searchpath, int nohints); elf_object_t * elf_tryload_shlib(const char *libname); -int elf_match_file(struct sod *sodp, char *name, int namelen); +int elf_match_file(struct sod *sodp, char *name, int namelen); +int load_lib(const char *, struct elf_object *); int load_lib(const char *name, struct elf_object *parent) diff --git a/libexec/ld.so/ldconfig/prebind.c b/libexec/ld.so/ldconfig/prebind.c index 7b6c224d932..75d48ee53cf 100644 --- a/libexec/ld.so/ldconfig/prebind.c +++ b/libexec/ld.so/ldconfig/prebind.c @@ -1,4 +1,4 @@ -/* $OpenBSD: prebind.c,v 1.22 2013/07/15 00:01:58 jca Exp $ */ +/* $OpenBSD: prebind.c,v 1.23 2013/11/13 05:41:43 deraadt Exp $ */ /* * Copyright (c) 2006 Dale Rahn <drahn@dalerahn.com> * @@ -129,6 +129,8 @@ int objarray_sz; void copy_oldsymcache(int objidx, void *prebind_data); void elf_load_existing_prebind(struct elf_object *object, int fd); +void insert_sym_objcache(struct elf_object *, int, + const struct elf_object *, const Elf_Sym *, int); struct elf_object * elf_load_object(void *pexe, const char *name); void elf_free_object(struct elf_object *object); @@ -137,7 +139,7 @@ int load_obj_needed(struct elf_object *object); int load_lib(const char *name, struct elf_object *parent); elf_object_t * elf_load_shlib_hint(struct sod *sod, struct sod *req_sod, int use_hints, const char *libpath); -char * elf_find_shlib(struct sod *sodp, const char *searchpath, +char *elf_find_shlib(struct sod *sodp, const char *searchpath, int nohints); elf_object_t * elf_tryload_shlib(const char *libname); int elf_match_file(struct sod *sodp, char *name, int namelen); @@ -2242,8 +2244,8 @@ copy_oldsymcache(int objidx, void *prebind_map) c += offset; footer = (void *)c; - nameidx = prebind_map + footer->nameidx_idx; - nametab = prebind_map + footer->nametab_idx; + nameidx = (void *)((char *)prebind_map + footer->nameidx_idx); + nametab = (void *)((char *)prebind_map + footer->nametab_idx); idxtolib = xcalloc(footer->numlibs, sizeof(int)); found = 0; @@ -2271,7 +2273,7 @@ copy_oldsymcache(int objidx, void *prebind_map) /* build idxtolibs */ tcache = objarray[objidx].symcache; - symcache = prebind_map + footer->symcache_idx; + symcache = (void *)((char *)prebind_map + footer->symcache_idx); for (i = 0; i < footer->symcache_cnt; i++) { tobj = objarray[idxtolib[symcache[i].obj_idx]].obj; @@ -2282,7 +2284,7 @@ copy_oldsymcache(int objidx, void *prebind_map) } tcache = objarray[objidx].pltsymcache; - symcache = prebind_map + footer->pltsymcache_idx; + symcache = (void *)((char *)prebind_map + footer->pltsymcache_idx); for (i = 0; i < footer->pltsymcache_cnt; i++) { tobj = objarray[idxtolib[symcache[i].obj_idx]].obj; diff --git a/libexec/ld.so/ldconfig/prebind_path.c b/libexec/ld.so/ldconfig/prebind_path.c index eab54011535..c2f7100c96e 100644 --- a/libexec/ld.so/ldconfig/prebind_path.c +++ b/libexec/ld.so/ldconfig/prebind_path.c @@ -1,4 +1,4 @@ -/* $OpenBSD: prebind_path.c,v 1.1 2013/03/20 21:49:59 kurt Exp $ */ +/* $OpenBSD: prebind_path.c,v 1.2 2013/11/13 05:41:43 deraadt Exp $ */ /* * Copyright (c) 2013 Kurt Miller <kurt@intricatesoftware.com> @@ -19,6 +19,7 @@ #include <sys/types.h> #include <stdlib.h> #include <string.h> +#include "util.h" void * _dl_malloc(size_t need) diff --git a/libexec/ld.so/library_subr.c b/libexec/ld.so/library_subr.c index da6dbe80fa7..e2cccc414b5 100644 --- a/libexec/ld.so/library_subr.c +++ b/libexec/ld.so/library_subr.c @@ -1,4 +1,4 @@ -/* $OpenBSD: library_subr.c,v 1.37 2013/03/20 21:49:59 kurt Exp $ */ +/* $OpenBSD: library_subr.c,v 1.38 2013/11/13 05:41:41 deraadt Exp $ */ /* * Copyright (c) 2002 Dale Rahn @@ -102,7 +102,7 @@ _dl_match_file(struct sod *sodp, const char *name, int namelen) * sodp is updated with the minor if this matches. */ -int +static int _dl_cmp_sod(struct sod *sodp, const struct sod *lsod) { int match; @@ -220,7 +220,7 @@ nohints: return NULL; } -elf_object_t * +static elf_object_t * _dl_lookup_object(const char *req_name, struct sod *req_sod) { elf_object_t *object = _dl_objects; @@ -243,7 +243,7 @@ _dl_lookup_object(const char *req_name, struct sod *req_sod) return(NULL); } -elf_object_t * +static elf_object_t * _dl_find_loaded_shlib(const char *req_name, struct sod req_sod, int flags) { elf_object_t *object; @@ -432,7 +432,7 @@ _dl_link_dlopen(elf_object_t *dep) DL_DEB(("linking %s as dlopen()ed\n", dep->load_name)); } -void +static void _dl_child_refcnt_decrement(elf_object_t *object) { struct dep_node *n; diff --git a/libexec/ld.so/resolve.c b/libexec/ld.so/resolve.c index 77d11653cb7..ab7779ff7a2 100644 --- a/libexec/ld.so/resolve.c +++ b/libexec/ld.so/resolve.c @@ -1,4 +1,4 @@ -/* $OpenBSD: resolve.c,v 1.63 2013/06/01 09:57:55 miod Exp $ */ +/* $OpenBSD: resolve.c,v 1.64 2013/11/13 05:41:42 deraadt Exp $ */ /* * Copyright (c) 1998 Per Fogelstrom, Opsycon AB @@ -357,7 +357,7 @@ _dl_finalize_object(const char *objname, Elf_Dyn *dynp, Elf_Phdr *phdrp, return (object); } -void +static void _dl_tailq_free(struct dep_node *n) { struct dep_node *next; @@ -371,7 +371,6 @@ _dl_tailq_free(struct dep_node *n) elf_object_t *free_objects; -void _dl_cleanup_objects(void); void _dl_cleanup_objects() { @@ -421,11 +420,6 @@ _dl_remove_object(elf_object_t *object) } -int _dl_find_symbol_obj(elf_object_t *object, const char *name, - unsigned long hash, int flags, const Elf_Sym **ref, - const Elf_Sym **weak_sym, - elf_object_t **weak_object); - sym_cache *_dl_symcache; int _dl_symcachestat_hits; int _dl_symcachestat_lookups; @@ -505,6 +499,58 @@ _dl_newsymsearch(void) } } +static int +_dl_find_symbol_obj(elf_object_t *object, const char *name, unsigned long hash, + int flags, const Elf_Sym **this, const Elf_Sym **weak_sym, + elf_object_t **weak_object) +{ + const Elf_Sym *symt = object->dyn.symtab; + const char *strt = object->dyn.strtab; + long si; + const char *symn; + + for (si = object->buckets[hash % object->nbuckets]; + si != STN_UNDEF; si = object->chains[si]) { + const Elf_Sym *sym = symt + si; + + if (sym->st_value == 0) + continue; + + if (ELF_ST_TYPE(sym->st_info) != STT_NOTYPE && + ELF_ST_TYPE(sym->st_info) != STT_OBJECT && + ELF_ST_TYPE(sym->st_info) != STT_FUNC) + continue; + + symn = strt + sym->st_name; + if (sym != *this && _dl_strcmp(symn, name)) + continue; + + /* allow this symbol if we are referring to a function + * which has a value, even if section is UNDEF. + * this allows &func to refer to PLT as per the + * ELF spec. st_value is checked above. + * if flags has SYM_PLT set, we must have actual + * symbol, so this symbol is skipped. + */ + if (sym->st_shndx == SHN_UNDEF) { + if ((flags & SYM_PLT) || sym->st_value == 0 || + ELF_ST_TYPE(sym->st_info) != STT_FUNC) + continue; + } + + if (ELF_ST_BIND(sym->st_info) == STB_GLOBAL) { + *this = sym; + return 1; + } else if (ELF_ST_BIND(sym->st_info) == STB_WEAK) { + if (!*weak_sym) { + *weak_sym = sym; + *weak_object = object; + } + } + } + return 0; +} + Elf_Addr _dl_find_symbol(const char *name, const Elf_Sym **this, int flags, const Elf_Sym *ref_sym, elf_object_t *req_obj, @@ -638,58 +684,6 @@ found: return (object->obj_base); } -int -_dl_find_symbol_obj(elf_object_t *object, const char *name, unsigned long hash, - int flags, const Elf_Sym **this, const Elf_Sym **weak_sym, - elf_object_t **weak_object) -{ - const Elf_Sym *symt = object->dyn.symtab; - const char *strt = object->dyn.strtab; - long si; - const char *symn; - - for (si = object->buckets[hash % object->nbuckets]; - si != STN_UNDEF; si = object->chains[si]) { - const Elf_Sym *sym = symt + si; - - if (sym->st_value == 0) - continue; - - if (ELF_ST_TYPE(sym->st_info) != STT_NOTYPE && - ELF_ST_TYPE(sym->st_info) != STT_OBJECT && - ELF_ST_TYPE(sym->st_info) != STT_FUNC) - continue; - - symn = strt + sym->st_name; - if (sym != *this && _dl_strcmp(symn, name)) - continue; - - /* allow this symbol if we are referring to a function - * which has a value, even if section is UNDEF. - * this allows &func to refer to PLT as per the - * ELF spec. st_value is checked above. - * if flags has SYM_PLT set, we must have actual - * symbol, so this symbol is skipped. - */ - if (sym->st_shndx == SHN_UNDEF) { - if ((flags & SYM_PLT) || sym->st_value == 0 || - ELF_ST_TYPE(sym->st_info) != STT_FUNC) - continue; - } - - if (ELF_ST_BIND(sym->st_info) == STB_GLOBAL) { - *this = sym; - return 1; - } else if (ELF_ST_BIND(sym->st_info) == STB_WEAK) { - if (!*weak_sym) { - *weak_sym = sym; - *weak_object = object; - } - } - } - return 0; -} - void _dl_debug_state(void) { diff --git a/libexec/ld.so/resolve.h b/libexec/ld.so/resolve.h index 3bee635444e..d99423e2ea0 100644 --- a/libexec/ld.so/resolve.h +++ b/libexec/ld.so/resolve.h @@ -1,4 +1,4 @@ -/* $OpenBSD: resolve.h,v 1.69 2013/06/01 09:57:55 miod Exp $ */ +/* $OpenBSD: resolve.h,v 1.70 2013/11/13 05:41:42 deraadt Exp $ */ /* * Copyright (c) 1998 Per Fogelstrom, Opsycon AB @@ -233,6 +233,7 @@ Elf_Addr _dl_bind(elf_object_t *object, int index); int _dl_match_file(struct sod *sodp, const char *name, int namelen); char *_dl_find_shlib(struct sod *sodp, char **searchpath, int nohints); void _dl_load_list_free(struct load_list *load_list); +void _dl_debug_state(void); void _dl_thread_kern_go(void); void _dl_thread_kern_stop(void); diff --git a/libexec/ld.so/util.c b/libexec/ld.so/util.c index fb36517407d..d8d5a435da8 100644 --- a/libexec/ld.so/util.c +++ b/libexec/ld.so/util.c @@ -1,4 +1,4 @@ -/* $OpenBSD: util.c,v 1.26 2013/06/09 13:10:19 miod Exp $ */ +/* $OpenBSD: util.c,v 1.27 2013/11/13 05:41:42 deraadt Exp $ */ /* * Copyright (c) 1998 Per Fogelstrom, Opsycon AB @@ -52,8 +52,8 @@ __stack_smash_handler(char func[], int damaged) /* * Static vars usable after bootstrapping. */ -static void *_dl_malloc_pool = 0; -static long *_dl_malloc_free = 0; +static char *_dl_malloc_pool; +static long *_dl_malloc_free; char * _dl_strdup(const char *orig) @@ -98,7 +98,7 @@ _dl_malloc(size_t need) have = _dl_round_page((long)_dl_malloc_pool) - (long)_dl_malloc_pool; if (need > have) { if (have >= 8 + DL_MALLOC_ALIGN) { - p = _dl_malloc_pool; + p = (void *)_dl_malloc_pool; p = (void *) ((long)p + DL_MALLOC_ALIGN); p[-1] = have; _dl_free((void *)p); /* move to freelist */ @@ -111,7 +111,7 @@ _dl_malloc(size_t need) _dl_exit(7); } } - p = _dl_malloc_pool; + p = (void *)_dl_malloc_pool; _dl_malloc_pool += need; _dl_memset(p, 0, need); p = (void *) ((long)p + DL_MALLOC_ALIGN); |