From: nasm-bot f. H. P. A. <hp...@zy...> - 2009-07-20 01:12:33
|
Commit-ID: 9bd1506d5999d7c41a4cf6de2f43b97939bb260e Gitweb: http://repo.or.cz/w/nasm.git?a=commitdiff;h=9bd1506d5999d7c41a4cf6de2f43b97939bb260e Author: H. Peter Anvin <hp...@zy...> AuthorDate: Sat, 18 Jul 2009 21:07:17 -0400 Committer: H. Peter Anvin <hp...@zy...> CommitDate: Sat, 18 Jul 2009 18:43:12 -0700 Remove function pointers in output, simplify error handling Remove a bunch of function pointers in the output stage; they are never changed and don't add any value. Also make "ofile" a global variable and let the backend use it directly. All we ever did with these variables were stashing it in locals and using them as-is anyway for no benefit. Also change the global error function, nasm_error() into a true function which invokes a function pointer internally. That lets us use direct calls to it. Signed-off-by: H. Peter Anvin <hp...@zy...> --- nasm.c | 188 ++++++++++++++++++++++-------------------------- nasm.h | 48 +++++++------ nasmlib.c | 53 ++++++++------ nasmlib.h | 11 ++-- ndisasm.c | 8 +-- output/nulldbg.c | 12 ++-- output/outaout.c | 145 ++++++++++++++++++-------------------- output/outas86.c | 124 +++++++++++++++----------------- output/outbin.c | 159 +++++++++++++++++++---------------------- output/outcoff.c | 175 +++++++++++++++++++++------------------------ output/outdbg.c | 60 ++++++--------- output/outelf32.c | 195 ++++++++++++++++++++++++--------------------------- output/outelf64.c | 196 ++++++++++++++++++++++++--------------------------- output/outform.c | 55 ++++++-------- output/outform.h | 12 ++-- output/outieee.c | 67 +++++++---------- output/outlib.h | 2 +- output/outmacho32.c | 134 ++++++++++++++++------------------ output/outmacho64.c | 196 ++++++++++++++++++++++++--------------------------- output/outobj.c | 128 +++++++++++++++------------------ output/outrdf2.c | 70 ++++++++----------- raa.c | 3 +- saa.c | 31 ++------ 23 files changed, 958 insertions(+), 1114 deletions(-) diff --git a/nasm.c b/nasm.c index f413d35..7bcdc5a 100644 --- a/nasm.c +++ b/nasm.c @@ -70,14 +70,11 @@ static int get_bits(char *value); static uint32_t get_cpu(char *cpu_str); static void parse_cmdline(int, char **); static void assemble_file(char *, StrList **); -static void register_output_formats(void); -static void report_error_gnu(int severity, const char *fmt, ...); -static void report_error_vc(int severity, const char *fmt, ...); -static void report_error_common(int severity, const char *fmt, - va_list args); +static void nasm_verror_gnu(int severity, const char *fmt, va_list args); +static void nasm_verror_vc(int severity, const char *fmt, va_list args); +static void nasm_verror_common(int severity, const char *fmt, va_list args); static bool is_suppressed_warning(int severity); static void usage(void); -static efunc report_error; static int using_debug_info, opt_verbose_info; bool tasm_compatible_mode = false; @@ -85,7 +82,7 @@ int pass0, passn; int maxbits = 0; int globalrel = 0; -time_t official_compile_time; +static time_t official_compile_time; static char inname[FILENAME_MAX]; static char outname[FILENAME_MAX]; @@ -93,11 +90,12 @@ static char listname[FILENAME_MAX]; static char errname[FILENAME_MAX]; static int globallineno; /* for forward-reference tracking */ /* static int pass = 0; */ -static struct ofmt *ofmt = NULL; +struct ofmt *ofmt = &OF_DEFAULT; +const struct dfmt *dfmt; static FILE *error_file; /* Where to write error messages */ -static FILE *ofile = NULL; +FILE *ofile = NULL; int optimizing = -1; /* number of optimization passes to take */ static int sb, cmd_sb = 16; /* by default */ static uint32_t cmd_cpu = IF_PLEVEL; /* highest level by default */ @@ -277,7 +275,7 @@ static void emit_dependencies(StrList *list) if (depend_file && strcmp(depend_file, "-")) { deps = fopen(depend_file, "w"); if (!deps) { - report_error(ERR_NONFATAL|ERR_NOFILE|ERR_USAGE, + nasm_error(ERR_NONFATAL|ERR_NOFILE|ERR_USAGE, "unable to write dependency file `%s'", depend_file); return; } @@ -317,13 +315,13 @@ int main(int argc, char **argv) pass0 = 0; want_usage = terminate_after_phase = false; - report_error = report_error_gnu; + nasm_set_verror(nasm_verror_gnu); error_file = stderr; tolower_init(); - nasm_set_malloc_error(report_error); + nasm_init_malloc_error(); offsets = raa_init(); forwrefs = saa_init((int32_t)sizeof(struct forwrefinfo)); @@ -332,8 +330,6 @@ int main(int argc, char **argv) seg_init(); - register_output_formats(); - /* Define some macros dependent on the runtime, but not on the command line. */ define_macros_early(); @@ -371,10 +367,10 @@ int main(int argc, char **argv) if (depend_missing_ok) pp_include_path(NULL); /* "assume generated" */ - preproc->reset(inname, 0, report_error, evaluate, &nasmlist, + preproc->reset(inname, 0, nasm_error, evaluate, &nasmlist, depend_ptr); if (outname[0] == '\0') - ofmt->filename(inname, outname, report_error); + ofmt->filename(inname, outname); ofile = NULL; while ((line = preproc->getline())) nasm_free(line); @@ -392,7 +388,7 @@ int main(int argc, char **argv) if (*outname) { ofile = fopen(outname, "w"); if (!ofile) - report_error(ERR_FATAL | ERR_NOFILE, + nasm_error(ERR_FATAL | ERR_NOFILE, "unable to open output file `%s'", outname); } else @@ -401,7 +397,7 @@ int main(int argc, char **argv) location.known = false; /* pass = 1; */ - preproc->reset(inname, 3, report_error, evaluate, &nasmlist, + preproc->reset(inname, 3, nasm_error, evaluate, &nasmlist, depend_ptr); while ((line = preproc->getline())) { @@ -443,11 +439,11 @@ int main(int argc, char **argv) * the name of the input file and then put that inside the * file. */ - ofmt->filename(inname, outname, report_error); + ofmt->filename(inname, outname); ofile = fopen(outname, (ofmt->flags & OFMT_TEXT) ? "w" : "wb"); if (!ofile) { - report_error(ERR_FATAL | ERR_NOFILE, + nasm_error(ERR_FATAL | ERR_NOFILE, "unable to open output file `%s'", outname); } @@ -458,8 +454,9 @@ int main(int argc, char **argv) */ init_labels(); - ofmt->init(ofile, report_error, define_label, evaluate); - ofmt->current_dfmt->init(ofmt, NULL, ofile, report_error); + ofmt->init(); + dfmt = ofmt->current_dfmt; + dfmt->init(); assemble_file(inname, depend_ptr); @@ -468,7 +465,7 @@ int main(int argc, char **argv) cleanup_labels(); fflush(ofile); if (ferror(ofile)) { - report_error(ERR_NONFATAL|ERR_NOFILE, + nasm_error(ERR_NONFATAL|ERR_NOFILE, "write error on output file `%s'", outname); } } @@ -514,7 +511,7 @@ static char *get_param(char *p, char *q, bool *advance) *advance = true; return q; } - report_error(ERR_NONFATAL | ERR_NOFILE | ERR_USAGE, + nasm_error(ERR_NONFATAL | ERR_NOFILE | ERR_USAGE, "option `-%c' requires an argument", p[1]); return NULL; } @@ -527,7 +524,7 @@ static void copy_filename(char *dst, const char *src) size_t len = strlen(src); if (len >= (size_t)FILENAME_MAX) { - report_error(ERR_FATAL | ERR_NOFILE, "file name too long"); + nasm_error(ERR_FATAL | ERR_NOFILE, "file name too long"); return; } strncpy(dst, src, FILENAME_MAX); @@ -658,7 +655,7 @@ static bool process_arg(char *p, char *q) case 'f': /* output format */ ofmt = ofmt_find(param); if (!ofmt) { - report_error(ERR_FATAL | ERR_NOFILE | ERR_USAGE, + nasm_error(ERR_FATAL | ERR_NOFILE | ERR_USAGE, "unrecognised output format `%s' - " "use -hf for a list", param); } @@ -698,7 +695,7 @@ static bool process_arg(char *p, char *q) break; default: - report_error(ERR_FATAL, + nasm_error(ERR_FATAL, "unknown optimization option -O%c\n", *param); break; @@ -739,7 +736,7 @@ static bool process_arg(char *p, char *q) case 'F': /* specify debug format */ ofmt->current_dfmt = dfmt_find(ofmt, param); if (!ofmt->current_dfmt) { - report_error(ERR_FATAL | ERR_NOFILE | ERR_USAGE, + nasm_error(ERR_FATAL | ERR_NOFILE | ERR_USAGE, "unrecognized debug format `%s' for" " output format `%s'", param, ofmt->shortname); @@ -749,11 +746,11 @@ static bool process_arg(char *p, char *q) case 'X': /* specify error reporting format */ if (nasm_stricmp("vc", param) == 0) - report_error = report_error_vc; + nasm_set_verror(nasm_verror_vc); else if (nasm_stricmp("gnu", param) == 0) - report_error = report_error_gnu; + nasm_set_verror(nasm_verror_gnu); else - report_error(ERR_FATAL | ERR_NOFILE | ERR_USAGE, + nasm_error(ERR_FATAL | ERR_NOFILE | ERR_USAGE, "unrecognized error reporting format `%s'", param); break; @@ -843,7 +840,7 @@ static bool process_arg(char *p, char *q) case 'w': if (param[0] != '+' && param[0] != '-') { - report_error(ERR_NONFATAL | ERR_NOFILE | ERR_USAGE, + nasm_error(ERR_NONFATAL | ERR_NOFILE | ERR_USAGE, "invalid option to `-w'"); break; } @@ -863,7 +860,7 @@ static bool process_arg(char *p, char *q) for (i = 1; i <= ERR_WARN_MAX; i++) warning_on_global[i] = !do_warn; else - report_error(ERR_NONFATAL | ERR_NOFILE | ERR_USAGE, + nasm_error(ERR_NONFATAL | ERR_NOFILE | ERR_USAGE, "invalid warning `%s'", param); break; @@ -892,12 +889,12 @@ static bool process_arg(char *p, char *q) advance = true; break; default: - report_error(ERR_NONFATAL|ERR_NOFILE|ERR_USAGE, + nasm_error(ERR_NONFATAL|ERR_NOFILE|ERR_USAGE, "unknown dependency option `-M%c'", p[2]); break; } if (advance && (!q || !q[0])) { - report_error(ERR_NONFATAL|ERR_NOFILE|ERR_USAGE, + nasm_error(ERR_NONFATAL|ERR_NOFILE|ERR_USAGE, "option `-M%c' requires a parameter", p[2]); break; } @@ -923,7 +920,7 @@ static bool process_arg(char *p, char *q) case OPT_POSTFIX: { if (!q) { - report_error(ERR_NONFATAL | ERR_NOFILE | + nasm_error(ERR_NONFATAL | ERR_NOFILE | ERR_USAGE, "option `--%s' requires an argument", p + 2); @@ -946,7 +943,7 @@ static bool process_arg(char *p, char *q) } default: { - report_error(ERR_NONFATAL | ERR_NOFILE | ERR_USAGE, + nasm_error(ERR_NONFATAL | ERR_NOFILE | ERR_USAGE, "unrecognised option `--%s'", p + 2); break; } @@ -956,13 +953,13 @@ static bool process_arg(char *p, char *q) default: if (!ofmt->setinfo(GI_SWITCH, &p)) - report_error(ERR_NONFATAL | ERR_NOFILE | ERR_USAGE, + nasm_error(ERR_NONFATAL | ERR_NOFILE | ERR_USAGE, "unrecognised option `-%c'", p[1]); break; } } else { if (*inname) { - report_error(ERR_NONFATAL | ERR_NOFILE | ERR_USAGE, + nasm_error(ERR_NONFATAL | ERR_NOFILE | ERR_USAGE, "more than one input file specified"); } else { copy_filename(inname, p); @@ -1122,7 +1119,7 @@ static void parse_cmdline(int argc, char **argv) process_respfile(rfile); fclose(rfile); } else - report_error(ERR_NONFATAL | ERR_NOFILE | ERR_USAGE, + nasm_error(ERR_NONFATAL | ERR_NOFILE | ERR_USAGE, "unable to open response file `%s'", p); } } else @@ -1133,13 +1130,13 @@ static void parse_cmdline(int argc, char **argv) /* Look for basic command line typos. This definitely doesn't catch all errors, but it might help cases of fumbled fingers. */ if (!*inname) - report_error(ERR_NONFATAL | ERR_NOFILE | ERR_USAGE, + nasm_error(ERR_NONFATAL | ERR_NOFILE | ERR_USAGE, "no input file specified"); else if (!strcmp(inname, errname) || !strcmp(inname, outname) || !strcmp(inname, listname) || (depend_file && !strcmp(inname, depend_file))) - report_error(ERR_FATAL | ERR_NOFILE | ERR_USAGE, + nasm_error(ERR_FATAL | ERR_NOFILE | ERR_USAGE, "file `%s' is both input and output file", inname); @@ -1147,7 +1144,7 @@ static void parse_cmdline(int argc, char **argv) error_file = fopen(errname, "w"); if (!error_file) { error_file = stderr; /* Revert to default! */ - report_error(ERR_FATAL | ERR_NOFILE | ERR_USAGE, + nasm_error(ERR_FATAL | ERR_NOFILE | ERR_USAGE, "cannot open file `%s' for error messages", errname); } @@ -1169,7 +1166,7 @@ static void assemble_file(char *fname, StrList **depend_ptr) int pass_max; if (cmd_sb == 32 && cmd_cpu < IF_386) - report_error(ERR_FATAL, "command line: " + nasm_error(ERR_FATAL, "command line: " "32-bit segment size requires a higher cpu"); pass_max = prev_offset_changed = (INT_MAX >> 1) + 2; /* Almost unlimited */ @@ -1187,7 +1184,7 @@ static void assemble_file(char *fname, StrList **depend_ptr) cpu = cmd_cpu; if (pass0 == 2) { if (*listname) - nasmlist.init(listname, report_error); + nasmlist.init(listname, nasm_error); } in_abs_seg = false; global_offset_changed = 0; /* set by redefine_label */ @@ -1199,7 +1196,7 @@ static void assemble_file(char *fname, StrList **depend_ptr) raa_free(offsets); offsets = raa_init(); } - preproc->reset(fname, pass1, report_error, evaluate, &nasmlist, + preproc->reset(fname, pass1, nasm_error, evaluate, &nasmlist, pass1 == 2 ? depend_ptr : NULL); memcpy(warning_on, warning_on_global, (ERR_WARN_MAX+1) * sizeof(bool)); @@ -1226,7 +1223,7 @@ static void assemble_file(char *fname, StrList **depend_ptr) case D_SECTION: seg = ofmt->section(value, pass2, &sb); if (seg == NO_SEG) { - report_error(pass1 == 1 ? ERR_NONFATAL : ERR_PANIC, + nasm_error(pass1 == 1 ? ERR_NONFATAL : ERR_PANIC, "segment name `%s' not recognized", value); } else { @@ -1256,7 +1253,7 @@ static void assemble_file(char *fname, StrList **depend_ptr) q++; } if (!validid) { - report_error(ERR_NONFATAL, + nasm_error(ERR_NONFATAL, "identifier expected after EXTERN"); break; } @@ -1269,9 +1266,9 @@ static void assemble_file(char *fname, StrList **depend_ptr) int temp = pass0; pass0 = 1; /* fake pass 1 in labels.c */ declare_as_global(value, special, - report_error); + nasm_error); define_label(value, seg_alloc(), 0L, NULL, - false, true, ofmt, report_error); + false, true, ofmt, nasm_error); pass0 = temp; } } /* else pass0 == 1 */ @@ -1301,7 +1298,7 @@ static void assemble_file(char *fname, StrList **depend_ptr) q++; } if (!validid) { - report_error(ERR_NONFATAL, + nasm_error(ERR_NONFATAL, "identifier expected after GLOBAL"); break; } @@ -1310,7 +1307,7 @@ static void assemble_file(char *fname, StrList **depend_ptr) special = q; } else special = NULL; - declare_as_global(value, special, report_error); + declare_as_global(value, special, nasm_error); } /* pass == 1 */ break; case D_COMMON: /* [COMMON symbol size:special] */ @@ -1329,7 +1326,7 @@ static void assemble_file(char *fname, StrList **depend_ptr) p++; } if (!validid) { - report_error(ERR_NONFATAL, + nasm_error(ERR_NONFATAL, "identifier expected after COMMON"); break; } @@ -1347,13 +1344,13 @@ static void assemble_file(char *fname, StrList **depend_ptr) } size = readnum(p, &rn_error); if (rn_error) { - report_error(ERR_NONFATAL, + nasm_error(ERR_NONFATAL, "invalid size specified" " in COMMON declaration"); break; } } else { - report_error(ERR_NONFATAL, + nasm_error(ERR_NONFATAL, "no size specified in" " COMMON declaration"); break; @@ -1361,7 +1358,7 @@ static void assemble_file(char *fname, StrList **depend_ptr) if (pass0 < 2) { define_common(value, seg_alloc(), size, - special, ofmt, report_error); + special, ofmt, nasm_error); } else if (pass0 == 2) { if (special) ofmt->symdef(value, 0L, 0L, 3, special); @@ -1373,10 +1370,10 @@ static void assemble_file(char *fname, StrList **depend_ptr) stdscan_bufptr = value; tokval.t_type = TOKEN_INVALID; e = evaluate(stdscan, NULL, &tokval, NULL, pass2, - report_error, NULL); + nasm_error, NULL); if (e) { if (!is_reloc(e)) - report_error(pass0 == + nasm_error(pass0 == 1 ? ERR_NONFATAL : ERR_PANIC, "cannot use non-relocatable expression as " "ABSOLUTE address"); @@ -1387,7 +1384,7 @@ static void assemble_file(char *fname, StrList **depend_ptr) } else if (passn == 1) abs_offset = 0x100; /* don't go near zero in case of / */ else - report_error(ERR_PANIC, "invalid ABSOLUTE address " + nasm_error(ERR_PANIC, "invalid ABSOLUTE address " "in pass two"); in_abs_seg = true; location.segment = NO_SEG; @@ -1405,14 +1402,14 @@ static void assemble_file(char *fname, StrList **depend_ptr) } *q++ = 0; if (!validid) { - report_error(passn == 1 ? ERR_NONFATAL : ERR_PANIC, + nasm_error(passn == 1 ? ERR_NONFATAL : ERR_PANIC, "identifier expected after DEBUG"); break; } while (*p && nasm_isspace(*p)) p++; if (pass0 == 2) - ofmt->current_dfmt->debug_directive(debugid, p); + dfmt->debug_directive(debugid, p); break; case D_WARNING: /* [WARNING {+|-|*}warn-name] */ while (*value && nasm_isspace(*value)) @@ -1442,7 +1439,7 @@ static void assemble_file(char *fname, StrList **depend_ptr) } } else - report_error(ERR_NONFATAL, + nasm_error(ERR_NONFATAL, "invalid warning id in WARNING directive"); break; case D_CPU: /* [CPU] */ @@ -1484,27 +1481,27 @@ static void assemble_file(char *fname, StrList **depend_ptr) break; case D_FLOAT: if (float_option(value)) { - report_error(pass1 == 1 ? ERR_NONFATAL : ERR_PANIC, + nasm_error(pass1 == 1 ? ERR_NONFATAL : ERR_PANIC, "unknown 'float' directive: %s", value); } break; default: if (!d || !ofmt->directive(d, value, pass2)) - report_error(pass1 == 1 ? ERR_NONFATAL : ERR_PANIC, + nasm_error(pass1 == 1 ? ERR_NONFATAL : ERR_PANIC, "unrecognised directive [%s]", directive); break; } if (err) { - report_error(ERR_NONFATAL, + nasm_error(ERR_NONFATAL, "invalid parameter to [%s] directive", directive); } } else { /* it isn't a directive */ parse_line(pass1, line, &output_ins, - report_error, evaluate, def_label); + nasm_error, evaluate, def_label); if (optimizing > 0) { if (forwref != NULL && globallineno == forwref->lineno) { @@ -1543,7 +1540,7 @@ static void assemble_file(char *fname, StrList **depend_ptr) * in the normal place. */ if (!output_ins.label) - report_error(ERR_NONFATAL, + nasm_error(ERR_NONFATAL, "EQU not preceded by label"); else if (output_ins.label[0] != '.' || @@ -1558,7 +1555,7 @@ static void assemble_file(char *fname, StrList **depend_ptr) output_ins.oprs[0].segment, output_ins.oprs[0].offset, NULL, false, isext, ofmt, - report_error); + nasm_error); } else if (output_ins.operands == 2 && (output_ins.oprs[0].type & IMMEDIATE) && (output_ins.oprs[0].type & COLON) @@ -1571,9 +1568,9 @@ static void assemble_file(char *fname, StrList **depend_ptr) output_ins.oprs[0].offset | SEG_ABS, output_ins.oprs[1].offset, NULL, false, false, ofmt, - report_error); + nasm_error); } else - report_error(ERR_NONFATAL, + nasm_error(ERR_NONFATAL, "bad syntax for EQU"); } } else { @@ -1590,7 +1587,7 @@ static void assemble_file(char *fname, StrList **depend_ptr) output_ins.oprs[0].segment, output_ins.oprs[0].offset, NULL, false, false, ofmt, - report_error); + nasm_error); } else if (output_ins.operands == 2 && (output_ins.oprs[0]. type & IMMEDIATE) @@ -1606,9 +1603,9 @@ static void assemble_file(char *fname, StrList **depend_ptr) offset | SEG_ABS, output_ins.oprs[1].offset, NULL, false, false, ofmt, - report_error); + nasm_error); } else - report_error(ERR_NONFATAL, + nasm_error(ERR_NONFATAL, "bad syntax for EQU"); } } @@ -1617,7 +1614,7 @@ static void assemble_file(char *fname, StrList **depend_ptr) if (pass1 == 1) { int64_t l = insn_size(location.segment, offs, sb, cpu, - &output_ins, report_error); + &output_ins, nasm_error); /* if (using_debug_info) && output_ins.opcode != -1) */ if (using_debug_info) @@ -1690,8 +1687,7 @@ static void assemble_file(char *fname, StrList **depend_ptr) } - ofmt->current_dfmt->debug_typevalue(typeinfo); - + dfmt->debug_typevalue(typeinfo); } if (l != -1) { offs += l; @@ -1704,7 +1700,7 @@ static void assemble_file(char *fname, StrList **depend_ptr) } else { offs += assemble(location.segment, offs, sb, cpu, - &output_ins, ofmt, report_error, + &output_ins, ofmt, nasm_error, &nasmlist); SET_CURR_OFFS(offs); @@ -1717,7 +1713,7 @@ static void assemble_file(char *fname, StrList **depend_ptr) } /* end while (line = preproc->getline... */ if (pass0 == 2 && global_offset_changed && !terminate_after_phase) - report_error(ERR_NONFATAL, + nasm_error(ERR_NONFATAL, "phase error detected at end of assembly."); if (pass1 == 1) @@ -1740,10 +1736,10 @@ static void assemble_file(char *fname, StrList **depend_ptr) /* We get here if the labels don't converge * Example: FOO equ FOO + 1 */ - report_error(ERR_NONFATAL, + nasm_error(ERR_NONFATAL, "Can't find valid values for all labels " "after %d passes, giving up.", passn); - report_error(ERR_NONFATAL, + nasm_error(ERR_NONFATAL, "Possible causes: recursive EQUs, macro abuse."); break; } @@ -1820,9 +1816,8 @@ static enum directives getkw(char **directive, char **value) * @param severity the severity of the warning or error * @param fmt the printf style format string */ -static void report_error_gnu(int severity, const char *fmt, ...) +static void nasm_verror_gnu(int severity, const char *fmt, va_list ap) { - va_list ap; char *currentfile = NULL; int32_t lineno = 0; @@ -1839,9 +1834,7 @@ static void report_error_gnu(int severity, const char *fmt, ...) fputs("nasm: ", error_file); } - va_start(ap, fmt); - report_error_common(severity, fmt, ap); - va_end(ap); + nasm_verror_common(severity, fmt, ap); } /** @@ -1859,9 +1852,8 @@ static void report_error_gnu(int severity, const char *fmt, ...) * @param severity the severity of the warning or error * @param fmt the printf style format string */ -static void report_error_vc(int severity, const char *fmt, ...) +static void nasm_verror_vc(int severity, const char *fmt, va_list ap) { - va_list ap; char *currentfile = NULL; int32_t lineno = 0; @@ -1878,9 +1870,7 @@ static void report_error_vc(int severity, const char *fmt, ...) fputs("nasm: ", error_file); } - va_start(ap, fmt); - report_error_common(severity, fmt, ap); - va_end(ap); + nasm_verror_common(severity, fmt, ap); } /** @@ -1914,8 +1904,7 @@ static bool is_suppressed_warning(int severity) * @param severity the severity of the warning or error * @param fmt the printf style format string */ -static void report_error_common(int severity, const char *fmt, - va_list args) +static void nasm_verror_common(int severity, const char *fmt, va_list args) { char msg[1024]; const char *pfx; @@ -1985,11 +1974,6 @@ static void usage(void) fputs("type `nasm -h' for help\n", error_file); } -static void register_output_formats(void) -{ - ofmt = ofmt_register(report_error); -} - #define BUF_DELTA 512 static FILE *no_pp_fp; @@ -2119,7 +2103,7 @@ static uint32_t get_cpu(char *value) !nasm_stricmp(value, "itanic") || !nasm_stricmp(value, "merced")) return IF_IA64; - report_error(pass0 < 2 ? ERR_NONFATAL : ERR_FATAL, + nasm_error(pass0 < 2 ? ERR_NONFATAL : ERR_FATAL, "unknown 'cpu' type"); return IF_PLEVEL; /* the maximum level */ @@ -2133,24 +2117,24 @@ static int get_bits(char *value) return i; /* set for a 16-bit segment */ else if (i == 32) { if (cpu < IF_386) { - report_error(ERR_NONFATAL, + nasm_error(ERR_NONFATAL, "cannot specify 32-bit segment on processor below a 386"); i = 16; } } else if (i == 64) { if (cpu < IF_X86_64) { - report_error(ERR_NONFATAL, + nasm_error(ERR_NONFATAL, "cannot specify 64-bit segment on processor below an x86-64"); i = 16; } if (i != maxbits) { - report_error(ERR_NONFATAL, + nasm_error(ERR_NONFATAL, "%s output format does not support 64-bit code", ofmt->shortname); i = 16; } } else { - report_error(pass0 < 2 ? ERR_NONFATAL : ERR_FATAL, + nasm_error(pass0 < 2 ? ERR_NONFATAL : ERR_FATAL, "`%s' is not a valid segment size; must be 16, 32 or 64", value); i = 16; diff --git a/nasm.h b/nasm.h index faab7ef..341983a 100644 --- a/nasm.h +++ b/nasm.h @@ -122,9 +122,12 @@ typedef bool (*lfunc) (char *label, int32_t *segment, int64_t *offset); * should affect the local-label system), or something odder like * an EQU or a segment-base symbol, which shouldn't. */ -typedef void (*ldfunc) (char *label, int32_t segment, int64_t offset, - char *special, bool is_norm, bool isextrn, - struct ofmt * ofmt, efunc error); +typedef void (*ldfunc)(char *label, int32_t segment, int64_t offset, + char *special, bool is_norm, bool isextrn, + struct ofmt * ofmt, efunc error); +void define_label(char *label, int32_t segment, int64_t offset, + char *special, bool is_norm, bool isextrn, + struct ofmt * ofmt, efunc error); /* * List-file generators should look like this: @@ -786,7 +789,7 @@ struct ofmt { * an output format, be sure to set this to whatever default you want * */ - struct dfmt *current_dfmt; + const struct dfmt *current_dfmt; /* * This, if non-NULL, is a NULL-terminated list of `char *'s @@ -798,13 +801,10 @@ struct ofmt { macros_t *stdmac; /* - * This procedure is called at the start of an output session. - * It tells the output format what file it will be writing to, - * what routine to report errors through, and how to interface - * to the label manager and expression evaluator if necessary. - * It also gives it a chance to do other initialisation. + * This procedure is called at the start of an output session to set + * up internal parameters. */ - void (*init) (FILE * fp, efunc error, ldfunc ldef, evalfunc eval); + void (*init)(void); /* * This procedure is called to pass generic information to the @@ -924,7 +924,7 @@ struct ofmt { * The parameter `outname' points to an area of storage * guaranteed to be at least FILENAME_MAX in size. */ - void (*filename) (char *inname, char *outname, efunc error); + void (*filename) (char *inname, char *outname); /* * This procedure is called after assembly finishes, to allow @@ -938,6 +938,8 @@ struct ofmt { void (*cleanup) (int debuginfo); }; +extern struct ofmt *ofmt; +extern FILE *ofile; /* * ------------------------------------------------------------ @@ -959,17 +961,15 @@ struct dfmt { const char *shortname; /* - * init - called initially to set up local pointer to object format, - * void pointer to implementation defined data, file pointer (which - * probably won't be used, but who knows?), and error function. + * init - called initially to set up local pointer to object format. */ - void (*init) (struct ofmt * of, void *id, FILE * fp, efunc error); + void (*init)(void); /* * linenum - called any time there is output with a change of * line number or file. */ - void (*linenum) (const char *filename, int32_t linenumber, int32_t segto); + void (*linenum)(const char *filename, int32_t linenumber, int32_t segto); /* * debug_deflabel - called whenever a label is defined. Parameters @@ -977,8 +977,8 @@ struct dfmt { * would be called before the output format version. */ - void (*debug_deflabel) (char *name, int32_t segment, int64_t offset, - int is_global, char *special); + void (*debug_deflabel)(char *name, int32_t segment, int64_t offset, + int is_global, char *special); /* * debug_directive - called whenever a DEBUG directive other than 'LINE' * is encountered. 'directive' contains the first parameter to the @@ -987,27 +987,29 @@ struct dfmt { * function with 'directive' equal to "VAR" and 'params' equal to * "_somevar:int". */ - void (*debug_directive) (const char *directive, const char *params); + void (*debug_directive)(const char *directive, const char *params); /* * typevalue - called whenever the assembler wishes to register a type * for the last defined label. This routine MUST detect if a type was * already registered and not re-register it. */ - void (*debug_typevalue) (int32_t type); + void (*debug_typevalue)(int32_t type); /* * debug_output - called whenever output is required * 'type' is the type of info required, and this is format-specific */ - void (*debug_output) (int type, void *param); + void (*debug_output)(int type, void *param); /* * cleanup - called after processing of file is complete */ - void (*cleanup) (void); - + void (*cleanup)(void); }; + +extern const struct dfmt *dfmt; + /* * The type definition macros * for debugging diff --git a/nasmlib.c b/nasmlib.c index ae7abfb..35aa505 100644 --- a/nasmlib.c +++ b/nasmlib.c @@ -48,7 +48,7 @@ #include "insns.h" int globalbits = 0; /* defined in nasm.h, works better here for ASM+DISASM */ -efunc nasm_malloc_error; /* Exported for the benefit of vsnprintf.c */ +static vefunc nasm_verror; /* Global error handling function */ #ifdef LOGALLOC static FILE *logfp; @@ -72,9 +72,22 @@ void tolower_init(void) nasm_tolower_tab[i] = tolower(i); } -void nasm_set_malloc_error(efunc error) +void nasm_set_verror(vefunc ve) +{ + nasm_verror = ve; +} + +void nasm_error(int severity, const char *fmt, ...) +{ + va_list ap; + + va_start(ap, fmt); + nasm_verror(severity, fmt, ap); + va_end(ap); +} + +void nasm_init_malloc_error(void) { - nasm_malloc_error = error; #ifdef LOGALLOC logfp = fopen("malloc.log", "w"); setvbuf(logfp, NULL, _IOLBF, BUFSIZ); @@ -90,7 +103,7 @@ void *nasm_malloc(size_t size) { void *p = malloc(size); if (!p) - nasm_malloc_error(ERR_FATAL | ERR_NOFILE, "out of memory"); + nasm_error(ERR_FATAL | ERR_NOFILE, "out of memory"); #ifdef LOGALLOC else fprintf(logfp, "%s %d malloc(%ld) returns %p\n", @@ -107,7 +120,7 @@ void *nasm_zalloc(size_t size) { void *p = calloc(size, 1); if (!p) - nasm_malloc_error(ERR_FATAL | ERR_NOFILE, "out of memory"); + nasm_error(ERR_FATAL | ERR_NOFILE, "out of memory"); #ifdef LOGALLOC else fprintf(logfp, "%s %d calloc(%ld, 1) returns %p\n", @@ -124,7 +137,7 @@ void *nasm_realloc(void *q, size_t size) { void *p = q ? realloc(q, size) : malloc(size); if (!p) - nasm_malloc_error(ERR_FATAL | ERR_NOFILE, "out of memory"); + nasm_error(ERR_FATAL | ERR_NOFILE, "out of memory"); #ifdef LOGALLOC else if (q) fprintf(logfp, "%s %d realloc(%p,%ld) returns %p\n", @@ -161,7 +174,7 @@ char *nasm_strdup(const char *s) p = malloc(size); if (!p) - nasm_malloc_error(ERR_FATAL | ERR_NOFILE, "out of memory"); + nasm_error(ERR_FATAL | ERR_NOFILE, "out of memory"); #ifdef LOGALLOC else fprintf(logfp, "%s %d strdup(%ld) returns %p\n", @@ -182,7 +195,7 @@ char *nasm_strndup(const char *s, size_t len) p = malloc(size); if (!p) - nasm_malloc_error(ERR_FATAL | ERR_NOFILE, "out of memory"); + nasm_error(ERR_FATAL | ERR_NOFILE, "out of memory"); #ifdef LOGALLOC else fprintf(logfp, "%s %d strndup(%ld) returns %p\n", @@ -195,8 +208,7 @@ char *nasm_strndup(const char *s, size_t len) no_return nasm_assert_failed(const char *file, int line, const char *msg) { - nasm_malloc_error(ERR_FATAL, "assertion %s failed at %s:%d", - msg, file, line); + nasm_error(ERR_FATAL, "assertion %s failed at %s:%d", msg, file, line); exit(1); } @@ -396,9 +408,9 @@ int64_t readnum(char *str, bool *error) } if (warn) - nasm_malloc_error(ERR_WARNING | ERR_PASS1 | ERR_WARN_NOV, - "numeric constant %s does not fit in 64 bits", - str); + nasm_error(ERR_WARNING | ERR_PASS1 | ERR_WARN_NOV, + "numeric constant %s does not fit in 64 bits", + str); return result * sign; } @@ -513,8 +525,7 @@ size_t fwritezero(size_t bytes, FILE *fp) return count; } -void standard_extension(char *inname, char *outname, char *extension, - efunc error) +void standard_extension(char *inname, char *outname, char *extension) { char *p, *q; @@ -531,13 +542,13 @@ void standard_extension(char *inname, char *outname, char *extension, p++; /* go back to end if none found */ if (!strcmp(p, extension)) { /* is the extension already there? */ if (*extension) - error(ERR_WARNING | ERR_NOFILE, - "file name already ends in `%s': " - "output will be in `nasm.out'", extension); + nasm_error(ERR_WARNING | ERR_NOFILE, + "file name already ends in `%s': " + "output will be in `nasm.out'", extension); else - error(ERR_WARNING | ERR_NOFILE, - "file name already has no extension: " - "output will be in `nasm.out'"); + nasm_error(ERR_WARNING | ERR_NOFILE, + "file name already has no extension: " + "output will be in `nasm.out'"); strcpy(outname, "nasm.out"); } else strcpy(p, extension); diff --git a/nasmlib.h b/nasmlib.h index 421e8cc..21e976e 100644 --- a/nasmlib.h +++ b/nasmlib.h @@ -83,7 +83,9 @@ extern unsigned char nasm_tolower_tab[256]; * An error reporting function should look like this. */ typedef void (*efunc) (int severity, const char *fmt, ...); -extern efunc nasm_malloc_error; +typedef void (*vefunc) (int severity, const char *fmt, va_list ap); +void nasm_error(int severity, const char *fmt, ...); +void nasm_set_verror(vefunc); /* * These are the error severity codes which get passed as the first @@ -133,7 +135,7 @@ extern efunc nasm_malloc_error; * passed a NULL pointer; nasm_free will do nothing if it is passed * a NULL pointer. */ -void nasm_set_malloc_error(efunc); +void nasm_init_malloc_error(void); #ifndef LOGALLOC void *nasm_malloc(size_t); void *nasm_zalloc(size_t); @@ -220,10 +222,7 @@ int32_t seg_alloc(void); * many output formats will be able to make use of this: a standard * function to add an extension to the name of the input file */ -#ifdef NASM_NASM_H -void standard_extension(char *inname, char *outname, char *extension, - efunc error); -#endif +void standard_extension(char *inname, char *outname, char *extension); /* * Utility macros... diff --git a/ndisasm.c b/ndisasm.c index 9234c6e..8c924b9 100644 --- a/ndisasm.c +++ b/ndisasm.c @@ -68,11 +68,8 @@ static const char *help = static void output_ins(uint32_t, uint8_t *, int, char *); static void skip(uint32_t dist, FILE * fp); -static void ndisasm_error(int severity, const char *fmt, ...) +static void ndisasm_verror(int severity, const char *fmt, va_list va) { - va_list va; - - va_start(va, fmt); vfprintf(stderr, fmt, va); if (severity & ERR_FATAL) @@ -97,7 +94,8 @@ int main(int argc, char **argv) FILE *fp; tolower_init(); - nasm_set_malloc_error(ndisasm_error); + nasm_set_verror(ndisasm_verror); + nasm_init_malloc_error(); offset = 0; init_sync(); diff --git a/output/nulldbg.c b/output/nulldbg.c index 54a4580..2b985c5 100644 --- a/output/nulldbg.c +++ b/output/nulldbg.c @@ -34,19 +34,17 @@ #include "nasm.h" #include "nasmlib.h" -void null_debug_init(struct ofmt *of, void *id, FILE * fp, efunc error) +void null_debug_init(void) { - (void)of; - (void)id; - (void)fp; - (void)error; } + void null_debug_linenum(const char *filename, int32_t linenumber, int32_t segto) { (void)filename; (void)linenumber; (void)segto; } + void null_debug_deflabel(char *name, int32_t segment, int64_t offset, int is_global, char *special) { @@ -56,20 +54,24 @@ void null_debug_deflabel(char *name, int32_t segment, int64_t offset, (void)is_global; (void)special; } + void null_debug_routine(const char *directive, const char *params) { (void)directive; (void)params; } + void null_debug_typevalue(int32_t type) { (void)type; } + void null_debug_output(int type, void *param) { (void)type; (void)param; } + void null_debug_cleanup(void) { } diff --git a/output/outaout.c b/output/outaout.c index c39eedd..0b3c7ca 100644 --- a/output/outaout.c +++ b/output/outaout.c @@ -49,6 +49,7 @@ #include "saa.h" #include "raa.h" #include "stdscan.h" +#include "eval.h" #include "output/outform.h" #include "output/outlib.h" @@ -129,10 +130,6 @@ static uint32_t strslen; static struct Symbol *fwds; -static FILE *aoutfp; -static efunc error; -static evalfunc evaluate; - static int bsd; static int is_pic; @@ -153,13 +150,8 @@ static int32_t aout_gotpc_sect, aout_gotoff_sect; static int32_t aout_got_sect, aout_plt_sect; static int32_t aout_sym_sect; -static void aoutg_init(FILE * fp, efunc errfunc, ldfunc ldef, - evalfunc eval) +static void aoutg_init(void) { - aoutfp = fp; - error = errfunc; - evaluate = eval; - (void)ldef; /* placate optimisers */ stext.data = saa_init(1L); stext.head = NULL; stext.tail = &stext.head; @@ -183,10 +175,10 @@ static void aoutg_init(FILE * fp, efunc errfunc, ldfunc ldef, #ifdef OF_AOUT -static void aout_init(FILE * fp, efunc errfunc, ldfunc ldef, evalfunc eval) +static void aout_init(void) { bsd = false; - aoutg_init(fp, errfunc, ldef, eval); + aoutg_init(); aout_gotpc_sect = aout_gotoff_sect = aout_got_sect = aout_plt_sect = aout_sym_sect = NO_SEG; @@ -198,29 +190,28 @@ static void aout_init(FILE * fp, efunc errfunc, ldfunc ldef, evalfunc eval) extern struct ofmt of_aoutb; -static void aoutb_init(FILE * fp, efunc errfunc, ldfunc ldef, - evalfunc eval) +static void aoutb_init(void) { bsd = true; - aoutg_init(fp, errfunc, ldef, eval); + aoutg_init(); is_pic = 0x00; /* may become 0x40 */ aout_gotpc_sect = seg_alloc(); - ldef("..gotpc", aout_gotpc_sect + 1, 0L, NULL, false, false, &of_aoutb, - error); + define_label("..gotpc", aout_gotpc_sect + 1, 0L, NULL, false, false, &of_aoutb, + nasm_error); aout_gotoff_sect = seg_alloc(); - ldef("..gotoff", aout_gotoff_sect + 1, 0L, NULL, false, false, - &of_aoutb, error); + define_label("..gotoff", aout_gotoff_sect + 1, 0L, NULL, false, false, + &of_aoutb, nasm_error); aout_got_sect = seg_alloc(); - ldef("..got", aout_got_sect + 1, 0L, NULL, false, false, &of_aoutb, - error); + define_label("..got", aout_got_sect + 1, 0L, NULL, false, false, &of_aoutb, + nasm_error); aout_plt_sect = seg_alloc(); - ldef("..plt", aout_plt_sect + 1, 0L, NULL, false, false, &of_aoutb, - error); + define_label("..plt", aout_plt_sect + 1, 0L, NULL, false, false, &of_aoutb, + nasm_error); aout_sym_sect = seg_alloc(); - ldef("..sym", aout_sym_sect + 1, 0L, NULL, false, false, &of_aoutb, - error); + define_label("..sym", aout_sym_sect + 1, 0L, NULL, false, false, &of_aoutb, + nasm_error); } #endif @@ -292,7 +283,7 @@ static void aout_deflabel(char *name, int32_t segment, int64_t offset, if (strcmp(name, "..gotpc") && strcmp(name, "..gotoff") && strcmp(name, "..got") && strcmp(name, "..plt") && strcmp(name, "..sym")) - error(ERR_NONFATAL, "unrecognised special symbol `%s'", name); + nasm_error(ERR_NONFATAL, "unrecognised special symbol `%s'", name); return; } @@ -315,10 +306,10 @@ static void aout_deflabel(char *name, int32_t segment, int64_t offset, stdscan_reset(); stdscan_bufptr = p; tokval.t_type = TOKEN_INVALID; - e = evaluate(stdscan, NULL, &tokval, NULL, 1, error, NULL); + e = evaluate(stdscan, NULL, &tokval, NULL, 1, nasm_error, NULL); if (e) { if (!is_simple(e)) - error(ERR_NONFATAL, "cannot use relocatable" + nasm_error(ERR_NONFATAL, "cannot use relocatable" " expression as symbol size"); else (*s)->size = reloc_value(e); @@ -387,7 +378,7 @@ static void aout_deflabel(char *name, int32_t segment, int64_t offset, !nasm_strnicmp(special, "object", n)) sym->type |= SYM_DATA; else - error(ERR_NONFATAL, "unrecognised symbol type `%.*s'", + nasm_error(ERR_NONFATAL, "unrecognised symbol type `%.*s'", n, special); if (special[n]) { struct tokenval tokval; @@ -396,7 +387,7 @@ static void aout_deflabel(char *name, int32_t segment, int64_t offset, char *saveme = stdscan_bufptr; /* bugfix? fbk 8/10/00 */ if (!bsd) { - error(ERR_NONFATAL, "Linux a.out does not support" + nasm_error(ERR_NONFATAL, "Linux a.out does not support" " symbol size information"); } else { while (special[n] && nasm_isspace(special[n])) @@ -409,7 +400,7 @@ static void aout_deflabel(char *name, int32_t segment, int64_t offset, stdscan_reset(); stdscan_bufptr = special + n; tokval.t_type = TOKEN_INVALID; - e = evaluate(stdscan, NULL, &tokval, &fwd, 0, error, + e = evaluate(stdscan, NULL, &tokval, &fwd, 0, nasm_error, NULL); if (fwd) { sym->nextfwd = fwds; @@ -417,7 +408,7 @@ static void aout_deflabel(char *name, int32_t segment, int64_t offset, sym->name = nasm_strdup(name); } else if (e) { if (!is_simple(e)) - error(ERR_NONFATAL, "cannot use relocatable" + nasm_error(ERR_NONFATAL, "cannot use relocatable" " expression as symbol size"); else sym->size = reloc_value(e); @@ -443,7 +434,7 @@ static void aout_deflabel(char *name, int32_t segment, int64_t offset, nsyms++; /* and another for the size */ if (special && !special_used) - error(ERR_NONFATAL, "no special symbol features supported here"); + nasm_error(ERR_NONFATAL, "no special symbol features supported here"); } static void aout_add_reloc(struct Section *sect, int32_t segment, @@ -511,7 +502,7 @@ static int32_t aout_add_gsym_reloc(struct Section *sect, shead = sbss.gsyms; if (!shead) { if (exact && offset != 0) - error(ERR_NONFATAL, "unable to find a suitable global symbol" + nasm_error(ERR_NONFATAL, "unable to find a suitable global symbol" " for this reference"); else aout_add_reloc(sect, segment, type, bytes); @@ -535,7 +526,7 @@ static int32_t aout_add_gsym_reloc(struct Section *sect, sym = sm; } if (!sym && exact) { - error(ERR_NONFATAL, "unable to find a suitable global symbol" + nasm_error(ERR_NONFATAL, "unable to find a suitable global symbol" " for this reference"); return 0; } @@ -582,7 +573,7 @@ static int32_t aout_add_gotoff_reloc(struct Section *sect, int32_t segment, else if (segment == sbss.index) asym = sbss.asym; if (!asym) - error(ERR_NONFATAL, "`..gotoff' relocations require a non-global" + nasm_error(ERR_NONFATAL, "`..gotoff' relocations require a non-global" " symbol in the section"); r = *sect->tail = nasm_malloc(sizeof(struct Reloc)); @@ -612,7 +603,7 @@ static void aout_out(int32_t segto, const void *data, */ if (segto == NO_SEG) { if (type != OUT_RESERVE) - error(ERR_NONFATAL, "attempt to assemble code in [ABSOLUTE]" + nasm_error(ERR_NONFATAL, "attempt to assemble code in [ABSOLUTE]" " space"); return; } @@ -624,13 +615,13 @@ static void aout_out(int32_t segto, const void *data, else if (segto == sbss.index) s = NULL; else { - error(ERR_WARNING, "attempt to assemble code in" + nasm_error(ERR_WARNING, "attempt to assemble code in" " segment %d: defaulting to `.text'", segto); s = &stext; } if (!s && type != OUT_RESERVE) { - error(ERR_WARNING, "attempt to initialize memory in the" + nasm_error(ERR_WARNING, "attempt to initialize memory in the" " BSS section: ignored"); sbss.len += realsize(type, size); return; @@ -638,7 +629,7 @@ static void aout_out(int32_t segto, const void *data, if (type == OUT_RESERVE) { if (s) { - error(ERR_WARNING, "uninitialized space declared in" + nasm_error(ERR_WARNING, "uninitialized space declared in" " %s section: zeroing", (segto == stext.index ? "code" : "data")); aout_sect_write(s, NULL, size); @@ -646,20 +637,20 @@ static void aout_out(int32_t segto, const void *data, sbss.len += size; } else if (type == OUT_RAWDATA) { if (segment != NO_SEG) - error(ERR_PANIC, "OUT_RAWDATA with other than NO_SEG"); + nasm_error(ERR_PANIC, "OUT_RAWDATA with other than NO_SEG"); aout_sect_write(s, data, size); } else if (type == OUT_ADDRESS) { addr = *(int64_t *)data; if (segment != NO_SEG) { if (segment % 2) { - error(ERR_NONFATAL, "a.out format does not support" + nasm_error(ERR_NONFATAL, "a.out format does not support" " segment base references"); } else { if (wrt == NO_SEG) { aout_add_reloc(s, segment, RELTYPE_ABSOLUTE, size); } else if (!bsd) { - error(ERR_NONFATAL, + nasm_error(ERR_NONFATAL, "Linux a.out format does not support" " any use of WRT"); wrt = NO_SEG; /* we can at least _try_ to continue */ @@ -681,11 +672,11 @@ static void aout_out(int32_t segto, const void *data, false); } else if (wrt == aout_plt_sect + 1) { is_pic = 0x40; - error(ERR_NONFATAL, + nasm_error(ERR_NONFATAL, "a.out format cannot produce non-PC-" "relative PLT references"); } else { - error(ERR_NONFATAL, + nasm_error(ERR_NONFATAL, "a.out format does not support this" " use of WRT"); wrt = NO_SEG; /* we can at least _try_ to continue */ @@ -700,15 +691,15 @@ static void aout_out(int32_t segto, const void *data, aout_sect_write(s, mydata, size); } else if (type == OUT_REL2ADR) { if (segment == segto) - error(ERR_PANIC, "intra-segment OUT_REL2ADR"); + nasm_error(ERR_PANIC, "intra-segment OUT_REL2ADR"); if (segment != NO_SEG && segment % 2) { - error(ERR_NONFATAL, "a.out format does not support" + nasm_error(ERR_NONFATAL, "a.out format does not support" " segment base references"); } else { if (wrt == NO_SEG) { aout_add_reloc(s, segment, RELTYPE_RELATIVE, 2); } else if (!bsd) { - error(ERR_NONFATAL, "Linux a.out format does not support" + nasm_error(ERR_NONFATAL, "Linux a.out format does not support" " any use of WRT"); wrt = NO_SEG; /* we can at least _try_ to continue */ } else if (wrt == aout_plt_sect + 1) { @@ -717,10 +708,10 @@ static void aout_out(int32_t segto, const void *data, } else if (wrt == aout_gotpc_sect + 1 || wrt == aout_gotoff_sect + 1 || wrt == aout_got_sect + 1) { - error(ERR_NONFATAL, "a.out format cannot produce PC-" + nasm_error(ERR_NONFATAL, "a.out format cannot produce PC-" "relative GOT references"); } else { - error(ERR_NONFATAL, "a.out format does not support this" + nasm_error(ERR_NONFATAL, "a.out format does not support this" " use of WRT"); wrt = NO_SEG; /* we can at least _try_ to continue */ } @@ -730,15 +721,15 @@ static void aout_out(int32_t segto, const void *data, aout_sect_write(s, mydata, 2L); } else if (type == OUT_REL4ADR) { if (segment == segto) - error(ERR_PANIC, "intra-segment OUT_REL4ADR"); + nasm_error(ERR_PANIC, "intra-segment OUT_REL4ADR"); if (segment != NO_SEG && segment % 2) { - error(ERR_NONFATAL, "a.out format does not support" + nasm_error(ERR_NONFATAL, "a.out format does not support" " segment base references"); } else { if (wrt == NO_SEG) { aout_add_reloc(s, segment, RELTYPE_RELATIVE, 4); } else if (!bsd) { - error(ERR_NONFATAL, "Linux a.out format does not support" + nasm_error(ERR_NONFATAL, "Linux a.out format does not support" " any use of WRT"); wrt = NO_SEG; /* we can at least _try_ to continue */ } else if (wrt == aout_plt_sect + 1) { @@ -747,10 +738,10 @@ static void aout_out(int32_t segto, const void *data, } else if (wrt == aout_gotpc_sect + 1 || wrt == aout_gotoff_sect + 1 || wrt == aout_got_sect + 1) { - error(ERR_NONFATAL, "a.out format cannot produce PC-" + nasm_error(ERR_NONFATAL, "a.out format cannot produce PC-" "relative GOT references"); } else { - error(ERR_NONFATAL, "a.out format does not support this" + nasm_error(ERR_NONFATAL, "a.out format does not support this" " use of WRT"); wrt = NO_SEG; /* we can at least _try_ to continue */ } @@ -822,20 +813,20 @@ static void aout_write(void) * Emit the a.out header. */ /* OMAGIC, M_386 or MID_I386, no flags */ - fwriteint32_t(bsd ? 0x07018600 | is_pic : 0x640107L, aoutfp); - fwriteint32_t(stext.len, aoutfp); - fwriteint32_t(sdata.len, aoutfp); - fwriteint32_t(sbss.len, aoutfp); - fwriteint32_t(nsyms * 12, aoutfp); /* length of symbol table */ - fwriteint32_t(0L, aoutfp); /* object files have no entry point */ - fwriteint32_t(stext.nrelocs * 8, aoutfp); /* size of text relocs */ - fwriteint32_t(sdata.nrelocs * 8, aoutfp); /* size of data relocs */ + fwriteint32_t(bsd ? 0x07018600 | is_pic : 0x640107L, ofile); + fwriteint32_t(stext.len, ofile); + fwriteint32_t(sdata.len, ofile); + fwriteint32_t(sbss.len, ofile); + fwriteint32_t(nsyms * 12, ofile); /* length of symbol table */ + fwriteint32_t(0L, ofile); /* object files have no entry point */ + fwriteint32_t(stext.nrelocs * 8, ofile); /* size of text relocs */ + fwriteint32_t(sdata.nrelocs * 8, ofile); /* size of data relocs */ /* * Write out the code section and the data section. */ - saa_fpwrite(stext.data, aoutfp); - saa_fpwrite(sdata.data, aoutfp); + saa_fpwrite(stext.data, ofile); + saa_fpwrite(sdata.data, ofile); /* * Write out the relocations. @@ -851,8 +842,8 @@ static void aout_write(void) /* * And the string table. */ - fwriteint32_t(strslen + 4, aoutfp); /* length includes length count */ - saa_fpwrite(strs, aoutfp); + fwriteint32_t(strslen + 4, ofile); /* length includes length count */ + saa_fpwrite(strs, ofile); } static void aout_write_relocs(struct Reloc *r) @@ -860,7 +851,7 @@ static void aout_write_relocs(struct Reloc *r) while (r) { uint32_t word2; - fwriteint32_t(r->address, aoutfp); + fwriteint32_t(r->address, ofile); if (r->symbol >= 0) word2 = r->symbol; @@ -869,7 +860,7 @@ static void aout_write_relocs(struct Reloc *r) word2 |= r->reltype << 24; word2 |= (r->bytes == 1 ? 0 : r->bytes == 2 ? 0x2000000L : 0x4000000L); - fwriteint32_t(word2, aoutfp); + fwriteint32_t(word2, ofile); r = r->next; } @@ -882,8 +873,8 @@ static void aout_write_syms(void) saa_rewind(syms); for (i = 0; i < nsyms; i++) { struct Symbol *sym = saa_rstruct(syms); - fwriteint32_t(sym->strpos, aoutfp); - fwritei... [truncated message content] |