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