diff options
author | Dale Rahn <drahn@cvs.openbsd.org> | 2006-05-03 22:14:45 +0000 |
---|---|---|
committer | Dale Rahn <drahn@cvs.openbsd.org> | 2006-05-03 22:14:45 +0000 |
commit | d271b6812612822db88add8a08a3ff0ad016494c (patch) | |
tree | e07825ce0a16ec9da64919edbdf00012abc7437e /libexec | |
parent | 8284cb202e0f5f465b5675359f76833e134657d2 (diff) |
several fixes dealing with determining if a program or library is being
processed. Also handles symlinks/hardlinks between binaries better.
Diffstat (limited to 'libexec')
-rw-r--r-- | libexec/ld.so/prebind/debug.c | 6 | ||||
-rw-r--r-- | libexec/ld.so/prebind/objarray.c | 25 | ||||
-rw-r--r-- | libexec/ld.so/prebind/prebind.c | 55 |
3 files changed, 51 insertions, 35 deletions
diff --git a/libexec/ld.so/prebind/debug.c b/libexec/ld.so/prebind/debug.c index 413bdb75ebe..d4002d5646b 100644 --- a/libexec/ld.so/prebind/debug.c +++ b/libexec/ld.so/prebind/debug.c @@ -1,4 +1,4 @@ -/* $OpenBSD: debug.c,v 1.1 2006/05/03 16:10:52 drahn Exp $ */ +/* $OpenBSD: debug.c,v 1.2 2006/05/03 22:14:44 drahn Exp $ */ /* * Copyright (c) 2006 Dale Rahn <drahn@dalerahn.com> * @@ -108,8 +108,8 @@ elf_dump_footer(struct prebind_footer *footer) printf("pltsymcache_cnt %d\n", footer->pltsymcache_cnt); printf("fixup_cnt %d\n", footer->fixup_cnt); printf("numlibs %d\n", footer->numlibs); - printf("id0 %d\n", footer->id0); - printf("id1 %d\n", footer->id1); + printf("id0 %x\n", footer->id0); + printf("id1 %x\n", footer->id1); printf("orig_size %lld\n", (long long)footer->orig_size); printf("version %d\n", footer->prebind_version); printf("bind_id %c%c%c%c\n", footer->bind_id[0], diff --git a/libexec/ld.so/prebind/objarray.c b/libexec/ld.so/prebind/objarray.c index 1c4f45f751c..17bb9fb14f6 100644 --- a/libexec/ld.so/prebind/objarray.c +++ b/libexec/ld.so/prebind/objarray.c @@ -1,4 +1,4 @@ -/* $OpenBSD: objarray.c,v 1.1 2006/05/03 16:10:52 drahn Exp $ */ +/* $OpenBSD: objarray.c,v 1.2 2006/05/03 22:14:44 drahn Exp $ */ /* * Copyright (c) 2006 Dale Rahn <drahn@dalerahn.com> * @@ -63,6 +63,8 @@ elf_add_object_curbin_list(struct elf_object *object) ol = malloc(sizeof (struct objlist)); ol->object = object; TAILQ_INSERT_TAIL(&(curbin->curbin_list), ol, list); + if ( load_object == NULL) + load_object = object; ol->load_prog = load_object; #if 0 @@ -116,7 +118,9 @@ elf_sum_reloc() #if 0 printf("\tprog %d %s\n", ol->load_prog->dyn.null, ol->load_prog->load_name); - printf("cache:\n"); + printf("cache: %p %p %s\n", + objarray[i].symcache, ol->cache, + ol->object->load_name ); #endif elf_copy_syms(objarray[i].symcache, @@ -439,6 +443,7 @@ elf_write_lib(struct elf_object *object, struct nameidx *nameidx, u_int32_t *maptab = NULL; u_int32_t footer_offset; int i; + size_t len; /* open the file */ fd = open(object->load_name, O_RDWR); @@ -451,7 +456,7 @@ elf_write_lib(struct elf_object *object, struct nameidx *nameidx, } } lseek(fd, -((off_t)sizeof(struct prebind_footer)), SEEK_END); - read(fd, &footer, sizeof(struct prebind_footer)); + len = read(fd, &footer, sizeof(struct prebind_footer)); if (footer.bind_id[0] == BIND_ID0 && footer.bind_id[1] == BIND_ID1 && @@ -644,6 +649,7 @@ elf_fixup_prog_load(int fd, struct prebind_footer *footer, ehdr->e_phnum++; done: + msync(buf, 8192, MS_SYNC); munmap(buf, 8192); } @@ -674,9 +680,10 @@ elf_clear_prog_load(int fd, struct elf_object *object) if ((phdr[loadsection].p_type != PT_LOAD) || ((phdr[loadsection].p_flags & 0x08000000) == 0)) { /* doesn't look like ours */ - printf("mapped, %s id doesn't match %lx\n", + printf("mapped, %s id doesn't match %lx %d %d\n", object->load_name, - (long)(phdr[loadsection].p_vaddr)); + (long)(phdr[loadsection].p_vaddr), + phdr[loadsection].p_flags, loadsection); goto done; } @@ -686,6 +693,7 @@ elf_clear_prog_load(int fd, struct elf_object *object) ehdr->e_phnum--; done: + msync(buf, 8192, MS_SYNC); munmap(buf, 8192); } void @@ -804,13 +812,13 @@ elf_calc_fixups(struct proglist *pl, struct objlist *ol, int libidx) } void -elf_add_object(struct elf_object *object, int lib) +elf_add_object(struct elf_object *object, int objtype) { struct objarray_list *newarray; struct objlist *ol; ol = malloc(sizeof (struct objlist)); ol->object = object; - if (lib) + if (objtype != OBJTYPE_EXE) TAILQ_INSERT_TAIL(&library_list, ol, list); if (objarray_cnt+1 >= objarray_sz) { objarray_sz += 512; @@ -913,7 +921,6 @@ write_txtbusy_file(char *name) void *buf; size_t len, wlen; -printf("txtbusy processing %s\n", name); err = lstat(name, &sb); /* get mode of old file (preserve mode) */ if (err != 0) return -1; /* stat shouldn't fail but if it does */ @@ -931,9 +938,7 @@ printf("txtbusy processing %s\n", name); buf = malloc(BUFSZ); fd = open(prebind_name, O_RDWR|O_CREAT|O_TRUNC, sb.st_mode); - printf("opened %s %d mode %o\n", prebind_name, fd, sb.st_mode); oldfd = open(name, O_RDONLY); - printf("opened %s %d\n", name, oldfd); while ((len = read(oldfd, buf, BUFSZ)) > 0) { wlen = write(fd, buf, len); if (wlen != len) { diff --git a/libexec/ld.so/prebind/prebind.c b/libexec/ld.so/prebind/prebind.c index c58e5297c9e..5d27938a984 100644 --- a/libexec/ld.so/prebind/prebind.c +++ b/libexec/ld.so/prebind/prebind.c @@ -1,4 +1,4 @@ -/* $OpenBSD: prebind.c,v 1.4 2006/05/03 19:58:40 drahn Exp $ */ +/* $OpenBSD: prebind.c,v 1.5 2006/05/03 22:14:44 drahn Exp $ */ /* * Copyright (c) 2006 Dale Rahn <drahn@dalerahn.com> * @@ -93,11 +93,12 @@ char * elf_find_shlib(struct sod *sodp, const char *searchpath, elf_object_t * elf_tryload_shlib(const char *libname); int elf_match_file(struct sod *sodp, char *name, int namelen); void elf_init_objarray(void); -void elf_add_object(struct elf_object *object, int lib); +void elf_add_object(struct elf_object *object, int objtype); void elf_print_objarray(void); struct elf_object * elf_lookup_object(const char *name); -struct elf_object * elf_lookup_object_devino(dev_t dev, ino_t inode); +struct elf_object * elf_lookup_object_devino(dev_t dev, ino_t inode, + int objtype); void elf_free_curbin_list(struct elf_object *obj); void elf_resolve_curbin(void); struct proglist *elf_newbin(void); @@ -150,7 +151,8 @@ load_file_or_dir(char *name) load_exe(name); break; case S_IFDIR: - printf("loading dir %s\n", name); + if (verbose > 0) + printf("loading dir %s\n", name); load_dir(name); break; default: @@ -204,15 +206,16 @@ load_exe(char *name) curbin = elf_newbin(); if (verbose > 0) printf("processing %s\n", name); - object = load_file(name, 0); - if (load_object != NULL) { + object = load_file(name, OBJTYPE_EXE); + if (object != NULL && load_object != NULL && + object->load_object == NULL) { TAILQ_FOREACH(ol, &(curbin->curbin_list), list) { fail = load_obj_needed(ol->object); if (fail != 0) break; /* XXX */ } - interp = load_file(curbin->interp, 2); + interp = load_file(curbin->interp, OBJTYPE_DLO); /* slight abuse of this field */ object->load_object = interp; @@ -228,11 +231,13 @@ load_exe(char *name) if (load_object != NULL) { load_object = NULL; } + } else { + free (curbin); } } struct elf_object * -load_file(const char *filename, int lib) +load_file(const char *filename, int objtype) { int fd = -1; void *buf = NULL; @@ -266,7 +271,7 @@ load_file(const char *filename, int lib) goto done; } - obj = elf_lookup_object_devino( ifstat.st_dev, ifstat.st_ino); + obj = elf_lookup_object_devino( ifstat.st_dev, ifstat.st_ino, objtype); if (obj != NULL) goto done; @@ -289,10 +294,11 @@ load_file(const char *filename, int lib) goto done; } - if ((lib == 0) && (pehdr->e_type != ET_EXEC)) + if ((objtype == OBJTYPE_EXE) && (pehdr->e_type != ET_EXEC)) goto done; - if ((lib == 1 || lib == 2) && (pehdr->e_type != ET_DYN)) + if ((objtype == OBJTYPE_LIB || objtype == OBJTYPE_DLO) && + (pehdr->e_type != ET_DYN)) goto done; @@ -319,24 +325,25 @@ printf("e_shstrndx %x\n\n", pehdr->e_shstrndx); obj = elf_load_object(pexe, filename); - - munmap(buf, ifstat.st_size); buf = NULL; if (obj != NULL) { + obj->obj_type = objtype; + obj->dev = ifstat.st_dev; obj->inode = ifstat.st_ino; if (load_object == NULL) load_object = obj; - elf_add_object(obj, lib); + elf_add_object(obj, objtype); #ifdef DEBUG1 dump_info(obj); #endif } - if (lib == 1 && merge_mode == 1) { + if ((objtype == OBJTYPE_LIB || objtype == OBJTYPE_DLO) + && merge_mode == 1) { /* * for libraries, check if old prebind info exists * and load it if we are in merge mode @@ -396,7 +403,7 @@ main(int argc, char **argv) for (i = 0; i < argc; i++) { load_file_or_dir(argv[i]); } - if (verbose > 1) { + if (verbose > 4) { elf_print_objarray(); elf_print_prog_list(&prog_list); } @@ -904,7 +911,7 @@ elf_tryload_shlib(const char *libname) struct elf_object *object; object = elf_lookup_object(libname); if (object == NULL) { - object = load_file(libname, 1); + object = load_file(libname, OBJTYPE_LIB); } if (object == NULL) printf("tryload_shlib %s\n", libname); @@ -975,8 +982,6 @@ elf_newbin(void) return proglist; } - - /* * Copy the contents of a libraries symbol cache instance into * the 'global' symbol cache for that library @@ -1085,18 +1090,24 @@ elf_lookup_object(const char *name) } struct elf_object * -elf_lookup_object_devino(dev_t dev, ino_t inode) +elf_lookup_object_devino(dev_t dev, ino_t inode, int objtype) { struct objlist *ol; TAILQ_FOREACH(ol, &(curbin->curbin_list), list) { if (ol->object->dev == dev && - ol->object->inode == inode) + ol->object->inode == inode) { + if (ol->object->obj_type != objtype) + return NULL; return ol->object; + } } TAILQ_FOREACH(ol, &library_list, list) { if (ol->object->dev == dev && ol->object->inode == inode) { - elf_add_object_curbin_list(ol->object); + if (ol->object->obj_type != objtype) + return NULL; + if (objtype != OBJTYPE_EXE) + elf_add_object_curbin_list(ol->object); return ol->object; } } |