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