1 /* $OpenBSD: prebind_struct.h,v 1.3 2006/06/15 22:09:32 drahn Exp $ */
2 /*
3  * Copyright (c) 2006 Dale Rahn <drahn@dalerahn.com>
4  *
5  * Permission to use, copy, modify, and distribute this software for any
6  * purpose with or without fee is hereby granted, provided that the above
7  * copyright notice and this permission notice appear in all copies.
8  *
9  * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
10  * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
11  * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
12  * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
13  * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
14  * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
15  * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
16  */
17 
18 struct symcache_noflag {
19 	const elf_object_t *obj;
20 	const Elf_Sym	*sym;
21 };
22 
23 struct objlist {
24 	TAILQ_ENTRY(objlist) list;
25 	TAILQ_ENTRY(objlist) inst_list;
26 	struct elf_object *load_prog;
27 	struct elf_object *object;
28 };
29 
30 struct proglist {
31 	TAILQ_ENTRY(proglist) list;
32 	TAILQ_HEAD(, objlist) curbin_list;
33 	struct fixup **fixup;
34 	int *fixupcnt;
35 	int *fixupcntalloc;
36 	int nobj;
37 	u_int32_t **libmap;
38 	u_int32_t *libmapcnt;
39 	char	*interp;
40 };
41 extern struct proglist *curbin;
42 extern struct elf_object *load_object;
43 
44 typedef TAILQ_HEAD(, proglist) prog_list_ty;
45 typedef TAILQ_HEAD(, objlist) obj_list_ty;
46 
47 extern obj_list_ty library_list;
48 extern prog_list_ty prog_list;
49 
50 /* debug */
51 void	elf_print_curbin_list(struct proglist *bin);
52 void	elf_print_prog_list (prog_list_ty *prog_list);
53 
54 void	elf_add_object_curbin_list(struct elf_object *object);
55 
56 void	elf_copy_syms(struct symcache_noflag *tcache,
57 	    struct symcache_noflag *scache, struct elf_object *obj,
58 	    struct elf_object *prog, int nsyms);
59 int	elf_prep_lib_prebind(struct elf_object *object);
60 int	elf_prep_bin_prebind(struct proglist *pl);
61 void	elf_calc_fixups(struct proglist *pl, struct objlist *ol, int libidx);
62 int	elf_write_lib(struct elf_object *object, struct nameidx *nameidx,
63 	    char *nametab, int nametablen, int numlibs,
64 	    int nfixup, struct fixup **fixup, int *fixupcnt,
65 	    u_int32_t **libmap, int *libmapcnt,
66 	    struct symcachetab *symcachetab, int symcache_cnt,
67 	    struct symcachetab *pltsymcachetab, int pltsymcache_cnt);
68 
69 void	dump_symcachetab(struct symcachetab *symcachetab, int symcache_cnt,
70 	    struct elf_object *object, int id);
71 void	dump_info(struct elf_object *object);
72 void	elf_clear_prog_load(int fd, struct elf_object *object);
73 void	elf_fixup_prog_load(int fd, struct prebind_footer *footer,
74 	    struct elf_object *object);
75 void	elf_dump_footer(struct prebind_footer *footer);
76 
77 extern	int verbose;
78 extern	int merge;
79 extern	int safe;
80 
81 extern int64_t prebind_blocks;
82 extern struct elf_object *load_object;
83 struct elf_object *elf_lookup_object(const char *name);
84 struct elf_object *load_file(const char *filename, int objtype);
85 
86 void	elf_load_existing_prebind(struct elf_object *object, int fd);
87