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.17 1997/12/06 17:59:52 jdp 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 struct dl_info; 45 46 /* 47 * A `Shared Object Descriptor' describes a shared object that is needed 48 * to complete the link edit process of the object containing it. 49 * A list of such objects (chained through `sod_next') is pointed at 50 * by `sdt_sods' in the section_dispatch_table structure. 51 */ 52 53 struct sod { /* Shared Object Descriptor */ 54 long sod_name; /* name (relative to load address) */ 55 u_int sod_library : 1, /* Searched for by library rules */ 56 sod_reserved : 31; 57 short sod_major; /* major version number */ 58 short sod_minor; /* minor version number */ 59 long sod_next; /* next sod */ 60 }; 61 62 /* 63 * `Shared Object Map's are used by the run-time link editor (ld.so) to 64 * keep track of all shared objects loaded into a process' address space. 65 * These structures are only used at run-time and do not occur within 66 * the text or data segment of an executable or shared library. 67 */ 68 struct so_map { /* Shared Object Map */ 69 caddr_t som_addr; /* Address at which object mapped */ 70 char *som_path; /* Path to mmap'ed file */ 71 struct so_map *som_next; /* Next map in chain */ 72 struct sod *som_sod; /* Sod responsible for this map */ 73 caddr_t som_sodbase; /* Base address of this sod */ 74 u_int som_write : 1; /* Text is currently writable */ 75 struct _dynamic *som_dynamic; /* _dynamic structure */ 76 caddr_t som_spd; /* Private data */ 77 }; 78 79 /* 80 * Symbol description with size. This is simply an `nlist' with 81 * one field (nz_size) added. 82 * Used to convey size information on items in the data segment 83 * of shared objects. An array of these live in the shared object's 84 * text segment and is addressed by the `sdt_nzlist' field. 85 */ 86 struct nzlist { 87 struct nlist nlist; 88 u_long nz_size; 89 }; 90 91 #define nz_un nlist.n_un 92 #define nz_strx nlist.n_un.n_strx 93 #define nz_name nlist.n_un.n_name 94 #define nz_type nlist.n_type 95 #define nz_value nlist.n_value 96 #define nz_desc nlist.n_desc 97 #define nz_other nlist.n_other 98 99 /* 100 * The `section_dispatch_table' structure contains offsets to various data 101 * structures needed to do run-time relocation. 102 */ 103 struct section_dispatch_table { 104 struct so_map *sdt_loaded; /* List of loaded objects */ 105 long sdt_sods; /* List of shared objects descriptors */ 106 long sdt_paths; /* Library search paths */ 107 long sdt_got; /* Global offset table */ 108 long sdt_plt; /* Procedure linkage table */ 109 long sdt_rel; /* Relocation table */ 110 long sdt_hash; /* Symbol hash table */ 111 long sdt_nzlist; /* Symbol table itself */ 112 long sdt_filler2; /* Unused (was: stab_hash) */ 113 long sdt_buckets; /* Number of hash buckets */ 114 long sdt_strings; /* Symbol strings */ 115 long sdt_str_sz; /* Size of symbol strings */ 116 long sdt_text_sz; /* Size of text area */ 117 long sdt_plt_sz; /* Size of procedure linkage table */ 118 }; 119 120 /* 121 * RRS symbol hash table, addressed by `sdt_hash' in section_dispatch_table. 122 * Used to quickly lookup symbols of the shared object by hashing 123 * on the symbol's name. `rh_symbolnum' is the index of the symbol 124 * in the shared object's symbol list (`sdt_nzlist'), `rh_next' is 125 * the next symbol in the hash bucket (in case of collisions). 126 */ 127 struct rrs_hash { 128 int rh_symbolnum; /* Symbol number */ 129 int rh_next; /* Next hash entry */ 130 }; 131 132 /* 133 * `rt_symbols' is used to keep track of run-time allocated commons 134 * and data items copied from shared objects. 135 */ 136 struct rt_symbol { 137 struct nzlist *rt_sp; /* The symbol */ 138 struct rt_symbol *rt_next; /* Next in linear list */ 139 struct rt_symbol *rt_link; /* Next in bucket */ 140 caddr_t rt_srcaddr; /* Address of "master" copy */ 141 struct so_map *rt_smp; /* Originating map */ 142 }; 143 144 /* 145 * Debugger interface structure. 146 */ 147 struct so_debug { 148 int dd_version; /* Version # of interface */ 149 int dd_in_debugger; /* Set when run by debugger */ 150 int dd_sym_loaded; /* Run-time linking brought more 151 symbols into scope */ 152 char *dd_bpt_addr; /* Address of rtld-generated bpt */ 153 int dd_bpt_shadow; /* Original contents of bpt */ 154 struct rt_symbol *dd_cc; /* Allocated commons/copied data */ 155 }; 156 157 /* 158 * Version returned to crt0 from ld.so 159 */ 160 #define LDSO_VERSION_NONE 0 /* FreeBSD2.0, 2.0.5 */ 161 #define LDSO_VERSION_HAS_DLEXIT 1 /* includes dlexit in ld_entry */ 162 #define LDSO_VERSION_HAS_DLSYM3 2 /* includes 3-argument dlsym */ 163 #define LDSO_VERSION_HAS_DLADDR 3 /* includes dladdr in ld_entry */ 164 165 /* 166 * Entry points into ld.so - user interface to the run-time linker. 167 * Entries are valid for the given version numbers returned by ld.so 168 * to crt0. 169 */ 170 struct ld_entry { 171 void *(*dlopen) __P((const char *, int)); /* NONE */ 172 int (*dlclose) __P((void *)); /* NONE */ 173 void *(*dlsym) __P((void *, const char *)); /* NONE */ 174 const char *(*dlerror) __P((void)); /* NONE */ 175 void (*dlexit) __P((void)); /* HAS_DLEXIT */ 176 void *(*dlsym3) __P((void *, const char *, void *)); /* HAS_DLSYM3 */ 177 int (*dladdr) __P((const void *, 178 struct dl_info *)); /* HAS_DLADDR */ 179 }; 180 181 /* 182 * This is the structure pointed at by the __DYNAMIC symbol if an 183 * executable requires the attention of the run-time link editor. 184 * __DYNAMIC is given the value zero if no run-time linking needs to 185 * be done (it is always present in shared objects). 186 * The union `d_un' provides for different versions of the dynamic 187 * linking mechanism (switched on by `d_version'). The last version 188 * used by Sun is 3. We leave some room here and go to version number 189 * 8 for NetBSD, the main difference lying in the support for the 190 * `nz_list' type of symbols. 191 */ 192 193 struct _dynamic { 194 int d_version; /* version # of this interface */ 195 struct so_debug *d_debug; 196 union { 197 struct section_dispatch_table *d_sdt; 198 } d_un; 199 struct ld_entry *d_entry; /* XXX */ 200 }; 201 202 #define LD_VERSION_SUN (3) 203 #define LD_VERSION_BSD (8) 204 #define LD_VERSION_NZLIST_P(v) ((v) >= 8) 205 206 #define LD_GOT(x) ((x)->d_un.d_sdt->sdt_got) 207 #define LD_PLT(x) ((x)->d_un.d_sdt->sdt_plt) 208 #define LD_REL(x) ((x)->d_un.d_sdt->sdt_rel) 209 #define LD_SYMBOL(x) ((x)->d_un.d_sdt->sdt_nzlist) 210 #define LD_HASH(x) ((x)->d_un.d_sdt->sdt_hash) 211 #define LD_STRINGS(x) ((x)->d_un.d_sdt->sdt_strings) 212 #define LD_NEED(x) ((x)->d_un.d_sdt->sdt_sods) 213 #define LD_BUCKETS(x) ((x)->d_un.d_sdt->sdt_buckets) 214 #define LD_PATHS(x) ((x)->d_un.d_sdt->sdt_paths) 215 216 #define LD_GOTSZ(x) ((x)->d_un.d_sdt->sdt_plt - (x)->d_un.d_sdt->sdt_got) 217 #define LD_RELSZ(x) ((x)->d_un.d_sdt->sdt_hash - (x)->d_un.d_sdt->sdt_rel) 218 #define LD_HASHSZ(x) ((x)->d_un.d_sdt->sdt_nzlist - (x)->d_un.d_sdt->sdt_hash) 219 #define LD_STABSZ(x) ((x)->d_un.d_sdt->sdt_strings - (x)->d_un.d_sdt->sdt_nzlist) 220 #define LD_PLTSZ(x) ((x)->d_un.d_sdt->sdt_plt_sz) 221 #define LD_STRSZ(x) ((x)->d_un.d_sdt->sdt_str_sz) 222 #define LD_TEXTSZ(x) ((x)->d_un.d_sdt->sdt_text_sz) 223 224 /* 225 * Interface to ld.so 226 */ 227 struct crt_ldso { 228 int crt_ba; /* Base address of ld.so */ 229 int crt_dzfd; /* "/dev/zero" file descriptor (SunOS) */ 230 int crt_ldfd; /* ld.so file descriptor */ 231 struct _dynamic *crt_dp; /* Main's __DYNAMIC */ 232 char **crt_ep; /* environment strings */ 233 caddr_t crt_bp; /* Breakpoint if run from debugger */ 234 char *crt_prog; /* Program name (v3) */ 235 char *crt_ldso; /* Link editor name (v4) */ 236 struct ld_entry *crt_ldentry; /* dl*() access (v4) */ 237 char **crt_argv; /* argument strings (v5) */ 238 }; 239 240 /* 241 * Version passed from crt0 to ld.so (1st argument to _rtld()). 242 */ 243 #define CRT_VERSION_SUN 1 244 #define CRT_VERSION_BSD_2 2 245 #define CRT_VERSION_BSD_3 3 246 #define CRT_VERSION_BSD_4 4 247 #define CRT_VERSION_BSD_5 5 248 249 /* 250 * Maximum number of recognized shared object version numbers. 251 */ 252 #define MAXDEWEY 8 253 254 /* 255 * Header of the hints file. 256 */ 257 struct hints_header { 258 long hh_magic; 259 #define HH_MAGIC 011421044151 260 long hh_version; /* Interface version number */ 261 #define LD_HINTS_VERSION_1 1 262 #define LD_HINTS_VERSION_2 2 263 long hh_hashtab; /* Location of hash table */ 264 long hh_nbucket; /* Number of buckets in hashtab */ 265 long hh_strtab; /* Location of strings */ 266 long hh_strtab_sz; /* Size of strings */ 267 long hh_ehints; /* End of hints (max offset in file) */ 268 long hh_dirlist; /* Colon-separated list of srch dirs */ 269 }; 270 271 #define HH_BADMAG(hdr) ((hdr).hh_magic != HH_MAGIC) 272 273 /* 274 * Hash table element in hints file. 275 */ 276 struct hints_bucket { 277 /* namex and pathx are indices into the string table */ 278 int hi_namex; /* Library name */ 279 int hi_pathx; /* Full path */ 280 int hi_dewey[MAXDEWEY]; /* The versions */ 281 int hi_ndewey; /* Number of version numbers */ 282 #define hi_major hi_dewey[0] 283 #define hi_minor hi_dewey[1] 284 int hi_next; /* Next in this bucket */ 285 }; 286 287 #define _PATH_LD_HINTS "/var/run/ld.so.hints" 288 289 #endif /* _LINK_H_ */ 290