Source code pulled from OpenBSD for OpenNTPD. The place to contribute to this code is via the OpenBSD CVS tree.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

204 lines
7.4 KiB

  1. /* $OpenBSD: link_aout.h,v 1.1 2002/06/07 03:00:01 art Exp $ */
  2. /*
  3. * Copyright (c) 1993 Paul Kranenburg
  4. * All rights reserved.
  5. *
  6. * Redistribution and use in source and binary forms, with or without
  7. * modification, are permitted provided that the following conditions
  8. * are met:
  9. * 1. Redistributions of source code must retain the above copyright
  10. * notice, this list of conditions and the following disclaimer.
  11. * 2. Redistributions in binary form must reproduce the above copyright
  12. * notice, this list of conditions and the following disclaimer in the
  13. * documentation and/or other materials provided with the distribution.
  14. * 3. All advertising materials mentioning features or use of this software
  15. * must display the following acknowledgement:
  16. * This product includes software developed by Paul Kranenburg.
  17. * 4. The name of the author may not be used to endorse or promote products
  18. * derived from this software without specific prior written permission
  19. *
  20. * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
  21. * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
  22. * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
  23. * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
  24. * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
  25. * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
  26. * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
  27. * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
  28. * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
  29. * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  30. */
  31. /*
  32. * RRS section definitions.
  33. *
  34. * The layout of some data structures defined in this header file is
  35. * such that we can provide compatibility with the SunOS 4.x shared
  36. * library scheme.
  37. */
  38. /*
  39. * Symbol description with size. This is simply an `nlist' with
  40. * one field (nz_size) added.
  41. * Used to convey size information on items in the data segment
  42. * of shared objects. An array of these live in the shared object's
  43. * text segment and is addressed by the `sdt_nzlist' field.
  44. */
  45. struct nzlist {
  46. struct nlist nlist;
  47. u_long nz_size;
  48. #define nz_un nlist.n_un
  49. #define nz_strx nlist.n_un.n_strx
  50. #define nz_name nlist.n_un.n_name
  51. #define nz_type nlist.n_type
  52. #define nz_value nlist.n_value
  53. #define nz_desc nlist.n_desc
  54. #define nz_other nlist.n_other
  55. };
  56. #define N_AUX(p) ((p)->n_other & 0xf)
  57. #define N_BIND(p) (((unsigned int)(p)->n_other >> 4) & 0xf)
  58. #define N_OTHER(r, v) (((unsigned int)(r) << 4) | ((v) & 0xf))
  59. #define AUX_OBJECT 1
  60. #define AUX_FUNC 2
  61. /*#define BIND_LOCAL 0 not used */
  62. /*#define BIND_GLOBAL 1 not used */
  63. #define BIND_WEAK 2
  64. /*
  65. * The `section_dispatch_table' structure contains offsets to various data
  66. * structures needed to do run-time relocation.
  67. */
  68. struct section_dispatch_table {
  69. struct so_map *sdt_loaded; /* List of loaded objects */
  70. long sdt_sods; /* List of shared objects descriptors */
  71. long sdt_paths; /* Library search paths */
  72. long sdt_got; /* Global offset table */
  73. long sdt_plt; /* Procedure linkage table */
  74. long sdt_rel; /* Relocation table */
  75. long sdt_hash; /* Symbol hash table */
  76. long sdt_nzlist; /* Symbol table itself */
  77. long sdt_filler2; /* Unused (was: stab_hash) */
  78. long sdt_buckets; /* Number of hash buckets */
  79. long sdt_strings; /* Symbol strings */
  80. long sdt_str_sz; /* Size of symbol strings */
  81. long sdt_text_sz; /* Size of text area */
  82. long sdt_plt_sz; /* Size of procedure linkage table */
  83. };
  84. /*
  85. * RRS symbol hash table, addressed by `sdt_hash' in section_dispatch_table.
  86. * Used to quickly lookup symbols of the shared object by hashing
  87. * on the symbol's name. `rh_symbolnum' is the index of the symbol
  88. * in the shared object's symbol list (`sdt_nzlist'), `rh_next' is
  89. * the next symbol in the hash bucket (in case of collisions).
  90. */
  91. struct rrs_hash {
  92. int rh_symbolnum; /* Symbol number */
  93. int rh_next; /* Next hash entry */
  94. };
  95. /*
  96. * `rt_symbols' is used to keep track of run-time allocated commons
  97. * and data items copied from shared objects.
  98. */
  99. struct rt_symbol {
  100. struct nzlist *rt_sp; /* The symbol */
  101. struct rt_symbol *rt_next; /* Next in linear list */
  102. struct rt_symbol *rt_link; /* Next in bucket */
  103. caddr_t rt_srcaddr; /* Address of "master" copy */
  104. struct so_map *rt_smp; /* Originating map */
  105. };
  106. /*
  107. * Debugger interface structure.
  108. */
  109. struct so_debug {
  110. int dd_version; /* Version # of interface */
  111. int dd_in_debugger; /* Set when run by debugger */
  112. int dd_sym_loaded; /* Run-time linking brought more
  113. symbols into scope */
  114. char *dd_bpt_addr; /* Address of rtld-generated bpt */
  115. int dd_bpt_shadow; /* Original contents of bpt */
  116. struct rt_symbol *dd_cc; /* Allocated commons/copied data */
  117. };
  118. /*
  119. * Entry points into ld.so - user interface to the run-time linker.
  120. */
  121. struct ld_entry {
  122. void *(*dlopen)(const char *, int);
  123. int (*dlclose)(void *);
  124. void *(*dlsym)(void *, const char *);
  125. int (*dlctl)(void *, int, void *);
  126. void (*dlexit)(void);
  127. void (*dlrsrvd[3])(void);
  128. };
  129. /*
  130. * This is the structure pointed at by the __DYNAMIC symbol if an
  131. * executable requires the attention of the run-time link editor.
  132. * __DYNAMIC is given the value zero if no run-time linking needs to
  133. * be done (it is always present in shared objects).
  134. * The union `d_un' provides for different versions of the dynamic
  135. * linking mechanism (switched on by `d_version'). The last version
  136. * used by Sun is 3. We leave some room here and go to version number
  137. * 8 for NetBSD, the main difference lying in the support for the
  138. * `nz_list' type of symbols.
  139. */
  140. struct _dynamic {
  141. int d_version; /* version # of this interface */
  142. struct so_debug *d_debug;
  143. union {
  144. struct section_dispatch_table *d_sdt;
  145. } d_un;
  146. struct ld_entry *d_entry; /* compat - now in crt_ldso */
  147. };
  148. #define LD_VERSION_SUN (3)
  149. #define LD_VERSION_BSD (8)
  150. #define LD_VERSION_NZLIST_P(v) ((v) >= 8)
  151. #define LD_GOT(x) ((x)->d_un.d_sdt->sdt_got)
  152. #define LD_PLT(x) ((x)->d_un.d_sdt->sdt_plt)
  153. #define LD_REL(x) ((x)->d_un.d_sdt->sdt_rel)
  154. #define LD_SYMBOL(x) ((x)->d_un.d_sdt->sdt_nzlist)
  155. #define LD_HASH(x) ((x)->d_un.d_sdt->sdt_hash)
  156. #define LD_STRINGS(x) ((x)->d_un.d_sdt->sdt_strings)
  157. #define LD_NEED(x) ((x)->d_un.d_sdt->sdt_sods)
  158. #define LD_BUCKETS(x) ((x)->d_un.d_sdt->sdt_buckets)
  159. #define LD_PATHS(x) ((x)->d_un.d_sdt->sdt_paths)
  160. #define LD_GOTSZ(x) ((x)->d_un.d_sdt->sdt_plt - (x)->d_un.d_sdt->sdt_got)
  161. #define LD_RELSZ(x) ((x)->d_un.d_sdt->sdt_hash - (x)->d_un.d_sdt->sdt_rel)
  162. #define LD_HASHSZ(x) ((x)->d_un.d_sdt->sdt_nzlist - (x)->d_un.d_sdt->sdt_hash)
  163. #define LD_STABSZ(x) ((x)->d_un.d_sdt->sdt_strings - (x)->d_un.d_sdt->sdt_nzlist)
  164. #define LD_PLTSZ(x) ((x)->d_un.d_sdt->sdt_plt_sz)
  165. #define LD_STRSZ(x) ((x)->d_un.d_sdt->sdt_str_sz)
  166. #define LD_TEXTSZ(x) ((x)->d_un.d_sdt->sdt_text_sz)
  167. /*
  168. * Interface to ld.so
  169. */
  170. struct crt_ldso {
  171. int crt_ba; /* Base address of ld.so */
  172. int crt_dzfd; /* "/dev/zero" file descriptor (SunOS) */
  173. int crt_ldfd; /* ld.so file descriptor */
  174. struct _dynamic *crt_dp; /* Main's __DYNAMIC */
  175. char **crt_ep; /* environment strings */
  176. caddr_t crt_bp; /* Breakpoint if run from debugger */
  177. char *crt_prog; /* Program name (v3) */
  178. char *crt_ldso; /* Link editor name (v4) */
  179. struct ld_entry *crt_ldentry; /* dl*() access (v4) */
  180. };
  181. /*
  182. * Version passed from crt0 to ld.so (1st argument to _rtld()).
  183. */
  184. #define CRT_VERSION_SUN 1
  185. #define CRT_VERSION_BSD_2 2
  186. #define CRT_VERSION_BSD_3 3
  187. #define CRT_VERSION_BSD_4 4