link.h revision 1156
160786Sps/* 2240121Sdelphij * Copyright (c) 1993 Paul Kranenburg 360786Sps * All rights reserved. 460786Sps * 560786Sps * Redistribution and use in source and binary forms, with or without 660786Sps * modification, are permitted provided that the following conditions 7240121Sdelphij * are met: 860786Sps * 1. Redistributions of source code must retain the above copyright 960786Sps * notice, this list of conditions and the following disclaimer. 1060786Sps * 2. Redistributions in binary form must reproduce the above copyright 1160786Sps * notice, this list of conditions and the following disclaimer in the 1260786Sps * documentation and/or other materials provided with the distribution. 1360786Sps * 3. All advertising materials mentioning features or use of this software 1460786Sps * must display the following acknowledgement: 1560786Sps * This product includes software developed by Paul Kranenburg. 1660786Sps * 4. The name of the author may not be used to endorse or promote products 1760786Sps * derived from this software withough specific prior written permission 1860786Sps * 1960786Sps * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR 2060786Sps * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES 2160786Sps * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 2260786Sps * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, 2360786Sps * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT 2460786Sps * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 2560786Sps * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 2660786Sps * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 2760786Sps * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF 2860786Sps * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 2960786Sps * 3060786Sps * $Id$ 3160786Sps */ 3260786Sps 3360786Sps/* 3460786Sps * RRS section definitions. 3560786Sps * 3660786Sps * The layout of some data structures defined in this header file is 3760786Sps * such that we can provide compatibility with the SunOS 4.x shared 3860786Sps * library scheme. 3960786Sps */ 4060786Sps 41128345Stjr#ifndef _LINK_H_ 4260786Sps#define _LINK_H_ 43128345Stjr 44128345Stjr/* 4560786Sps * A `Shared Object Descriptor' descibes a shared object that is needed 4660786Sps * to complete the link edit process of the object containing it. 47128345Stjr * A list of such objects (chained through `sod_next') is pointed at 4860786Sps * by `sdt_sods' in the section_dispatch_table structure. 4960786Sps */ 5060786Sps 5160786Spsstruct sod { /* Shared Object Descriptor */ 5260786Sps long sod_name; /* name (relative to load address) */ 5360786Sps u_int sod_library : 1, /* Searched for by library rules */ 5460786Sps sod_reserved : 31; 5560786Sps short sod_major; /* major version number */ 5660786Sps short sod_minor; /* minor version number */ 5760786Sps long sod_next; /* next sod */ 58191930Sdelphij}; 5960786Sps 6060786Sps/* 6160786Sps * `Shared Object Map's are used by the run-time link editor (ld.so) to 62128345Stjr * keep track of all shared objects loaded into a process' address space. 63128345Stjr * These structures are only used at run-time and do not occur within 64128345Stjr * the text or data segment of an executable or shared library. 65128345Stjr */ 6660786Spsstruct so_map { /* Shared Object Map */ 6760786Sps caddr_t som_addr; /* Address at which object mapped */ 6860786Sps char *som_path; /* Path to mmap'ed file */ 6960786Sps struct so_map *som_next; /* Next map in chain */ 70191930Sdelphij struct sod *som_sod; /* Sod responsible for this map */ 7160786Sps caddr_t som_sodbase; /* Base address of this sod */ 7260786Sps u_int som_write : 1; /* Text is currently writable */ 7360786Sps struct _dynamic *som_dynamic; /* _dynamic structure */ 7460786Sps caddr_t som_spd; /* Private data */ 7560786Sps}; 7660786Sps 7760786Sps/* 78128345Stjr * Symbol description with size. This is simply an `nlist' with 7960786Sps * one field (nz_size) added. 8060786Sps * Used to convey size information on items in the data segment 8160786Sps * of shared objects. An array of these live in the shared object's 8260786Sps * text segment and is addressed by the `sdt_nzlist' field. 8360786Sps */ 8460786Spsstruct nzlist { 8560786Sps struct nlist nlist; 8660786Sps u_long nz_size; 8760786Sps#define nz_un nlist.n_un 8860786Sps#define nz_strx nlist.n_un.n_strx 8960786Sps#define nz_name nlist.n_un.n_name 9060786Sps#define nz_type nlist.n_type 9160786Sps#define nz_value nlist.n_value 9260786Sps#define nz_desc nlist.n_desc 9360786Sps#define nz_other nlist.n_other 9460786Sps}; 9560786Sps 9660786Sps#define N_AUX(p) ((p)->n_other & 0xf) 9760786Sps#define N_RESERVED(p) (((unsigned int)(p)->n_other >> 4) & 0xf) 9860786Sps#define N_OTHER(r, v) (((unsigned int)(r) << 4) | ((v) & 0xf)) 9960786Sps 10060786Sps#define AUX_OBJECT 1 10160786Sps#define AUX_FUNC 2 10260786Sps 10360786Sps 10460786Sps/* 105128345Stjr * The `section_dispatch_table' structure contains offsets to various data 10660786Sps * structures needed to do run-time relocation. 10760786Sps */ 10860786Spsstruct section_dispatch_table { 10960786Sps struct so_map *sdt_loaded; /* List of loaded objects */ 11060786Sps long sdt_sods; /* List of shared objects descriptors */ 11160786Sps long sdt_filler1; /* Unused (was: search rules) */ 11260786Sps long sdt_got; /* Global offset table */ 11360786Sps long sdt_plt; /* Procedure linkage table */ 11460786Sps long sdt_rel; /* Relocation table */ 11560786Sps long sdt_hash; /* Symbol hash table */ 11660786Sps long sdt_nzlist; /* Symbol table itself */ 11760786Sps long sdt_filler2; /* Unused (was: stab_hash) */ 11860786Sps long sdt_buckets; /* Number of hash buckets */ 11960786Sps long sdt_strings; /* Symbol strings */ 12060786Sps long sdt_str_sz; /* Size of symbol strings */ 12160786Sps long sdt_text_sz; /* Size of text area */ 12260786Sps long sdt_plt_sz; /* Size of procedure linkage table */ 12360786Sps}; 124128345Stjr 125128345Stjr/* 12660786Sps * RRS symbol hash table, addressed by `sdt_hash' in section_dispatch_table. 12760786Sps * Used to quickly lookup symbols of the shared object by hashing 128128345Stjr * on the symbol's name. `rh_symbolnum' is the index of the symbol 129128345Stjr * in the shared object's symbol list (`sdt_nzlist'), `rh_next' is 130128345Stjr * the next symbol in the hash bucket (in case of collisions). 131128345Stjr */ 13260786Spsstruct rrs_hash { 13360786Sps int rh_symbolnum; /* Symbol number */ 13460786Sps int rh_next; /* Next hash entry */ 13560786Sps}; 13660786Sps 13760786Sps/* 13860786Sps * `rt_symbols' is used to keep track of run-time allocated commons 139128345Stjr * and data items copied from shared objects. 14060786Sps */ 14160786Spsstruct rt_symbol { 14260786Sps struct nzlist *rt_sp; /* The symbol */ 14360786Sps struct rt_symbol *rt_next; /* Next in linear list */ 14460786Sps struct rt_symbol *rt_link; /* Next in bucket */ 14560786Sps caddr_t rt_srcaddr; /* Address of "master" copy */ 14660786Sps struct so_map *rt_smp; /* Originating map */ 14760786Sps}; 14860786Sps 14960786Sps/* 15060786Sps * Debugger interface structure. 15160786Sps */ 15260786Spsstruct so_debug { 15360786Sps int dd_version; /* Version # of interface */ 15460786Sps int dd_in_debugger; /* Set when run by debugger */ 15560786Sps int dd_sym_loaded; /* Run-time linking brought more 15660786Sps symbols into scope */ 15760786Sps char *dd_bpt_addr; /* Address of rtld-generated bpt */ 15860786Sps int dd_bpt_shadow; /* Original contents of bpt */ 15960786Sps struct rt_symbol *dd_cc; /* Allocated commons/copied data */ 16060786Sps}; 16160786Sps 16260786Sps/* 16360786Sps * Entry points into ld.so - user interface to the run-time linker. 16460786Sps */ 16560786Spsstruct ld_entry { 16660786Sps void *(*dlopen) __P((char *, int)); 16760786Sps int (*dlclose) __P((void *)); 16860786Sps void *(*dlsym) __P((void *, char *)); 16960786Sps int (*dlctl) __P((void *, int, void *)); 170128345Stjr}; 17160786Sps 17260786Sps/* 17360786Sps * dlctl() commands 17460786Sps */ 17560786Sps#define DL_GETERRNO 1 17660786Sps 17760786Sps/* 17860786Sps * dl*() prototypes. 17960786Sps */ 18060786Spsextern void *dlopen __P((char *, int)); 18160786Spsextern int dlclose __P((void *)); 18260786Spsextern void *dlsym __P((void *, char *)); 18360786Spsextern int dlctl __P((void *, int, void *)); 18460786Sps 18560786Sps 18660786Sps/* 18760786Sps * This is the structure pointed at by the __DYNAMIC symbol if an 18860786Sps * executable requires the attention of the run-time link editor. 18960786Sps * __DYNAMIC is given the value zero if no run-time linking needs to 19060786Sps * be done (it is always present in shared objects). 19160786Sps * The union `d_un' provides for different versions of the dynamic 19260786Sps * linking mechanism (switched on by `d_version'). The last version 19360786Sps * used by Sun is 3. We leave some room here and go to version number 19460786Sps * 8 for NetBSD, the main difference lying in the support for the 19560786Sps * `nz_list' type of symbols. 19660786Sps */ 19760786Sps 19860786Spsstruct _dynamic { 19960786Sps int d_version; /* version # of this interface */ 20060786Sps struct so_debug *d_debug; 20160786Sps union { 20260786Sps struct section_dispatch_table *d_sdt; 20360786Sps } d_un; 20460786Sps struct ld_entry *d_entry; 20560786Sps}; 20660786Sps 20760786Sps#define LD_VERSION_SUN (3) 20860786Sps#define LD_VERSION_BSD (8) 20960786Sps#define LD_VERSION_NZLIST_P(v) ((v) >= 8) 21060786Sps 21160786Sps#define LD_GOT(x) ((x)->d_un.d_sdt->sdt_got) 21260786Sps#define LD_PLT(x) ((x)->d_un.d_sdt->sdt_plt) 21360786Sps#define LD_REL(x) ((x)->d_un.d_sdt->sdt_rel) 21460786Sps#define LD_SYMBOL(x) ((x)->d_un.d_sdt->sdt_nzlist) 21560786Sps#define LD_HASH(x) ((x)->d_un.d_sdt->sdt_hash) 21660786Sps#define LD_STRINGS(x) ((x)->d_un.d_sdt->sdt_strings) 21760786Sps#define LD_NEED(x) ((x)->d_un.d_sdt->sdt_sods) 21860786Sps#define LD_BUCKETS(x) ((x)->d_un.d_sdt->sdt_buckets) 21960786Sps 22060786Sps#define LD_GOTSZ(x) ((x)->d_un.d_sdt->sdt_plt - (x)->d_un.d_sdt->sdt_got) 22160786Sps#define LD_RELSZ(x) ((x)->d_un.d_sdt->sdt_hash - (x)->d_un.d_sdt->sdt_rel) 22260786Sps#define LD_HASHSZ(x) ((x)->d_un.d_sdt->sdt_nzlist - (x)->d_un.d_sdt->sdt_hash) 22360786Sps#define LD_STABSZ(x) ((x)->d_un.d_sdt->sdt_strings - (x)->d_un.d_sdt->sdt_nzlist) 22460786Sps#define LD_PLTSZ(x) ((x)->d_un.d_sdt->sdt_plt_sz) 22560786Sps#define LD_STRSZ(x) ((x)->d_un.d_sdt->sdt_str_sz) 22660786Sps#define LD_TEXTSZ(x) ((x)->d_un.d_sdt->sdt_text_sz) 22760786Sps 22860786Sps/* 22960786Sps * Interface to ld.so 23060786Sps */ 23160786Spsstruct crt_ldso { 23260786Sps int crt_ba; /* Base address of ld.so */ 23360786Sps int crt_dzfd; /* "/dev/zero" file decriptor (SunOS) */ 23460786Sps int crt_ldfd; /* ld.so file descriptor */ 23560786Sps struct _dynamic *crt_dp; /* Main's __DYNAMIC */ 23660786Sps char **crt_ep; /* environment strings */ 23760786Sps caddr_t crt_bp; /* Breakpoint if run from debugger */ 23860786Sps char *crt_prog; /* Program name */ 23960786Sps}; 24060786Sps 24160786Sps/* 24260786Sps * Version passed from crt0 to ld.so (1st argument to _rtld()). 24360786Sps */ 24460786Sps#define CRT_VERSION_SUN 1 245191930Sdelphij#define CRT_VERSION_BSD 2 246191930Sdelphij#define CRT_VERSION_BSD_2 2 247191930Sdelphij#define CRT_VERSION_BSD_3 3 248191930Sdelphij 249191930Sdelphij 250191930Sdelphij/* 251191930Sdelphij * Maximum number of recognized shared object version numbers. 252191930Sdelphij */ 253191930Sdelphij#define MAXDEWEY 8 254191930Sdelphij 255191930Sdelphij/* 256191930Sdelphij * Header of the hints file. 257191930Sdelphij */ 258191930Sdelphijstruct hints_header { 259191930Sdelphij long hh_magic; 260191930Sdelphij#define HH_MAGIC 011421044151 26160786Sps long hh_version; /* Interface version number */ 26260786Sps#define LD_HINTS_VERSION_1 1 26360786Sps long hh_hashtab; /* Location of hash table */ 264128345Stjr long hh_nbucket; /* Number of buckets in hashtab */ 26560786Sps long hh_strtab; /* Location of strings */ 26660786Sps long hh_strtab_sz; /* Size of strings */ 26760786Sps long hh_ehints; /* End of hints (max offset in file) */ 268128345Stjr}; 269128345Stjr 27060786Sps#define HH_BADMAG(hdr) ((hdr).hh_magic != HH_MAGIC) 27160786Sps 27260786Sps/* 27360786Sps * Hash table element in hints file. 27460786Sps */ 27560786Spsstruct hints_bucket { 27660786Sps /* namex and pathx are indices into the string table */ 27760786Sps int hi_namex; /* Library name */ 27860786Sps int hi_pathx; /* Full path */ 27960786Sps int hi_dewey[MAXDEWEY]; /* The versions */ 28060786Sps int hi_ndewey; /* Number of version numbers */ 28160786Sps#define hi_major hi_dewey[0] 28260786Sps#define hi_minor hi_dewey[1] 28360786Sps int hi_next; /* Next in this bucket */ 28460786Sps}; 28560786Sps 28660786Sps#define _PATH_LD_HINTS "/var/run/ld.so.hints" 28760786Sps 28860786Sps#endif /* _LINK_H_ */ 28960786Sps 29060786Sps