link_aout.h revision 13771
1152521Spjd/*
2127412Sgad * Copyright (c) 1993 Paul Kranenburg
3127412Sgad * All rights reserved.
4330449Seadler *
5330449Seadler * Redistribution and use in source and binary forms, with or without
6127412Sgad * modification, are permitted provided that the following conditions
7152518Spjd * are met:
8127412Sgad * 1. Redistributions of source code must retain the above copyright
9127412Sgad *    notice, this list of conditions and the following disclaimer.
10127412Sgad * 2. Redistributions in binary form must reproduce the above copyright
11127412Sgad *    notice, this list of conditions and the following disclaimer in the
12127412Sgad *    documentation and/or other materials provided with the distribution.
13127412Sgad * 3. All advertising materials mentioning features or use of this software
14127412Sgad *    must display the following acknowledgement:
15127412Sgad *      This product includes software developed by Paul Kranenburg.
16127412Sgad * 4. The name of the author may not be used to endorse or promote products
17127412Sgad *    derived from this software without specific prior written permission
18127412Sgad *
19127412Sgad * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
20127412Sgad * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
21127412Sgad * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
22127412Sgad * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
23127412Sgad * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
24127412Sgad * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
25127412Sgad * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
26127412Sgad * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
27127412Sgad * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
28127412Sgad * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
29127412Sgad *
30127412Sgad *	$Id: link.h,v 1.5 1995/06/27 09:52:59 dfr Exp $
31127412Sgad */
32127412Sgad
33127412Sgad/*
34127412Sgad * RRS section definitions.
35127412Sgad *
36127412Sgad * The layout of some data structures defined in this header file is
37127412Sgad * such that we can provide compatibility with the SunOS 4.x shared
38127412Sgad * library scheme.
39127412Sgad */
40127412Sgad
41127412Sgad#ifndef _LINK_H_
42127412Sgad#define _LINK_H_
43127412Sgad
44143878Spjd/*
45127425Sgad * A `Shared Object Descriptor' describes a shared object that is needed
46127412Sgad * to complete the link edit process of the object containing it.
47203802Spjd * A list of such objects (chained through `sod_next') is pointed at
48330324Seadler * by `sdt_sods' in the section_dispatch_table structure.
49127412Sgad */
50127412Sgad
51127412Sgadstruct sod {	/* Shared Object Descriptor */
52127425Sgad	long	sod_name;		/* name (relative to load address) */
53127412Sgad	u_int	sod_library  : 1,	/* Searched for by library rules */
54127412Sgad		sod_reserved : 31;
55127412Sgad	short	sod_major;		/* major version number */
56127412Sgad	short	sod_minor;		/* minor version number */
57127412Sgad	long	sod_next;		/* next sod */
58127425Sgad};
59127412Sgad
60127412Sgad/*
61127412Sgad * `Shared Object Map's are used by the run-time link editor (ld.so) to
62127412Sgad * keep track of all shared objects loaded into a process' address space.
63127412Sgad * These structures are only used at run-time and do not occur within
64132198Stjr * the text or data segment of an executable or shared library.
65287012Sjamie */
66127412Sgadstruct so_map {		/* Shared Object Map */
67127412Sgad	caddr_t		som_addr;	/* Address at which object mapped */
68127412Sgad	char 		*som_path;	/* Path to mmap'ed file */
69127412Sgad	struct so_map	*som_next;	/* Next map in chain */
70127412Sgad	struct sod	*som_sod;	/* Sod responsible for this map */
71127412Sgad	caddr_t		som_sodbase;	/* Base address of this sod */
72143874Spjd	u_int		som_write : 1;	/* Text is currently writable */
73143874Spjd	struct _dynamic	*som_dynamic;	/* _dynamic structure */
74143874Spjd	caddr_t		som_spd;	/* Private data */
75143877Spjd};
76143877Spjd
77295435Skib/*
78127425Sgad * Symbol description with size. This is simply an `nlist' with
79127412Sgad * one field (nz_size) added.
80127412Sgad * Used to convey size information on items in the data segment
81127412Sgad * of shared objects. An array of these live in the shared object's
82127412Sgad * text segment and is addressed by the `sdt_nzlist' field.
83127412Sgad */
84127412Sgadstruct nzlist {
85287012Sjamie	struct nlist	nlist;
86254134Strasz	u_long		nz_size;
87254134Strasz#define nz_un		nlist.n_un
88127412Sgad#define nz_strx		nlist.n_un.n_strx
89127412Sgad#define nz_name		nlist.n_un.n_name
90127412Sgad#define nz_type		nlist.n_type
91127412Sgad#define nz_value	nlist.n_value
92127412Sgad#define nz_desc		nlist.n_desc
93254134Strasz#define nz_other	nlist.n_other
94127412Sgad};
95127412Sgad
96127412Sgad#define N_AUX(p)	((p)->n_other & 0xf)
97127412Sgad#define N_BIND(p)	(((unsigned int)(p)->n_other >> 4) & 0xf)
98152521Spjd#define N_OTHER(r, v)	(((unsigned int)(r) << 4) | ((v) & 0xf))
99152521Spjd
100152521Spjd#define AUX_OBJECT	1
101152521Spjd#define AUX_FUNC	2
102152521Spjd/*#define BIND_LOCAL	0	not used */
103152521Spjd/*#define BIND_GLOBAL	1	not used */
104152521Spjd#define BIND_WEAK	2
105152521Spjd
106152521Spjd
107152521Spjd/*
108152521Spjd * The `section_dispatch_table' structure contains offsets to various data
109152521Spjd * structures needed to do run-time relocation.
110152521Spjd */
111152521Spjdstruct section_dispatch_table {
112152521Spjd	struct so_map *sdt_loaded;	/* List of loaded objects */
113203802Spjd	long	sdt_sods;		/* List of shared objects descriptors */
114152521Spjd	long	sdt_filler1;		/* Unused (was: search rules) */
115152521Spjd	long	sdt_got;		/* Global offset table */
116127412Sgad	long	sdt_plt;		/* Procedure linkage table */
117201145Santoine	long	sdt_rel;		/* Relocation table */
118201145Santoine	long	sdt_hash;		/* Symbol hash table */
119201145Santoine	long	sdt_nzlist;		/* Symbol table itself */
120201145Santoine	long	sdt_filler2;		/* Unused (was: stab_hash) */
121201145Santoine	long	sdt_buckets;		/* Number of hash buckets */
122201145Santoine	long	sdt_strings;		/* Symbol strings */
123201145Santoine	long	sdt_str_sz;		/* Size of symbol strings */
124201145Santoine	long	sdt_text_sz;		/* Size of text area */
125254134Strasz	long	sdt_plt_sz;		/* Size of procedure linkage table */
126127412Sgad};
127152521Spjd
128152521Spjd/*
129152521Spjd * RRS symbol hash table, addressed by `sdt_hash' in section_dispatch_table.
130152521Spjd * Used to quickly lookup symbols of the shared object by hashing
131152521Spjd * on the symbol's name. `rh_symbolnum' is the index of the symbol
132127412Sgad * in the shared object's symbol list (`sdt_nzlist'), `rh_next' is
133127412Sgad * the next symbol in the hash bucket (in case of collisions).
134127412Sgad */
135127412Sgadstruct rrs_hash {
136149471Spjd	int	rh_symbolnum;		/* Symbol number */
137127462Sgad	int	rh_next;		/* Next hash entry */
138209363Sbrian};
139149471Spjd
140127430Sgad/*
141152521Spjd * `rt_symbols' is used to keep track of run-time allocated commons
142127425Sgad * and data items copied from shared objects.
143127412Sgad */
144127430Sgadstruct rt_symbol {
145127412Sgad	struct nzlist		*rt_sp;		/* The symbol */
146127412Sgad	struct rt_symbol	*rt_next;	/* Next in linear list */
147192242Sbrian	struct rt_symbol	*rt_link;	/* Next in bucket */
148127412Sgad	caddr_t			rt_srcaddr;	/* Address of "master" copy */
149132198Stjr	struct so_map		*rt_smp;	/* Originating map */
150132198Stjr};
151127412Sgad
152127412Sgad/*
153127412Sgad * Debugger interface structure.
154127412Sgad */
155127412Sgadstruct so_debug {
156127412Sgad	int	dd_version;		/* Version # of interface */
157127412Sgad	int	dd_in_debugger;		/* Set when run by debugger */
158127412Sgad	int	dd_sym_loaded;		/* Run-time linking brought more
159127412Sgad					   symbols into scope */
160127412Sgad	char   	 *dd_bpt_addr;		/* Address of rtld-generated bpt */
161127412Sgad	int	dd_bpt_shadow;		/* Original contents of bpt */
162127412Sgad	struct rt_symbol *dd_cc;	/* Allocated commons/copied data */
163127412Sgad};
164127412Sgad
165127412Sgad/*
166218285Sjilles * Version returned to crt0 from ld.so
167127412Sgad */
168127412Sgad#define LDSO_VERSION_NONE	0	/* FreeBSD2.0, 2.0.5 */
169127412Sgad#define LDSO_VERSION_HAS_DLEXIT	1	/* includes dlexit in ld_entry */
170127412Sgad
171127412Sgad/*
172127412Sgad * Entry points into ld.so - user interface to the run-time linker.
173127412Sgad * Entries are valid for the given version numbers returned by ld.so
174127412Sgad * to crt0.
175127412Sgad */
176127412Sgadstruct ld_entry {
177127412Sgad	void	*(*dlopen) __P((char *, int));		/* NONE */
178127412Sgad	int	(*dlclose) __P((void *));		/* NONE */
179127412Sgad	void	*(*dlsym) __P((void *, char *));	/* NONE */
180192242Sbrian	char	*(*dlerror) __P((void));		/* NONE */
181127412Sgad	void	(*dlexit) __P((void));			/* HAS_DLEXIT */
182127433Sgad};
183149471Spjd
184149471Spjd/*
185203802Spjd * dl*() prototypes.
186203688Sbrucec */
187203688Sbrucecextern void	*dlopen __P((char *, int));
188127412Sgadextern int	dlclose __P((void *));
189254134Straszextern void	*dlsym __P((void *, char *));
190127412Sgadextern char	*dlerror __P((void));
191127433Sgad
192127433Sgad
193127433Sgad/*
194143874Spjd * This is the structure pointed at by the __DYNAMIC symbol if an
195149471Spjd * executable requires the attention of the run-time link editor.
196143874Spjd * __DYNAMIC is given the value zero if no run-time linking needs to
197143874Spjd * be done (it is always present in shared objects).
198127412Sgad * The union `d_un' provides for different versions of the dynamic
199127412Sgad * linking mechanism (switched on by `d_version'). The last version
200127412Sgad * used by Sun is 3. We leave some room here and go to version number
201127412Sgad * 8 for NetBSD, the main difference lying in the support for the
202152518Spjd * `nz_list' type of symbols.
203152518Spjd */
204152518Spjd
205152518Spjdstruct	_dynamic {
206152518Spjd	int		d_version;	/* version # of this interface */
207149471Spjd	struct so_debug	*d_debug;
208149471Spjd	union {
209149471Spjd		struct section_dispatch_table *d_sdt;
210127427Sgad	} d_un;
211127427Sgad	struct ld_entry *d_entry;	/* XXX */
212127427Sgad};
213127427Sgad
214127427Sgad#define LD_VERSION_SUN		(3)
215127427Sgad#define LD_VERSION_BSD		(8)
216127412Sgad#define LD_VERSION_NZLIST_P(v)	((v) >= 8)
217127412Sgad
218127412Sgad#define LD_GOT(x)	((x)->d_un.d_sdt->sdt_got)
219127412Sgad#define LD_PLT(x)	((x)->d_un.d_sdt->sdt_plt)
220143877Spjd#define LD_REL(x)	((x)->d_un.d_sdt->sdt_rel)
221143877Spjd#define LD_SYMBOL(x)	((x)->d_un.d_sdt->sdt_nzlist)
222143877Spjd#define LD_HASH(x)	((x)->d_un.d_sdt->sdt_hash)
223143877Spjd#define LD_STRINGS(x)	((x)->d_un.d_sdt->sdt_strings)
224143877Spjd#define LD_NEED(x)	((x)->d_un.d_sdt->sdt_sods)
225127412Sgad#define LD_BUCKETS(x)	((x)->d_un.d_sdt->sdt_buckets)
226127412Sgad
227127412Sgad#define LD_GOTSZ(x)	((x)->d_un.d_sdt->sdt_plt - (x)->d_un.d_sdt->sdt_got)
228127412Sgad#define LD_RELSZ(x)	((x)->d_un.d_sdt->sdt_hash - (x)->d_un.d_sdt->sdt_rel)
229192242Sbrian#define LD_HASHSZ(x)	((x)->d_un.d_sdt->sdt_nzlist - (x)->d_un.d_sdt->sdt_hash)
230192242Sbrian#define LD_STABSZ(x)	((x)->d_un.d_sdt->sdt_strings - (x)->d_un.d_sdt->sdt_nzlist)
231192242Sbrian#define LD_PLTSZ(x)	((x)->d_un.d_sdt->sdt_plt_sz)
232254134Strasz#define LD_STRSZ(x)	((x)->d_un.d_sdt->sdt_str_sz)
233254134Strasz#define LD_TEXTSZ(x)	((x)->d_un.d_sdt->sdt_text_sz)
234254134Strasz
235254134Strasz/*
236127412Sgad * Interface to ld.so
237127412Sgad */
238127412Sgadstruct crt_ldso {
239127412Sgad	int		crt_ba;		/* Base address of ld.so */
240127412Sgad	int		crt_dzfd;	/* "/dev/zero" file descriptor (SunOS) */
241127412Sgad	int		crt_ldfd;	/* ld.so file descriptor */
242127412Sgad	struct _dynamic	*crt_dp;	/* Main's __DYNAMIC */
243127412Sgad	char		**crt_ep;	/* environment strings */
244127412Sgad	caddr_t		crt_bp;		/* Breakpoint if run from debugger */
245127412Sgad	char		*crt_prog;	/* Program name (v3) */
246127412Sgad	char		*crt_ldso;	/* Link editor name (v4) */
247127412Sgad	struct ld_entry	*crt_ldentry;	/* dl*() access (v4) */
248143875Spjd};
249143875Spjd
250143875Spjd/*
251143873Spjd * Version passed from crt0 to ld.so (1st argument to _rtld()).
252287012Sjamie */
253143873Spjd#define CRT_VERSION_SUN		1
254143873Spjd#define CRT_VERSION_BSD_2	2
255127412Sgad#define CRT_VERSION_BSD_3	3
256127412Sgad#define CRT_VERSION_BSD_4	4
257127412Sgad
258127412Sgad/*
259127412Sgad * Maximum number of recognized shared object version numbers.
260127412Sgad */
261127412Sgad#define MAXDEWEY	8
262143878Spjd
263143878Spjd/*
264143878Spjd * Header of the hints file.
265143878Spjd */
266203802Spjdstruct hints_header {
267203802Spjd	long		hh_magic;
268203802Spjd#define HH_MAGIC	011421044151
269203802Spjd	long		hh_version;	/* Interface version number */
270203802Spjd#define LD_HINTS_VERSION_1	1
271127412Sgad	long		hh_hashtab;	/* Location of hash table */
272127412Sgad	long		hh_nbucket;	/* Number of buckets in hashtab */
273127412Sgad	long		hh_strtab;	/* Location of strings */
274127412Sgad	long		hh_strtab_sz;	/* Size of strings */
275127412Sgad	long		hh_ehints;	/* End of hints (max offset in file) */
276127412Sgad};
277127412Sgad
278127412Sgad#define HH_BADMAG(hdr)	((hdr).hh_magic != HH_MAGIC)
279127412Sgad
280127412Sgad/*
281127412Sgad * Hash table element in hints file.
282127412Sgad */
283127412Sgadstruct hints_bucket {
284127412Sgad	/* namex and pathx are indices into the string table */
285127412Sgad	int		hi_namex;		/* Library name */
286127412Sgad	int		hi_pathx;		/* Full path */
287127412Sgad	int		hi_dewey[MAXDEWEY];	/* The versions */
288127412Sgad	int		hi_ndewey;		/* Number of version numbers */
289127412Sgad#define hi_major hi_dewey[0]
290127412Sgad#define hi_minor hi_dewey[1]
291127412Sgad	int		hi_next;		/* Next in this bucket */
292127412Sgad};
293127412Sgad
294127412Sgad#define _PATH_LD_HINTS		"/var/run/ld.so.hints"
295127412Sgad
296127412Sgad#endif /* _LINK_H_ */
297127412Sgad
298127412Sgad