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