xref: /onnv-gate/usr/src/lib/libbc/inc/include/link.h (revision 0:68f95e015346)
1*0Sstevel@tonic-gate /*
2*0Sstevel@tonic-gate  * CDDL HEADER START
3*0Sstevel@tonic-gate  *
4*0Sstevel@tonic-gate  * The contents of this file are subject to the terms of the
5*0Sstevel@tonic-gate  * Common Development and Distribution License, Version 1.0 only
6*0Sstevel@tonic-gate  * (the "License").  You may not use this file except in compliance
7*0Sstevel@tonic-gate  * with the License.
8*0Sstevel@tonic-gate  *
9*0Sstevel@tonic-gate  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
10*0Sstevel@tonic-gate  * or http://www.opensolaris.org/os/licensing.
11*0Sstevel@tonic-gate  * See the License for the specific language governing permissions
12*0Sstevel@tonic-gate  * and limitations under the License.
13*0Sstevel@tonic-gate  *
14*0Sstevel@tonic-gate  * When distributing Covered Code, include this CDDL HEADER in each
15*0Sstevel@tonic-gate  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
16*0Sstevel@tonic-gate  * If applicable, add the following below this CDDL HEADER, with the
17*0Sstevel@tonic-gate  * fields enclosed by brackets "[]" replaced with your own identifying
18*0Sstevel@tonic-gate  * information: Portions Copyright [yyyy] [name of copyright owner]
19*0Sstevel@tonic-gate  *
20*0Sstevel@tonic-gate  * CDDL HEADER END
21*0Sstevel@tonic-gate  */
22*0Sstevel@tonic-gate #pragma ident	"%Z%%M%	%I%	%E% SMI"
23*0Sstevel@tonic-gate 
24*0Sstevel@tonic-gate /*
25*0Sstevel@tonic-gate  * Copyright (c) 1987 by Sun Microsystems, Inc.
26*0Sstevel@tonic-gate  */
27*0Sstevel@tonic-gate 
28*0Sstevel@tonic-gate /*
29*0Sstevel@tonic-gate  * Link editor public definitions.
30*0Sstevel@tonic-gate  */
31*0Sstevel@tonic-gate 
32*0Sstevel@tonic-gate #ifndef _link_h
33*0Sstevel@tonic-gate #define _link_h
34*0Sstevel@tonic-gate 
35*0Sstevel@tonic-gate /*
36*0Sstevel@tonic-gate  * Structure describing logical name and requirements on an object
37*0Sstevel@tonic-gate  * which is to be loaded dynamically.
38*0Sstevel@tonic-gate  */
39*0Sstevel@tonic-gate struct old_link_object {
40*0Sstevel@tonic-gate 	char	*lo_name;		/* name of object */
41*0Sstevel@tonic-gate 	int	lo_library : 1,		/* searched for by library rules */
42*0Sstevel@tonic-gate 		lo_unused : 31;
43*0Sstevel@tonic-gate 	short	lo_major;		/* major version number */
44*0Sstevel@tonic-gate 	short	lo_minor;		/* minor version number */
45*0Sstevel@tonic-gate };
46*0Sstevel@tonic-gate 
47*0Sstevel@tonic-gate struct link_object {
48*0Sstevel@tonic-gate 	long	lo_name;		/* name (often relative) */
49*0Sstevel@tonic-gate 	int	lo_library : 1,		/* searched for by library rules */
50*0Sstevel@tonic-gate 		lo_unused : 31;
51*0Sstevel@tonic-gate 	short	lo_major;		/* major version number */
52*0Sstevel@tonic-gate 	short	lo_minor;		/* minor version number */
53*0Sstevel@tonic-gate 	long	lo_next;		/* next one (often relative) */
54*0Sstevel@tonic-gate };
55*0Sstevel@tonic-gate 
56*0Sstevel@tonic-gate /*
57*0Sstevel@tonic-gate  * Structure describing name and placement of dynamically loaded
58*0Sstevel@tonic-gate  * objects in a process' address space.
59*0Sstevel@tonic-gate  */
60*0Sstevel@tonic-gate struct link_map {
61*0Sstevel@tonic-gate 	caddr_t	lm_addr;		/* address at which object mapped */
62*0Sstevel@tonic-gate 	char 	*lm_name;		/* full name of loaded object */
63*0Sstevel@tonic-gate 	struct	link_map *lm_next;	/* next object in map */
64*0Sstevel@tonic-gate 	struct	link_object *lm_lop;	/* link object that got us here */
65*0Sstevel@tonic-gate 	caddr_t lm_lob;			/* base address for said link object */
66*0Sstevel@tonic-gate 	int	lm_rwt : 1;		/* text is read/write */
67*0Sstevel@tonic-gate 	struct	link_dynamic *lm_ld;	/* dynamic structure */
68*0Sstevel@tonic-gate 	caddr_t	lm_lpd;			/* loader private data */
69*0Sstevel@tonic-gate };
70*0Sstevel@tonic-gate 
71*0Sstevel@tonic-gate /*
72*0Sstevel@tonic-gate  * Version 1 of dynamic linking information.  With the exception of
73*0Sstevel@tonic-gate  * ld_loaded (determined at execution time) and ld_stab_hash (a special
74*0Sstevel@tonic-gate  * case of relocation handled at execution time), the values in this
75*0Sstevel@tonic-gate  * structure reflect offsets from the containing link_dynamic structure.
76*0Sstevel@tonic-gate  */
77*0Sstevel@tonic-gate struct link_dynamic_1 {
78*0Sstevel@tonic-gate 	struct	link_map *ld_loaded;	/* list of loaded objects */
79*0Sstevel@tonic-gate 	long	ld_need;		/* list of needed objects */
80*0Sstevel@tonic-gate 	long	ld_rules;		/* search rules for library objects */
81*0Sstevel@tonic-gate 	long	ld_got;			/* global offset table */
82*0Sstevel@tonic-gate 	long	ld_plt;			/* procedure linkage table */
83*0Sstevel@tonic-gate 	long	ld_rel;			/* relocation table */
84*0Sstevel@tonic-gate 	long	ld_hash;		/* symbol hash table */
85*0Sstevel@tonic-gate 	long	ld_stab;		/* symbol table itself */
86*0Sstevel@tonic-gate 	long	(*ld_stab_hash)();	/* "pointer" to symbol hash function */
87*0Sstevel@tonic-gate 	long	ld_buckets;		/* number of hash buckets */
88*0Sstevel@tonic-gate 	long	ld_symbols;		/* symbol strings */
89*0Sstevel@tonic-gate 	long	ld_symb_size;		/* size of symbol strings */
90*0Sstevel@tonic-gate 	long	ld_text;		/* size of text area */
91*0Sstevel@tonic-gate };
92*0Sstevel@tonic-gate 
93*0Sstevel@tonic-gate struct link_dynamic_2 {
94*0Sstevel@tonic-gate 	struct	link_map *ld_loaded;	/* list of loaded objects */
95*0Sstevel@tonic-gate 	long	ld_need;		/* list of needed objects */
96*0Sstevel@tonic-gate 	long	ld_rules;		/* search rules for library objects */
97*0Sstevel@tonic-gate 	long	ld_got;			/* global offset table */
98*0Sstevel@tonic-gate 	long	ld_plt;			/* procedure linkage table */
99*0Sstevel@tonic-gate 	long	ld_rel;			/* relocation table */
100*0Sstevel@tonic-gate 	long	ld_hash;		/* symbol hash table */
101*0Sstevel@tonic-gate 	long	ld_stab;		/* symbol table itself */
102*0Sstevel@tonic-gate 	long	(*ld_stab_hash)();	/* "pointer" to symbol hash function */
103*0Sstevel@tonic-gate 	long	ld_buckets;		/* number of hash buckets */
104*0Sstevel@tonic-gate 	long	ld_symbols;		/* symbol strings */
105*0Sstevel@tonic-gate 	long	ld_symb_size;		/* size of symbol strings */
106*0Sstevel@tonic-gate 	long	ld_text;		/* size of text area */
107*0Sstevel@tonic-gate 	long	ld_plt_sz;		/* size of procedure linkage table */
108*0Sstevel@tonic-gate };
109*0Sstevel@tonic-gate 
110*0Sstevel@tonic-gate /*
111*0Sstevel@tonic-gate  * Structure pointing to run time allocated common symbols and
112*0Sstevel@tonic-gate  * its string.
113*0Sstevel@tonic-gate  */
114*0Sstevel@tonic-gate struct rtc_symb {
115*0Sstevel@tonic-gate 	struct	nlist *rtc_sp;		/* symbol for common */
116*0Sstevel@tonic-gate 	struct	rtc_symb *rtc_next;	/* next common */
117*0Sstevel@tonic-gate };
118*0Sstevel@tonic-gate 
119*0Sstevel@tonic-gate /*
120*0Sstevel@tonic-gate  * Debugger interface structure.
121*0Sstevel@tonic-gate  */
122*0Sstevel@tonic-gate struct 	ld_debug {
123*0Sstevel@tonic-gate 	int	ldd_version;		/* version # of interface */
124*0Sstevel@tonic-gate 	int	ldd_in_debugger;	/* a debugger is running us */
125*0Sstevel@tonic-gate 	int	ldd_sym_loaded;		/* we loaded some symbols */
126*0Sstevel@tonic-gate 	char    *ldd_bp_addr;		/* place for ld-generated bpt */
127*0Sstevel@tonic-gate 	int	ldd_bp_inst;		/* instruction which was there */
128*0Sstevel@tonic-gate 	struct rtc_symb *ldd_cp;	/* commons we built */
129*0Sstevel@tonic-gate };
130*0Sstevel@tonic-gate 
131*0Sstevel@tonic-gate /*
132*0Sstevel@tonic-gate  * Structure associated with each object which may be or which requires
133*0Sstevel@tonic-gate  * execution-time link editing.  Used by the run-time linkage editor to
134*0Sstevel@tonic-gate  * identify needed objects and symbol definitions and references.
135*0Sstevel@tonic-gate  */
136*0Sstevel@tonic-gate struct 	old_link_dynamic {
137*0Sstevel@tonic-gate 	int	ld_version;		/* version # of this structure */
138*0Sstevel@tonic-gate 	union {
139*0Sstevel@tonic-gate 		struct link_dynamic_1 ld_1;
140*0Sstevel@tonic-gate 	} ld_un;
141*0Sstevel@tonic-gate 
142*0Sstevel@tonic-gate 	int	in_debugging;
143*0Sstevel@tonic-gate 	int	sym_loaded;
144*0Sstevel@tonic-gate 	char    *bp_addr;
145*0Sstevel@tonic-gate 	int	bp_inst;
146*0Sstevel@tonic-gate 	struct rtc_symb *cp; 		/* pointer to an array of runtime */
147*0Sstevel@tonic-gate 					/* allocated common symbols. */
148*0Sstevel@tonic-gate };
149*0Sstevel@tonic-gate 
150*0Sstevel@tonic-gate struct	link_dynamic {
151*0Sstevel@tonic-gate 	int	ld_version;		/* version # of this structure */
152*0Sstevel@tonic-gate 	struct 	ld_debug *ldd;
153*0Sstevel@tonic-gate 	union {
154*0Sstevel@tonic-gate 		struct link_dynamic_1 *ld_1;
155*0Sstevel@tonic-gate 		struct link_dynamic_2 *ld_2;
156*0Sstevel@tonic-gate 	} ld_un;
157*0Sstevel@tonic-gate };
158*0Sstevel@tonic-gate 
159*0Sstevel@tonic-gate #define v2 ld_un.ld_2
160*0Sstevel@tonic-gate #define v1 ld_un.ld_1
161*0Sstevel@tonic-gate 
162*0Sstevel@tonic-gate /*
163*0Sstevel@tonic-gate  * get size of relocations
164*0Sstevel@tonic-gate  */
165*0Sstevel@tonic-gate #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*0Sstevel@tonic-gate 
167*0Sstevel@tonic-gate #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*0Sstevel@tonic-gate 
169*0Sstevel@tonic-gate #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*0Sstevel@tonic-gate 
171*0Sstevel@tonic-gate #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*0Sstevel@tonic-gate 
173*0Sstevel@tonic-gate #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*0Sstevel@tonic-gate 
175*0Sstevel@tonic-gate #undef v2
176*0Sstevel@tonic-gate #undef v1
177*0Sstevel@tonic-gate 
178*0Sstevel@tonic-gate #endif /*!_link_h*/
179