link.h (90f2ed3a8f966e570ae2dac9cfefda8ae9263e37) | link.h (a70c96594a91bffb4cd231cc67facca8a7fa901d) |
---|---|
1/* | 1/* |
2 * Copyright (c) 1993 Paul Kranenburg 3 * All rights reserved. 4 * 5 * Redistribution and use in source and binary forms, with or without 6 * modification, are permitted provided that the following conditions 7 * are met: 8 * 1. Redistributions of source code must retain the above copyright 9 * notice, this list of conditions and the following disclaimer. 10 * 2. Redistributions in binary form must reproduce the above copyright 11 * notice, this list of conditions and the following disclaimer in the 12 * documentation and/or other materials provided with the distribution. 13 * 3. All advertising materials mentioning features or use of this software 14 * must display the following acknowledgement: 15 * This product includes software developed by Paul Kranenburg. 16 * 4. The name of the author may not be used to endorse or promote products 17 * derived from this software withough specific prior written permission 18 * 19 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR 20 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES 21 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 22 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, 23 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT 24 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 25 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 26 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 27 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF 28 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 29 * 30 * $Id$ 31 */ 32 33/* |
|
2 * RRS section definitions. | 34 * RRS section definitions. |
3 * Nomenclature and, more importantly, the layout of the various 4 * data structures defined in this header file are borrowed from 5 * Sun Microsystems' original <link.h>, so we can provide compatibility 6 * with the SunOS 4.x shared library scheme. | |
7 * | 35 * |
8 * $Id: link.h,v 1.2 1993/10/22 21:04:19 pk Exp $ 9 * (derived from: @(#)link.h 1.6 88/08/19 SMI 10 * Copyright (c) 1987 by Sun Microsystems, Inc.) | 36 * The layout of some data structures defined in this header file is 37 * such that we can provide compatibility with the SunOS 4.x shared 38 * library scheme. |
11 */ 12 13#ifndef _LINK_H_ 14#define _LINK_H_ 15 16/* | 39 */ 40 41#ifndef _LINK_H_ 42#define _LINK_H_ 43 44/* |
17 * A `link_object' structure descibes a shared object that is needed | 45 * A `Shared Object Descriptor' descibes a shared object that is needed |
18 * to complete the link edit process of the object containing it. | 46 * to complete the link edit process of the object containing it. |
19 * A list of such objects (chained through `lo_next') is pointed at 20 * by `ld_need' in the link_dynamic_2 structure. | 47 * A list of such objects (chained through `sod_next') is pointed at 48 * by `sdt_sods' in the section_dispatch_table structure. |
21 */ 22 | 49 */ 50 |
23struct link_object { 24 long lo_name; /* name (relative to load address) */ 25 u_int lo_library : 1, /* searched for by library rules */ 26 lo_unused : 31; 27 short lo_major; /* major version number */ 28 short lo_minor; /* minor version number */ 29 long lo_next; /* next one (often relative) */ | 51struct sod { /* Shared Object Descriptor */ 52 long sod_name; /* name (relative to load address) */ 53 u_int sod_library : 1, /* Searched for by library rules */ 54 sod_reserved : 31; 55 short sod_major; /* major version number */ 56 short sod_minor; /* minor version number */ 57 long sod_next; /* next sod */ |
30}; 31 32/* | 58}; 59 60/* |
33 * `link_maps' are used by the run-time link editor (ld.so) to keep 34 * track of all shared objects loaded into a process' address space. | 61 * `Shared Object Map's are used by the run-time link editor (ld.so) to 62 * keep track of all shared objects loaded into a process' address space. |
35 * These structures are only used at run-time and do not occur within 36 * the text or data segment of an executable or shared library. 37 */ | 63 * These structures are only used at run-time and do not occur within 64 * the text or data segment of an executable or shared library. 65 */ |
38struct link_map { 39 caddr_t lm_addr; /* address at which object mapped */ 40 char *lm_name; /* full name of loaded object */ 41 struct link_map *lm_next; /* next object in map */ 42 struct link_object *lm_lop; /* link object that got us here */ 43 caddr_t lm_lob; /* base address for said link object */ 44 u_int lm_rwt : 1; /* text is read/write */ 45 struct link_dynamic *lm_ld; /* dynamic structure */ 46 caddr_t lm_lpd; /* loader private data */ | 66struct so_map { /* Shared Object Map */ 67 caddr_t som_addr; /* Address at which object mapped */ 68 char *som_path; /* Path to mmap'ed file */ 69 struct so_map *som_next; /* Next map in chain */ 70 struct sod *som_sod; /* Sod responsible for this map */ 71 caddr_t som_sodbase; /* Base address of this sod */ 72 u_int som_write : 1; /* Text is currently writable */ 73 struct _dynamic *som_dynamic; /* _dynamic structure */ 74 caddr_t som_spd; /* Private data */ |
47}; 48 49/* 50 * Symbol description with size. This is simply an `nlist' with 51 * one field (nz_size) added. 52 * Used to convey size information on items in the data segment 53 * of shared objects. An array of these live in the shared object's | 75}; 76 77/* 78 * Symbol description with size. This is simply an `nlist' with 79 * one field (nz_size) added. 80 * Used to convey size information on items in the data segment 81 * of shared objects. An array of these live in the shared object's |
54 * text segment and is address by the `ld_symbols' field. | 82 * text segment and is addressed by the `sdt_nzlist' field. |
55 */ 56struct nzlist { 57 struct nlist nlist; 58 u_long nz_size; 59#define nz_un nlist.n_un 60#define nz_strx nlist.n_un.n_strx 61#define nz_name nlist.n_un.n_name 62#define nz_type nlist.n_type 63#define nz_value nlist.n_value 64#define nz_desc nlist.n_desc 65#define nz_other nlist.n_other 66}; 67 | 83 */ 84struct nzlist { 85 struct nlist nlist; 86 u_long nz_size; 87#define nz_un nlist.n_un 88#define nz_strx nlist.n_un.n_strx 89#define nz_name nlist.n_un.n_name 90#define nz_type nlist.n_type 91#define nz_value nlist.n_value 92#define nz_desc nlist.n_desc 93#define nz_other nlist.n_other 94}; 95 |
96#define N_AUX(p) ((p)->n_other & 0xf) 97#define N_RESERVED(p) (((unsigned int)(p)->n_other >> 4) & 0xf) 98#define N_OTHER(r, v) (((unsigned int)(r) << 4) | ((v) & 0xf)) 99 100#define AUX_OBJECT 1 101#define AUX_FUNC 2 102 103 |
|
68/* | 104/* |
69 * The `link_dynamic_2' structure contains offsets to various data | 105 * The `section_dispatch_table' structure contains offsets to various data |
70 * structures needed to do run-time relocation. 71 */ | 106 * structures needed to do run-time relocation. 107 */ |
72struct link_dynamic_2 { 73 struct link_map *ld_loaded; /* list of loaded objects */ 74 long ld_need; /* list of needed objects */ 75 long ld_rules; /* search rules for library objects */ 76 long ld_got; /* global offset table */ 77 long ld_plt; /* procedure linkage table */ 78 long ld_rel; /* relocation table */ 79 long ld_hash; /* symbol hash table */ 80 long ld_symbols; /* symbol table itself */ 81 long (*ld_stab_hash)(); /* "pointer" to symbol hash function */ 82 long ld_buckets; /* number of hash buckets */ 83 long ld_strings; /* symbol strings */ 84 long ld_str_sz; /* size of symbol strings */ 85 long ld_text_sz; /* size of text area */ 86 long ld_plt_sz; /* size of procedure linkage table */ | 108struct section_dispatch_table { 109 struct so_map *sdt_loaded; /* List of loaded objects */ 110 long sdt_sods; /* List of shared objects descriptors */ 111 long sdt_filler1; /* Unused (was: search rules) */ 112 long sdt_got; /* Global offset table */ 113 long sdt_plt; /* Procedure linkage table */ 114 long sdt_rel; /* Relocation table */ 115 long sdt_hash; /* Symbol hash table */ 116 long sdt_nzlist; /* Symbol table itself */ 117 long sdt_filler2; /* Unused (was: stab_hash) */ 118 long sdt_buckets; /* Number of hash buckets */ 119 long sdt_strings; /* Symbol strings */ 120 long sdt_str_sz; /* Size of symbol strings */ 121 long sdt_text_sz; /* Size of text area */ 122 long sdt_plt_sz; /* Size of procedure linkage table */ |
87}; 88 89/* | 123}; 124 125/* |
90 * RRS symbol hash table, addressed by `ld_hash' in link_dynamic_2 | 126 * RRS symbol hash table, addressed by `sdt_hash' in section_dispatch_table. |
91 * Used to quickly lookup symbols of the shared object by hashing 92 * on the symbol's name. `rh_symbolnum' is the index of the symbol | 127 * Used to quickly lookup symbols of the shared object by hashing 128 * on the symbol's name. `rh_symbolnum' is the index of the symbol |
93 * in the shared object's symbol list (`ld_symbols'), `rh_next' is | 129 * in the shared object's symbol list (`sdt_nzlist'), `rh_next' is |
94 * the next symbol in the hash bucket (in case of collisions). 95 */ 96struct rrs_hash { | 130 * the next symbol in the hash bucket (in case of collisions). 131 */ 132struct rrs_hash { |
97 int rh_symbolnum; /* symbol number */ 98 int rh_next; /* next hash entry */ | 133 int rh_symbolnum; /* Symbol number */ 134 int rh_next; /* Next hash entry */ |
99}; 100 101/* 102 * `rt_symbols' is used to keep track of run-time allocated commons 103 * and data items copied from shared objects. 104 */ 105struct rt_symbol { | 135}; 136 137/* 138 * `rt_symbols' is used to keep track of run-time allocated commons 139 * and data items copied from shared objects. 140 */ 141struct rt_symbol { |
106 struct nzlist *rt_sp; /* the symbol */ 107 struct rt_symbol *rt_next; /* next in linear list */ 108 struct rt_symbol *rt_link; /* next in bucket */ 109 caddr_t rt_srcaddr; /* address of "master" copy */ | 142 struct nzlist *rt_sp; /* The symbol */ 143 struct rt_symbol *rt_next; /* Next in linear list */ 144 struct rt_symbol *rt_link; /* Next in bucket */ 145 caddr_t rt_srcaddr; /* Address of "master" copy */ 146 struct so_map *rt_smp; /* Originating map */ |
110}; 111 112/* 113 * Debugger interface structure. 114 */ | 147}; 148 149/* 150 * Debugger interface structure. 151 */ |
115struct ld_debug { 116 int ldd_version; /* version # of interface */ 117 int ldd_in_debugger; /* a debugger is running us */ 118 int ldd_sym_loaded; /* we loaded some symbols */ 119 char *ldd_bp_addr; /* place for ld-generated bpt */ 120 int ldd_bp_inst; /* instruction which was there */ 121 struct rt_symbol *ldd_cp; /* commons we built */ | 152struct so_debug { 153 int dd_version; /* Version # of interface */ 154 int dd_in_debugger; /* Set when run by debugger */ 155 int dd_sym_loaded; /* Run-time linking brought more 156 symbols into scope */ 157 char *dd_bpt_addr; /* Address of rtld-generated bpt */ 158 int dd_bpt_shadow; /* Original contents of bpt */ 159 struct rt_symbol *dd_cc; /* Allocated commons/copied data */ |
122}; 123 124/* 125 * Entry points into ld.so - user interface to the run-time linker. | 160}; 161 162/* 163 * Entry points into ld.so - user interface to the run-time linker. |
126 * (see also libdl.a) | |
127 */ 128struct ld_entry { | 164 */ 165struct ld_entry { |
129 int (*dlopen)(); 130 int (*dlclose)(); 131 int (*dlsym)(); | 166 void *(*dlopen) __P((char *, int)); 167 int (*dlclose) __P((void *)); 168 void *(*dlsym) __P((void *, char *)); 169 int (*dlctl) __P((void *, int, void *)); |
132}; 133 134/* | 170}; 171 172/* |
173 * dlctl() commands 174 */ 175#define DL_GETERRNO 1 176 177/* 178 * dl*() prototypes. 179 */ 180extern void *dlopen __P((char *, int)); 181extern int dlclose __P((void *)); 182extern void *dlsym __P((void *, char *)); 183extern int dlctl __P((void *, int, void *)); 184 185 186/* |
|
135 * This is the structure pointed at by the __DYNAMIC symbol if an 136 * executable requires the attention of the run-time link editor. 137 * __DYNAMIC is given the value zero if no run-time linking needs to 138 * be done (it is always present in shared objects). | 187 * This is the structure pointed at by the __DYNAMIC symbol if an 188 * executable requires the attention of the run-time link editor. 189 * __DYNAMIC is given the value zero if no run-time linking needs to 190 * be done (it is always present in shared objects). |
139 * The union `ld_un' provides for different versions of the dynamic 140 * linking mechanism (switched on by `ld_version'). The last version | 191 * The union `d_un' provides for different versions of the dynamic 192 * linking mechanism (switched on by `d_version'). The last version |
141 * used by Sun is 3. We leave some room here and go to version number 142 * 8 for NetBSD, the main difference lying in the support for the 143 * `nz_list' type of symbols. 144 */ 145 | 193 * used by Sun is 3. We leave some room here and go to version number 194 * 8 for NetBSD, the main difference lying in the support for the 195 * `nz_list' type of symbols. 196 */ 197 |
146struct link_dynamic { 147 int ld_version; /* version # of this structure */ 148 struct ld_debug *ldd; | 198struct _dynamic { 199 int d_version; /* version # of this interface */ 200 struct so_debug *d_debug; |
149 union { | 201 union { |
150 struct link_dynamic_2 *ld_2; 151 } ld_un; 152 struct ld_entry *ld_entry; | 202 struct section_dispatch_table *d_sdt; 203 } d_un; 204 struct ld_entry *d_entry; |
153}; 154 155#define LD_VERSION_SUN (3) 156#define LD_VERSION_BSD (8) 157#define LD_VERSION_NZLIST_P(v) ((v) >= 8) 158 | 205}; 206 207#define LD_VERSION_SUN (3) 208#define LD_VERSION_BSD (8) 209#define LD_VERSION_NZLIST_P(v) ((v) >= 8) 210 |
159#define LD_GOT(x) ((x)->ld_un.ld_2->ld_got) 160#define LD_PLT(x) ((x)->ld_un.ld_2->ld_plt) 161#define LD_REL(x) ((x)->ld_un.ld_2->ld_rel) 162#define LD_SYMBOL(x) ((x)->ld_un.ld_2->ld_symbols) 163#define LD_HASH(x) ((x)->ld_un.ld_2->ld_hash) 164#define LD_STRINGS(x) ((x)->ld_un.ld_2->ld_strings) 165#define LD_NEED(x) ((x)->ld_un.ld_2->ld_need) 166#define LD_BUCKETS(x) ((x)->ld_un.ld_2->ld_buckets) | 211#define LD_GOT(x) ((x)->d_un.d_sdt->sdt_got) 212#define LD_PLT(x) ((x)->d_un.d_sdt->sdt_plt) 213#define LD_REL(x) ((x)->d_un.d_sdt->sdt_rel) 214#define LD_SYMBOL(x) ((x)->d_un.d_sdt->sdt_nzlist) 215#define LD_HASH(x) ((x)->d_un.d_sdt->sdt_hash) 216#define LD_STRINGS(x) ((x)->d_un.d_sdt->sdt_strings) 217#define LD_NEED(x) ((x)->d_un.d_sdt->sdt_sods) 218#define LD_BUCKETS(x) ((x)->d_un.d_sdt->sdt_buckets) |
167 | 219 |
168#define LD_GOTSZ(x) ((x)->ld_un.ld_2->ld_plt - (x)->ld_un.ld_2->ld_got) 169#define LD_RELSZ(x) ((x)->ld_un.ld_2->ld_hash - (x)->ld_un.ld_2->ld_rel) 170#define LD_HASHSZ(x) ((x)->ld_un.ld_2->ld_symbols - (x)->ld_un.ld_2->ld_hash) 171#define LD_STABSZ(x) ((x)->ld_un.ld_2->ld_strings - (x)->ld_un.ld_2->ld_symbols) 172#define LD_PLTSZ(x) ((x)->ld_un.ld_2->ld_plt_sz) 173#define LD_STRSZ(x) ((x)->ld_un.ld_2->ld_str_sz) 174#define LD_TEXTSZ(x) ((x)->ld_un.ld_2->ld_text_sz) | 220#define LD_GOTSZ(x) ((x)->d_un.d_sdt->sdt_plt - (x)->d_un.d_sdt->sdt_got) 221#define LD_RELSZ(x) ((x)->d_un.d_sdt->sdt_hash - (x)->d_un.d_sdt->sdt_rel) 222#define LD_HASHSZ(x) ((x)->d_un.d_sdt->sdt_nzlist - (x)->d_un.d_sdt->sdt_hash) 223#define LD_STABSZ(x) ((x)->d_un.d_sdt->sdt_strings - (x)->d_un.d_sdt->sdt_nzlist) 224#define LD_PLTSZ(x) ((x)->d_un.d_sdt->sdt_plt_sz) 225#define LD_STRSZ(x) ((x)->d_un.d_sdt->sdt_str_sz) 226#define LD_TEXTSZ(x) ((x)->d_un.d_sdt->sdt_text_sz) |
175 176/* | 227 228/* |
177 * Interface to ld.so (see link(5)) | 229 * Interface to ld.so |
178 */ 179struct crt_ldso { 180 int crt_ba; /* Base address of ld.so */ 181 int crt_dzfd; /* "/dev/zero" file decriptor (SunOS) */ 182 int crt_ldfd; /* ld.so file descriptor */ | 230 */ 231struct crt_ldso { 232 int crt_ba; /* Base address of ld.so */ 233 int crt_dzfd; /* "/dev/zero" file decriptor (SunOS) */ 234 int crt_ldfd; /* ld.so file descriptor */ |
183 struct link_dynamic *crt_dp;/* Main's __DYNAMIC */ | 235 struct _dynamic *crt_dp; /* Main's __DYNAMIC */ |
184 char **crt_ep; /* environment strings */ 185 caddr_t crt_bp; /* Breakpoint if run from debugger */ | 236 char **crt_ep; /* environment strings */ 237 caddr_t crt_bp; /* Breakpoint if run from debugger */ |
238 char *crt_prog; /* Program name */ |
|
186}; 187 188/* 189 * Version passed from crt0 to ld.so (1st argument to _rtld()). 190 */ 191#define CRT_VERSION_SUN 1 192#define CRT_VERSION_BSD 2 | 239}; 240 241/* 242 * Version passed from crt0 to ld.so (1st argument to _rtld()). 243 */ 244#define CRT_VERSION_SUN 1 245#define CRT_VERSION_BSD 2 |
246#define CRT_VERSION_BSD_2 2 247#define CRT_VERSION_BSD_3 3 |
|
193 194 195/* 196 * Maximum number of recognized shared object version numbers. 197 */ 198#define MAXDEWEY 8 199 200/* --- 34 unchanged lines hidden --- | 248 249 250/* 251 * Maximum number of recognized shared object version numbers. 252 */ 253#define MAXDEWEY 8 254 255/* --- 34 unchanged lines hidden --- |