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