1139825Simp/*- 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$ 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 41102284Speter#ifndef _SYS_LINK_AOUT_H_ 42102284Speter#define _SYS_LINK_AOUT_H_ 43697Spaul 4433137Sjdpstruct dl_info; 4533137Sjdp 46697Spaul/* 4713771Smpp * A `Shared Object Descriptor' describes a shared object that is needed 48697Spaul * to complete the link edit process of the object containing it. 491156Sjkh * A list of such objects (chained through `sod_next') is pointed at 501156Sjkh * by `sdt_sods' in the section_dispatch_table structure. 51697Spaul */ 52697Spaul 531156Sjkhstruct sod { /* Shared Object Descriptor */ 541156Sjkh long sod_name; /* name (relative to load address) */ 551156Sjkh u_int sod_library : 1, /* Searched for by library rules */ 561156Sjkh sod_reserved : 31; 571156Sjkh short sod_major; /* major version number */ 581156Sjkh short sod_minor; /* minor version number */ 591156Sjkh long sod_next; /* next sod */ 60697Spaul}; 61697Spaul 62697Spaul/* 631156Sjkh * `Shared Object Map's are used by the run-time link editor (ld.so) to 641156Sjkh * keep track of all shared objects loaded into a process' address space. 65697Spaul * These structures are only used at run-time and do not occur within 66697Spaul * the text or data segment of an executable or shared library. 67697Spaul */ 681156Sjkhstruct so_map { /* Shared Object Map */ 691156Sjkh caddr_t som_addr; /* Address at which object mapped */ 701156Sjkh char *som_path; /* Path to mmap'ed file */ 711156Sjkh struct so_map *som_next; /* Next map in chain */ 721156Sjkh struct sod *som_sod; /* Sod responsible for this map */ 731156Sjkh caddr_t som_sodbase; /* Base address of this sod */ 741156Sjkh u_int som_write : 1; /* Text is currently writable */ 751156Sjkh struct _dynamic *som_dynamic; /* _dynamic structure */ 761156Sjkh caddr_t som_spd; /* Private data */ 77697Spaul}; 78697Spaul 79697Spaul/* 80697Spaul * Symbol description with size. This is simply an `nlist' with 81697Spaul * one field (nz_size) added. 82697Spaul * Used to convey size information on items in the data segment 83697Spaul * of shared objects. An array of these live in the shared object's 841156Sjkh * text segment and is addressed by the `sdt_nzlist' field. 85697Spaul */ 86697Spaulstruct nzlist { 87697Spaul struct nlist nlist; 88697Spaul u_long nz_size; 8931584Sjdp}; 9031584Sjdp 91697Spaul#define nz_un nlist.n_un 92697Spaul#define nz_strx nlist.n_un.n_strx 93697Spaul#define nz_name nlist.n_un.n_name 94697Spaul#define nz_type nlist.n_type 95697Spaul#define nz_value nlist.n_value 96697Spaul#define nz_desc nlist.n_desc 97697Spaul#define nz_other nlist.n_other 98697Spaul 99697Spaul/* 1001156Sjkh * The `section_dispatch_table' structure contains offsets to various data 101697Spaul * structures needed to do run-time relocation. 102697Spaul */ 1031156Sjkhstruct section_dispatch_table { 1041156Sjkh struct so_map *sdt_loaded; /* List of loaded objects */ 1051156Sjkh long sdt_sods; /* List of shared objects descriptors */ 10618591Speter long sdt_paths; /* Library search paths */ 1071156Sjkh long sdt_got; /* Global offset table */ 1081156Sjkh long sdt_plt; /* Procedure linkage table */ 1091156Sjkh long sdt_rel; /* Relocation table */ 1101156Sjkh long sdt_hash; /* Symbol hash table */ 1111156Sjkh long sdt_nzlist; /* Symbol table itself */ 1121156Sjkh long sdt_filler2; /* Unused (was: stab_hash) */ 1131156Sjkh long sdt_buckets; /* Number of hash buckets */ 1141156Sjkh long sdt_strings; /* Symbol strings */ 1151156Sjkh long sdt_str_sz; /* Size of symbol strings */ 1161156Sjkh long sdt_text_sz; /* Size of text area */ 1171156Sjkh long sdt_plt_sz; /* Size of procedure linkage table */ 118697Spaul}; 119697Spaul 120697Spaul/* 1211156Sjkh * RRS symbol hash table, addressed by `sdt_hash' in section_dispatch_table. 122697Spaul * Used to quickly lookup symbols of the shared object by hashing 123697Spaul * on the symbol's name. `rh_symbolnum' is the index of the symbol 1241156Sjkh * in the shared object's symbol list (`sdt_nzlist'), `rh_next' is 125697Spaul * the next symbol in the hash bucket (in case of collisions). 126697Spaul */ 127697Spaulstruct rrs_hash { 1281156Sjkh int rh_symbolnum; /* Symbol number */ 1291156Sjkh int rh_next; /* Next hash entry */ 130697Spaul}; 131697Spaul 132697Spaul/* 133697Spaul * `rt_symbols' is used to keep track of run-time allocated commons 134697Spaul * and data items copied from shared objects. 135697Spaul */ 136697Spaulstruct rt_symbol { 1371156Sjkh struct nzlist *rt_sp; /* The symbol */ 1381156Sjkh struct rt_symbol *rt_next; /* Next in linear list */ 1391156Sjkh struct rt_symbol *rt_link; /* Next in bucket */ 1401156Sjkh caddr_t rt_srcaddr; /* Address of "master" copy */ 1411156Sjkh struct so_map *rt_smp; /* Originating map */ 142697Spaul}; 143697Spaul 144697Spaul/* 145697Spaul * Debugger interface structure. 146697Spaul */ 1471156Sjkhstruct so_debug { 1481156Sjkh int dd_version; /* Version # of interface */ 1491156Sjkh int dd_in_debugger; /* Set when run by debugger */ 1501156Sjkh int dd_sym_loaded; /* Run-time linking brought more 1511156Sjkh symbols into scope */ 1521156Sjkh char *dd_bpt_addr; /* Address of rtld-generated bpt */ 1531156Sjkh int dd_bpt_shadow; /* Original contents of bpt */ 1541156Sjkh struct rt_symbol *dd_cc; /* Allocated commons/copied data */ 155697Spaul}; 156697Spaul 157697Spaul/* 1589335Sdfr * Version returned to crt0 from ld.so 1599335Sdfr */ 1609335Sdfr#define LDSO_VERSION_NONE 0 /* FreeBSD2.0, 2.0.5 */ 1619335Sdfr#define LDSO_VERSION_HAS_DLEXIT 1 /* includes dlexit in ld_entry */ 16227838Sjdp#define LDSO_VERSION_HAS_DLSYM3 2 /* includes 3-argument dlsym */ 16333137Sjdp#define LDSO_VERSION_HAS_DLADDR 3 /* includes dladdr in ld_entry */ 1649335Sdfr 1659335Sdfr/* 166697Spaul * Entry points into ld.so - user interface to the run-time linker. 1679335Sdfr * Entries are valid for the given version numbers returned by ld.so 1689335Sdfr * to crt0. 169697Spaul */ 170697Spaulstruct ld_entry { 17193032Simp void *(*dlopen)(const char *, int); /* NONE */ 17293032Simp int (*dlclose)(void *); /* NONE */ 17393032Simp void *(*dlsym)(void *, const char *); /* NONE */ 17493032Simp const char *(*dlerror)(void); /* NONE */ 17593032Simp void (*dlexit)(void); /* HAS_DLEXIT */ 17693032Simp void *(*dlsym3)(void *, const char *, void *); /* HAS_DLSYM3 */ 17793032Simp int (*dladdr)(const void *, struct dl_info *); /* HAS_DLADDR */ 178697Spaul}; 179697Spaul 180697Spaul/* 181697Spaul * This is the structure pointed at by the __DYNAMIC symbol if an 182697Spaul * executable requires the attention of the run-time link editor. 183697Spaul * __DYNAMIC is given the value zero if no run-time linking needs to 184697Spaul * be done (it is always present in shared objects). 1851156Sjkh * The union `d_un' provides for different versions of the dynamic 1861156Sjkh * linking mechanism (switched on by `d_version'). The last version 187697Spaul * used by Sun is 3. We leave some room here and go to version number 188697Spaul * 8 for NetBSD, the main difference lying in the support for the 189697Spaul * `nz_list' type of symbols. 190697Spaul */ 191697Spaul 19283047Sobrienstruct _dynamic { 1931156Sjkh int d_version; /* version # of this interface */ 1941156Sjkh struct so_debug *d_debug; 195697Spaul union { 1961156Sjkh struct section_dispatch_table *d_sdt; 1971156Sjkh } d_un; 1986887Snate struct ld_entry *d_entry; /* XXX */ 199697Spaul}; 200697Spaul 201697Spaul#define LD_VERSION_SUN (3) 202697Spaul#define LD_VERSION_BSD (8) 203697Spaul#define LD_VERSION_NZLIST_P(v) ((v) >= 8) 204697Spaul 2051156Sjkh#define LD_GOT(x) ((x)->d_un.d_sdt->sdt_got) 2061156Sjkh#define LD_PLT(x) ((x)->d_un.d_sdt->sdt_plt) 2071156Sjkh#define LD_REL(x) ((x)->d_un.d_sdt->sdt_rel) 2081156Sjkh#define LD_SYMBOL(x) ((x)->d_un.d_sdt->sdt_nzlist) 2091156Sjkh#define LD_HASH(x) ((x)->d_un.d_sdt->sdt_hash) 2101156Sjkh#define LD_STRINGS(x) ((x)->d_un.d_sdt->sdt_strings) 2111156Sjkh#define LD_NEED(x) ((x)->d_un.d_sdt->sdt_sods) 2121156Sjkh#define LD_BUCKETS(x) ((x)->d_un.d_sdt->sdt_buckets) 21318591Speter#define LD_PATHS(x) ((x)->d_un.d_sdt->sdt_paths) 214697Spaul 2151156Sjkh#define LD_GOTSZ(x) ((x)->d_un.d_sdt->sdt_plt - (x)->d_un.d_sdt->sdt_got) 2161156Sjkh#define LD_RELSZ(x) ((x)->d_un.d_sdt->sdt_hash - (x)->d_un.d_sdt->sdt_rel) 2171156Sjkh#define LD_HASHSZ(x) ((x)->d_un.d_sdt->sdt_nzlist - (x)->d_un.d_sdt->sdt_hash) 2181156Sjkh#define LD_STABSZ(x) ((x)->d_un.d_sdt->sdt_strings - (x)->d_un.d_sdt->sdt_nzlist) 2191156Sjkh#define LD_PLTSZ(x) ((x)->d_un.d_sdt->sdt_plt_sz) 2201156Sjkh#define LD_STRSZ(x) ((x)->d_un.d_sdt->sdt_str_sz) 2211156Sjkh#define LD_TEXTSZ(x) ((x)->d_un.d_sdt->sdt_text_sz) 222697Spaul 223697Spaul/* 2241156Sjkh * Interface to ld.so 225697Spaul */ 226697Spaulstruct crt_ldso { 227697Spaul int crt_ba; /* Base address of ld.so */ 22813771Smpp int crt_dzfd; /* "/dev/zero" file descriptor (SunOS) */ 229697Spaul int crt_ldfd; /* ld.so file descriptor */ 2301156Sjkh struct _dynamic *crt_dp; /* Main's __DYNAMIC */ 231697Spaul char **crt_ep; /* environment strings */ 232697Spaul caddr_t crt_bp; /* Breakpoint if run from debugger */ 2336887Snate char *crt_prog; /* Program name (v3) */ 2346887Snate char *crt_ldso; /* Link editor name (v4) */ 2356887Snate struct ld_entry *crt_ldentry; /* dl*() access (v4) */ 23633137Sjdp char **crt_argv; /* argument strings (v5) */ 237697Spaul}; 238697Spaul 239697Spaul/* 240697Spaul * Version passed from crt0 to ld.so (1st argument to _rtld()). 241697Spaul */ 242697Spaul#define CRT_VERSION_SUN 1 2431156Sjkh#define CRT_VERSION_BSD_2 2 2441156Sjkh#define CRT_VERSION_BSD_3 3 2456887Snate#define CRT_VERSION_BSD_4 4 24633137Sjdp#define CRT_VERSION_BSD_5 5 247697Spaul 248697Spaul/* 249697Spaul * Maximum number of recognized shared object version numbers. 250697Spaul */ 251697Spaul#define MAXDEWEY 8 252697Spaul 253697Spaul/* 254697Spaul * Header of the hints file. 255697Spaul */ 256697Spaulstruct hints_header { 257697Spaul long hh_magic; 258697Spaul#define HH_MAGIC 011421044151 259697Spaul long hh_version; /* Interface version number */ 260697Spaul#define LD_HINTS_VERSION_1 1 26118591Speter#define LD_HINTS_VERSION_2 2 262697Spaul long hh_hashtab; /* Location of hash table */ 263697Spaul long hh_nbucket; /* Number of buckets in hashtab */ 264697Spaul long hh_strtab; /* Location of strings */ 265697Spaul long hh_strtab_sz; /* Size of strings */ 266697Spaul long hh_ehints; /* End of hints (max offset in file) */ 26718591Speter long hh_dirlist; /* Colon-separated list of srch dirs */ 268697Spaul}; 269697Spaul 270697Spaul#define HH_BADMAG(hdr) ((hdr).hh_magic != HH_MAGIC) 271697Spaul 272697Spaul/* 273697Spaul * Hash table element in hints file. 274697Spaul */ 275697Spaulstruct hints_bucket { 276697Spaul /* namex and pathx are indices into the string table */ 277697Spaul int hi_namex; /* Library name */ 278697Spaul int hi_pathx; /* Full path */ 279697Spaul int hi_dewey[MAXDEWEY]; /* The versions */ 280697Spaul int hi_ndewey; /* Number of version numbers */ 281697Spaul#define hi_major hi_dewey[0] 282697Spaul#define hi_minor hi_dewey[1] 283697Spaul int hi_next; /* Next in this bucket */ 284697Spaul}; 285697Spaul 286697Spaul#define _PATH_LD_HINTS "/var/run/ld.so.hints" 287697Spaul 288102284Speter#endif /* _SYS_LINK_AOUT_H_ */ 289