mirror of
https://git.code.sf.net/p/quake/quakeforge
synced 2025-03-21 18:01:15 +00:00
fix a bunch of silly bugs and get the linked output written (hangs, though)
This commit is contained in:
parent
4d1dbc8cc1
commit
a9899087d3
5 changed files with 57 additions and 30 deletions
|
@ -34,6 +34,6 @@
|
|||
|
||||
void linker_begin (void);
|
||||
void linker_add_object_file (const char *filename);
|
||||
void linker_finish (void);
|
||||
struct qfo_s *linker_finish (void);
|
||||
|
||||
#endif//__linker_h
|
||||
|
|
|
@ -126,7 +126,8 @@ defspace_adddata (defspace_t *space, pr_type_t *data, int size)
|
|||
space->max_size * sizeof (pr_type_t));
|
||||
}
|
||||
if (data)
|
||||
memcpy (space->data, data, space->max_size * sizeof (pr_type_t));
|
||||
memcpy (space->data + space->size, data, size * sizeof (pr_type_t));
|
||||
space->size += size;
|
||||
}
|
||||
|
||||
scope_t *
|
||||
|
|
|
@ -47,6 +47,7 @@ static const char rcsid[] =
|
|||
#include "emit.h"
|
||||
#include "expr.h"
|
||||
#include "immediate.h"
|
||||
#include "linker.h"
|
||||
#include "obj_file.h"
|
||||
#include "qfcc.h"
|
||||
#include "reloc.h"
|
||||
|
@ -93,7 +94,7 @@ defs_get_key (void *_def, void *unused)
|
|||
{
|
||||
qfo_def_t *def = (qfo_def_t *) _def;
|
||||
|
||||
return G_GETSTR (def->name);
|
||||
return strings->strings + def->name;
|
||||
}
|
||||
|
||||
static void
|
||||
|
@ -101,7 +102,7 @@ add_strings (qfo_t *qfo)
|
|||
{
|
||||
int i;
|
||||
|
||||
for (i = 0; i < qfo->strings_size; i += strlen (qfo->strings + i))
|
||||
for (i = 0; i < qfo->strings_size; i += strlen (qfo->strings + i) + 1)
|
||||
strpool_addstr (strings, qfo->strings + i);
|
||||
}
|
||||
|
||||
|
@ -171,29 +172,25 @@ add_defs (qfo_t *qfo)
|
|||
qfo_def_t *d;
|
||||
|
||||
if (def->flags & QFOD_GLOBAL) {
|
||||
if ((d = Hash_Find (defined_defs, G_GETSTR (def->name)))) {
|
||||
if ((d = Hash_Find (defined_defs,
|
||||
strings->strings + def->name))) {
|
||||
pr.source_file = def->file;
|
||||
pr.source_line = def->line;
|
||||
error (0, "%s redefined", G_GETSTR (def->name));
|
||||
error (0, "%s redefined", strings->strings + def->name);
|
||||
}
|
||||
}
|
||||
if (def->basic_type == ev_string && def->ofs
|
||||
&& QFO_var (qfo, string, def->ofs)) {
|
||||
string_t s;
|
||||
s = strpool_addstr (strings, QFO_STRING (qfo, def->ofs));
|
||||
QFO_var (qfo, string, def->ofs) = s;
|
||||
}
|
||||
if (def->ofs)
|
||||
def->ofs += data_base;
|
||||
if (def->flags & QFOD_GLOBAL) {
|
||||
while ((d = Hash_Find (extern_defs, G_GETSTR (def->name)))) {
|
||||
Hash_Del (extern_defs, G_GETSTR (d->name));
|
||||
while ((d = Hash_Find (extern_defs,
|
||||
strings->strings + def->name))) {
|
||||
Hash_Del (extern_defs, strings->strings + d->name);
|
||||
if (d->full_type != def->full_type) {
|
||||
pr.source_file = def->file;
|
||||
pr.source_line = def->line;
|
||||
error (0, "type mismatch %s %s",
|
||||
G_GETSTR (def->full_type),
|
||||
G_GETSTR (d->full_type));
|
||||
error (0, "type mismatch `%s' `%s'",
|
||||
type_strings->strings + def->full_type,
|
||||
type_strings->strings + d->full_type);
|
||||
}
|
||||
}
|
||||
Hash_Add (defined_defs, def);
|
||||
|
@ -339,6 +336,21 @@ linker_add_object_file (const char *filename)
|
|||
fixup_relocs (qfo);
|
||||
|
||||
qfo_delete (qfo);
|
||||
}
|
||||
|
||||
qfo_t *
|
||||
linker_finish (void)
|
||||
{
|
||||
qfo_def_t **undef_defs, **def;
|
||||
qfo_t *qfo;
|
||||
|
||||
undef_defs = (qfo_def_t **) Hash_GetList (extern_defs);
|
||||
for (def = undef_defs; *def; def++) {
|
||||
pr.source_file = (*def)->file;
|
||||
pr.source_line = (*def)->line;
|
||||
error (0, "undefined symbol %s", strings->strings + (*def)->name);
|
||||
return 0;
|
||||
}
|
||||
|
||||
qfo = qfo_new ();
|
||||
qfo_add_code (qfo, code->code, code->size);
|
||||
|
@ -348,17 +360,7 @@ linker_add_object_file (const char *filename)
|
|||
qfo_add_relocs (qfo, relocs.relocs, relocs.num_relocs);
|
||||
qfo_add_defs (qfo, defs.defs, defs.num_defs);
|
||||
qfo_add_functions (qfo, funcs.funcs, funcs.num_funcs);
|
||||
qfo_add_lines (qfo, lines.lines, lines.num_lines);
|
||||
qfo_add_types (qfo, type_strings->strings, type_strings->size);
|
||||
}
|
||||
|
||||
void
|
||||
linker_finish (void)
|
||||
{
|
||||
qfo_def_t **undef_defs, **def;
|
||||
undef_defs = (qfo_def_t **) Hash_GetList (extern_defs);
|
||||
for (def = undef_defs; *def; def++) {
|
||||
pr.source_file = (*def)->file;
|
||||
pr.source_line = (*def)->line;
|
||||
error (0, "undefined symbol %s", G_GETSTR ((*def)->name));
|
||||
}
|
||||
return qfo;
|
||||
}
|
||||
|
|
|
@ -525,6 +525,8 @@ qfo_new (void)
|
|||
void
|
||||
qfo_add_code (qfo_t *qfo, dstatement_t *code, int code_size)
|
||||
{
|
||||
if (!code_size)
|
||||
return;
|
||||
qfo->code = malloc (code_size * sizeof (dstatement_t));
|
||||
qfo->code_size = code_size;
|
||||
memcpy (qfo->code, code, code_size * sizeof (dstatement_t));
|
||||
|
@ -533,6 +535,8 @@ qfo_add_code (qfo_t *qfo, dstatement_t *code, int code_size)
|
|||
void
|
||||
qfo_add_data (qfo_t *qfo, pr_type_t *data, int data_size)
|
||||
{
|
||||
if (!data_size)
|
||||
return;
|
||||
qfo->data = malloc (data_size * sizeof (pr_type_t));
|
||||
qfo->data_size = data_size;
|
||||
memcpy (qfo->data, data, data_size * sizeof (pr_type_t));
|
||||
|
@ -541,6 +545,8 @@ qfo_add_data (qfo_t *qfo, pr_type_t *data, int data_size)
|
|||
void
|
||||
qfo_add_far_data (qfo_t *qfo, pr_type_t *far_data, int far_data_size)
|
||||
{
|
||||
if (!far_data_size)
|
||||
return;
|
||||
qfo->far_data = malloc (far_data_size * sizeof (pr_type_t));
|
||||
qfo->far_data_size = far_data_size;
|
||||
memcpy (qfo->far_data, far_data, far_data_size * sizeof (pr_type_t));
|
||||
|
@ -549,6 +555,8 @@ qfo_add_far_data (qfo_t *qfo, pr_type_t *far_data, int far_data_size)
|
|||
void
|
||||
qfo_add_strings (qfo_t *qfo, const char *strings, int strings_size)
|
||||
{
|
||||
if (!strings_size)
|
||||
return;
|
||||
qfo->strings = malloc (strings_size);
|
||||
qfo->strings_size = strings_size;
|
||||
memcpy (qfo->strings, strings, strings_size);
|
||||
|
@ -557,6 +565,8 @@ qfo_add_strings (qfo_t *qfo, const char *strings, int strings_size)
|
|||
void
|
||||
qfo_add_relocs (qfo_t *qfo, qfo_reloc_t *relocs, int num_relocs)
|
||||
{
|
||||
if (!num_relocs)
|
||||
return;
|
||||
qfo->relocs = malloc (num_relocs * sizeof (qfo_reloc_t));
|
||||
qfo->num_relocs = num_relocs;
|
||||
memcpy (qfo->relocs, relocs, num_relocs * sizeof (qfo_reloc_t));
|
||||
|
@ -565,6 +575,8 @@ qfo_add_relocs (qfo_t *qfo, qfo_reloc_t *relocs, int num_relocs)
|
|||
void
|
||||
qfo_add_defs (qfo_t *qfo, qfo_def_t *defs, int num_defs)
|
||||
{
|
||||
if (!num_defs)
|
||||
return;
|
||||
qfo->defs = malloc (num_defs * sizeof (qfo_def_t));
|
||||
qfo->num_defs = num_defs;
|
||||
memcpy (qfo->defs, defs, num_defs * sizeof (qfo_def_t));
|
||||
|
@ -573,6 +585,8 @@ qfo_add_defs (qfo_t *qfo, qfo_def_t *defs, int num_defs)
|
|||
void
|
||||
qfo_add_functions (qfo_t *qfo, qfo_function_t *functions, int num_functions)
|
||||
{
|
||||
if (!num_functions)
|
||||
return;
|
||||
qfo->functions = malloc (num_functions * sizeof (qfo_function_t));
|
||||
qfo->num_functions = num_functions;
|
||||
memcpy (qfo->functions, functions, num_functions * sizeof (qfo_function_t));
|
||||
|
@ -581,6 +595,8 @@ qfo_add_functions (qfo_t *qfo, qfo_function_t *functions, int num_functions)
|
|||
void
|
||||
qfo_add_lines (qfo_t *qfo, pr_lineno_t *lines, int num_lines)
|
||||
{
|
||||
if (!num_lines)
|
||||
return;
|
||||
qfo->lines = malloc (num_lines * sizeof (pr_lineno_t));
|
||||
qfo->num_lines = num_lines;
|
||||
memcpy (qfo->lines, lines, num_lines * sizeof (pr_lineno_t));
|
||||
|
@ -589,6 +605,8 @@ qfo_add_lines (qfo_t *qfo, pr_lineno_t *lines, int num_lines)
|
|||
void
|
||||
qfo_add_types (qfo_t *qfo, const char *types, int types_size)
|
||||
{
|
||||
if (!types_size)
|
||||
return;
|
||||
qfo->types = malloc (types_size);
|
||||
qfo->types_size = types_size;
|
||||
memcpy (qfo->types, types, types_size);
|
||||
|
|
|
@ -540,11 +540,17 @@ separate_compile (void)
|
|||
}
|
||||
}
|
||||
if (!err && !options.compile) {
|
||||
qfo_t *qfo;
|
||||
linker_begin ();
|
||||
for (file = source_files; *file; file++) {
|
||||
linker_add_object_file (*file);
|
||||
}
|
||||
linker_finish ();
|
||||
qfo = linker_finish ();
|
||||
if (qfo) {
|
||||
qfo_to_progs (qfo, &pr);
|
||||
finish_compilation ();
|
||||
WriteData (0);
|
||||
}
|
||||
}
|
||||
return err;
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue