link.h revision 50473
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 * 3050473Speter * $FreeBSD: head/include/link.h 50473 1999-08-27 23:45:13Z peter $ 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 4436311Sdfr#if (defined(FREEBSD_ELF) || defined(__ELF__)) && !defined(FREEBSD_AOUT) 4536311Sdfr 4636311Sdfr#include <sys/types.h> 4736311Sdfr 4836311Sdfrstruct link_map { 4936311Sdfr caddr_t l_addr; /* Base Address of library */ 5036311Sdfr#ifdef __mips__ 5136311Sdfr caddr_t l_offs; /* Load Offset of library */ 5236311Sdfr#endif 5336311Sdfr const char *l_name; /* Absolute Path to Library */ 5436311Sdfr const void *l_ld; /* Pointer to .dynamic in memory */ 5536311Sdfr struct link_map *l_next, *l_prev; /* linked list of of mapped libs */ 5636311Sdfr}; 5736311Sdfr 5836311Sdfrstruct r_debug { 5936311Sdfr int r_version; /* not used */ 6036311Sdfr struct link_map *r_map; /* list of loaded images */ 6136311Sdfr void (*r_brk)(void); /* pointer to break point */ 6236311Sdfr enum { 6336311Sdfr RT_CONSISTENT, /* things are stable */ 6436311Sdfr RT_ADD, /* adding a shared library */ 6536311Sdfr RT_DELETE /* removing a shared library */ 6636311Sdfr } r_state; 6736311Sdfr}; 6836311Sdfr 6936311Sdfr#else /* !__ELF__ */ 7036311Sdfr 7133137Sjdpstruct dl_info; 7233137Sjdp 73697Spaul/* 7413771Smpp * A `Shared Object Descriptor' describes a shared object that is needed 75697Spaul * to complete the link edit process of the object containing it. 761156Sjkh * A list of such objects (chained through `sod_next') is pointed at 771156Sjkh * by `sdt_sods' in the section_dispatch_table structure. 78697Spaul */ 79697Spaul 801156Sjkhstruct sod { /* Shared Object Descriptor */ 811156Sjkh long sod_name; /* name (relative to load address) */ 821156Sjkh u_int sod_library : 1, /* Searched for by library rules */ 831156Sjkh sod_reserved : 31; 841156Sjkh short sod_major; /* major version number */ 851156Sjkh short sod_minor; /* minor version number */ 861156Sjkh long sod_next; /* next sod */ 87697Spaul}; 88697Spaul 89697Spaul/* 901156Sjkh * `Shared Object Map's are used by the run-time link editor (ld.so) to 911156Sjkh * keep track of all shared objects loaded into a process' address space. 92697Spaul * These structures are only used at run-time and do not occur within 93697Spaul * the text or data segment of an executable or shared library. 94697Spaul */ 951156Sjkhstruct so_map { /* Shared Object Map */ 961156Sjkh caddr_t som_addr; /* Address at which object mapped */ 971156Sjkh char *som_path; /* Path to mmap'ed file */ 981156Sjkh struct so_map *som_next; /* Next map in chain */ 991156Sjkh struct sod *som_sod; /* Sod responsible for this map */ 1001156Sjkh caddr_t som_sodbase; /* Base address of this sod */ 1011156Sjkh u_int som_write : 1; /* Text is currently writable */ 1021156Sjkh struct _dynamic *som_dynamic; /* _dynamic structure */ 1031156Sjkh caddr_t som_spd; /* Private data */ 104697Spaul}; 105697Spaul 106697Spaul/* 107697Spaul * Symbol description with size. This is simply an `nlist' with 108697Spaul * one field (nz_size) added. 109697Spaul * Used to convey size information on items in the data segment 110697Spaul * of shared objects. An array of these live in the shared object's 1111156Sjkh * text segment and is addressed by the `sdt_nzlist' field. 112697Spaul */ 113697Spaulstruct nzlist { 114697Spaul struct nlist nlist; 115697Spaul u_long nz_size; 11631584Sjdp}; 11731584Sjdp 118697Spaul#define nz_un nlist.n_un 119697Spaul#define nz_strx nlist.n_un.n_strx 120697Spaul#define nz_name nlist.n_un.n_name 121697Spaul#define nz_type nlist.n_type 122697Spaul#define nz_value nlist.n_value 123697Spaul#define nz_desc nlist.n_desc 124697Spaul#define nz_other nlist.n_other 125697Spaul 126697Spaul/* 1271156Sjkh * The `section_dispatch_table' structure contains offsets to various data 128697Spaul * structures needed to do run-time relocation. 129697Spaul */ 1301156Sjkhstruct section_dispatch_table { 1311156Sjkh struct so_map *sdt_loaded; /* List of loaded objects */ 1321156Sjkh long sdt_sods; /* List of shared objects descriptors */ 13318591Speter long sdt_paths; /* Library search paths */ 1341156Sjkh long sdt_got; /* Global offset table */ 1351156Sjkh long sdt_plt; /* Procedure linkage table */ 1361156Sjkh long sdt_rel; /* Relocation table */ 1371156Sjkh long sdt_hash; /* Symbol hash table */ 1381156Sjkh long sdt_nzlist; /* Symbol table itself */ 1391156Sjkh long sdt_filler2; /* Unused (was: stab_hash) */ 1401156Sjkh long sdt_buckets; /* Number of hash buckets */ 1411156Sjkh long sdt_strings; /* Symbol strings */ 1421156Sjkh long sdt_str_sz; /* Size of symbol strings */ 1431156Sjkh long sdt_text_sz; /* Size of text area */ 1441156Sjkh long sdt_plt_sz; /* Size of procedure linkage table */ 145697Spaul}; 146697Spaul 147697Spaul/* 1481156Sjkh * RRS symbol hash table, addressed by `sdt_hash' in section_dispatch_table. 149697Spaul * Used to quickly lookup symbols of the shared object by hashing 150697Spaul * on the symbol's name. `rh_symbolnum' is the index of the symbol 1511156Sjkh * in the shared object's symbol list (`sdt_nzlist'), `rh_next' is 152697Spaul * the next symbol in the hash bucket (in case of collisions). 153697Spaul */ 154697Spaulstruct rrs_hash { 1551156Sjkh int rh_symbolnum; /* Symbol number */ 1561156Sjkh int rh_next; /* Next hash entry */ 157697Spaul}; 158697Spaul 159697Spaul/* 160697Spaul * `rt_symbols' is used to keep track of run-time allocated commons 161697Spaul * and data items copied from shared objects. 162697Spaul */ 163697Spaulstruct rt_symbol { 1641156Sjkh struct nzlist *rt_sp; /* The symbol */ 1651156Sjkh struct rt_symbol *rt_next; /* Next in linear list */ 1661156Sjkh struct rt_symbol *rt_link; /* Next in bucket */ 1671156Sjkh caddr_t rt_srcaddr; /* Address of "master" copy */ 1681156Sjkh struct so_map *rt_smp; /* Originating map */ 169697Spaul}; 170697Spaul 171697Spaul/* 172697Spaul * Debugger interface structure. 173697Spaul */ 1741156Sjkhstruct so_debug { 1751156Sjkh int dd_version; /* Version # of interface */ 1761156Sjkh int dd_in_debugger; /* Set when run by debugger */ 1771156Sjkh int dd_sym_loaded; /* Run-time linking brought more 1781156Sjkh symbols into scope */ 1791156Sjkh char *dd_bpt_addr; /* Address of rtld-generated bpt */ 1801156Sjkh int dd_bpt_shadow; /* Original contents of bpt */ 1811156Sjkh struct rt_symbol *dd_cc; /* Allocated commons/copied data */ 182697Spaul}; 183697Spaul 184697Spaul/* 1859335Sdfr * Version returned to crt0 from ld.so 1869335Sdfr */ 1879335Sdfr#define LDSO_VERSION_NONE 0 /* FreeBSD2.0, 2.0.5 */ 1889335Sdfr#define LDSO_VERSION_HAS_DLEXIT 1 /* includes dlexit in ld_entry */ 18927838Sjdp#define LDSO_VERSION_HAS_DLSYM3 2 /* includes 3-argument dlsym */ 19033137Sjdp#define LDSO_VERSION_HAS_DLADDR 3 /* includes dladdr in ld_entry */ 1919335Sdfr 1929335Sdfr/* 193697Spaul * Entry points into ld.so - user interface to the run-time linker. 1949335Sdfr * Entries are valid for the given version numbers returned by ld.so 1959335Sdfr * to crt0. 196697Spaul */ 197697Spaulstruct ld_entry { 19831342Sbrian void *(*dlopen) __P((const char *, int)); /* NONE */ 1999335Sdfr int (*dlclose) __P((void *)); /* NONE */ 20031342Sbrian void *(*dlsym) __P((void *, const char *)); /* NONE */ 20131342Sbrian const char *(*dlerror) __P((void)); /* NONE */ 2029335Sdfr void (*dlexit) __P((void)); /* HAS_DLEXIT */ 20331342Sbrian void *(*dlsym3) __P((void *, const char *, void *)); /* HAS_DLSYM3 */ 20433137Sjdp int (*dladdr) __P((const void *, 20533137Sjdp struct dl_info *)); /* HAS_DLADDR */ 206697Spaul}; 207697Spaul 208697Spaul/* 209697Spaul * This is the structure pointed at by the __DYNAMIC symbol if an 210697Spaul * executable requires the attention of the run-time link editor. 211697Spaul * __DYNAMIC is given the value zero if no run-time linking needs to 212697Spaul * be done (it is always present in shared objects). 2131156Sjkh * The union `d_un' provides for different versions of the dynamic 2141156Sjkh * linking mechanism (switched on by `d_version'). The last version 215697Spaul * used by Sun is 3. We leave some room here and go to version number 216697Spaul * 8 for NetBSD, the main difference lying in the support for the 217697Spaul * `nz_list' type of symbols. 218697Spaul */ 219697Spaul 2201156Sjkhstruct _dynamic { 2211156Sjkh int d_version; /* version # of this interface */ 2221156Sjkh struct so_debug *d_debug; 223697Spaul union { 2241156Sjkh struct section_dispatch_table *d_sdt; 2251156Sjkh } d_un; 2266887Snate struct ld_entry *d_entry; /* XXX */ 227697Spaul}; 228697Spaul 229697Spaul#define LD_VERSION_SUN (3) 230697Spaul#define LD_VERSION_BSD (8) 231697Spaul#define LD_VERSION_NZLIST_P(v) ((v) >= 8) 232697Spaul 2331156Sjkh#define LD_GOT(x) ((x)->d_un.d_sdt->sdt_got) 2341156Sjkh#define LD_PLT(x) ((x)->d_un.d_sdt->sdt_plt) 2351156Sjkh#define LD_REL(x) ((x)->d_un.d_sdt->sdt_rel) 2361156Sjkh#define LD_SYMBOL(x) ((x)->d_un.d_sdt->sdt_nzlist) 2371156Sjkh#define LD_HASH(x) ((x)->d_un.d_sdt->sdt_hash) 2381156Sjkh#define LD_STRINGS(x) ((x)->d_un.d_sdt->sdt_strings) 2391156Sjkh#define LD_NEED(x) ((x)->d_un.d_sdt->sdt_sods) 2401156Sjkh#define LD_BUCKETS(x) ((x)->d_un.d_sdt->sdt_buckets) 24118591Speter#define LD_PATHS(x) ((x)->d_un.d_sdt->sdt_paths) 242697Spaul 2431156Sjkh#define LD_GOTSZ(x) ((x)->d_un.d_sdt->sdt_plt - (x)->d_un.d_sdt->sdt_got) 2441156Sjkh#define LD_RELSZ(x) ((x)->d_un.d_sdt->sdt_hash - (x)->d_un.d_sdt->sdt_rel) 2451156Sjkh#define LD_HASHSZ(x) ((x)->d_un.d_sdt->sdt_nzlist - (x)->d_un.d_sdt->sdt_hash) 2461156Sjkh#define LD_STABSZ(x) ((x)->d_un.d_sdt->sdt_strings - (x)->d_un.d_sdt->sdt_nzlist) 2471156Sjkh#define LD_PLTSZ(x) ((x)->d_un.d_sdt->sdt_plt_sz) 2481156Sjkh#define LD_STRSZ(x) ((x)->d_un.d_sdt->sdt_str_sz) 2491156Sjkh#define LD_TEXTSZ(x) ((x)->d_un.d_sdt->sdt_text_sz) 250697Spaul 251697Spaul/* 2521156Sjkh * Interface to ld.so 253697Spaul */ 254697Spaulstruct crt_ldso { 255697Spaul int crt_ba; /* Base address of ld.so */ 25613771Smpp int crt_dzfd; /* "/dev/zero" file descriptor (SunOS) */ 257697Spaul int crt_ldfd; /* ld.so file descriptor */ 2581156Sjkh struct _dynamic *crt_dp; /* Main's __DYNAMIC */ 259697Spaul char **crt_ep; /* environment strings */ 260697Spaul caddr_t crt_bp; /* Breakpoint if run from debugger */ 2616887Snate char *crt_prog; /* Program name (v3) */ 2626887Snate char *crt_ldso; /* Link editor name (v4) */ 2636887Snate struct ld_entry *crt_ldentry; /* dl*() access (v4) */ 26433137Sjdp char **crt_argv; /* argument strings (v5) */ 265697Spaul}; 266697Spaul 267697Spaul/* 268697Spaul * Version passed from crt0 to ld.so (1st argument to _rtld()). 269697Spaul */ 270697Spaul#define CRT_VERSION_SUN 1 2711156Sjkh#define CRT_VERSION_BSD_2 2 2721156Sjkh#define CRT_VERSION_BSD_3 3 2736887Snate#define CRT_VERSION_BSD_4 4 27433137Sjdp#define CRT_VERSION_BSD_5 5 275697Spaul 276697Spaul/* 277697Spaul * Maximum number of recognized shared object version numbers. 278697Spaul */ 279697Spaul#define MAXDEWEY 8 280697Spaul 281697Spaul/* 282697Spaul * Header of the hints file. 283697Spaul */ 284697Spaulstruct hints_header { 285697Spaul long hh_magic; 286697Spaul#define HH_MAGIC 011421044151 287697Spaul long hh_version; /* Interface version number */ 288697Spaul#define LD_HINTS_VERSION_1 1 28918591Speter#define LD_HINTS_VERSION_2 2 290697Spaul long hh_hashtab; /* Location of hash table */ 291697Spaul long hh_nbucket; /* Number of buckets in hashtab */ 292697Spaul long hh_strtab; /* Location of strings */ 293697Spaul long hh_strtab_sz; /* Size of strings */ 294697Spaul long hh_ehints; /* End of hints (max offset in file) */ 29518591Speter long hh_dirlist; /* Colon-separated list of srch dirs */ 296697Spaul}; 297697Spaul 298697Spaul#define HH_BADMAG(hdr) ((hdr).hh_magic != HH_MAGIC) 299697Spaul 300697Spaul/* 301697Spaul * Hash table element in hints file. 302697Spaul */ 303697Spaulstruct hints_bucket { 304697Spaul /* namex and pathx are indices into the string table */ 305697Spaul int hi_namex; /* Library name */ 306697Spaul int hi_pathx; /* Full path */ 307697Spaul int hi_dewey[MAXDEWEY]; /* The versions */ 308697Spaul int hi_ndewey; /* Number of version numbers */ 309697Spaul#define hi_major hi_dewey[0] 310697Spaul#define hi_minor hi_dewey[1] 311697Spaul int hi_next; /* Next in this bucket */ 312697Spaul}; 313697Spaul 314697Spaul#define _PATH_LD_HINTS "/var/run/ld.so.hints" 315697Spaul 31636311Sdfr#endif /* !__ELF__ */ 31736311Sdfr 318697Spaul#endif /* _LINK_H_ */ 319