xref: /titanic_44/usr/src/cmd/sgs/rtld/common/_elf.h (revision 1e4c938b57d1656808e4112127ff1dce3eba5314)
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 /*
23  *	Copyright (c) 1988 AT&T
24  *	  All Rights Reserved
25  *
26  * Copyright (c) 1991, 2010, Oracle and/or its affiliates. All rights reserved.
27  */
28 #ifndef	__ELF_DOT_H
29 #define	__ELF_DOT_H
30 
31 #include <sys/types.h>
32 #include <sys/mman.h>
33 #include <sgs.h>
34 #include <elf.h>
35 #include <_rtld.h>
36 
37 #ifdef	__cplusplus
38 extern "C" {
39 #endif
40 
41 /*
42  * Common extern functions for ELF file class.
43  */
44 extern	int	elf_config(Rt_map *, int);
45 extern	Rtc_obj	*elf_config_ent(const char *, Word, int, const char **);
46 extern	void	elf_config_flt(Lm_list *, const char *, const char *,
47 		    Alist **, Aliste);
48 #if	defined(__i386)
49 extern	int	elf_copy_gen(Rt_map *);
50 #endif
51 extern	int	elf_copy_reloc(char *, Sym *, Rt_map *, void *, Sym *,
52 		    Rt_map *, const void *);
53 extern	int	elf_find_sym(Slookup *, Sresult *, uint_t *, int *);
54 extern	int	elf_lazy_find_sym(Slookup *, Sresult *, uint_t *, int *);
55 extern	Rt_map	*elf_lazy_load(Rt_map *, Slookup *, uint_t, const char *,
56 		    uint_t, Grp_hdl **, int *);
57 extern	int	elf_lookup_filtee(Slookup *, Sresult *, uint_t *, uint_t,
58 		    int *);
59 extern	int	elf_mach_flags_check(Rej_desc *, Ehdr *);
60 extern	Rt_map	*elf_new_lmp(Lm_list *, Aliste, Fdesc *, Addr, size_t, void *,
61 		    Rt_map *, int *);
62 extern	Rt_map	*elf_obj_file(Lm_list *, Aliste, Rt_map *, const char *,
63 		    mmapobj_result_t *, mmapobj_result_t *, uint_t);
64 extern	Rt_map	*elf_obj_fini(Lm_list *, Rt_map *, Rt_map *, int *);
65 extern	void	elf_plt_init(void *, caddr_t);
66 #if	defined(__sparcv9)
67 extern	void	elf_plt2_init(uint_t *, Rt_map *);
68 #endif
69 extern	int	elf_reloc(Rt_map *, uint_t, int *, APlist **);
70 extern	void	elf_reloc_bad(Rt_map *, void *, uchar_t, ulong_t,
71 		    ulong_t);
72 extern	int	elf_reloc_error(Rt_map *, const char *, void *, uint_t);
73 extern	int	elf_rtld_load();
74 extern	long	elf_static_tls(Rt_map *, Sym *, void *, uchar_t, char *,
75 		    ulong_t, long);
76 extern	Fct	*elf_verify(caddr_t, size_t, Fdesc *, const char *, Rej_desc *);
77 extern	int	elf_verify_vers(const char *, Rt_map *, Rt_map *);
78 
79 /*
80  * Padinfo
81  *
82  * Used to track the which PLTpadd entries have been used and
83  * to where they are bound.
84  *
85  * NOTE: these are only currently used for SparcV9
86  */
87 typedef struct pltpadinfo {
88 	Addr	pp_addr;
89 	void	*pp_plt;
90 } Pltpadinfo;
91 
92 /*
93  * Private data for an ELF file class.
94  */
95 typedef struct _rt_elf_private {
96 	void		*e_symtab;	/* symbol table */
97 	void		*e_sunwsymtab;	/* symtab augmented with local fcns */
98 	uint_t		*e_hash;	/* hash table */
99 	char		*e_strtab;	/* string table */
100 	void		*e_reloc;	/* relocation table */
101 	uint_t		*e_pltgot;	/* addrs for procedure linkage table */
102 	void		*e_jmprel;	/* plt relocations */
103 	ulong_t		e_sunwsortent;	/* size of sunw[sym|tls]sort entry */
104 	uint_t		*e_sunwsymsort;	/* sunwsymtab indices sorted by addr */
105 	ulong_t		e_sunwsymsortsz; /* size of sunwsymtab */
106 	ulong_t		e_sunwsymsz;	/* size of e_sunwsymtab */
107 	ulong_t		e_pltrelsize;	/* size of PLT relocation entries */
108 	ulong_t		e_relsz;	/* size of relocs */
109 	ulong_t		e_relent;	/* size of base reloc entry */
110 	ulong_t		e_movesz;	/* size of movetabs */
111 	ulong_t		e_moveent;	/* size of base movetab entry */
112 	ulong_t		e_tlsstatoff;	/* TLS offset into static block */
113 	void		*e_movetab;	/* movetable address */
114 	Phdr		*e_pttls;	/* PT_TLS */
115 	Phdr		*e_ptunwind;	/* PT_SUNW_UNWIND (amd64 specific) */
116 	ulong_t		e_syment;	/* size of symtab entry */
117 	Verneed		*e_verneed;	/* versions needed by this image and */
118 	int		e_verneednum;	/*	their associated count */
119 	Verdef		*e_verdef;	/* versions defined by this image and */
120 	int		e_verdefnum;	/*	their associated count */
121 	Versym 		*e_versym;	/* Per-symbol versions */
122 	ulong_t		e_syminent;	/* syminfo entry size */
123 	void		*e_pltpad;	/* PLTpad table */
124 	void		*e_pltpadend;	/* end of PLTpad table */
125 	Syscapset	e_capset;	/* capabilities set */
126 	Capinfo		*e_capinfo;	/* symbol capabilities information */
127 	uint_t		e_capchainent;	/* size of capabilities chain entry */
128 	uint_t		e_capchainsz;	/* size of capabilities chain data */
129 } Rt_elfp;
130 
131 /*
132  * Macros for getting to linker ELF private data.
133  */
134 #define	ELFPRV(X)		((X)->rt_priv)
135 #define	SYMTAB(X)		(((Rt_elfp *)(X)->rt_priv)->e_symtab)
136 #define	SUNWSYMTAB(X)		(((Rt_elfp *)(X)->rt_priv)->e_sunwsymtab)
137 #define	HASH(X)			(((Rt_elfp *)(X)->rt_priv)->e_hash)
138 #define	STRTAB(X)		(((Rt_elfp *)(X)->rt_priv)->e_strtab)
139 #define	REL(X)			(((Rt_elfp *)(X)->rt_priv)->e_reloc)
140 #define	PLTGOT(X)		(((Rt_elfp *)(X)->rt_priv)->e_pltgot)
141 #define	MOVESZ(X)		(((Rt_elfp *)(X)->rt_priv)->e_movesz)
142 #define	MOVEENT(X)		(((Rt_elfp *)(X)->rt_priv)->e_moveent)
143 #define	MOVETAB(X)		(((Rt_elfp *)(X)->rt_priv)->e_movetab)
144 #define	JMPREL(X)		(((Rt_elfp *)(X)->rt_priv)->e_jmprel)
145 #define	SUNWSYMSZ(X)		(((Rt_elfp *)(X)->rt_priv)->e_sunwsymsz)
146 #define	PTTLS(X)		(((Rt_elfp *)(X)->rt_priv)->e_pttls)
147 #define	PTUNWIND(X)		(((Rt_elfp *)(X)->rt_priv)->e_ptunwind)
148 #define	TLSSTATOFF(X)		(((Rt_elfp *)(X)->rt_priv)->e_tlsstatoff)
149 #define	PLTRELSZ(X)		(((Rt_elfp *)(X)->rt_priv)->e_pltrelsize)
150 #define	RELSZ(X)		(((Rt_elfp *)(X)->rt_priv)->e_relsz)
151 #define	RELENT(X)		(((Rt_elfp *)(X)->rt_priv)->e_relent)
152 #define	SYMENT(X)		(((Rt_elfp *)(X)->rt_priv)->e_syment)
153 #define	VERNEED(X)		(((Rt_elfp *)(X)->rt_priv)->e_verneed)
154 #define	VERNEEDNUM(X)		(((Rt_elfp *)(X)->rt_priv)->e_verneednum)
155 #define	VERDEF(X)		(((Rt_elfp *)(X)->rt_priv)->e_verdef)
156 #define	VERDEFNUM(X)		(((Rt_elfp *)(X)->rt_priv)->e_verdefnum)
157 #define	VERSYM(X)		(((Rt_elfp *)(X)->rt_priv)->e_versym)
158 #define	SYMINENT(X)		(((Rt_elfp *)(X)->rt_priv)->e_syminent)
159 #define	PLTPAD(X)		(((Rt_elfp *)(X)->rt_priv)->e_pltpad)
160 #define	PLTPADEND(X)		(((Rt_elfp *)(X)->rt_priv)->e_pltpadend)
161 #define	SUNWSORTENT(X)		(((Rt_elfp *)(X)->rt_priv)->e_sunwsortent)
162 #define	SUNWSYMSORT(X)		(((Rt_elfp *)(X)->rt_priv)->e_sunwsymsort)
163 #define	SUNWSYMSORTSZ(X)	(((Rt_elfp *)(X)->rt_priv)->e_sunwsymsortsz)
164 #define	CAPSET(X)		(((Rt_elfp *)(X)->rt_priv)->e_capset)
165 #define	CAPINFO(X)		(((Rt_elfp *)(X)->rt_priv)->e_capinfo)
166 #define	CAPCHAINENT(X)		(((Rt_elfp *)(X)->rt_priv)->e_capchainent)
167 #define	CAPCHAINSZ(X)		(((Rt_elfp *)(X)->rt_priv)->e_capchainsz)
168 
169 /*
170  * Most of the above macros are used from ELF specific routines, however there
171  * are a couple of instances where we need to ensure the file being processed
172  * is ELF before dereferencing the macro.
173  */
174 #define	THIS_IS_ELF(X)		(FCT(X) == &elf_fct)
175 #define	THIS_IS_NOT_ELF(X)	(FCT(X) != &elf_fct)
176 
177 #ifdef	__cplusplus
178 }
179 #endif
180 
181 #endif	/* __ELF_DOT_H */
182