xref: /illumos-gate/usr/src/cmd/sgs/librtld/common/_librtld.h (revision 2a8bcb4efb45d99ac41c94a75c396b362c414f7f)
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 2006 Sun Microsystems, Inc.  All rights reserved.
24  * Use is subject to license terms.
25  */
26 
27 #ifndef	__LIBRTLD_H
28 #define	__LIBRTLD_H
29 
30 #include <libelf.h>
31 #include <rtld.h>
32 #include <machdep.h>
33 
34 #ifdef	__cplusplus
35 extern "C" {
36 #endif
37 
38 
39 /*
40  * Define a cache structure that is used to retain all elf section information.
41  */
42 typedef struct cache {
43 	int		c_flags;
44 	Elf_Scn		*c_scn;
45 	Shdr		*c_shdr;
46 	Elf_Data	*c_data;
47 	char		*c_name;
48 	void		*c_info;
49 } Cache;
50 
51 #define	FLG_C_EXCLUDE	1		/* exclude section from output image */
52 #define	FLG_C_HEAP	2		/* heap section (addition) */
53 #define	FLG_C_RELOC	3		/* relocation section requiring */
54 					/*	modification */
55 #define	FLG_C_SHSTR	4		/* section header string table */
56 #define	FLG_C_END	5		/* null terminating section marker */
57 
58 
59 /*
60  * Define a structure for maintaining relocation information.  During the first
61  * pass through an input files relocation records, counts are maintained of the
62  * number of relocations to recreate in the output image.  The intent is to
63  * localize any remaining relocation records.  The relocation structure
64  * indicates the actions that must be performed on the output images relocation
65  * information.
66  */
67 typedef struct reloc {
68 	int		r_flags;
69 	Xword		r_pltndx;	/* pltndx if a JMP relocation */
70 	Addr		r_value;	/* value to apply to relocation */
71 	unsigned long	r_size;		/* size (used for copy relocations) */
72 	const char	*r_name;		/* relocation symbol */
73 } Reloc;
74 
75 #define	FLG_R_UNDO	0x01		/* undo any relocation offset value */
76 #define	FLG_R_CLR	0x02		/* clear the relocation record */
77 #define	FLG_R_INC	0x04		/* increment the relocation offset */
78 					/*	(uses new fixed addr) */
79 #define	FLG_R_APPLY	0x08		/* apply the relocation */
80 
81 
82 /*
83  * Define any local prototypes.
84  */
85 extern	void	apply_reloc(void *, Reloc *, const char *, uchar_t *, Rt_map *);
86 extern	void	clear_reloc(void *);
87 extern	int	count_reloc(Cache *, Cache *, Rt_map *, int, Addr, Xword *,
88 		    Xword *, Xword *, Alist *);
89 extern	void	inc_reloc(void *, void *, Reloc *, uchar_t *, uchar_t *);
90 extern	int	syminfo(Cache *, Alist **);
91 extern	void	undo_reloc(void *, uchar_t *, uchar_t *, Reloc *);
92 extern	int	update_dynamic(Cache *, Cache *, Rt_map *, int, Addr, Off,
93 		    const char *, Xword, Xword, Xword, Xword, Xword);
94 extern	void	update_reloc(Cache *, Cache *, Cache *, const char *,
95 		    Rt_map *, Rel **, Rel **, Rel **);
96 extern	void	update_sym(Cache *, Cache *, Addr, Half, Addr);
97 
98 #ifdef	__cplusplus
99 }
100 #endif
101 
102 #endif /* __LIBRTLD_H */
103