]> Git Repo - binutils.git/blob - gas/a.out.gnu.h
*** empty log message ***
[binutils.git] / gas / a.out.gnu.h
1 #ifndef __A_OUT_GNU_H__
2 #define __A_OUT_GNU_H__
3
4 #include "target.h"             /* Figure out which target and host systems */
5
6 #define __GNU_EXEC_MACROS__
7
8 #ifndef __STRUCT_EXEC_OVERRIDE__
9
10 struct exec
11 {
12   unsigned long a_info;         /* Use macros N_MAGIC, etc for access */
13   unsigned a_text;              /* length of text, in bytes */
14   unsigned a_data;              /* length of data, in bytes */
15   unsigned a_bss;               /* length of uninitialized data area for file, in bytes */
16   unsigned a_syms;              /* length of symbol table data in file, in bytes */
17   unsigned a_entry;             /* start address */
18   unsigned a_trsize;            /* length of relocation info for text, in bytes */
19   unsigned a_drsize;            /* length of relocation info for data, in bytes */
20 };
21
22 #endif /* __STRUCT_EXEC_OVERRIDE__ */
23
24 /* these go in the N_MACHTYPE field */
25 /* These symbols could be defined by code from Suns...punt 'em */
26 #undef M_OLDSUN2
27 #undef M_68010
28 #undef M_68020
29 #undef M_SPARC
30 enum machine_type {
31   M_OLDSUN2 = 0,
32   M_68010 = 1,
33   M_68020 = 2,
34   M_SPARC = 3,
35   /* skip a bunch so we don't run into any of sun's numbers */
36   M_386 = 100,
37   M_29K = 101,
38 };
39
40 #define N_MAGIC(exec) ((exec).a_info & 0xffff)
41 #define N_MACHTYPE(exec) ((enum machine_type)(((exec).a_info >> 16) & 0xff))
42 #define N_FLAGS(exec) (((exec).a_info >> 24) & 0xff)
43 #define N_SET_INFO(exec, magic, type, flags) \
44         ((exec).a_info = ((magic) & 0xffff) \
45          | (((int)(type) & 0xff) << 16) \
46          | (((flags) & 0xff) << 24))
47 #define N_SET_MAGIC(exec, magic) \
48         ((exec).a_info = (((exec).a_info & 0xffff0000) | ((magic) & 0xffff)))
49
50 #define N_SET_MACHTYPE(exec, machtype) \
51         ((exec).a_info = \
52          ((exec).a_info&0xff00ffff) | ((((int)(machtype))&0xff) << 16))
53
54 #define N_SET_FLAGS(exec, flags) \
55         ((exec).a_info = \
56          ((exec).a_info&0x00ffffff) | (((flags) & 0xff) << 24))
57
58 /* Code indicating object file or impure executable.  */
59 #define OMAGIC 0407
60 /* Code indicating pure executable.  */
61 #define NMAGIC 0410
62 /* Code indicating demand-paged executable.  */
63 #define ZMAGIC 0413
64
65 #define N_BADMAG(x)                                     \
66  (N_MAGIC(x) != OMAGIC && N_MAGIC(x) != NMAGIC          \
67   && N_MAGIC(x) != ZMAGIC)
68
69 #define _N_BADMAG(x)                                    \
70  (N_MAGIC(x) != OMAGIC && N_MAGIC(x) != NMAGIC          \
71   && N_MAGIC(x) != ZMAGIC)
72
73 #define _N_HDROFF(x) (1024 - sizeof (struct exec))
74
75 #define N_TXTOFF(x) \
76  (N_MAGIC(x) == ZMAGIC ? _N_HDROFF((x)) + sizeof (struct exec) : sizeof (struct exec))
77
78 #define N_DATOFF(x) (N_TXTOFF(x) + (x).a_text)
79
80 #define N_TRELOFF(x) (N_DATOFF(x) + (x).a_data)
81
82 #define N_DRELOFF(x) (N_TRELOFF(x) + (x).a_trsize)
83
84 #define N_SYMOFF(x) (N_DRELOFF(x) + (x).a_drsize)
85
86 #define N_STROFF(x) (N_SYMOFF(x) + (x).a_syms)
87
88 /* Address of text segment in memory after it is loaded.  */
89 /* Don't load things at zero, it encourages zero-pointer bugs */
90 #ifndef TEXT_START_ADDR
91 #define TEXT_START_ADDR 0x10000
92 #endif
93 #define N_TXTADDR(x) TEXT_START_ADDR
94
95 /* Address of data segment in memory after it is loaded.
96    Note that it is up to you to define SEGMENT_SIZE
97    on machines not listed here.  */
98 #ifndef SEGMENT_SIZE
99 #if defined(vax) || defined(hp300) || defined(pyr)
100 #define SEGMENT_SIZE page_size
101 #endif
102 #ifdef  sony
103 #define SEGMENT_SIZE    0x2000
104 #endif  /* Sony.  */
105 #ifdef is68k
106 #define SEGMENT_SIZE 0x20000
107 #endif
108 #if defined(m68k) && defined(PORTAR)
109 #define PAGE_SIZE 0x400
110 #define SEGMENT_SIZE PAGE_SIZE
111 #endif
112 #endif
113
114 #define _N_SEGMENT_ROUND(x) (((x) + SEGMENT_SIZE - 1) & ~(SEGMENT_SIZE - 1))
115
116 #define _N_TXTENDADDR(x) (N_TXTADDR(x)+(x).a_text)
117
118 #ifndef N_DATADDR
119 #define N_DATADDR(x) \
120     (N_MAGIC(x)==OMAGIC? (_N_TXTENDADDR(x)) \
121      : (_N_SEGMENT_ROUND (_N_TXTENDADDR(x))))
122 #endif
123
124 /* Address of bss segment in memory after it is loaded.  */
125 #define N_BSSADDR(x) (N_DATADDR(x) + (x).a_data)
126 \f
127 struct nlist {
128   union {
129     char *n_name;
130     struct nlist *n_next;
131     long n_strx;
132   } n_un;
133   unsigned char n_type;
134   char n_other;
135   short n_desc;
136   unsigned long n_value;
137 };
138
139 #define N_UNDF 0
140 #define N_ABS 2
141 #define N_TEXT 4
142 #define N_DATA 6
143 #define N_BSS 8
144 #define N_FN 15
145
146 #define N_EXT 1
147 #define N_TYPE 036
148 #define N_STAB 0340
149
150 /* The following type indicates the definition of a symbol as being
151    an indirect reference to another symbol.  The other symbol
152    appears as an undefined reference, immediately following this symbol.
153
154    Indirection is asymmetrical.  The other symbol's value will be used
155    to satisfy requests for the indirect symbol, but not vice versa.
156    If the other symbol does not have a definition, libraries will
157    be searched to find a definition.  */
158 #define N_INDR 0xa
159
160 /* The following symbols refer to set elements.
161    All the N_SET[ATDB] symbols with the same name form one set.
162    Space is allocated for the set in the text section, and each set
163    element's value is stored into one word of the space.
164    The first word of the space is the length of the set (number of elements).
165
166    The address of the set is made into an N_SETV symbol
167    whose name is the same as the name of the set.
168    This symbol acts like a N_DATA global symbol
169    in that it can satisfy undefined external references.  */
170
171 /* These appear as input to LD, in a .o file.  */
172 #define N_SETA  0x14            /* Absolute set element symbol */
173 #define N_SETT  0x16            /* Text set element symbol */
174 #define N_SETD  0x18            /* Data set element symbol */
175 #define N_SETB  0x1A            /* Bss set element symbol */
176
177 /* This is output from LD.  */
178 #define N_SETV  0x1C            /* Pointer to set vector in data area.  */
179 \f
180 /* This structure describes a single relocation to be performed.
181    The text-relocation section of the file is a vector of these structures,
182    all of which apply to the text section.
183    Likewise, the data-relocation section applies to the data section.  */
184
185 #if TARGET == TARGET_SPARC || TARGET == TARGET_AM29K
186 /*
187  * The following enum and struct were borrowed from
188  * sunOS  /usr/include/sun4/a.out.h  and extended to handle
189  * other machines.
190  */
191
192 enum reloc_type
193 {
194     RELOC_8,        RELOC_16,        RELOC_32,       RELOC_DISP8,
195     RELOC_DISP16,   RELOC_DISP32,    RELOC_WDISP30,  RELOC_WDISP22,
196     RELOC_HI22,     RELOC_22,        RELOC_13,       RELOC_LO10,
197     RELOC_SFA_BASE, RELOC_SFA_OFF13, RELOC_BASE10,   RELOC_BASE13,
198     RELOC_BASE22,   RELOC_PC10,      RELOC_PC22,     RELOC_JMP_TBL,
199     RELOC_SEGOFF16, RELOC_GLOB_DAT,  RELOC_JMP_SLOT, RELOC_RELATIVE,
200
201 /* 29K relocation types */
202     RELOC_JUMPTARG, RELOC_CONST,     RELOC_CONSTH,
203
204     NO_RELOC
205 };
206
207 #define RELOC_TYPE_NAMES \
208 "8",            "16",           "32",           "DISP8",        \
209 "DISP16",       "DISP32",       "WDISP30",      "WDISP22",      \
210 "HI22",         "22",           "13",           "LO10",         \
211 "SFA_BASE",     "SFAOFF13",     "BASE10",       "BASE13",       \
212 "BASE22",       "PC10",         "PC22",         "JMP_TBL",      \
213 "SEGOFF16",     "GLOB_DAT",     "JMP_SLOT",     "RELATIVE",     \
214 "JUMPTARG",     "CONST",        "CONSTH",                       \
215 "NO_RELOC",                                                     \
216 "XXX_28", "XXX_29", "XXX_30", "XXX_31"
217
218 struct reloc_info_extended
219 {
220   unsigned long r_address;
221   unsigned int  r_index:24;
222 # define        r_symbolnum  r_index
223   unsigned      r_extern:1;
224   unsigned      :2;
225   enum reloc_type r_type:5;
226   long int      r_addend;
227 };
228
229 /* Let programs know what they're dealing with */
230 #define RELOC_EXTENDED                  1
231
232 #undef relocation_info
233 #define relocation_info                 reloc_info_extended
234 #define RELOC_ADDRESS(r)                ((r)->r_address)
235 #define RELOC_EXTERN_P(r)               ((r)->r_extern)
236 #define RELOC_TYPE(r)                   ((r)->r_index)
237 #define RELOC_EXTENDED_TYPE(r)          ((r)->r_type)
238 #define RELOC_SYMBOL(r)                 ((r)->r_index)
239 #define RELOC_MEMORY_SUB_P(r)           0
240 #define RELOC_MEMORY_ADD_P(r)           0
241 #define RELOC_ADD_EXTRA(r)              ((r)->r_addend)
242 #define RELOC_PCREL_P(r)             \
243         (  ((r)->r_type >= RELOC_DISP8 && (r)->r_type <= RELOC_WDISP22) \
244          || (r)->r_type == RELOC_JUMPTARG )
245 #define RELOC_VALUE_RIGHTSHIFT(r)       (reloc_target_rightshift[(r)->r_type])
246 #define RELOC_TARGET_SIZE(r)            (reloc_target_size[(r)->r_type])
247 #define RELOC_TARGET_BITPOS(r)          0
248 #define RELOC_TARGET_BITSIZE(r)         (reloc_target_bitsize[(r)->r_type])
249
250 /* Note that these are very dependent on the order of the enums in
251    enum reloc_type (in a.out.h); if they change the following must be
252    changed */
253 /* Also note that some of these may be incorrect; I have no information */
254 #ifndef __STDC__
255 #define const   /**/
256 #endif
257 static const int reloc_target_rightshift[] = {
258   0, 0, 0, 0,
259   0, 0, 2, 2,
260  10, 0, 0, 0,
261   0, 0, 0, 0,
262   0, 0, 0, 0,
263   0, 0, 0, 0,
264   2, 0,16,      /* 29K jumptarg, const, consth */
265   0,
266 };
267 #define RELOC_SIZE_SPLIT16      13
268 static const int reloc_target_size[] = {
269   0, 1, 2, 0,
270   1, 2, 2, 2,
271   2, 2, 2, 2,
272   2, 2, 2, 2,
273   2, 2, 2, 2,
274   2, 2, 2, 2,
275   RELOC_SIZE_SPLIT16, RELOC_SIZE_SPLIT16, RELOC_SIZE_SPLIT16,
276   0,
277 };
278 static const int reloc_target_bitsize[] = {
279   8, 16, 32, 8,
280  16, 32, 30, 22,
281  22, 22, 13, 10,
282  32, 32, 16,  0,
283   0,  0,  0,  0,        /* dunno */
284   0,  0,  0,  0,
285  16, 16, 16,            /* 29K jumptarg, const, consth */
286   0,
287 };
288
289 #define MAX_ALIGNMENT   (sizeof (double))
290
291 #else  /* Not SPARC or AM29K */
292
293 struct relocation_info
294 {
295   /* Address (within segment) to be relocated.  */
296   int r_address;
297   /* The meaning of r_symbolnum depends on r_extern.  */
298   unsigned int r_symbolnum:24;
299   /* Nonzero means value is a pc-relative offset
300      and it should be relocated for changes in its own address
301      as well as for changes in the symbol or section specified.  */
302   unsigned int r_pcrel:1;
303   /* Length (as exponent of 2) of the field to be relocated.
304      Thus, a value of 2 indicates 1<<2 bytes.  */
305   unsigned int r_length:2;
306   /* 1 => relocate with value of symbol.
307           r_symbolnum is the index of the symbol
308           in file's the symbol table.
309      0 => relocate with the address of a segment.
310           r_symbolnum is N_TEXT, N_DATA, N_BSS or N_ABS
311           (the N_EXT bit may be set also, but signifies nothing).  */
312   unsigned int r_extern:1;
313   /* Four bits that aren't used, but when writing an object file
314      it is desirable to clear them.  */
315   unsigned int r_pad:4;
316 };
317 #endif
318
319 /*
320  * Ok.  Following are the relocation information macros.  If your
321  * system should not be able to use the default set (below), you must
322  * define the following:
323
324  *   relocation_info: This must be typedef'd (or #define'd) to the type
325  * of structure that is stored in the relocation info section of your
326  * a.out files.  Often this is defined in the a.out.h for your system.
327  *
328  *   RELOC_ADDRESS (rval): Offset into the current section of the
329  * <whatever> to be relocated.  *Must be an lvalue*.
330  *
331  *   RELOC_EXTERN_P (rval):  Is this relocation entry based on an
332  * external symbol (1), or was it fully resolved upon entering the
333  * loader (0) in which case some combination of the value in memory
334  * (if RELOC_MEMORY_ADD_P) and the extra (if RELOC_ADD_EXTRA) contains
335  * what the value of the relocation actually was.  *Must be an lvalue*.
336  *
337  *   RELOC_TYPE (rval): If this entry was fully resolved upon
338  * entering the loader, what type should it be relocated as?
339  *
340  *   RELOC_EXTENDED_TYPE (rval): If this entry is for a machine using
341  * extended relocatino, what type of field is it?  (For example, on RISC
342  * machines, odd-sized displacements or split displacements occur.)
343  *
344  *   RELOC_SYMBOL (rval): If this entry was not fully resolved upon
345  * entering the loader, what is the index of it's symbol in the symbol
346  * table?  *Must be a lvalue*.
347  *
348  *   RELOC_MEMORY_ADD_P (rval): This should return true if the final
349  * relocation value output here should be added to memory, or if the
350  * section of memory described should simply be set to the relocation
351  * value.
352  *
353  *   RELOC_ADD_EXTRA (rval): (Optional) This macro, if defined, gives
354  * an extra value to be added to the relocation value based on the
355  * individual relocation entry.  *Must be an lvalue if defined*.
356  *
357  *   RELOC_PCREL_P (rval): True if the relocation value described is
358  * pc relative.
359  *
360  *   RELOC_VALUE_RIGHTSHIFT (rval): Number of bits right to shift the
361  * final relocation value before putting it where it belongs.
362  *
363  *   RELOC_TARGET_SIZE (rval): log to the base 2 of the number of
364  * bytes of size this relocation entry describes; 1 byte == 0; 2 bytes
365  * == 1; 4 bytes == 2, and etc.  This is somewhat redundant (we could
366  * do everything in terms of the bit operators below), but having this
367  * macro could end up producing better code on machines without fancy
368  * bit twiddling.  Also, it's easier to understand/code big/little
369  * endian distinctions with this macro.
370  *
371  *   RELOC_TARGET_BITPOS (rval): The starting bit position within the
372  * object described in RELOC_TARGET_SIZE in which the relocation value
373  * will go.
374  *
375  *   RELOC_TARGET_BITSIZE (rval): How many bits are to be replaced
376  * with the bits of the relocation value.  It may be assumed by the
377  * code that the relocation value will fit into this many bits.  This
378  * may be larger than RELOC_TARGET_SIZE if such be useful.
379  *
380  *
381  *              Things I haven't implemented
382  *              ----------------------------
383  *
384  *    Values for RELOC_TARGET_SIZE other than 0, 1, or 2.
385  *
386  *    Pc relative relocation for External references.
387  */
388 #if TARGET == TARGET_SEQUENT
389 #define RELOC_ADDRESS(r)                ((r)->r_address)
390 #define RELOC_EXTERN_P(r)               ((r)->r_extern)
391 #define RELOC_TYPE(r)           ((r)->r_symbolnum)
392 #define RELOC_SYMBOL(r)         ((r)->r_symbolnum)
393 #define RELOC_MEMORY_SUB_P(r)   ((r)->r_bsr)
394 #define RELOC_MEMORY_ADD_P(r)   1
395 #undef RELOC_ADD_EXTRA
396 #define RELOC_PCREL_P(r)                ((r)->r_pcrel || (r)->r_bsr)
397 #define RELOC_VALUE_RIGHTSHIFT(r)       0
398 #define RELOC_TARGET_SIZE(r)            ((r)->r_length)
399 #define RELOC_TARGET_BITPOS(r)  0
400 #define RELOC_TARGET_BITSIZE(r) 32
401 #endif
402
403 /* Default macros */
404 #ifndef RELOC_ADDRESS
405 #define RELOC_ADDRESS(r)                ((r)->r_address)
406 #define RELOC_EXTERN_P(r)               ((r)->r_extern)
407 #define RELOC_TYPE(r)                   ((r)->r_symbolnum)
408 #define RELOC_SYMBOL(r)                 ((r)->r_symbolnum)
409 #define RELOC_MEMORY_SUB_P(r)           0
410 #define RELOC_MEMORY_ADD_P(r)           1
411 #undef RELOC_ADD_EXTRA
412 #define RELOC_PCREL_P(r)                ((r)->r_pcrel)
413 #define RELOC_VALUE_RIGHTSHIFT(r)       0
414 #define RELOC_TARGET_SIZE(r)            ((r)->r_length)
415 #define RELOC_TARGET_BITPOS(r)          0
416 #define RELOC_TARGET_BITSIZE(r)         32
417 #endif
418
419 /* Maximum alignment required of a common'd variable.  If a var of this
420    size or larger is allocated in BSS when nobody defines it, it gets
421    this alignment.  */
422
423 #ifndef MAX_ALIGNMENT
424 #define MAX_ALIGNMENT   (sizeof (int))
425 #endif
426
427
428 /* Definitions for routines that read and write GNU a.out files */
429
430 enum objfile_kind {
431         OBJFILE_ERROR,
432         OBJFILE_UNKNOWN,
433         OBJFILE_SINGLE,
434         OBJFILE_ARCHIVE,
435 };
436
437 enum objfile_kind read_aout_header();   /* (desc, &header)  read&swap header */
438
439 /* Read an a.out header from DESC and call rel_fn(DESC, header)
440    if it is an object file, lib_fn(DESC) if it is a library, else
441    call err_fn("msg") */
442 void handle_aout_header();              /* (desc, rel_fn, lib_fn, err_fn) */
443
444 /* Byte-swapping definitions */
445
446 void swap_aoutheader();         /* BSD a.out header */
447 short swap_getshort ();
448 void swap_putshort();
449 long swap_getlong ();
450 void swap_putlong();
451 void swap_reloc_info_in();      /* BSD relocation information */
452 void swap_reloc_info_out();     /* BSD relocation information */
453 void swap_nlists();             /* BSD symbol name lists */
454 void swap_root_updates();       /* GDB Symseg */
455
456 /* Bring on the encapsulation, if configured in! */
457 #ifdef COFF_ENCAPSULATE
458 #include "a.out.encap.h"
459 #endif
460
461 #endif /* __A_OUT_GNU_H__ */
This page took 0.050259 seconds and 4 git commands to generate.