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