1 /* a.out object file format
2 Copyright (C) 1989, 1990, 1991 Free Software Foundation, Inc.
4 This file is part of GAS, the GNU Assembler.
6 GAS is free software; you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as
8 published by the Free Software Foundation; either version 1,
9 or (at your option) any later version.
11 GAS is distributed in the hope that it will be useful, but
12 WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See
14 the GNU General Public License for more details.
16 You should have received a copy of the GNU General Public
17 License along with GAS; see the file COPYING. If not, write
18 to the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA. */
22 /* Tag to validate a.out object file format processing */
28 #include "a.out.gnu.h" /* Needed to define struct nlist. Sigh. */
33 struct reloc_info_generic
35 unsigned long r_address;
37 * Using bit fields here is a bad idea because the order is not portable. :-(
40 #define r_symbolnum r_index
41 unsigned r_extern : 1;
43 unsigned r_length:2; /* 0=>byte 1=>short 2=>long 3=>8byte */
44 unsigned r_bsr:1; /* NS32K */
45 unsigned r_disp:1; /* NS32k */
46 unsigned r_callj:1; /* i960 */
47 enum reloc_type r_type;
51 extern const short seg_N_TYPE[];
52 extern const segT N_TYPE_seg[];
54 #ifndef DEFAULT_MAGIC_NUMBER_FOR_OBJECT_FILE
55 #define DEFAULT_MAGIC_NUMBER_FOR_OBJECT_FILE (OMAGIC)
56 #endif /* DEFAULT_MAGIC_NUMBER_FOR_OBJECT_FILE */
59 /* Symbol table entry data type */
61 typedef struct nlist obj_symbol_type; /* Symbol table entry */
63 /* If compiler generate leading underscores, remove them. */
65 #ifndef STRIP_UNDERSCORE
66 #define STRIP_UNDERSCORE 0
67 #endif /* STRIP_UNDERSCORE */
69 /* Symbol table macros and constants */
72 * Macros to extract information from a symbol table entry.
73 * This syntaxic indirection allows independence regarding a.out or coff.
74 * The argument (s) of all these macros is a pointer to a symbol table entry.
77 /* True if the symbol is external */
78 #define S_IS_EXTERNAL(s) ((s)->sy_symbol.n_type & N_EXT)
80 /* True if symbol has been defined, ie is in N_{TEXT,DATA,BSS,ABS} or N_EXT */
81 #define S_IS_DEFINED(s) ((S_GET_TYPE(s) != N_UNDF) || (S_GET_OTHER(s) != 0) || (S_GET_DESC(s) != 0))
83 #define S_IS_REGISTER(s) ((s)->sy_symbol.n_type == N_REGISTER)
85 /* True if a debug special symbol entry */
86 #define S_IS_DEBUG(s) ((s)->sy_symbol.n_type & N_STAB)
87 /* True if a symbol is local symbol name */
88 /* A symbol name whose name begin with ^A is a gas internal pseudo symbol
89 nameless symbols come from .stab directives. */
90 #define S_IS_LOCAL(s) (S_GET_NAME(s) && \
92 (S_GET_NAME(s)[0] == '\001' || \
93 (S_LOCAL_NAME(s) && !flagseen['L'])))
94 /* True if a symbol is not defined in this file */
95 #define S_IS_EXTERN(s) ((s)->sy_symbol.n_type & N_EXT)
96 /* True if the symbol has been generated because of a .stabd directive */
97 #define S_IS_STABD(s) (S_GET_NAME(s) == (char *)0)
100 /* The value of the symbol */
101 #define S_GET_VALUE(s) (((s)->sy_symbol.n_value))
102 /* The name of the symbol */
103 #define S_GET_NAME(s) ((s)->sy_symbol.n_un.n_name)
104 /* The pointer to the string table */
105 #define S_GET_OFFSET(s) ((s)->sy_symbol.n_un.n_strx)
106 /* The type of the symbol */
107 #define S_GET_TYPE(s) ((s)->sy_symbol.n_type & N_TYPE)
108 /* The numeric value of the segment */
109 #define S_GET_SEGMENT(s) (N_TYPE_seg[S_GET_TYPE(s)])
110 /* The n_other expression value */
111 #define S_GET_OTHER(s) ((s)->sy_symbol.n_other)
112 /* The n_desc expression value */
113 #define S_GET_DESC(s) ((s)->sy_symbol.n_desc)
116 /* Set the value of the symbol */
117 #define S_SET_VALUE(s,v) ((s)->sy_symbol.n_value = (unsigned long) (v))
118 /* Assume that a symbol cannot be simultaneously in more than on segment */
120 #define S_SET_SEGMENT(s,seg) ((s)->sy_symbol.n_type &= ~N_TYPE,(s)->sy_symbol.n_type|=SEGMENT_TO_SYMBOL_TYPE(seg))
121 /* The symbol is external */
122 #define S_SET_EXTERNAL(s) ((s)->sy_symbol.n_type |= N_EXT)
123 /* The symbol is not external */
124 #define S_CLEAR_EXTERNAL(s) ((s)->sy_symbol.n_type &= ~N_EXT)
125 /* Set the name of the symbol */
126 #define S_SET_NAME(s,v) ((s)->sy_symbol.n_un.n_name = (v))
127 /* Set the offset in the string table */
128 #define S_SET_OFFSET(s,v) ((s)->sy_symbol.n_un.n_strx = (v))
129 /* Set the n_other expression value */
130 #define S_SET_OTHER(s,v) ((s)->sy_symbol.n_other = (v))
131 /* Set the n_desc expression value */
132 #define S_SET_DESC(s,v) ((s)->sy_symbol.n_desc = (v))
134 /* File header macro and type definition */
136 #define H_GET_FILE_SIZE(h) (sizeof(struct exec) + \
137 H_GET_TEXT_SIZE(h) + H_GET_DATA_SIZE(h) + \
138 H_GET_SYMBOL_TABLE_SIZE(h) + \
139 H_GET_TEXT_RELOCATION_SIZE(h) + \
140 H_GET_DATA_RELOCATION_SIZE(h) + \
141 (h)->string_table_size)
143 #define H_GET_TEXT_SIZE(h) ((h)->header.a_text)
144 #define H_GET_DATA_SIZE(h) ((h)->header.a_data)
145 #define H_GET_BSS_SIZE(h) ((h)->header.a_bss)
146 #define H_GET_TEXT_RELOCATION_SIZE(h) ((h)->header.a_trsize)
147 #define H_GET_DATA_RELOCATION_SIZE(h) ((h)->header.a_drsize)
148 #define H_GET_SYMBOL_TABLE_SIZE(h) ((h)->header.a_syms)
149 #define H_GET_MAGIC_NUMBER(h) ((h)->header.a_info)
150 #define H_GET_ENTRY_POINT(h) ((h)->header.a_entry)
151 #define H_GET_STRING_SIZE(h) ((h)->string_table_size)
152 #ifdef EXEC_MACHINE_TYPE
153 #define H_GET_MACHINE_TYPE(h) ((h)->header.a_machtype)
154 #endif /* EXEC_MACHINE_TYPE */
156 #define H_GET_VERSION(h) ((h)->header.a_version)
157 #endif /* EXEC_VERSION */
159 #define H_SET_TEXT_SIZE(h,v) ((h)->header.a_text = md_section_align(SEG_TEXT, (v)))
160 #define H_SET_DATA_SIZE(h,v) ((h)->header.a_data = md_section_align(SEG_DATA, (v)))
161 #define H_SET_BSS_SIZE(h,v) ((h)->header.a_bss = md_section_align(SEG_BSS, (v)))
163 #define H_SET_RELOCATION_SIZE(h,t,d) (H_SET_TEXT_RELOCATION_SIZE((h),(t)),\
164 H_SET_DATA_RELOCATION_SIZE((h),(d)))
166 #define H_SET_TEXT_RELOCATION_SIZE(h,v) ((h)->header.a_trsize = (v))
167 #define H_SET_DATA_RELOCATION_SIZE(h,v) ((h)->header.a_drsize = (v))
168 #define H_SET_SYMBOL_TABLE_SIZE(h,v) ((h)->header.a_syms = (v) * \
169 sizeof(struct nlist))
171 #define H_SET_MAGIC_NUMBER(h,v) ((h)->header.a_info = (v))
173 #define H_SET_ENTRY_POINT(h,v) ((h)->header.a_entry = (v))
174 #define H_SET_STRING_SIZE(h,v) ((h)->string_table_size = (v))
175 #ifdef EXEC_MACHINE_TYPE
176 #define H_SET_MACHINE_TYPE(h,v) ((h)->header.a_machtype = (v))
177 #endif /* EXEC_MACHINE_TYPE */
179 #define H_SET_VERSION(h,v) ((h)->header.a_version = (v))
180 #endif /* EXEC_VERSION */
183 * Current means for getting the name of a segment.
184 * This will change for infinite-segments support (e.g. COFF).
186 #define segment_name(seg) ( seg_name[(int)(seg)] )
187 extern char *const seg_name[];
190 struct exec header; /* a.out header */
191 long string_table_size; /* names + '\0' + sizeof(int) */
194 /* line numbering stuff. */
195 #define OBJ_EMIT_LINENO(a, b, c) ;
196 #define obj_pre_write_hook(a) ;
205 /* end of obj-aout.h */