[BACK]Return to link.h CVS log [TXT][DIR] Up to [cvs.NetBSD.org] / src / libexec / ld.aout_so

Annotation of src/libexec/ld.aout_so/link.h, Revision 1.15

1.15    ! matt        1: /*     $NetBSD: link.h,v 1.14 1998/09/05 13:08:41 pk Exp $     */
1.5       cgd         2:
1.14      pk          3: /*-
                      4:  * Copyright (c) 1998 The NetBSD Foundation, Inc.
1.3       pk          5:  * All rights reserved.
                      6:  *
1.14      pk          7:  * This code is derived from software contributed to The NetBSD Foundation
                      8:  * by Paul Kranenburg.
                      9:  *
1.3       pk         10:  * Redistribution and use in source and binary forms, with or without
                     11:  * modification, are permitted provided that the following conditions
                     12:  * are met:
                     13:  * 1. Redistributions of source code must retain the above copyright
                     14:  *    notice, this list of conditions and the following disclaimer.
                     15:  * 2. Redistributions in binary form must reproduce the above copyright
                     16:  *    notice, this list of conditions and the following disclaimer in the
                     17:  *    documentation and/or other materials provided with the distribution.
                     18:  * 3. All advertising materials mentioning features or use of this software
                     19:  *    must display the following acknowledgement:
1.14      pk         20:  *        This product includes software developed by the NetBSD
                     21:  *        Foundation, Inc. and its contributors.
                     22:  * 4. Neither the name of The NetBSD Foundation nor the names of its
                     23:  *    contributors may be used to endorse or promote products derived
                     24:  *    from this software without specific prior written permission.
1.3       pk         25:  *
1.14      pk         26:  * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
                     27:  * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
                     28:  * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
                     29:  * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
                     30:  * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
                     31:  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
                     32:  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
                     33:  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
                     34:  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
                     35:  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
                     36:  * POSSIBILITY OF SUCH DAMAGE.
1.3       pk         37:  */
                     38:
                     39: /*
1.1       pk         40:  * RRS section definitions.
                     41:  *
1.3       pk         42:  * The layout of some data structures defined in this header file is
                     43:  * such that we can provide compatibility with the SunOS 4.x shared
                     44:  * library scheme.
1.1       pk         45:  */
                     46:
                     47: #ifndef _LINK_H_
                     48: #define _LINK_H_
1.13      thorpej    49:
                     50: #include <dlfcn.h>                     /* for Dl_info */
1.1       pk         51:
                     52: /*
1.3       pk         53:  * A `Shared Object Descriptor' descibes a shared object that is needed
1.1       pk         54:  * to complete the link edit process of the object containing it.
1.3       pk         55:  * A list of such objects (chained through `sod_next') is pointed at
                     56:  * by `sdt_sods' in the section_dispatch_table structure.
1.1       pk         57:  */
                     58:
1.3       pk         59: struct sod {   /* Shared Object Descriptor */
                     60:        long    sod_name;               /* name (relative to load address) */
                     61:        u_int   sod_library  : 1,       /* Searched for by library rules */
                     62:                sod_reserved : 31;
                     63:        short   sod_major;              /* major version number */
                     64:        short   sod_minor;              /* minor version number */
                     65:        long    sod_next;               /* next sod */
1.1       pk         66: };
                     67:
                     68: /*
1.3       pk         69:  * `Shared Object Map's are used by the run-time link editor (ld.so) to
                     70:  * keep track of all shared objects loaded into a process' address space.
1.1       pk         71:  * These structures are only used at run-time and do not occur within
                     72:  * the text or data segment of an executable or shared library.
                     73:  */
1.3       pk         74: struct so_map {                /* Shared Object Map */
                     75:        caddr_t         som_addr;       /* Address at which object mapped */
                     76:        char            *som_path;      /* Path to mmap'ed file */
                     77:        struct so_map   *som_next;      /* Next map in chain */
                     78:        struct sod      *som_sod;       /* Sod responsible for this map */
                     79:        caddr_t         som_sodbase;    /* Base address of this sod */
                     80:        u_int           som_write : 1;  /* Text is currently writable */
                     81:        struct _dynamic *som_dynamic;   /* _dynamic structure */
                     82:        caddr_t         som_spd;        /* Private data */
1.1       pk         83: };
                     84:
                     85: /*
                     86:  * Symbol description with size. This is simply an `nlist' with
                     87:  * one field (nz_size) added.
                     88:  * Used to convey size information on items in the data segment
                     89:  * of shared objects. An array of these live in the shared object's
1.3       pk         90:  * text segment and is addressed by the `sdt_nzlist' field.
1.1       pk         91:  */
                     92: struct nzlist {
                     93:        struct nlist    nlist;
                     94:        u_long          nz_size;
                     95: #define nz_un          nlist.n_un
                     96: #define nz_strx                nlist.n_un.n_strx
                     97: #define nz_name                nlist.n_un.n_name
                     98: #define nz_type                nlist.n_type
                     99: #define nz_value       nlist.n_value
                    100: #define nz_desc                nlist.n_desc
                    101: #define nz_other       nlist.n_other
                    102: };
                    103:
1.3       pk        104: #define N_AUX(p)       ((p)->n_other & 0xf)
1.6       pk        105: #define N_BIND(p)      (((unsigned int)(p)->n_other >> 4) & 0xf)
1.3       pk        106: #define N_OTHER(r, v)  (((unsigned int)(r) << 4) | ((v) & 0xf))
                    107:
                    108: #define AUX_OBJECT     1
                    109: #define AUX_FUNC       2
1.15    ! matt      110: #define AUX_LABEL      3
1.6       pk        111: /*#define BIND_LOCAL   0       not used */
                    112: /*#define BIND_GLOBAL  1       not used */
                    113: #define BIND_WEAK      2
1.3       pk        114:
                    115:
1.1       pk        116: /*
1.3       pk        117:  * The `section_dispatch_table' structure contains offsets to various data
1.1       pk        118:  * structures needed to do run-time relocation.
                    119:  */
1.3       pk        120: struct section_dispatch_table {
                    121:        struct so_map *sdt_loaded;      /* List of loaded objects */
                    122:        long    sdt_sods;               /* List of shared objects descriptors */
1.7       pk        123:        long    sdt_paths;              /* Library search paths */
1.3       pk        124:        long    sdt_got;                /* Global offset table */
                    125:        long    sdt_plt;                /* Procedure linkage table */
                    126:        long    sdt_rel;                /* Relocation table */
                    127:        long    sdt_hash;               /* Symbol hash table */
                    128:        long    sdt_nzlist;             /* Symbol table itself */
                    129:        long    sdt_filler2;            /* Unused (was: stab_hash) */
                    130:        long    sdt_buckets;            /* Number of hash buckets */
                    131:        long    sdt_strings;            /* Symbol strings */
                    132:        long    sdt_str_sz;             /* Size of symbol strings */
                    133:        long    sdt_text_sz;            /* Size of text area */
                    134:        long    sdt_plt_sz;             /* Size of procedure linkage table */
1.1       pk        135: };
                    136:
                    137: /*
1.3       pk        138:  * RRS symbol hash table, addressed by `sdt_hash' in section_dispatch_table.
1.1       pk        139:  * Used to quickly lookup symbols of the shared object by hashing
                    140:  * on the symbol's name. `rh_symbolnum' is the index of the symbol
1.3       pk        141:  * in the shared object's symbol list (`sdt_nzlist'), `rh_next' is
1.1       pk        142:  * the next symbol in the hash bucket (in case of collisions).
                    143:  */
                    144: struct rrs_hash {
1.3       pk        145:        int     rh_symbolnum;           /* Symbol number */
                    146:        int     rh_next;                /* Next hash entry */
1.1       pk        147: };
                    148:
                    149: /*
                    150:  * `rt_symbols' is used to keep track of run-time allocated commons
                    151:  * and data items copied from shared objects.
                    152:  */
                    153: struct rt_symbol {
1.3       pk        154:        struct nzlist           *rt_sp;         /* The symbol */
                    155:        struct rt_symbol        *rt_next;       /* Next in linear list */
                    156:        struct rt_symbol        *rt_link;       /* Next in bucket */
                    157:        caddr_t                 rt_srcaddr;     /* Address of "master" copy */
                    158:        struct so_map           *rt_smp;        /* Originating map */
1.1       pk        159: };
                    160:
                    161: /*
                    162:  * Debugger interface structure.
                    163:  */
1.3       pk        164: struct so_debug {
                    165:        int     dd_version;             /* Version # of interface */
                    166:        int     dd_in_debugger;         /* Set when run by debugger */
                    167:        int     dd_sym_loaded;          /* Run-time linking brought more
                    168:                                           symbols into scope */
                    169:        char     *dd_bpt_addr;          /* Address of rtld-generated bpt */
                    170:        int     dd_bpt_shadow;          /* Original contents of bpt */
                    171:        struct rt_symbol *dd_cc;        /* Allocated commons/copied data */
1.1       pk        172: };
                    173:
                    174: /*
                    175:  * Entry points into ld.so - user interface to the run-time linker.
                    176:  */
                    177: struct ld_entry {
1.11      scottr    178:        void    *(*dlopen) __P((const char *, int));
1.3       pk        179:        int     (*dlclose) __P((void *));
1.11      scottr    180:        void    *(*dlsym) __P((void *, const char *));
1.3       pk        181:        int     (*dlctl) __P((void *, int, void *));
1.9       pk        182:        void    (*dlexit) __P((void));
1.12      pk        183:        int     (*dladdr) __P((void *, Dl_info *));
                    184:        void    (*dlrsrvd[2]) __P((void));
1.1       pk        185: };
1.3       pk        186:
                    187: /*
1.1       pk        188:  * This is the structure pointed at by the __DYNAMIC symbol if an
                    189:  * executable requires the attention of the run-time link editor.
                    190:  * __DYNAMIC is given the value zero if no run-time linking needs to
                    191:  * be done (it is always present in shared objects).
1.3       pk        192:  * The union `d_un' provides for different versions of the dynamic
                    193:  * linking mechanism (switched on by `d_version'). The last version
1.1       pk        194:  * used by Sun is 3. We leave some room here and go to version number
                    195:  * 8 for NetBSD, the main difference lying in the support for the
                    196:  * `nz_list' type of symbols.
                    197:  */
                    198:
1.3       pk        199: struct _dynamic {
                    200:        int             d_version;      /* version # of this interface */
                    201:        struct so_debug *d_debug;
1.1       pk        202:        union {
1.3       pk        203:                struct section_dispatch_table *d_sdt;
                    204:        } d_un;
1.9       pk        205:        struct ld_entry *d_entry;       /* compat - now in crt_ldso */
1.1       pk        206: };
                    207:
                    208: #define LD_VERSION_SUN         (3)
                    209: #define LD_VERSION_BSD         (8)
                    210: #define LD_VERSION_NZLIST_P(v) ((v) >= 8)
                    211:
1.3       pk        212: #define LD_GOT(x)      ((x)->d_un.d_sdt->sdt_got)
                    213: #define LD_PLT(x)      ((x)->d_un.d_sdt->sdt_plt)
                    214: #define LD_REL(x)      ((x)->d_un.d_sdt->sdt_rel)
                    215: #define LD_SYMBOL(x)   ((x)->d_un.d_sdt->sdt_nzlist)
                    216: #define LD_HASH(x)     ((x)->d_un.d_sdt->sdt_hash)
                    217: #define LD_STRINGS(x)  ((x)->d_un.d_sdt->sdt_strings)
                    218: #define LD_NEED(x)     ((x)->d_un.d_sdt->sdt_sods)
                    219: #define LD_BUCKETS(x)  ((x)->d_un.d_sdt->sdt_buckets)
1.7       pk        220: #define LD_PATHS(x)    ((x)->d_un.d_sdt->sdt_paths)
1.3       pk        221:
                    222: #define LD_GOTSZ(x)    ((x)->d_un.d_sdt->sdt_plt - (x)->d_un.d_sdt->sdt_got)
                    223: #define LD_RELSZ(x)    ((x)->d_un.d_sdt->sdt_hash - (x)->d_un.d_sdt->sdt_rel)
                    224: #define LD_HASHSZ(x)   ((x)->d_un.d_sdt->sdt_nzlist - (x)->d_un.d_sdt->sdt_hash)
                    225: #define LD_STABSZ(x)   ((x)->d_un.d_sdt->sdt_strings - (x)->d_un.d_sdt->sdt_nzlist)
                    226: #define LD_PLTSZ(x)    ((x)->d_un.d_sdt->sdt_plt_sz)
                    227: #define LD_STRSZ(x)    ((x)->d_un.d_sdt->sdt_str_sz)
                    228: #define LD_TEXTSZ(x)   ((x)->d_un.d_sdt->sdt_text_sz)
1.1       pk        229:
                    230: /*
1.3       pk        231:  * Interface to ld.so
1.1       pk        232:  */
                    233: struct crt_ldso {
                    234:        int             crt_ba;         /* Base address of ld.so */
                    235:        int             crt_dzfd;       /* "/dev/zero" file decriptor (SunOS) */
                    236:        int             crt_ldfd;       /* ld.so file descriptor */
1.3       pk        237:        struct _dynamic *crt_dp;        /* Main's __DYNAMIC */
1.1       pk        238:        char            **crt_ep;       /* environment strings */
                    239:        caddr_t         crt_bp;         /* Breakpoint if run from debugger */
1.6       pk        240:        char            *crt_prog;      /* Program name (v3) */
                    241:        char            *crt_ldso;      /* Link editor name (v4) */
                    242:        struct ld_entry *crt_ldentry;   /* dl*() access (v4) */
1.1       pk        243: };
                    244:
                    245: /*
                    246:  * Version passed from crt0 to ld.so (1st argument to _rtld()).
                    247:  */
                    248: #define CRT_VERSION_SUN                1
1.3       pk        249: #define CRT_VERSION_BSD_2      2
                    250: #define CRT_VERSION_BSD_3      3
1.6       pk        251: #define CRT_VERSION_BSD_4      4
1.2       pk        252:
                    253:
                    254: /*
                    255:  * Maximum number of recognized shared object version numbers.
                    256:  */
                    257: #define MAXDEWEY       8
                    258:
                    259: /*
                    260:  * Header of the hints file.
                    261:  */
                    262: struct hints_header {
                    263:        long            hh_magic;
                    264: #define HH_MAGIC       011421044151
                    265:        long            hh_version;     /* Interface version number */
                    266: #define LD_HINTS_VERSION_1     1
1.10      pk        267: #define LD_HINTS_VERSION_2     2
1.2       pk        268:        long            hh_hashtab;     /* Location of hash table */
                    269:        long            hh_nbucket;     /* Number of buckets in hashtab */
                    270:        long            hh_strtab;      /* Location of strings */
                    271:        long            hh_strtab_sz;   /* Size of strings */
                    272:        long            hh_ehints;      /* End of hints (max offset in file) */
1.10      pk        273:        long            hh_dirlist;     /* Colon-separated list of srch dirs */
1.2       pk        274: };
                    275:
                    276: #define HH_BADMAG(hdr) ((hdr).hh_magic != HH_MAGIC)
                    277:
                    278: /*
                    279:  * Hash table element in hints file.
                    280:  */
                    281: struct hints_bucket {
                    282:        /* namex and pathx are indices into the string table */
                    283:        int             hi_namex;               /* Library name */
                    284:        int             hi_pathx;               /* Full path */
                    285:        int             hi_dewey[MAXDEWEY];     /* The versions */
                    286:        int             hi_ndewey;              /* Number of version numbers */
                    287: #define hi_major hi_dewey[0]
                    288: #define hi_minor hi_dewey[1]
                    289:        int             hi_next;                /* Next in this bucket */
                    290: };
                    291:
                    292: #define _PATH_LD_HINTS         "/var/run/ld.so.hints"
1.1       pk        293:
                    294: #endif /* _LINK_H_ */
                    295:

CVSweb <webmaster@jp.NetBSD.org>