link_aout.h revision 66043
171088Sjasone/* 271088Sjasone * Copyright (c) 1993 Paul Kranenburg 371088Sjasone * All rights reserved. 471088Sjasone * 571088Sjasone * Redistribution and use in source and binary forms, with or without 671088Sjasone * modification, are permitted provided that the following conditions 771088Sjasone * are met: 871088Sjasone * 1. Redistributions of source code must retain the above copyright 971088Sjasone * notice, this list of conditions and the following disclaimer. 1071088Sjasone * 2. Redistributions in binary form must reproduce the above copyright 1171088Sjasone * notice, this list of conditions and the following disclaimer in the 1271088Sjasone * documentation and/or other materials provided with the distribution. 1371088Sjasone * 3. All advertising materials mentioning features or use of this software 1471088Sjasone * must display the following acknowledgement: 1571088Sjasone * This product includes software developed by Paul Kranenburg. 1671088Sjasone * 4. The name of the author may not be used to endorse or promote products 1771088Sjasone * derived from this software without specific prior written permission 1871088Sjasone * 1971088Sjasone * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR 2071088Sjasone * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES 2171088Sjasone * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 2271088Sjasone * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, 2371088Sjasone * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT 2471088Sjasone * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 2571088Sjasone * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 2671088Sjasone * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 27116182Sobrien * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF 28116182Sobrien * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 29116182Sobrien * 3071088Sjasone * $FreeBSD: head/sys/sys/link_aout.h 66043 2000-09-18 20:40:32Z jdp $ 3171088Sjasone */ 3271088Sjasone 3371088Sjasone/* 3476166Smarkm * RRS section definitions. 3576166Smarkm * 3671088Sjasone * The layout of some data structures defined in this header file is 3771088Sjasone * such that we can provide compatibility with the SunOS 4.x shared 3871088Sjasone * library scheme. 3971088Sjasone */ 40109862Sjeff 4171088Sjasone#ifndef _LINK_H_ 42126326Sjhb#define _LINK_H_ 4371088Sjasone 4471088Sjasone#if (defined(FREEBSD_ELF) || defined(__ELF__)) && !defined(FREEBSD_AOUT) 4571088Sjasone 4671088Sjasone#include <sys/types.h> 4771088Sjasone 4871088Sjasonestruct link_map { 4971088Sjasone caddr_t l_addr; /* Base Address of library */ 5071088Sjasone#ifdef __mips__ 5171088Sjasone caddr_t l_offs; /* Load Offset of library */ 5283366Sjulian#endif 5387594Sobrien const char *l_name; /* Absolute Path to Library */ 54103216Sjulian const void *l_ld; /* Pointer to .dynamic in memory */ 5587594Sobrien struct link_map *l_next, *l_prev; /* linked list of of mapped libs */ 5687594Sobrien}; 5771088Sjasone 5871088Sjasonestruct r_debug { 5971088Sjasone int r_version; /* not used */ 6071088Sjasone struct link_map *r_map; /* list of loaded images */ 6171088Sjasone void (*r_brk)(struct r_debug *, struct link_map *); 6271088Sjasone /* pointer to break point */ 6371088Sjasone enum { 6471088Sjasone RT_CONSISTENT, /* things are stable */ 6571088Sjasone RT_ADD, /* adding a shared library */ 6671088Sjasone RT_DELETE /* removing a shared library */ 6771088Sjasone } r_state; 68127954Sjhb}; 6971088Sjasone 7071088Sjasone#else /* !__ELF__ */ 7171088Sjasone 7271088Sjasonestruct dl_info; 7371088Sjasone 7471088Sjasone/* 7571088Sjasone * A `Shared Object Descriptor' describes a shared object that is needed 7671088Sjasone * to complete the link edit process of the object containing it. 7771088Sjasone * A list of such objects (chained through `sod_next') is pointed at 78126326Sjhb * by `sdt_sods' in the section_dispatch_table structure. 79136445Sjhb */ 8071088Sjasone 81136445Sjhbstruct sod { /* Shared Object Descriptor */ 82126326Sjhb long sod_name; /* name (relative to load address) */ 83126326Sjhb u_int sod_library : 1, /* Searched for by library rules */ 84126326Sjhb sod_reserved : 31; 85126326Sjhb short sod_major; /* major version number */ 8671088Sjasone short sod_minor; /* minor version number */ 8771088Sjasone long sod_next; /* next sod */ 8871088Sjasone}; 8983366Sjulian 9071088Sjasone/* 9183366Sjulian * `Shared Object Map's are used by the run-time link editor (ld.so) to 9271088Sjasone * keep track of all shared objects loaded into a process' address space. 9371088Sjasone * These structures are only used at run-time and do not occur within 9471088Sjasone * the text or data segment of an executable or shared library. 9571088Sjasone */ 9671088Sjasonestruct so_map { /* Shared Object Map */ 9771088Sjasone caddr_t som_addr; /* Address at which object mapped */ 9871088Sjasone char *som_path; /* Path to mmap'ed file */ 9971088Sjasone struct so_map *som_next; /* Next map in chain */ 100153321Srodrigc struct sod *som_sod; /* Sod responsible for this map */ 101153321Srodrigc caddr_t som_sodbase; /* Base address of this sod */ 102153321Srodrigc u_int som_write : 1; /* Text is currently writable */ 103153321Srodrigc struct _dynamic *som_dynamic; /* _dynamic structure */ 104153321Srodrigc caddr_t som_spd; /* Private data */ 105153321Srodrigc}; 106153321Srodrigc 107153321Srodrigc/* 108153321Srodrigc * Symbol description with size. This is simply an `nlist' with 109153321Srodrigc * one field (nz_size) added. 110153321Srodrigc * Used to convey size information on items in the data segment 111153321Srodrigc * of shared objects. An array of these live in the shared object's 112153321Srodrigc * text segment and is addressed by the `sdt_nzlist' field. 113153321Srodrigc */ 114153321Srodrigcstruct nzlist { 115153321Srodrigc struct nlist nlist; 116153321Srodrigc u_long nz_size; 117153321Srodrigc}; 118153321Srodrigc 119153321Srodrigc#define nz_un nlist.n_un 120153321Srodrigc#define nz_strx nlist.n_un.n_strx 121153321Srodrigc#define nz_name nlist.n_un.n_name 122153321Srodrigc#define nz_type nlist.n_type 123153321Srodrigc#define nz_value nlist.n_value 124153321Srodrigc#define nz_desc nlist.n_desc 125153321Srodrigc#define nz_other nlist.n_other 12683366Sjulian 12771088Sjasone/* 12897995Sjhb * The `section_dispatch_table' structure contains offsets to various data 12997995Sjhb * structures needed to do run-time relocation. 13071088Sjasone */ 13183366Sjulianstruct section_dispatch_table { 132111883Sjhb struct so_map *sdt_loaded; /* List of loaded objects */ 133111883Sjhb long sdt_sods; /* List of shared objects descriptors */ 13471088Sjasone long sdt_paths; /* Library search paths */ 135126326Sjhb long sdt_got; /* Global offset table */ 13671088Sjasone long sdt_plt; /* Procedure linkage table */ 137100209Sgallatin long sdt_rel; /* Relocation table */ 138100209Sgallatin long sdt_hash; /* Symbol hash table */ 139100209Sgallatin long sdt_nzlist; /* Symbol table itself */ 140100209Sgallatin long sdt_filler2; /* Unused (was: stab_hash) */ 14171088Sjasone long sdt_buckets; /* Number of hash buckets */ 142153321Srodrigc long sdt_strings; /* Symbol strings */ 14371088Sjasone long sdt_str_sz; /* Size of symbol strings */ 14471088Sjasone long sdt_text_sz; /* Size of text area */ 14595322Shsu long sdt_plt_sz; /* Size of procedure linkage table */ 146136445Sjhb}; 14795322Shsu 148127954Sjhb/* 14988900Sjhb * RRS symbol hash table, addressed by `sdt_hash' in section_dispatch_table. 15088900Sjhb * Used to quickly lookup symbols of the shared object by hashing 15171088Sjasone * on the symbol's name. `rh_symbolnum' is the index of the symbol 152136445Sjhb * in the shared object's symbol list (`sdt_nzlist'), `rh_next' is 153126326Sjhb * the next symbol in the hash bucket (in case of collisions). 15471088Sjasone */ 15571088Sjasonestruct rrs_hash { 15671088Sjasone int rh_symbolnum; /* Symbol number */ 15771088Sjasone int rh_next; /* Next hash entry */ 15871088Sjasone}; 15971088Sjasone 16083366Sjulian/* 16171088Sjasone * `rt_symbols' is used to keep track of run-time allocated commons 16271088Sjasone * and data items copied from shared objects. 16371088Sjasone */ 16471088Sjasonestruct rt_symbol { 16571088Sjasone struct nzlist *rt_sp; /* The symbol */ 16671088Sjasone struct rt_symbol *rt_next; /* Next in linear list */ 16783366Sjulian struct rt_symbol *rt_link; /* Next in bucket */ 16883658Speter caddr_t rt_srcaddr; /* Address of "master" copy */ 169126326Sjhb struct so_map *rt_smp; /* Originating map */ 17071088Sjasone}; 17171088Sjasone 17283366Sjulian/* 17383650Sjhb * Debugger interface structure. 17471088Sjasone */ 17597995Sjhbstruct so_debug { 17697995Sjhb int dd_version; /* Version # of interface */ 17771088Sjasone int dd_in_debugger; /* Set when run by debugger */ 17883366Sjulian int dd_sym_loaded; /* Run-time linking brought more 179111883Sjhb symbols into scope */ 180111883Sjhb char *dd_bpt_addr; /* Address of rtld-generated bpt */ 18174912Sjhb int dd_bpt_shadow; /* Original contents of bpt */ 18271088Sjasone struct rt_symbol *dd_cc; /* Allocated commons/copied data */ 18371088Sjasone}; 18471088Sjasone 18571088Sjasone/* 18671088Sjasone * Version returned to crt0 from ld.so 18771088Sjasone */ 18871088Sjasone#define LDSO_VERSION_NONE 0 /* FreeBSD2.0, 2.0.5 */ 18971088Sjasone#define LDSO_VERSION_HAS_DLEXIT 1 /* includes dlexit in ld_entry */ 190133440Sjhb#define LDSO_VERSION_HAS_DLSYM3 2 /* includes 3-argument dlsym */ 19171088Sjasone#define LDSO_VERSION_HAS_DLADDR 3 /* includes dladdr in ld_entry */ 19295322Shsu 193136445Sjhb/* 19495322Shsu * Entry points into ld.so - user interface to the run-time linker. 195133440Sjhb * Entries are valid for the given version numbers returned by ld.so 196133440Sjhb * to crt0. 197133440Sjhb */ 198133440Sjhbstruct ld_entry { 199133440Sjhb void *(*dlopen) __P((const char *, int)); /* NONE */ 200134013Sjhb int (*dlclose) __P((void *)); /* NONE */ 201134013Sjhb void *(*dlsym) __P((void *, const char *)); /* NONE */ 202134013Sjhb const char *(*dlerror) __P((void)); /* NONE */ 203134013Sjhb void (*dlexit) __P((void)); /* HAS_DLEXIT */ 204134013Sjhb void *(*dlsym3) __P((void *, const char *, void *)); /* HAS_DLSYM3 */ 205133440Sjhb int (*dladdr) __P((const void *, 20671088Sjasone struct dl_info *)); /* HAS_DLADDR */ 207127954Sjhb}; 20888900Sjhb 20988900Sjhb/* 21071088Sjasone * This is the structure pointed at by the __DYNAMIC symbol if an 211136445Sjhb * executable requires the attention of the run-time link editor. 212134013Sjhb * __DYNAMIC is given the value zero if no run-time linking needs to 213126326Sjhb * be done (it is always present in shared objects). 214134013Sjhb * The union `d_un' provides for different versions of the dynamic 215126326Sjhb * linking mechanism (switched on by `d_version'). The last version 216126326Sjhb * used by Sun is 3. We leave some room here and go to version number 21771088Sjasone * 8 for NetBSD, the main difference lying in the support for the 21871088Sjasone * `nz_list' type of symbols. 21997995Sjhb */ 22097995Sjhb 22171088Sjasonestruct _dynamic { 22297995Sjhb int d_version; /* version # of this interface */ 22372200Sbmilekic struct so_debug *d_debug; 22474912Sjhb union { 22571088Sjasone struct section_dispatch_table *d_sdt; 22671088Sjasone } d_un; 22771088Sjasone struct ld_entry *d_entry; /* XXX */ 22871088Sjasone}; 22971088Sjasone 23071088Sjasone#define LD_VERSION_SUN (3) 23171088Sjasone#define LD_VERSION_BSD (8) 23271088Sjasone#define LD_VERSION_NZLIST_P(v) ((v) >= 8) 23371088Sjasone 23471088Sjasone#define LD_GOT(x) ((x)->d_un.d_sdt->sdt_got) 23571088Sjasone#define LD_PLT(x) ((x)->d_un.d_sdt->sdt_plt) 23671088Sjasone#define LD_REL(x) ((x)->d_un.d_sdt->sdt_rel) 23783366Sjulian#define LD_SYMBOL(x) ((x)->d_un.d_sdt->sdt_nzlist) 23871088Sjasone#define LD_HASH(x) ((x)->d_un.d_sdt->sdt_hash) 23971088Sjasone#define LD_STRINGS(x) ((x)->d_un.d_sdt->sdt_strings) 24071088Sjasone#define LD_NEED(x) ((x)->d_un.d_sdt->sdt_sods) 24183366Sjulian#define LD_BUCKETS(x) ((x)->d_un.d_sdt->sdt_buckets) 24271088Sjasone#define LD_PATHS(x) ((x)->d_un.d_sdt->sdt_paths) 24371088Sjasone 24497995Sjhb#define LD_GOTSZ(x) ((x)->d_un.d_sdt->sdt_plt - (x)->d_un.d_sdt->sdt_got) 24597995Sjhb#define LD_RELSZ(x) ((x)->d_un.d_sdt->sdt_hash - (x)->d_un.d_sdt->sdt_rel) 24671088Sjasone#define LD_HASHSZ(x) ((x)->d_un.d_sdt->sdt_nzlist - (x)->d_un.d_sdt->sdt_hash) 24783366Sjulian#define LD_STABSZ(x) ((x)->d_un.d_sdt->sdt_strings - (x)->d_un.d_sdt->sdt_nzlist) 248111883Sjhb#define LD_PLTSZ(x) ((x)->d_un.d_sdt->sdt_plt_sz) 249111883Sjhb#define LD_STRSZ(x) ((x)->d_un.d_sdt->sdt_str_sz) 25074912Sjhb#define LD_TEXTSZ(x) ((x)->d_un.d_sdt->sdt_text_sz) 25171088Sjasone 25271088Sjasone/* 25371088Sjasone * Interface to ld.so 25471088Sjasone */ 25571088Sjasonestruct crt_ldso { 25683366Sjulian int crt_ba; /* Base address of ld.so */ 25771088Sjasone int crt_dzfd; /* "/dev/zero" file descriptor (SunOS) */ 25871088Sjasone int crt_ldfd; /* ld.so file descriptor */ 25971088Sjasone struct _dynamic *crt_dp; /* Main's __DYNAMIC */ 26071088Sjasone char **crt_ep; /* environment strings */ 26195322Shsu caddr_t crt_bp; /* Breakpoint if run from debugger */ 262136445Sjhb char *crt_prog; /* Program name (v3) */ 26395322Shsu char *crt_ldso; /* Link editor name (v4) */ 264127954Sjhb struct ld_entry *crt_ldentry; /* dl*() access (v4) */ 26588900Sjhb char **crt_argv; /* argument strings (v5) */ 26688900Sjhb}; 26771088Sjasone 268136445Sjhb/* 269126885Sjhb * Version passed from crt0 to ld.so (1st argument to _rtld()). 270131249Sjhb */ 27171088Sjasone#define CRT_VERSION_SUN 1 27271088Sjasone#define CRT_VERSION_BSD_2 2 27397995Sjhb#define CRT_VERSION_BSD_3 3 27497995Sjhb#define CRT_VERSION_BSD_4 4 27571088Sjasone#define CRT_VERSION_BSD_5 5 27671088Sjasone 27772200Sbmilekic/* 27874912Sjhb * Maximum number of recognized shared object version numbers. 27971088Sjasone */ 28071088Sjasone#define MAXDEWEY 8 28171088Sjasone 28271088Sjasone/* 28371088Sjasone * Header of the hints file. 28471088Sjasone */ 28583366Sjulianstruct hints_header { 28671088Sjasone long hh_magic; 28771088Sjasone#define HH_MAGIC 011421044151 28871088Sjasone long hh_version; /* Interface version number */ 28971088Sjasone#define LD_HINTS_VERSION_1 1 29071088Sjasone#define LD_HINTS_VERSION_2 2 29171088Sjasone long hh_hashtab; /* Location of hash table */ 29283366Sjulian long hh_nbucket; /* Number of buckets in hashtab */ 29383650Sjhb long hh_strtab; /* Location of strings */ 29471088Sjasone long hh_strtab_sz; /* Size of strings */ 29571088Sjasone long hh_ehints; /* End of hints (max offset in file) */ 29671088Sjasone long hh_dirlist; /* Colon-separated list of srch dirs */ 29771088Sjasone}; 29883366Sjulian 29983650Sjhb#define HH_BADMAG(hdr) ((hdr).hh_magic != HH_MAGIC) 30071088Sjasone 30171088Sjasone/* 30297995Sjhb * Hash table element in hints file. 30397995Sjhb */ 30471088Sjasonestruct hints_bucket { 30583366Sjulian /* namex and pathx are indices into the string table */ 306111883Sjhb int hi_namex; /* Library name */ 307111883Sjhb int hi_pathx; /* Full path */ 30874912Sjhb int hi_dewey[MAXDEWEY]; /* The versions */ 30971088Sjasone int hi_ndewey; /* Number of version numbers */ 31071088Sjasone#define hi_major hi_dewey[0] 31171088Sjasone#define hi_minor hi_dewey[1] 31271088Sjasone int hi_next; /* Next in this bucket */ 31371088Sjasone}; 31483366Sjulian 31571088Sjasone#define _PATH_LD_HINTS "/var/run/ld.so.hints" 31671088Sjasone 31771088Sjasone#endif /* !__ELF__ */ 31871088Sjasone 31995322Shsu#endif /* _LINK_H_ */ 320136445Sjhb