xref: /netbsd/include/link_aout.h (revision 2a9a9741)
1*2a9a9741Sdholland /*	$NetBSD: link_aout.h,v 1.23 2016/01/23 01:26:14 dholland Exp $	*/
24d2cbfceScgd 
30a97faa0Spk /*-
40a97faa0Spk  * Copyright (c) 1998 The NetBSD Foundation, Inc.
5ad127b0aSpk  * All rights reserved.
62dfde2bcSpk  *
70a97faa0Spk  * This code is derived from software contributed to The NetBSD Foundation
80a97faa0Spk  * by Paul Kranenburg.
90a97faa0Spk  *
10ad127b0aSpk  * Redistribution and use in source and binary forms, with or without
11ad127b0aSpk  * modification, are permitted provided that the following conditions
12ad127b0aSpk  * are met:
13ad127b0aSpk  * 1. Redistributions of source code must retain the above copyright
14ad127b0aSpk  *    notice, this list of conditions and the following disclaimer.
15ad127b0aSpk  * 2. Redistributions in binary form must reproduce the above copyright
16ad127b0aSpk  *    notice, this list of conditions and the following disclaimer in the
17ad127b0aSpk  *    documentation and/or other materials provided with the distribution.
18ad127b0aSpk  *
190a97faa0Spk  * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
200a97faa0Spk  * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
210a97faa0Spk  * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
220a97faa0Spk  * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
230a97faa0Spk  * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
240a97faa0Spk  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
250a97faa0Spk  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
260a97faa0Spk  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
270a97faa0Spk  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
280a97faa0Spk  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
290a97faa0Spk  * POSSIBILITY OF SUCH DAMAGE.
30ad127b0aSpk  */
31ad127b0aSpk 
32ad127b0aSpk /*
33ad127b0aSpk  * RRS section definitions.
34ad127b0aSpk  *
35ad127b0aSpk  * The layout of some data structures defined in this header file is
36ad127b0aSpk  * such that we can provide compatibility with the SunOS 4.x shared
37ad127b0aSpk  * library scheme.
382dfde2bcSpk  */
392dfde2bcSpk 
40e278587dSthorpej #ifndef _LINK_AOUT_H_
41e278587dSthorpej #define _LINK_AOUT_H_
422dfde2bcSpk 
43dd26162dSthorpej #include <dlfcn.h>			/* for Dl_info */
44f6f34d9cSpk #include <a.out.h>			/* for struct nlist */
45dd26162dSthorpej 
462dfde2bcSpk /*
47fd2b9df4Swiz  * A `Shared Object Descriptor' describes a shared object that is needed
482dfde2bcSpk  * to complete the link edit process of the object containing it.
49ad127b0aSpk  * A list of such objects (chained through `sod_next') is pointed at
50ad127b0aSpk  * by `sdt_sods' in the section_dispatch_table structure.
512dfde2bcSpk  */
522dfde2bcSpk 
53ad127b0aSpk struct sod {	/* Shared Object Descriptor */
54ad127b0aSpk 	long	sod_name;		/* name (relative to load address) */
55*2a9a9741Sdholland 	unsigned int sod_library  : 1,	/* Searched for by library rules */
56ad127b0aSpk 		sod_reserved : 31;
57ad127b0aSpk 	short	sod_major;		/* major version number */
58ad127b0aSpk 	short	sod_minor;		/* minor version number */
59ad127b0aSpk 	long	sod_next;		/* next sod */
602dfde2bcSpk };
612dfde2bcSpk 
622dfde2bcSpk /*
63ad127b0aSpk  * `Shared Object Map's are used by the run-time link editor (ld.so) to
64ad127b0aSpk  * keep track of all shared objects loaded into a process' address space.
652dfde2bcSpk  * These structures are only used at run-time and do not occur within
662dfde2bcSpk  * the text or data segment of an executable or shared library.
672dfde2bcSpk  */
68ad127b0aSpk struct so_map {		/* Shared Object Map */
69ad127b0aSpk 	caddr_t		som_addr;	/* Address at which object mapped */
70ad127b0aSpk 	char 		*som_path;	/* Path to mmap'ed file */
71ad127b0aSpk 	struct so_map	*som_next;	/* Next map in chain */
72ad127b0aSpk 	struct sod	*som_sod;	/* Sod responsible for this map */
73ad127b0aSpk 	caddr_t		som_sodbase;	/* Base address of this sod */
74*2a9a9741Sdholland 	unsigned int	som_write : 1;	/* Text is currently writable */
75ad127b0aSpk 	struct _dynamic	*som_dynamic;	/* _dynamic structure */
76ad127b0aSpk 	caddr_t		som_spd;	/* Private data */
772dfde2bcSpk };
782dfde2bcSpk 
792dfde2bcSpk /*
802dfde2bcSpk  * Symbol description with size. This is simply an `nlist' with
812dfde2bcSpk  * one field (nz_size) added.
822dfde2bcSpk  * Used to convey size information on items in the data segment
832dfde2bcSpk  * of shared objects. An array of these live in the shared object's
84ad127b0aSpk  * text segment and is addressed by the `sdt_nzlist' field.
852dfde2bcSpk  */
862dfde2bcSpk struct nzlist {
872dfde2bcSpk 	struct nlist	nlist;
882720ce68Sdholland 	unsigned long	nz_size;
892dfde2bcSpk #define nz_un		nlist.n_un
902dfde2bcSpk #define nz_strx		nlist.n_un.n_strx
912dfde2bcSpk #define nz_name		nlist.n_un.n_name
922dfde2bcSpk #define nz_type		nlist.n_type
932dfde2bcSpk #define nz_value	nlist.n_value
942dfde2bcSpk #define nz_desc		nlist.n_desc
952dfde2bcSpk #define nz_other	nlist.n_other
962dfde2bcSpk };
972dfde2bcSpk 
98ad127b0aSpk #define N_AUX(p)	((p)->n_other & 0xf)
99da34da60Spk #define N_BIND(p)	(((unsigned int)(p)->n_other >> 4) & 0xf)
100ad127b0aSpk #define N_OTHER(r, v)	(((unsigned int)(r) << 4) | ((v) & 0xf))
101ad127b0aSpk 
102ad127b0aSpk #define AUX_OBJECT	1
103ad127b0aSpk #define AUX_FUNC	2
104f94bc8f4Smatt #define AUX_LABEL	3
105da34da60Spk /*#define BIND_LOCAL	0	not used */
106da34da60Spk /*#define BIND_GLOBAL	1	not used */
107da34da60Spk #define BIND_WEAK	2
108ad127b0aSpk 
109ad127b0aSpk 
1102dfde2bcSpk /*
111ad127b0aSpk  * The `section_dispatch_table' structure contains offsets to various data
1122dfde2bcSpk  * structures needed to do run-time relocation.
1132dfde2bcSpk  */
114ad127b0aSpk struct section_dispatch_table {
115ad127b0aSpk 	struct so_map *sdt_loaded;	/* List of loaded objects */
116ad127b0aSpk 	long	sdt_sods;		/* List of shared objects descriptors */
117fe9497fdSpk 	long	sdt_paths;		/* Library search paths */
118ad127b0aSpk 	long	sdt_got;		/* Global offset table */
119ad127b0aSpk 	long	sdt_plt;		/* Procedure linkage table */
120ad127b0aSpk 	long	sdt_rel;		/* Relocation table */
121ad127b0aSpk 	long	sdt_hash;		/* Symbol hash table */
122ad127b0aSpk 	long	sdt_nzlist;		/* Symbol table itself */
123ad127b0aSpk 	long	sdt_filler2;		/* Unused (was: stab_hash) */
124ad127b0aSpk 	long	sdt_buckets;		/* Number of hash buckets */
125ad127b0aSpk 	long	sdt_strings;		/* Symbol strings */
126ad127b0aSpk 	long	sdt_str_sz;		/* Size of symbol strings */
127ad127b0aSpk 	long	sdt_text_sz;		/* Size of text area */
128ad127b0aSpk 	long	sdt_plt_sz;		/* Size of procedure linkage table */
1292dfde2bcSpk };
1302dfde2bcSpk 
1312dfde2bcSpk /*
132ad127b0aSpk  * RRS symbol hash table, addressed by `sdt_hash' in section_dispatch_table.
1332dfde2bcSpk  * Used to quickly lookup symbols of the shared object by hashing
1342dfde2bcSpk  * on the symbol's name. `rh_symbolnum' is the index of the symbol
135ad127b0aSpk  * in the shared object's symbol list (`sdt_nzlist'), `rh_next' is
1362dfde2bcSpk  * the next symbol in the hash bucket (in case of collisions).
1372dfde2bcSpk  */
1382dfde2bcSpk struct rrs_hash {
139ad127b0aSpk 	int	rh_symbolnum;		/* Symbol number */
140ad127b0aSpk 	int	rh_next;		/* Next hash entry */
1412dfde2bcSpk };
1422dfde2bcSpk 
1432dfde2bcSpk /*
1442dfde2bcSpk  * `rt_symbols' is used to keep track of run-time allocated commons
1452dfde2bcSpk  * and data items copied from shared objects.
1462dfde2bcSpk  */
1472dfde2bcSpk struct rt_symbol {
148ad127b0aSpk 	struct nzlist		*rt_sp;		/* The symbol */
149ad127b0aSpk 	struct rt_symbol	*rt_next;	/* Next in linear list */
150ad127b0aSpk 	struct rt_symbol	*rt_link;	/* Next in bucket */
151ad127b0aSpk 	caddr_t			rt_srcaddr;	/* Address of "master" copy */
152ad127b0aSpk 	struct so_map		*rt_smp;	/* Originating map */
1532dfde2bcSpk };
1542dfde2bcSpk 
1552dfde2bcSpk /*
1562dfde2bcSpk  * Debugger interface structure.
1572dfde2bcSpk  */
158ad127b0aSpk struct so_debug {
159ad127b0aSpk 	int	dd_version;		/* Version # of interface */
160ad127b0aSpk 	int	dd_in_debugger;		/* Set when run by debugger */
161ad127b0aSpk 	int	dd_sym_loaded;		/* Run-time linking brought more
162ad127b0aSpk 					   symbols into scope */
163ad127b0aSpk 	char   	 *dd_bpt_addr;		/* Address of rtld-generated bpt */
164ad127b0aSpk 	int	dd_bpt_shadow;		/* Original contents of bpt */
165ad127b0aSpk 	struct rt_symbol *dd_cc;	/* Allocated commons/copied data */
1662dfde2bcSpk };
1672dfde2bcSpk 
1682dfde2bcSpk /*
1692dfde2bcSpk  * Entry points into ld.so - user interface to the run-time linker.
1702dfde2bcSpk  */
1712dfde2bcSpk struct ld_entry {
17219b7469aSperry 	void	*(*dlopen)(const char *, int);
17319b7469aSperry 	int	(*dlclose)(void *);
17419b7469aSperry 	void	*(*dlsym)(void *, const char *);
17519b7469aSperry 	int	(*dlctl)(void *, int, void *);
17619b7469aSperry 	void	(*dlexit)(void);
17719b7469aSperry 	int	(*dladdr)(const void *, Dl_info *);
17819b7469aSperry 	void	(*dlrsrvd[2])(void);
1792dfde2bcSpk };
1802dfde2bcSpk 
1812dfde2bcSpk /*
1822dfde2bcSpk  * This is the structure pointed at by the __DYNAMIC symbol if an
1832dfde2bcSpk  * executable requires the attention of the run-time link editor.
1842dfde2bcSpk  * __DYNAMIC is given the value zero if no run-time linking needs to
1852dfde2bcSpk  * be done (it is always present in shared objects).
186ad127b0aSpk  * The union `d_un' provides for different versions of the dynamic
187ad127b0aSpk  * linking mechanism (switched on by `d_version'). The last version
1882dfde2bcSpk  * used by Sun is 3. We leave some room here and go to version number
1892dfde2bcSpk  * 8 for NetBSD, the main difference lying in the support for the
1902dfde2bcSpk  * `nz_list' type of symbols.
1912dfde2bcSpk  */
1922dfde2bcSpk 
193ad127b0aSpk struct	_dynamic {
194ad127b0aSpk 	int		d_version;	/* version # of this interface */
195ad127b0aSpk 	struct so_debug	*d_debug;
1962dfde2bcSpk 	union {
197ad127b0aSpk 		struct section_dispatch_table *d_sdt;
198ad127b0aSpk 	} d_un;
199fa6e0672Spk 	struct ld_entry *d_entry;	/* compat - now in crt_ldso */
2002dfde2bcSpk };
2012dfde2bcSpk 
2022dfde2bcSpk #define LD_VERSION_SUN		(3)
2032dfde2bcSpk #define LD_VERSION_BSD		(8)
2042dfde2bcSpk #define LD_VERSION_NZLIST_P(v)	((v) >= 8)
2052dfde2bcSpk 
206ad127b0aSpk #define LD_GOT(x)	((x)->d_un.d_sdt->sdt_got)
207ad127b0aSpk #define LD_PLT(x)	((x)->d_un.d_sdt->sdt_plt)
208ad127b0aSpk #define LD_REL(x)	((x)->d_un.d_sdt->sdt_rel)
209ad127b0aSpk #define LD_SYMBOL(x)	((x)->d_un.d_sdt->sdt_nzlist)
210ad127b0aSpk #define LD_HASH(x)	((x)->d_un.d_sdt->sdt_hash)
211ad127b0aSpk #define LD_STRINGS(x)	((x)->d_un.d_sdt->sdt_strings)
212ad127b0aSpk #define LD_NEED(x)	((x)->d_un.d_sdt->sdt_sods)
213ad127b0aSpk #define LD_BUCKETS(x)	((x)->d_un.d_sdt->sdt_buckets)
214fe9497fdSpk #define LD_PATHS(x)	((x)->d_un.d_sdt->sdt_paths)
2152dfde2bcSpk 
216ad127b0aSpk #define LD_GOTSZ(x)	((x)->d_un.d_sdt->sdt_plt - (x)->d_un.d_sdt->sdt_got)
217ad127b0aSpk #define LD_RELSZ(x)	((x)->d_un.d_sdt->sdt_hash - (x)->d_un.d_sdt->sdt_rel)
218ad127b0aSpk #define LD_HASHSZ(x)	((x)->d_un.d_sdt->sdt_nzlist - (x)->d_un.d_sdt->sdt_hash)
219ad127b0aSpk #define LD_STABSZ(x)	((x)->d_un.d_sdt->sdt_strings - (x)->d_un.d_sdt->sdt_nzlist)
220ad127b0aSpk #define LD_PLTSZ(x)	((x)->d_un.d_sdt->sdt_plt_sz)
221ad127b0aSpk #define LD_STRSZ(x)	((x)->d_un.d_sdt->sdt_str_sz)
222ad127b0aSpk #define LD_TEXTSZ(x)	((x)->d_un.d_sdt->sdt_text_sz)
2232dfde2bcSpk 
2242dfde2bcSpk /*
225ad127b0aSpk  * Interface to ld.so
2262dfde2bcSpk  */
2272dfde2bcSpk struct crt_ldso {
2282dfde2bcSpk 	int		crt_ba;		/* Base address of ld.so */
229fd2b9df4Swiz 	int		crt_dzfd;	/* "/dev/zero" file descriptor (SunOS) */
2302dfde2bcSpk 	int		crt_ldfd;	/* ld.so file descriptor */
231ad127b0aSpk 	struct _dynamic	*crt_dp;	/* Main's __DYNAMIC */
2322dfde2bcSpk 	char		**crt_ep;	/* environment strings */
2332dfde2bcSpk 	caddr_t		crt_bp;		/* Breakpoint if run from debugger */
234da34da60Spk 	char		*crt_prog;	/* Program name (v3) */
235da34da60Spk 	char		*crt_ldso;	/* Link editor name (v4) */
236da34da60Spk 	struct ld_entry	*crt_ldentry;	/* dl*() access (v4) */
2372dfde2bcSpk };
2382dfde2bcSpk 
2392dfde2bcSpk /*
2402dfde2bcSpk  * Version passed from crt0 to ld.so (1st argument to _rtld()).
2412dfde2bcSpk  */
2422dfde2bcSpk #define CRT_VERSION_SUN		1
243ad127b0aSpk #define CRT_VERSION_BSD_2	2
244ad127b0aSpk #define CRT_VERSION_BSD_3	3
245da34da60Spk #define CRT_VERSION_BSD_4	4
2462dfde2bcSpk 
2478846fa47Spk 
2488846fa47Spk /*
2498846fa47Spk  * Maximum number of recognized shared object version numbers.
2508846fa47Spk  */
2518846fa47Spk #define MAXDEWEY	8
2528846fa47Spk 
2538846fa47Spk /*
2548846fa47Spk  * Header of the hints file.
2558846fa47Spk  */
2568846fa47Spk struct hints_header {
2578846fa47Spk 	long		hh_magic;
2588846fa47Spk #define HH_MAGIC	011421044151
2598846fa47Spk 	long		hh_version;	/* Interface version number */
2608846fa47Spk #define LD_HINTS_VERSION_1	1
261d9824003Spk #define LD_HINTS_VERSION_2	2
2628846fa47Spk 	long		hh_hashtab;	/* Location of hash table */
2638846fa47Spk 	long		hh_nbucket;	/* Number of buckets in hashtab */
2648846fa47Spk 	long		hh_strtab;	/* Location of strings */
2658846fa47Spk 	long		hh_strtab_sz;	/* Size of strings */
2668846fa47Spk 	long		hh_ehints;	/* End of hints (max offset in file) */
267d9824003Spk 	long		hh_dirlist;	/* Colon-separated list of srch dirs */
2688846fa47Spk };
2698846fa47Spk 
2708846fa47Spk #define HH_BADMAG(hdr)	((hdr).hh_magic != HH_MAGIC)
2718846fa47Spk 
2728846fa47Spk /*
2738846fa47Spk  * Hash table element in hints file.
2748846fa47Spk  */
2758846fa47Spk struct hints_bucket {
2768846fa47Spk 	/* namex and pathx are indices into the string table */
2778846fa47Spk 	int		hi_namex;		/* Library name */
2788846fa47Spk 	int		hi_pathx;		/* Full path */
2798846fa47Spk 	int		hi_dewey[MAXDEWEY];	/* The versions */
2808846fa47Spk 	int		hi_ndewey;		/* Number of version numbers */
2818846fa47Spk #define hi_major hi_dewey[0]
2828846fa47Spk #define hi_minor hi_dewey[1]
2838846fa47Spk 	int		hi_next;		/* Next in this bucket */
2848846fa47Spk };
2858846fa47Spk 
2868846fa47Spk #define _PATH_LD_HINTS		"/var/run/ld.so.hints"
2878846fa47Spk 
288e278587dSthorpej #endif /* _LINK_AOUT_H_ */
289