link.h revision 697
1697Spaul/* 2697Spaul * RRS section definitions. 3697Spaul * Nomenclature and, more importantly, the layout of the various 4697Spaul * data structures defined in this header file are borrowed from 5697Spaul * Sun Microsystems' original <link.h>, so we can provide compatibility 6697Spaul * with the SunOS 4.x shared library scheme. 7697Spaul * 8697Spaul * $Id: link.h,v 1.2 1993/10/22 21:04:19 pk Exp $ 9697Spaul * (derived from: @(#)link.h 1.6 88/08/19 SMI 10697Spaul * Copyright (c) 1987 by Sun Microsystems, Inc.) 11697Spaul */ 12697Spaul 13697Spaul#ifndef _LINK_H_ 14697Spaul#define _LINK_H_ 15697Spaul 16697Spaul/* 17697Spaul * A `link_object' structure descibes a shared object that is needed 18697Spaul * to complete the link edit process of the object containing it. 19697Spaul * A list of such objects (chained through `lo_next') is pointed at 20697Spaul * by `ld_need' in the link_dynamic_2 structure. 21697Spaul */ 22697Spaul 23697Spaulstruct link_object { 24697Spaul long lo_name; /* name (relative to load address) */ 25697Spaul u_int lo_library : 1, /* searched for by library rules */ 26697Spaul lo_unused : 31; 27697Spaul short lo_major; /* major version number */ 28697Spaul short lo_minor; /* minor version number */ 29697Spaul long lo_next; /* next one (often relative) */ 30697Spaul}; 31697Spaul 32697Spaul/* 33697Spaul * `link_maps' are used by the run-time link editor (ld.so) to keep 34697Spaul * track of all shared objects loaded into a process' address space. 35697Spaul * These structures are only used at run-time and do not occur within 36697Spaul * the text or data segment of an executable or shared library. 37697Spaul */ 38697Spaulstruct link_map { 39697Spaul caddr_t lm_addr; /* address at which object mapped */ 40697Spaul char *lm_name; /* full name of loaded object */ 41697Spaul struct link_map *lm_next; /* next object in map */ 42697Spaul struct link_object *lm_lop; /* link object that got us here */ 43697Spaul caddr_t lm_lob; /* base address for said link object */ 44697Spaul u_int lm_rwt : 1; /* text is read/write */ 45697Spaul struct link_dynamic *lm_ld; /* dynamic structure */ 46697Spaul caddr_t lm_lpd; /* loader private data */ 47697Spaul}; 48697Spaul 49697Spaul/* 50697Spaul * Symbol description with size. This is simply an `nlist' with 51697Spaul * one field (nz_size) added. 52697Spaul * Used to convey size information on items in the data segment 53697Spaul * of shared objects. An array of these live in the shared object's 54697Spaul * text segment and is address by the `ld_symbols' field. 55697Spaul */ 56697Spaulstruct nzlist { 57697Spaul struct nlist nlist; 58697Spaul u_long nz_size; 59697Spaul#define nz_un nlist.n_un 60697Spaul#define nz_strx nlist.n_un.n_strx 61697Spaul#define nz_name nlist.n_un.n_name 62697Spaul#define nz_type nlist.n_type 63697Spaul#define nz_value nlist.n_value 64697Spaul#define nz_desc nlist.n_desc 65697Spaul#define nz_other nlist.n_other 66697Spaul}; 67697Spaul 68697Spaul/* 69697Spaul * The `link_dynamic_2' structure contains offsets to various data 70697Spaul * structures needed to do run-time relocation. 71697Spaul */ 72697Spaulstruct link_dynamic_2 { 73697Spaul struct link_map *ld_loaded; /* list of loaded objects */ 74697Spaul long ld_need; /* list of needed objects */ 75697Spaul long ld_rules; /* search rules for library objects */ 76697Spaul long ld_got; /* global offset table */ 77697Spaul long ld_plt; /* procedure linkage table */ 78697Spaul long ld_rel; /* relocation table */ 79697Spaul long ld_hash; /* symbol hash table */ 80697Spaul long ld_symbols; /* symbol table itself */ 81697Spaul long (*ld_stab_hash)(); /* "pointer" to symbol hash function */ 82697Spaul long ld_buckets; /* number of hash buckets */ 83697Spaul long ld_strings; /* symbol strings */ 84697Spaul long ld_str_sz; /* size of symbol strings */ 85697Spaul long ld_text_sz; /* size of text area */ 86697Spaul long ld_plt_sz; /* size of procedure linkage table */ 87697Spaul}; 88697Spaul 89697Spaul/* 90697Spaul * RRS symbol hash table, addressed by `ld_hash' in link_dynamic_2 91697Spaul * Used to quickly lookup symbols of the shared object by hashing 92697Spaul * on the symbol's name. `rh_symbolnum' is the index of the symbol 93697Spaul * in the shared object's symbol list (`ld_symbols'), `rh_next' is 94697Spaul * the next symbol in the hash bucket (in case of collisions). 95697Spaul */ 96697Spaulstruct rrs_hash { 97697Spaul int rh_symbolnum; /* symbol number */ 98697Spaul int rh_next; /* next hash entry */ 99697Spaul}; 100697Spaul 101697Spaul/* 102697Spaul * `rt_symbols' is used to keep track of run-time allocated commons 103697Spaul * and data items copied from shared objects. 104697Spaul */ 105697Spaulstruct rt_symbol { 106697Spaul struct nzlist *rt_sp; /* the symbol */ 107697Spaul struct rt_symbol *rt_next; /* next in linear list */ 108697Spaul struct rt_symbol *rt_link; /* next in bucket */ 109697Spaul caddr_t rt_srcaddr; /* address of "master" copy */ 110697Spaul}; 111697Spaul 112697Spaul/* 113697Spaul * Debugger interface structure. 114697Spaul */ 115697Spaulstruct ld_debug { 116697Spaul int ldd_version; /* version # of interface */ 117697Spaul int ldd_in_debugger; /* a debugger is running us */ 118697Spaul int ldd_sym_loaded; /* we loaded some symbols */ 119697Spaul char *ldd_bp_addr; /* place for ld-generated bpt */ 120697Spaul int ldd_bp_inst; /* instruction which was there */ 121697Spaul struct rt_symbol *ldd_cp; /* commons we built */ 122697Spaul}; 123697Spaul 124697Spaul/* 125697Spaul * Entry points into ld.so - user interface to the run-time linker. 126697Spaul * (see also libdl.a) 127697Spaul */ 128697Spaulstruct ld_entry { 129697Spaul int (*dlopen)(); 130697Spaul int (*dlclose)(); 131697Spaul int (*dlsym)(); 132697Spaul}; 133697Spaul 134697Spaul/* 135697Spaul * This is the structure pointed at by the __DYNAMIC symbol if an 136697Spaul * executable requires the attention of the run-time link editor. 137697Spaul * __DYNAMIC is given the value zero if no run-time linking needs to 138697Spaul * be done (it is always present in shared objects). 139697Spaul * The union `ld_un' provides for different versions of the dynamic 140697Spaul * linking mechanism (switched on by `ld_version'). The last version 141697Spaul * used by Sun is 3. We leave some room here and go to version number 142697Spaul * 8 for NetBSD, the main difference lying in the support for the 143697Spaul * `nz_list' type of symbols. 144697Spaul */ 145697Spaul 146697Spaulstruct link_dynamic { 147697Spaul int ld_version; /* version # of this structure */ 148697Spaul struct ld_debug *ldd; 149697Spaul union { 150697Spaul struct link_dynamic_2 *ld_2; 151697Spaul } ld_un; 152697Spaul struct ld_entry *ld_entry; 153697Spaul}; 154697Spaul 155697Spaul#define LD_VERSION_SUN (3) 156697Spaul#define LD_VERSION_BSD (8) 157697Spaul#define LD_VERSION_NZLIST_P(v) ((v) >= 8) 158697Spaul 159697Spaul#define LD_GOT(x) ((x)->ld_un.ld_2->ld_got) 160697Spaul#define LD_PLT(x) ((x)->ld_un.ld_2->ld_plt) 161697Spaul#define LD_REL(x) ((x)->ld_un.ld_2->ld_rel) 162697Spaul#define LD_SYMBOL(x) ((x)->ld_un.ld_2->ld_symbols) 163697Spaul#define LD_HASH(x) ((x)->ld_un.ld_2->ld_hash) 164697Spaul#define LD_STRINGS(x) ((x)->ld_un.ld_2->ld_strings) 165697Spaul#define LD_NEED(x) ((x)->ld_un.ld_2->ld_need) 166697Spaul#define LD_BUCKETS(x) ((x)->ld_un.ld_2->ld_buckets) 167697Spaul 168697Spaul#define LD_GOTSZ(x) ((x)->ld_un.ld_2->ld_plt - (x)->ld_un.ld_2->ld_got) 169697Spaul#define LD_RELSZ(x) ((x)->ld_un.ld_2->ld_hash - (x)->ld_un.ld_2->ld_rel) 170697Spaul#define LD_HASHSZ(x) ((x)->ld_un.ld_2->ld_symbols - (x)->ld_un.ld_2->ld_hash) 171697Spaul#define LD_STABSZ(x) ((x)->ld_un.ld_2->ld_strings - (x)->ld_un.ld_2->ld_symbols) 172697Spaul#define LD_PLTSZ(x) ((x)->ld_un.ld_2->ld_plt_sz) 173697Spaul#define LD_STRSZ(x) ((x)->ld_un.ld_2->ld_str_sz) 174697Spaul#define LD_TEXTSZ(x) ((x)->ld_un.ld_2->ld_text_sz) 175697Spaul 176697Spaul/* 177697Spaul * Interface to ld.so (see link(5)) 178697Spaul */ 179697Spaulstruct crt_ldso { 180697Spaul int crt_ba; /* Base address of ld.so */ 181697Spaul int crt_dzfd; /* "/dev/zero" file decriptor (SunOS) */ 182697Spaul int crt_ldfd; /* ld.so file descriptor */ 183697Spaul struct link_dynamic *crt_dp;/* Main's __DYNAMIC */ 184697Spaul char **crt_ep; /* environment strings */ 185697Spaul caddr_t crt_bp; /* Breakpoint if run from debugger */ 186697Spaul}; 187697Spaul 188697Spaul/* 189697Spaul * Version passed from crt0 to ld.so (1st argument to _rtld()). 190697Spaul */ 191697Spaul#define CRT_VERSION_SUN 1 192697Spaul#define CRT_VERSION_BSD 2 193697Spaul 194697Spaul 195697Spaul/* 196697Spaul * Maximum number of recognized shared object version numbers. 197697Spaul */ 198697Spaul#define MAXDEWEY 8 199697Spaul 200697Spaul/* 201697Spaul * Header of the hints file. 202697Spaul */ 203697Spaulstruct hints_header { 204697Spaul long hh_magic; 205697Spaul#define HH_MAGIC 011421044151 206697Spaul long hh_version; /* Interface version number */ 207697Spaul#define LD_HINTS_VERSION_1 1 208697Spaul long hh_hashtab; /* Location of hash table */ 209697Spaul long hh_nbucket; /* Number of buckets in hashtab */ 210697Spaul long hh_strtab; /* Location of strings */ 211697Spaul long hh_strtab_sz; /* Size of strings */ 212697Spaul long hh_ehints; /* End of hints (max offset in file) */ 213697Spaul}; 214697Spaul 215697Spaul#define HH_BADMAG(hdr) ((hdr).hh_magic != HH_MAGIC) 216697Spaul 217697Spaul/* 218697Spaul * Hash table element in hints file. 219697Spaul */ 220697Spaulstruct hints_bucket { 221697Spaul /* namex and pathx are indices into the string table */ 222697Spaul int hi_namex; /* Library name */ 223697Spaul int hi_pathx; /* Full path */ 224697Spaul int hi_dewey[MAXDEWEY]; /* The versions */ 225697Spaul int hi_ndewey; /* Number of version numbers */ 226697Spaul#define hi_major hi_dewey[0] 227697Spaul#define hi_minor hi_dewey[1] 228697Spaul int hi_next; /* Next in this bucket */ 229697Spaul}; 230697Spaul 231697Spaul#define _PATH_LD_HINTS "/var/run/ld.so.hints" 232697Spaul 233697Spaul#endif /* _LINK_H_ */ 234697Spaul 235