xref: /titanic_51/usr/src/cmd/sgs/rtld/common/_elf.h (revision a776e90690d98f629ab57f6493ff5949af9d65bd)
1 /*
2  * CDDL HEADER START
3  *
4  * The contents of this file are subject to the terms of the
5  * Common Development and Distribution License (the "License").
6  * You may not use this file except in compliance with the License.
7  *
8  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
9  * or http://www.opensolaris.org/os/licensing.
10  * See the License for the specific language governing permissions
11  * and limitations under the License.
12  *
13  * When distributing Covered Code, include this CDDL HEADER in each
14  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
15  * If applicable, add the following below this CDDL HEADER, with the
16  * fields enclosed by brackets "[]" replaced with your own identifying
17  * information: Portions Copyright [yyyy] [name of copyright owner]
18  *
19  * CDDL HEADER END
20  */
21 /*
22  *	Copyright (c) 1988 AT&T
23  *	  All Rights Reserved
24  *
25  *
26  * Copyright 2008 Sun Microsystems, Inc.  All rights reserved.
27  * Use is subject to license terms.
28  */
29 
30 #ifndef	__ELF_DOT_H
31 #define	__ELF_DOT_H
32 
33 #pragma ident	"%Z%%M%	%I%	%E% SMI"
34 
35 #include <sys/types.h>
36 #include <elf.h>
37 #include <_rtld.h>
38 
39 #ifdef	__cplusplus
40 extern "C" {
41 #endif
42 
43 /*
44  * Common extern functions for ELF file class.
45  */
46 extern	int	elf_reloc(Rt_map *, uint_t, int *);
47 extern	int	elf_reloc_error(Rt_map *, const char *, void *, uint_t);
48 extern	void	elf_plt_init(void *, caddr_t);
49 extern	int	elf_set_prot(Rt_map *, int);
50 extern	Rt_map	*elf_obj_file(Lm_list *, Aliste, const char *, int);
51 extern	Rt_map	*elf_obj_fini(Lm_list *, Rt_map *, int *);
52 extern	int	elf_copy_reloc(char *, Sym *, Rt_map *, void *, Sym *,
53 		    Rt_map *, const void *);
54 extern	Sym	*elf_find_sym(Slookup *, Rt_map **, uint_t *, int *);
55 extern	Sym	*elf_lazy_find_sym(Slookup *, Rt_map **, uint_t *, int *);
56 extern	Rt_map	*elf_lazy_load(Rt_map *, Slookup *, uint_t, const char *,
57 		    int *);
58 extern	Sym	*elf_lookup_filtee(Slookup *, Rt_map **, uint_t *, uint_t,
59 		    int *);
60 extern	Rt_map	*elf_new_lm(Lm_list *, const char *, const char *, Dyn *,
61 		    ulong_t, ulong_t, Aliste, ulong_t, ulong_t, ulong_t,
62 		    ulong_t, Mmap *, uint_t, int *);
63 extern	int	elf_rtld_load();
64 
65 #if	defined(__sparcv9)
66 extern	void	elf_plt2_init(uint_t *, Rt_map *);
67 #endif
68 
69 #if	defined(__i386)
70 extern	ulong_t	elf_reloc_relacount(ulong_t, ulong_t, ulong_t, ulong_t);
71 extern	int	elf_copy_gen(Rt_map *);
72 #endif
73 
74 /*
75  * Padinfo
76  *
77  * Used to track the which PLTpadd entries have been used and
78  * to where they are bound.
79  *
80  * NOTE: these are only currently used for SparcV9
81  */
82 typedef struct pltpadinfo {
83 	Addr	pp_addr;
84 	void	*pp_plt;
85 } Pltpadinfo;
86 
87 /*
88  * Private data for an ELF file class.
89  */
90 typedef struct _rt_elf_private {
91 	void		*e_symtab;	/* symbol table */
92 	void		*e_sunwsymtab;	/* symtab augmented with local fcns */
93 	uint_t		*e_hash;	/* hash table */
94 	char		*e_strtab;	/* string table */
95 	void		*e_reloc;	/* relocation table */
96 	uint_t		*e_pltgot;	/* addrs for procedure linkage table */
97 	void		*e_pltreserve;	/* ia64: DT_IA_64_PLTRESERVE */
98 	void		*e_dynplt;	/* dynamic plt table - used by prof */
99 	void		*e_jmprel;	/* plt relocations */
100 	ulong_t		e_sunwsortent;	/* size of sunw[sym|tls]sort entry */
101 	uint_t		*e_sunwsymsort;	/* sunwsymtab indices sorted by addr */
102 	ulong_t		e_sunwsymsortsz; /* size of sunwsymtab */
103 	ulong_t		e_sunwsymsz;	/* size of e_sunwsymtab */
104 	ulong_t		e_pltrelsize;	/* size of PLT relocation entries */
105 	ulong_t		e_relsz;	/* size of relocs */
106 	ulong_t		e_relent;	/* size of base reloc entry */
107 	ulong_t		e_movesz;	/* size of movetabs */
108 	ulong_t		e_moveent;	/* size of base movetab entry */
109 	ulong_t		e_tlsstatoff;	/* TLS offset into static block */
110 	void		*e_movetab;	/* movetable address */
111 	Phdr		*e_sunwbss;	/* program header for SUNWBSS */
112 	Phdr		*e_pttls;	/* PT_TLS */
113 	Phdr		*e_ptunwind;	/* PT_SUNW_UNWIND (amd64 specific) */
114 	ulong_t		e_syment;	/* size of symtab entry */
115 	ulong_t		e_entry;	/* entry point for file */
116 	Verneed		*e_verneed;	/* versions needed by this image and */
117 	int		e_verneednum;	/*	their associated count */
118 	Verdef		*e_verdef;	/* versions defined by this image and */
119 	int		e_verdefnum;	/*	their associated count */
120 	Versym 		*e_versym;	/* Per-symbol versions */
121 	ulong_t		e_syminent;	/* syminfo entry size */
122 	void		*e_pltpad;	/* PLTpad table */
123 	void		*e_pltpadend;	/* end of PLTpad table */
124 } Rt_elfp;
125 
126 /*
127  * Macros for getting to linker ELF private data.
128  */
129 #define	ELFPRV(X)		((X)->rt_priv)
130 #define	SYMTAB(X)		(((Rt_elfp *)(X)->rt_priv)->e_symtab)
131 #define	SUNWSYMTAB(X)		(((Rt_elfp *)(X)->rt_priv)->e_sunwsymtab)
132 #define	HASH(X)			(((Rt_elfp *)(X)->rt_priv)->e_hash)
133 #define	STRTAB(X)		(((Rt_elfp *)(X)->rt_priv)->e_strtab)
134 #define	REL(X)			(((Rt_elfp *)(X)->rt_priv)->e_reloc)
135 #define	PLTGOT(X)		(((Rt_elfp *)(X)->rt_priv)->e_pltgot)
136 #define	MOVESZ(X)		(((Rt_elfp *)(X)->rt_priv)->e_movesz)
137 #define	MOVEENT(X)		(((Rt_elfp *)(X)->rt_priv)->e_moveent)
138 #define	MOVETAB(X)		(((Rt_elfp *)(X)->rt_priv)->e_movetab)
139 #define	DYNPLT(X)		(((Rt_elfp *)(X)->rt_priv)->e_dynplt)
140 #define	JMPREL(X)		(((Rt_elfp *)(X)->rt_priv)->e_jmprel)
141 #define	SUNWSYMSZ(X)		(((Rt_elfp *)(X)->rt_priv)->e_sunwsymsz)
142 #define	PTTLS(X)		(((Rt_elfp *)(X)->rt_priv)->e_pttls)
143 #define	PTUNWIND(X)		(((Rt_elfp *)(X)->rt_priv)->e_ptunwind)
144 #define	TLSSTATOFF(X)		(((Rt_elfp *)(X)->rt_priv)->e_tlsstatoff)
145 #define	PLTRELSZ(X)		(((Rt_elfp *)(X)->rt_priv)->e_pltrelsize)
146 #define	RELSZ(X)		(((Rt_elfp *)(X)->rt_priv)->e_relsz)
147 #define	RELENT(X)		(((Rt_elfp *)(X)->rt_priv)->e_relent)
148 #define	SYMENT(X)		(((Rt_elfp *)(X)->rt_priv)->e_syment)
149 #define	ENTRY(X)		(((Rt_elfp *)(X)->rt_priv)->e_entry)
150 #define	VERNEED(X)		(((Rt_elfp *)(X)->rt_priv)->e_verneed)
151 #define	VERNEEDNUM(X)		(((Rt_elfp *)(X)->rt_priv)->e_verneednum)
152 #define	VERDEF(X)		(((Rt_elfp *)(X)->rt_priv)->e_verdef)
153 #define	VERDEFNUM(X)		(((Rt_elfp *)(X)->rt_priv)->e_verdefnum)
154 #define	VERSYM(X)		(((Rt_elfp *)(X)->rt_priv)->e_versym)
155 #define	SUNWBSS(X)		(((Rt_elfp *)(X)->rt_priv)->e_sunwbss)
156 #define	SYMINENT(X)		(((Rt_elfp *)(X)->rt_priv)->e_syminent)
157 #define	PLTPAD(X)		(((Rt_elfp *)(X)->rt_priv)->e_pltpad)
158 #define	PLTPADEND(X)		(((Rt_elfp *)(X)->rt_priv)->e_pltpadend)
159 #define	PLTRESERVE(X)		(((Rt_elfp *)(X)->rt_priv)->e_pltreserve)
160 #define	SUNWSORTENT(X)		(((Rt_elfp *)(X)->rt_priv)->e_sunwsortent)
161 #define	SUNWSYMSORT(X)		(((Rt_elfp *)(X)->rt_priv)->e_sunwsymsort)
162 #define	SUNWSYMSORTSZ(X)	(((Rt_elfp *)(X)->rt_priv)->e_sunwsymsortsz)
163 
164 #ifdef	__cplusplus
165 }
166 #endif
167 
168 #endif	/* __ELF_DOT_H */
169