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