]> git.ipfire.org Git - thirdparty/binutils-gdb.git/blame - gas/config/obj-bout.c
White space and comments only. The devo tree prior to this delta is
[thirdparty/binutils-gdb.git] / gas / config / obj-bout.c
CommitLineData
fecd2382
RP
1/* b.out object file format
2 Copyright (C) 1989, 1990, 1991 Free Software Foundation, Inc.
a39116f1
RP
3
4 This file is part of GAS, the GNU Assembler.
5
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 2,
9 or (at your option) any later version.
10
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.
15
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. */
fecd2382
RP
19
20/* $Id$ */
21
22#include "as.h"
23#include "obstack.h"
86c094f2 24#include "aout/stab_gnu.h"
fecd2382 25const short /* in: segT out: N_TYPE bits */
a39116f1
RP
26 seg_N_TYPE[] = {
27 N_ABS,
28 N_TEXT,
29 N_DATA,
30 N_BSS,
31 N_UNDF, /* unknown */
32 N_UNDF, /* absent */
33 N_UNDF, /* pass1 */
34 N_UNDF, /* error */
35 N_UNDF, /* bignum/flonum */
36 N_UNDF, /* difference */
37 N_REGISTER, /* register */
38 };
fecd2382
RP
39
40const segT N_TYPE_seg [N_TYPE+2] = { /* 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,
56};
57
58#ifdef __STDC__
59static void obj_bout_stab(int what);
60static void obj_bout_line(void);
61static void obj_bout_desc(void);
62#else /* __STDC__ */
63static void obj_bout_desc();
64static void obj_bout_stab();
65static void obj_bout_line();
66#endif /* __STDC__ */
67
68const pseudo_typeS obj_pseudo_table[] = {
a39116f1 69 /* stabs (aka a.out aka b.out directives for debug symbols) */
fecd2382
RP
70 { "desc", obj_bout_desc, 0 }, /* def */
71 { "line", obj_bout_line, 0 }, /* source code line number */
72 { "stabd", obj_bout_stab, 'd' }, /* stabs */
73 { "stabn", obj_bout_stab, 'n' }, /* stabs */
74 { "stabs", obj_bout_stab, 's' }, /* stabs */
a39116f1
RP
75
76 /* coff debugging directives. Currently ignored silently */
fecd2382
RP
77 { "def", s_ignore, 0 },
78 { "dim", s_ignore, 0 },
79 { "endef", s_ignore, 0 },
80 { "ln", s_ignore, 0 },
81 { "scl", s_ignore, 0 },
82 { "size", s_ignore, 0 },
83 { "tag", s_ignore, 0 },
84 { "type", s_ignore, 0 },
85 { "val", s_ignore, 0 },
a39116f1
RP
86
87 /* other stuff we don't handle */
fecd2382
RP
88 { "ABORT", s_ignore, 0 },
89 { "ident", s_ignore, 0 },
a39116f1 90
fecd2382
RP
91 { NULL} /* end sentinel */
92}; /* obj_pseudo_table */
93
94/* Relocation. */
95
fecd2382
RP
96/*
97 * emit_relocations()
98 *
99 * Crawl along a fixS chain. Emit the segment's relocations.
100 */
101void obj_emit_relocations(where, fixP, segment_address_in_file)
102char **where;
103fixS *fixP; /* Fixup chain for this segment. */
104relax_addressT segment_address_in_file;
105{
a79c6033
RP
106 for (; fixP; fixP = fixP->fx_next) {
107 if (fixP->fx_addsy != NULL) {
108 tc_bout_fix_to_chars(*where, fixP, segment_address_in_file);
b97ea9ed 109 *where += sizeof(struct relocation_info);
a79c6033
RP
110 } /* if there's a symbol */
111 } /* for each fixup */
a39116f1 112
fecd2382
RP
113} /* emit_relocations() */
114
115/* Aout file generation & utilities */
116
117/* Convert a lvalue to machine dependent data */
118void obj_header_append(where, headers)
119char **where;
120object_headers *headers;
121{
122 /* Always leave in host byte order */
a39116f1 123
fecd2382 124 headers->header.a_talign = section_alignment[SEG_TEXT];
a39116f1 125
fecd2382
RP
126 if (headers->header.a_talign < 2){
127 headers->header.a_talign = 2;
128 } /* force to at least 2 */
a39116f1 129
fecd2382
RP
130 headers->header.a_dalign = section_alignment[SEG_DATA];
131 headers->header.a_balign = section_alignment[SEG_BSS];
a39116f1 132
fecd2382 133 headers->header.a_tload = 0;
a79c6033 134 headers->header.a_dload = md_section_align(SEG_DATA, H_GET_TEXT_SIZE(headers));
a39116f1 135
fecd2382
RP
136 append(where, (char *) &headers->header, sizeof(headers->header));
137} /* a_header_append() */
138
139void obj_symbol_to_chars(where, symbolP)
140char **where;
141symbolS *symbolP;
142{
a39116f1 143 /* leave in host byte order */
fecd2382
RP
144 append(where, (char *)&symbolP->sy_symbol, sizeof(obj_symbol_type));
145} /* obj_symbol_to_chars() */
146
147void obj_emit_symbols(where, symbol_rootP)
148char **where;
149symbolS *symbol_rootP;
150{
a39116f1
RP
151 symbolS * symbolP;
152
153 /*
154 * Emit all symbols left in the symbol chain.
155 */
156 for(symbolP = symbol_rootP; symbolP; symbolP = symbol_next(symbolP)) {
157 /* Used to save the offset of the name. It is used to point
158 to the string in memory but must be a file offset. */
159 char *temp;
160
161 temp = S_GET_NAME(symbolP);
162 S_SET_OFFSET(symbolP, symbolP->sy_name_offset);
163
164 /* Any symbol still undefined and is not a dbg symbol is made N_EXT. */
165 if (!S_IS_DEBUG(symbolP) && !S_IS_DEFINED(symbolP)) S_SET_EXTERNAL(symbolP);
166
167 obj_symbol_to_chars(where, symbolP);
168 S_SET_NAME(symbolP,temp);
169 }
fecd2382
RP
170} /* emit_symbols() */
171
172void obj_symbol_new_hook(symbolP)
173symbolS *symbolP;
174{
175 S_SET_OTHER(symbolP, 0);
176 S_SET_DESC(symbolP, 0);
177 return;
178} /* obj_symbol_new_hook() */
179
180static void obj_bout_line() {
181 /* Assume delimiter is part of expression. */
182 /* BSD4.2 as fails with delightful bug, so we */
183 /* are not being incompatible here. */
184 new_logical_line ((char *)NULL, (int)(get_absolute_expression ()));
185 demand_empty_rest_of_line();
186} /* obj_bout_line() */
187
188/*
189 * stab()
190 *
191 * Handle .stabX directives, which used to be open-coded.
192 * So much creeping featurism overloaded the semantics that we decided
193 * to put all .stabX thinking in one place. Here.
194 *
195 * We try to make any .stabX directive legal. Other people's AS will often
196 * do assembly-time consistency checks: eg assigning meaning to n_type bits
197 * and "protecting" you from setting them to certain values. (They also zero
198 * certain bits before emitting symbols. Tut tut.)
199 *
200 * If an expression is not absolute we either gripe or use the relocation
201 * information. Other people's assemblers silently forget information they
202 * don't need and invent information they need that you didn't supply.
203 *
204 * .stabX directives always make a symbol table entry. It may be junk if
205 * the rest of your .stabX directive is malformed.
206 */
207static void obj_bout_stab(what)
208int what;
209{
a39116f1
RP
210 register symbolS * symbolP = 0;
211 register char * string;
212 int saved_type = 0;
213 int length;
214 int goof; /* TRUE if we have aborted. */
215 long longint;
216
217 /*
218 * Enter with input_line_pointer pointing past .stabX and any following
219 * whitespace.
220 */
fecd2382
RP
221 goof = 0; /* JF who forgot this?? */
222 if (what == 's') {
223 string = demand_copy_C_string(& length);
224 SKIP_WHITESPACE();
225 if (*input_line_pointer == ',')
a39116f1 226 input_line_pointer ++;
fecd2382
RP
227 else {
228 as_bad("I need a comma after symbol's name");
229 goof = 1;
230 }
231 } else
a39116f1
RP
232 string = "";
233
234 /*
235 * Input_line_pointer->after ','. String->symbol name.
236 */
fecd2382
RP
237 if (!goof) {
238 symbolP = symbol_new(string,
239 SEG_UNKNOWN,
240 0,
241 (struct frag *)0);
242 switch (what) {
243 case 'd':
244 S_SET_NAME(symbolP,NULL); /* .stabd feature. */
245 S_SET_VALUE(symbolP,obstack_next_free(&frags) -
246 frag_now->fr_literal);
247 symbolP->sy_frag = frag_now;
248 break;
a39116f1 249
fecd2382
RP
250 case 'n':
251 symbolP->sy_frag = &zero_address_frag;
252 break;
a39116f1 253
fecd2382
RP
254 case 's':
255 symbolP->sy_frag = & zero_address_frag;
256 break;
a39116f1 257
fecd2382
RP
258 default:
259 BAD_CASE(what);
260 break;
261 }
262 if (get_absolute_expression_and_terminator(& longint) == ',')
a39116f1 263 symbolP->sy_symbol.n_type = saved_type = longint;
fecd2382
RP
264 else {
265 as_bad("I want a comma after the n_type expression");
266 goof = 1;
267 input_line_pointer--; /* Backup over a non-',' char. */
268 }
269 }
270 if (! goof) {
271 if (get_absolute_expression_and_terminator (& longint) == ',')
a39116f1 272 S_SET_OTHER(symbolP,longint);
fecd2382
RP
273 else {
274 as_bad("I want a comma after the n_other expression");
275 goof = 1;
276 input_line_pointer--; /* Backup over a non-',' char. */
277 }
278 }
279 if (! goof) {
280 S_SET_DESC(symbolP, get_absolute_expression ());
281 if (what == 's' || what == 'n') {
282 if (* input_line_pointer != ',') {
283 as_bad("I want a comma after the n_desc expression");
284 goof = 1;
285 } else {
286 input_line_pointer ++;
287 }
288 }
289 }
290 if ((! goof) && (what=='s' || what=='n')) {
291 pseudo_set(symbolP);
292 symbolP->sy_symbol.n_type = saved_type;
293 }
86c094f2 294#ifndef NO_LISTING
a39116f1
RP
295 {
296 extern int listing;
297
298 if (listing && !goof)
299 {
300 if (symbolP->sy_symbol.n_type == N_SLINE)
301 {
302
303 listing_source_line(symbolP->sy_symbol.n_desc);
304 }
305 else if (symbolP->sy_symbol.n_type == N_SO
306 || symbolP->sy_symbol.n_type == N_SOL)
307 {
308 listing_source_file(string);
309 }
310 }
311 }
312
86c094f2 313#endif
a39116f1 314
fecd2382 315 if (goof)
a39116f1 316 ignore_rest_of_line ();
fecd2382 317 else
a39116f1 318 demand_empty_rest_of_line ();
fecd2382
RP
319} /* obj_bout_stab() */
320
321static void obj_bout_desc() {
322 register char *name;
323 register char c;
324 register char *p;
325 register symbolS * symbolP;
326 register int temp;
a39116f1 327
fecd2382
RP
328 /*
329 * Frob invented at RMS' request. Set the n_desc of a symbol.
330 */
331 name = input_line_pointer;
332 c = get_symbol_end();
333 p = input_line_pointer;
334 * p = c;
335 SKIP_WHITESPACE();
336 if (*input_line_pointer != ',') {
337 *p = 0;
338 as_bad("Expected comma after name \"%s\"", name);
339 *p = c;
340 ignore_rest_of_line();
341 } else {
342 input_line_pointer ++;
343 temp = get_absolute_expression ();
344 *p = 0;
345 symbolP = symbol_find_or_make(name);
346 *p = c;
347 S_SET_DESC(symbolP,temp);
348 }
349 demand_empty_rest_of_line();
350} /* obj_bout_desc() */
351
352void obj_read_begin_hook() {
353 return;
354} /* obj_read_begin_hook() */
355
356void obj_crawl_symbol_chain(headers)
357object_headers *headers;
358{
359 symbolS **symbolPP;
360 symbolS *symbolP;
361 int symbol_number = 0;
a39116f1 362
fecd2382
RP
363 /* JF deal with forward references first... */
364 for (symbolP = symbol_rootP; symbolP; symbolP = symbol_next(symbolP)) {
365 if (symbolP->sy_forward) {
366 S_SET_VALUE(symbolP, S_GET_VALUE(symbolP)
367 + S_GET_VALUE(symbolP->sy_forward)
368 + symbolP->sy_forward->sy_frag->fr_address);
a39116f1 369
fecd2382
RP
370 symbolP->sy_forward=0;
371 } /* if it has a forward reference */
372 } /* walk the symbol chain */
a39116f1 373
fecd2382 374 tc_crawl_symbol_chain(headers);
a39116f1 375
fecd2382
RP
376 symbolPP = & symbol_rootP; /*->last symbol chain link. */
377 while ((symbolP = *symbolPP) != NULL) {
378 if (flagseen['R'] && (S_GET_SEGMENT(symbolP) == SEG_DATA)) {
379 S_SET_SEGMENT(symbolP, SEG_TEXT);
380 } /* if pusing data into text */
a39116f1 381
fecd2382 382 S_SET_VALUE(symbolP, S_GET_VALUE(symbolP) + symbolP->sy_frag->fr_address);
a39116f1 383
fecd2382
RP
384 /* OK, here is how we decide which symbols go out into the
385 brave new symtab. Symbols that do are:
a39116f1 386
fecd2382
RP
387 * symbols with no name (stabd's?)
388 * symbols with debug info in their N_TYPE
a39116f1 389
fecd2382
RP
390 Symbols that don't are:
391 * symbols that are registers
392 * symbols with \1 as their 3rd character (numeric labels)
393 * "local labels" as defined by S_LOCAL_NAME(name)
394 if the -L switch was passed to gas.
a39116f1 395
fecd2382
RP
396 All other symbols are output. We complain if a deleted
397 symbol was marked external. */
a39116f1
RP
398
399
fecd2382
RP
400 if (1
401 && !S_IS_REGISTER(symbolP)
402 && (!S_GET_NAME(symbolP)
403 || S_IS_DEBUG(symbolP)
404#ifdef TC_I960
405 /* FIXME-SOON this ifdef seems highly dubious to me. xoxorich. */
406 || !S_IS_DEFINED(symbolP)
407 || S_IS_EXTERNAL(symbolP)
408#endif /* TC_I960 */
409 || (S_GET_NAME(symbolP)[0] != '\001' && (flagseen ['L'] || ! S_LOCAL_NAME(symbolP))))) {
410 symbolP->sy_number = symbol_number++;
a39116f1 411
fecd2382
RP
412 /* The + 1 after strlen account for the \0 at the
413 end of each string */
414 if (!S_IS_STABD(symbolP)) {
415 /* Ordinary case. */
416 symbolP->sy_name_offset = string_byte_count;
417 string_byte_count += strlen(S_GET_NAME(symbolP)) + 1;
418 }
419 else /* .Stabd case. */
420 symbolP->sy_name_offset = 0;
421 symbolPP = &(symbol_next(symbolP));
422 } else {
423 if (S_IS_EXTERNAL(symbolP) || !S_IS_DEFINED(symbolP)) {
424 as_bad("Local symbol %s never defined", S_GET_NAME(symbolP));
425 } /* oops. */
a39116f1 426
fecd2382
RP
427 /* Unhook it from the chain */
428 *symbolPP = symbol_next(symbolP);
429 } /* if this symbol should be in the output */
430 } /* for each symbol */
a39116f1 431
fecd2382 432 H_SET_SYMBOL_TABLE_SIZE(headers, symbol_number);
a39116f1 433
fecd2382
RP
434 return;
435} /* obj_crawl_symbol_chain() */
436
437/*
438 * Find strings by crawling along symbol table chain.
439 */
440
441void obj_emit_strings(where)
442char **where;
443{
444 symbolS *symbolP;
a39116f1 445
3cc6716d 446#ifdef CROSS_COMPILE
fecd2382
RP
447 /* Gotta do md_ byte-ordering stuff for string_byte_count first - KWK */
448 md_number_to_chars(*where, string_byte_count, sizeof(string_byte_count));
449 *where += sizeof(string_byte_count);
3cc6716d 450#else /* CROSS_COMPILE */
fecd2382 451 append(where, (char *) &string_byte_count, (unsigned long) sizeof(string_byte_count));
3cc6716d 452#endif /* CROSS_COMPILE */
a39116f1 453
fecd2382
RP
454 for(symbolP = symbol_rootP; symbolP; symbolP = symbol_next(symbolP)) {
455 if(S_GET_NAME(symbolP))
456 append(where, S_GET_NAME(symbolP), (unsigned long)(strlen (S_GET_NAME(symbolP)) + 1));
457 } /* walk symbol chain */
a39116f1 458
fecd2382
RP
459 return;
460} /* obj_emit_strings() */
461
462/*
463 * Local Variables:
464 * comment-column: 0
465 * fill-column: 131
466 * End:
467 */
468
469/* end of obj-bout.c */