link.h revision 66043
1135042Srwatson/* 2135042Srwatson * Copyright (c) 1993 Paul Kranenburg 3135042Srwatson * All rights reserved. 4135042Srwatson * 5135042Srwatson * Redistribution and use in source and binary forms, with or without 6135042Srwatson * modification, are permitted provided that the following conditions 7135042Srwatson * are met: 8135042Srwatson * 1. Redistributions of source code must retain the above copyright 9135042Srwatson * notice, this list of conditions and the following disclaimer. 10135042Srwatson * 2. Redistributions in binary form must reproduce the above copyright 11135042Srwatson * notice, this list of conditions and the following disclaimer in the 12135042Srwatson * documentation and/or other materials provided with the distribution. 13135042Srwatson * 3. All advertising materials mentioning features or use of this software 14135042Srwatson * must display the following acknowledgement: 15135042Srwatson * This product includes software developed by Paul Kranenburg. 16135042Srwatson * 4. The name of the author may not be used to endorse or promote products 17135042Srwatson * derived from this software without specific prior written permission 18135042Srwatson * 19135042Srwatson * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR 20135042Srwatson * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES 21135042Srwatson * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 22135042Srwatson * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, 23135042Srwatson * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT 24135042Srwatson * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 25135042Srwatson * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 26135042Srwatson * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 27135042Srwatson * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF 28135042Srwatson * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 29135042Srwatson * 30135042Srwatson * $FreeBSD: head/include/link.h 66043 2000-09-18 20:40:32Z jdp $ 31135042Srwatson */ 32227345Scognet 33135042Srwatson/* 34135042Srwatson * RRS section definitions. 35227345Scognet * 36135042Srwatson * The layout of some data structures defined in this header file is 37135042Srwatson * such that we can provide compatibility with the SunOS 4.x shared 38135042Srwatson * library scheme. 39135042Srwatson */ 40135042Srwatson 41135042Srwatson#ifndef _LINK_H_ 42227345Scognet#define _LINK_H_ 43135042Srwatson 44227345Scognet#if (defined(FREEBSD_ELF) || defined(__ELF__)) && !defined(FREEBSD_AOUT) 45227345Scognet 46244644Sluigi#include <sys/types.h> 47244644Sluigi 48244644Sluigistruct link_map { 49244644Sluigi caddr_t l_addr; /* Base Address of library */ 50244644Sluigi#ifdef __mips__ 51244644Sluigi caddr_t l_offs; /* Load Offset of library */ 52244644Sluigi#endif 53244644Sluigi const char *l_name; /* Absolute Path to Library */ 54244644Sluigi const void *l_ld; /* Pointer to .dynamic in memory */ 55244644Sluigi struct link_map *l_next, *l_prev; /* linked list of of mapped libs */ 56244644Sluigi}; 57244644Sluigi 58244644Sluigistruct r_debug { 59244644Sluigi int r_version; /* not used */ 60244644Sluigi struct link_map *r_map; /* list of loaded images */ 61244644Sluigi void (*r_brk)(struct r_debug *, struct link_map *); 62244672Sluigi /* pointer to break point */ 63244644Sluigi enum { 64244644Sluigi RT_CONSISTENT, /* things are stable */ 65244644Sluigi RT_ADD, /* adding a shared library */ 66244644Sluigi RT_DELETE /* removing a shared library */ 67244644Sluigi } r_state; 68135042Srwatson}; 69135042Srwatson 70135042Srwatson#else /* !__ELF__ */ 71135042Srwatson 72244644Sluigistruct dl_info; 73135042Srwatson 74135042Srwatson/* 75135042Srwatson * A `Shared Object Descriptor' describes a shared object that is needed 76244644Sluigi * to complete the link edit process of the object containing it. 77244644Sluigi * A list of such objects (chained through `sod_next') is pointed at 78244644Sluigi * by `sdt_sods' in the section_dispatch_table structure. 79244644Sluigi */ 80244644Sluigi 81244644Sluigistruct sod { /* Shared Object Descriptor */ 82244644Sluigi long sod_name; /* name (relative to load address) */ 83244644Sluigi u_int sod_library : 1, /* Searched for by library rules */ 84244644Sluigi sod_reserved : 31; 85244644Sluigi short sod_major; /* major version number */ 86244644Sluigi short sod_minor; /* minor version number */ 87244644Sluigi long sod_next; /* next sod */ 88244644Sluigi}; 89244644Sluigi 90244644Sluigi/* 91244644Sluigi * `Shared Object Map's are used by the run-time link editor (ld.so) to 92244644Sluigi * keep track of all shared objects loaded into a process' address space. 93244644Sluigi * These structures are only used at run-time and do not occur within 94244644Sluigi * the text or data segment of an executable or shared library. 95244644Sluigi */ 96244644Sluigistruct so_map { /* Shared Object Map */ 97244644Sluigi caddr_t som_addr; /* Address at which object mapped */ 98244644Sluigi char *som_path; /* Path to mmap'ed file */ 99244644Sluigi struct so_map *som_next; /* Next map in chain */ 100244644Sluigi struct sod *som_sod; /* Sod responsible for this map */ 101244644Sluigi caddr_t som_sodbase; /* Base address of this sod */ 102244644Sluigi u_int som_write : 1; /* Text is currently writable */ 103244644Sluigi struct _dynamic *som_dynamic; /* _dynamic structure */ 104244644Sluigi caddr_t som_spd; /* Private data */ 105244644Sluigi}; 106244644Sluigi 107244644Sluigi/* 108244644Sluigi * Symbol description with size. This is simply an `nlist' with 109244644Sluigi * one field (nz_size) added. 110244644Sluigi * Used to convey size information on items in the data segment 111244644Sluigi * of shared objects. An array of these live in the shared object's 112244644Sluigi * text segment and is addressed by the `sdt_nzlist' field. 113244644Sluigi */ 114244644Sluigistruct nzlist { 115244644Sluigi struct nlist nlist; 116244644Sluigi u_long nz_size; 117244644Sluigi}; 118244644Sluigi 119244644Sluigi#define nz_un nlist.n_un 120244672Sluigi#define nz_strx nlist.n_un.n_strx 121244644Sluigi#define nz_name nlist.n_un.n_name 122244644Sluigi#define nz_type nlist.n_type 123244644Sluigi#define nz_value nlist.n_value 124244644Sluigi#define nz_desc nlist.n_desc 125244644Sluigi#define nz_other nlist.n_other 126244672Sluigi 127244672Sluigi/* 128244644Sluigi * The `section_dispatch_table' structure contains offsets to various data 129244644Sluigi * structures needed to do run-time relocation. 130244644Sluigi */ 131244644Sluigistruct section_dispatch_table { 132244644Sluigi struct so_map *sdt_loaded; /* List of loaded objects */ 133244672Sluigi long sdt_sods; /* List of shared objects descriptors */ 134244644Sluigi long sdt_paths; /* Library search paths */ 135244644Sluigi long sdt_got; /* Global offset table */ 136244644Sluigi long sdt_plt; /* Procedure linkage table */ 137244644Sluigi long sdt_rel; /* Relocation table */ 138244644Sluigi long sdt_hash; /* Symbol hash table */ 139244644Sluigi long sdt_nzlist; /* Symbol table itself */ 140244644Sluigi long sdt_filler2; /* Unused (was: stab_hash) */ 141244644Sluigi long sdt_buckets; /* Number of hash buckets */ 142244644Sluigi long sdt_strings; /* Symbol strings */ 143244644Sluigi long sdt_str_sz; /* Size of symbol strings */ 144244644Sluigi long sdt_text_sz; /* Size of text area */ 145244644Sluigi long sdt_plt_sz; /* Size of procedure linkage table */ 146244672Sluigi}; 147244672Sluigi 148244644Sluigi/* 149244644Sluigi * RRS symbol hash table, addressed by `sdt_hash' in section_dispatch_table. 150244644Sluigi * Used to quickly lookup symbols of the shared object by hashing 151244644Sluigi * on the symbol's name. `rh_symbolnum' is the index of the symbol 152244644Sluigi * in the shared object's symbol list (`sdt_nzlist'), `rh_next' is 153244644Sluigi * the next symbol in the hash bucket (in case of collisions). 154244644Sluigi */ 155244672Sluigistruct rrs_hash { 156244644Sluigi int rh_symbolnum; /* Symbol number */ 157244644Sluigi int rh_next; /* Next hash entry */ 158244672Sluigi}; 159244644Sluigi 160244644Sluigi/* 161244672Sluigi * `rt_symbols' is used to keep track of run-time allocated commons 162244644Sluigi * and data items copied from shared objects. 163244644Sluigi */ 164244672Sluigistruct rt_symbol { 165244644Sluigi struct nzlist *rt_sp; /* The symbol */ 166244644Sluigi struct rt_symbol *rt_next; /* Next in linear list */ 167244644Sluigi struct rt_symbol *rt_link; /* Next in bucket */ 168244644Sluigi caddr_t rt_srcaddr; /* Address of "master" copy */ 169244644Sluigi struct so_map *rt_smp; /* Originating map */ 170244672Sluigi}; 171244644Sluigi 172244644Sluigi/* 173244644Sluigi * Debugger interface structure. 174244672Sluigi */ 175244644Sluigistruct so_debug { 176244644Sluigi int dd_version; /* Version # of interface */ 177244672Sluigi int dd_in_debugger; /* Set when run by debugger */ 178244644Sluigi int dd_sym_loaded; /* Run-time linking brought more 179244644Sluigi symbols into scope */ 180244644Sluigi char *dd_bpt_addr; /* Address of rtld-generated bpt */ 181244644Sluigi int dd_bpt_shadow; /* Original contents of bpt */ 182244644Sluigi struct rt_symbol *dd_cc; /* Allocated commons/copied data */ 183244644Sluigi}; 184244644Sluigi 185244644Sluigi/* 186244672Sluigi * Version returned to crt0 from ld.so 187244672Sluigi */ 188244672Sluigi#define LDSO_VERSION_NONE 0 /* FreeBSD2.0, 2.0.5 */ 189244672Sluigi#define LDSO_VERSION_HAS_DLEXIT 1 /* includes dlexit in ld_entry */ 190244644Sluigi#define LDSO_VERSION_HAS_DLSYM3 2 /* includes 3-argument dlsym */ 191244672Sluigi#define LDSO_VERSION_HAS_DLADDR 3 /* includes dladdr in ld_entry */ 192244644Sluigi 193244644Sluigi/* 194244644Sluigi * Entry points into ld.so - user interface to the run-time linker. 195244644Sluigi * Entries are valid for the given version numbers returned by ld.so 196135042Srwatson * to crt0. 197135042Srwatson */ 198227345Scognetstruct ld_entry { 199135042Srwatson void *(*dlopen) __P((const char *, int)); /* NONE */ 200227345Scognet int (*dlclose) __P((void *)); /* NONE */ 201244644Sluigi void *(*dlsym) __P((void *, const char *)); /* NONE */ 202244644Sluigi const char *(*dlerror) __P((void)); /* NONE */ 203227345Scognet void (*dlexit) __P((void)); /* HAS_DLEXIT */ 204227345Scognet void *(*dlsym3) __P((void *, const char *, void *)); /* HAS_DLSYM3 */ 205227345Scognet int (*dladdr) __P((const void *, 206135042Srwatson struct dl_info *)); /* HAS_DLADDR */ 207244644Sluigi}; 208135042Srwatson 209135042Srwatson/* 210227345Scognet * This is the structure pointed at by the __DYNAMIC symbol if an 211227345Scognet * executable requires the attention of the run-time link editor. 212227345Scognet * __DYNAMIC is given the value zero if no run-time linking needs to 213227345Scognet * be done (it is always present in shared objects). 214135042Srwatson * The union `d_un' provides for different versions of the dynamic 215135042Srwatson * linking mechanism (switched on by `d_version'). The last version 216135042Srwatson * used by Sun is 3. We leave some room here and go to version number 217135042Srwatson * 8 for NetBSD, the main difference lying in the support for the 218244644Sluigi * `nz_list' type of symbols. 219244644Sluigi */ 220244644Sluigi 221244644Sluigistruct _dynamic { 222135042Srwatson int d_version; /* version # of this interface */ 223135042Srwatson struct so_debug *d_debug; 224135042Srwatson union { 225135042Srwatson struct section_dispatch_table *d_sdt; 226135042Srwatson } d_un; 227135042Srwatson struct ld_entry *d_entry; /* XXX */ 228135042Srwatson}; 229135042Srwatson 230227345Scognet#define LD_VERSION_SUN (3) 231227345Scognet#define LD_VERSION_BSD (8) 232227345Scognet#define LD_VERSION_NZLIST_P(v) ((v) >= 8) 233135042Srwatson 234227345Scognet#define LD_GOT(x) ((x)->d_un.d_sdt->sdt_got) 235135042Srwatson#define LD_PLT(x) ((x)->d_un.d_sdt->sdt_plt) 236135042Srwatson#define LD_REL(x) ((x)->d_un.d_sdt->sdt_rel) 237227345Scognet#define LD_SYMBOL(x) ((x)->d_un.d_sdt->sdt_nzlist) 238227345Scognet#define LD_HASH(x) ((x)->d_un.d_sdt->sdt_hash) 239227345Scognet#define LD_STRINGS(x) ((x)->d_un.d_sdt->sdt_strings) 240227345Scognet#define LD_NEED(x) ((x)->d_un.d_sdt->sdt_sods) 241227345Scognet#define LD_BUCKETS(x) ((x)->d_un.d_sdt->sdt_buckets) 242227345Scognet#define LD_PATHS(x) ((x)->d_un.d_sdt->sdt_paths) 243227345Scognet 244227345Scognet#define LD_GOTSZ(x) ((x)->d_un.d_sdt->sdt_plt - (x)->d_un.d_sdt->sdt_got) 245227345Scognet#define LD_RELSZ(x) ((x)->d_un.d_sdt->sdt_hash - (x)->d_un.d_sdt->sdt_rel) 246227345Scognet#define LD_HASHSZ(x) ((x)->d_un.d_sdt->sdt_nzlist - (x)->d_un.d_sdt->sdt_hash) 247227345Scognet#define LD_STABSZ(x) ((x)->d_un.d_sdt->sdt_strings - (x)->d_un.d_sdt->sdt_nzlist) 248227345Scognet#define LD_PLTSZ(x) ((x)->d_un.d_sdt->sdt_plt_sz) 249227345Scognet#define LD_STRSZ(x) ((x)->d_un.d_sdt->sdt_str_sz) 250227345Scognet#define LD_TEXTSZ(x) ((x)->d_un.d_sdt->sdt_text_sz) 251227345Scognet 252227345Scognet/* 253227345Scognet * Interface to ld.so 254227345Scognet */ 255227345Scognetstruct crt_ldso { 256227345Scognet int crt_ba; /* Base address of ld.so */ 257227345Scognet int crt_dzfd; /* "/dev/zero" file descriptor (SunOS) */ 258227345Scognet int crt_ldfd; /* ld.so file descriptor */ 259135536Srwatson struct _dynamic *crt_dp; /* Main's __DYNAMIC */ 260227345Scognet char **crt_ep; /* environment strings */ 261227345Scognet caddr_t crt_bp; /* Breakpoint if run from debugger */ 262135042Srwatson char *crt_prog; /* Program name (v3) */ 263227345Scognet char *crt_ldso; /* Link editor name (v4) */ 264135042Srwatson struct ld_entry *crt_ldentry; /* dl*() access (v4) */ 265135042Srwatson char **crt_argv; /* argument strings (v5) */ 266244644Sluigi}; 267244644Sluigi 268135042Srwatson/* 269244672Sluigi * Version passed from crt0 to ld.so (1st argument to _rtld()). 270244644Sluigi */ 271244644Sluigi#define CRT_VERSION_SUN 1 272227345Scognet#define CRT_VERSION_BSD_2 2 273227345Scognet#define CRT_VERSION_BSD_3 3 274135042Srwatson#define CRT_VERSION_BSD_4 4 275#define CRT_VERSION_BSD_5 5 276 277/* 278 * Maximum number of recognized shared object version numbers. 279 */ 280#define MAXDEWEY 8 281 282/* 283 * Header of the hints file. 284 */ 285struct hints_header { 286 long hh_magic; 287#define HH_MAGIC 011421044151 288 long hh_version; /* Interface version number */ 289#define LD_HINTS_VERSION_1 1 290#define LD_HINTS_VERSION_2 2 291 long hh_hashtab; /* Location of hash table */ 292 long hh_nbucket; /* Number of buckets in hashtab */ 293 long hh_strtab; /* Location of strings */ 294 long hh_strtab_sz; /* Size of strings */ 295 long hh_ehints; /* End of hints (max offset in file) */ 296 long hh_dirlist; /* Colon-separated list of srch dirs */ 297}; 298 299#define HH_BADMAG(hdr) ((hdr).hh_magic != HH_MAGIC) 300 301/* 302 * Hash table element in hints file. 303 */ 304struct hints_bucket { 305 /* namex and pathx are indices into the string table */ 306 int hi_namex; /* Library name */ 307 int hi_pathx; /* Full path */ 308 int hi_dewey[MAXDEWEY]; /* The versions */ 309 int hi_ndewey; /* Number of version numbers */ 310#define hi_major hi_dewey[0] 311#define hi_minor hi_dewey[1] 312 int hi_next; /* Next in this bucket */ 313}; 314 315#define _PATH_LD_HINTS "/var/run/ld.so.hints" 316 317#endif /* !__ELF__ */ 318 319#endif /* _LINK_H_ */ 320