Home | History | Annotate | Line # | Download | only in include
link_aout.h revision 1.7
      1 /*	$NetBSD: link_aout.h,v 1.7 1995/06/04 21:57:18 pk Exp $	*/
      2 
      3 /*
      4  * Copyright (c) 1993 Paul Kranenburg
      5  * All rights reserved.
      6  *
      7  * Redistribution and use in source and binary forms, with or without
      8  * modification, are permitted provided that the following conditions
      9  * are met:
     10  * 1. Redistributions of source code must retain the above copyright
     11  *    notice, this list of conditions and the following disclaimer.
     12  * 2. Redistributions in binary form must reproduce the above copyright
     13  *    notice, this list of conditions and the following disclaimer in the
     14  *    documentation and/or other materials provided with the distribution.
     15  * 3. All advertising materials mentioning features or use of this software
     16  *    must display the following acknowledgement:
     17  *      This product includes software developed by Paul Kranenburg.
     18  * 4. The name of the author may not be used to endorse or promote products
     19  *    derived from this software withough specific prior written permission
     20  *
     21  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
     22  * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
     23  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
     24  * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
     25  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
     26  * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
     27  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
     28  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
     29  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
     30  * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
     31  */
     32 
     33 /*
     34  * RRS section definitions.
     35  *
     36  * The layout of some data structures defined in this header file is
     37  * such that we can provide compatibility with the SunOS 4.x shared
     38  * library scheme.
     39  */
     40 
     41 #ifndef _LINK_H_
     42 #define _LINK_H_
     43 
     44 /*
     45  * A `Shared Object Descriptor' descibes a shared object that is needed
     46  * to complete the link edit process of the object containing it.
     47  * A list of such objects (chained through `sod_next') is pointed at
     48  * by `sdt_sods' in the section_dispatch_table structure.
     49  */
     50 
     51 struct sod {	/* Shared Object Descriptor */
     52 	long	sod_name;		/* name (relative to load address) */
     53 	u_int	sod_library  : 1,	/* Searched for by library rules */
     54 		sod_reserved : 31;
     55 	short	sod_major;		/* major version number */
     56 	short	sod_minor;		/* minor version number */
     57 	long	sod_next;		/* next sod */
     58 };
     59 
     60 /*
     61  * `Shared Object Map's are used by the run-time link editor (ld.so) to
     62  * keep track of all shared objects loaded into a process' address space.
     63  * These structures are only used at run-time and do not occur within
     64  * the text or data segment of an executable or shared library.
     65  */
     66 struct so_map {		/* Shared Object Map */
     67 	caddr_t		som_addr;	/* Address at which object mapped */
     68 	char 		*som_path;	/* Path to mmap'ed file */
     69 	struct so_map	*som_next;	/* Next map in chain */
     70 	struct sod	*som_sod;	/* Sod responsible for this map */
     71 	caddr_t		som_sodbase;	/* Base address of this sod */
     72 	u_int		som_write : 1;	/* Text is currently writable */
     73 	struct _dynamic	*som_dynamic;	/* _dynamic structure */
     74 	caddr_t		som_spd;	/* Private data */
     75 };
     76 
     77 /*
     78  * Symbol description with size. This is simply an `nlist' with
     79  * one field (nz_size) added.
     80  * Used to convey size information on items in the data segment
     81  * of shared objects. An array of these live in the shared object's
     82  * text segment and is addressed by the `sdt_nzlist' field.
     83  */
     84 struct nzlist {
     85 	struct nlist	nlist;
     86 	u_long		nz_size;
     87 #define nz_un		nlist.n_un
     88 #define nz_strx		nlist.n_un.n_strx
     89 #define nz_name		nlist.n_un.n_name
     90 #define nz_type		nlist.n_type
     91 #define nz_value	nlist.n_value
     92 #define nz_desc		nlist.n_desc
     93 #define nz_other	nlist.n_other
     94 };
     95 
     96 #define N_AUX(p)	((p)->n_other & 0xf)
     97 #define N_BIND(p)	(((unsigned int)(p)->n_other >> 4) & 0xf)
     98 #define N_OTHER(r, v)	(((unsigned int)(r) << 4) | ((v) & 0xf))
     99 
    100 #define AUX_OBJECT	1
    101 #define AUX_FUNC	2
    102 /*#define BIND_LOCAL	0	not used */
    103 /*#define BIND_GLOBAL	1	not used */
    104 #define BIND_WEAK	2
    105 
    106 
    107 /*
    108  * The `section_dispatch_table' structure contains offsets to various data
    109  * structures needed to do run-time relocation.
    110  */
    111 struct section_dispatch_table {
    112 	struct so_map *sdt_loaded;	/* List of loaded objects */
    113 	long	sdt_sods;		/* List of shared objects descriptors */
    114 	long	sdt_paths;		/* Library search paths */
    115 	long	sdt_got;		/* Global offset table */
    116 	long	sdt_plt;		/* Procedure linkage table */
    117 	long	sdt_rel;		/* Relocation table */
    118 	long	sdt_hash;		/* Symbol hash table */
    119 	long	sdt_nzlist;		/* Symbol table itself */
    120 	long	sdt_filler2;		/* Unused (was: stab_hash) */
    121 	long	sdt_buckets;		/* Number of hash buckets */
    122 	long	sdt_strings;		/* Symbol strings */
    123 	long	sdt_str_sz;		/* Size of symbol strings */
    124 	long	sdt_text_sz;		/* Size of text area */
    125 	long	sdt_plt_sz;		/* Size of procedure linkage table */
    126 };
    127 
    128 /*
    129  * RRS symbol hash table, addressed by `sdt_hash' in section_dispatch_table.
    130  * Used to quickly lookup symbols of the shared object by hashing
    131  * on the symbol's name. `rh_symbolnum' is the index of the symbol
    132  * in the shared object's symbol list (`sdt_nzlist'), `rh_next' is
    133  * the next symbol in the hash bucket (in case of collisions).
    134  */
    135 struct rrs_hash {
    136 	int	rh_symbolnum;		/* Symbol number */
    137 	int	rh_next;		/* Next hash entry */
    138 };
    139 
    140 /*
    141  * `rt_symbols' is used to keep track of run-time allocated commons
    142  * and data items copied from shared objects.
    143  */
    144 struct rt_symbol {
    145 	struct nzlist		*rt_sp;		/* The symbol */
    146 	struct rt_symbol	*rt_next;	/* Next in linear list */
    147 	struct rt_symbol	*rt_link;	/* Next in bucket */
    148 	caddr_t			rt_srcaddr;	/* Address of "master" copy */
    149 	struct so_map		*rt_smp;	/* Originating map */
    150 };
    151 
    152 /*
    153  * Debugger interface structure.
    154  */
    155 struct so_debug {
    156 	int	dd_version;		/* Version # of interface */
    157 	int	dd_in_debugger;		/* Set when run by debugger */
    158 	int	dd_sym_loaded;		/* Run-time linking brought more
    159 					   symbols into scope */
    160 	char   	 *dd_bpt_addr;		/* Address of rtld-generated bpt */
    161 	int	dd_bpt_shadow;		/* Original contents of bpt */
    162 	struct rt_symbol *dd_cc;	/* Allocated commons/copied data */
    163 };
    164 
    165 /*
    166  * Entry points into ld.so - user interface to the run-time linker.
    167  */
    168 struct ld_entry {
    169 	void	*(*dlopen) __P((char *, int));
    170 	int	(*dlclose) __P((void *));
    171 	void	*(*dlsym) __P((void *, char *));
    172 	int	(*dlctl) __P((void *, int, void *));
    173 };
    174 
    175 /*
    176  * dlctl() commands
    177  */
    178 #define DL_GETERRNO	1
    179 #define DL_SETSRCHPATH	x
    180 #define DL_GETLIST	x
    181 #define DL_GETREFCNT	x
    182 #define DL_GETLOADADDR	x
    183 
    184 /*
    185  * dl*() prototypes.
    186  */
    187 extern void	*dlopen __P((char *, int));
    188 extern int	dlclose __P((void *));
    189 extern void	*dlsym __P((void *, char *));
    190 extern int	dlctl __P((void *, int, void *));
    191 
    192 
    193 /*
    194  * This is the structure pointed at by the __DYNAMIC symbol if an
    195  * executable requires the attention of the run-time link editor.
    196  * __DYNAMIC is given the value zero if no run-time linking needs to
    197  * be done (it is always present in shared objects).
    198  * The union `d_un' provides for different versions of the dynamic
    199  * linking mechanism (switched on by `d_version'). The last version
    200  * used by Sun is 3. We leave some room here and go to version number
    201  * 8 for NetBSD, the main difference lying in the support for the
    202  * `nz_list' type of symbols.
    203  */
    204 
    205 struct	_dynamic {
    206 	int		d_version;	/* version # of this interface */
    207 	struct so_debug	*d_debug;
    208 	union {
    209 		struct section_dispatch_table *d_sdt;
    210 	} d_un;
    211 	struct ld_entry *d_entry;	/* XXX */
    212 };
    213 
    214 #define LD_VERSION_SUN		(3)
    215 #define LD_VERSION_BSD		(8)
    216 #define LD_VERSION_NZLIST_P(v)	((v) >= 8)
    217 
    218 #define LD_GOT(x)	((x)->d_un.d_sdt->sdt_got)
    219 #define LD_PLT(x)	((x)->d_un.d_sdt->sdt_plt)
    220 #define LD_REL(x)	((x)->d_un.d_sdt->sdt_rel)
    221 #define LD_SYMBOL(x)	((x)->d_un.d_sdt->sdt_nzlist)
    222 #define LD_HASH(x)	((x)->d_un.d_sdt->sdt_hash)
    223 #define LD_STRINGS(x)	((x)->d_un.d_sdt->sdt_strings)
    224 #define LD_NEED(x)	((x)->d_un.d_sdt->sdt_sods)
    225 #define LD_BUCKETS(x)	((x)->d_un.d_sdt->sdt_buckets)
    226 #define LD_PATHS(x)	((x)->d_un.d_sdt->sdt_paths)
    227 
    228 #define LD_GOTSZ(x)	((x)->d_un.d_sdt->sdt_plt - (x)->d_un.d_sdt->sdt_got)
    229 #define LD_RELSZ(x)	((x)->d_un.d_sdt->sdt_hash - (x)->d_un.d_sdt->sdt_rel)
    230 #define LD_HASHSZ(x)	((x)->d_un.d_sdt->sdt_nzlist - (x)->d_un.d_sdt->sdt_hash)
    231 #define LD_STABSZ(x)	((x)->d_un.d_sdt->sdt_strings - (x)->d_un.d_sdt->sdt_nzlist)
    232 #define LD_PLTSZ(x)	((x)->d_un.d_sdt->sdt_plt_sz)
    233 #define LD_STRSZ(x)	((x)->d_un.d_sdt->sdt_str_sz)
    234 #define LD_TEXTSZ(x)	((x)->d_un.d_sdt->sdt_text_sz)
    235 
    236 /*
    237  * Interface to ld.so
    238  */
    239 struct crt_ldso {
    240 	int		crt_ba;		/* Base address of ld.so */
    241 	int		crt_dzfd;	/* "/dev/zero" file decriptor (SunOS) */
    242 	int		crt_ldfd;	/* ld.so file descriptor */
    243 	struct _dynamic	*crt_dp;	/* Main's __DYNAMIC */
    244 	char		**crt_ep;	/* environment strings */
    245 	caddr_t		crt_bp;		/* Breakpoint if run from debugger */
    246 	char		*crt_prog;	/* Program name (v3) */
    247 	char		*crt_ldso;	/* Link editor name (v4) */
    248 	struct ld_entry	*crt_ldentry;	/* dl*() access (v4) */
    249 };
    250 
    251 /*
    252  * Version passed from crt0 to ld.so (1st argument to _rtld()).
    253  */
    254 #define CRT_VERSION_SUN		1
    255 #define CRT_VERSION_BSD_2	2
    256 #define CRT_VERSION_BSD_3	3
    257 #define CRT_VERSION_BSD_4	4
    258 
    259 
    260 /*
    261  * Maximum number of recognized shared object version numbers.
    262  */
    263 #define MAXDEWEY	8
    264 
    265 /*
    266  * Header of the hints file.
    267  */
    268 struct hints_header {
    269 	long		hh_magic;
    270 #define HH_MAGIC	011421044151
    271 	long		hh_version;	/* Interface version number */
    272 #define LD_HINTS_VERSION_1	1
    273 	long		hh_hashtab;	/* Location of hash table */
    274 	long		hh_nbucket;	/* Number of buckets in hashtab */
    275 	long		hh_strtab;	/* Location of strings */
    276 	long		hh_strtab_sz;	/* Size of strings */
    277 	long		hh_ehints;	/* End of hints (max offset in file) */
    278 };
    279 
    280 #define HH_BADMAG(hdr)	((hdr).hh_magic != HH_MAGIC)
    281 
    282 /*
    283  * Hash table element in hints file.
    284  */
    285 struct hints_bucket {
    286 	/* namex and pathx are indices into the string table */
    287 	int		hi_namex;		/* Library name */
    288 	int		hi_pathx;		/* Full path */
    289 	int		hi_dewey[MAXDEWEY];	/* The versions */
    290 	int		hi_ndewey;		/* Number of version numbers */
    291 #define hi_major hi_dewey[0]
    292 #define hi_minor hi_dewey[1]
    293 	int		hi_next;		/* Next in this bucket */
    294 };
    295 
    296 #define _PATH_LD_HINTS		"/var/run/ld.so.hints"
    297 
    298 #endif /* _LINK_H_ */
    299 
    300