obj-aout.h revision 38889
1/* obj-aout.h, a.out object file format for gas, the assembler.
2   Copyright (C) 1989, 90, 91, 92, 93, 94, 95, 96, 1998
3   Free Software Foundation, Inc.
4
5   This file is part of GAS, the GNU Assembler.
6
7   GAS is free software; you can redistribute it and/or modify
8   it under the terms of the GNU General Public License as
9   published by the Free Software Foundation; either version 2,
10   or (at your option) any later version.
11
12   GAS is distributed in the hope that it will be useful, but
13   WITHOUT ANY WARRANTY; without even the implied warranty of
14   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See
15   the GNU General Public License for more details.
16
17   You should have received a copy of the GNU General Public License
18   along with GAS; see the file COPYING.  If not, write to the Free
19   Software Foundation, 59 Temple Place - Suite 330, Boston, MA
20   02111-1307, USA. */
21
22/* Tag to validate a.out object file format processing */
23#define OBJ_AOUT 1
24
25#include "targ-cpu.h"
26
27#ifdef BFD_ASSEMBLER
28
29#include "bfd/libaout.h"
30
31#define OUTPUT_FLAVOR bfd_target_aout_flavour
32
33#else /* ! BFD_ASSEMBLER */
34
35#ifndef VMS
36#include "aout_gnu.h"		/* Needed to define struct nlist. Sigh. */
37#else
38#include "a_out.h"
39#endif
40
41#ifndef AOUT_MACHTYPE
42#define AOUT_MACHTYPE 0
43#endif /* AOUT_MACHTYPE */
44
45extern const short seg_N_TYPE[];
46extern const segT N_TYPE_seg[];
47
48#ifndef DEFAULT_MAGIC_NUMBER_FOR_OBJECT_FILE
49#define DEFAULT_MAGIC_NUMBER_FOR_OBJECT_FILE	(OMAGIC)
50#endif /* DEFAULT_MAGIC_NUMBER_FOR_OBJECT_FILE */
51
52#endif /* ! BFD_ASSEMBLER */
53
54/* SYMBOL TABLE */
55/* Symbol table entry data type */
56
57typedef struct nlist obj_symbol_type;	/* Symbol table entry */
58
59/* Symbol table macros and constants */
60
61#ifdef BFD_ASSEMBLER
62
63#define S_SET_OTHER(S,V)		(aout_symbol((S)->bsym)->other = (V))
64#define S_SET_TYPE(S,T)			(aout_symbol((S)->bsym)->type = (T))
65#define S_SET_DESC(S,D)			(aout_symbol((S)->bsym)->desc = (D))
66#define S_GET_OTHER(S)			(aout_symbol((S)->bsym)->other)
67#define S_GET_TYPE(S)			(aout_symbol((S)->bsym)->type)
68#define S_GET_DESC(S)			(aout_symbol((S)->bsym)->desc)
69
70asection *text_section, *data_section, *bss_section;
71
72#define obj_frob_symbol(S,PUNT)	obj_aout_frob_symbol (S, &PUNT)
73#define obj_frob_file()		obj_aout_frob_file ()
74extern void obj_aout_frob_symbol PARAMS ((struct symbol *, int *));
75extern void obj_aout_frob_file PARAMS ((void));
76
77#define obj_sec_sym_ok_for_reloc(SEC)	(1)
78
79#else
80
81/* We use the sy_obj field to record whether a symbol is weak.  */
82#define OBJ_SYMFIELD_TYPE char
83
84/*
85 *  Macros to extract information from a symbol table entry.
86 *  This syntaxic indirection allows independence regarding a.out or coff.
87 *  The argument (s) of all these macros is a pointer to a symbol table entry.
88 */
89
90/* True if the symbol is external */
91#define S_IS_EXTERNAL(s)	((s)->sy_symbol.n_type & N_EXT)
92
93/* True if symbol has been defined, ie is in N_{TEXT,DATA,BSS,ABS} or N_EXT */
94#define S_IS_DEFINED(s) \
95  (S_GET_TYPE (s) != N_UNDF || S_GET_DESC (s) != 0)
96
97#define S_IS_COMMON(s) \
98  (S_GET_TYPE (s) == N_UNDF && S_GET_VALUE (s) != 0)
99
100#define S_IS_REGISTER(s)	((s)->sy_symbol.n_type == N_REGISTER)
101
102/* True if a debug special symbol entry */
103#define S_IS_DEBUG(s)		((s)->sy_symbol.n_type & N_STAB)
104/* True if a symbol is local symbol name */
105#define S_IS_LOCAL(s) 					\
106  ((S_GET_NAME (s) 					\
107    && !S_IS_DEBUG (s) 					\
108    && (strchr (S_GET_NAME (s), '\001') != NULL		\
109        || strchr (S_GET_NAME (s), '\002') != NULL	\
110        || (S_LOCAL_NAME(s) && !flag_keep_locals)))	\
111   || (flag_strip_local_absolute			\
112       && ! S_IS_EXTERNAL(s)				\
113       && S_GET_SEGMENT (s) == absolute_section))
114/* True if a symbol is not defined in this file */
115#define S_IS_EXTERN(s)		((s)->sy_symbol.n_type & N_EXT)
116/* True if the symbol has been generated because of a .stabd directive */
117#define S_IS_STABD(s)		(S_GET_NAME(s) == (char *)0)
118
119/* Accessors */
120/* The name of the symbol */
121#define S_GET_NAME(s)		((s)->sy_symbol.n_un.n_name)
122/* The pointer to the string table */
123#define S_GET_OFFSET(s)		((s)->sy_symbol.n_un.n_strx)
124/* The type of the symbol */
125#define S_GET_TYPE(s)		((s)->sy_symbol.n_type & N_TYPE)
126/* The numeric value of the segment */
127#define S_GET_SEGMENT(s)	(N_TYPE_seg[S_GET_TYPE(s)])
128/* The n_other expression value */
129#define S_GET_OTHER(s)		((s)->sy_symbol.n_other)
130/* The n_desc expression value */
131#define S_GET_DESC(s)		((s)->sy_symbol.n_desc)
132/* Whether the symbol is weak.  */
133#define S_GET_WEAK(s)		((s)->sy_obj)
134
135/* Modifiers */
136/* Assume that a symbol cannot be simultaneously in more than on segment */
137/* set segment */
138#define S_SET_SEGMENT(s,seg)	((s)->sy_symbol.n_type &= ~N_TYPE,(s)->sy_symbol.n_type|=SEGMENT_TO_SYMBOL_TYPE(seg))
139/* The symbol is external */
140#define S_SET_EXTERNAL(s)	((s)->sy_symbol.n_type |= N_EXT)
141/* The symbol is not external */
142#define S_CLEAR_EXTERNAL(s)	((s)->sy_symbol.n_type &= ~N_EXT)
143/* Set the name of the symbol */
144#define S_SET_NAME(s,v)		((s)->sy_symbol.n_un.n_name = (v))
145/* Set the offset in the string table */
146#define S_SET_OFFSET(s,v)	((s)->sy_symbol.n_un.n_strx = (v))
147/* Set the n_type field */
148#define S_SET_TYPE(s,t)		((s)->sy_symbol.n_type = (t))
149/* Set the n_other expression value */
150#define S_SET_OTHER(s,v)	((s)->sy_symbol.n_other = (v))
151/* Set the n_desc expression value */
152#define S_SET_DESC(s,v)		((s)->sy_symbol.n_desc = (v))
153/* Mark the symbol as weak.  This causes n_type to be adjusted when
154   the symbol is written out.  */
155#define S_SET_WEAK(s)		((s)->sy_obj = 1)
156
157/* File header macro and type definition */
158
159#define H_GET_FILE_SIZE(h)	(H_GET_HEADER_SIZE(h) \
160				 + H_GET_TEXT_SIZE(h) \
161				 + H_GET_DATA_SIZE(h) \
162				 + H_GET_SYMBOL_TABLE_SIZE(h) \
163				 + H_GET_TEXT_RELOCATION_SIZE(h) \
164				 + H_GET_DATA_RELOCATION_SIZE(h) \
165				 + H_GET_STRING_SIZE(h))
166
167#define H_GET_HEADER_SIZE(h)		(EXEC_BYTES_SIZE)
168#define H_GET_TEXT_SIZE(h)		((h)->header.a_text)
169#define H_GET_DATA_SIZE(h)		((h)->header.a_data)
170#define H_GET_BSS_SIZE(h)		((h)->header.a_bss)
171#define H_GET_TEXT_RELOCATION_SIZE(h)	((h)->header.a_trsize)
172#define H_GET_DATA_RELOCATION_SIZE(h)	((h)->header.a_drsize)
173#define H_GET_SYMBOL_TABLE_SIZE(h)	((h)->header.a_syms)
174#define H_GET_ENTRY_POINT(h)		((h)->header.a_entry)
175#define H_GET_STRING_SIZE(h)		((h)->string_table_size)
176#define H_GET_LINENO_SIZE(h)		(0)
177
178#define H_GET_DYNAMIC(h)		((h)->header.a_info >> 31)
179#define H_GET_VERSION(h)		(((h)->header.a_info >> 24) & 0x7f)
180#define H_GET_MACHTYPE(h)		(((h)->header.a_info >> 16) & 0xff)
181#define H_GET_MAGIC_NUMBER(h)		((h)->header.a_info & 0xffff)
182
183#define H_SET_DYNAMIC(h,v)		((h)->header.a_info = (((v) << 31) \
184							       | (H_GET_VERSION(h) << 24) \
185							       | (H_GET_MACHTYPE(h) << 16) \
186							       | (H_GET_MAGIC_NUMBER(h))))
187
188#define H_SET_VERSION(h,v)		((h)->header.a_info = ((H_GET_DYNAMIC(h) << 31) \
189							       | ((v) << 24) \
190							       | (H_GET_MACHTYPE(h) << 16) \
191							       | (H_GET_MAGIC_NUMBER(h))))
192
193#define H_SET_MACHTYPE(h,v)		((h)->header.a_info = ((H_GET_DYNAMIC(h) << 31) \
194							       | (H_GET_VERSION(h) << 24) \
195							       | ((v) << 16) \
196							       | (H_GET_MAGIC_NUMBER(h))))
197
198#define H_SET_MAGIC_NUMBER(h,v)		((h)->header.a_info = ((H_GET_DYNAMIC(h) << 31) \
199							       | (H_GET_VERSION(h) << 24) \
200							       | (H_GET_MACHTYPE(h) << 16) \
201							       | ((v))))
202
203#define H_SET_TEXT_SIZE(h,v)		((h)->header.a_text = md_section_align(SEG_TEXT, (v)))
204#define H_SET_DATA_SIZE(h,v)		((h)->header.a_data = md_section_align(SEG_DATA, (v)))
205#define H_SET_BSS_SIZE(h,v)		((h)->header.a_bss = md_section_align(SEG_BSS, (v)))
206
207#define H_SET_RELOCATION_SIZE(h,t,d)	(H_SET_TEXT_RELOCATION_SIZE((h),(t)),\
208					 H_SET_DATA_RELOCATION_SIZE((h),(d)))
209
210#define H_SET_TEXT_RELOCATION_SIZE(h,v)	((h)->header.a_trsize = (v))
211#define H_SET_DATA_RELOCATION_SIZE(h,v)	((h)->header.a_drsize = (v))
212#define H_SET_SYMBOL_TABLE_SIZE(h,v)	((h)->header.a_syms = (v) * 12)
213
214#define H_SET_ENTRY_POINT(h,v)		((h)->header.a_entry = (v))
215#define H_SET_STRING_SIZE(h,v)		((h)->string_table_size = (v))
216
217typedef struct
218  {
219    struct exec header;		/* a.out header */
220    long string_table_size;	/* names + '\0' + sizeof(int) */
221  }
222
223object_headers;
224
225/* line numbering stuff. */
226#define OBJ_EMIT_LINENO(a, b, c)	{;}
227
228struct fix;
229void tc_aout_fix_to_chars PARAMS ((char *where, struct fix *fixP, relax_addressT segment_address));
230
231#endif
232
233#define obj_symbol_new_hook(s)	{;}
234
235#define EMIT_SECTION_SYMBOLS		0
236
237#define AOUT_STABS
238
239/* end of obj-aout.h */
240