#define OBJ_HEADER "obj-aout.h"
#include "as.h"
#ifdef BFD_ASSEMBLER
#undef NO_RELOC
#include "aout/aout64.h"
#endif
#include "obstack.h"
#ifndef BFD_ASSEMBLER
const short seg_N_TYPE[] =
{
N_ABS,
N_TEXT,
N_DATA,
N_BSS,
N_UNDF,
N_UNDF,
N_UNDF,
N_UNDF,
N_UNDF,
N_UNDF,
N_REGISTER,
};
const segT N_TYPE_seg[N_TYPE + 2] =
{
SEG_UNKNOWN,
SEG_GOOF,
SEG_ABSOLUTE,
SEG_GOOF,
SEG_TEXT,
SEG_GOOF,
SEG_DATA,
SEG_GOOF,
SEG_BSS,
SEG_GOOF,
SEG_GOOF, SEG_GOOF, SEG_GOOF, SEG_GOOF, SEG_GOOF, SEG_GOOF, SEG_GOOF, SEG_GOOF,
SEG_GOOF, SEG_GOOF, SEG_GOOF, SEG_GOOF, SEG_GOOF, SEG_GOOF, SEG_GOOF, SEG_GOOF,
SEG_GOOF, SEG_GOOF, SEG_GOOF, SEG_GOOF,
SEG_REGISTER,
SEG_GOOF,
};
#endif
static void obj_aout_line PARAMS ((int));
static void obj_aout_weak PARAMS ((int));
static void obj_aout_type PARAMS ((int));
const pseudo_typeS aout_pseudo_table[] =
{
{"line", obj_aout_line, 0},
{"ln", obj_aout_line, 0},
{"weak", obj_aout_weak, 0},
{"type", obj_aout_type, 0},
{"def", s_ignore, 0},
{"dim", s_ignore, 0},
{"endef", s_ignore, 0},
{"ident", s_ignore, 0},
{"line", s_ignore, 0},
{"ln", s_ignore, 0},
{"scl", s_ignore, 0},
{"size", s_ignore, 0},
{"tag", s_ignore, 0},
{"val", s_ignore, 0},
{"version", s_ignore, 0},
{"optim", s_ignore, 0},
{"ABORT", s_abort, 0},
{NULL, NULL, 0}
};
#ifdef BFD_ASSEMBLER
void
obj_aout_frob_symbol (sym, punt)
symbolS *sym;
int *punt ATTRIBUTE_UNUSED;
{
flagword flags;
asection *sec;
int desc, type, other;
flags = symbol_get_bfdsym (sym)->flags;
desc = aout_symbol (symbol_get_bfdsym (sym))->desc;
type = aout_symbol (symbol_get_bfdsym (sym))->type;
other = aout_symbol (symbol_get_bfdsym (sym))->other;
sec = S_GET_SEGMENT (sym);
if (! (type & ~ (N_TYPE | N_EXT)))
{
if (type == (N_UNDF | N_EXT)
&& sec == &bfd_abs_section)
{
sec = bfd_und_section_ptr;
S_SET_SEGMENT (sym, sec);
}
if ((type & N_TYPE) != N_INDR
&& (type & N_TYPE) != N_SETA
&& (type & N_TYPE) != N_SETT
&& (type & N_TYPE) != N_SETD
&& (type & N_TYPE) != N_SETB
&& type != N_WARNING
&& (sec == &bfd_abs_section
|| sec == &bfd_und_section))
return;
if (flags & BSF_EXPORT)
type |= N_EXT;
switch (type & N_TYPE)
{
case N_SETA:
case N_SETT:
case N_SETD:
case N_SETB:
symbol_get_bfdsym (sym)->flags |= BSF_DEBUGGING;
if (S_IS_COMMON (sym))
as_bad (_("Attempt to put a common symbol into set %s"),
S_GET_NAME (sym));
else if (! S_IS_DEFINED (sym))
as_bad (_("Attempt to put an undefined symbol into set %s"),
S_GET_NAME (sym));
break;
case N_INDR:
S_SET_SEGMENT (sym, bfd_ind_section_ptr);
symbol_get_bfdsym (sym)->flags |= BSF_INDIRECT;
if (type & N_EXT)
{
symbol_get_bfdsym (sym)->flags |= BSF_EXPORT;
symbol_get_bfdsym (sym)->flags &=~ BSF_LOCAL;
}
break;
case N_WARNING:
symbol_get_bfdsym (sym)->flags |= BSF_WARNING;
break;
}
}
else
{
symbol_get_bfdsym (sym)->flags |= BSF_DEBUGGING;
}
aout_symbol (symbol_get_bfdsym (sym))->type = type;
if (S_IS_WEAK (sym))
{
if (S_IS_COMMON (sym))
as_bad (_("Symbol `%s' can not be both weak and common"),
S_GET_NAME (sym));
}
}
void
obj_aout_frob_file_before_fix ()
{
bfd_byte b = 0;
bfd_boolean x = TRUE;
if (bfd_section_size (stdoutput, text_section) != 0)
{
x = bfd_set_section_contents (stdoutput, text_section, &b, (file_ptr) 0,
(bfd_size_type) 1);
}
else if (bfd_section_size (stdoutput, data_section) != 0)
{
x = bfd_set_section_contents (stdoutput, data_section, &b, (file_ptr) 0,
(bfd_size_type) 1);
}
assert (x);
}
#else
void
obj_emit_relocations (where, fixP, segment_address_in_file)
char **where;
fixS *fixP;
relax_addressT segment_address_in_file;
{
for (; fixP; fixP = fixP->fx_next)
if (fixP->fx_done == 0)
{
symbolS *sym;
sym = fixP->fx_addsy;
while (sym->sy_value.X_op == O_symbol
&& (! S_IS_DEFINED (sym) || S_IS_COMMON (sym)))
sym = sym->sy_value.X_add_symbol;
fixP->fx_addsy = sym;
if (! sym->sy_resolved && ! S_IS_DEFINED (sym))
{
char *file;
unsigned int line;
if (expr_symbol_where (sym, &file, &line))
as_bad_where (file, line, _("unresolved relocation"));
else
as_bad (_("bad relocation: symbol `%s' not in symbol table"),
S_GET_NAME (sym));
}
tc_aout_fix_to_chars (*where, fixP, segment_address_in_file);
*where += md_reloc_size;
}
}
#ifndef obj_header_append
void
obj_header_append (where, headers)
char **where;
object_headers *headers;
{
char *p;
tc_headers_hook (headers);
#ifdef __A_OUT_GNU_H__
#define SIZEOF_HEADER(PIECE) (sizeof (((struct exec_bytes *) 0)->PIECE))
#else
#define SIZEOF_HEADER(PIECE) 4
#endif
#define DO(PIECE) \
md_number_to_chars (p, headers->header.PIECE, SIZEOF_HEADER (PIECE)); \
p += SIZEOF_HEADER (PIECE);
p = *where;
DO (a_info);
DO (a_text);
DO (a_data);
DO (a_bss);
DO (a_syms);
DO (a_entry);
DO (a_trsize);
DO (a_drsize);
*where = p;
#undef DO
#undef SIZEOF_HEADER
}
#endif
void
obj_symbol_to_chars (where, symbolP)
char **where;
symbolS *symbolP;
{
char *p = *where;
md_number_to_chars (p, S_GET_OFFSET (symbolP), 4);
p += 4;
*p++ = symbolP->sy_symbol.n_type;
*p++ = symbolP->sy_symbol.n_other;
md_number_to_chars (p, S_GET_DESC (symbolP), 2);
p += 2;
md_number_to_chars (p, S_GET_VALUE (symbolP), 4);
p += 4;
*where = p;
}
void
obj_emit_symbols (where, symbol_rootP)
char **where;
symbolS *symbol_rootP;
{
symbolS *symbolP;
for (symbolP = symbol_rootP; symbolP; symbolP = symbol_next (symbolP))
{
register char *temp;
temp = S_GET_NAME (symbolP);
S_SET_OFFSET (symbolP, symbolP->sy_name_offset);
if (!S_IS_DEBUG (symbolP) && !S_IS_DEFINED (symbolP))
S_SET_EXTERNAL (symbolP);
if (S_GET_WEAK (symbolP))
{
switch (S_GET_TYPE (symbolP))
{
case N_UNDF: S_SET_TYPE (symbolP, N_WEAKU); break;
case N_ABS: S_SET_TYPE (symbolP, N_WEAKA); break;
case N_TEXT: S_SET_TYPE (symbolP, N_WEAKT); break;
case N_DATA: S_SET_TYPE (symbolP, N_WEAKD); break;
case N_BSS: S_SET_TYPE (symbolP, N_WEAKB); break;
default: as_bad (_("%s: bad type for weak symbol"), temp); break;
}
}
obj_symbol_to_chars (where, symbolP);
S_SET_NAME (symbolP, temp);
}
}
#endif
static void
obj_aout_line (ignore)
int ignore ATTRIBUTE_UNUSED;
{
new_logical_line ((char *) NULL, (int) (get_absolute_expression ()));
demand_empty_rest_of_line ();
}
static void
obj_aout_weak (ignore)
int ignore ATTRIBUTE_UNUSED;
{
char *name;
int c;
symbolS *symbolP;
do
{
name = input_line_pointer;
c = get_symbol_end ();
symbolP = symbol_find_or_make (name);
*input_line_pointer = c;
SKIP_WHITESPACE ();
S_SET_WEAK (symbolP);
if (c == ',')
{
input_line_pointer++;
SKIP_WHITESPACE ();
if (*input_line_pointer == '\n')
c = '\n';
}
}
while (c == ',');
demand_empty_rest_of_line ();
}
static void
obj_aout_type (ignore)
int ignore ATTRIBUTE_UNUSED;
{
char *name;
int c;
symbolS *sym;
name = input_line_pointer;
c = get_symbol_end ();
sym = symbol_find_or_make (name);
*input_line_pointer = c;
SKIP_WHITESPACE ();
if (*input_line_pointer == ',')
{
++input_line_pointer;
SKIP_WHITESPACE ();
if (*input_line_pointer == '@')
{
++input_line_pointer;
if (strncmp (input_line_pointer, "object", 6) == 0)
S_SET_OTHER (sym, 1);
else if (strncmp (input_line_pointer, "function", 8) == 0)
S_SET_OTHER (sym, 2);
}
}
s_ignore (0);
}
#ifndef BFD_ASSEMBLER
void
obj_crawl_symbol_chain (headers)
object_headers *headers;
{
symbolS *symbolP;
symbolS **symbolPP;
int symbol_number = 0;
tc_crawl_symbol_chain (headers);
symbolPP = &symbol_rootP;
while ((symbolP = *symbolPP) != NULL)
{
if (symbolP->sy_mri_common)
{
if (S_IS_EXTERNAL (symbolP))
as_bad (_("%s: global symbols not supported in common sections"),
S_GET_NAME (symbolP));
*symbolPP = symbol_next (symbolP);
continue;
}
if (flag_readonly_data_in_text && (S_GET_SEGMENT (symbolP) == SEG_DATA))
{
S_SET_SEGMENT (symbolP, SEG_TEXT);
}
resolve_symbol_value (symbolP);
if (symbolP->sy_value.X_op == O_symbol
&& (! S_IS_DEFINED (symbolP)
|| S_IS_COMMON (symbolP)
|| symbol_resolved_p (symbolP)))
{
*symbolPP = symbol_next (symbolP);
continue;
}
if (!S_IS_REGISTER (symbolP)
&& (!S_GET_NAME (symbolP)
|| S_IS_DEBUG (symbolP)
|| !S_IS_DEFINED (symbolP)
|| S_IS_EXTERNAL (symbolP)
|| (S_GET_NAME (symbolP)[0] != '\001'
&& (flag_keep_locals || !S_LOCAL_NAME (symbolP)))))
{
symbolP->sy_number = symbol_number++;
if (!S_IS_STABD (symbolP))
{
symbolP->sy_name_offset = string_byte_count;
string_byte_count += strlen (S_GET_NAME (symbolP)) + 1;
}
else
symbolP->sy_name_offset = 0;
symbolPP = &symbolP->sy_next;
}
else
{
if (S_IS_EXTERNAL (symbolP) || !S_IS_DEFINED (symbolP))
{
as_bad (_("Local symbol %s never defined."), decode_local_label_name (S_GET_NAME (symbolP)));
}
*symbolPP = symbol_next (symbolP);
}
}
H_SET_SYMBOL_TABLE_SIZE (headers, symbol_number);
}
void
obj_emit_strings (where)
char **where;
{
symbolS *symbolP;
md_number_to_chars (*where, string_byte_count, 4);
*where += 4;
for (symbolP = symbol_rootP; symbolP; symbolP = symbol_next (symbolP))
{
if (S_GET_NAME (symbolP))
append (where, S_GET_NAME (symbolP),
(unsigned long) (strlen (S_GET_NAME (symbolP)) + 1));
}
}
#ifndef AOUT_VERSION
#define AOUT_VERSION 0
#endif
void
obj_pre_write_hook (headers)
object_headers *headers;
{
H_SET_DYNAMIC (headers, 0);
H_SET_VERSION (headers, AOUT_VERSION);
H_SET_MACHTYPE (headers, AOUT_MACHTYPE);
tc_aout_pre_write_hook (headers);
}
#endif
#ifdef BFD_ASSEMBLER
static void aout_pop_insert PARAMS ((void));
static int obj_aout_s_get_other PARAMS ((symbolS *));
static void obj_aout_s_set_other PARAMS ((symbolS *, int));
static int obj_aout_s_get_desc PARAMS ((symbolS *));
static void obj_aout_s_set_desc PARAMS ((symbolS *, int));
static int obj_aout_s_get_type PARAMS ((symbolS *));
static void obj_aout_s_set_type PARAMS ((symbolS *, int));
static int obj_aout_separate_stab_sections PARAMS ((void));
static int obj_aout_sec_sym_ok_for_reloc PARAMS ((asection *));
static void obj_aout_process_stab PARAMS ((segT, int, const char *, int, int, int));
static void
aout_pop_insert ()
{
pop_insert (aout_pseudo_table);
}
static int
obj_aout_s_get_other (sym)
symbolS *sym;
{
return aout_symbol (symbol_get_bfdsym (sym))->other;
}
static void
obj_aout_s_set_other (sym, o)
symbolS *sym;
int o;
{
aout_symbol (symbol_get_bfdsym (sym))->other = o;
}
static int
obj_aout_sec_sym_ok_for_reloc (sec)
asection *sec ATTRIBUTE_UNUSED;
{
return obj_sec_sym_ok_for_reloc (sec);
}
static void
obj_aout_process_stab (seg, w, s, t, o, d)
segT seg ATTRIBUTE_UNUSED;
int w;
const char *s;
int t;
int o;
int d;
{
aout_process_stab (w, s, t, o, d);
}
static int
obj_aout_s_get_desc (sym)
symbolS *sym;
{
return aout_symbol (symbol_get_bfdsym (sym))->desc;
}
static void
obj_aout_s_set_desc (sym, d)
symbolS *sym;
int d;
{
aout_symbol (symbol_get_bfdsym (sym))->desc = d;
}
static int
obj_aout_s_get_type (sym)
symbolS *sym;
{
return aout_symbol (symbol_get_bfdsym (sym))->type;
}
static void
obj_aout_s_set_type (sym, t)
symbolS *sym;
int t;
{
aout_symbol (symbol_get_bfdsym (sym))->type = t;
}
static int
obj_aout_separate_stab_sections ()
{
return 0;
}
const struct format_ops aout_format_ops =
{
bfd_target_aout_flavour,
1,
0,
0,
0,
obj_aout_frob_symbol,
0,
0,
obj_aout_frob_file_before_fix,
0,
0,
0,
0,
0,
obj_aout_s_get_other,
obj_aout_s_set_other,
obj_aout_s_get_desc,
obj_aout_s_set_desc,
obj_aout_s_get_type,
obj_aout_s_set_type,
0,
0,
obj_aout_process_stab,
obj_aout_separate_stab_sections,
0,
obj_aout_sec_sym_ok_for_reloc,
aout_pop_insert,
0,
0,
0
};
#endif