link.h revision 27838
1697Spaul/* 21156Sjkh * Copyright (c) 1993 Paul Kranenburg 31156Sjkh * All rights reserved. 41156Sjkh * 51156Sjkh * Redistribution and use in source and binary forms, with or without 61156Sjkh * modification, are permitted provided that the following conditions 71156Sjkh * are met: 81156Sjkh * 1. Redistributions of source code must retain the above copyright 91156Sjkh * notice, this list of conditions and the following disclaimer. 101156Sjkh * 2. Redistributions in binary form must reproduce the above copyright 111156Sjkh * notice, this list of conditions and the following disclaimer in the 121156Sjkh * documentation and/or other materials provided with the distribution. 131156Sjkh * 3. All advertising materials mentioning features or use of this software 141156Sjkh * must display the following acknowledgement: 151156Sjkh * This product includes software developed by Paul Kranenburg. 161156Sjkh * 4. The name of the author may not be used to endorse or promote products 1713771Smpp * derived from this software without specific prior written permission 181156Sjkh * 191156Sjkh * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR 201156Sjkh * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES 211156Sjkh * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 221156Sjkh * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, 231156Sjkh * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT 241156Sjkh * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 251156Sjkh * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 261156Sjkh * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 271156Sjkh * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF 281156Sjkh * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 291156Sjkh * 3027838Sjdp * $Id: link.h,v 1.13 1997/05/07 20:00:00 eivind Exp $ 311156Sjkh */ 321156Sjkh 331156Sjkh/* 34697Spaul * RRS section definitions. 35697Spaul * 361156Sjkh * The layout of some data structures defined in this header file is 371156Sjkh * such that we can provide compatibility with the SunOS 4.x shared 381156Sjkh * library scheme. 39697Spaul */ 40697Spaul 41697Spaul#ifndef _LINK_H_ 42697Spaul#define _LINK_H_ 43697Spaul 44697Spaul/* 4513771Smpp * A `Shared Object Descriptor' describes a shared object that is needed 46697Spaul * to complete the link edit process of the object containing it. 471156Sjkh * A list of such objects (chained through `sod_next') is pointed at 481156Sjkh * by `sdt_sods' in the section_dispatch_table structure. 49697Spaul */ 50697Spaul 511156Sjkhstruct sod { /* Shared Object Descriptor */ 521156Sjkh long sod_name; /* name (relative to load address) */ 531156Sjkh u_int sod_library : 1, /* Searched for by library rules */ 541156Sjkh sod_reserved : 31; 551156Sjkh short sod_major; /* major version number */ 561156Sjkh short sod_minor; /* minor version number */ 571156Sjkh long sod_next; /* next sod */ 58697Spaul}; 59697Spaul 60697Spaul/* 611156Sjkh * `Shared Object Map's are used by the run-time link editor (ld.so) to 621156Sjkh * keep track of all shared objects loaded into a process' address space. 63697Spaul * These structures are only used at run-time and do not occur within 64697Spaul * the text or data segment of an executable or shared library. 65697Spaul */ 661156Sjkhstruct so_map { /* Shared Object Map */ 671156Sjkh caddr_t som_addr; /* Address at which object mapped */ 681156Sjkh char *som_path; /* Path to mmap'ed file */ 691156Sjkh struct so_map *som_next; /* Next map in chain */ 701156Sjkh struct sod *som_sod; /* Sod responsible for this map */ 711156Sjkh caddr_t som_sodbase; /* Base address of this sod */ 721156Sjkh u_int som_write : 1; /* Text is currently writable */ 731156Sjkh struct _dynamic *som_dynamic; /* _dynamic structure */ 741156Sjkh caddr_t som_spd; /* Private data */ 75697Spaul}; 76697Spaul 77697Spaul/* 78697Spaul * Symbol description with size. This is simply an `nlist' with 79697Spaul * one field (nz_size) added. 80697Spaul * Used to convey size information on items in the data segment 81697Spaul * of shared objects. An array of these live in the shared object's 821156Sjkh * text segment and is addressed by the `sdt_nzlist' field. 83697Spaul */ 84697Spaulstruct nzlist { 85697Spaul struct nlist nlist; 86697Spaul u_long nz_size; 87697Spaul#define nz_un nlist.n_un 88697Spaul#define nz_strx nlist.n_un.n_strx 89697Spaul#define nz_name nlist.n_un.n_name 90697Spaul#define nz_type nlist.n_type 91697Spaul#define nz_value nlist.n_value 92697Spaul#define nz_desc nlist.n_desc 93697Spaul#define nz_other nlist.n_other 94697Spaul}; 95697Spaul 961156Sjkh#define N_AUX(p) ((p)->n_other & 0xf) 976887Snate#define N_BIND(p) (((unsigned int)(p)->n_other >> 4) & 0xf) 981156Sjkh#define N_OTHER(r, v) (((unsigned int)(r) << 4) | ((v) & 0xf)) 991156Sjkh 1001156Sjkh#define AUX_OBJECT 1 1011156Sjkh#define AUX_FUNC 2 1026887Snate/*#define BIND_LOCAL 0 not used */ 1036887Snate/*#define BIND_GLOBAL 1 not used */ 1046887Snate#define BIND_WEAK 2 1051156Sjkh 1061156Sjkh 107697Spaul/* 1081156Sjkh * The `section_dispatch_table' structure contains offsets to various data 109697Spaul * structures needed to do run-time relocation. 110697Spaul */ 1111156Sjkhstruct section_dispatch_table { 1121156Sjkh struct so_map *sdt_loaded; /* List of loaded objects */ 1131156Sjkh long sdt_sods; /* List of shared objects descriptors */ 11418591Speter long sdt_paths; /* Library search paths */ 1151156Sjkh long sdt_got; /* Global offset table */ 1161156Sjkh long sdt_plt; /* Procedure linkage table */ 1171156Sjkh long sdt_rel; /* Relocation table */ 1181156Sjkh long sdt_hash; /* Symbol hash table */ 1191156Sjkh long sdt_nzlist; /* Symbol table itself */ 1201156Sjkh long sdt_filler2; /* Unused (was: stab_hash) */ 1211156Sjkh long sdt_buckets; /* Number of hash buckets */ 1221156Sjkh long sdt_strings; /* Symbol strings */ 1231156Sjkh long sdt_str_sz; /* Size of symbol strings */ 1241156Sjkh long sdt_text_sz; /* Size of text area */ 1251156Sjkh long sdt_plt_sz; /* Size of procedure linkage table */ 126697Spaul}; 127697Spaul 128697Spaul/* 1291156Sjkh * RRS symbol hash table, addressed by `sdt_hash' in section_dispatch_table. 130697Spaul * Used to quickly lookup symbols of the shared object by hashing 131697Spaul * on the symbol's name. `rh_symbolnum' is the index of the symbol 1321156Sjkh * in the shared object's symbol list (`sdt_nzlist'), `rh_next' is 133697Spaul * the next symbol in the hash bucket (in case of collisions). 134697Spaul */ 135697Spaulstruct rrs_hash { 1361156Sjkh int rh_symbolnum; /* Symbol number */ 1371156Sjkh int rh_next; /* Next hash entry */ 138697Spaul}; 139697Spaul 140697Spaul/* 141697Spaul * `rt_symbols' is used to keep track of run-time allocated commons 142697Spaul * and data items copied from shared objects. 143697Spaul */ 144697Spaulstruct rt_symbol { 1451156Sjkh struct nzlist *rt_sp; /* The symbol */ 1461156Sjkh struct rt_symbol *rt_next; /* Next in linear list */ 1471156Sjkh struct rt_symbol *rt_link; /* Next in bucket */ 1481156Sjkh caddr_t rt_srcaddr; /* Address of "master" copy */ 1491156Sjkh struct so_map *rt_smp; /* Originating map */ 150697Spaul}; 151697Spaul 152697Spaul/* 153697Spaul * Debugger interface structure. 154697Spaul */ 1551156Sjkhstruct so_debug { 1561156Sjkh int dd_version; /* Version # of interface */ 1571156Sjkh int dd_in_debugger; /* Set when run by debugger */ 1581156Sjkh int dd_sym_loaded; /* Run-time linking brought more 1591156Sjkh symbols into scope */ 1601156Sjkh char *dd_bpt_addr; /* Address of rtld-generated bpt */ 1611156Sjkh int dd_bpt_shadow; /* Original contents of bpt */ 1621156Sjkh struct rt_symbol *dd_cc; /* Allocated commons/copied data */ 163697Spaul}; 164697Spaul 165697Spaul/* 1669335Sdfr * Version returned to crt0 from ld.so 1679335Sdfr */ 1689335Sdfr#define LDSO_VERSION_NONE 0 /* FreeBSD2.0, 2.0.5 */ 1699335Sdfr#define LDSO_VERSION_HAS_DLEXIT 1 /* includes dlexit in ld_entry */ 17027838Sjdp#define LDSO_VERSION_HAS_DLSYM3 2 /* includes 3-argument dlsym */ 1719335Sdfr 1729335Sdfr/* 173697Spaul * Entry points into ld.so - user interface to the run-time linker. 1749335Sdfr * Entries are valid for the given version numbers returned by ld.so 1759335Sdfr * to crt0. 176697Spaul */ 177697Spaulstruct ld_entry { 1789335Sdfr void *(*dlopen) __P((char *, int)); /* NONE */ 1799335Sdfr int (*dlclose) __P((void *)); /* NONE */ 1809335Sdfr void *(*dlsym) __P((void *, char *)); /* NONE */ 1819335Sdfr char *(*dlerror) __P((void)); /* NONE */ 1829335Sdfr void (*dlexit) __P((void)); /* HAS_DLEXIT */ 18327838Sjdp void *(*dlsym3) __P((void *, char *, void *)); /* HAS_DLSYM3 */ 184697Spaul}; 185697Spaul 186697Spaul/* 1871156Sjkh * dl*() prototypes. 1881156Sjkh */ 18918801Sscrappyextern void *dlopen __P((char *, int)); 1901156Sjkhextern int dlclose __P((void *)); 19118801Sscrappyextern void *dlsym __P((void *, char *)); 1926232Sjkhextern char *dlerror __P((void)); 1931156Sjkh 1941156Sjkh 1951156Sjkh/* 196697Spaul * This is the structure pointed at by the __DYNAMIC symbol if an 197697Spaul * executable requires the attention of the run-time link editor. 198697Spaul * __DYNAMIC is given the value zero if no run-time linking needs to 199697Spaul * be done (it is always present in shared objects). 2001156Sjkh * The union `d_un' provides for different versions of the dynamic 2011156Sjkh * linking mechanism (switched on by `d_version'). The last version 202697Spaul * used by Sun is 3. We leave some room here and go to version number 203697Spaul * 8 for NetBSD, the main difference lying in the support for the 204697Spaul * `nz_list' type of symbols. 205697Spaul */ 206697Spaul 2071156Sjkhstruct _dynamic { 2081156Sjkh int d_version; /* version # of this interface */ 2091156Sjkh struct so_debug *d_debug; 210697Spaul union { 2111156Sjkh struct section_dispatch_table *d_sdt; 2121156Sjkh } d_un; 2136887Snate struct ld_entry *d_entry; /* XXX */ 214697Spaul}; 215697Spaul 216697Spaul#define LD_VERSION_SUN (3) 217697Spaul#define LD_VERSION_BSD (8) 218697Spaul#define LD_VERSION_NZLIST_P(v) ((v) >= 8) 219697Spaul 2201156Sjkh#define LD_GOT(x) ((x)->d_un.d_sdt->sdt_got) 2211156Sjkh#define LD_PLT(x) ((x)->d_un.d_sdt->sdt_plt) 2221156Sjkh#define LD_REL(x) ((x)->d_un.d_sdt->sdt_rel) 2231156Sjkh#define LD_SYMBOL(x) ((x)->d_un.d_sdt->sdt_nzlist) 2241156Sjkh#define LD_HASH(x) ((x)->d_un.d_sdt->sdt_hash) 2251156Sjkh#define LD_STRINGS(x) ((x)->d_un.d_sdt->sdt_strings) 2261156Sjkh#define LD_NEED(x) ((x)->d_un.d_sdt->sdt_sods) 2271156Sjkh#define LD_BUCKETS(x) ((x)->d_un.d_sdt->sdt_buckets) 22818591Speter#define LD_PATHS(x) ((x)->d_un.d_sdt->sdt_paths) 229697Spaul 2301156Sjkh#define LD_GOTSZ(x) ((x)->d_un.d_sdt->sdt_plt - (x)->d_un.d_sdt->sdt_got) 2311156Sjkh#define LD_RELSZ(x) ((x)->d_un.d_sdt->sdt_hash - (x)->d_un.d_sdt->sdt_rel) 2321156Sjkh#define LD_HASHSZ(x) ((x)->d_un.d_sdt->sdt_nzlist - (x)->d_un.d_sdt->sdt_hash) 2331156Sjkh#define LD_STABSZ(x) ((x)->d_un.d_sdt->sdt_strings - (x)->d_un.d_sdt->sdt_nzlist) 2341156Sjkh#define LD_PLTSZ(x) ((x)->d_un.d_sdt->sdt_plt_sz) 2351156Sjkh#define LD_STRSZ(x) ((x)->d_un.d_sdt->sdt_str_sz) 2361156Sjkh#define LD_TEXTSZ(x) ((x)->d_un.d_sdt->sdt_text_sz) 237697Spaul 238697Spaul/* 2391156Sjkh * Interface to ld.so 240697Spaul */ 241697Spaulstruct crt_ldso { 242697Spaul int crt_ba; /* Base address of ld.so */ 24313771Smpp int crt_dzfd; /* "/dev/zero" file descriptor (SunOS) */ 244697Spaul int crt_ldfd; /* ld.so file descriptor */ 2451156Sjkh struct _dynamic *crt_dp; /* Main's __DYNAMIC */ 246697Spaul char **crt_ep; /* environment strings */ 247697Spaul caddr_t crt_bp; /* Breakpoint if run from debugger */ 2486887Snate char *crt_prog; /* Program name (v3) */ 2496887Snate char *crt_ldso; /* Link editor name (v4) */ 2506887Snate struct ld_entry *crt_ldentry; /* dl*() access (v4) */ 251697Spaul}; 252697Spaul 253697Spaul/* 254697Spaul * Version passed from crt0 to ld.so (1st argument to _rtld()). 255697Spaul */ 256697Spaul#define CRT_VERSION_SUN 1 2571156Sjkh#define CRT_VERSION_BSD_2 2 2581156Sjkh#define CRT_VERSION_BSD_3 3 2596887Snate#define CRT_VERSION_BSD_4 4 260697Spaul 261697Spaul/* 262697Spaul * Maximum number of recognized shared object version numbers. 263697Spaul */ 264697Spaul#define MAXDEWEY 8 265697Spaul 266697Spaul/* 267697Spaul * Header of the hints file. 268697Spaul */ 269697Spaulstruct hints_header { 270697Spaul long hh_magic; 271697Spaul#define HH_MAGIC 011421044151 272697Spaul long hh_version; /* Interface version number */ 273697Spaul#define LD_HINTS_VERSION_1 1 27418591Speter#define LD_HINTS_VERSION_2 2 275697Spaul long hh_hashtab; /* Location of hash table */ 276697Spaul long hh_nbucket; /* Number of buckets in hashtab */ 277697Spaul long hh_strtab; /* Location of strings */ 278697Spaul long hh_strtab_sz; /* Size of strings */ 279697Spaul long hh_ehints; /* End of hints (max offset in file) */ 28018591Speter long hh_dirlist; /* Colon-separated list of srch dirs */ 281697Spaul}; 282697Spaul 283697Spaul#define HH_BADMAG(hdr) ((hdr).hh_magic != HH_MAGIC) 284697Spaul 285697Spaul/* 286697Spaul * Hash table element in hints file. 287697Spaul */ 288697Spaulstruct hints_bucket { 289697Spaul /* namex and pathx are indices into the string table */ 290697Spaul int hi_namex; /* Library name */ 291697Spaul int hi_pathx; /* Full path */ 292697Spaul int hi_dewey[MAXDEWEY]; /* The versions */ 293697Spaul int hi_ndewey; /* Number of version numbers */ 294697Spaul#define hi_major hi_dewey[0] 295697Spaul#define hi_minor hi_dewey[1] 296697Spaul int hi_next; /* Next in this bucket */ 297697Spaul}; 298697Spaul 299697Spaul#define _PATH_LD_HINTS "/var/run/ld.so.hints" 300697Spaul 301697Spaul#endif /* _LINK_H_ */ 302697Spaul 303