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