From 4a680bf98168b4863fdd24c64edfbce780bf935a Mon Sep 17 00:00:00 2001 From: Bill Currie Date: Wed, 6 Aug 2003 21:36:07 +0000 Subject: [PATCH] grovel around for the source file and line of an undefined def to give better diagnostics --- tools/qfcc/source/linker.c | 42 +++++++++++++++++++++++++++++++++++++- 1 file changed, 41 insertions(+), 1 deletion(-) diff --git a/tools/qfcc/source/linker.c b/tools/qfcc/source/linker.c index 4cd2ce2e5..de361ae9f 100644 --- a/tools/qfcc/source/linker.c +++ b/tools/qfcc/source/linker.c @@ -798,6 +798,46 @@ linker_add_lib (const char *libname) return 0; } +static void +undefined_def (qfo_def_t *def) +{ + qfo_def_t line_def; + int i; + qfo_reloc_t *reloc = relocs.relocs + def->relocs; + + for (i = 0; i < def->num_relocs; i++, reloc++) { + if (reloc->type == rel_op_a_def || reloc->type == rel_op_b_def + || reloc->type == rel_op_c_def) { + qfo_func_t *func = funcs.funcs; + qfo_func_t *best = func; + int best_dist = reloc->ofs - func->code; + pr_lineno_t *line; + + while (best_dist && func - funcs.funcs < funcs.num_funcs) { + if (func->code <= reloc->ofs) { + if (best_dist < 0 || reloc->ofs - func->code < best_dist) { + best = func; + best_dist = reloc->ofs - func->code; + } + } + func++; + } + line = lines.lines + best->line_info; + line_def.file = best->file; + line_def.line = best->line; + if (!line->line && line->fa.func == best - funcs.funcs) { + while (line - lines.lines < lines.num_lines - 1 && line[1].line + && line[1].fa.addr <= reloc->ofs) + line++; + line_def.line = line->line + best->line; + } + def_error (&line_def, "undefined symbol %s", STRING (def->name)); + } else { + def_error (def, "undefined symbol %s", STRING (def->name)); + } + } +} + qfo_t * linker_finish (void) { @@ -833,7 +873,7 @@ linker_finish (void) undef_defs = (defref_t **) Hash_GetList (extern_defs); for (defref = undef_defs; *defref; defref++) { qfo_def_t *def = deref_def (*defref, &global_defs); - def_error (def, "undefined symbol %s", STRING (def->name)); + undefined_def (def); } free (undef_defs); if (pr.error_count)