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