summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTheo de Raadt <deraadt@cvs.openbsd.org>2006-05-12 23:20:54 +0000
committerTheo de Raadt <deraadt@cvs.openbsd.org>2006-05-12 23:20:54 +0000
commit2b0781cc11cefa28d450d3cc30901ec7ae040340 (patch)
tree14fe29ed6d31d9dee0f3dea9036cf51de00b6a26
parent9588320eaa6af8d8d2023d04ebfea3ea7858acb6 (diff)
move the prebind code into ldconfig as the -P option.
next we will want to enhance the verbose mode, fix error handling, and change the prebind delete code to use the same directory handling code ok drahn
-rw-r--r--libexec/ld.so/ldconfig/Makefile4
-rw-r--r--libexec/ld.so/ldconfig/debug.c (renamed from libexec/ld.so/prebind/debug.c)2
-rw-r--r--libexec/ld.so/ldconfig/dl_prebind.c619
-rw-r--r--libexec/ld.so/ldconfig/etc.c16
-rw-r--r--libexec/ld.so/ldconfig/ldconfig.c34
-rw-r--r--libexec/ld.so/ldconfig/library.c (renamed from libexec/ld.so/prebind/objarray.c)2
-rw-r--r--libexec/ld.so/ldconfig/prebind.8 (renamed from libexec/ld.so/prebind/prebind.8)2
-rw-r--r--libexec/ld.so/ldconfig/prebind.c (renamed from libexec/ld.so/prebind/prebind.c)157
-rw-r--r--libexec/ld.so/ldconfig/prebind.h64
-rw-r--r--libexec/ld.so/ldconfig/prebind_delete.c27
-rw-r--r--libexec/ld.so/ldconfig/prebind_struct.h (renamed from libexec/ld.so/prebind/prebind_struct.h)6
-rw-r--r--libexec/ld.so/ldconfig/sod.c (renamed from libexec/ld.so/prebind/sod.c)2
-rw-r--r--libexec/ld.so/prebind/Makefile18
13 files changed, 773 insertions, 180 deletions
diff --git a/libexec/ld.so/ldconfig/Makefile b/libexec/ld.so/ldconfig/Makefile
index 1b165066953..c65c6d118f4 100644
--- a/libexec/ld.so/ldconfig/Makefile
+++ b/libexec/ld.so/ldconfig/Makefile
@@ -1,8 +1,8 @@
-# $OpenBSD: Makefile,v 1.6 2006/05/11 22:19:22 deraadt Exp $
+# $OpenBSD: Makefile,v 1.7 2006/05/12 23:20:52 deraadt Exp $
# $NetBSD: Makefile,v 1.10 1995/03/06 04:24:41 cgd Exp $
PROG= ldconfig
-SRCS= ldconfig.c shlib.c etc.c prebind_delete.c
+SRCS= ldconfig.c shlib.c etc.c prebind_delete.c debug.c prebind.c library.c sod.c
LDDIR?= $(.CURDIR)/..
#CFLAGS+=-Werror
CFLAGS+=-I$(.CURDIR) -I$(.CURDIR)/..
diff --git a/libexec/ld.so/prebind/debug.c b/libexec/ld.so/ldconfig/debug.c
index b7aa78bba23..c768826e4b8 100644
--- a/libexec/ld.so/prebind/debug.c
+++ b/libexec/ld.so/ldconfig/debug.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: debug.c,v 1.4 2006/05/08 20:39:44 deraadt Exp $ */
+/* $OpenBSD: debug.c,v 1.1 2006/05/12 23:20:52 deraadt Exp $ */
/*
* Copyright (c) 2006 Dale Rahn <drahn@dalerahn.com>
*
diff --git a/libexec/ld.so/ldconfig/dl_prebind.c b/libexec/ld.so/ldconfig/dl_prebind.c
new file mode 100644
index 00000000000..e71052bb4ae
--- /dev/null
+++ b/libexec/ld.so/ldconfig/dl_prebind.c
@@ -0,0 +1,619 @@
+/* $OpenBSD: dl_prebind.c,v 1.1 2006/05/12 23:20:52 deraadt Exp $ */
+
+/*
+ * Copyright (c) 2006 Dale Rahn <drahn@dalerahn.com>
+ *
+ * Permission to use, copy, modify, and distribute this software for any
+ * purpose with or without fee is hereby granted, provided that the above
+ * copyright notice and this permission notice appear in all copies.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
+ * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
+ * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
+ * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
+ * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
+ * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
+ * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
+ */
+
+#include <sys/types.h>
+#include <sys/mman.h>
+#include <sys/exec.h>
+#include <sys/param.h>
+#include <sys/sysctl.h>
+#include <nlist.h>
+#include <string.h>
+#include <link.h>
+#include <dlfcn.h>
+#include <unistd.h>
+
+#include "syscall.h"
+#include "archdep.h"
+#include "resolve.h"
+#include "sod.h"
+#include "stdlib.h"
+#include "dl_prebind.h"
+
+void elf_dump_footer(struct prebind_footer *footer);
+void dump_prelink(Elf_Addr base, u_long size);
+void prebind_dump_footer(struct prebind_footer *footer, char *file);
+void prebind_dump_symcache(struct symcachetab *symcachetab, u_int32_t cnt);
+void prebind_dump_nameidx(struct nameidx *nameidx, u_int32_t numblibs,
+ char *nametab);
+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;
+struct prebind_footer *prog_footer;
+extern char *_dl_noprebind;
+extern char *_dl_prebind_validate;
+
+int _dl_prebind_match_failed; /* = 0 */
+
+char *prebind_bind_now = "prebind";
+
+struct prebind_footer *
+_dl_prebind_data_to_footer(void *prebind_data)
+{
+ u_int32_t *poffset, offset;
+ struct prebind_footer *footer;
+ char *c;
+
+ poffset = prebind_data;
+ c = prebind_data;
+ offset = *poffset;
+ c += offset;
+ footer = (void *)c;
+ return footer;
+}
+
+void
+prebind_load_exe(Elf_Phdr *phdp, elf_object_t *exe_obj)
+{
+ struct prebind_footer *footer;
+
+ exe_obj->prebind_data = (void *)phdp->p_vaddr;
+ _dl_prog_prebind_map = exe_obj->prebind_data;
+
+ footer = _dl_prebind_data_to_footer(_dl_objects->prebind_data);
+
+ if (footer->bind_id[0] == BIND_ID0 &&
+ footer->bind_id[1] == BIND_ID1 &&
+ footer->bind_id[2] == BIND_ID2 &&
+ footer->bind_id[3] == BIND_ID3 &&
+ footer->prebind_version == PREBIND_VERSION) {
+ prog_footer = footer;
+ if (_dl_bindnow == NULL)
+ _dl_bindnow = prebind_bind_now;
+ } else {
+ DL_DEB(("prebind data missing\n"));
+ _dl_prog_prebind_map = NULL;
+ }
+ if (_dl_noprebind != NULL) {
+ /*prog_footer is valid, we should free it */
+ _dl_prog_prebind_map = NULL;
+ prog_footer = NULL;
+ exe_obj->prebind_data = NULL;
+ if (_dl_bindnow == prebind_bind_now)
+ _dl_bindnow = NULL;
+ }
+#if 0
+ else if (_dl_debug)
+ dump_prelink((long)_dl_prog_prebind_map,
+ prog_footer->prebind_size);
+#endif
+}
+
+void *
+prebind_load_fd(int fd, const char *name)
+{
+ struct prebind_footer footer;
+ struct nameidx *nameidx;
+ void *prebind_data;
+ char *nametab;
+ ssize_t len;
+ int idx;
+
+ if (_dl_prog_prebind_map == NULL || _dl_prebind_match_failed)
+ return 0;
+
+ _dl_lseek(fd, -(off_t)sizeof(struct prebind_footer), SEEK_END);
+ len = _dl_read(fd, (void *)&footer, sizeof(struct prebind_footer));
+
+ if (len != sizeof(struct prebind_footer) ||
+ footer.bind_id[0] != BIND_ID0 ||
+ footer.bind_id[1] != BIND_ID1 ||
+ footer.bind_id[2] != BIND_ID2 ||
+ footer.bind_id[3] != BIND_ID3 ||
+ footer.prebind_version != PREBIND_VERSION) {
+ _dl_prebind_match_failed = 1;
+ DL_DEB(("prebind match failed %s\n", name));
+ return (NULL);
+ }
+
+ prebind_data = _dl_mmap(0, footer.prebind_size, PROT_READ,
+ 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;
+
+ /* libraries are loaded in random order, so we just have
+ * to look thru the list to find ourselves
+ */
+ for (idx = 0; idx < prog_footer->numlibs; idx++) {
+ if (_dl_strcmp(nametab + nameidx[idx].name, name) == 0)
+ break;
+ }
+
+ if (idx == prog_footer->numlibs) {
+ _dl_prebind_match_failed = 1; /* not found */
+ } else if (footer.id0 != nameidx[idx].id0 ||
+ footer.id1 != nameidx[idx].id1) {
+ _dl_prebind_match_failed = 1;
+ DL_DEB(("prebind match id0 %d pid0 %d id1 %d pid1 %d\n",
+ footer.id0, nameidx[idx].id0,
+ footer.id1, nameidx[idx].id1));
+ }
+
+ if (_dl_prebind_match_failed == 1) {
+ DL_DEB(("prebind match failed for %s\n", name));
+ }
+
+ return prebind_data;
+}
+#define NUM_STATIC_OBJS 10
+elf_object_t *objarray_static[NUM_STATIC_OBJS];
+elf_object_t **objarray;
+
+void
+prebind_symcache(elf_object_t *object, int plt)
+{
+ u_int32_t *fixupidx, *fixupcnt, *libmap, *idxtolib;
+ u_int32_t *poffset, offset, symcache_cnt;
+ struct symcachetab *symcachetab;
+ struct prebind_footer *footer;
+ int i = 0, cur_obj = -1, idx;
+ void *prebind_map;
+ struct nameidx *nameidx;
+ char *nametab, *c;
+ struct fixup *fixup;
+ elf_object_t *obj;
+
+ struct symcachetab *s;
+
+ if (object->prebind_data == NULL)
+ return;
+// DL_DEB(("prebind symcache %s\n", object->load_name));
+
+ obj = _dl_objects;
+ while (obj != NULL) {
+ if (obj == object)
+ cur_obj = i;
+ i++;
+ obj = obj->next;
+ }
+
+ if (cur_obj == -1)
+ return; /* unable to find object ? */
+
+ if (objarray == NULL) {
+ if (i <= NUM_STATIC_OBJS) {
+ objarray = &objarray_static[0];
+ } else {
+ objarray = _dl_malloc(sizeof(elf_object_t *) * i);
+ }
+
+ obj = _dl_objects;
+ i = 0;
+ while (obj != NULL) {
+ objarray[i] = obj;
+ i++;
+ obj = obj->next;
+ }
+ }
+
+ poffset = (u_int32_t *)object->prebind_data;
+ c = object->prebind_data;
+ offset = *poffset;
+ c += offset;
+
+ footer = (void *)c;
+ prebind_map = (void *)object->prebind_data;
+ nameidx = prebind_map + footer->nameidx_idx;;
+ if (plt) {
+ symcachetab = 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;
+ symcache_cnt = footer->symcache_cnt;
+// DL_DEB(("loading got %d\n", symcache_cnt));
+ }
+ nametab = prebind_map + footer->nametab_idx;
+
+ libmap = _dl_prog_prebind_map + prog_footer->libmap_idx;
+ idxtolib = _dl_prog_prebind_map + libmap[cur_obj];
+
+ for (i = 0; i < symcache_cnt; i++) {
+ struct elf_object *tobj;
+ const Elf_Sym *sym;
+ const char *str;
+
+ s = &(symcachetab[i]);
+ if (cur_obj == 0)
+ idx = s->obj_idx;
+ else
+ idx = idxtolib[s->obj_idx];
+
+ if (idx == -1) /* somehow an invalid object ref happend */
+ continue;
+#if 0
+ DL_DEB(("%s:", object->load_name));
+ DL_DEB(("symidx %d: obj %d %d sym %d flags %x\n",
+ s->idx, s->obj_idx, idx, s->sym_idx,
+ SYM_SEARCH_ALL|SYM_WARNNOTFOUND|plt));
+#endif
+ tobj = objarray[idx];
+ sym = tobj->dyn.symtab + s->sym_idx;
+ str = tobj->dyn.strtab + sym->st_name;
+#ifdef DEBUG2
+ DL_DEB(("symidx %d: obj %d %s sym %d %s flags %d %x\n",
+ s->idx, s->obj_idx, tobj->load_name,
+ s->sym_idx, str, SYM_SEARCH_ALL|SYM_WARNNOTFOUND|plt,
+ object->load_addr + sym->st_value));
+#endif
+ _dl_symcache[s->idx].obj = tobj;
+ _dl_symcache[s->idx].sym = sym;
+ _dl_symcache[s->idx].flags =
+ SYM_SEARCH_ALL|SYM_WARNNOTFOUND|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;
+
+ for (i = 0; i < fixupcnt[2*cur_obj]; i++) {
+ struct fixup *f;
+ struct elf_object *tobj;
+ const Elf_Sym *sym;
+ const char *str;
+
+ f = &(fixup[i]);
+#if 0
+ DL_DEB(("symidx %d: obj %d sym %d flags %x\n",
+ f->sym, f->obj_idx, f->sym_idx, f->flags));
+#endif
+ tobj = objarray[f->obj_idx];
+ sym = tobj->dyn.symtab + f->sym_idx;
+ str = tobj->dyn.strtab + sym->st_name;
+#ifdef DEBUG2
+ DL_DEB(("symidx %d: obj %d %s sym %d %s flags %d %x\n",
+ f->sym, f->obj_idx, tobj->load_name,
+ f->sym_idx, str, SYM_SEARCH_ALL|SYM_WARNNOTFOUND|plt,
+ object->load_addr + sym->st_value));
+#endif
+ _dl_symcache[f->sym].obj = tobj;
+ _dl_symcache[f->sym].sym = sym;
+ _dl_symcache[f->sym].flags =
+ SYM_SEARCH_ALL|SYM_WARNNOTFOUND|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;
+
+#if 0
+ DL_DEB(("prebind loading symbols fixup plt %s\n",
+ object->load_name));
+#endif
+ for (i = 0; i < fixupcnt[2*cur_obj+1]; i++) {
+ struct fixup *f;
+ struct elf_object *tobj;
+ const Elf_Sym *sym;
+ const char *str;
+
+ f = &(fixup[i]);
+#if 0
+ DL_DEB(("symidx %d: obj %d sym %d flags %x\n",
+ f->sym, f->obj_idx, f->sym_idx,
+ SYM_SEARCH_ALL|SYM_WARNNOTFOUND|plt));
+#endif
+ tobj = objarray[f->obj_idx];
+ sym = tobj->dyn.symtab + f->sym_idx;
+ str = tobj->dyn.strtab + sym->st_name;
+#ifdef DEBUG2
+ DL_DEB(("symidx %d: obj %d %s sym %d %s flags %d %x\n",
+ f->sym, f->obj_idx, tobj->load_name,
+ f->sym_idx, str, SYM_SEARCH_ALL|SYM_WARNNOTFOUND|plt,
+ object->load_addr + sym->st_value));
+#endif
+ _dl_symcache[f->sym].obj = tobj;
+ _dl_symcache[f->sym].sym = sym;
+ _dl_symcache[f->sym].flags =
+ SYM_SEARCH_ALL|SYM_WARNNOTFOUND|plt;
+ }
+ }
+// DL_DEB(("prebind_data loaded\n"));
+}
+
+void
+prebind_free(elf_object_t *object)
+{
+ struct prebind_footer *footer;
+
+ if (object->prebind_data == NULL)
+ return;
+#ifdef DEBUG1
+ DL_DEB(("prebind_free for %s %p\n", object->load_name,
+ object->prebind_data));
+#endif
+ if (object->prebind_data != 0) {
+ footer = _dl_prebind_data_to_footer(object->prebind_data);
+
+#ifdef DEBUG1
+ DL_DEB(("freeing prebind data sz %x\n", footer->prebind_size));
+#endif
+
+ _dl_munmap((void *)ELF_TRUNC((long)object->prebind_data, _dl_pagesz),
+ ELF_ROUND((long)object->prebind_data+footer->prebind_size,
+ _dl_pagesz) - ELF_TRUNC((long)object->prebind_data, _dl_pagesz));
+
+ object->prebind_data = NULL;
+ _dl_prog_prebind_map = NULL;
+
+ if (_dl_bindnow == prebind_bind_now)
+ _dl_bindnow = NULL;
+ }
+}
+
+int validate_errs;
+
+struct timeval beforetp;
+
+void
+_dl_prebind_pre_resolve()
+{
+ struct prebind_footer *footer;
+ elf_object_t *object;
+ struct nameidx *nameidx;
+ char *nametab, *name;
+ 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;
+ for (idx = 1, object = _dl_objects->next; object != NULL;
+ object = object->next, idx++) {
+ if (object->prebind_data == NULL) {
+ /* ld.so doesn't have prebind data */
+ if (object->next == NULL)
+ continue;
+ DL_DEB(("missing prebind data %s\n",
+ object->load_name));
+ _dl_prebind_match_failed = 1;
+ break;
+ }
+ footer = _dl_prebind_data_to_footer(
+ object->prebind_data);
+ if (footer == NULL ||
+ nameidx[idx].id0 != footer->id0 ||
+ nameidx[idx].id1 != footer->id1) {
+ DL_DEB(("invalid prebind data %s\n",
+ object->load_name));
+ _dl_prebind_match_failed = 1;
+ break;
+ }
+ name = object->load_name;
+ if (_dl_strcmp(nametab + nameidx[idx].name, name)
+ != 0) {
+ DL_DEB(("invalid prebind name %s\n",
+ object->load_name));
+ _dl_prebind_match_failed = 1;
+ break;
+ }
+ }
+ }
+
+ if (_dl_prebind_match_failed) {
+ for (object = _dl_objects; object != NULL;
+ object = object->next)
+ prebind_free(object);
+ if (_dl_bindnow == prebind_bind_now)
+ _dl_bindnow = NULL;
+ }
+
+ if (_dl_debug)
+ _dl_gettimeofday(&beforetp, NULL);
+}
+
+void
+_dl_prebind_post_resolve()
+{
+ char buf[7];
+ int i;
+ struct timeval after_tp;
+ struct timeval diff_tp;
+ elf_object_t *object;
+
+ if (_dl_debug) {
+ _dl_gettimeofday(&after_tp, NULL);
+
+ timersub(&after_tp, &beforetp, &diff_tp);
+
+ for (i = 0; i < 6; i++) {
+ buf[5-i] = (diff_tp.tv_usec % 10) + '0';
+ diff_tp.tv_usec /= 10;
+ }
+ buf[6] = '\0';
+
+ _dl_printf("relocation took %d.%s\n", diff_tp.tv_sec, buf);
+ }
+
+ for (object = _dl_objects; object != NULL; object = object->next)
+ prebind_free(object);
+
+ if (_dl_prebind_validate) {
+ if (validate_errs) {
+ _dl_printf("validate_errs %d\n", validate_errs);
+ _dl_exit(20);
+ } else {
+ _dl_exit(0);
+ }
+ }
+}
+
+void
+prebind_validate(elf_object_t *req_obj, unsigned int symidx, int flags,
+ const Elf_Sym *ref_sym)
+{
+ const Elf_Sym *sym, **this;
+ const elf_object_t *sobj;
+ const char *symn;
+ Elf_Addr ret;
+
+ /* Don't verify non-matching flags*/
+
+ sym = req_obj->dyn.symtab;
+ sym += symidx;
+ symn = req_obj->dyn.strtab + sym->st_name;
+ this = &sym;
+
+ //_dl_printf("checking %s\n", symn);
+ ret = _dl_find_symbol(symn, this, flags, ref_sym, req_obj, &sobj);
+
+ if (_dl_symcache[symidx].sym != *this ||
+ _dl_symcache[symidx].obj != sobj) {
+ _dl_printf("symbol %d mismatch on sym %s req_obj %s,\n"
+ "should be obj %s is obj %s\n",
+ symidx, symn, req_obj->load_name, sobj->load_name,
+ _dl_symcache[symidx].obj->load_name);
+ if (req_obj == sobj)
+ _dl_printf("obj %p %p\n", _dl_symcache[symidx].obj, sobj);
+ sym = _dl_symcache[symidx].obj->dyn.symtab;
+ sym += symidx;
+ symn = _dl_symcache[symidx].obj->dyn.strtab + sym->st_name;
+ _dl_printf("obj %s name %s\n",
+ _dl_symcache[symidx].obj->load_name,
+ symn);
+ }
+}
+
+#ifdef DEBUG1
+void
+prebind_dump_symcache(struct symcachetab *symcachetab, u_int32_t cnt)
+{
+ struct symcachetab *s;
+ int i;
+
+ _dl_printf("cache: cnt %d\n", cnt);
+ for (i = 0; i < cnt; i++) {
+ s = &(symcachetab[i]);
+ _dl_printf("symidx %d: obj %d sym %d\n",
+ s->idx, s->obj_idx, s->sym_idx);
+ }
+}
+
+void
+prebind_dump_nameidx(struct nameidx *nameidx, u_int32_t numlibs, char *nametab)
+{
+ struct nameidx *n;
+ int i;
+
+ _dl_printf("libs:\n");
+ for (i = 0; i < numlibs; i++) {
+ _dl_printf("lib %d offset %d id0 %d, id1 %d\n", i,
+ nameidx[i].name, nameidx[i].id0, nameidx[i].id1);
+ }
+ for (i = 0; i < numlibs; i++) {
+ n = &(nameidx[i]);
+ _dl_printf("nametab %p n %d\n", nametab, n->name);
+ _dl_printf("lib %s %x %x\n", nametab + n->name, n->id0, n->id1);
+ }
+}
+
+void
+prebind_dump_fixup(struct fixup *fixup, u_int32_t numfixups)
+{
+ struct fixup *f;
+ int i;
+
+ _dl_printf("fixup: %d\n", numfixups);
+ for (i = 0; i < numfixups; i++) {
+ f = &(fixup[i]);
+
+ _dl_printf("idx %d obj %d sym idx %d\n",
+ f->sym, f->obj_idx, f->sym_idx);
+
+ }
+}
+
+void
+prebind_dump_libmap(u_int32_t *libmap, u_int32_t numlibs)
+{
+ int i;
+
+ for (i = 0; i < numlibs; i++) {
+ //_dl_printf("lib%d off %d %s\n", i, libmap[i], strtab+libmap[i]);
+ _dl_printf("lib%d off %d\n", i, libmap[i]);
+ }
+}
+
+void
+dl_dump_footer(struct prebind_footer *footer)
+{
+// _dl_printf("base %qd\n", (long long)footer->prebind_base);
+ _dl_printf("nameidx_idx %d\n", footer->nameidx_idx);
+ _dl_printf("symcache_idx %d\n", footer->symcache_idx);
+ _dl_printf("fixupcnt_idx %d\n", footer->fixupcnt_idx);
+ _dl_printf("fixup_cnt %d\n", footer->fixup_cnt);
+ _dl_printf("nametab_idx %d\n", footer->nametab_idx);
+ _dl_printf("symcache_cnt %d\n", footer->symcache_cnt);
+ _dl_printf("fixup_cnt %d\n", footer->fixup_cnt);
+ _dl_printf("numlibs %d\n", footer->numlibs);
+ _dl_printf("id0 %d\n", footer->id0);
+ _dl_printf("id1 %d\n", footer->id1);
+// _dl_printf("orig_size %lld\n", (long long)footer->orig_size);
+ _dl_printf("version %d\n", footer->prebind_version);
+ _dl_printf("bind_id %c%c%c%c\n", footer->bind_id[0],
+ footer->bind_id[1], footer->bind_id[2], footer->bind_id[3]);
+}
+void
+dump_prelink(Elf_Addr base, u_long size)
+{
+ u_int32_t *fixupidx, *fixupcnt, *libmap;
+ struct symcachetab *symcachetab;
+ struct prebind_footer *footer;
+ struct nameidx *nameidx;
+ struct fixup *fixup;
+ char *nametab, *id;
+ void *prebind_map;
+ int i;
+
+ id = (char *) (base+size);
+ id -= 4;
+ DL_DEB(("id %c %c %c %c\n", id[0], id[1], id[2], id[3]));
+ footer = (void *) (base+size - sizeof (struct prebind_footer));
+ dl_dump_footer(footer);
+
+ prebind_map = (void *)base;
+ nameidx = prebind_map + footer->nameidx_idx;;
+ symcachetab = prebind_map + footer->symcache_idx;
+ fixupidx = prebind_map + footer->fixup_idx;
+ nametab = prebind_map + footer->nametab_idx;
+ fixupcnt = prebind_map + footer->fixupcnt_idx;
+ libmap = prebind_map + footer->libmap_idx;
+
+ prebind_dump_symcache(symcachetab, footer->symcache_cnt);
+ prebind_dump_nameidx(nameidx, footer->numlibs, nametab);
+ for (i = 0; i < footer->fixup_cnt; i++) {
+ _dl_printf("fixup %d cnt %d idx %d\n", i, fixupcnt[i], fixupidx[i]);
+ fixup = prebind_map + fixupidx[i];
+ prebind_dump_fixup(fixup, fixupcnt[i]);
+ }
+ prebind_dump_libmap(libmap, footer->numlibs);
+}
+#endif /* DEBUG1 */
diff --git a/libexec/ld.so/ldconfig/etc.c b/libexec/ld.so/ldconfig/etc.c
index a1783c4ebf1..80111fce6f7 100644
--- a/libexec/ld.so/ldconfig/etc.c
+++ b/libexec/ld.so/ldconfig/etc.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: etc.c,v 1.5 2003/07/06 20:04:00 deraadt Exp $ */
+/* $OpenBSD: etc.c,v 1.6 2006/05/12 23:20:52 deraadt Exp $ */
/* Public Domain */
@@ -41,6 +41,20 @@ xrealloc(void *ptr, size_t size)
return (nptr);
}
+void *
+xcalloc(size_t nmemb, size_t size)
+{
+ void *ret;
+
+ ret = calloc(nmemb, size);
+ if (ret == NULL) {
+ printf("unable to allocate memory\n");
+ abort();
+ exit (20);
+ }
+ return ret;
+}
+
char *
concat(const char *s1, const char *s2, const char *s3)
{
diff --git a/libexec/ld.so/ldconfig/ldconfig.c b/libexec/ld.so/ldconfig/ldconfig.c
index cab2ee9ba03..fa1fe87151d 100644
--- a/libexec/ld.so/ldconfig/ldconfig.c
+++ b/libexec/ld.so/ldconfig/ldconfig.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: ldconfig.c,v 1.19 2006/05/11 22:03:22 deraadt Exp $ */
+/* $OpenBSD: ldconfig.c,v 1.20 2006/05/12 23:20:52 deraadt Exp $ */
/*
* Copyright (c) 1993,1995 Paul Kranenburg
@@ -58,12 +58,12 @@
extern char *__progname;
-static int verbose;
+int verbose;
static int delete;
static int doprebind;
static int nostd;
static int justread;
-static int merge;
+int merge;
static int rescan;
static int unconfig;
@@ -91,7 +91,7 @@ void
usage(void)
{
fprintf(stderr,
- "usage: %s [-DmRrsUv] [path ...]\n", __progname);
+ "usage: %s [-DmPrRsUv] [path ...]\n", __progname);
exit(1);
}
@@ -101,7 +101,7 @@ main(int argc, char *argv[])
int i, c;
int rval = 0;
- while ((c = getopt(argc, argv, "DRmrsUv")) != -1) {
+ while ((c = getopt(argc, argv, "DmPrRsUv")) != -1) {
switch (c) {
case 'R':
rescan = 1;
@@ -124,8 +124,8 @@ main(int argc, char *argv[])
case 'D':
delete = 1;
break;
-// case 'P':
-// doprebind = 1;
+ case 'P':
+ doprebind = 1;
break;
default:
usage();
@@ -139,12 +139,6 @@ main(int argc, char *argv[])
dir_list = xmalloc(1);
*dir_list = '\0';
- if (delete) {
- if (rescan || unconfig || merge || justread || nostd || doprebind)
- errx(1, "cannot mix -U -R -r -s -P options with -D");
- exit (prebind_delete(&argv[optind], verbose));
- }
-
if (justread || merge || rescan) {
if ((rval = readhints()) != 0)
return rval;
@@ -158,11 +152,15 @@ main(int argc, char *argv[])
} else if (!nostd)
std_search_path();
-// if (doprebind) {
-// if (rescan || unconfig || justread || nostd)
-// errx(1, "cannot mix other options with -P");
-// exit (prebind(&argv[optind], verbose, merge));
-// }
+ if (delete) {
+ if (rescan || unconfig || merge || justread || nostd || doprebind)
+ errx(1, "cannot mix -U -R -r -s -P options with -D");
+ exit (prebind_delete(&argv[optind]));
+ } else if (doprebind) {
+ if (rescan || unconfig || justread || nostd)
+ errx(1, "cannot mix other options with -P");
+ exit (prebind(&argv[optind]));
+ }
if (unconfig) {
if (optind < argc)
diff --git a/libexec/ld.so/prebind/objarray.c b/libexec/ld.so/ldconfig/library.c
index 5aed79d7cf4..cc4baa72df9 100644
--- a/libexec/ld.so/prebind/objarray.c
+++ b/libexec/ld.so/ldconfig/library.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: objarray.c,v 1.8 2006/05/12 15:12:42 drahn Exp $ */
+/* $OpenBSD: library.c,v 1.1 2006/05/12 23:20:52 deraadt Exp $ */
/*
* Copyright (c) 2006 Dale Rahn <drahn@dalerahn.com>
*
diff --git a/libexec/ld.so/prebind/prebind.8 b/libexec/ld.so/ldconfig/prebind.8
index 10e22d32216..2464674a231 100644
--- a/libexec/ld.so/prebind/prebind.8
+++ b/libexec/ld.so/ldconfig/prebind.8
@@ -1,4 +1,4 @@
-.\" $OpenBSD: prebind.8,v 1.6 2006/05/11 21:05:22 jmc Exp $
+.\" $OpenBSD: prebind.8,v 1.1 2006/05/12 23:20:52 deraadt Exp $
.\"
.\" Copyright (c) 2006 Dale Rahn <drahn@openbsd.org>
.\"
diff --git a/libexec/ld.so/prebind/prebind.c b/libexec/ld.so/ldconfig/prebind.c
index 9a860ed35d2..6d7af426cb9 100644
--- a/libexec/ld.so/prebind/prebind.c
+++ b/libexec/ld.so/ldconfig/prebind.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: prebind.c,v 1.18 2006/05/12 16:37:59 drahn Exp $ */
+/* $OpenBSD: prebind.c,v 1.1 2006/05/12 23:20:52 deraadt Exp $ */
/*
* Copyright (c) 2006 Dale Rahn <drahn@dalerahn.com>
*
@@ -79,7 +79,6 @@ obj_list_ty library_list =
prog_list_ty prog_list =
TAILQ_HEAD_INITIALIZER(prog_list);
-
struct objarray_list {
struct elf_object *obj;
struct symcache_noflag *symcache;
@@ -94,13 +93,12 @@ struct objarray_list {
TAILQ_HEAD(, objlist) inst_list;
} *objarray;
-int objarray_cnt;
-int objarray_sz;
-
-int write_txtbusy_file(char *name);
-void copy_oldsymcache(int objidx, void *prebind_data);
-void elf_load_existing_prebind(struct elf_object *object, int fd);
+int objarray_cnt;
+int objarray_sz;
+int write_txtbusy_file(char *name);
+void copy_oldsymcache(int objidx, void *prebind_data);
+void elf_load_existing_prebind(struct elf_object *object, int fd);
struct elf_object * elf_load_object(void *pexe, const char *name);
void elf_free_object(struct elf_object *object);
@@ -134,7 +132,6 @@ void add_fixup_oldprog(struct elf_object *prog, struct elf_object *obj, int idx,
void elf_dump_footer(struct prebind_footer *footer);
-
void elf_fixup_prog_load(int fd, struct prebind_footer *footer,
struct elf_object *object);
void elf_clear_prog_load(int fd, struct elf_object *object);
@@ -153,50 +150,22 @@ int elf_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);
-int verbose; /* how verbose to be when operating */
-int merge_mode; /* merge (do not overwrite) existing prebind library info */
-
struct elf_object *load_object;
-struct elf_object * load_file(const char *filename, int lib);
+struct elf_object *load_file(const char *filename, int lib);
int elf_check_note(void *buf, Elf_Phdr *phdr);
void load_file_or_dir(char *name);
void load_dir(char *name);
void load_exe(char *name);
-void __dead usage();
int
-main(int argc, char **argv)
+prebind(char **argv)
{
int i;
- int ch;
- extern int optind;
-
- /* GETOPT */
- while ((ch = getopt(argc, argv, "mv")) != -1) {
- switch (ch) {
- case 'm':
- merge_mode = 1;
- break;
- case 'v':
- verbose++;
- break;
- default:
- usage();
- /* NOTREACHED */
- }
- }
- argc -= optind;
- argv += optind;
-
- if (argc == 0) {
- usage();
- /* NOTREACHED */
- }
elf_init_objarray();
- for (i = 0; i < argc; i++)
+ for (i = 0; argv[i]; i++)
load_file_or_dir(argv[i]);
if (verbose > 4) {
@@ -206,16 +175,7 @@ main(int argc, char **argv)
elf_sum_reloc();
printf("total new blocks %lld\n", prebind_blocks);
-
- return 0;
-}
-
-void __dead
-usage()
-{
- extern char *__progname;
- printf("%s [-mv] {programlist}\n", __progname);
- exit(1);
+ return (0);
}
/*
@@ -260,9 +220,9 @@ load_file_or_dir(char *name)
void
load_dir(char *name)
{
- DIR *dirp;
struct dirent *dp;
struct stat sb;
+ DIR *dirp;
char *buf;
dirp = opendir(name);
@@ -361,15 +321,14 @@ load_exe(char *name)
struct elf_object *
load_file(const char *filename, int objtype)
{
+ struct elf_object *obj = NULL;
+ int fd = -1, i, note_found;
struct stat ifstat;
+ void *buf = NULL;
Elf_Ehdr *ehdr;
Elf_Shdr *shdr;
Elf_Phdr *phdr;
char *pexe;
- struct elf_object *obj = NULL;
- void *buf = NULL;
- int fd = -1, i;
- int note_found;
fd = open(filename, O_RDONLY);
if (fd == -1) {
@@ -431,7 +390,6 @@ load_file(const char *filename, int objtype)
(ehdr->e_type != ET_DYN))
goto done;
-
pexe = buf;
if (ehdr->e_shstrndx == 0)
goto done;
@@ -441,7 +399,6 @@ load_file(const char *filename, int objtype)
shstrtab = (char *)(pexe + shdr->sh_offset);
-
obj = elf_load_object(pexe, filename);
munmap(buf, ifstat.st_size);
@@ -461,8 +418,8 @@ load_file(const char *filename, int objtype)
dump_info(obj);
#endif
}
- if ((objtype == OBJTYPE_LIB || objtype == OBJTYPE_DLO)
- && merge_mode == 1) {
+ if ((objtype == OBJTYPE_LIB || objtype == OBJTYPE_DLO) &&
+ merge == 1) {
/*
* for libraries and dynamic linker, check if old prebind
* info exists and load it if we are in merge mode
@@ -495,7 +452,6 @@ elf_check_note(void *buf, Elf_Phdr *phdr)
pint = (u_int *)((char *)buf + address);
osname = (char *)buf + address + sizeof(*pint) * 3;
-
if (pint[0] == 8 /* OpenBSD\0 */ &&
pint[1] == 4 /* ??? */ &&
pint[2] == 1 /* type_osversion */ &&
@@ -508,7 +464,6 @@ elf_check_note(void *buf, Elf_Phdr *phdr)
struct elf_object *
elf_load_object(void *pexe, const char *name)
{
- int i;
struct elf_object *object;
Elf_Dyn *dynp = NULL, *odynp;
Elf_Ehdr *ehdr;
@@ -517,7 +472,7 @@ elf_load_object(void *pexe, const char *name)
const char *strt;
Elf_Addr loff;
Elf_Word *needed_list;
- int needed_cnt = 0;
+ int needed_cnt = 0, i;
object = calloc(1, sizeof (struct elf_object));
if (object == NULL) {
@@ -698,10 +653,7 @@ elf_load_object(void *pexe, const char *name)
exit(10);
}
}
-
-
- object->dyn.needed = (Elf_Addr)needed_list;
-
+ object->dyn.needed = (Elf_Addr)needed_list;
}
#ifdef DEBUG1
@@ -716,7 +668,7 @@ elf_load_object(void *pexe, const char *name)
void
elf_free_object(struct elf_object *object)
{
- free (object->load_name);
+ free(object->load_name);
if (object->dyn.hash != NULL)
free(object->dyn.hash);
free((void *)object->dyn.strtab);
@@ -788,7 +740,6 @@ load_obj_needed(struct elf_object *object)
return 0;
}
-
/*
* allocate a proglist entry for a new binary
* so that it is available for libraries to reference
@@ -839,7 +790,6 @@ elf_copy_syms(struct symcache_noflag *tcache, struct symcache_noflag *scache,
if (scache[i].obj == NULL)
continue;
-
if (tcache[i].obj != NULL) {
lib_prog_ref = (obj != prog && scache[i].obj == prog);
if (scache[i].obj != tcache[i].obj || lib_prog_ref) {
@@ -895,7 +845,7 @@ insert_sym_objcache(struct elf_object *obj, int idx,
if (flags)
tcache = objarray[obj->dyn.null].pltsymcache;
- else
+ else
tcache = objarray[obj->dyn.null].symcache;
if (tcache[idx].obj != NULL) {
@@ -961,7 +911,6 @@ add_fixup_prog(struct elf_object *prog, struct elf_object *obj, int idx,
pl = objarray[prog->dyn.null].proglist;
-
libidx = -1;
for (i = 0; i < pl->nobj; i++) {
if (pl->libmap[0][i] == obj->dyn.null) {
@@ -974,7 +923,6 @@ add_fixup_prog(struct elf_object *prog, struct elf_object *obj, int idx,
return;
}
-
/* have to check for duplicate patches */
for (i = 0; i < pl->fixupcnt[libidx]; i++) {
if (pl->fixup[libidx][i].sym == idx)
@@ -987,10 +935,9 @@ add_fixup_prog(struct elf_object *prog, struct elf_object *obj, int idx,
ref_obj->dyn.strtab + ref_sym->st_name,
pl->fixupcnt[libidx]);
-
if (pl->fixupcntalloc[libidx] < pl->fixupcnt[libidx] + 1) {
- pl->fixupcntalloc[libidx] += 16;
- pl->fixup[libidx] = realloc(pl->fixup[libidx],
+ pl->fixupcntalloc[libidx] += 16;
+ pl->fixup[libidx] = realloc(pl->fixup[libidx],
sizeof (struct fixup) * pl->fixupcntalloc[libidx]);
if (pl->fixup[libidx] == NULL) {
printf("realloc fixup, out of memory\n");
@@ -1254,7 +1201,6 @@ elf_reloc(struct elf_object *object)
struct symcache_noflag *symcache;
struct symcache_noflag *pltsymcache;
-
numrel = object->dyn.relsz / sizeof(Elf_Rel);
#ifdef DEBUG1
printf("rel relocations: %d\n", numrel);
@@ -1424,7 +1370,7 @@ elf_add_object_curbin_list(struct elf_object *object)
ol = xmalloc(sizeof (struct objlist));
ol->object = object;
TAILQ_INSERT_TAIL(&(curbin->curbin_list), ol, list);
- if ( load_object == NULL)
+ if (load_object == NULL)
load_object = object;
ol->load_prog = load_object;
@@ -1688,7 +1634,7 @@ elf_prep_bin_prebind(struct proglist *pl)
}
pl->libmapcnt[i] = objarray[idxtolib[i]].numlibs;
- pl->libmap[i] = xcalloc( objarray[idxtolib[i]].numlibs,
+ pl->libmap[i] = xcalloc(objarray[idxtolib[i]].numlibs,
sizeof(u_int32_t));
if (i != 0) {
for (j = 0; j < objarray[idxtolib[i]].numlibs; j++) {
@@ -1710,11 +1656,11 @@ elf_prep_bin_prebind(struct proglist *pl)
free(nameidx);
free(nametab);
free(libmap);
-
return ret;
}
int64_t prebind_blocks;
+
int
elf_write_lib(struct elf_object *object, struct nameidx *nameidx,
char *nametab, int nametablen, int numlibs,
@@ -1723,16 +1669,13 @@ elf_write_lib(struct elf_object *object, struct nameidx *nameidx,
struct symcachetab *symcachetab, int symcache_cnt,
struct symcachetab *pltsymcachetab, int pltsymcache_cnt)
{
- off_t base_offset;
+ u_int32_t footer_offset, *maptab = NULL;
+ u_int32_t next_start, *fixuptab = NULL;
struct prebind_footer footer;
struct stat ifstat;
- int fd;
- u_int32_t next_start;
- u_int32_t *fixuptab = NULL;
- u_int32_t *maptab = NULL;
- u_int32_t footer_offset;
- int i;
+ off_t base_offset;
size_t len;
+ int fd, i;
/* open the file */
fd = open(object->load_name, O_RDWR);
@@ -1798,21 +1741,20 @@ elf_write_lib(struct elf_object *object, struct nameidx *nameidx,
next_start += 2*nfixup * sizeof(u_int32_t);
footer.fixupcnt_idx = next_start;
next_start += 2*nfixup * sizeof(u_int32_t);
- fixuptab = xcalloc( 2*nfixup, sizeof(u_int32_t));
- for ( i = 0; i < 2*nfixup; i++) {
+ fixuptab = xcalloc(2*nfixup, sizeof(u_int32_t));
+ for (i = 0; i < 2*nfixup; i++) {
fixuptab[i] = next_start;
next_start += fixupcnt[i] * sizeof(struct fixup);
}
footer.libmap_idx = next_start;
next_start += 2*nfixup * sizeof(u_int32_t);
- maptab = xcalloc( 2*nfixup, sizeof(u_int32_t));
+ maptab = xcalloc(2*nfixup, sizeof(u_int32_t));
maptab[0] = next_start;
for (i = 1; i < nfixup; i++) {
maptab[i] = next_start;
next_start += libmapcnt[i] * sizeof(u_int32_t);
}
-
}
footer.nametab_idx = next_start;
next_start += nametablen;
@@ -2153,15 +2095,11 @@ copy_oldsymcache(int objidx, void *prebind_map)
struct elf_object *tobj;
struct symcache_noflag *tcache;
struct symcachetab *symcache;
- int i, j;
- int found;
- char *c;
+ int i, j, found, *idxtolib;
+ char *c, *nametab;
u_int32_t offset;
u_int32_t *poffset;
struct nameidx *nameidx;
- char *nametab;
- int *idxtolib;
-
object = objarray[objidx].obj;
@@ -2224,30 +2162,3 @@ done:
free (idxtolib);
/* munmap(prebind_map, size);*/
}
-
-void *
-xmalloc(size_t size)
-{
- void *ret;
-
- ret = malloc(size);
- if (ret == NULL) {
- printf("unable to allocate memory\n");
- exit (20);
- }
- return ret;
-}
-
-void *
-xcalloc(size_t nmemb, size_t size)
-{
- void *ret;
-
- ret = calloc(nmemb, size);
- if (ret == NULL) {
- printf("unable to allocate memory\n");
- abort();
- exit (20);
- }
- return ret;
-}
diff --git a/libexec/ld.so/ldconfig/prebind.h b/libexec/ld.so/ldconfig/prebind.h
new file mode 100644
index 00000000000..2cfa5e7d591
--- /dev/null
+++ b/libexec/ld.so/ldconfig/prebind.h
@@ -0,0 +1,64 @@
+/* $OpenBSD: prebind.h,v 1.1 2006/05/12 23:20:52 deraadt Exp $ */
+/*
+ * Copyright (c) 2006 Dale Rahn <drahn@dalerahn.com>
+ *
+ * Permission to use, copy, modify, and distribute this software for any
+ * purpose with or without fee is hereby granted, provided that the above
+ * copyright notice and this permission notice appear in all copies.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
+ * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
+ * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
+ * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
+ * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
+ * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
+ * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
+ */
+
+#define PREBIND_VERSION 2
+struct prebind_footer {
+ off_t prebind_base;
+ u_int32_t nameidx_idx;
+ u_int32_t symcache_idx;
+ u_int32_t pltsymcache_idx;
+ u_int32_t fixup_idx;
+ u_int32_t nametab_idx;
+ u_int32_t fixupcnt_idx;
+ u_int32_t libmap_idx;
+
+ u_int32_t symcache_cnt;
+ u_int32_t pltsymcache_cnt;
+ u_int32_t fixup_cnt;
+ u_int32_t numlibs;
+ u_int32_t prebind_size;
+
+ u_int32_t id0;
+ u_int32_t id1;
+ /* do not modify or add fields below this point in the struct */
+ off_t orig_size;
+ u_int32_t prebind_version;
+ char bind_id[4];
+#define BIND_ID0 'P'
+#define BIND_ID1 'R'
+#define BIND_ID2 'E'
+#define BIND_ID3 'B'
+};
+
+
+struct nameidx {
+ u_int32_t name;
+ u_int32_t id0;
+ u_int32_t id1;
+};
+
+struct symcachetab {
+ u_int32_t idx;
+ u_int32_t obj_idx;
+ u_int32_t sym_idx;
+};
+
+struct fixup {
+ u_int32_t sym;
+ u_int32_t obj_idx;
+ u_int32_t sym_idx;
+};
diff --git a/libexec/ld.so/ldconfig/prebind_delete.c b/libexec/ld.so/ldconfig/prebind_delete.c
index ddcad2c9dc5..b5fa6a3cf03 100644
--- a/libexec/ld.so/ldconfig/prebind_delete.c
+++ b/libexec/ld.so/ldconfig/prebind_delete.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: prebind_delete.c,v 1.2 2006/05/11 22:19:23 deraadt Exp $ */
+/* $OpenBSD: prebind_delete.c,v 1.3 2006/05/12 23:20:52 deraadt Exp $ */
/*
* Copyright (c) 2006 Dale Rahn <drahn@dalerahn.com>
@@ -19,6 +19,7 @@
#include <sys/types.h>
#include <sys/mman.h>
#include <sys/exec_elf.h>
+#include <elf_abi.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <stdlib.h>
@@ -30,18 +31,20 @@
#define BUFSZ (256 * 1024)
-int strip_prebind(char *file, int verbose);
-int prebind_remove_load_section(int fd, char *name, int verbose);
+int strip_prebind(char *file);
+int prebind_remove_load_section(int fd, char *name);
int prebind_newfile(int fd, char *name, struct stat *st,
- struct prebind_footer *footer, int verbose);
+ struct prebind_footer *footer);
+
+extern int verbose;
int
-prebind_delete(char **argv, int verbose)
+prebind_delete(char **argv)
{
extern char *__progname;
while (*argv) {
- if (strip_prebind(*argv, verbose) == -1)
+ if (strip_prebind(*argv) == -1)
return (1);
argv++;
}
@@ -49,7 +52,7 @@ prebind_delete(char **argv, int verbose)
}
int
-strip_prebind(char *file, int verbose)
+strip_prebind(char *file)
{
struct prebind_footer footer;
extern char *__progname;
@@ -83,9 +86,9 @@ strip_prebind(char *file, int verbose)
}
if (rdonly) {
- fd = prebind_newfile(fd, file, &st, &footer, verbose);
+ fd = prebind_newfile(fd, file, &st, &footer);
} else {
- prebind_remove_load_section(fd, file, verbose);
+ prebind_remove_load_section(fd, file);
ftruncate(fd, footer.orig_size);
}
@@ -100,7 +103,7 @@ done:
}
int
-prebind_remove_load_section(int fd, char *name, int verbose)
+prebind_remove_load_section(int fd, char *name)
{
Elf_Ehdr *ehdr;
Elf_Phdr *phdr;
@@ -141,7 +144,7 @@ done:
int
prebind_newfile(int infd, char *name, struct stat *st,
- struct prebind_footer *footer, int verbose)
+ struct prebind_footer *footer)
{
struct timeval tv[2];
char *newname, *buf;
@@ -188,7 +191,7 @@ prebind_newfile(int infd, char *name, struct stat *st,
free(buf);
/* now back track, and delete the header */
- if (prebind_remove_load_section(outfd, newname, verbose) == -1)
+ if (prebind_remove_load_section(outfd, newname) == -1)
goto fail;
if (ftruncate(outfd, footer->orig_size) == -1)
goto fail;
diff --git a/libexec/ld.so/prebind/prebind_struct.h b/libexec/ld.so/ldconfig/prebind_struct.h
index 31fb20e7ead..42a64bb868d 100644
--- a/libexec/ld.so/prebind/prebind_struct.h
+++ b/libexec/ld.so/ldconfig/prebind_struct.h
@@ -1,4 +1,4 @@
-/* $OpenBSD: prebind_struct.h,v 1.5 2006/05/12 16:37:59 drahn Exp $ */
+/* $OpenBSD: prebind_struct.h,v 1.1 2006/05/12 23:20:53 deraadt Exp $ */
/*
* Copyright (c) 2006 Dale Rahn <drahn@dalerahn.com>
*
@@ -76,10 +76,12 @@ void elf_fixup_prog_load(int fd, struct prebind_footer *footer,
void elf_dump_footer(struct prebind_footer *footer);
extern int verbose;
+extern int merge;
+
extern int64_t prebind_blocks;
extern struct elf_object *load_object;
struct elf_object *elf_lookup_object(const char *name);
-struct elf_object * load_file(const char *filename, int objtype);
+struct elf_object *load_file(const char *filename, int objtype);
void elf_load_existing_prebind(struct elf_object *object, int fd);
diff --git a/libexec/ld.so/prebind/sod.c b/libexec/ld.so/ldconfig/sod.c
index f92213cf867..d3383ee7b14 100644
--- a/libexec/ld.so/prebind/sod.c
+++ b/libexec/ld.so/ldconfig/sod.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: sod.c,v 1.1 2006/05/03 16:10:52 drahn Exp $ */
+/* $OpenBSD: sod.c,v 1.1 2006/05/12 23:20:53 deraadt Exp $ */
/*
* Copyright (c) 1993 Paul Kranenburg
diff --git a/libexec/ld.so/prebind/Makefile b/libexec/ld.so/prebind/Makefile
deleted file mode 100644
index fefaf2ee57b..00000000000
--- a/libexec/ld.so/prebind/Makefile
+++ /dev/null
@@ -1,18 +0,0 @@
-# $OpenBSD: Makefile,v 1.2 2006/05/08 20:34:36 deraadt Exp $
-
-SRCS= prebind.c sod.c debug.c objarray.c
-.if (${MACHINE} == "mips64")
-NOPROG=
-.else
-PROG= prebind
-.endif
-MAN= prebind.8
-
-BINDIR= /usr/sbin
-
-CFLAGS += -Wall -ggdb
-CFLAGS += -I${.CURDIR}/..
-
-BINDIR= /usr/sbin
-
-.include <bsd.prog.mk>