1 /* b.out object file format
2 Copyright 1989, 1990, 1991, 1992, 1993, 1994, 1996, 2000, 2001, 2002,
3 2003, 2005 Free Software Foundation, Inc.
5 This file is part of GAS, the GNU Assembler.
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.
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.
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, 51 Franklin Street - Fifth Floor, Boston, MA
25 /* In: segT Out: N_TYPE bits. */
26 const short seg_N_TYPE
[] =
32 N_UNDF
, /* Unknown. */
34 N_UNDF
, /* Expression. */
38 N_REGISTER
, /* Register. */
41 const segT N_TYPE_seg
[N_TYPE
+ 2] =
42 { /* N_TYPE == 0x1E = 32-2 */
43 SEG_UNKNOWN
, /* N_UNDF == 0 */
45 SEG_ABSOLUTE
, /* N_ABS == 2 */
47 SEG_TEXT
, /* N_TEXT == 4 */
49 SEG_DATA
, /* N_DATA == 6 */
51 SEG_BSS
, /* N_BSS == 8 */
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
, SEG_GOOF
, SEG_GOOF
, SEG_GOOF
, SEG_GOOF
,
55 SEG_GOOF
, SEG_GOOF
, SEG_GOOF
, SEG_GOOF
,
56 SEG_REGISTER
, /* Dummy N_REGISTER for regs = 30. */
62 /* Crawl along a fixS chain. Emit the segment's relocations. */
65 obj_emit_relocations (char **where
,
66 fixS
*fixP
, /* Fixup chain for this segment. */
67 relax_addressT segment_address_in_file
)
69 for (; fixP
; fixP
= fixP
->fx_next
)
71 if (fixP
->fx_done
== 0
72 || fixP
->fx_r_type
!= NO_RELOC
)
77 while (sym
->sy_value
.X_op
== O_symbol
78 && (! S_IS_DEFINED (sym
) || S_IS_COMMON (sym
)))
79 sym
= sym
->sy_value
.X_add_symbol
;
82 tc_bout_fix_to_chars (*where
, fixP
, segment_address_in_file
);
83 *where
+= md_reloc_size
;
88 /* Aout file generation & utilities . */
90 /* Convert a lvalue to machine dependent data. */
93 obj_header_append (char **where
, object_headers
*headers
)
95 /* Always leave in host byte order. */
98 headers
->header
.a_talign
= section_alignment
[SEG_TEXT
];
100 /* Force to at least 2. */
101 if (headers
->header
.a_talign
< 2)
102 headers
->header
.a_talign
= 2;
104 headers
->header
.a_dalign
= section_alignment
[SEG_DATA
];
105 headers
->header
.a_balign
= section_alignment
[SEG_BSS
];
107 headers
->header
.a_tload
= 0;
108 headers
->header
.a_dload
=
109 md_section_align (SEG_DATA
, H_GET_TEXT_SIZE (headers
));
111 headers
->header
.a_relaxable
= linkrelax
;
114 host_number_to_chars (p
, headers
->header
.a_magic
, 4);
116 host_number_to_chars (p
, headers
->header
.a_text
, 4);
118 host_number_to_chars (p
, headers
->header
.a_data
, 4);
120 host_number_to_chars (p
, headers
->header
.a_bss
, 4);
122 host_number_to_chars (p
, headers
->header
.a_syms
, 4);
124 host_number_to_chars (p
, headers
->header
.a_entry
, 4);
126 host_number_to_chars (p
, headers
->header
.a_trsize
, 4);
128 host_number_to_chars (p
, headers
->header
.a_drsize
, 4);
130 host_number_to_chars (p
, headers
->header
.a_tload
, 4);
132 host_number_to_chars (p
, headers
->header
.a_dload
, 4);
134 *p
++ = headers
->header
.a_talign
;
135 *p
++ = headers
->header
.a_dalign
;
136 *p
++ = headers
->header
.a_balign
;
137 *p
++ = headers
->header
.a_relaxable
;
142 obj_symbol_to_chars (char **where
, symbolS
*symbolP
)
146 host_number_to_chars (p
, S_GET_OFFSET (symbolP
), 4);
148 /* Can't use S_GET_TYPE here as it masks. */
149 *p
++ = symbolP
->sy_symbol
.n_type
;
150 *p
++ = symbolP
->sy_symbol
.n_other
;
151 host_number_to_chars (p
, S_GET_DESC (symbolP
), 2);
153 host_number_to_chars (p
, S_GET_VALUE (symbolP
), 4);
159 obj_emit_symbols (char **where
, symbolS
*symbol_rootP
)
163 /* Emit all symbols left in the symbol chain. */
164 for (symbolP
= symbol_rootP
; symbolP
; symbolP
= symbol_next (symbolP
))
166 /* Used to save the offset of the name. It is used to point to
167 the string in memory but must be a file offset. */
170 temp
= S_GET_NAME (symbolP
);
171 S_SET_OFFSET (symbolP
, symbolP
->sy_name_offset
);
173 /* Any symbol still undefined and is not a dbg symbol is made N_EXT. */
174 if (!S_IS_DEBUG (symbolP
) && !S_IS_DEFINED (symbolP
))
175 S_SET_EXTERNAL (symbolP
);
177 obj_symbol_to_chars (where
, symbolP
);
178 S_SET_NAME (symbolP
, temp
);
183 obj_symbol_new_hook (symbolS
*symbolP
)
185 S_SET_OTHER (symbolP
, 0);
186 S_SET_DESC (symbolP
, 0);
190 obj_bout_line (int ignore ATTRIBUTE_UNUSED
)
192 /* Assume delimiter is part of expression. */
193 /* BSD4.2 as fails with delightful bug, so we are not being
194 incompatible here. */
195 new_logical_line (NULL
, (int) (get_absolute_expression ()));
196 demand_empty_rest_of_line ();
200 obj_read_begin_hook (void)
205 obj_crawl_symbol_chain (object_headers
*headers
)
209 int symbol_number
= 0;
211 tc_crawl_symbol_chain (headers
);
213 symbolPP
= &symbol_rootP
; /* -> last symbol chain link. */
214 while ((symbolP
= *symbolPP
) != NULL
)
216 if (flag_readonly_data_in_text
&& (S_GET_SEGMENT (symbolP
) == SEG_DATA
))
218 S_SET_SEGMENT (symbolP
, SEG_TEXT
);
221 resolve_symbol_value (symbolP
);
223 /* Skip symbols which were equated to undefined or common
225 if (symbolP
->sy_value
.X_op
== O_symbol
226 && (! S_IS_DEFINED (symbolP
) || S_IS_COMMON (symbolP
)))
228 *symbolPP
= symbol_next (symbolP
);
232 /* OK, here is how we decide which symbols go out into the
233 brave new symtab. Symbols that do are:
235 * symbols with no name (stabd's?)
236 * symbols with debug info in their N_TYPE
238 Symbols that don't are:
239 * symbols that are registers
240 * symbols with \1 as their 3rd character (numeric labels)
241 * "local labels" as defined by S_LOCAL_NAME(name)
242 if the -L switch was passed to gas.
244 All other symbols are output. We complain if a deleted
245 symbol was marked external. */
248 && !S_IS_REGISTER (symbolP
)
249 && (!S_GET_NAME (symbolP
)
250 || S_IS_DEBUG (symbolP
)
252 /* FIXME-SOON this ifdef seems highly dubious to me. xoxorich. */
253 || !S_IS_DEFINED (symbolP
)
254 || S_IS_EXTERNAL (symbolP
)
256 || (S_GET_NAME (symbolP
)[0] != '\001'
257 && (flag_keep_locals
|| !S_LOCAL_NAME (symbolP
)))))
259 symbolP
->sy_number
= symbol_number
++;
261 /* The + 1 after strlen account for the \0 at the end of
263 if (!S_IS_STABD (symbolP
))
266 symbolP
->sy_name_offset
= string_byte_count
;
267 string_byte_count
+= strlen (S_GET_NAME (symbolP
)) + 1;
269 else /* .Stabd case. */
270 symbolP
->sy_name_offset
= 0;
271 symbolPP
= &(symbolP
->sy_next
);
275 if (S_IS_EXTERNAL (symbolP
) || !S_IS_DEFINED (symbolP
))
276 as_bad (_("Local symbol %s never defined"),
277 S_GET_NAME (symbolP
));
279 /* Unhook it from the chain. */
280 *symbolPP
= symbol_next (symbolP
);
284 H_SET_SYMBOL_TABLE_SIZE (headers
, symbol_number
);
287 /* Find strings by crawling along symbol table chain. */
290 obj_emit_strings (char **where
)
294 md_number_to_chars (*where
, string_byte_count
, 4);
297 for (symbolP
= symbol_rootP
; symbolP
; symbolP
= symbol_next (symbolP
))
298 if (S_GET_NAME (symbolP
))
299 append (where
, S_GET_NAME (symbolP
),
300 (unsigned long) (strlen (S_GET_NAME (symbolP
)) + 1));
303 const pseudo_typeS obj_pseudo_table
[] =
305 {"line", obj_bout_line
, 0}, /* Source code line number. */
307 /* COFF debugging directives. Currently ignored silently. */
308 {"def", s_ignore
, 0},
309 {"dim", s_ignore
, 0},
310 {"endef", s_ignore
, 0},
312 {"scl", s_ignore
, 0},
313 {"size", s_ignore
, 0},
314 {"tag", s_ignore
, 0},
315 {"type", s_ignore
, 0},
316 {"val", s_ignore
, 0},
318 /* Other stuff we don't handle. */
319 {"ABORT", s_ignore
, 0},
320 {"ident", s_ignore
, 0},