* config/tc-mn10200.c (mn10200_insert_operand): Don't
[deliverable/binutils-gdb.git] / gas / config / obj-bout.c
CommitLineData
fecd2382 1/* b.out object file format
011d16ac
ILT
2 Copyright (C) 1989, 90, 91, 92, 93, 94, 95, 1996
3 Free Software Foundation, Inc.
355afbcd 4
a39116f1 5 This file is part of GAS, the GNU Assembler.
355afbcd 6
a39116f1
RP
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.
355afbcd 11
a39116f1
RP
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.
355afbcd 16
a39116f1
RP
17 You should have received a copy of the GNU General Public
18 License along with GAS; see the file COPYING. If not, write
a2a5a4fa 19 to the Free Software Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */
fecd2382 20
fecd2382
RP
21#include "as.h"
22#include "obstack.h"
355afbcd
KR
23const short /* in: segT out: N_TYPE bits */
24 seg_N_TYPE[] =
25{
26 N_ABS,
27 N_TEXT,
28 N_DATA,
29 N_BSS,
30 N_UNDF, /* unknown */
355afbcd 31 N_UNDF, /* error */
5ac34ac3
ILT
32 N_UNDF, /* expression */
33 N_UNDF, /* debug */
34 N_UNDF, /* ntv */
35 N_UNDF, /* ptv */
355afbcd
KR
36 N_REGISTER, /* register */
37};
38
39const segT N_TYPE_seg[N_TYPE + 2] =
40{ /* N_TYPE == 0x1E = 32-2 */
41 SEG_UNKNOWN, /* N_UNDF == 0 */
42 SEG_GOOF,
43 SEG_ABSOLUTE, /* N_ABS == 2 */
44 SEG_GOOF,
45 SEG_TEXT, /* N_TEXT == 4 */
46 SEG_GOOF,
47 SEG_DATA, /* N_DATA == 6 */
48 SEG_GOOF,
49 SEG_BSS, /* N_BSS == 8 */
50 SEG_GOOF,
51 SEG_GOOF, SEG_GOOF, SEG_GOOF, SEG_GOOF, SEG_GOOF, SEG_GOOF, SEG_GOOF, SEG_GOOF,
52 SEG_GOOF, SEG_GOOF, SEG_GOOF, SEG_GOOF, SEG_GOOF, SEG_GOOF, SEG_GOOF, SEG_GOOF,
53 SEG_GOOF, SEG_GOOF, SEG_GOOF, SEG_GOOF,
54 SEG_REGISTER, /* dummy N_REGISTER for regs = 30 */
55 SEG_GOOF,
fecd2382
RP
56};
57
4f0bccc7 58static void obj_bout_line PARAMS ((int));
fecd2382 59
355afbcd
KR
60const pseudo_typeS obj_pseudo_table[] =
61{
355afbcd 62 {"line", obj_bout_line, 0}, /* source code line number */
355afbcd
KR
63
64/* coff debugging directives. Currently ignored silently */
65 {"def", s_ignore, 0},
66 {"dim", s_ignore, 0},
67 {"endef", s_ignore, 0},
68 {"ln", s_ignore, 0},
69 {"scl", s_ignore, 0},
70 {"size", s_ignore, 0},
71 {"tag", s_ignore, 0},
72 {"type", s_ignore, 0},
73 {"val", s_ignore, 0},
74
75/* other stuff we don't handle */
76 {"ABORT", s_ignore, 0},
77 {"ident", s_ignore, 0},
78
79 {NULL} /* end sentinel */
80}; /* obj_pseudo_table */
fecd2382
RP
81
82/* Relocation. */
83
fecd2382
RP
84/*
85 * emit_relocations()
86 *
87 * Crawl along a fixS chain. Emit the segment's relocations.
88 */
355afbcd
KR
89void
90obj_emit_relocations (where, fixP, segment_address_in_file)
91 char **where;
92 fixS *fixP; /* Fixup chain for this segment. */
93 relax_addressT segment_address_in_file;
fecd2382 94{
355afbcd
KR
95 for (; fixP; fixP = fixP->fx_next)
96 {
98c6bbbe 97 if (fixP->fx_done == 0
355afbcd
KR
98 || fixP->fx_r_type != NO_RELOC)
99 {
e24cf2b5
ILT
100 symbolS *sym;
101
102 sym = fixP->fx_addsy;
103 while (sym->sy_value.X_op == O_symbol
104 && (! S_IS_DEFINED (sym) || S_IS_COMMON (sym)))
105 sym = sym->sy_value.X_add_symbol;
106 fixP->fx_addsy = sym;
107
355afbcd
KR
108 tc_bout_fix_to_chars (*where, fixP, segment_address_in_file);
109 *where += sizeof (struct relocation_info);
110 } /* if there's a symbol */
111 } /* for each fixup */
112
113} /* emit_relocations() */
fecd2382
RP
114
115/* Aout file generation & utilities */
116
117/* Convert a lvalue to machine dependent data */
355afbcd
KR
118void
119obj_header_append (where, headers)
120 char **where;
121 object_headers *headers;
fecd2382 122{
355afbcd
KR
123 /* Always leave in host byte order */
124
125 headers->header.a_talign = section_alignment[SEG_TEXT];
126
127 if (headers->header.a_talign < 2)
128 {
129 headers->header.a_talign = 2;
130 } /* force to at least 2 */
131
132 headers->header.a_dalign = section_alignment[SEG_DATA];
133 headers->header.a_balign = section_alignment[SEG_BSS];
134
135 headers->header.a_tload = 0;
136 headers->header.a_dload = md_section_align (SEG_DATA, H_GET_TEXT_SIZE (headers));
137
138 headers->header.a_relaxable = linkrelax;
462088b8 139
8ae35e59 140#ifdef CROSS_COMPILE
355afbcd
KR
141 md_number_to_chars (*where, headers->header.a_magic, sizeof (headers->header.a_magic));
142 *where += sizeof (headers->header.a_magic);
143 md_number_to_chars (*where, headers->header.a_text, sizeof (headers->header.a_text));
144 *where += sizeof (headers->header.a_text);
145 md_number_to_chars (*where, headers->header.a_data, sizeof (headers->header.a_data));
146 *where += sizeof (headers->header.a_data);
147 md_number_to_chars (*where, headers->header.a_bss, sizeof (headers->header.a_bss));
148 *where += sizeof (headers->header.a_bss);
149 md_number_to_chars (*where, headers->header.a_syms, sizeof (headers->header.a_syms));
150 *where += sizeof (headers->header.a_syms);
151 md_number_to_chars (*where, headers->header.a_entry, sizeof (headers->header.a_entry));
152 *where += sizeof (headers->header.a_entry);
153 md_number_to_chars (*where, headers->header.a_trsize, sizeof (headers->header.a_trsize));
154 *where += sizeof (headers->header.a_trsize);
155 md_number_to_chars (*where, headers->header.a_drsize, sizeof (headers->header.a_drsize));
156 *where += sizeof (headers->header.a_drsize);
157 md_number_to_chars (*where, headers->header.a_tload, sizeof (headers->header.a_tload));
158 *where += sizeof (headers->header.a_tload);
159 md_number_to_chars (*where, headers->header.a_dload, sizeof (headers->header.a_dload));
160 *where += sizeof (headers->header.a_dload);
161 md_number_to_chars (*where, headers->header.a_talign, sizeof (headers->header.a_talign));
162 *where += sizeof (headers->header.a_talign);
163 md_number_to_chars (*where, headers->header.a_dalign, sizeof (headers->header.a_dalign));
164 *where += sizeof (headers->header.a_dalign);
165 md_number_to_chars (*where, headers->header.a_balign, sizeof (headers->header.a_balign));
166 *where += sizeof (headers->header.a_balign);
167 md_number_to_chars (*where, headers->header.a_relaxable, sizeof (headers->header.a_relaxable));
168 *where += sizeof (headers->header.a_relaxable);
8ae35e59 169#else /* ! CROSS_COMPILE */
355afbcd 170 append (where, (char *) &headers->header, sizeof (headers->header));
8ae35e59 171#endif /* ! CROSS_COMPILE */
355afbcd 172} /* a_header_append() */
fecd2382 173
355afbcd
KR
174void
175obj_symbol_to_chars (where, symbolP)
176 char **where;
177 symbolS *symbolP;
fecd2382 178{
355afbcd
KR
179 md_number_to_chars ((char *) &(S_GET_OFFSET (symbolP)), S_GET_OFFSET (symbolP), sizeof (S_GET_OFFSET (symbolP)));
180 md_number_to_chars ((char *) &(S_GET_DESC (symbolP)), S_GET_DESC (symbolP), sizeof (S_GET_DESC (symbolP)));
85051959 181 md_number_to_chars ((char *) &symbolP->sy_symbol.n_value, S_GET_VALUE (symbolP), sizeof (symbolP->sy_symbol.n_value));
8ae35e59 182
355afbcd
KR
183 append (where, (char *) &symbolP->sy_symbol, sizeof (obj_symbol_type));
184} /* obj_symbol_to_chars() */
fecd2382 185
355afbcd
KR
186void
187obj_emit_symbols (where, symbol_rootP)
188 char **where;
189 symbolS *symbol_rootP;
fecd2382 190{
355afbcd
KR
191 symbolS *symbolP;
192
193 /*
a39116f1
RP
194 * Emit all symbols left in the symbol chain.
195 */
355afbcd
KR
196 for (symbolP = symbol_rootP; symbolP; symbolP = symbol_next (symbolP))
197 {
198 /* Used to save the offset of the name. It is used to point
a39116f1 199 to the string in memory but must be a file offset. */
355afbcd
KR
200 char *temp;
201
202 temp = S_GET_NAME (symbolP);
203 S_SET_OFFSET (symbolP, symbolP->sy_name_offset);
204
205 /* Any symbol still undefined and is not a dbg symbol is made N_EXT. */
206 if (!S_IS_DEBUG (symbolP) && !S_IS_DEFINED (symbolP))
207 S_SET_EXTERNAL (symbolP);
fecd2382 208
355afbcd
KR
209 obj_symbol_to_chars (where, symbolP);
210 S_SET_NAME (symbolP, temp);
211 }
212} /* emit_symbols() */
213
214void
215obj_symbol_new_hook (symbolP)
216 symbolS *symbolP;
217{
218 S_SET_OTHER (symbolP, 0);
219 S_SET_DESC (symbolP, 0);
c999fd9f 220}
355afbcd
KR
221
222static void
4f0bccc7
ILT
223obj_bout_line (ignore)
224 int ignore;
fecd2382 225{
355afbcd
KR
226 /* Assume delimiter is part of expression. */
227 /* BSD4.2 as fails with delightful bug, so we */
228 /* are not being incompatible here. */
229 new_logical_line ((char *) NULL, (int) (get_absolute_expression ()));
230 demand_empty_rest_of_line ();
231} /* obj_bout_line() */
fecd2382 232
355afbcd
KR
233void
234obj_read_begin_hook ()
235{
c999fd9f 236}
fecd2382 237
355afbcd
KR
238void
239obj_crawl_symbol_chain (headers)
240 object_headers *headers;
fecd2382 241{
355afbcd
KR
242 symbolS **symbolPP;
243 symbolS *symbolP;
244 int symbol_number = 0;
245
355afbcd
KR
246 tc_crawl_symbol_chain (headers);
247
248 symbolPP = &symbol_rootP; /*->last symbol chain link. */
249 while ((symbolP = *symbolPP) != NULL)
250 {
def66e24 251 if (flag_readonly_data_in_text && (S_GET_SEGMENT (symbolP) == SEG_DATA))
355afbcd
KR
252 {
253 S_SET_SEGMENT (symbolP, SEG_TEXT);
254 } /* if pusing data into text */
255
5868b1fe 256 resolve_symbol_value (symbolP);
355afbcd 257
e24cf2b5
ILT
258 /* Skip symbols which were equated to undefined or common
259 symbols. */
260 if (symbolP->sy_value.X_op == O_symbol
261 && (! S_IS_DEFINED (symbolP) || S_IS_COMMON (symbolP)))
262 {
263 *symbolPP = symbol_next (symbolP);
264 continue;
265 }
266
355afbcd 267 /* OK, here is how we decide which symbols go out into the
4f0bccc7 268 brave new symtab. Symbols that do are:
355afbcd 269
4f0bccc7
ILT
270 * symbols with no name (stabd's?)
271 * symbols with debug info in their N_TYPE
355afbcd 272
4f0bccc7
ILT
273 Symbols that don't are:
274 * symbols that are registers
275 * symbols with \1 as their 3rd character (numeric labels)
276 * "local labels" as defined by S_LOCAL_NAME(name)
277 if the -L switch was passed to gas.
355afbcd 278
4f0bccc7
ILT
279 All other symbols are output. We complain if a deleted
280 symbol was marked external. */
355afbcd
KR
281
282
283 if (1
284 && !S_IS_REGISTER (symbolP)
285 && (!S_GET_NAME (symbolP)
286 || S_IS_DEBUG (symbolP)
fecd2382 287#ifdef TC_I960
355afbcd
KR
288 /* FIXME-SOON this ifdef seems highly dubious to me. xoxorich. */
289 || !S_IS_DEFINED (symbolP)
290 || S_IS_EXTERNAL (symbolP)
fecd2382 291#endif /* TC_I960 */
def66e24 292 || (S_GET_NAME (symbolP)[0] != '\001' && (flag_keep_locals || !S_LOCAL_NAME (symbolP)))))
355afbcd
KR
293 {
294 symbolP->sy_number = symbol_number++;
295
296 /* The + 1 after strlen account for the \0 at the
fecd2382 297 end of each string */
355afbcd
KR
298 if (!S_IS_STABD (symbolP))
299 {
300 /* Ordinary case. */
301 symbolP->sy_name_offset = string_byte_count;
302 string_byte_count += strlen (S_GET_NAME (symbolP)) + 1;
303 }
304 else /* .Stabd case. */
305 symbolP->sy_name_offset = 0;
306 symbolPP = &(symbol_next (symbolP));
307 }
308 else
309 {
310 if (S_IS_EXTERNAL (symbolP) || !S_IS_DEFINED (symbolP))
311 {
312 as_bad ("Local symbol %s never defined", S_GET_NAME (symbolP));
313 } /* oops. */
314
315 /* Unhook it from the chain */
316 *symbolPP = symbol_next (symbolP);
317 } /* if this symbol should be in the output */
318 } /* for each symbol */
319
320 H_SET_SYMBOL_TABLE_SIZE (headers, symbol_number);
c999fd9f 321}
fecd2382
RP
322
323/*
324 * Find strings by crawling along symbol table chain.
325 */
326
355afbcd
KR
327void
328obj_emit_strings (where)
329 char **where;
fecd2382 330{
355afbcd
KR
331 symbolS *symbolP;
332
3cc6716d 333#ifdef CROSS_COMPILE
355afbcd
KR
334 /* Gotta do md_ byte-ordering stuff for string_byte_count first - KWK */
335 md_number_to_chars (*where, string_byte_count, sizeof (string_byte_count));
336 *where += sizeof (string_byte_count);
3cc6716d 337#else /* CROSS_COMPILE */
355afbcd 338 append (where, (char *) &string_byte_count, (unsigned long) sizeof (string_byte_count));
3cc6716d 339#endif /* CROSS_COMPILE */
355afbcd
KR
340
341 for (symbolP = symbol_rootP; symbolP; symbolP = symbol_next (symbolP))
342 {
343 if (S_GET_NAME (symbolP))
344 append (where, S_GET_NAME (symbolP), (unsigned long) (strlen (S_GET_NAME (symbolP)) + 1));
345 } /* walk symbol chain */
c999fd9f 346}
fecd2382 347
fecd2382 348/* end of obj-bout.c */
This page took 0.196714 seconds and 4 git commands to generate.