xref: /titanic_52/usr/src/lib/libbc/inc/include/link.h (revision 1e49577a7fcde812700ded04431b49d67cc57d6d)
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 #pragma ident	"%Z%%M%	%I%	%E% SMI"
23 
24 /*
25  * Copyright (c) 1987 by Sun Microsystems, Inc.
26  */
27 
28 /*
29  * Link editor public definitions.
30  */
31 
32 #ifndef _link_h
33 #define _link_h
34 
35 /*
36  * Structure describing logical name and requirements on an object
37  * which is to be loaded dynamically.
38  */
39 struct old_link_object {
40 	char	*lo_name;		/* name of object */
41 	int	lo_library : 1,		/* searched for by library rules */
42 		lo_unused : 31;
43 	short	lo_major;		/* major version number */
44 	short	lo_minor;		/* minor version number */
45 };
46 
47 struct link_object {
48 	long	lo_name;		/* name (often relative) */
49 	int	lo_library : 1,		/* searched for by library rules */
50 		lo_unused : 31;
51 	short	lo_major;		/* major version number */
52 	short	lo_minor;		/* minor version number */
53 	long	lo_next;		/* next one (often relative) */
54 };
55 
56 /*
57  * Structure describing name and placement of dynamically loaded
58  * objects in a process' address space.
59  */
60 struct link_map {
61 	caddr_t	lm_addr;		/* address at which object mapped */
62 	char 	*lm_name;		/* full name of loaded object */
63 	struct	link_map *lm_next;	/* next object in map */
64 	struct	link_object *lm_lop;	/* link object that got us here */
65 	caddr_t lm_lob;			/* base address for said link object */
66 	int	lm_rwt : 1;		/* text is read/write */
67 	struct	link_dynamic *lm_ld;	/* dynamic structure */
68 	caddr_t	lm_lpd;			/* loader private data */
69 };
70 
71 /*
72  * Version 1 of dynamic linking information.  With the exception of
73  * ld_loaded (determined at execution time) and ld_stab_hash (a special
74  * case of relocation handled at execution time), the values in this
75  * structure reflect offsets from the containing link_dynamic structure.
76  */
77 struct link_dynamic_1 {
78 	struct	link_map *ld_loaded;	/* list of loaded objects */
79 	long	ld_need;		/* list of needed objects */
80 	long	ld_rules;		/* search rules for library objects */
81 	long	ld_got;			/* global offset table */
82 	long	ld_plt;			/* procedure linkage table */
83 	long	ld_rel;			/* relocation table */
84 	long	ld_hash;		/* symbol hash table */
85 	long	ld_stab;		/* symbol table itself */
86 	long	(*ld_stab_hash)();	/* "pointer" to symbol hash function */
87 	long	ld_buckets;		/* number of hash buckets */
88 	long	ld_symbols;		/* symbol strings */
89 	long	ld_symb_size;		/* size of symbol strings */
90 	long	ld_text;		/* size of text area */
91 };
92 
93 struct link_dynamic_2 {
94 	struct	link_map *ld_loaded;	/* list of loaded objects */
95 	long	ld_need;		/* list of needed objects */
96 	long	ld_rules;		/* search rules for library objects */
97 	long	ld_got;			/* global offset table */
98 	long	ld_plt;			/* procedure linkage table */
99 	long	ld_rel;			/* relocation table */
100 	long	ld_hash;		/* symbol hash table */
101 	long	ld_stab;		/* symbol table itself */
102 	long	(*ld_stab_hash)();	/* "pointer" to symbol hash function */
103 	long	ld_buckets;		/* number of hash buckets */
104 	long	ld_symbols;		/* symbol strings */
105 	long	ld_symb_size;		/* size of symbol strings */
106 	long	ld_text;		/* size of text area */
107 	long	ld_plt_sz;		/* size of procedure linkage table */
108 };
109 
110 /*
111  * Structure pointing to run time allocated common symbols and
112  * its string.
113  */
114 struct rtc_symb {
115 	struct	nlist *rtc_sp;		/* symbol for common */
116 	struct	rtc_symb *rtc_next;	/* next common */
117 };
118 
119 /*
120  * Debugger interface structure.
121  */
122 struct 	ld_debug {
123 	int	ldd_version;		/* version # of interface */
124 	int	ldd_in_debugger;	/* a debugger is running us */
125 	int	ldd_sym_loaded;		/* we loaded some symbols */
126 	char    *ldd_bp_addr;		/* place for ld-generated bpt */
127 	int	ldd_bp_inst;		/* instruction which was there */
128 	struct rtc_symb *ldd_cp;	/* commons we built */
129 };
130 
131 /*
132  * Structure associated with each object which may be or which requires
133  * execution-time link editing.  Used by the run-time linkage editor to
134  * identify needed objects and symbol definitions and references.
135  */
136 struct 	old_link_dynamic {
137 	int	ld_version;		/* version # of this structure */
138 	union {
139 		struct link_dynamic_1 ld_1;
140 	} ld_un;
141 
142 	int	in_debugging;
143 	int	sym_loaded;
144 	char    *bp_addr;
145 	int	bp_inst;
146 	struct rtc_symb *cp; 		/* pointer to an array of runtime */
147 					/* allocated common symbols. */
148 };
149 
150 struct	link_dynamic {
151 	int	ld_version;		/* version # of this structure */
152 	struct 	ld_debug *ldd;
153 	union {
154 		struct link_dynamic_1 *ld_1;
155 		struct link_dynamic_2 *ld_2;
156 	} ld_un;
157 };
158 
159 #define v2 ld_un.ld_2
160 #define v1 ld_un.ld_1
161 
162 /*
163  * get size of relocations
164  */
165 #define GETGOTSZ(x) (x->ld_version < 2 ? ((struct old_link_dynamic *) x)->v1.ld_plt - ((struct old_link_dynamic *) x)->v1.ld_got : (x)->v2->ld_plt - (x)->v2->ld_got)
166 
167 #define GETPLTSZ(x) (x->ld_version < 2 ? ((struct old_link_dynamic *) x)->v1.ld_rel - ((struct old_link_dynamic *) x)->v1.ld_plt : (x)->v2->ld_rel - (x)->v2->ld_plt)
168 
169 #define GETRELSZ(x) (x->ld_version < 2 ? ((struct old_link_dynamic *) x)->v1.ld_hash - ((struct old_link_dynamic *) x)->v1.ld_rel : (x)->v2->ld_hash - (x)->v2->ld_rel)
170 
171 #define GETHASHSZ(x) (x->ld_version < 2 ? ((struct old_link_dynamic *) x)->v1.ld_stab - ((struct old_link_dynamic *) x)->v1.ld_hash : (x)->v2->ld_stab - (x)->v2->ld_hash)
172 
173 #define GETSTABSZ(x) (x->ld_version < 2 ? ((struct old_link_dynamic *) x)->v1.ld_symbols - ((struct old_link_dynamic *) x)->v1.ld_stab : (x)->v2->ld_symbols - (x)->v2->ld_stab)
174 
175 #undef v2
176 #undef v1
177 
178 #endif /*!_link_h*/
179