1 1.1 pk /* 2 1.1 pk * RRS section definitions. 3 1.1 pk * Nomenclature and, more importantly, the layout of the various 4 1.1 pk * data structures defined in this header file are borrowed from 5 1.1 pk * Sun Microsystems' original <link.h>, so we can provide compatibility 6 1.1 pk * with the SunOS 4.x shared library scheme. 7 1.1 pk * 8 1.1 pk * $Id: link_aout.h,v 1.1 1993/10/17 00:51:31 pk Exp $ 9 1.1 pk * (derived from: @(#)link.h 1.6 88/08/19 SMI 10 1.1 pk * Copyright (c) 1987 by Sun Microsystems, Inc.) 11 1.1 pk */ 12 1.1 pk 13 1.1 pk #ifndef _LINK_H_ 14 1.1 pk #define _LINK_H_ 15 1.1 pk 16 1.1 pk /* 17 1.1 pk * A `link_object' structure descibes a shared object that is needed 18 1.1 pk * to complete the link edit process of the object containing it. 19 1.1 pk * A list of such objects (chained through `lo_next') is pointed at 20 1.1 pk * by `ld_need' in the link_dynamic_2 structure. 21 1.1 pk */ 22 1.1 pk 23 1.1 pk struct link_object { 24 1.1 pk long lo_name; /* name (relative to load address) */ 25 1.1 pk u_int lo_library : 1, /* searched for by library rules */ 26 1.1 pk lo_unused : 31; 27 1.1 pk short lo_major; /* major version number */ 28 1.1 pk short lo_minor; /* minor version number */ 29 1.1 pk long lo_next; /* next one (often relative) */ 30 1.1 pk }; 31 1.1 pk 32 1.1 pk /* 33 1.1 pk * `link_maps' are used by the run-time link editor (ld.so) to keep 34 1.1 pk * track of all shared objects loaded into a process' address space. 35 1.1 pk * These structures are only used at run-time and do not occur within 36 1.1 pk * the text or data segment of an executable or shared library. 37 1.1 pk */ 38 1.1 pk struct link_map { 39 1.1 pk caddr_t lm_addr; /* address at which object mapped */ 40 1.1 pk char *lm_name; /* full name of loaded object */ 41 1.1 pk struct link_map *lm_next; /* next object in map */ 42 1.1 pk struct link_object *lm_lop; /* link object that got us here */ 43 1.1 pk caddr_t lm_lob; /* base address for said link object */ 44 1.1 pk u_int lm_rwt : 1; /* text is read/write */ 45 1.1 pk struct link_dynamic *lm_ld; /* dynamic structure */ 46 1.1 pk caddr_t lm_lpd; /* loader private data */ 47 1.1 pk }; 48 1.1 pk 49 1.1 pk /* 50 1.1 pk * Symbol description with size. This is simply an `nlist' with 51 1.1 pk * one field (nz_size) added. 52 1.1 pk * Used to convey size information on items in the data segment 53 1.1 pk * of shared objects. An array of these live in the shared object's 54 1.1 pk * text segment and is address by the `ld_symbols' field. 55 1.1 pk */ 56 1.1 pk struct nzlist { 57 1.1 pk struct nlist nlist; 58 1.1 pk u_long nz_size; 59 1.1 pk #define nz_un nlist.n_un 60 1.1 pk #define nz_strx nlist.n_un.n_strx 61 1.1 pk #define nz_name nlist.n_un.n_name 62 1.1 pk #define nz_type nlist.n_type 63 1.1 pk #define nz_value nlist.n_value 64 1.1 pk #define nz_desc nlist.n_desc 65 1.1 pk #define nz_other nlist.n_other 66 1.1 pk }; 67 1.1 pk 68 1.1 pk /* 69 1.1 pk * The `link_dynamic_2' structure contains offsets to various data 70 1.1 pk * structures needed to do run-time relocation. 71 1.1 pk */ 72 1.1 pk struct link_dynamic_2 { 73 1.1 pk struct link_map *ld_loaded; /* list of loaded objects */ 74 1.1 pk long ld_need; /* list of needed objects */ 75 1.1 pk long ld_rules; /* search rules for library objects */ 76 1.1 pk long ld_got; /* global offset table */ 77 1.1 pk long ld_plt; /* procedure linkage table */ 78 1.1 pk long ld_rel; /* relocation table */ 79 1.1 pk long ld_hash; /* symbol hash table */ 80 1.1 pk long ld_symbols; /* symbol table itself */ 81 1.1 pk long (*ld_stab_hash)(); /* "pointer" to symbol hash function */ 82 1.1 pk long ld_buckets; /* number of hash buckets */ 83 1.1 pk long ld_strings; /* symbol strings */ 84 1.1 pk long ld_str_sz; /* size of symbol strings */ 85 1.1 pk long ld_text_sz; /* size of text area */ 86 1.1 pk long ld_plt_sz; /* size of procedure linkage table */ 87 1.1 pk }; 88 1.1 pk 89 1.1 pk /* 90 1.1 pk * RRS symbol hash table, addressed by `ld_hash' in link_dynamic_2 91 1.1 pk * Used to quickly lookup symbols of the shared object by hashing 92 1.1 pk * on the symbol's name. `rh_symbolnum' is the index of the symbol 93 1.1 pk * in the shared object's symbol list (`ld_symbols'), `rh_next' is 94 1.1 pk * the next symbol in the hash bucket (in case of collisions). 95 1.1 pk */ 96 1.1 pk struct rrs_hash { 97 1.1 pk int rh_symbolnum; /* symbol number */ 98 1.1 pk int rh_next; /* next hash entry */ 99 1.1 pk }; 100 1.1 pk 101 1.1 pk /* 102 1.1 pk * `rt_symbols' is used to keep track of run-time allocated commons 103 1.1 pk * and data items copied from shared objects. 104 1.1 pk */ 105 1.1 pk struct rt_symbol { 106 1.1 pk struct nzlist *rt_sp; /* the symbol */ 107 1.1 pk struct rt_symbol *rt_next; /* next in linear list */ 108 1.1 pk struct rt_symbol *rt_link; /* next in bucket */ 109 1.1 pk caddr_t rt_srcaddr; /* address of "master" copy */ 110 1.1 pk }; 111 1.1 pk 112 1.1 pk /* 113 1.1 pk * Debugger interface structure. 114 1.1 pk */ 115 1.1 pk struct ld_debug { 116 1.1 pk int ldd_version; /* version # of interface */ 117 1.1 pk int ldd_in_debugger; /* a debugger is running us */ 118 1.1 pk int ldd_sym_loaded; /* we loaded some symbols */ 119 1.1 pk char *ldd_bp_addr; /* place for ld-generated bpt */ 120 1.1 pk int ldd_bp_inst; /* instruction which was there */ 121 1.1 pk struct rt_symbol *ldd_cp; /* commons we built */ 122 1.1 pk }; 123 1.1 pk 124 1.1 pk /* 125 1.1 pk * Entry points into ld.so - user interface to the run-time linker. 126 1.1 pk * (see also libdl.a) 127 1.1 pk */ 128 1.1 pk struct ld_entry { 129 1.1 pk int (*dlopen)(); 130 1.1 pk int (*dlclose)(); 131 1.1 pk int (*dlsym)(); 132 1.1 pk }; 133 1.1 pk 134 1.1 pk /* 135 1.1 pk * This is the structure pointed at by the __DYNAMIC symbol if an 136 1.1 pk * executable requires the attention of the run-time link editor. 137 1.1 pk * __DYNAMIC is given the value zero if no run-time linking needs to 138 1.1 pk * be done (it is always present in shared objects). 139 1.1 pk * The union `ld_un' provides for different versions of the dynamic 140 1.1 pk * linking mechanism (switched on by `ld_version'). The last version 141 1.1 pk * used by Sun is 3. We leave some room here and go to version number 142 1.1 pk * 8 for NetBSD, the main difference lying in the support for the 143 1.1 pk * `nz_list' type of symbols. 144 1.1 pk */ 145 1.1 pk 146 1.1 pk struct link_dynamic { 147 1.1 pk int ld_version; /* version # of this structure */ 148 1.1 pk struct ld_debug *ldd; 149 1.1 pk union { 150 1.1 pk struct link_dynamic_2 *ld_2; 151 1.1 pk } ld_un; 152 1.1 pk struct ld_entry *ld_entry; 153 1.1 pk }; 154 1.1 pk 155 1.1 pk #define LD_VERSION_SUN (3) 156 1.1 pk #define LD_VERSION_BSD (8) 157 1.1 pk #define LD_VERSION_NZLIST_P(v) ((v) >= 8) 158 1.1 pk 159 1.1 pk #define LD_GOT(x) ((x)->ld_un.ld_2->ld_got) 160 1.1 pk #define LD_PLT(x) ((x)->ld_un.ld_2->ld_plt) 161 1.1 pk #define LD_REL(x) ((x)->ld_un.ld_2->ld_rel) 162 1.1 pk #define LD_SYMBOL(x) ((x)->ld_un.ld_2->ld_symbols) 163 1.1 pk #define LD_HASH(x) ((x)->ld_un.ld_2->ld_hash) 164 1.1 pk #define LD_STRINGS(x) ((x)->ld_un.ld_2->ld_strings) 165 1.1 pk #define LD_NEED(x) ((x)->ld_un.ld_2->ld_need) 166 1.1 pk #define LD_BUCKETS(x) ((x)->ld_un.ld_2->ld_buckets) 167 1.1 pk 168 1.1 pk #define LD_GOTSZ(x) ((x)->ld_un.ld_2->ld_plt - (x)->ld_un.ld_2->ld_got) 169 1.1 pk #define LD_RELSZ(x) ((x)->ld_un.ld_2->ld_hash - (x)->ld_un.ld_2->ld_rel) 170 1.1 pk #define LD_HASHSZ(x) ((x)->ld_un.ld_2->ld_symbols - (x)->ld_un.ld_2->ld_hash) 171 1.1 pk #define LD_STABSZ(x) ((x)->ld_un.ld_2->ld_strings - (x)->ld_un.ld_2->ld_symbols) 172 1.1 pk #define LD_PLTSZ(x) ((x)->ld_un.ld_2->ld_plt_sz) 173 1.1 pk #define LD_STRSZ(x) ((x)->ld_un.ld_2->ld_str_sz) 174 1.1 pk #define LD_TEXTSZ(x) ((x)->ld_un.ld_2->ld_text_sz) 175 1.1 pk 176 1.1 pk /* 177 1.1 pk * Interface to ld.so (see link(5)) 178 1.1 pk */ 179 1.1 pk struct crt_ldso { 180 1.1 pk int crt_ba; /* Base address of ld.so */ 181 1.1 pk int crt_dzfd; /* "/dev/zero" file decriptor (SunOS) */ 182 1.1 pk int crt_ldfd; /* ld.so file descriptor */ 183 1.1 pk struct link_dynamic *crt_dp;/* Main's __DYNAMIC */ 184 1.1 pk char **crt_ep; /* environment strings */ 185 1.1 pk caddr_t crt_bp; /* Breakpoint if run from debugger */ 186 1.1 pk }; 187 1.1 pk 188 1.1 pk /* 189 1.1 pk * Version passed from crt0 to ld.so (1st argument to _rtld()). 190 1.1 pk */ 191 1.1 pk #define CRT_VERSION_SUN 1 192 1.1 pk #define CRT_VERSION_BSD 2 193 1.1 pk 194 1.1 pk #endif /* _LINK_H_ */ 195 1.1 pk 196