Take care of relocs when defining external defs.

For most of the cases, some relocs may have been lost, but they were
certainly lost for type encodings. Now that all seems to be fixed.
This commit is contained in:
Bill Currie 2012-11-12 16:14:09 +09:00
parent eb5581c7bd
commit 93b007b1f8
6 changed files with 24 additions and 5 deletions

View file

@ -239,6 +239,8 @@ void reloc_def_field_ofs (struct def_s *def, struct def_s *location);
*/
void reloc_def_op (struct ex_label_s *label, struct def_s *location);
void reloc_attach_relocs (reloc_t *relocs, reloc_t **location);
///@}
#endif//__reloc_h

View file

@ -391,7 +391,7 @@ init_field_def (def_t *def, expr_t *init, storage_class_t storage)
}
if (!field_sym->s.def) {
field_sym->s.def = new_def (def->name, type, pr.entity_data, storage);
field_sym->s.def->relocs = relocs;
reloc_attach_relocs (relocs, &field_sym->s.def->relocs);
field_sym->s.def->nosave = 1;
}
field_def = field_sym->s.def;
@ -470,7 +470,7 @@ initialize_def (symbol_t *sym, type_t *type, expr_t *init, defspace_t *space,
}
if (!sym->s.def) {
sym->s.def = new_def (sym->name, type, space, storage);
sym->s.def->relocs = relocs;
reloc_attach_relocs (relocs, &sym->s.def->relocs);
}
if (type == &type_vector && options.code.vector_components)
init_vector_components (sym, 0);

View file

@ -513,7 +513,7 @@ make_function (symbol_t *sym, const char *nice_name, defspace_t *space,
}
if (!sym->s.func->def) {
sym->s.func->def = new_def (sym->name, sym->type, space, storage);
sym->s.func->def->relocs = relocs;
reloc_attach_relocs (relocs, &sym->s.func->def->relocs);
}
}

View file

@ -255,6 +255,8 @@ qfo_encode_class (type_t *type)
def_t *
qfo_encode_type (type_t *type)
{
reloc_t *relocs = 0;
static encode_f funcs[] = {
qfo_encode_none, // ty_none
qfo_encode_struct, // ty_struct
@ -265,7 +267,7 @@ qfo_encode_type (type_t *type)
};
if (type->type_def && type->type_def->external) {
//FIXME relocs
relocs = type->type_def->relocs;
free_def (type->type_def);
type->type_def = 0;
}
@ -276,5 +278,6 @@ qfo_encode_type (type_t *type)
if (!type->encoding)
type->encoding = type_get_encoding (type);
type->type_def = funcs[type->meta] (type);
reloc_attach_relocs (relocs, &type->type_def->relocs);
return type->type_def;
}

View file

@ -282,3 +282,16 @@ reloc_def_op (ex_label_t *label, def_t *location)
ref->label = label;
pr.relocs = ref;
}
void
reloc_attach_relocs (reloc_t *relocs, reloc_t **location)
{
reloc_t *r;
if (!relocs)
return;
for (r = relocs; r->next; r = r->next)
;
r->next = *location;
*location = relocs;
}

View file

@ -42,6 +42,7 @@
#include "diagnostic.h"
#include "function.h"
#include "qfcc.h"
#include "reloc.h"
#include "strpool.h"
#include "symtab.h"
#include "type.h"
@ -213,7 +214,7 @@ make_symbol (const char *name, type_t *type, defspace_t *space,
}
if (!sym->s.def) {
sym->s.def = new_def (name, type, space, storage);
sym->s.def->relocs = relocs;
reloc_attach_relocs (relocs, &sym->s.def->relocs);
}
return sym;
}