xref: /netbsd-src/include/link_aout.h (revision 38023541164cff097d5fadec63134189b1453b8c)
1 /*
2  * RRS section definitions.
3  * Nomenclature and, more importantly, the layout of the various
4  * data structures defined in this header file are borrowed from
5  * Sun Microsystems' original <link.h>, so we can provide compatibility
6  * with the SunOS 4.x shared library scheme.
7  *
8  *	$Id: link_aout.h,v 1.2 1993/10/22 21:04:19 pk Exp $
9  *		(derived from: @(#)link.h 1.6 88/08/19 SMI
10  *		Copyright (c) 1987 by Sun Microsystems, Inc.)
11  */
12 
13 #ifndef _LINK_H_
14 #define _LINK_H_
15 
16 /*
17  * A `link_object' structure descibes a shared object that is needed
18  * to complete the link edit process of the object containing it.
19  * A list of such objects (chained through `lo_next') is pointed at
20  * by `ld_need' in the link_dynamic_2 structure.
21  */
22 
23 struct link_object {
24 	long	lo_name;		/* name (relative to load address) */
25 	u_int	lo_library : 1,		/* searched for by library rules */
26 		lo_unused : 31;
27 	short	lo_major;		/* major version number */
28 	short	lo_minor;		/* minor version number */
29 	long	lo_next;		/* next one (often relative) */
30 };
31 
32 /*
33  * `link_maps' are used by the run-time link editor (ld.so) to keep
34  * track of all shared objects loaded into a process' address space.
35  * These structures are only used at run-time and do not occur within
36  * the text or data segment of an executable or shared library.
37  */
38 struct link_map {
39 	caddr_t	lm_addr;		/* address at which object mapped */
40 	char 	*lm_name;		/* full name of loaded object */
41 	struct	link_map *lm_next;	/* next object in map */
42 	struct	link_object *lm_lop;	/* link object that got us here */
43 	caddr_t lm_lob;			/* base address for said link object */
44 	u_int	lm_rwt : 1;		/* text is read/write */
45 	struct	link_dynamic *lm_ld;	/* dynamic structure */
46 	caddr_t	lm_lpd;			/* loader private data */
47 };
48 
49 /*
50  * Symbol description with size. This is simply an `nlist' with
51  * one field (nz_size) added.
52  * Used to convey size information on items in the data segment
53  * of shared objects. An array of these live in the shared object's
54  * text segment and is address by the `ld_symbols' field.
55  */
56 struct nzlist {
57 	struct nlist	nlist;
58 	u_long		nz_size;
59 #define nz_un		nlist.n_un
60 #define nz_strx		nlist.n_un.n_strx
61 #define nz_name		nlist.n_un.n_name
62 #define nz_type		nlist.n_type
63 #define nz_value	nlist.n_value
64 #define nz_desc		nlist.n_desc
65 #define nz_other	nlist.n_other
66 };
67 
68 /*
69  * The `link_dynamic_2' structure contains offsets to various data
70  * structures needed to do run-time relocation.
71  */
72 struct link_dynamic_2 {
73 	struct	link_map *ld_loaded;	/* list of loaded objects */
74 	long	ld_need;		/* list of needed objects */
75 	long	ld_rules;		/* search rules for library objects */
76 	long	ld_got;			/* global offset table */
77 	long	ld_plt;			/* procedure linkage table */
78 	long	ld_rel;			/* relocation table */
79 	long	ld_hash;		/* symbol hash table */
80 	long	ld_symbols;		/* symbol table itself */
81 	long	(*ld_stab_hash)();	/* "pointer" to symbol hash function */
82 	long	ld_buckets;		/* number of hash buckets */
83 	long	ld_strings;		/* symbol strings */
84 	long	ld_str_sz;		/* size of symbol strings */
85 	long	ld_text_sz;		/* size of text area */
86 	long	ld_plt_sz;		/* size of procedure linkage table */
87 };
88 
89 /*
90  * RRS symbol hash table, addressed by `ld_hash' in link_dynamic_2
91  * Used to quickly lookup symbols of the shared object by hashing
92  * on the symbol's name. `rh_symbolnum' is the index of the symbol
93  * in the shared object's symbol list (`ld_symbols'), `rh_next' is
94  * the next symbol in the hash bucket (in case of collisions).
95  */
96 struct rrs_hash {
97 	int	rh_symbolnum;		/* symbol number */
98 	int	rh_next;		/* next hash entry */
99 };
100 
101 /*
102  * `rt_symbols' is used to keep track of run-time allocated commons
103  * and data items copied from shared objects.
104  */
105 struct rt_symbol {
106 	struct nzlist		*rt_sp;		/* the symbol */
107 	struct rt_symbol	*rt_next;	/* next in linear list */
108 	struct rt_symbol	*rt_link;	/* next in bucket */
109 	caddr_t			rt_srcaddr;	/* address of "master" copy */
110 };
111 
112 /*
113  * Debugger interface structure.
114  */
115 struct 	ld_debug {
116 	int	ldd_version;		/* version # of interface */
117 	int	ldd_in_debugger;	/* a debugger is running us */
118 	int	ldd_sym_loaded;		/* we loaded some symbols */
119 	char    *ldd_bp_addr;		/* place for ld-generated bpt */
120 	int	ldd_bp_inst;		/* instruction which was there */
121 	struct rt_symbol *ldd_cp;	/* commons we built */
122 };
123 
124 /*
125  * Entry points into ld.so - user interface to the run-time linker.
126  * (see also libdl.a)
127  */
128 struct ld_entry {
129 	int	(*dlopen)();
130 	int	(*dlclose)();
131 	int	(*dlsym)();
132 };
133 
134 /*
135  * This is the structure pointed at by the __DYNAMIC symbol if an
136  * executable requires the attention of the run-time link editor.
137  * __DYNAMIC is given the value zero if no run-time linking needs to
138  * be done (it is always present in shared objects).
139  * The union `ld_un' provides for different versions of the dynamic
140  * linking mechanism (switched on by `ld_version'). The last version
141  * used by Sun is 3. We leave some room here and go to version number
142  * 8 for NetBSD, the main difference lying in the support for the
143  * `nz_list' type of symbols.
144  */
145 
146 struct	link_dynamic {
147 	int	ld_version;		/* version # of this structure */
148 	struct 	ld_debug *ldd;
149 	union {
150 		struct link_dynamic_2 *ld_2;
151 	} ld_un;
152 	struct  ld_entry *ld_entry;
153 };
154 
155 #define LD_VERSION_SUN		(3)
156 #define LD_VERSION_BSD		(8)
157 #define LD_VERSION_NZLIST_P(v)	((v) >= 8)
158 
159 #define LD_GOT(x)	((x)->ld_un.ld_2->ld_got)
160 #define LD_PLT(x)	((x)->ld_un.ld_2->ld_plt)
161 #define LD_REL(x)	((x)->ld_un.ld_2->ld_rel)
162 #define LD_SYMBOL(x)	((x)->ld_un.ld_2->ld_symbols)
163 #define LD_HASH(x)	((x)->ld_un.ld_2->ld_hash)
164 #define LD_STRINGS(x)	((x)->ld_un.ld_2->ld_strings)
165 #define LD_NEED(x)	((x)->ld_un.ld_2->ld_need)
166 #define LD_BUCKETS(x)	((x)->ld_un.ld_2->ld_buckets)
167 
168 #define LD_GOTSZ(x)	((x)->ld_un.ld_2->ld_plt - (x)->ld_un.ld_2->ld_got)
169 #define LD_RELSZ(x)	((x)->ld_un.ld_2->ld_hash - (x)->ld_un.ld_2->ld_rel)
170 #define LD_HASHSZ(x)	((x)->ld_un.ld_2->ld_symbols - (x)->ld_un.ld_2->ld_hash)
171 #define LD_STABSZ(x)	((x)->ld_un.ld_2->ld_strings - (x)->ld_un.ld_2->ld_symbols)
172 #define LD_PLTSZ(x)	((x)->ld_un.ld_2->ld_plt_sz)
173 #define LD_STRSZ(x)	((x)->ld_un.ld_2->ld_str_sz)
174 #define LD_TEXTSZ(x)	((x)->ld_un.ld_2->ld_text_sz)
175 
176 /*
177  * Interface to ld.so (see link(5))
178  */
179 struct crt_ldso {
180 	int		crt_ba;		/* Base address of ld.so */
181 	int		crt_dzfd;	/* "/dev/zero" file decriptor (SunOS) */
182 	int		crt_ldfd;	/* ld.so file descriptor */
183 	struct link_dynamic	*crt_dp;/* Main's __DYNAMIC */
184 	char		**crt_ep;	/* environment strings */
185 	caddr_t		crt_bp;		/* Breakpoint if run from debugger */
186 };
187 
188 /*
189  * Version passed from crt0 to ld.so (1st argument to _rtld()).
190  */
191 #define CRT_VERSION_SUN		1
192 #define CRT_VERSION_BSD		2
193 
194 
195 /*
196  * Maximum number of recognized shared object version numbers.
197  */
198 #define MAXDEWEY	8
199 
200 /*
201  * Header of the hints file.
202  */
203 struct hints_header {
204 	long		hh_magic;
205 #define HH_MAGIC	011421044151
206 	long		hh_version;	/* Interface version number */
207 #define LD_HINTS_VERSION_1	1
208 	long		hh_hashtab;	/* Location of hash table */
209 	long		hh_nbucket;	/* Number of buckets in hashtab */
210 	long		hh_strtab;	/* Location of strings */
211 	long		hh_strtab_sz;	/* Size of strings */
212 	long		hh_ehints;	/* End of hints (max offset in file) */
213 };
214 
215 #define HH_BADMAG(hdr)	((hdr).hh_magic != HH_MAGIC)
216 
217 /*
218  * Hash table element in hints file.
219  */
220 struct hints_bucket {
221 	/* namex and pathx are indices into the string table */
222 	int		hi_namex;		/* Library name */
223 	int		hi_pathx;		/* Full path */
224 	int		hi_dewey[MAXDEWEY];	/* The versions */
225 	int		hi_ndewey;		/* Number of version numbers */
226 #define hi_major hi_dewey[0]
227 #define hi_minor hi_dewey[1]
228 	int		hi_next;		/* Next in this bucket */
229 };
230 
231 #define _PATH_LD_HINTS		"/var/run/ld.so.hints"
232 
233 #endif /* _LINK_H_ */
234 
235