4 * The contents of this file are subject to the terms of the
5 * Common Development and Distribution License (the "License").
6 * You may not use this file except in compliance with the License.
8 * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
9 * or http://www.opensolaris.org/os/licensing.
10 * See the License for the specific language governing permissions
11 * and limitations under the License.
13 * When distributing Covered Code, include this CDDL HEADER in each
14 * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
15 * If applicable, add the following below this CDDL HEADER, with the
16 * fields enclosed by brackets "[]" replaced with your own identifying
17 * information: Portions Copyright [yyyy] [name of copyright owner]
23 * Copyright (c) 1990, 2010, Oracle and/or its affiliates. All rights reserved.
25 #ifndef _A_DOT_OUT_DOT_H
26 #define _A_DOT_OUT_DOT_H
28 #include <sys/types.h>
38 #define max(a, b) ((a) < (b) ? (b) : (a))
40 typedef struct link_dynamic Link_dynamic
;
43 * Extern functions for a.out format file class.
45 extern ulong_t
aout_bndr(caddr_t
);
46 extern int aout_get_mmap(Lm_list
*, mmapobj_result_t
*);
47 extern int aout_lookup_sym(Slookup
*, Sresult
*, uint_t
*, int *);
48 extern Rt_map
*aout_new_lmp(Lm_list
*, Aliste
, Fdesc
*, Addr
, size_t, void *,
50 extern void aout_plt_write(caddr_t
, ulong_t
);
51 extern int aout_reloc(Rt_map
*, uint_t
, int *, APlist
**);
52 extern void aout_rtbndr(caddr_t
);
53 extern Fct
*aout_verify(caddr_t
, size_t, Fdesc
*, const char *,
57 * Private data for an a.out format file class.
59 typedef struct _rt_aout_private
{
60 struct link_dynamic
*lm_ld
; /* 4.x aout dynamic pointer */
61 struct ld_private
*lm_lpd
; /* private aout object area */
65 * Special defines for a.out format file class.
67 #define N_UNDF 0x0 /* undefined */
68 #define N_ABS 0x2 /* absolute */
69 #define N_COMM 0x12 /* common (internal to ld) */
70 #define N_EXT 01 /* external bit, or'ed in */
73 * Format of a symbol table entry.
77 char *n_name
; /* for use when in-core */
78 long n_strx
; /* index into file string table */
80 uchar_t n_type
; /* type flag (N_TEXT,..) */
81 char n_other
; /* unused */
82 short n_desc
; /* see <stab.h> */
83 ulong_t n_value
; /* value of symbol (or sdb offset) */
87 * Link editor public definitions.
94 * Structure describing logical name and requirements on an object
95 * which is to be loaded dynamically.
97 struct old_link_object
{
98 char *lo_name
; /* name of object */
99 int lo_library
: 1, /* searched for by library rules */
101 short lo_major
; /* major version number */
102 short lo_minor
; /* minor version number */
106 long lo_name
; /* name (often relative) */
107 int lo_library
: 1, /* searched for by library rules */
109 short lo_major
; /* major version number */
110 short lo_minor
; /* minor version number */
111 long lo_next
; /* next one (often relative) */
113 typedef struct link_object Lnk_obj
;
116 * Structure describing name and placement of dynamically loaded
117 * objects in a process' address space.
119 typedef struct a_link_map A_link_map
;
122 caddr_t lm_addr
; /* address at which object mapped */
123 char *lm_name
; /* full name of loaded object */
124 struct a_link_map
*lm_next
; /* next object in map */
125 struct link_object
*lm_lop
; /* link object that got us here */
126 caddr_t lm_lob
; /* base address for said link object */
127 int lm_rwt
: 1; /* text is read/write */
128 struct link_dynamic
*lm_ld
; /* dynamic structure */
129 caddr_t lm_lpd
; /* loader private data */
133 * Version 1 of dynamic linking information. With the exception of
134 * ld_loaded (determined at execution time) and ld_stab_hash (a special
135 * case of relocation handled at execution time), the values in this
136 * structure reflect offsets from the containing link_dynamic structure.
138 struct link_dynamic_1
{
139 struct a_link_map
*ld_loaded
; /* list of loaded objects */
140 long ld_need
; /* list of needed objects */
141 long ld_rules
; /* search rules for library objects */
142 long ld_got
; /* global offset table */
143 long ld_plt
; /* procedure linkage table */
144 long ld_rel
; /* relocation table */
145 long ld_hash
; /* symbol hash table */
146 long ld_stab
; /* symbol table itself */
147 long (*ld_stab_hash
)(); /* "pointer" to symbol hash function */
148 long ld_buckets
; /* number of hash buckets */
149 long ld_symbols
; /* symbol strings */
150 long ld_symb_size
; /* size of symbol strings */
151 long ld_text
; /* size of text area */
154 struct link_dynamic_2
{
155 struct a_link_map
*ld_loaded
; /* list of loaded objects */
156 long ld_need
; /* list of needed objects */
157 long ld_rules
; /* search rules for library objects */
158 long ld_got
; /* global offset table */
159 long ld_plt
; /* procedure linkage table */
160 long ld_rel
; /* relocation table */
161 long ld_hash
; /* symbol hash table */
162 long ld_stab
; /* symbol table itself */
163 long (*ld_stab_hash
)(); /* "pointer" to symbol hash function */
164 long ld_buckets
; /* number of hash buckets */
165 long ld_symbols
; /* symbol strings */
166 long ld_symb_size
; /* size of symbol strings */
167 long ld_text
; /* size of text area */
168 long ld_plt_sz
; /* size of procedure linkage table */
172 * Structure pointing to run time allocated common symbols and
176 struct nlist
*rtc_sp
; /* symbol for common */
177 struct rtc_symb
*rtc_next
; /* next common */
181 * Debugger interface structure.
184 int ldd_version
; /* version # of interface */
185 int ldd_in_debugger
; /* a debugger is running us */
186 int ldd_sym_loaded
; /* we loaded some symbols */
187 char *ldd_bp_addr
; /* place for ld-generated bpt */
188 int ldd_bp_inst
; /* instruction which was there */
189 struct rtc_symb
*ldd_cp
; /* commons we built */
193 * Structure associated with each object which may be or which requires
194 * execution-time link editing. Used by the run-time linkage editor to
195 * identify needed objects and symbol definitions and references.
197 struct old_link_dynamic
{
198 int ld_version
; /* version # of this structure */
200 struct link_dynamic_1 ld_1
;
207 struct rtc_symb
*cp
; /* pointer to an array of runtime */
208 /* allocated common symbols. */
211 struct link_dynamic
{
212 int ld_version
; /* version # of this structure */
213 struct ld_debug
*ldd
;
215 struct link_dynamic_1
*ld_1
;
216 struct link_dynamic_2
*ld_2
;
222 * Get size of relocations.
224 #define GETGOTSZ(x) (x->ld_version < 2 ? \
225 ((struct old_link_dynamic *)x)->v1.ld_plt - \
226 ((struct old_link_dynamic *)x)->v1.ld_got : \
227 (x)->v2->ld_plt - (x)->v2->ld_got)
229 #define GETPLTSZ(x) (x->ld_version < 2 ? \
230 ((struct old_link_dynamic *)x)->v1.ld_rel - \
231 ((struct old_link_dynamic *)x)->v1.ld_plt : \
232 (x)->v2->ld_rel - (x)->v2->ld_plt)
234 #define GETRELSZ(x) (x->ld_version < 2 ? \
235 ((struct old_link_dynamic *)x)->v1.ld_hash - \
236 ((struct old_link_dynamic *)x)->v1.ld_rel : \
237 (x)->v2->ld_hash - (x)->v2->ld_rel)
239 #define GETHASHSZ(x) (x->ld_version < 2 ? \
240 ((struct old_link_dynamic *)x)->v1.ld_stab - \
241 ((struct old_link_dynamic *)x)->v1.ld_hash : \
242 (x)->v2->ld_stab - (x)->v2->ld_hash)
244 #define GETSTABSZ(x) (x->ld_version < 2 ? \
245 ((struct old_link_dynamic *)x)->v1.ld_symbols -\
246 ((struct old_link_dynamic *)x)->v1.ld_stab : \
247 (x)->v2->ld_symbols - (x)->v2->ld_stab)
252 #endif /* !_link_h */
254 #define MAIN_BASE 0x2000 /* base address of a.out in 4.x system */
257 * Macros for getting to linker a.out format private data.
259 #define AOUTPRV(X) ((X)->rt_priv)
260 #define AOUTDYN(X) (((Rt_aoutp *)(X)->rt_priv)->lm_ld)
261 #define LM2LP(X) ((struct ld_private *)((Rt_aoutp *) \
262 (X)->rt_priv)->lm_lpd)
263 #define TEXTBASE(X) (LM2LP(X)->lp_textbase)
266 * Most of the above macros are used from AOUT specific routines, however there
267 * are a couple of instances where we need to ensure the file being processed
268 * is AOUT before dereferencing the macro.
270 #define THIS_IS_AOUT(X) (FCT(X) == &aout_fct)
273 * Code collapsing macros.
275 #define v2 ld_un.ld_2
276 #define v1 ld_un.ld_1
277 #define JMPOFF(x) (x)->v2->ld_plt
278 #define RELOCOFF(x) (x)->v2->ld_rel
279 #define HASHOFF(x) (x)->v2->ld_hash
280 #define SYMOFF(x) (x)->v2->ld_stab
281 #define STROFF(x) (x)->v2->ld_symbols
284 int jb_inst
[3]; /* need 4 instructions for jump slot */
288 int fssymbno
; /* ordinal symbol number */
289 int next
; /* index to the hash array pointed by fs_hash */
293 * Sparc relocation types.
297 RELOC_8
, RELOC_16
, RELOC_32
, /* simplest relocs */
298 RELOC_DISP8
, RELOC_DISP16
, RELOC_DISP32
, /* Disp's (pc-rel) */
299 RELOC_WDISP30
, RELOC_WDISP22
, /* SR word disp's */
300 RELOC_HI22
, RELOC_22
, /* SR 22-bit relocs */
301 RELOC_13
, RELOC_LO10
, /* SR 13&10-bit reloc */
302 RELOC_SFA_BASE
, RELOC_SFA_OFF13
, /* SR S.F.A. relocs */
303 RELOC_BASE10
, RELOC_BASE13
, RELOC_BASE22
, /* base_relative pic */
304 RELOC_PC10
, RELOC_PC22
, /* special pc-rel pic */
305 RELOC_JMP_TBL
, /* jmp_tbl_rel in pic */
306 RELOC_SEGOFF16
, /* Shlib off-in-seg */
307 RELOC_GLOB_DAT
, RELOC_JMP_SLOT
, RELOC_RELATIVE
/* rtld relocs */
311 * Format of a relocation datum.
313 #define r_symbolnum r_index
315 struct relocation_info
/* used when header.a_machtype == M_SPARC */
317 ulong_t r_address
; /* relocation addr (offset in seg) */
318 uint_t r_index
:24; /* segment index or symbol index */
319 uint_t r_extern
: 1; /* if F, r_index==SEG#; if T, SYM idx */
320 int : 2; /* <unused> */
321 enum reloc_type r_type
: 5; /* type of relocation to perform */
322 long r_addend
; /* addend for relocation value */
326 struct jbind
*lp_plt
; /* procedure linkage table */
327 struct relocation_info
*lp_rp
; /* relocation table */
328 struct fshash
*lp_hash
; /* hash table */
329 struct nlist
*lp_symtab
; /* symbol table */
330 char *lp_symstr
; /* symbol strings */
331 caddr_t lp_textbase
; /* base address for text addressing */
332 struct nlist
*(*lp_interp
)(); /* link map interpreter */
333 long lp_refcnt
; /* reference count of link map */
334 struct dl_object
*lp_dlp
; /* pointer to a dlopen object */
335 caddr_t lp_symbol_base
; /* base address for symbols */
340 * Offsets of various sections of an object file.
342 #define PAGSIZ 0x02000
343 #define SEGSIZ PAGSIZ
345 #define N_TXTOFF(x) \
347 ((x).a_magic == ZMAGIC ? 0 : sizeof (struct exec))
349 #define N_SYMOFF(x) \
351 (N_TXTOFF(x) + (x).a_text + (x).a_data + (x).a_trsize + (x).a_drsize)
354 /* round to segment size */ \
355 (M_SROUND((x).a_text) + (x).a_data + (x).a_bss)
361 #endif /* _A_DOT_OUT_DOT_H */