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;
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];
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 */
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;
}
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));
seg_init();
- register_output_formats();
-
/* Define some macros dependent on the runtime, but not
on the command line. */
define_macros_early();
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);
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
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())) {
* 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);
}
*/
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);
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);
}
}
*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;
}
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);
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);
}
break;
default:
- report_error(ERR_FATAL,
+ nasm_error(ERR_FATAL,
"unknown optimization option -O%c\n",
*param);
break;
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);
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;
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;
}
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;
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;
}
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);
}
default:
{
- report_error(ERR_NONFATAL | ERR_NOFILE | ERR_USAGE,
+ nasm_error(ERR_NONFATAL | ERR_NOFILE | ERR_USAGE,
"unrecognised option `--%s'", p + 2);
break;
}
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);
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
/* 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);
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);
}
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 */
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 */
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));
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 {
q++;
}
if (!validid) {
- report_error(ERR_NONFATAL,
+ nasm_error(ERR_NONFATAL,
"identifier expected after EXTERN");
break;
}
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 */
q++;
}
if (!validid) {
- report_error(ERR_NONFATAL,
+ nasm_error(ERR_NONFATAL,
"identifier expected after GLOBAL");
break;
}
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] */
p++;
}
if (!validid) {
- report_error(ERR_NONFATAL,
+ nasm_error(ERR_NONFATAL,
"identifier expected after COMMON");
break;
}
}
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;
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);
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");
} 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;
}
*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))
}
}
else
- report_error(ERR_NONFATAL,
+ nasm_error(ERR_NONFATAL,
"invalid warning id in WARNING directive");
break;
case D_CPU: /* [CPU] */
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) {
* 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] != '.' ||
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)
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 {
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)
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");
}
}
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)
}
- ofmt->current_dfmt->debug_typevalue(typeinfo);
-
+ dfmt->debug_typevalue(typeinfo);
}
if (l != -1) {
offs += l;
} else {
offs += assemble(location.segment, offs, sb, cpu,
- &output_ins, ofmt, report_error,
+ &output_ins, ofmt, nasm_error,
&nasmlist);
SET_CURR_OFFS(offs);
} /* 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)
/* 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;
}
* @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;
fputs("nasm: ", error_file);
}
- va_start(ap, fmt);
- report_error_common(severity, fmt, ap);
- va_end(ap);
+ nasm_verror_common(severity, fmt, ap);
}
/**
* @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;
fputs("nasm: ", error_file);
}
- va_start(ap, fmt);
- report_error_common(severity, fmt, ap);
- va_end(ap);
+ nasm_verror_common(severity, fmt, ap);
}
/**
* @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;
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;
!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 */
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;
* 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:
* 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
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
* 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
void (*cleanup) (int debuginfo);
};
+extern struct ofmt *ofmt;
+extern FILE *ofile;
/*
* ------------------------------------------------------------
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
* 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
* 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
#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;
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);
{
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",
{
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",
{
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",
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",
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",
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);
}
}
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;
}
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;
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);
* 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
* 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);
* 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...
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)
FILE *fp;
tolower_init();
- nasm_set_malloc_error(ndisasm_error);
+ nasm_set_verror(ndisasm_verror);
+ nasm_init_malloc_error();
offset = 0;
init_sync();
#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)
{
(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)
{
}
#include "saa.h"
#include "raa.h"
#include "stdscan.h"
+#include "eval.h"
#include "output/outform.h"
#include "output/outlib.h"
static struct Symbol *fwds;
-static FILE *aoutfp;
-static efunc error;
-static evalfunc evaluate;
-
static int bsd;
static int is_pic;
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;
#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;
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
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;
}
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);
!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;
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]))
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;
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);
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,
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);
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;
}
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));
*/
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;
}
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;
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);
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 */
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 */
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) {
} 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 */
}
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) {
} 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 */
}
* 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.
/*
* 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)
while (r) {
uint32_t word2;
- fwriteint32_t(r->address, aoutfp);
+ fwriteint32_t(r->address, ofile);
if (r->symbol >= 0)
word2 = r->symbol;
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;
}
saa_rewind(syms);
for (i = 0; i < nsyms; i++) {
struct Symbol *sym = saa_rstruct(syms);
- fwriteint32_t(sym->strpos, aoutfp);
- fwriteint32_t((int32_t)sym->type & ~SYM_WITH_SIZE, aoutfp);
+ fwriteint32_t(sym->strpos, ofile);
+ fwriteint32_t((int32_t)sym->type & ~SYM_WITH_SIZE, ofile);
/*
* Fix up the symbol value now we know the final section
* sizes.
sym->value += stext.len;
if ((sym->type & SECT_MASK) == SECT_BSS)
sym->value += stext.len + sdata.len;
- fwriteint32_t(sym->value, aoutfp);
+ fwriteint32_t(sym->value, ofile);
/*
* Output a size record if necessary.
*/
if (sym->type & SYM_WITH_SIZE) {
- fwriteint32_t(sym->strpos, aoutfp);
- fwriteint32_t(0x0DL, aoutfp); /* special value: means size */
- fwriteint32_t(sym->size, aoutfp);
+ fwriteint32_t(sym->strpos, ofile);
+ fwriteint32_t(0x0DL, ofile); /* special value: means size */
+ fwriteint32_t(sym->size, ofile);
i++; /* use up another of `nsyms' */
}
}
return segment;
}
-static void aout_filename(char *inname, char *outname, efunc error)
+static void aout_filename(char *inname, char *outname)
{
- standard_extension(inname, outname, ".o", error);
+ standard_extension(inname, outname, ".o");
}
extern macros_t aout_stdmac[];
static int as86_reloc_size;
-static FILE *as86fp;
-static efunc error;
-
static void as86_write(void);
static void as86_write_section(struct Section *, int);
static int as86_add_string(char *name);
static void as86_sect_write(struct Section *, const uint8_t *,
uint32_t);
-static void as86_init(FILE * fp, efunc errfunc, ldfunc ldef, evalfunc eval)
+static void as86_init(void)
{
- as86fp = fp;
- error = errfunc;
- (void)ldef; /* placate optimisers */
- (void)eval;
stext.data = saa_init(1L);
stext.datalen = 0L;
stext.head = stext.last = NULL;
struct Symbol *sym;
if (special)
- error(ERR_NONFATAL, "as86 format does not support any"
+ nasm_error(ERR_NONFATAL, "as86 format does not support any"
" special symbol types");
if (name[0] == '.' && name[1] == '.' && name[2] != '@') {
if (strcmp(name, "..start")) {
- error(ERR_NONFATAL, "unrecognised special symbol `%s'", name);
+ nasm_error(ERR_NONFATAL, "unrecognised special symbol `%s'", name);
return;
} else {
is_start = true;
if (wrt != NO_SEG) {
wrt = NO_SEG; /* continue to do _something_ */
- error(ERR_NONFATAL, "WRT not supported by as86 output format");
+ nasm_error(ERR_NONFATAL, "WRT not supported by as86 output format");
}
/*
*/
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;
}
else if (segto == bssindex)
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");
bsslen += realsize(type, size);
return;
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"));
as86_sect_write(s, NULL, size);
bsslen += 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");
as86_sect_write(s, data, size);
as86_add_piece(s, 0, 0L, 0L, size, 0);
} else if (type == OUT_ADDRESS) {
if (segment != NO_SEG) {
if (segment % 2) {
- error(ERR_NONFATAL, "as86 format does not support"
+ nasm_error(ERR_NONFATAL, "as86 format does not support"
" segment base references");
} else {
offset = *(int64_t *)data;
}
} 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) {
if (segment % 2) {
- error(ERR_NONFATAL, "as86 format does not support"
+ nasm_error(ERR_NONFATAL, "as86 format does not support"
" segment base references");
} else {
offset = *(int64_t *)data;
}
} 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) {
if (segment % 2) {
- error(ERR_NONFATAL, "as86 format does not support"
+ nasm_error(ERR_NONFATAL, "as86 format does not support"
" segment base references");
} else {
offset = *(int64_t *)data;
/*
* Emit the as86 header.
*/
- fwriteint32_t(0x000186A3L, as86fp);
- fputc(0x2A, as86fp);
- fwriteint32_t(27 + symlen + seglen + strslen, as86fp); /* header length */
- fwriteint32_t(stext.len + sdata.len + bsslen, as86fp);
- fwriteint16_t(strslen, as86fp);
- fwriteint16_t(0, as86fp); /* class = revision = 0 */
- fwriteint32_t(0x55555555L, as86fp); /* segment max sizes: always this */
- fwriteint32_t(segsize, as86fp); /* segment size descriptors */
+ fwriteint32_t(0x000186A3L, ofile);
+ fputc(0x2A, ofile);
+ fwriteint32_t(27 + symlen + seglen + strslen, ofile); /* header length */
+ fwriteint32_t(stext.len + sdata.len + bsslen, ofile);
+ fwriteint16_t(strslen, ofile);
+ fwriteint16_t(0, ofile); /* class = revision = 0 */
+ fwriteint32_t(0x55555555L, ofile); /* segment max sizes: always this */
+ fwriteint32_t(segsize, ofile); /* segment size descriptors */
if (segsize & 0x01000000L)
- fwriteint32_t(stext.len, as86fp);
+ fwriteint32_t(stext.len, ofile);
else
- fwriteint16_t(stext.len, as86fp);
+ fwriteint16_t(stext.len, ofile);
if (segsize & 0x40000000L)
- fwriteint32_t(sdata.len + bsslen, as86fp);
+ fwriteint32_t(sdata.len + bsslen, ofile);
else
- fwriteint16_t(sdata.len + bsslen, as86fp);
- fwriteint16_t(nsyms, as86fp);
+ fwriteint16_t(sdata.len + bsslen, ofile);
+ fwriteint16_t(nsyms, ofile);
/*
* Write the symbol table.
saa_rewind(syms);
for (i = 0; i < nsyms; i++) {
struct Symbol *sym = saa_rstruct(syms);
- fwriteint16_t(sym->strpos, as86fp);
- fwriteint16_t(sym->flags, as86fp);
+ fwriteint16_t(sym->strpos, ofile);
+ fwriteint16_t(sym->flags, ofile);
switch (sym->flags & (3 << 14)) {
case 0 << 14:
break;
case 1 << 14:
- fputc(sym->value, as86fp);
+ fputc(sym->value, ofile);
break;
case 2 << 14:
- fwriteint16_t(sym->value, as86fp);
+ fwriteint16_t(sym->value, ofile);
break;
case 3 << 14:
- fwriteint32_t(sym->value, as86fp);
+ fwriteint32_t(sym->value, ofile);
break;
}
}
/*
* Write out the string table.
*/
- saa_fpwrite(strs, as86fp);
+ saa_fpwrite(strs, ofile);
/*
* Write the program text.
* Append the BSS section to the .data section
*/
if (bsslen > 65535L) {
- fputc(0x13, as86fp);
- fwriteint32_t(bsslen, as86fp);
+ fputc(0x13, ofile);
+ fwriteint32_t(bsslen, ofile);
} else if (bsslen > 255) {
- fputc(0x12, as86fp);
- fwriteint16_t(bsslen, as86fp);
+ fputc(0x12, ofile);
+ fwriteint16_t(bsslen, ofile);
} else if (bsslen) {
- fputc(0x11, as86fp);
- fputc(bsslen, as86fp);
+ fputc(0x11, ofile);
+ fputc(bsslen, ofile);
}
- fputc(0, as86fp); /* termination */
+ fputc(0, ofile); /* termination */
}
static void as86_set_rsize(int size)
if (as86_reloc_size != size) {
switch (as86_reloc_size = size) {
case 1:
- fputc(0x01, as86fp);
+ fputc(0x01, ofile);
break;
case 2:
- fputc(0x02, as86fp);
+ fputc(0x02, ofile);
break;
case 4:
- fputc(0x03, as86fp);
+ fputc(0x03, ofile);
break;
default:
- error(ERR_PANIC, "bizarre relocation size %d", size);
+ nasm_error(ERR_PANIC, "bizarre relocation size %d", size);
+ break;
}
}
}
uint32_t s;
int32_t length;
- fputc(0x20 + index, as86fp); /* select the right section */
+ fputc(0x20 + index, ofile); /* select the right section */
saa_rewind(sect->data);
do {
char buf[64];
int32_t tmplen = (length > 64 ? 64 : length);
- fputc(0x40 | (tmplen & 0x3F), as86fp);
+ fputc(0x40 | (tmplen & 0x3F), ofile);
saa_rnbytes(sect->data, buf, tmplen);
- fwrite(buf, 1, tmplen, as86fp);
+ fwrite(buf, 1, tmplen, ofile);
length -= tmplen;
} while (length > 0);
break;
if (p->number == SECT_BSS)
p->number = SECT_DATA, p->offset += sdata.len;
as86_set_rsize(p->bytes);
- fputc(0x80 | (p->relative ? 0x20 : 0) | p->number, as86fp);
+ fputc(0x80 | (p->relative ? 0x20 : 0) | p->number, ofile);
if (as86_reloc_size == 2)
- fwriteint16_t(p->offset, as86fp);
+ fwriteint16_t(p->offset, ofile);
else
- fwriteint32_t(p->offset, as86fp);
+ fwriteint32_t(p->offset, ofile);
break;
case 2:
/*
s = 0;
fputc(0xC0 |
(p->relative ? 0x20 : 0) |
- (p->number > 255 ? 0x04 : 0) | s, as86fp);
+ (p->number > 255 ? 0x04 : 0) | s, ofile);
if (p->number > 255)
- fwriteint16_t(p->number, as86fp);
+ fwriteint16_t(p->number, ofile);
else
- fputc(p->number, as86fp);
+ fputc(p->number, ofile);
switch ((int)s) {
case 0:
break;
case 1:
- fputc(p->offset, as86fp);
+ fputc(p->offset, ofile);
break;
case 2:
- fwriteint16_t(p->offset, as86fp);
+ fwriteint16_t(p->offset, ofile);
break;
case 3:
- fwriteint32_t(p->offset, as86fp);
+ fwriteint32_t(p->offset, ofile);
break;
}
break;
return segment;
}
-static void as86_filename(char *inname, char *outname, efunc error)
+static void as86_filename(char *inname, char *outname)
{
char *p;
} else
strcpy(as86_module, inname);
- standard_extension(inname, outname, ".o", error);
+ standard_extension(inname, outname, ".o");
}
extern macros_t as86_stdmac[];
#ifdef OF_BIN
-static FILE *fp, *rf = NULL;
-static efunc error;
-static struct ofmt *my_ofmt;
+static FILE *rf = NULL;
static void (*do_output)(void);
/* Section flags keep track of which attributes the user has defined. */
if (s->flags & (START_DEFINED | ALIGN_DEFINED | FOLLOWS_DEFINED)) { /* Check for a mixture of real and virtual section attributes. */
if (s->flags & (VSTART_DEFINED | VALIGN_DEFINED |
VFOLLOWS_DEFINED))
- error(ERR_FATAL|ERR_NOFILE,
+ nasm_error(ERR_FATAL|ERR_NOFILE,
"cannot mix real and virtual attributes"
" in nobits section (%s)", s->name);
/* Real and virtual attributes mean the same thing for nobits sections. */
s && strcmp(s->name, g->follows);
sp = &s->next, s = s->next) ;
if (!s)
- error(ERR_FATAL|ERR_NOFILE, "section %s follows an invalid or"
+ nasm_error(ERR_FATAL|ERR_NOFILE, "section %s follows an invalid or"
" unknown section (%s)", g->name, g->follows);
if (s->next && (s->next->flags & FOLLOWS_DEFINED) &&
!strcmp(s->name, s->next->follows))
- error(ERR_FATAL|ERR_NOFILE, "sections %s and %s can't both follow"
+ nasm_error(ERR_FATAL|ERR_NOFILE, "sections %s and %s can't both follow"
" section %s", g->name, s->next->name, s->name);
/* Find the end of the current follows group (gs). */
for (gsp = &g->next, gs = g->next;
if (sections->flags & START_DEFINED) {
/* Make sure this section doesn't begin before the origin. */
if (sections->start < origin)
- error(ERR_FATAL|ERR_NOFILE, "section %s begins"
+ nasm_error(ERR_FATAL|ERR_NOFILE, "section %s begins"
" before program origin", sections->name);
} else if (sections->flags & ALIGN_DEFINED) {
sections->start = ((origin + sections->align - 1) &
/* Check for section overlap. */
if (s) {
if (s->start < origin)
- error(ERR_FATAL|ERR_NOFILE, "section %s beings before program origin",
+ nasm_error(ERR_FATAL|ERR_NOFILE, "section %s beings before program origin",
s->name);
if (g->start > s->start)
- error(ERR_FATAL|ERR_NOFILE, "sections %s ~ %s and %s overlap!",
+ nasm_error(ERR_FATAL|ERR_NOFILE, "sections %s ~ %s and %s overlap!",
gs->name, g->name, s->name);
if (pend > s->start)
- error(ERR_FATAL|ERR_NOFILE, "sections %s and %s overlap!",
+ nasm_error(ERR_FATAL|ERR_NOFILE, "sections %s and %s overlap!",
g->name, s->name);
}
/* Remember this section as the latest >0 length section. */
for (s = sections; s && strcmp(g->vfollows, s->name);
s = s->next) ;
if (!s)
- error(ERR_FATAL|ERR_NOFILE,
+ nasm_error(ERR_FATAL|ERR_NOFILE,
"section %s vfollows unknown section (%s)",
g->name, g->vfollows);
} else if (g->ifollows != NULL)
for (h = 0, s = sections; s; s = s->next) {
if (!(s->flags & VSTART_DEFINED)) { /* Non-fatal errors after assembly has completed are generally a
* no-no, but we'll throw a fatal one eventually so it's ok. */
- error(ERR_NONFATAL, "cannot compute vstart for section %s",
+ nasm_error(ERR_NONFATAL, "cannot compute vstart for section %s",
s->name);
h++;
}
}
if (h)
- error(ERR_FATAL|ERR_NOFILE, "circular vfollows path detected");
+ nasm_error(ERR_FATAL|ERR_NOFILE, "circular vfollows path detected");
#ifdef DEBUG
fprintf(stdout,
if (wrt != NO_SEG) {
wrt = NO_SEG; /* continue to do _something_ */
- error(ERR_NONFATAL, "WRT not supported by binary output format");
+ nasm_error(ERR_NONFATAL, "WRT not supported by binary output format");
}
/* Handle absolute-assembly (structure definitions). */
if (segto == NO_SEG) {
if (type != OUT_RESERVE)
- error(ERR_NONFATAL, "attempt to assemble code in"
+ nasm_error(ERR_NONFATAL, "attempt to assemble code in"
" [ABSOLUTE] space");
return;
}
/* Find the segment we are targeting. */
s = find_section_by_index(segto);
if (!s)
- error(ERR_PANIC, "code directed to nonexistent segment?");
+ nasm_error(ERR_PANIC, "code directed to nonexistent segment?");
/* "Smart" section-type adaptation code. */
if (!(s->flags & TYPE_DEFINED)) {
}
if ((s->flags & TYPE_NOBITS) && (type != OUT_RESERVE))
- error(ERR_WARNING, "attempt to initialize memory in a"
+ nasm_error(ERR_WARNING, "attempt to initialize memory in a"
" nobits section: ignored");
if (type == OUT_ADDRESS) {
if (segment != NO_SEG && !find_section_by_index(segment)) {
if (segment % 2)
- error(ERR_NONFATAL, "binary output format does not support"
+ nasm_error(ERR_NONFATAL, "binary output format does not support"
" segment base references");
else
- error(ERR_NONFATAL, "binary output format does not support"
+ nasm_error(ERR_NONFATAL, "binary output format does not support"
" external references");
segment = NO_SEG;
}
s->length += size;
} else if (type == OUT_RESERVE) {
if (s->flags & TYPE_PROGBITS) {
- error(ERR_WARNING, "uninitialized space declared in"
+ nasm_error(ERR_WARNING, "uninitialized space declared in"
" %s section: zeroing", s->name);
saa_wbytes(s->contents, NULL, size);
}
size = realsize(type, size);
if (segment != NO_SEG && !find_section_by_index(segment)) {
if (segment % 2)
- error(ERR_NONFATAL, "binary output format does not support"
+ nasm_error(ERR_NONFATAL, "binary output format does not support"
" segment base references");
else
- error(ERR_NONFATAL, "binary output format does not support"
+ nasm_error(ERR_NONFATAL, "binary output format does not support"
" external references");
segment = NO_SEG;
}
(void)offset; /* Don't warn that this parameter is unused */
if (special)
- error(ERR_NONFATAL, "binary format does not support any"
+ nasm_error(ERR_NONFATAL, "binary format does not support any"
" special symbol types");
else if (name[0] == '.' && name[1] == '.' && name[2] != '@')
- error(ERR_NONFATAL, "unrecognised special symbol `%s'", name);
+ nasm_error(ERR_NONFATAL, "unrecognised special symbol `%s'", name);
else if (is_global == 2)
- error(ERR_NONFATAL, "binary output format does not support common"
+ nasm_error(ERR_NONFATAL, "binary output format does not support common"
" variables");
else {
struct Section *s;
break;
}
if (!**line) {
- error(ERR_NONFATAL,
+ nasm_error(ERR_NONFATAL,
"invalid syntax in `section' directive");
return -1;
}
++(*line);
}
if (!**line) {
- error(ERR_NONFATAL, "expecting `)'");
+ nasm_error(ERR_NONFATAL, "expecting `)'");
return -1;
}
}
/* Check for no value given. */
if (!*exp) {
- error(ERR_WARNING, "No value given to attribute in"
+ nasm_error(ERR_WARNING, "No value given to attribute in"
" `section' directive");
return -1;
}
stdscan_reset();
stdscan_bufptr = exp;
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_really_simple(e)) {
- error(ERR_NONFATAL, "section attribute value must be"
+ nasm_error(ERR_NONFATAL, "section attribute value must be"
" a critical expression");
return -1;
}
} else {
- error(ERR_NONFATAL, "Invalid attribute value"
+ nasm_error(ERR_NONFATAL, "Invalid attribute value"
" specified in `section' directive.");
return -1;
}
*astring = '\0';
astring++;
}
- error(ERR_WARNING, "ignoring unknown section attribute:"
+ nasm_error(ERR_WARNING, "ignoring unknown section attribute:"
" \"%s\"", p);
}
continue;
case ATTRIB_NOBITS:
if ((sec->flags & TYPE_DEFINED)
&& (sec->flags & TYPE_PROGBITS))
- error(ERR_NONFATAL,
+ nasm_error(ERR_NONFATAL,
"attempt to change section type"
" from progbits to nobits");
else
/* Handle progbits attribute. */
case ATTRIB_PROGBITS:
if ((sec->flags & TYPE_DEFINED) && (sec->flags & TYPE_NOBITS))
- error(ERR_NONFATAL, "attempt to change section type"
+ nasm_error(ERR_NONFATAL, "attempt to change section type"
" from nobits to progbits");
else
sec->flags |= TYPE_DEFINED | TYPE_PROGBITS;
/* Handle align attribute. */
case ATTRIB_ALIGN:
if (!format_mode && (!strcmp(sec->name, ".text")))
- error(ERR_NONFATAL, "cannot specify an alignment"
+ nasm_error(ERR_NONFATAL, "cannot specify an alignment"
" to the .text section");
else {
if (!value || ((value - 1) & value))
- error(ERR_NONFATAL, "argument to `align' is not a"
+ nasm_error(ERR_NONFATAL, "argument to `align' is not a"
" power of two");
else { /* Alignment is already satisfied if the previous
* align value is greater. */
/* Don't allow a conflicting align value. */
if ((sec->flags & START_DEFINED)
&& (sec->start & (value - 1)))
- error(ERR_NONFATAL,
+ nasm_error(ERR_NONFATAL,
"`align' value conflicts "
"with section start address");
else {
/* Handle valign attribute. */
case ATTRIB_VALIGN:
if (!value || ((value - 1) & value))
- error(ERR_NONFATAL, "argument to `valign' is not a"
+ nasm_error(ERR_NONFATAL, "argument to `valign' is not a"
" power of two");
else { /* Alignment is already satisfied if the previous
* align value is greater. */
/* Don't allow a conflicting valign value. */
if ((sec->flags & VSTART_DEFINED)
&& (sec->vstart & (value - 1)))
- error(ERR_NONFATAL,
+ nasm_error(ERR_NONFATAL,
"`valign' value conflicts "
"with `vstart' address");
else {
/* Handle start attribute. */
case ATTRIB_START:
if (sec->flags & FOLLOWS_DEFINED)
- error(ERR_NONFATAL, "cannot combine `start' and `follows'"
+ nasm_error(ERR_NONFATAL, "cannot combine `start' and `follows'"
" section attributes");
else if ((sec->flags & START_DEFINED) && (value != sec->start))
- error(ERR_NONFATAL, "section start address redefined");
+ nasm_error(ERR_NONFATAL, "section start address redefined");
else {
sec->start = value;
sec->flags |= START_DEFINED;
if (sec->flags & ALIGN_DEFINED) {
if (sec->start & (sec->align - 1))
- error(ERR_NONFATAL, "`start' address conflicts"
+ nasm_error(ERR_NONFATAL, "`start' address conflicts"
" with section alignment");
sec->flags ^= ALIGN_DEFINED;
}
/* Handle vstart attribute. */
case ATTRIB_VSTART:
if (sec->flags & VFOLLOWS_DEFINED)
- error(ERR_NONFATAL,
+ nasm_error(ERR_NONFATAL,
"cannot combine `vstart' and `vfollows'"
" section attributes");
else if ((sec->flags & VSTART_DEFINED)
&& (value != sec->vstart))
- error(ERR_NONFATAL,
+ nasm_error(ERR_NONFATAL,
"section virtual start address"
" (vstart) redefined");
else {
sec->flags |= VSTART_DEFINED;
if (sec->flags & VALIGN_DEFINED) {
if (sec->vstart & (sec->valign - 1))
- error(ERR_NONFATAL, "`vstart' address conflicts"
+ nasm_error(ERR_NONFATAL, "`vstart' address conflicts"
" with `valign' value");
sec->flags ^= VALIGN_DEFINED;
}
p = astring;
astring += strcspn(astring, " \t");
if (astring == p)
- error(ERR_NONFATAL, "expecting section name for `follows'"
+ nasm_error(ERR_NONFATAL, "expecting section name for `follows'"
" attribute");
else {
*(astring++) = '\0';
if (sec->flags & START_DEFINED)
- error(ERR_NONFATAL,
+ nasm_error(ERR_NONFATAL,
"cannot combine `start' and `follows'"
" section attributes");
sec->follows = nasm_strdup(p);
/* Handle vfollows attribute. */
case ATTRIB_VFOLLOWS:
if (sec->flags & VSTART_DEFINED)
- error(ERR_NONFATAL,
+ nasm_error(ERR_NONFATAL,
"cannot combine `vstart' and `vfollows'"
" section attributes");
else {
p = astring;
astring += strcspn(astring, " \t");
if (astring == p)
- error(ERR_NONFATAL,
+ nasm_error(ERR_NONFATAL,
"expecting section name for `vfollows'"
" attribute");
else {
/* section.<name>.start */
strcpy(label_name + base_len, ".start");
define_label(label_name, sec->start_index, 0L,
- NULL, 0, 0, my_ofmt, error);
+ NULL, 0, 0, ofmt, nasm_error);
/* section.<name>.vstart */
strcpy(label_name + base_len, ".vstart");
define_label(label_name, sec->vstart_index, 0L,
- NULL, 0, 0, my_ofmt, error);
+ NULL, 0, 0, ofmt, nasm_error);
nasm_free(label_name);
}
sec->flags |= TYPE_DEFINED | TYPE_NOBITS;
sec->ifollows = NULL;
} else if (!format_mode) {
- error(ERR_NONFATAL, "section name must be "
+ nasm_error(ERR_NONFATAL, "section name must be "
".text, .data, or .bss");
return current_section;
}
stdscan_reset();
stdscan_bufptr = args;
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_really_simple(e))
- error(ERR_NONFATAL, "org value must be a critical"
+ nasm_error(ERR_NONFATAL, "org value must be a critical"
" expression");
else {
value = reloc_value(e);
/* Check for ORG redefinition. */
if (origin_defined && (value != origin))
- error(ERR_NONFATAL, "program origin redefined");
+ nasm_error(ERR_NONFATAL, "program origin redefined");
else {
origin = value;
origin_defined = 1;
}
}
} else
- error(ERR_NONFATAL, "No or invalid offset specified"
+ nasm_error(ERR_NONFATAL, "No or invalid offset specified"
" in ORG directive.");
return 1;
}
else { /* Must be a filename. */
rf = fopen(p, "wt");
if (!rf) {
- error(ERR_WARNING, "unable to open map file `%s'",
+ nasm_error(ERR_WARNING, "unable to open map file `%s'",
p);
map_control = 0;
return 1;
}
}
} else
- error(ERR_WARNING, "map file already specified");
+ nasm_error(ERR_WARNING, "map file already specified");
}
if (map_control == 0)
map_control |= MAP_ORIGIN | MAP_SUMMARY;
}
}
-static void bin_filename(char *inname, char *outname, efunc error)
+static void bin_filename(char *inname, char *outname)
{
- standard_extension(inname, outname, "", error);
+ standard_extension(inname, outname, "");
infile = inname;
outfile = outname;
}
-static void ith_filename(char *inname, char *outname, efunc error)
+static void ith_filename(char *inname, char *outname)
{
- standard_extension(inname, outname, ".ith", error);
+ standard_extension(inname, outname, ".ith");
infile = inname;
outfile = outname;
}
-static void srec_filename(char *inname, char *outname, efunc error)
+static void srec_filename(char *inname, char *outname)
{
- standard_extension(inname, outname, ".srec", error);
+ standard_extension(inname, outname, ".srec");
infile = inname;
outfile = outname;
}
return 0;
}
-static void binfmt_init(FILE *afp, efunc errfunc, ldfunc ldef, evalfunc eval);
struct ofmt of_bin, of_ith, of_srec;
+static void binfmt_init(void);
static void do_output_bin(void);
static void do_output_ith(void);
static void do_output_srec(void);
-static void bin_init(FILE *afp, efunc errfunc, ldfunc ldef, evalfunc eval)
+static void bin_init(void)
{
- my_ofmt = &of_bin;
do_output = do_output_bin;
- binfmt_init(afp, errfunc, ldef, eval);
+ binfmt_init();
}
-static void ith_init(FILE *afp, efunc errfunc, ldfunc ldef, evalfunc eval)
+static void ith_init(void)
{
- my_ofmt = &of_ith;
do_output = do_output_ith;
- binfmt_init(afp, errfunc, ldef, eval);
+ binfmt_init();
}
-static void srec_init(FILE *afp, efunc errfunc, ldfunc ldef, evalfunc eval)
+static void srec_init(void)
{
- my_ofmt = &of_srec;
do_output = do_output_srec;
- binfmt_init(afp, errfunc, ldef, eval);
+ binfmt_init();
}
-static void binfmt_init(FILE *afp, efunc errfunc, ldfunc ldef, evalfunc eval)
+static void binfmt_init(void)
{
- fp = afp;
- error = errfunc;
-
- (void)eval; /* Don't warn that this parameter is unused. */
- (void)ldef; /* Placate optimizers. */
-
maxbits = 64; /* Support 64-bit Segments */
relocs = NULL;
reloctail = &relocs;
/* Pad the space between sections. */
nasm_assert(addr <= s->start);
- fwritezero(s->start - addr, fp);
+ fwritezero(s->start - addr, ofile);
/* Write the section to the output file. */
- saa_fpwrite(s->contents, fp);
+ saa_fpwrite(s->contents, ofile);
/* Keep track of the current file position */
addr = s->start + s->length;
p += sprintf(p, "%02X", dptr[i]);
p += sprintf(p, "%02X\n", csum);
- if (fwrite(buf, 1, p-buf, fp) != (size_t)(p-buf))
+ if (fwrite(buf, 1, p-buf, ofile) != (size_t)(p-buf))
return -1;
return 0;
p += sprintf(p, "%02X", dptr[i]);
p += sprintf(p, "%02X\n", csum);
- if (fwrite(buf, 1, p-buf, fp) != (size_t)(p-buf))
+ if (fwrite(buf, 1, p-buf, ofile) != (size_t)(p-buf))
return -1;
return 0;
#include "nasmlib.h"
#include "saa.h"
#include "raa.h"
+#include "eval.h"
#include "output/outform.h"
#include "output/outlib.h"
int32_t namlen; /* full name length */
};
-static FILE *coffp;
-static efunc error;
static char coff_infile[FILENAME_MAX];
struct Section {
static struct SAA *strs;
static uint32_t strslen;
-static void coff_gen_init(FILE *, efunc);
+static void coff_gen_init(void);
static void coff_sect_write(struct Section *, const uint8_t *,
uint32_t);
static void coff_write(void);
static void coff_write_relocs(struct Section *);
static void coff_write_symbols(void);
-static void coff_win32_init(FILE * fp, efunc errfunc,
- ldfunc ldef, evalfunc eval)
+static void coff_win32_init(void)
{
- win32 = true; win64 = false;
- (void)ldef; /* placate optimizers */
- (void)eval;
- coff_gen_init(fp, errfunc);
+ win32 = true;
+ win64 = false;
+ coff_gen_init();
}
-static void coff_win64_init(FILE * fp, efunc errfunc,
- ldfunc ldef, evalfunc eval)
+static void coff_win64_init(void)
{
- extern struct ofmt of_win64;
-
maxbits = 64;
- win32 = false; win64 = true;
- (void)ldef; /* placate optimizers */
- (void)eval;
- coff_gen_init(fp, errfunc);
+ win32 = false;
+ win64 = true;
+ coff_gen_init();
imagebase_sect = seg_alloc()+1;
- ldef(WRT_IMAGEBASE,imagebase_sect,0,NULL,false,false,&of_win64,errfunc);
+ define_label(WRT_IMAGEBASE, imagebase_sect, 0, NULL, false, false,
+ ofmt, nasm_error);
}
-static void coff_std_init(FILE * fp, efunc errfunc, ldfunc ldef,
- evalfunc eval)
+static void coff_std_init(void)
{
win32 = win64 = false;
- (void)ldef; /* placate optimizers */
- (void)eval;
- coff_gen_init(fp, errfunc);
+ coff_gen_init();
}
-static void coff_gen_init(FILE * fp, efunc errfunc)
+static void coff_gen_init(void)
{
- coffp = fp;
- error = errfunc;
sects = NULL;
nsects = sectlen = 0;
syms = saa_init(sizeof(struct Symbol));
if (*p)
*p++ = '\0';
if (strlen(name) > 8) {
- error(ERR_WARNING, "COFF section names limited to 8 characters:"
+ nasm_error(ERR_WARNING, "COFF section names limited to 8 characters:"
" truncating");
name[8] = '\0';
}
flags = RDATA_FLAGS;
else {
flags = DATA_FLAGS; /* gotta do something */
- error(ERR_NONFATAL, "standard COFF does not support"
+ nasm_error(ERR_NONFATAL, "standard COFF does not support"
" read-only data sections");
}
} else if (!nasm_stricmp(q, "bss")) {
flags = INFO_FLAGS;
else {
flags = DATA_FLAGS; /* gotta do something */
- error(ERR_NONFATAL, "standard COFF does not support"
+ nasm_error(ERR_NONFATAL, "standard COFF does not support"
" informational sections");
}
} else if (!nasm_strnicmp(q, "align=", 6)) {
if (!(win32 | win64))
- error(ERR_NONFATAL, "standard COFF does not support"
+ nasm_error(ERR_NONFATAL, "standard COFF does not support"
" section alignment specification");
else {
if (q[6 + strspn(q + 6, "0123456789")])
- error(ERR_NONFATAL,
+ nasm_error(ERR_NONFATAL,
"argument to `align' is not numeric");
else {
unsigned int align = atoi(q + 6);
if (!align || ((align - 1) & align))
- error(ERR_NONFATAL, "argument to `align' is not a"
+ nasm_error(ERR_NONFATAL, "argument to `align' is not a"
" power of two");
else if (align > 64)
- error(ERR_NONFATAL, "Win32 cannot align sections"
+ nasm_error(ERR_NONFATAL, "Win32 cannot align sections"
" to better than 64-byte boundaries");
else {
align_and = ~0x00F00000L;
sects[i]->flags |= align_or;
} else if (pass == 1) {
if (flags)
- error(ERR_WARNING, "section attributes ignored on"
+ nasm_error(ERR_WARNING, "section attributes ignored on"
" redeclaration of section `%s'", name);
}
struct Symbol *sym;
if (special)
- error(ERR_NONFATAL, "COFF format does not support any"
+ nasm_error(ERR_NONFATAL, "COFF format does not support any"
" special symbol types");
if (name[0] == '.' && name[1] == '.' && name[2] != '@') {
if (strcmp(name,WRT_IMAGEBASE))
- error(ERR_NONFATAL, "unrecognized special symbol `%s'", name);
+ nasm_error(ERR_NONFATAL, "unrecognized special symbol `%s'", name);
return;
}
if (wrt != NO_SEG && !win64) {
wrt = NO_SEG; /* continue to do _something_ */
- error(ERR_NONFATAL, "WRT not supported by COFF output formats");
+ nasm_error(ERR_NONFATAL, "WRT not supported by COFF output formats");
}
/*
*/
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;
}
if (!s) {
int tempint; /* ignored */
if (segto != coff_section_names(".text", 2, &tempint))
- error(ERR_PANIC, "strange segment conditions in COFF driver");
+ nasm_error(ERR_PANIC, "strange segment conditions in COFF driver");
else
s = sects[nsects - 1];
}
wrt = imagebase_sect;
if (!s->data && type != OUT_RESERVE) {
- error(ERR_WARNING, "attempt to initialize memory in"
+ nasm_error(ERR_WARNING, "attempt to initialize memory in"
" BSS section `%s': ignored", s->name);
s->len += realsize(type, size);
return;
if (type == OUT_RESERVE) {
if (s->data) {
- error(ERR_WARNING, "uninitialised space declared in"
+ nasm_error(ERR_WARNING, "uninitialised space declared in"
" non-BSS section `%s': zeroing", s->name);
coff_sect_write(s, NULL, size);
} else
s->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");
coff_sect_write(s, data, size);
} else if (type == OUT_ADDRESS) {
if (!(win64)) {
if (size != 4 && (segment != NO_SEG || wrt != NO_SEG))
- error(ERR_NONFATAL, "COFF format does not support non-32-bit"
+ nasm_error(ERR_NONFATAL, "COFF format does not support non-32-bit"
" relocations");
else {
int32_t fix = 0;
if (segment != NO_SEG || wrt != NO_SEG) {
if (wrt != NO_SEG) {
- error(ERR_NONFATAL, "COFF format does not support"
+ nasm_error(ERR_NONFATAL, "COFF format does not support"
" WRT types");
} else if (segment % 2) {
- error(ERR_NONFATAL, "COFF format does not support"
+ nasm_error(ERR_NONFATAL, "COFF format does not support"
" segment base references");
} else
fix = coff_add_reloc(s, segment, IMAGE_REL_I386_DIR32);
p = mydata;
if (size == 8) {
if (wrt == imagebase_sect) {
- error(ERR_NONFATAL, "operand size mismatch: 'wrt "
+ nasm_error(ERR_NONFATAL, "operand size mismatch: 'wrt "
WRT_IMAGEBASE "' is a 32-bit operand");
}
fix = coff_add_reloc(s, segment, IMAGE_REL_AMD64_ADDR64);
}
}
} else if (type == OUT_REL2ADR) {
- error(ERR_NONFATAL, "COFF format does not support 16-bit"
+ nasm_error(ERR_NONFATAL, "COFF format does not support 16-bit"
" relocations");
} else if (type == OUT_REL4ADR) {
if (segment == segto && !(win64)) /* Acceptable for RIP-relative */
- error(ERR_PANIC, "intra-segment OUT_REL4ADR");
+ nasm_error(ERR_PANIC, "intra-segment OUT_REL4ADR");
else if (segment == NO_SEG && win32)
- error(ERR_NONFATAL, "Win32 COFF does not correctly support"
+ nasm_error(ERR_NONFATAL, "Win32 COFF does not correctly support"
" relative references to absolute addresses");
else {
int32_t fix = 0;
if (segment != NO_SEG && segment % 2) {
- error(ERR_NONFATAL, "COFF format does not support"
+ nasm_error(ERR_NONFATAL, "COFF format does not support"
" segment base references");
} else
fix = coff_add_reloc(s, segment,
}
if (!*name) {
- error(ERR_NONFATAL, "`export' directive requires export name");
+ nasm_error(ERR_NONFATAL, "`export' directive requires export name");
return 1;
}
if (*q) {
- error(ERR_NONFATAL, "unrecognized export qualifier `%s'", q);
+ nasm_error(ERR_NONFATAL, "unrecognized export qualifier `%s'", q);
return 1;
}
AddExport(name);
}
}
if (n == nsyms) {
- error(ERR_NONFATAL,
+ nasm_error(ERR_NONFATAL,
"`safeseh' directive requires valid symbol");
}
}
* Output the COFF header.
*/
if (win64)
- fwriteint16_t(0x8664, coffp); /* MACHINE_x86-64 */
+ fwriteint16_t(0x8664, ofile); /* MACHINE_x86-64 */
else
- fwriteint16_t(0x014C, coffp); /* MACHINE_i386 */
- fwriteint16_t(nsects, coffp); /* number of sections */
- fwriteint32_t(time(NULL), coffp); /* time stamp */
- fwriteint32_t(sympos, coffp);
- fwriteint32_t(nsyms + initsym, coffp);
- fwriteint16_t(0, coffp); /* no optional header */
+ fwriteint16_t(0x014C, ofile); /* MACHINE_i386 */
+ fwriteint16_t(nsects, ofile); /* number of sections */
+ fwriteint32_t(time(NULL), ofile); /* time stamp */
+ fwriteint32_t(sympos, ofile);
+ fwriteint32_t(nsyms + initsym, ofile);
+ fwriteint16_t(0, ofile); /* no optional header */
/* Flags: 32-bit, no line numbers. Win32 doesn't even bother with them. */
- fwriteint16_t((win32 | win64) ? 0 : 0x104, coffp);
+ fwriteint16_t((win32 | win64) ? 0 : 0x104, ofile);
/*
* Output the section headers.
*/
for (i = 0; i < nsects; i++)
if (sects[i]->data) {
- saa_fpwrite(sects[i]->data, coffp);
+ saa_fpwrite(sects[i]->data, ofile);
coff_write_relocs(sects[i]);
}
* Output the symbol and string tables.
*/
coff_write_symbols();
- fwriteint32_t(strslen + 4, coffp); /* length includes length count */
- saa_fpwrite(strs, coffp);
+ fwriteint32_t(strslen + 4, ofile); /* length includes length count */
+ saa_fpwrite(strs, ofile);
}
static void coff_section_header(char *name, int32_t vsize,
memset(padname, 0, 8);
strncpy(padname, name, 8);
- fwrite(padname, 8, 1, coffp);
- fwriteint32_t(0, coffp); /* Virtual size field - set to 0 or vsize */
- fwriteint32_t(0L, coffp); /* RVA/offset - we ignore */
- fwriteint32_t(datalen, coffp);
- fwriteint32_t(datapos, coffp);
- fwriteint32_t(relpos, coffp);
- fwriteint32_t(0L, coffp); /* no line numbers - we don't do 'em */
- fwriteint16_t(nrelocs, coffp);
- fwriteint16_t(0, coffp); /* again, no line numbers */
- fwriteint32_t(flags, coffp);
+ fwrite(padname, 8, 1, ofile);
+ fwriteint32_t(0, ofile); /* Virtual size field - set to 0 or vsize */
+ fwriteint32_t(0L, ofile); /* RVA/offset - we ignore */
+ fwriteint32_t(datalen, ofile);
+ fwriteint32_t(datapos, ofile);
+ fwriteint32_t(relpos, ofile);
+ fwriteint32_t(0L, ofile); /* no line numbers - we don't do 'em */
+ fwriteint16_t(nrelocs, ofile);
+ fwriteint16_t(0, ofile); /* again, no line numbers */
+ fwriteint32_t(flags, ofile);
}
static void coff_write_relocs(struct Section *s)
struct Reloc *r;
for (r = s->head; r; r = r->next) {
- fwriteint32_t(r->address, coffp);
+ fwriteint32_t(r->address, ofile);
fwriteint32_t(r->symbol + (r->symbase == REAL_SYMBOLS ? initsym :
r->symbase == ABS_SYMBOL ? initsym - 1 :
r->symbase == SECT_SYMBOLS ? 2 : 0),
- coffp);
- fwriteint16_t(r->type, coffp);
+ ofile);
+ fwriteint16_t(r->type, ofile);
}
}
if (name) {
memset(padname, 0, 8);
strncpy(padname, name, 8);
- fwrite(padname, 8, 1, coffp);
+ fwrite(padname, 8, 1, ofile);
} else {
- fwriteint32_t(0, coffp);
- fwriteint32_t(strpos, coffp);
+ fwriteint32_t(0, ofile);
+ fwriteint32_t(strpos, ofile);
}
- fwriteint32_t(value, coffp);
- fwriteint16_t(section, coffp);
- fwriteint16_t(type, coffp);
- fputc(storageclass, coffp);
- fputc(aux, coffp);
+ fwriteint32_t(value, ofile);
+ fwriteint16_t(section, ofile);
+ fwriteint16_t(type, ofile);
+ fputc(storageclass, ofile);
+ fputc(aux, ofile);
}
static void coff_write_symbols(void)
coff_symbol(".file", 0L, 0L, -2, 0, 0x67, 1);
memset(filename, 0, 18);
strncpy(filename, coff_infile, 18);
- fwrite(filename, 18, 1, coffp);
+ fwrite(filename, 18, 1, ofile);
/*
* The section records, with their auxiliaries.
for (i = 0; i < (uint32_t) nsects; i++) {
coff_symbol(sects[i]->name, 0L, 0L, i + 1, 0, 3, 1);
- fwriteint32_t(sects[i]->len, coffp);
- fwriteint16_t(sects[i]->nrelocs, coffp);
- fwrite(filename, 12, 1, coffp);
+ fwriteint32_t(sects[i]->len, ofile);
+ fwriteint16_t(sects[i]->nrelocs, ofile);
+ fwrite(filename, 12, 1, ofile);
}
/*
return segment;
}
-static void coff_std_filename(char *inname, char *outname, efunc error)
+static void coff_std_filename(char *inname, char *outname)
{
strcpy(coff_infile, inname);
- standard_extension(inname, outname, ".o", error);
+ standard_extension(inname, outname, ".o");
}
-static void coff_win32_filename(char *inname, char *outname, efunc error)
+static void coff_win32_filename(char *inname, char *outname)
{
strcpy(coff_infile, inname);
- standard_extension(inname, outname, ".obj", error);
+ standard_extension(inname, outname, ".obj");
}
extern macros_t coff_stdmac[];
char *name;
} *dbgsect;
-FILE *dbgf;
-efunc dbgef;
-
struct ofmt of_dbg;
-static void dbg_init(FILE * fp, efunc errfunc, ldfunc ldef, evalfunc eval)
+static void dbg_init(void)
{
- (void)eval;
-
- dbgf = fp;
- dbgef = errfunc;
dbgsect = NULL;
- (void)ldef;
- fprintf(fp, "NASM Output format debug dump\n");
+ fprintf(ofile, "NASM Output format debug dump\n");
}
static void dbg_cleanup(int debuginfo)
*bits = 16;
if (!name)
- fprintf(dbgf, "section_name on init: returning %d\n",
+ fprintf(ofile, "section_name on init: returning %d\n",
seg = seg_alloc());
else {
int n = strcspn(name, " \t");
s->number = seg = seg_alloc();
s->next = dbgsect;
dbgsect = s;
- fprintf(dbgf, "section_name %s (pass %d): returning %d\n",
+ fprintf(ofile, "section_name %s (pass %d): returning %d\n",
name, pass, seg);
}
}
static void dbg_deflabel(char *name, int32_t segment, int64_t offset,
int is_global, char *special)
{
- fprintf(dbgf, "deflabel %s := %08"PRIx32":%016"PRIx64" %s (%d)%s%s\n",
+ fprintf(ofile, "deflabel %s := %08"PRIx32":%016"PRIx64" %s (%d)%s%s\n",
name, segment, offset,
is_global == 2 ? "common" : is_global ? "global" : "local",
is_global, special ? ": " : "", special);
int32_t ldata;
int id;
- fprintf(dbgf, "out to %"PRIx32", len = %"PRIu64": ", segto, size);
+ fprintf(ofile, "out to %"PRIx32", len = %"PRIu64": ", segto, size);
switch (type) {
case OUT_RESERVE:
- fprintf(dbgf, "reserved.\n");
+ fprintf(ofile, "reserved.\n");
break;
case OUT_RAWDATA:
- fprintf(dbgf, "raw data = ");
+ fprintf(ofile, "raw data = ");
while (size--) {
id = *(uint8_t *)data;
data = (char *)data + 1;
- fprintf(dbgf, "%02x ", id);
+ fprintf(ofile, "%02x ", id);
}
- fprintf(dbgf, "\n");
+ fprintf(ofile, "\n");
break;
case OUT_ADDRESS:
ldata = *(int64_t *)data;
- fprintf(dbgf, "addr %08"PRIx32" (seg %08"PRIx32", wrt %08"PRIx32")\n", ldata,
+ fprintf(ofile, "addr %08"PRIx32" (seg %08"PRIx32", wrt %08"PRIx32")\n", ldata,
segment, wrt);
break;
case OUT_REL2ADR:
- fprintf(dbgf, "rel2adr %04"PRIx16" (seg %08"PRIx32")\n",
+ fprintf(ofile, "rel2adr %04"PRIx16" (seg %08"PRIx32")\n",
(uint16_t)*(int64_t *)data, segment);
break;
case OUT_REL4ADR:
- fprintf(dbgf, "rel4adr %08"PRIx32" (seg %08"PRIx32")\n",
+ fprintf(ofile, "rel4adr %08"PRIx32" (seg %08"PRIx32")\n",
(uint32_t)*(int64_t *)data,
segment);
break;
case OUT_REL8ADR:
- fprintf(dbgf, "rel8adr %016"PRIx64" (seg %08"PRIx32")\n",
+ fprintf(ofile, "rel8adr %016"PRIx64" (seg %08"PRIx32")\n",
(uint64_t)*(int64_t *)data, segment);
break;
default:
- fprintf(dbgf, "unknown\n");
+ fprintf(ofile, "unknown\n");
break;
}
}
static int dbg_directive(enum directives directive, char *value, int pass)
{
- fprintf(dbgf, "directive [%s] value [%s] (pass %d)\n",
+ fprintf(ofile, "directive [%s] value [%s] (pass %d)\n",
directives[directive], value, pass);
return 1;
}
-static void dbg_filename(char *inname, char *outname, efunc error)
+static void dbg_filename(char *inname, char *outname)
{
- standard_extension(inname, outname, ".dbg", error);
+ standard_extension(inname, outname, ".dbg");
}
static int dbg_set_info(enum geninfo type, char **val)
char *types[] = {
"unknown", "label", "byte", "word", "dword", "float", "qword", "tbyte"
};
-void dbgdbg_init(struct ofmt *of, void *id, FILE * fp, efunc error)
+void dbgdbg_init(void)
{
- (void)of;
- (void)id;
- (void)fp;
- (void)error;
- fprintf(fp, " With debug info\n");
+ fprintf(ofile, " With debug info\n");
}
static void dbgdbg_cleanup(void)
{
static void dbgdbg_linnum(const char *lnfname, int32_t lineno, int32_t segto)
{
- fprintf(dbgf, "dbglinenum %s(%"PRId32") := %08"PRIx32"\n",
+ fprintf(ofile, "dbglinenum %s(%"PRId32") := %08"PRIx32"\n",
lnfname, lineno, segto);
}
static void dbgdbg_deflabel(char *name, int32_t segment,
int64_t offset, int is_global, char *special)
{
- fprintf(dbgf, "dbglabel %s := %08"PRIx32":%016"PRIx64" %s (%d)%s%s\n",
+ fprintf(ofile, "dbglabel %s := %08"PRIx32":%016"PRIx64" %s (%d)%s%s\n",
name,
segment, offset,
is_global == 2 ? "common" : is_global ? "global" : "local",
}
static void dbgdbg_define(const char *type, const char *params)
{
- fprintf(dbgf, "dbgdirective [%s] value [%s]\n", type, params);
+ fprintf(ofile, "dbgdirective [%s] value [%s]\n", type, params);
}
static void dbgdbg_output(int output_type, void *param)
{
}
static void dbgdbg_typevalue(int32_t type)
{
- fprintf(dbgf, "new type: %s(%"PRIX32")\n",
+ fprintf(ofile, "new type: %s(%"PRIX32")\n",
types[TYM_TYPE(type) >> 3], TYM_ELEMENTS(type));
}
static struct dfmt debug_debug_form = {
#include "saa.h"
#include "raa.h"
#include "stdscan.h"
+#include "eval.h"
#include "output/outform.h"
#include "output/outlib.h"
#include "rbtree.h"
static struct SAA *strs;
static uint32_t strslen;
-static FILE *elffp;
-static efunc error;
-static evalfunc evaluate;
-
static struct Symbol *fwds;
static char elf_module[FILENAME_MAX];
static void stabs32_cleanup(void);
/* dwarf debugging routines */
-static void dwarf32_init(struct ofmt *, void *, FILE *, efunc);
+static void dwarf32_init(void);
static void dwarf32_linenum(const char *filename, int32_t linenumber, int32_t);
static void dwarf32_output(int, void *);
static void dwarf32_generate(void);
static int32_t elf_got_sect, elf_plt_sect;
static int32_t elf_sym_sect, elf_tlsie_sect;
-static void elf_init(FILE * fp, efunc errfunc, ldfunc ldef, evalfunc eval)
+static void elf_init(void)
{
- elffp = fp;
- error = errfunc;
- evaluate = eval;
- (void)ldef; /* placate optimisers */
sects = NULL;
nsects = sectlen = 0;
syms = saa_init((int32_t)sizeof(struct Symbol));
fwds = NULL;
elf_gotpc_sect = seg_alloc();
- ldef("..gotpc", elf_gotpc_sect + 1, 0L, NULL, false, false, &of_elf32,
- error);
+ define_label("..gotpc", elf_gotpc_sect + 1, 0L, NULL, false, false, &of_elf32,
+ nasm_error);
elf_gotoff_sect = seg_alloc();
- ldef("..gotoff", elf_gotoff_sect + 1, 0L, NULL, false, false, &of_elf32,
- error);
+ define_label("..gotoff", elf_gotoff_sect + 1, 0L, NULL, false, false, &of_elf32,
+ nasm_error);
elf_got_sect = seg_alloc();
- ldef("..got", elf_got_sect + 1, 0L, NULL, false, false, &of_elf32,
- error);
+ define_label("..got", elf_got_sect + 1, 0L, NULL, false, false, &of_elf32,
+ nasm_error);
elf_plt_sect = seg_alloc();
- ldef("..plt", elf_plt_sect + 1, 0L, NULL, false, false, &of_elf32,
- error);
+ define_label("..plt", elf_plt_sect + 1, 0L, NULL, false, false, &of_elf32,
+ nasm_error);
elf_sym_sect = seg_alloc();
- ldef("..sym", elf_sym_sect + 1, 0L, NULL, false, false, &of_elf32,
- error);
+ define_label("..sym", elf_sym_sect + 1, 0L, NULL, false, false, &of_elf32,
+ nasm_error);
elf_tlsie_sect = seg_alloc();
- ldef("..tlsie", elf_tlsie_sect + 1, 0L, NULL, false, false, &of_elf32,
- error);
+ define_label("..tlsie", elf_tlsie_sect + 1, 0L, NULL, false, false, &of_elf32,
+ nasm_error);
def_seg = seg_alloc();
}
-static void elf_init_hack(FILE * fp, efunc errfunc, ldfunc ldef,
- evalfunc eval)
+static void elf_init_hack(void)
{
of_elf32.current_dfmt = of_elf.current_dfmt; /* Sync debugging format */
- elf_init(fp, errfunc, ldef, eval);
+ elf_init();
}
static void elf_cleanup(int debuginfo)
if (align == 0)
align = 1;
if ((align - 1) & align) { /* means it's not a power of two */
- error(ERR_NONFATAL, "section alignment %d is not"
+ nasm_error(ERR_NONFATAL, "section alignment %d is not"
" a power of two", align);
align = 1;
}
} else if (!nasm_stricmp(q, "nobits")) {
type = SHT_NOBITS;
} else if (pass == 1) {
- error(ERR_WARNING, "Unknown section attribute '%s' ignored on"
+ nasm_error(ERR_WARNING, "Unknown section attribute '%s' ignored on"
" declaration of section `%s'", q, name);
}
}
if (!strcmp(name, ".shstrtab") ||
!strcmp(name, ".symtab") ||
!strcmp(name, ".strtab")) {
- error(ERR_NONFATAL, "attempt to redefine reserved section"
+ nasm_error(ERR_NONFATAL, "attempt to redefine reserved section"
"name `%s'", name);
return NO_SEG;
}
if ((type && sects[i]->type != type)
|| (align && sects[i]->align != align)
|| (flags_and && ((sects[i]->flags & flags_and) != flags_or)))
- error(ERR_WARNING, "section attributes ignored on"
+ nasm_error(ERR_WARNING, "section attributes ignored on"
" redeclaration of section `%s'", name);
}
if (strcmp(name, "..gotpc") && strcmp(name, "..gotoff") &&
strcmp(name, "..got") && strcmp(name, "..plt") &&
strcmp(name, "..sym") && strcmp(name, "..tlsie"))
- error(ERR_NONFATAL, "unrecognised special symbol `%s'", name);
+ nasm_error(ERR_NONFATAL, "unrecognised special symbol `%s'", name);
return;
}
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);
if (nsects == 0 && segment == def_seg) {
int tempint;
if (segment != elf_section_names(".text", 2, &tempint))
- error(ERR_PANIC,
+ nasm_error(ERR_PANIC,
"strange segment conditions in ELF driver");
sym->section = nsects;
} else {
bool err;
sym->symv.key = readnum(special, &err);
if (err)
- error(ERR_NONFATAL, "alignment constraint `%s' is not a"
+ nasm_error(ERR_NONFATAL, "alignment constraint `%s' is not a"
" valid number", special);
else if ((sym->symv.key | (sym->symv.key - 1))
!= 2 * sym->symv.key - 1)
- error(ERR_NONFATAL, "alignment constraint `%s' is not a"
+ nasm_error(ERR_NONFATAL, "alignment constraint `%s' is not a"
" power of two", special);
}
special_used = true;
else if (!nasm_strnicmp(special, "notype", n))
sym->type |= STT_NOTYPE;
else
- error(ERR_NONFATAL, "unrecognised symbol type `%.*s'",
+ nasm_error(ERR_NONFATAL, "unrecognised symbol type `%.*s'",
n, special);
special += n;
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;
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);
nlocals++;
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 elf_add_reloc(struct Section *sect, int32_t segment, int type)
}
if (!s) {
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
elf_add_reloc(sect, segment, type);
srb = rb_search(s->gsyms, offset);
if (!srb || (exact && srb->key != offset)) {
- 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;
}
*/
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;
}
if (!s) {
int tempint; /* ignored */
if (segto != elf_section_names(".text", 2, &tempint))
- error(ERR_PANIC, "strange segment conditions in ELF driver");
+ nasm_error(ERR_PANIC, "strange segment conditions in ELF driver");
else {
s = sects[nsects - 1];
i = nsects - 1;
/* end of debugging stuff */
if (s->type == SHT_NOBITS && type != OUT_RESERVE) {
- error(ERR_WARNING, "attempt to initialize memory in"
+ nasm_error(ERR_WARNING, "attempt to initialize memory in"
" BSS section `%s': ignored", s->name);
s->len += realsize(type, size);
return;
if (type == OUT_RESERVE) {
if (s->type == SHT_PROGBITS) {
- error(ERR_WARNING, "uninitialized space declared in"
+ nasm_error(ERR_WARNING, "uninitialized space declared in"
" non-BSS section `%s': zeroing", s->name);
elf_sect_write(s, NULL, size);
} else
s->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");
elf_sect_write(s, data, size);
} else if (type == OUT_ADDRESS) {
bool gnu16 = false;
addr = *(int64_t *)data;
if (segment != NO_SEG) {
if (segment % 2) {
- error(ERR_NONFATAL, "ELF format does not support"
+ nasm_error(ERR_NONFATAL, "ELF format does not support"
" segment base references");
} else {
if (wrt == NO_SEG) {
R_386_32, false);
}
} else if (wrt == elf_plt_sect + 1) {
- error(ERR_NONFATAL, "ELF format cannot produce non-PC-"
+ nasm_error(ERR_NONFATAL, "ELF format cannot produce non-PC-"
"relative PLT references");
} else {
- error(ERR_NONFATAL, "ELF format does not support this"
+ nasm_error(ERR_NONFATAL, "ELF format does not support this"
" use of WRT");
wrt = NO_SEG; /* we can at least _try_ to continue */
}
}
p = mydata;
if (gnu16) {
- error(ERR_WARNING | ERR_WARN_GNUELF,
+ nasm_error(ERR_WARNING | ERR_WARN_GNUELF,
"16-bit relocations in ELF is a GNU extension");
WRITESHORT(p, addr);
} else {
if (size != 4 && segment != NO_SEG) {
- error(ERR_NONFATAL,
+ nasm_error(ERR_NONFATAL,
"Unsupported non-32-bit ELF relocation");
}
WRITELONG(p, addr);
elf_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, "ELF format does not support"
+ nasm_error(ERR_NONFATAL, "ELF format does not support"
" segment base references");
} else {
if (wrt == NO_SEG) {
- error(ERR_WARNING | ERR_WARN_GNUELF,
+ nasm_error(ERR_WARNING | ERR_WARN_GNUELF,
"16-bit relocations in ELF is a GNU extension");
elf_add_reloc(s, segment, R_386_PC16);
} else {
- error(ERR_NONFATAL,
+ nasm_error(ERR_NONFATAL,
"Unsupported non-32-bit ELF relocation");
}
}
elf_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, "ELF format does not support"
+ nasm_error(ERR_NONFATAL, "ELF format does not support"
" segment base references");
} else {
if (wrt == NO_SEG) {
} else if (wrt == elf_gotpc_sect + 1 ||
wrt == elf_gotoff_sect + 1 ||
wrt == elf_got_sect + 1) {
- error(ERR_NONFATAL, "ELF format cannot produce PC-"
+ nasm_error(ERR_NONFATAL, "ELF format cannot produce PC-"
"relative GOT references");
} else {
- error(ERR_NONFATAL, "ELF format does not support this"
+ nasm_error(ERR_NONFATAL, "ELF format does not support this"
" use of WRT");
wrt = NO_SEG; /* we can at least _try_ to continue */
}
/*
* Output the ELF header.
*/
- fwrite("\177ELF\1\1\1", 7, 1, elffp);
- fputc(elf_osabi, elffp);
- fputc(elf_abiver, elffp);
- fwritezero(7, elffp);
- fwriteint16_t(1, elffp); /* ET_REL relocatable file */
- fwriteint16_t(3, elffp); /* EM_386 processor ID */
- fwriteint32_t(1L, elffp); /* EV_CURRENT file format version */
- fwriteint32_t(0L, elffp); /* no entry point */
- fwriteint32_t(0L, elffp); /* no program header table */
- fwriteint32_t(0x40L, elffp); /* section headers straight after
+ fwrite("\177ELF\1\1\1", 7, 1, ofile);
+ fputc(elf_osabi, ofile);
+ fputc(elf_abiver, ofile);
+ fwritezero(7, ofile);
+ fwriteint16_t(1, ofile); /* ET_REL relocatable file */
+ fwriteint16_t(3, ofile); /* EM_386 processor ID */
+ fwriteint32_t(1L, ofile); /* EV_CURRENT file format version */
+ fwriteint32_t(0L, ofile); /* no entry point */
+ fwriteint32_t(0L, ofile); /* no program header table */
+ fwriteint32_t(0x40L, ofile); /* section headers straight after
* ELF header plus alignment */
- fwriteint32_t(0L, elffp); /* 386 defines no special flags */
- fwriteint16_t(0x34, elffp); /* size of ELF header */
- fwriteint16_t(0, elffp); /* no program header table, again */
- fwriteint16_t(0, elffp); /* still no program header table */
- fwriteint16_t(0x28, elffp); /* size of section header */
- fwriteint16_t(nsections, elffp); /* number of sections */
- fwriteint16_t(sec_shstrtab, elffp); /* string table section index for
+ fwriteint32_t(0L, ofile); /* 386 defines no special flags */
+ fwriteint16_t(0x34, ofile); /* size of ELF header */
+ fwriteint16_t(0, ofile); /* no program header table, again */
+ fwriteint16_t(0, ofile); /* still no program header table */
+ fwriteint16_t(0x28, ofile); /* size of section header */
+ fwriteint16_t(nsections, ofile); /* number of sections */
+ fwriteint16_t(sec_shstrtab, ofile); /* string table section index for
* section header table */
- fwriteint32_t(0L, elffp); /* align to 0x40 bytes */
- fwriteint32_t(0L, elffp);
- fwriteint32_t(0L, elffp);
+ fwriteint32_t(0L, ofile); /* align to 0x40 bytes */
+ fwriteint32_t(0L, ofile);
+ fwriteint32_t(0L, ofile);
/*
* Build the symbol table and relocation tables.
loclen, 0, 0, 1, 0);
p += strlen(p) + 1;
}
- fwritezero(align, elffp);
+ fwritezero(align, ofile);
/*
* Now output the sections.
elf_sects[elf_nsect].is_saa = is_saa;
elf_nsect++;
- fwriteint32_t((int32_t)name, elffp);
- fwriteint32_t((int32_t)type, elffp);
- fwriteint32_t((int32_t)flags, elffp);
- fwriteint32_t(0L, elffp); /* no address, ever, in object files */
- fwriteint32_t(type == 0 ? 0L : elf_foffs, elffp);
- fwriteint32_t(datalen, elffp);
+ fwriteint32_t((int32_t)name, ofile);
+ fwriteint32_t((int32_t)type, ofile);
+ fwriteint32_t((int32_t)flags, ofile);
+ fwriteint32_t(0L, ofile); /* no address, ever, in object files */
+ fwriteint32_t(type == 0 ? 0L : elf_foffs, ofile);
+ fwriteint32_t(datalen, ofile);
if (data)
elf_foffs += (datalen + SEG_ALIGN_1) & ~SEG_ALIGN_1;
- fwriteint32_t((int32_t)link, elffp);
- fwriteint32_t((int32_t)info, elffp);
- fwriteint32_t((int32_t)align, elffp);
- fwriteint32_t((int32_t)eltsize, elffp);
+ fwriteint32_t((int32_t)link, ofile);
+ fwriteint32_t((int32_t)info, ofile);
+ fwriteint32_t((int32_t)align, ofile);
+ fwriteint32_t((int32_t)eltsize, ofile);
}
static void elf_write_sections(void)
int32_t reallen = (len + SEG_ALIGN_1) & ~SEG_ALIGN_1;
int32_t align = reallen - len;
if (elf_sects[i].is_saa)
- saa_fpwrite(elf_sects[i].data, elffp);
+ saa_fpwrite(elf_sects[i].data, ofile);
else
- fwrite(elf_sects[i].data, len, 1, elffp);
- fwritezero(align, elffp);
+ fwrite(elf_sects[i].data, len, 1, ofile);
+ fwritezero(align, ofile);
}
}
n = readnum(value, &err);
if (err) {
- error(ERR_NONFATAL, "`osabi' directive requires a parameter");
+ nasm_error(ERR_NONFATAL, "`osabi' directive requires a parameter");
return 1;
}
if (n < 0 || n > 255) {
- error(ERR_NONFATAL, "valid osabi numbers are 0 to 255");
+ nasm_error(ERR_NONFATAL, "valid osabi numbers are 0 to 255");
return 1;
}
elf_osabi = n;
n = readnum(p+1, &err);
if (err || n < 0 || n > 255) {
- error(ERR_NONFATAL, "invalid ABI version number (valid: 0 to 255)");
+ nasm_error(ERR_NONFATAL, "invalid ABI version number (valid: 0 to 255)");
return 1;
}
}
}
-static void elf_filename(char *inname, char *outname, efunc error)
+static void elf_filename(char *inname, char *outname)
{
strcpy(elf_module, inname);
- standard_extension(inname, outname, ".o", error);
+ standard_extension(inname, outname, ".o");
}
extern macros_t elf_stdmac[];
/* dwarf routines */
-static void dwarf32_init(struct ofmt *of, void *id, FILE * fp, efunc error)
+static void dwarf32_init(void)
{
- (void)of;
- (void)id;
- (void)fp;
- (void)error;
-
ndebugs = 3; /* 3 debug symbols */
}
#include "saa.h"
#include "raa.h"
#include "stdscan.h"
+#include "eval.h"
#include "output/outform.h"
#include "output/outlib.h"
#include "rbtree.h"
static struct SAA *strs;
static uint32_t strslen;
-static FILE *elffp;
-static efunc error;
-static evalfunc evaluate;
-
static struct Symbol *fwds;
static char elf_module[FILENAME_MAX];
static void stabs64_cleanup(void);
/* dwarf debugging routines */
-static void dwarf64_init(struct ofmt *, void *, FILE *, efunc);
+static void dwarf64_init(void);
static void dwarf64_linenum(const char *filename, int32_t linenumber, int32_t);
static void dwarf64_output(int, void *);
static void dwarf64_generate(void);
static int32_t elf_sym_sect;
static int32_t elf_gottpoff_sect;
-static void elf_init(FILE * fp, efunc errfunc, ldfunc ldef, evalfunc eval)
+static void elf_init(void)
{
maxbits = 64;
- elffp = fp;
- error = errfunc;
- evaluate = eval;
- (void)ldef; /* placate optimisers */
sects = NULL;
nsects = sectlen = 0;
syms = saa_init((int32_t)sizeof(struct Symbol));
fwds = NULL;
elf_gotpc_sect = seg_alloc();
- ldef("..gotpc", elf_gotpc_sect + 1, 0L, NULL, false, false, &of_elf64,
- error);
+ define_label("..gotpc", elf_gotpc_sect + 1, 0L, NULL, false, false, &of_elf64,
+ nasm_error);
elf_gotoff_sect = seg_alloc();
- ldef("..gotoff", elf_gotoff_sect + 1, 0L, NULL, false, false, &of_elf64,
- error);
+ define_label("..gotoff", elf_gotoff_sect + 1, 0L, NULL, false, false, &of_elf64,
+ nasm_error);
elf_got_sect = seg_alloc();
- ldef("..got", elf_got_sect + 1, 0L, NULL, false, false, &of_elf64,
- error);
+ define_label("..got", elf_got_sect + 1, 0L, NULL, false, false, &of_elf64,
+ nasm_error);
elf_plt_sect = seg_alloc();
- ldef("..plt", elf_plt_sect + 1, 0L, NULL, false, false, &of_elf64,
- error);
+ define_label("..plt", elf_plt_sect + 1, 0L, NULL, false, false, &of_elf64,
+ nasm_error);
elf_sym_sect = seg_alloc();
- ldef("..sym", elf_sym_sect + 1, 0L, NULL, false, false, &of_elf64,
- error);
+ define_label("..sym", elf_sym_sect + 1, 0L, NULL, false, false, &of_elf64,
+ nasm_error);
elf_gottpoff_sect = seg_alloc();
- ldef("..gottpoff", elf_gottpoff_sect + 1, 0L, NULL, false, false, &of_elf64,
- error);
+ define_label("..gottpoff", elf_gottpoff_sect + 1, 0L, NULL, false, false, &of_elf64,
+ nasm_error);
def_seg = seg_alloc();
if (align == 0)
align = 1;
if ((align - 1) & align) { /* means it's not a power of two */
- error(ERR_NONFATAL, "section alignment %d is not"
+ nasm_error(ERR_NONFATAL, "section alignment %d is not"
" a power of two", align);
align = 1;
}
} else if (!nasm_stricmp(q, "nobits")) {
type = SHT_NOBITS;
} else if (pass == 1) {
- error(ERR_WARNING, "Unknown section attribute '%s' ignored on"
+ nasm_error(ERR_WARNING, "Unknown section attribute '%s' ignored on"
" declaration of section `%s'", q, name);
}
}
if (!strcmp(name, ".shstrtab") ||
!strcmp(name, ".symtab") ||
!strcmp(name, ".strtab")) {
- error(ERR_NONFATAL, "attempt to redefine reserved section"
+ nasm_error(ERR_NONFATAL, "attempt to redefine reserved section"
"name `%s'", name);
return NO_SEG;
}
if ((type && sects[i]->type != type)
|| (align && sects[i]->align != align)
|| (flags_and && ((sects[i]->flags & flags_and) != flags_or)))
- error(ERR_WARNING, "incompatible section attributes ignored on"
+ nasm_error(ERR_WARNING, "incompatible section attributes ignored on"
" redeclaration of section `%s'", name);
}
if (strcmp(name, "..gotpc") && strcmp(name, "..gotoff") &&
strcmp(name, "..got") && strcmp(name, "..plt") &&
strcmp(name, "..sym") && strcmp(name, "..gottpoff"))
- error(ERR_NONFATAL, "unrecognised special symbol `%s'", name);
+ nasm_error(ERR_NONFATAL, "unrecognised special symbol `%s'", name);
return;
}
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);
if (nsects == 0 && segment == def_seg) {
int tempint;
if (segment != elf_section_names(".text", 2, &tempint))
- error(ERR_PANIC,
+ nasm_error(ERR_PANIC,
"strange segment conditions in ELF driver");
sym->section = nsects;
} else {
bool err;
sym->symv.key = readnum(special, &err);
if (err)
- error(ERR_NONFATAL, "alignment constraint `%s' is not a"
+ nasm_error(ERR_NONFATAL, "alignment constraint `%s' is not a"
" valid number", special);
else if ((sym->symv.key | (sym->symv.key - 1))
!= 2 * sym->symv.key - 1)
- error(ERR_NONFATAL, "alignment constraint `%s' is not a"
+ nasm_error(ERR_NONFATAL, "alignment constraint `%s' is not a"
" power of two", special);
}
special_used = true;
else if (!nasm_strnicmp(special, "notype", n))
sym->type |= STT_NOTYPE;
else
- error(ERR_NONFATAL, "unrecognised symbol type `%.*s'",
+ nasm_error(ERR_NONFATAL, "unrecognised symbol type `%.*s'",
n, special);
special += n;
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;
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);
nlocals++;
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 elf_add_reloc(struct Section *sect, int32_t segment,
if (!s) {
if (exact && offset)
- error(ERR_NONFATAL, "invalid access to an external symbol");
+ nasm_error(ERR_NONFATAL, "invalid access to an external symbol");
else
elf_add_reloc(sect, segment, offset - pcrel, type);
return;
srb = rb_search(s->gsyms, offset);
if (!srb || (exact && srb->key != offset)) {
- 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;
}
*/
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;
}
if (!s) {
int tempint; /* ignored */
if (segto != elf_section_names(".text", 2, &tempint))
- error(ERR_PANIC, "strange segment conditions in ELF driver");
+ nasm_error(ERR_PANIC, "strange segment conditions in ELF driver");
else {
s = sects[nsects - 1];
i = nsects - 1;
/* end of debugging stuff */
if (s->type == SHT_NOBITS && type != OUT_RESERVE) {
- error(ERR_WARNING, "attempt to initialize memory in"
+ nasm_error(ERR_WARNING, "attempt to initialize memory in"
" BSS section `%s': ignored", s->name);
s->len += realsize(type, size);
return;
if (type == OUT_RESERVE) {
if (s->type == SHT_PROGBITS) {
- error(ERR_WARNING, "uninitialized space declared in"
+ nasm_error(ERR_WARNING, "uninitialized space declared in"
" non-BSS section `%s': zeroing", s->name);
elf_sect_write(s, NULL, size);
} else
s->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");
elf_sect_write(s, data, size);
} else if (type == OUT_ADDRESS) {
addr = *(int64_t *)data;
if (segment == NO_SEG) {
/* Do nothing */
} else if (segment % 2) {
- error(ERR_NONFATAL, "ELF format does not support"
+ nasm_error(ERR_NONFATAL, "ELF format does not support"
" segment base references");
} else {
if (wrt == NO_SEG) {
elf_add_reloc(s, segment, addr, R_X86_64_64);
break;
default:
- error(ERR_PANIC, "internal error elf64-hpa-871");
+ nasm_error(ERR_PANIC, "internal error elf64-hpa-871");
break;
}
addr = 0;
addr = 0;
} else if (wrt == elf_gotoff_sect + 1) {
if (size != 8) {
- error(ERR_NONFATAL, "ELF64 requires ..gotoff "
+ nasm_error(ERR_NONFATAL, "ELF64 requires ..gotoff "
"references to be qword");
} else {
elf_add_reloc(s, segment, addr, R_X86_64_GOTOFF64);
addr = 0;
break;
default:
- error(ERR_NONFATAL, "invalid ..got reference");
+ nasm_error(ERR_NONFATAL, "invalid ..got reference");
break;
}
} else if (wrt == elf_sym_sect + 1) {
addr = 0;
break;
default:
- error(ERR_PANIC, "internal error elf64-hpa-903");
+ nasm_error(ERR_PANIC, "internal error elf64-hpa-903");
break;
}
} else if (wrt == elf_plt_sect + 1) {
- error(ERR_NONFATAL, "ELF format cannot produce non-PC-"
+ nasm_error(ERR_NONFATAL, "ELF format cannot produce non-PC-"
"relative PLT references");
} else {
- error(ERR_NONFATAL, "ELF format does not support this"
+ nasm_error(ERR_NONFATAL, "ELF format does not support this"
" use of WRT");
}
}
} else if (type == OUT_REL2ADR) {
addr = *(int64_t *)data - size;
if (segment == segto)
- error(ERR_PANIC, "intra-segment OUT_REL2ADR");
+ nasm_error(ERR_PANIC, "intra-segment OUT_REL2ADR");
if (segment == NO_SEG) {
/* Do nothing */
} else if (segment % 2) {
- error(ERR_NONFATAL, "ELF format does not support"
+ nasm_error(ERR_NONFATAL, "ELF format does not support"
" segment base references");
} else {
if (wrt == NO_SEG) {
elf_add_reloc(s, segment, addr, R_X86_64_PC16);
addr = 0;
} else {
- error(ERR_NONFATAL,
+ nasm_error(ERR_NONFATAL,
"Unsupported non-32-bit ELF relocation [2]");
}
}
} else if (type == OUT_REL4ADR) {
addr = *(int64_t *)data - size;
if (segment == segto)
- error(ERR_PANIC, "intra-segment OUT_REL4ADR");
+ nasm_error(ERR_PANIC, "intra-segment OUT_REL4ADR");
if (segment == NO_SEG) {
/* Do nothing */
} else if (segment % 2) {
- error(ERR_NONFATAL, "ELF64 format does not support"
+ nasm_error(ERR_NONFATAL, "ELF64 format does not support"
" segment base references");
} else {
if (wrt == NO_SEG) {
addr = 0;
} else if (wrt == elf_gotoff_sect + 1 ||
wrt == elf_got_sect + 1) {
- error(ERR_NONFATAL, "ELF64 requires ..gotoff references to be "
+ nasm_error(ERR_NONFATAL, "ELF64 requires ..gotoff references to be "
"qword absolute");
} else if (wrt == elf_gottpoff_sect + 1) {
elf_add_gsym_reloc(s, segment, addr+size, size,
R_X86_64_GOTTPOFF, true);
addr = 0;
} else {
- error(ERR_NONFATAL, "ELF64 format does not support this"
+ nasm_error(ERR_NONFATAL, "ELF64 format does not support this"
" use of WRT");
}
}
} else if (type == OUT_REL8ADR) {
addr = *(int64_t *)data - size;
if (segment == segto)
- error(ERR_PANIC, "intra-segment OUT_REL8ADR");
+ nasm_error(ERR_PANIC, "intra-segment OUT_REL8ADR");
if (segment == NO_SEG) {
/* Do nothing */
} else if (segment % 2) {
- error(ERR_NONFATAL, "ELF64 format does not support"
+ nasm_error(ERR_NONFATAL, "ELF64 format does not support"
" segment base references");
} else {
if (wrt == NO_SEG) {
addr = 0;
} else if (wrt == elf_gotoff_sect + 1 ||
wrt == elf_got_sect + 1) {
- error(ERR_NONFATAL, "ELF64 requires ..gotoff references to be "
+ nasm_error(ERR_NONFATAL, "ELF64 requires ..gotoff references to be "
"absolute");
} else if (wrt == elf_gottpoff_sect + 1) {
- error(ERR_NONFATAL, "ELF64 requires ..gottpoff references to be "
+ nasm_error(ERR_NONFATAL, "ELF64 requires ..gottpoff references to be "
"dword");
} else {
- error(ERR_NONFATAL, "ELF64 format does not support this"
+ nasm_error(ERR_NONFATAL, "ELF64 format does not support this"
" use of WRT");
}
}
/*
* Output the ELF header.
*/
- fwrite("\177ELF\2\1\1", 7, 1, elffp);
- fputc(elf_osabi, elffp);
- fputc(elf_abiver, elffp);
- fwritezero(7, elffp);
- fwriteint16_t(ET_REL, elffp); /* relocatable file */
- fwriteint16_t(EM_X86_64, elffp); /* processor ID */
- fwriteint32_t(1L, elffp); /* EV_CURRENT file format version */
- fwriteint64_t(0L, elffp); /* no entry point */
- fwriteint64_t(0L, elffp); /* no program header table */
- fwriteint64_t(0x40L, elffp); /* section headers straight after
+ fwrite("\177ELF\2\1\1", 7, 1, ofile);
+ fputc(elf_osabi, ofile);
+ fputc(elf_abiver, ofile);
+ fwritezero(7, ofile);
+ fwriteint16_t(ET_REL, ofile); /* relocatable file */
+ fwriteint16_t(EM_X86_64, ofile); /* processor ID */
+ fwriteint32_t(1L, ofile); /* EV_CURRENT file format version */
+ fwriteint64_t(0L, ofile); /* no entry point */
+ fwriteint64_t(0L, ofile); /* no program header table */
+ fwriteint64_t(0x40L, ofile); /* section headers straight after
* ELF header plus alignment */
- fwriteint32_t(0L, elffp); /* 386 defines no special flags */
- fwriteint16_t(0x40, elffp); /* size of ELF header */
- fwriteint16_t(0, elffp); /* no program header table, again */
- fwriteint16_t(0, elffp); /* still no program header table */
- fwriteint16_t(sizeof(Elf64_Shdr), elffp); /* size of section header */
- fwriteint16_t(nsections, elffp); /* number of sections */
- fwriteint16_t(sec_shstrtab, elffp); /* string table section index for
+ fwriteint32_t(0L, ofile); /* 386 defines no special flags */
+ fwriteint16_t(0x40, ofile); /* size of ELF header */
+ fwriteint16_t(0, ofile); /* no program header table, again */
+ fwriteint16_t(0, ofile); /* still no program header table */
+ fwriteint16_t(sizeof(Elf64_Shdr), ofile); /* size of section header */
+ fwriteint16_t(nsections, ofile); /* number of sections */
+ fwriteint16_t(sec_shstrtab, ofile); /* string table section index for
* section header table */
/*
loclen, 0, 0, 1, 0);
p += strlen(p) + 1;
}
- fwritezero(align, elffp);
+ fwritezero(align, ofile);
/*
* Now output the sections.
elf_sects[elf_nsect].is_saa = is_saa;
elf_nsect++;
- fwriteint32_t((int32_t)name, elffp);
- fwriteint32_t((int32_t)type, elffp);
- fwriteint64_t((int64_t)flags, elffp);
- fwriteint64_t(0L, elffp); /* no address, ever, in object files */
- fwriteint64_t(type == 0 ? 0L : elf_foffs, elffp);
- fwriteint64_t(datalen, elffp);
+ fwriteint32_t((int32_t)name, ofile);
+ fwriteint32_t((int32_t)type, ofile);
+ fwriteint64_t((int64_t)flags, ofile);
+ fwriteint64_t(0L, ofile); /* no address, ever, in object files */
+ fwriteint64_t(type == 0 ? 0L : elf_foffs, ofile);
+ fwriteint64_t(datalen, ofile);
if (data)
elf_foffs += (datalen + SEG_ALIGN_1) & ~SEG_ALIGN_1;
- fwriteint32_t((int32_t)link, elffp);
- fwriteint32_t((int32_t)info, elffp);
- fwriteint64_t((int64_t)align, elffp);
- fwriteint64_t((int64_t)eltsize, elffp);
+ fwriteint32_t((int32_t)link, ofile);
+ fwriteint32_t((int32_t)info, ofile);
+ fwriteint64_t((int64_t)align, ofile);
+ fwriteint64_t((int64_t)eltsize, ofile);
}
static void elf_write_sections(void)
int32_t reallen = (len + SEG_ALIGN_1) & ~SEG_ALIGN_1;
int32_t align = reallen - len;
if (elf_sects[i].is_saa)
- saa_fpwrite(elf_sects[i].data, elffp);
+ saa_fpwrite(elf_sects[i].data, ofile);
else
- fwrite(elf_sects[i].data, len, 1, elffp);
- fwritezero(align, elffp);
+ fwrite(elf_sects[i].data, len, 1, ofile);
+ fwritezero(align, ofile);
}
}
n = readnum(value, &err);
if (err) {
- error(ERR_NONFATAL, "`osabi' directive requires a parameter");
+ nasm_error(ERR_NONFATAL, "`osabi' directive requires a parameter");
return 1;
}
if (n < 0 || n > 255) {
- error(ERR_NONFATAL, "valid osabi numbers are 0 to 255");
+ nasm_error(ERR_NONFATAL, "valid osabi numbers are 0 to 255");
return 1;
}
elf_osabi = n;
n = readnum(p+1, &err);
if (err || n < 0 || n > 255) {
- error(ERR_NONFATAL, "invalid ABI version number (valid: 0 to 255)");
+ nasm_error(ERR_NONFATAL, "invalid ABI version number (valid: 0 to 255)");
return 1;
}
}
}
-static void elf_filename(char *inname, char *outname, efunc error)
+static void elf_filename(char *inname, char *outname)
{
strcpy(elf_module, inname);
- standard_extension(inname, outname, ".o", error);
+ standard_extension(inname, outname, ".o");
}
extern macros_t elf_stdmac[];
nasm_free(stabstrbuf);
}
/* dwarf routines */
-static void dwarf64_init(struct ofmt *of, void *id, FILE * fp, efunc error)
+static void dwarf64_init(void)
{
- (void)of;
- (void)id;
- (void)fp;
- (void)error;
-
ndebugs = 3; /* 3 debug symbols */
}
#define BUILD_DRIVERS_ARRAY
#include "output/outform.h"
-static int ndrivers = 0;
-
struct ofmt *ofmt_find(char *name)
{ /* find driver */
- int i;
-
- for (i = 0; i < ndrivers; i++)
- if (!strcmp(name, drivers[i]->shortname))
- return drivers[i];
+ struct ofmt **ofp, *of;
+ for (ofp = drivers; (of = *ofp); ofp++) {
+ if (!nasm_stricmp(name, of->shortname))
+ return of;
+ }
return NULL;
}
+
struct dfmt *dfmt_find(struct ofmt *ofmt, char *name)
{ /* find driver */
- struct dfmt **dfmt = ofmt->debug_formats;
- while (*dfmt) {
- if (!strcmp(name, (*dfmt)->shortname))
- return (*dfmt);
- dfmt++;
+ struct dfmt **dfp, *df;
+
+ for (dfp = ofmt->debug_formats; (df = *dfp); dfp++) {
+ if (!nasm_stricmp(name, df->shortname))
+ return df;
}
return NULL;
}
void ofmt_list(struct ofmt *deffmt, FILE * fp)
{
- int i;
- for (i = 0; i < ndrivers; i++)
- fprintf(fp, " %c %-10s%s\n",
- drivers[i] == deffmt ? '*' : ' ',
- drivers[i]->shortname, drivers[i]->fullname);
-}
-void dfmt_list(struct ofmt *ofmt, FILE * fp)
-{
- struct dfmt **drivers = ofmt->debug_formats;
- while (*drivers) {
+ struct ofmt **ofp, *of;
+
+ for (ofp = drivers; (of = *ofp); ofp++) {
fprintf(fp, " %c %-10s%s\n",
- drivers[0] == ofmt->current_dfmt ? '*' : ' ',
- drivers[0]->shortname, drivers[0]->fullname);
- drivers++;
+ of == deffmt ? '*' : ' ',
+ of->shortname, of->fullname);
}
}
-struct ofmt *ofmt_register(efunc error)
+
+void dfmt_list(struct ofmt *ofmt, FILE *fp)
{
- for (ndrivers = 0; drivers[ndrivers] != NULL; ndrivers++) ;
+ struct dfmt **dfp, *df;
- if (ndrivers == 0) {
- error(ERR_PANIC | ERR_NOFILE,
- "No output drivers given at compile time");
+ for (dfp = ofmt->debug_formats; (df = *dfp); dfp++) {
+ fprintf(fp, " %c %-10s%s\n",
+ df == ofmt->current_dfmt ? '*' : ' ',
+ df->shortname, df->fullname);
}
-
- return (&OF_DEFAULT);
}
#define OF_DEFAULT of_bin
#endif
-#ifdef BUILD_DRIVERS_ARRAY /* only if included from outform.c */
-
-/* pull in the externs for the different formats, then make the *drivers
- * array based on the above defines */
-
extern struct ofmt of_bin;
extern struct ofmt of_ith;
extern struct ofmt of_srec;
extern struct ofmt of_macho64;
extern struct ofmt of_dbg;
-struct ofmt *drivers[] = {
+#ifdef BUILD_DRIVERS_ARRAY /* only if included from outform.c */
+
+/* pull in the externs for the different formats, then make the *drivers
+ * array based on the above defines */
+
+static struct ofmt *drivers[] = {
#ifdef OF_BIN
&of_bin,
&of_ith,
static char ieee_infile[FILENAME_MAX];
static int ieee_uppercase;
-static efunc error;
-static ldfunc deflabel;
-static FILE *ofp;
static bool any_segs;
static int arrindex;
/*
* pup init
*/
-static void ieee_init(FILE * fp, efunc errfunc, ldfunc ldef, evalfunc eval)
+static void ieee_init(void)
{
- (void)eval;
- ofp = fp;
- error = errfunc;
- deflabel = ldef;
any_segs = false;
fpubhead = NULL;
fpubtail = &fpubhead;
int i;
if (special) {
- error(ERR_NONFATAL, "unrecognised symbol type `%s'", special);
+ nasm_error(ERR_NONFATAL, "unrecognised symbol type `%s'", special);
}
/*
* First check for the double-period, signifying something
*/
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;
}
if (!any_segs) {
int tempint; /* ignored */
if (segto != ieee_segment("__NASMDEFSEG", 2, &tempint))
- error(ERR_PANIC, "strange segment conditions in IEEE driver");
+ nasm_error(ERR_PANIC, "strange segment conditions in IEEE driver");
}
/*
if (seg->index == segto)
break;
if (!seg)
- error(ERR_PANIC, "code directed to nonexistent segment?");
+ nasm_error(ERR_PANIC, "code directed to nonexistent segment?");
if (type == OUT_RAWDATA) {
ucdata = data;
} else if (type == OUT_ADDRESS || type == OUT_REL2ADR ||
type == OUT_REL4ADR) {
if (segment == NO_SEG && type != OUT_ADDRESS)
- error(ERR_NONFATAL, "relative call to absolute address not"
+ nasm_error(ERR_NONFATAL, "relative call to absolute address not"
" supported by IEEE format");
ldata = *(int64_t *)data;
if (type == OUT_REL2ADR)
s.addend = 0;
s.id2 = eb->index[i];
} else
- error(ERR_NONFATAL,
+ nasm_error(ERR_NONFATAL,
"Source of WRT must be an offset");
}
} else
- error(ERR_PANIC,
+ nasm_error(ERR_PANIC,
"unrecognised WRT value in ieee_write_fixup");
} else
- error(ERR_NONFATAL, "target of WRT must be a section ");
+ nasm_error(ERR_NONFATAL, "target of WRT must be a section ");
}
s.size = size;
ieee_install_fixup(segto, &s);
*/
if (eb) {
if (realtype == OUT_REL2ADR || realtype == OUT_REL4ADR) {
- error(ERR_PANIC,
+ nasm_error(ERR_PANIC,
"Segment of a rel not supported in ieee_write_fixup");
} else {
/* If we want the segment */
} else
/* If we get here the seg value doesn't make sense */
- error(ERR_PANIC,
+ nasm_error(ERR_PANIC,
"unrecognised segment value in ieee_write_fixup");
}
} else
/* If we get here the seg value doesn't make sense */
- error(ERR_PANIC,
+ nasm_error(ERR_PANIC,
"unrecognised segment value in ieee_write_fixup");
}
}
if (size != 2 && s.ftype == FT_SEG)
- error(ERR_NONFATAL, "IEEE format can only handle 2-byte"
+ nasm_error(ERR_NONFATAL, "IEEE format can only handle 2-byte"
" segment base references");
s.size = size;
ieee_install_fixup(segto, &s);
ieee_idx++;
if (!strcmp(seg->name, name)) {
if (attrs > 0 && pass == 1)
- error(ERR_WARNING, "segment attributes specified on"
+ nasm_error(ERR_WARNING, "segment attributes specified on"
" redeclaration of segment: ignoring");
if (seg->use32)
*bits = 32;
seg->align = 1;
if (rn_error) {
seg->align = 1;
- error(ERR_NONFATAL, "segment alignment should be"
+ nasm_error(ERR_NONFATAL, "segment alignment should be"
" numeric");
}
switch ((int)seg->align) {
case 128:
break;
default:
- error(ERR_NONFATAL, "invalid alignment value %d",
+ nasm_error(ERR_NONFATAL, "invalid alignment value %d",
seg->align);
seg->align = 1;
break;
} else if (!nasm_strnicmp(p, "absolute=", 9)) {
seg->align = SEG_ABS + readnum(p + 9, &rn_error);
if (rn_error)
- error(ERR_NONFATAL, "argument to `absolute' segment"
+ nasm_error(ERR_NONFATAL, "argument to `absolute' segment"
" attribute should be numeric");
}
}
ieee_seg_needs_update = seg;
if (seg->align >= SEG_ABS)
- deflabel(name, NO_SEG, seg->align - SEG_ABS,
- NULL, false, false, &of_ieee, error);
+ define_label(name, NO_SEG, seg->align - SEG_ABS,
+ NULL, false, false, &of_ieee, nasm_error);
else
- deflabel(name, seg->index + 1, 0L,
- NULL, false, false, &of_ieee, error);
+ define_label(name, seg->index + 1, 0L,
+ NULL, false, false, &of_ieee, nasm_error);
ieee_seg_needs_update = NULL;
if (seg->use32)
/*
* filename
*/
-static void ieee_filename(char *inname, char *outname, efunc error)
+static void ieee_filename(char *inname, char *outname)
{
strcpy(ieee_infile, inname);
- standard_extension(inname, outname, ".o", error);
+ standard_extension(inname, outname, ".o");
}
static void ieee_write_file(int debuginfo)
if (seg->index == ieee_entry_seg)
break;
if (!seg)
- error(ERR_PANIC, "Start address records are incorrect");
+ nasm_error(ERR_PANIC, "Start address records are incorrect");
else
ieee_putascii("ASG,R%X,%lX,+.\n", seg->ieee_index,
ieee_entry_ofs);
if ((uint8_t)buffer[i] > 31)
checksum += buffer[i];
va_end(ap);
- fprintf(ofp, buffer);
+ fprintf(ofile, buffer);
}
/*
} else
strcpy(dest, source);
}
-void dbgls_init(struct ofmt *of, void *id, FILE * fp, efunc error)
+void dbgls_init(void)
{
int tempint;
- (void)of;
- (void)id;
- (void)fp;
- (void)error;
fnhead = NULL;
fntail = &fnhead;
if (!any_segs) {
int tempint; /* ignored */
if (segto != ieee_segment("__NASMDEFSEG", 2, &tempint))
- error(ERR_PANIC, "strange segment conditions in OBJ driver");
+ nasm_error(ERR_PANIC, "strange segment conditions in OBJ driver");
}
/*
if (seg->index == segto)
break;
if (!seg)
- error(ERR_PANIC, "lineno directed to nonexistent segment?");
+ nasm_error(ERR_PANIC, "lineno directed to nonexistent segment?");
for (fn = fnhead; fn; fn = fn->next) {
if (!nasm_stricmp(lnfname, fn->name))
/* Do-nothing versions of all the debug routines */
struct ofmt;
-void null_debug_init(struct ofmt *of, void *id, FILE * fp, efunc error);
+void null_debug_init(void);
void null_debug_linenum(const char *filename, int32_t linenumber,
int32_t segto);
void null_debug_deflabel(char *name, int32_t segment, int64_t offset,
#include "nasmlib.h"
#include "saa.h"
#include "raa.h"
+#include "eval.h"
#include "output/outform.h"
#include "output/outlib.h"
static struct SAA *strs;
static uint32_t strslen;
-static FILE *machofp;
static efunc error;
-static evalfunc evaluate;
extern struct ofmt of_macho;
return NO_SECT;
}
-static void macho_init(FILE * fp, efunc errfunc, ldfunc ldef,
- evalfunc eval)
+static void macho_init(void)
{
char zero = 0;
- machofp = fp;
- error = errfunc;
- evaluate = eval;
-
- (void)ldef; /* placate optimisers */
-
sects = NULL;
sectstail = §s;
return section;
}
-static void macho_filename(char *inname, char *outname, efunc error)
+static void macho_filename(char *inname, char *outname)
{
- standard_extension(inname, outname, ".o", error);
+ standard_extension(inname, outname, ".o");
}
extern macros_t macho_stdmac[];
static void macho_write_header (void)
{
- fwriteint32_t(MH_MAGIC, machofp); /* magic */
- fwriteint32_t(CPU_TYPE_I386, machofp); /* CPU type */
- fwriteint32_t(CPU_SUBTYPE_I386_ALL, machofp); /* CPU subtype */
- fwriteint32_t(MH_OBJECT, machofp); /* Mach-O file type */
- fwriteint32_t(head_ncmds, machofp); /* number of load commands */
- fwriteint32_t(head_sizeofcmds, machofp); /* size of load commands */
- fwriteint32_t(0, machofp); /* no flags */
+ fwriteint32_t(MH_MAGIC, ofile); /* magic */
+ fwriteint32_t(CPU_TYPE_I386, ofile); /* CPU type */
+ fwriteint32_t(CPU_SUBTYPE_I386_ALL, ofile); /* CPU subtype */
+ fwriteint32_t(MH_OBJECT, ofile); /* Mach-O file type */
+ fwriteint32_t(head_ncmds, ofile); /* number of load commands */
+ fwriteint32_t(head_sizeofcmds, ofile); /* size of load commands */
+ fwriteint32_t(0, ofile); /* no flags */
}
/* Write out the segment load command at offset. */
uint32_t s_reloff = 0;
struct section *s;
- fwriteint32_t(LC_SEGMENT, machofp); /* cmd == LC_SEGMENT */
+ fwriteint32_t(LC_SEGMENT, ofile); /* cmd == LC_SEGMENT */
/* size of load command including section load commands */
fwriteint32_t(MACHO_SEGCMD_SIZE + seg_nsects *
- MACHO_SECTCMD_SIZE, machofp);
+ MACHO_SECTCMD_SIZE, ofile);
/* in an MH_OBJECT file all sections are in one unnamed (name
** all zeros) segment */
- fwritezero(16, machofp);
- fwriteint32_t(0, machofp); /* in-memory offset */
- fwriteint32_t(seg_vmsize, machofp); /* in-memory size */
- fwriteint32_t(offset, machofp); /* in-file offset to data */
- fwriteint32_t(seg_filesize, machofp); /* in-file size */
- fwriteint32_t(VM_PROT_DEFAULT, machofp); /* maximum vm protection */
- fwriteint32_t(VM_PROT_DEFAULT, machofp); /* initial vm protection */
- fwriteint32_t(seg_nsects, machofp); /* number of sections */
- fwriteint32_t(0, machofp); /* no flags */
+ fwritezero(16, ofile);
+ fwriteint32_t(0, ofile); /* in-memory offset */
+ fwriteint32_t(seg_vmsize, ofile); /* in-memory size */
+ fwriteint32_t(offset, ofile); /* in-file offset to data */
+ fwriteint32_t(seg_filesize, ofile); /* in-file size */
+ fwriteint32_t(VM_PROT_DEFAULT, ofile); /* maximum vm protection */
+ fwriteint32_t(VM_PROT_DEFAULT, ofile); /* initial vm protection */
+ fwriteint32_t(seg_nsects, ofile); /* number of sections */
+ fwriteint32_t(0, ofile); /* no flags */
/* emit section headers */
for (s = sects; s != NULL; s = s->next) {
- fwrite(s->sectname, sizeof(s->sectname), 1, machofp);
- fwrite(s->segname, sizeof(s->segname), 1, machofp);
- fwriteint32_t(s->addr, machofp);
- fwriteint32_t(s->size, machofp);
+ fwrite(s->sectname, sizeof(s->sectname), 1, ofile);
+ fwrite(s->segname, sizeof(s->segname), 1, ofile);
+ fwriteint32_t(s->addr, ofile);
+ fwriteint32_t(s->size, ofile);
/* dummy data for zerofill sections or proper values */
if ((s->flags & SECTION_TYPE) != S_ZEROFILL) {
- fwriteint32_t(offset, machofp);
+ fwriteint32_t(offset, ofile);
/* Write out section alignment, as a power of two.
e.g. 32-bit word alignment would be 2 (2^^2 = 4). */
if (s->align == -1)
s->align = DEFAULT_SECTION_ALIGNMENT;
- fwriteint32_t(s->align, machofp);
+ fwriteint32_t(s->align, ofile);
/* To be compatible with cctools as we emit
a zero reloff if we have no relocations. */
- fwriteint32_t(s->nreloc ? rel_base + s_reloff : 0, machofp);
- fwriteint32_t(s->nreloc, machofp);
+ fwriteint32_t(s->nreloc ? rel_base + s_reloff : 0, ofile);
+ fwriteint32_t(s->nreloc, ofile);
offset += s->size;
s_reloff += s->nreloc * MACHO_RELINFO_SIZE;
} else {
- fwriteint32_t(0, machofp);
- fwriteint32_t(0, machofp);
- fwriteint32_t(0, machofp);
- fwriteint32_t(0, machofp);
+ fwriteint32_t(0, ofile);
+ fwriteint32_t(0, ofile);
+ fwriteint32_t(0, ofile);
+ fwriteint32_t(0, ofile);
}
- fwriteint32_t(s->flags, machofp); /* flags */
- fwriteint32_t(0, machofp); /* reserved */
- fwriteint32_t(0, machofp); /* reserved */
+ fwriteint32_t(s->flags, ofile); /* flags */
+ fwriteint32_t(0, ofile); /* reserved */
+ fwriteint32_t(0, ofile); /* reserved */
}
rel_padcnt = rel_base - offset;
while (r) {
uint32_t word2;
- fwriteint32_t(r->addr, machofp); /* reloc offset */
+ fwriteint32_t(r->addr, ofile); /* reloc offset */
word2 = r->snum;
word2 |= r->pcrel << 24;
word2 |= r->length << 25;
word2 |= r->ext << 27;
word2 |= r->type << 28;
- fwriteint32_t(word2, machofp); /* reloc data */
+ fwriteint32_t(word2, ofile); /* reloc data */
r = r->next;
}
}
/* dump the section data to file */
- saa_fpwrite(s->data, machofp);
+ saa_fpwrite(s->data, ofile);
}
/* pad last section up to reloc entries on int32_t boundary */
- fwritezero(rel_padcnt, machofp);
+ fwritezero(rel_padcnt, ofile);
/* emit relocation entries */
for (s = sects; s != NULL; s = s->next)
for (sym = syms; sym != NULL; sym = sym->next) {
if ((sym->type & N_EXT) == 0) {
- fwriteint32_t(sym->strx, machofp); /* string table entry number */
- fwrite(&sym->type, 1, 1, machofp); /* symbol type */
- fwrite(&sym->sect, 1, 1, machofp); /* section */
- fwriteint16_t(sym->desc, machofp); /* description */
+ fwriteint32_t(sym->strx, ofile); /* string table entry number */
+ fwrite(&sym->type, 1, 1, ofile); /* symbol type */
+ fwrite(&sym->sect, 1, 1, ofile); /* section */
+ fwriteint16_t(sym->desc, ofile); /* description */
/* Fix up the symbol value now that we know the final section
sizes. */
sym->value += s->size;
}
- fwriteint32_t(sym->value, machofp); /* value (i.e. offset) */
+ fwriteint32_t(sym->value, ofile); /* value (i.e. offset) */
}
}
for (i = 0; i < nextdefsym; i++) {
sym = extdefsyms[i];
- fwriteint32_t(sym->strx, machofp);
- fwrite(&sym->type, 1, 1, machofp); /* symbol type */
- fwrite(&sym->sect, 1, 1, machofp); /* section */
- fwriteint16_t(sym->desc, machofp); /* description */
+ fwriteint32_t(sym->strx, ofile);
+ fwrite(&sym->type, 1, 1, ofile); /* symbol type */
+ fwrite(&sym->sect, 1, 1, ofile); /* section */
+ fwriteint16_t(sym->desc, ofile); /* description */
/* Fix up the symbol value now that we know the final section
sizes. */
sym->value += s->size;
}
- fwriteint32_t(sym->value, machofp); /* value (i.e. offset) */
+ fwriteint32_t(sym->value, ofile); /* value (i.e. offset) */
}
for (i = 0; i < nundefsym; i++) {
sym = undefsyms[i];
- fwriteint32_t(sym->strx, machofp);
- fwrite(&sym->type, 1, 1, machofp); /* symbol type */
- fwrite(&sym->sect, 1, 1, machofp); /* section */
- fwriteint16_t(sym->desc, machofp); /* description */
+ fwriteint32_t(sym->strx, ofile);
+ fwrite(&sym->type, 1, 1, ofile); /* symbol type */
+ fwrite(&sym->sect, 1, 1, ofile); /* section */
+ fwriteint16_t(sym->desc, ofile); /* description */
/* Fix up the symbol value now that we know the final section
sizes. */
sym->value += s->size;
}
- fwriteint32_t(sym->value, machofp); /* value (i.e. offset) */
+ fwriteint32_t(sym->value, ofile); /* value (i.e. offset) */
}
}
if (nsyms > 0) {
/* write out symbol command */
- fwriteint32_t(LC_SYMTAB, machofp); /* cmd == LC_SYMTAB */
- fwriteint32_t(MACHO_SYMCMD_SIZE, machofp); /* size of load command */
- fwriteint32_t(offset, machofp); /* symbol table offset */
- fwriteint32_t(nsyms, machofp); /* number of symbol
+ fwriteint32_t(LC_SYMTAB, ofile); /* cmd == LC_SYMTAB */
+ fwriteint32_t(MACHO_SYMCMD_SIZE, ofile); /* size of load command */
+ fwriteint32_t(offset, ofile); /* symbol table offset */
+ fwriteint32_t(nsyms, ofile); /* number of symbol
** table entries */
offset += nsyms * MACHO_NLIST_SIZE;
- fwriteint32_t(offset, machofp); /* string table offset */
- fwriteint32_t(strslen, machofp); /* string table size */
+ fwriteint32_t(offset, ofile); /* string table offset */
+ fwriteint32_t(strslen, ofile); /* string table size */
}
/* emit section data */
/* we don't need to pad here since MACHO_NLIST_SIZE == 12 */
/* emit string table */
- saa_fpwrite(strs, machofp);
+ saa_fpwrite(strs, ofile);
}
/* We do quite a bit here, starting with finalizing all of the data
for the object file, writing, and then freeing all of the data from
static struct SAA *strs;
static uint32_t strslen;
-static FILE *machofp;
-static efunc error;
-static evalfunc evaluate;
-
extern struct ofmt of_macho64;
/* Global file information. This should be cleaned up into either
return i;
if (i == MAX_SECT)
- error(ERR_WARNING,
+ nasm_error(ERR_WARNING,
"too many sections (>255) - clipped by fileindex");
return NO_SECT;
*/
static int32_t macho_gotpcrel_sect;
-static void macho_init(FILE * fp, efunc errfunc, ldfunc ldef,
- evalfunc eval)
+static void macho_init(void)
{
char zero = 0;
- maxbits = 64;
- machofp = fp;
- error = errfunc;
- evaluate = eval;
-
- (void)ldef; /* placate optimizers */
+ maxbits = 64;
sects = NULL;
sectstail = §s;
/* add special symbol for ..gotpcrel */
macho_gotpcrel_sect = seg_alloc();
macho_gotpcrel_sect ++;
- ldef("..gotpcrel", macho_gotpcrel_sect, 0L, NULL, false, false, &of_macho64, error);
+ define_label("..gotpcrel", macho_gotpcrel_sect, 0L, NULL, false, false, &of_macho64, nasm_error);
}
static void sect_write(struct section *sect,
if (secto == NO_SEG) {
if (type != OUT_RESERVE)
- error(ERR_NONFATAL, "attempt to assemble code in "
+ nasm_error(ERR_NONFATAL, "attempt to assemble code in "
"[ABSOLUTE] space");
return;
s = get_section_by_index(secto);
if (s == NULL) {
- error(ERR_WARNING, "attempt to assemble code in"
+ nasm_error(ERR_WARNING, "attempt to assemble code in"
" section %d: defaulting to `.text'", secto);
s = get_section_by_name("__TEXT", "__text");
/* should never happen */
if (s == NULL)
- error(ERR_PANIC, "text section not found");
+ nasm_error(ERR_PANIC, "text section not found");
}
sbss = get_section_by_name("__DATA", "__bss");
if (s == sbss && 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");
s->size += realsize(type, size);
return;
switch (type) {
case OUT_RESERVE:
if (s != sbss) {
- error(ERR_WARNING, "uninitialized space declared in"
+ nasm_error(ERR_WARNING, "uninitialized space declared in"
" %s section: zeroing",
get_section_name_by_index(secto));
case OUT_RAWDATA:
if (section != NO_SEG)
- error(ERR_PANIC, "OUT_RAWDATA with other than NO_SEG");
+ nasm_error(ERR_PANIC, "OUT_RAWDATA with other than NO_SEG");
sect_write(s, data, size);
break;
addr = *(int64_t *)data;
if (section != NO_SEG) {
if (section % 2) {
- error(ERR_NONFATAL, "Mach-O format does not support"
+ nasm_error(ERR_NONFATAL, "Mach-O format does not support"
" section base references");
} else {
if (wrt == NO_SEG) {
if (size < 8) {
- error(ERR_NONFATAL, "Mach-O 64-bit format does not support"
+ nasm_error(ERR_NONFATAL, "Mach-O 64-bit format does not support"
" 32-bit absolute addresses");
/*
Seemingly, Mach-O's X86_64_RELOC_SUBTRACTOR would require
addr -= add_reloc(s, section, 0, size, addr); // X86_64_RELOC_UNSIGNED
}
} else {
- error(ERR_NONFATAL, "Mach-O format does not support"
+ nasm_error(ERR_NONFATAL, "Mach-O format does not support"
" this use of WRT");
}
}
WRITESHORT(p, *(int64_t *)data);
if (section == secto)
- error(ERR_PANIC, "intra-section OUT_REL2ADR");
+ nasm_error(ERR_PANIC, "intra-section OUT_REL2ADR");
if (section == NO_SEG) {
/* Do nothing */
} else if (section % 2) {
- error(ERR_NONFATAL, "Mach-O format does not support"
+ nasm_error(ERR_NONFATAL, "Mach-O format does not support"
" section base references");
} else {
- error(ERR_NONFATAL, "Unsupported non-32-bit"
+ nasm_error(ERR_NONFATAL, "Unsupported non-32-bit"
" Macho-O relocation [2]");
}
WRITELONG(p, *(int64_t *)data);
if (section == secto)
- error(ERR_PANIC, "intra-section OUT_REL4ADR");
+ nasm_error(ERR_PANIC, "intra-section OUT_REL4ADR");
if (section != NO_SEG && section % 2) {
- error(ERR_NONFATAL, "Mach-O format does not support"
+ nasm_error(ERR_NONFATAL, "Mach-O format does not support"
" section base references");
} else {
if (wrt == NO_SEG) {
*mydata -= add_reloc(s, section, 3, 4, (int64_t)*mydata); // X86_64_GOT
}
} else {
- error(ERR_NONFATAL, "Mach-O format does not support"
+ nasm_error(ERR_NONFATAL, "Mach-O format does not support"
" this use of WRT");
wrt = NO_SEG; /* we can at least _try_ to continue */
}
break;
default:
- error(ERR_PANIC, "unknown output type?");
+ nasm_error(ERR_PANIC, "unknown output type?");
break;
}
}
newAlignment = exact_log2(value);
if (0 != *end) {
- error(ERR_PANIC,
+ nasm_error(ERR_PANIC,
"unknown or missing alignment value \"%s\" "
"specified for section \"%s\"",
currentAttribute + 6,
name);
return NO_SEG;
} else if (0 > newAlignment) {
- error(ERR_PANIC,
+ nasm_error(ERR_PANIC,
"alignment of %d (for section \"%s\") is not "
"a power of two",
value,
if ((-1 != originalIndex)
&& (s->align != newAlignment)
&& (s->align != -1)) {
- error(ERR_PANIC,
+ nasm_error(ERR_PANIC,
"section \"%s\" has already been specified "
"with alignment %d, conflicts with new "
"alignment of %d",
} else if (!nasm_stricmp("data", currentAttribute)) {
/* Do nothing; 'data' is implicit */
} else {
- error(ERR_PANIC,
+ nasm_error(ERR_PANIC,
"unknown section attribute %s for section %s",
currentAttribute,
name);
}
}
- error(ERR_PANIC, "invalid section name %s", name);
+ nasm_error(ERR_PANIC, "invalid section name %s", name);
return NO_SEG;
}
struct symbol *sym;
if (special) {
- error(ERR_NONFATAL, "The Mach-O output format does "
+ nasm_error(ERR_NONFATAL, "The Mach-O output format does "
"not support any special symbol types");
return;
}
if (is_global == 3) {
- error(ERR_NONFATAL, "The Mach-O format does not "
+ nasm_error(ERR_NONFATAL, "The Mach-O format does not "
"(yet) support forward reference fixups.");
return;
}
* _isn't_ a valid one, we should barf immediately.
*/
if (strcmp(name, "..gotpcrel"))
- error(ERR_NONFATAL, "unrecognized special symbol `%s'", name);
+ nasm_error(ERR_NONFATAL, "unrecognized special symbol `%s'", name);
return;
}
/* give an error on unfound section if it's not an
** external or common symbol (assemble_file() does a
** seg_alloc() on every call for them) */
- error(ERR_PANIC, "in-file index for section %d not found",
+ nasm_error(ERR_PANIC, "in-file index for section %d not found",
section);
}
}
return section;
}
-static void macho_filename(char *inname, char *outname, efunc error)
+static void macho_filename(char *inname, char *outname)
{
- standard_extension(inname, outname, ".o", error);
+ standard_extension(inname, outname, ".o");
}
extern macros_t macho_stdmac[];
static void macho_write_header (void)
{
- fwriteint32_t(MH_MAGIC_64, machofp); /* magic */
- fwriteint32_t(CPU_TYPE_X86_64, machofp); /* CPU type */
- fwriteint32_t(CPU_SUBTYPE_I386_ALL, machofp); /* CPU subtype */
- fwriteint32_t(MH_OBJECT, machofp); /* Mach-O file type */
- fwriteint32_t(head_ncmds64, machofp); /* number of load commands */
- fwriteint32_t(head_sizeofcmds64, machofp); /* size of load commands */
- fwriteint32_t(0, machofp); /* no flags */
- fwriteint32_t(0, machofp); /* reserved for future use */
+ fwriteint32_t(MH_MAGIC_64, ofile); /* magic */
+ fwriteint32_t(CPU_TYPE_X86_64, ofile); /* CPU type */
+ fwriteint32_t(CPU_SUBTYPE_I386_ALL, ofile); /* CPU subtype */
+ fwriteint32_t(MH_OBJECT, ofile); /* Mach-O file type */
+ fwriteint32_t(head_ncmds64, ofile); /* number of load commands */
+ fwriteint32_t(head_sizeofcmds64, ofile); /* size of load commands */
+ fwriteint32_t(0, ofile); /* no flags */
+ fwriteint32_t(0, ofile); /* reserved for future use */
}
/* Write out the segment load command at offset. */
uint32_t s_reloff = 0;
struct section *s;
- fwriteint32_t(LC_SEGMENT_64, machofp); /* cmd == LC_SEGMENT_64 */
+ fwriteint32_t(LC_SEGMENT_64, ofile); /* cmd == LC_SEGMENT_64 */
/* size of load command including section load commands */
fwriteint32_t(MACHO_SEGCMD64_SIZE + seg_nsects64 *
- MACHO_SECTCMD64_SIZE, machofp);
+ MACHO_SECTCMD64_SIZE, ofile);
/* in an MH_OBJECT file all sections are in one unnamed (name
** all zeros) segment */
- fwritezero(16, machofp);
- fwriteint64_t(0, machofp); /* in-memory offset */
- fwriteint64_t(seg_vmsize64, machofp); /* in-memory size */
- fwriteint64_t(offset, machofp); /* in-file offset to data */
- fwriteint64_t(seg_filesize64, machofp); /* in-file size */
- fwriteint32_t(VM_PROT_DEFAULT, machofp); /* maximum vm protection */
- fwriteint32_t(VM_PROT_DEFAULT, machofp); /* initial vm protection */
- fwriteint32_t(seg_nsects64, machofp); /* number of sections */
- fwriteint32_t(0, machofp); /* no flags */
+ fwritezero(16, ofile);
+ fwriteint64_t(0, ofile); /* in-memory offset */
+ fwriteint64_t(seg_vmsize64, ofile); /* in-memory size */
+ fwriteint64_t(offset, ofile); /* in-file offset to data */
+ fwriteint64_t(seg_filesize64, ofile); /* in-file size */
+ fwriteint32_t(VM_PROT_DEFAULT, ofile); /* maximum vm protection */
+ fwriteint32_t(VM_PROT_DEFAULT, ofile); /* initial vm protection */
+ fwriteint32_t(seg_nsects64, ofile); /* number of sections */
+ fwriteint32_t(0, ofile); /* no flags */
/* emit section headers */
for (s = sects; s != NULL; s = s->next) {
- fwrite(s->sectname, sizeof(s->sectname), 1, machofp);
- fwrite(s->segname, sizeof(s->segname), 1, machofp);
- fwriteint64_t(s->addr, machofp);
- fwriteint64_t(s->size, machofp);
+ fwrite(s->sectname, sizeof(s->sectname), 1, ofile);
+ fwrite(s->segname, sizeof(s->segname), 1, ofile);
+ fwriteint64_t(s->addr, ofile);
+ fwriteint64_t(s->size, ofile);
/* dummy data for zerofill sections or proper values */
if ((s->flags & SECTION_TYPE) != S_ZEROFILL) {
- fwriteint32_t(offset, machofp);
+ fwriteint32_t(offset, ofile);
/* Write out section alignment, as a power of two.
e.g. 32-bit word alignment would be 2 (2^2 = 4). */
if (s->align == -1)
s->align = DEFAULT_SECTION_ALIGNMENT;
- fwriteint32_t(s->align, machofp);
+ fwriteint32_t(s->align, ofile);
/* To be compatible with cctools as we emit
a zero reloff if we have no relocations. */
- fwriteint32_t(s->nreloc ? rel_base + s_reloff : 0, machofp);
- fwriteint32_t(s->nreloc, machofp);
+ fwriteint32_t(s->nreloc ? rel_base + s_reloff : 0, ofile);
+ fwriteint32_t(s->nreloc, ofile);
offset += s->size;
s_reloff += s->nreloc * MACHO_RELINFO64_SIZE;
} else {
- fwriteint32_t(0, machofp);
- fwriteint32_t(0, machofp);
- fwriteint32_t(0, machofp);
- fwriteint32_t(0, machofp);
+ fwriteint32_t(0, ofile);
+ fwriteint32_t(0, ofile);
+ fwriteint32_t(0, ofile);
+ fwriteint32_t(0, ofile);
}
if (s->nreloc) {
s->flags |= S_ATTR_EXT_RELOC;
}
- fwriteint32_t(s->flags, machofp); /* flags */
- fwriteint32_t(0, machofp); /* reserved */
- fwriteint32_t(0, machofp); /* reserved */
+ fwriteint32_t(s->flags, ofile); /* flags */
+ fwriteint32_t(0, ofile); /* reserved */
+ fwriteint32_t(0, ofile); /* reserved */
- fwriteint32_t(0, machofp); /* align */
+ fwriteint32_t(0, ofile); /* align */
}
rel_padcnt64 = rel_base - offset;
while (r) {
uint32_t word2;
- fwriteint32_t(r->addr, machofp); /* reloc offset */
+ fwriteint32_t(r->addr, ofile); /* reloc offset */
word2 = r->snum;
word2 |= r->pcrel << 24;
word2 |= r->length << 25;
word2 |= r->ext << 27;
word2 |= r->type << 28;
- fwriteint32_t(word2, machofp); /* reloc data */
+ fwriteint32_t(word2, ofile); /* reloc data */
r = r->next;
}
}
}
/* dump the section data to file */
- saa_fpwrite(s->data, machofp);
+ saa_fpwrite(s->data, ofile);
}
/* pad last section up to reloc entries on int64_t boundary */
- fwritezero(rel_padcnt64, machofp);
+ fwritezero(rel_padcnt64, ofile);
/* emit relocation entries */
for (s = sects; s != NULL; s = s->next)
for (sym = syms; sym != NULL; sym = sym->next) {
if ((sym->type & N_EXT) == 0) {
- fwriteint32_t(sym->strx, machofp); /* string table entry number */
- fwrite(&sym->type, 1, 1, machofp); /* symbol type */
- fwrite(&sym->sect, 1, 1, machofp); /* section */
- fwriteint16_t(sym->desc, machofp); /* description */
+ fwriteint32_t(sym->strx, ofile); /* string table entry number */
+ fwrite(&sym->type, 1, 1, ofile); /* symbol type */
+ fwrite(&sym->sect, 1, 1, ofile); /* section */
+ fwriteint16_t(sym->desc, ofile); /* description */
/* Fix up the symbol value now that we know the final section
sizes. */
sym->value += s->size;
}
- fwriteint64_t(sym->value, machofp); /* value (i.e. offset) */
+ fwriteint64_t(sym->value, ofile); /* value (i.e. offset) */
}
}
for (i = 0; i < nextdefsym; i++) {
sym = extdefsyms[i];
- fwriteint32_t(sym->strx, machofp);
- fwrite(&sym->type, 1, 1, machofp); /* symbol type */
- fwrite(&sym->sect, 1, 1, machofp); /* section */
- fwriteint16_t(sym->desc, machofp); /* description */
+ fwriteint32_t(sym->strx, ofile);
+ fwrite(&sym->type, 1, 1, ofile); /* symbol type */
+ fwrite(&sym->sect, 1, 1, ofile); /* section */
+ fwriteint16_t(sym->desc, ofile); /* description */
/* Fix up the symbol value now that we know the final section
sizes. */
sym->value += s->size;
}
- fwriteint64_t(sym->value, machofp); /* value (i.e. offset) */
+ fwriteint64_t(sym->value, ofile); /* value (i.e. offset) */
}
for (i = 0; i < nundefsym; i++) {
sym = undefsyms[i];
- fwriteint32_t(sym->strx, machofp);
- fwrite(&sym->type, 1, 1, machofp); /* symbol type */
- fwrite(&sym->sect, 1, 1, machofp); /* section */
- fwriteint16_t(sym->desc, machofp); /* description */
+ fwriteint32_t(sym->strx, ofile);
+ fwrite(&sym->type, 1, 1, ofile); /* symbol type */
+ fwrite(&sym->sect, 1, 1, ofile); /* section */
+ fwriteint16_t(sym->desc, ofile); /* description */
// Fix up the symbol value now that we know the final section sizes.
if (((sym->type & N_TYPE) == N_SECT) && (sym->sect != NO_SECT)) {
sym->value += s->size;
}
- fwriteint64_t(sym->value, machofp); // value (i.e. offset)
+ fwriteint64_t(sym->value, ofile); // value (i.e. offset)
}
}
if (seg_nsects64 > 0)
offset = macho_write_segment (offset);
else
- error(ERR_WARNING, "no sections?");
+ nasm_error(ERR_WARNING, "no sections?");
if (nsyms > 0) {
/* write out symbol command */
- fwriteint32_t(LC_SYMTAB, machofp); /* cmd == LC_SYMTAB */
- fwriteint32_t(MACHO_SYMCMD_SIZE, machofp); /* size of load command */
- fwriteint32_t(offset, machofp); /* symbol table offset */
- fwriteint32_t(nsyms, machofp); /* number of symbol
+ fwriteint32_t(LC_SYMTAB, ofile); /* cmd == LC_SYMTAB */
+ fwriteint32_t(MACHO_SYMCMD_SIZE, ofile); /* size of load command */
+ fwriteint32_t(offset, ofile); /* symbol table offset */
+ fwriteint32_t(nsyms, ofile); /* number of symbol
** table entries */
offset += nsyms * MACHO_NLIST64_SIZE;
- fwriteint32_t(offset, machofp); /* string table offset */
- fwriteint32_t(strslen, machofp); /* string table size */
+ fwriteint32_t(offset, ofile); /* string table offset */
+ fwriteint32_t(strslen, ofile); /* string table size */
}
/* emit section data */
/* we don't need to pad here since MACHO_NLIST64_SIZE == 16 */
/* emit string table */
- saa_fpwrite(strs, machofp);
+ saa_fpwrite(strs, ofile);
}
/* We do quite a bit here, starting with finalizing all of the data
for the object file, writing, and then freeing all of the data from
#include "nasm.h"
#include "nasmlib.h"
#include "stdscan.h"
+#include "eval.h"
#include "output/outform.h"
#include "output/outlib.h"
static char obj_infile[FILENAME_MAX];
-static efunc error;
-static evalfunc evaluate;
-static ldfunc deflabel;
-static FILE *ofp;
static int32_t first_seg;
static bool any_segs;
static int passtwo;
static void obj_write_file(int debuginfo);
static int obj_directive(enum directives, char *, int);
-static void obj_init(FILE * fp, efunc errfunc, ldfunc ldef, evalfunc eval)
+static void obj_init(void)
{
- ofp = fp;
- error = errfunc;
- evaluate = eval;
- deflabel = ldef;
first_seg = seg_alloc();
any_segs = false;
fpubhead = NULL;
obj_entry_ofs = offset;
return;
}
- error(ERR_NONFATAL, "unrecognised special symbol `%s'", name);
+ nasm_error(ERR_NONFATAL, "unrecognised special symbol `%s'", name);
}
/*
pub->segment = (segment == NO_SEG ? 0 : segment & ~SEG_ABS);
}
if (special)
- error(ERR_NONFATAL, "OBJ supports no special symbol features"
+ nasm_error(ERR_NONFATAL, "OBJ supports no special symbol features"
" for this symbol type");
return;
}
if (!any_segs && segment == first_seg) {
int tempint; /* ignored */
if (segment != obj_segment("__NASMDEFSEG", 2, &tempint))
- error(ERR_PANIC, "strange segment conditions in OBJ driver");
+ nasm_error(ERR_PANIC, "strange segment conditions in OBJ driver");
}
for (seg = seghead; seg && is_global; seg = seg->next)
loc->offset = offset;
if (special)
- error(ERR_NONFATAL,
+ nasm_error(ERR_NONFATAL,
"OBJ supports no special symbol features"
" for this symbol type");
return;
obj_ext_set_defwrt(ext, p);
special += len;
if (*special && *special != ':')
- error(ERR_NONFATAL, "`:' expected in special symbol"
+ nasm_error(ERR_NONFATAL, "`:' expected in special symbol"
" text for `%s'", ext->name);
else if (*special == ':')
special++;
if (ext->commonsize)
ext->commonelem = 1;
else
- error(ERR_NONFATAL,
+ nasm_error(ERR_NONFATAL,
"`%s': `far' keyword may only be applied"
" to common variables\n", ext->name);
special += 3;
if (ext->commonsize)
ext->commonelem = 0;
else
- error(ERR_NONFATAL,
+ nasm_error(ERR_NONFATAL,
"`%s': `far' keyword may only be applied"
" to common variables\n", ext->name);
special += 4;
stdscan_reset();
stdscan_bufptr = special;
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 common-variable element size");
else
ext->commonelem = reloc_value(e);
}
special = stdscan_bufptr;
} else {
- error(ERR_NONFATAL,
+ nasm_error(ERR_NONFATAL,
"`%s': element-size specifications only"
" apply to common variables", ext->name);
while (*special && *special != ':')
ext->index = ++externals;
if (special && !used_special)
- error(ERR_NONFATAL, "OBJ supports no special symbol features"
+ nasm_error(ERR_NONFATAL, "OBJ supports no special symbol features"
" for this symbol type");
}
*/
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;
}
if (!any_segs) {
int tempint; /* ignored */
if (segto != obj_segment("__NASMDEFSEG", 2, &tempint))
- error(ERR_PANIC, "strange segment conditions in OBJ driver");
+ nasm_error(ERR_PANIC, "strange segment conditions in OBJ driver");
}
/*
if (seg->index == segto)
break;
if (!seg)
- error(ERR_PANIC, "code directed to nonexistent segment?");
+ nasm_error(ERR_PANIC, "code directed to nonexistent segment?");
orp = seg->orp;
orp->parm[0] = seg->currentpos;
int rsize;
if (segment == NO_SEG && type != OUT_ADDRESS)
- error(ERR_NONFATAL, "relative call to absolute address not"
+ nasm_error(ERR_NONFATAL, "relative call to absolute address not"
" supported by OBJ format");
if (segment >= SEG_ABS)
- error(ERR_NONFATAL, "far-absolute relocations not supported"
+ nasm_error(ERR_NONFATAL, "far-absolute relocations not supported"
" by OBJ format");
ldata = *(int64_t *)data;
if (type == OUT_REL2ADR) {
*/
rsize = 2;
if (ldata & 0xFFFF)
- error(ERR_NONFATAL, "OBJ format cannot handle complex"
+ nasm_error(ERR_NONFATAL, "OBJ format cannot handle complex"
" dword-size segment base references");
}
if (segment != NO_SEG)
ObjRecord *forp;
if (bytes == 1) {
- error(ERR_NONFATAL, "`obj' output driver does not support"
+ nasm_error(ERR_NONFATAL, "`obj' output driver does not support"
" one-byte relocations");
return;
}
locat = FIX_16_SELECTOR;
seg--;
if (bytes != 2)
- error(ERR_PANIC, "OBJ: 4-byte segment base fixup got"
+ nasm_error(ERR_PANIC, "OBJ: 4-byte segment base fixup got"
" through sanity check");
} else {
base = false;
if (eb)
method = 6, e = eb->exts[i], tidx = e->index;
else
- error(ERR_PANIC,
+ nasm_error(ERR_PANIC,
"unrecognised segment value in obj_write_fixup");
}
}
else if (e->defwrt_type == DEFWRT_GROUP)
method |= 0x10, fidx = e->defwrt_ptr.grp->obj_index;
else {
- error(ERR_NONFATAL, "default WRT specification for"
+ nasm_error(ERR_NONFATAL, "default WRT specification for"
" external `%s' unresolved", e->name);
method |= 0x50, fidx = -1; /* got to do _something_ */
}
if (eb)
method |= 0x20, fidx = eb->exts[i]->index;
else
- error(ERR_PANIC,
+ nasm_error(ERR_PANIC,
"unrecognised WRT value in obj_write_fixup");
}
}
obj_idx++;
if (!strcmp(seg->name, name)) {
if (attrs > 0 && pass == 1)
- error(ERR_WARNING, "segment attributes specified on"
+ nasm_error(ERR_WARNING, "segment attributes specified on"
" redeclaration of segment: ignoring");
if (seg->use32)
*bits = 32;
if (!strcmp(grp->name, "FLAT"))
break;
if (!grp)
- error(ERR_PANIC, "failure to define FLAT?!");
+ nasm_error(ERR_PANIC, "failure to define FLAT?!");
}
seg->grp = grp;
} else if (!nasm_strnicmp(p, "class=", 6))
seg->align = readnum(p + 6, &rn_error);
if (rn_error) {
seg->align = 1;
- error(ERR_NONFATAL, "segment alignment should be"
+ nasm_error(ERR_NONFATAL, "segment alignment should be"
" numeric");
}
switch ((int)seg->align) {
case 4096: /* PharLap extension */
break;
case 8:
- error(ERR_WARNING,
+ nasm_error(ERR_WARNING,
"OBJ format does not support alignment"
" of 8: rounding up to 16");
seg->align = 16;
case 32:
case 64:
case 128:
- error(ERR_WARNING,
+ nasm_error(ERR_WARNING,
"OBJ format does not support alignment"
" of %d: rounding up to 256", seg->align);
seg->align = 256;
case 512:
case 1024:
case 2048:
- error(ERR_WARNING,
+ nasm_error(ERR_WARNING,
"OBJ format does not support alignment"
" of %d: rounding up to 4096", seg->align);
seg->align = 4096;
break;
default:
- error(ERR_NONFATAL, "invalid alignment value %d",
+ nasm_error(ERR_NONFATAL, "invalid alignment value %d",
seg->align);
seg->align = 1;
break;
} else if (!nasm_strnicmp(p, "absolute=", 9)) {
seg->align = SEG_ABS + readnum(p + 9, &rn_error);
if (rn_error)
- error(ERR_NONFATAL, "argument to `absolute' segment"
+ nasm_error(ERR_NONFATAL, "argument to `absolute' segment"
" attribute should be numeric");
}
}
obj_seg_needs_update = seg;
if (seg->align >= SEG_ABS)
- deflabel(name, NO_SEG, seg->align - SEG_ABS,
- NULL, false, false, &of_obj, error);
+ define_label(name, NO_SEG, seg->align - SEG_ABS,
+ NULL, false, false, &of_obj, nasm_error);
else
- deflabel(name, seg->index + 1, 0L,
- NULL, false, false, &of_obj, error);
+ define_label(name, seg->index + 1, 0L,
+ NULL, false, false, &of_obj, nasm_error);
obj_seg_needs_update = NULL;
/*
grp->segs[i] = grp->segs[grp->nindices];
grp->segs[grp->nindices++].index = seg->obj_index;
if (seg->grp)
- error(ERR_WARNING,
+ nasm_error(ERR_WARNING,
"segment `%s' is already part of"
" a group: first one takes precedence",
seg->name);
* practice, so the sanity check has been removed.
*
* if (!*q) {
- * error(ERR_NONFATAL,"GROUP directive contains no segments");
+ * nasm_error(ERR_NONFATAL,"GROUP directive contains no segments");
* return 1;
* }
*/
for (grp = grphead; grp; grp = grp->next) {
obj_idx++;
if (!strcmp(grp->name, v)) {
- error(ERR_NONFATAL, "group `%s' defined twice", v);
+ nasm_error(ERR_NONFATAL, "group `%s' defined twice", v);
return 1;
}
}
grp->name = NULL;
obj_grp_needs_update = grp;
- deflabel(v, grp->index + 1, 0L,
- NULL, false, false, &of_obj, error);
+ define_label(v, grp->index + 1, 0L,
+ NULL, false, false, &of_obj, nasm_error);
obj_grp_needs_update = NULL;
while (*q) {
grp->segs[grp->nentries++] = grp->segs[grp->nindices];
grp->segs[grp->nindices++].index = seg->obj_index;
if (seg->grp)
- error(ERR_WARNING,
+ nasm_error(ERR_WARNING,
"segment `%s' is already part of"
" a group: first one takes precedence",
seg->name);
impname = q;
if (!*extname || !*libname)
- error(ERR_NONFATAL, "`import' directive requires symbol name"
+ nasm_error(ERR_NONFATAL, "`import' directive requires symbol name"
" and library name");
else {
struct ImpDef *imp;
}
if (!*intname) {
- error(ERR_NONFATAL, "`export' directive requires export name");
+ nasm_error(ERR_NONFATAL, "`export' directive requires export name");
return 1;
}
if (!*extname) {
bool err = false;
flags |= EXPDEF_MASK_PARMCNT & readnum(v + 5, &err);
if (err) {
- error(ERR_NONFATAL,
+ nasm_error(ERR_NONFATAL,
"value `%s' for `parm' is non-numeric", v + 5);
return 1;
}
bool err = false;
ordinal = readnum(v, &err);
if (err) {
- error(ERR_NONFATAL,
+ nasm_error(ERR_NONFATAL,
"unrecognised export qualifier `%s'", v);
return 1;
}
return segment; /* no special treatment */
}
-static void obj_filename(char *inname, char *outname, efunc lerror)
+static void obj_filename(char *inname, char *outname)
{
strcpy(obj_infile, inname);
- standard_extension(inname, outname, ".obj", lerror);
+ standard_extension(inname, outname, ".obj");
}
static void obj_write_file(int debuginfo)
/* acbp |= 0x00 */ ;
else if (seg->align >= 4096) {
if (seg->align > 4096)
- error(ERR_NONFATAL, "segment `%s' requires more alignment"
+ nasm_error(ERR_NONFATAL, "segment `%s' requires more alignment"
" than OBJ format supports", seg->name);
acbp |= 0xC0; /* PharLap extension */
} else if (seg->align >= 256) {
if (grp->nindices != grp->nentries) {
for (i = grp->nindices; i < grp->nentries; i++) {
- error(ERR_NONFATAL, "group `%s' contains undefined segment"
+ nasm_error(ERR_NONFATAL, "group `%s' contains undefined segment"
" `%s'", grp->name, grp->segs[i].name);
nasm_free(grp->segs[i].name);
grp->segs[i].name = NULL;
}
}
if (!seg)
- error(ERR_NONFATAL, "entry point is not in this module");
+ nasm_error(ERR_NONFATAL, "entry point is not in this module");
}
/*
cksum = orp->type;
if (orp->x_size == 32)
cksum |= 1;
- fputc(cksum, ofp);
+ fputc(cksum, ofile);
len = orp->committed + 1;
cksum += (len & 0xFF) + ((len >> 8) & 0xFF);
- fwriteint16_t(len, ofp);
- fwrite(orp->buf, 1, len - 1, ofp);
+ fwriteint16_t(len, ofile);
+ fwrite(orp->buf, 1, len - 1, ofile);
for (ptr = orp->buf; --len; ptr++)
cksum += *ptr;
- fputc((-cksum) & 0xFF, ofp);
+ fputc((-cksum) & 0xFF, ofile);
}
extern macros_t obj_stdmac[];
-void dbgbi_init(struct ofmt *of, void *id, FILE * fp, efunc error)
+void dbgbi_init(void)
{
- (void)of;
- (void)id;
- (void)fp;
- (void)error;
-
fnhead = NULL;
fntail = &fnhead;
arrindex = ARRAYBOT;
if (!any_segs) {
int tempint; /* ignored */
if (segto != obj_segment("__NASMDEFSEG", 2, &tempint))
- error(ERR_PANIC, "strange segment conditions in OBJ driver");
+ nasm_error(ERR_PANIC, "strange segment conditions in OBJ driver");
}
/*
if (seg->index == segto)
break;
if (!seg)
- error(ERR_PANIC, "lineno directed to nonexistent segment?");
+ nasm_error(ERR_PANIC, "lineno directed to nonexistent segment?");
/* for (fn = fnhead; fn; fn = fnhead->next) */
for (fn = fnhead; fn; fn = fn->next) /* fbk - Austin Lunnen - John Fine */
static struct SAA *seg[RDF_MAXSEGS]; /* seg 0 = code, seg 1 = data */
static struct SAA *header; /* relocation/import/export records */
-static FILE *ofile;
-
-static efunc error;
-
static struct seginfo {
char *segname;
int segnumber;
static int32_t bsslength;
static int32_t headerlength;
-static void rdf2_init(FILE * fp, efunc errfunc, ldfunc ldef, evalfunc eval)
+static void rdf2_init(void)
{
int segtext, segdata, segbss;
- (void)ldef;
- (void)eval;
-
maxbits = 64;
/* set up the initial segments */
nsegments = 3;
- ofile = fp;
- error = errfunc;
-
seg[0] = saa_init(1L);
seg[1] = saa_init(1L);
seg[2] = NULL; /* special case! */
segdata = seg_alloc();
segbss = seg_alloc();
if (segtext != 0 || segdata != 2 || segbss != 4)
- error(ERR_PANIC,
+ nasm_error(ERR_PANIC,
"rdf segment numbers not allocated as expected (%d,%d,%d)",
segtext, segdata, segbss);
bsslength = 0;
reserved = readnum(q, &err);
if (err) {
- error(ERR_NONFATAL,
+ nasm_error(ERR_NONFATAL,
"value following comma must be numeric");
reserved = 0;
}
if (code == -1) { /* didn't find anything */
code = readnum(p, &err);
if (err) {
- error(ERR_NONFATAL, "unrecognised RDF segment type (%s)",
+ nasm_error(ERR_NONFATAL, "unrecognised RDF segment type (%s)",
p);
code = 3;
}
for (i = 0; i < nsegments; i++) {
if (!strcmp(name, segments[i].segname)) {
if (code != -1 || reserved != 0)
- error(ERR_NONFATAL, "segment attributes specified on"
+ nasm_error(ERR_NONFATAL, "segment attributes specified on"
" redeclaration of segment");
return segments[i].segnumber * 2;
}
/* declaring a new segment! */
if (code == -1) {
- error(ERR_NONFATAL, "new segment declared without type code");
+ nasm_error(ERR_NONFATAL, "new segment declared without type code");
code = 3;
}
if (nsegments == RDF_MAXSEGS) {
- error(ERR_FATAL, "reached compiled-in maximum segment limit (%d)",
+ nasm_error(ERR_FATAL, "reached compiled-in maximum segment limit (%d)",
RDF_MAXSEGS);
return NO_SEG;
}
segments[nsegments].segname = nasm_strdup(name);
i = seg_alloc();
if (i % 2 != 0)
- error(ERR_PANIC, "seg_alloc() returned odd number");
+ nasm_error(ERR_PANIC, "seg_alloc() returned odd number");
segments[nsegments].segnumber = i >> 1;
segments[nsegments].segtype = code;
segments[nsegments].segreserved = reserved;
/* Check if the label length is OK */
if ((len = strlen(name)) >= EXIM_LABEL_MAX) {
- error(ERR_NONFATAL, "label size exceeds %d bytes", EXIM_LABEL_MAX);
+ nasm_error(ERR_NONFATAL, "label size exceeds %d bytes", EXIM_LABEL_MAX);
return;
}
if (!len) {
- error(ERR_NONFATAL, "zero-length label");
+ nasm_error(ERR_NONFATAL, "zero-length label");
return;
}
bool err;
ci.align = readnum(special, &err);
if (err)
- error(ERR_NONFATAL, "alignment constraint `%s' is not a"
+ nasm_error(ERR_NONFATAL, "alignment constraint `%s' is not a"
" valid number", special);
else if ((ci.align | (ci.align - 1)) != 2 * ci.align - 1)
- error(ERR_NONFATAL, "alignment constraint `%s' is not a"
+ nasm_error(ERR_NONFATAL, "alignment constraint `%s' is not a"
" power of two", special);
}
write_common_rec(&ci);
!nasm_stricmp(special, "object")) {
symflags |= SYM_DATA;
} else
- error(ERR_NONFATAL, "unrecognised symbol type `%s'",
+ nasm_error(ERR_NONFATAL, "unrecognised symbol type `%s'",
special);
}
}
if (name[0] == '.' && name[1] == '.' && name[2] != '@') {
- error(ERR_NONFATAL, "unrecognised special symbol `%s'", name);
+ nasm_error(ERR_NONFATAL, "unrecognised special symbol `%s'", name);
return;
}
if (i >= nsegments) { /* EXTERN declaration */
ri.type = farsym ? RDFREC_FARIMPORT : RDFREC_IMPORT;
if (symflags & SYM_GLOBAL)
- error(ERR_NONFATAL,
+ nasm_error(ERR_NONFATAL,
"symbol type conflict - EXTERN cannot be EXPORT");
ri.flags = symflags;
ri.segment = segment;
} else if (is_global) {
r.type = RDFREC_GLOBAL; /* GLOBAL declaration */
if (symflags & SYM_IMPORT)
- error(ERR_NONFATAL,
+ nasm_error(ERR_NONFATAL,
"symbol type conflict - GLOBAL cannot be IMPORT");
r.flags = symflags;
r.segment = segment;
break;
}
if (i == nsegments)
- error(ERR_PANIC, "can't find segment %d", segment);
+ nasm_error(ERR_PANIC, "can't find segment %d", segment);
if (bytes < 0) {
b = buf;
break;
}
if (i == nsegments)
- error(ERR_PANIC, "can't find segment %d", segment);
+ nasm_error(ERR_PANIC, "can't find segment %d", segment);
return segments[i].seglength;
}
if (segto == NO_SEG) {
if (type != OUT_RESERVE)
- error(ERR_NONFATAL,
+ nasm_error(ERR_NONFATAL,
"attempt to assemble code in ABSOLUTE space");
return;
}
break;
}
if (seg >= nsegments) {
- error(ERR_NONFATAL,
+ nasm_error(ERR_NONFATAL,
"specified segment not supported by rdf output format");
return;
}
if (wrt != NO_SEG) {
wrt = NO_SEG; /* continue to do _something_ */
- error(ERR_NONFATAL, "WRT not supported by rdf output format");
+ nasm_error(ERR_NONFATAL, "WRT not supported by rdf output format");
}
if (segto == 2 && type != OUT_RESERVE) {
- error(ERR_NONFATAL, "BSS segments may not be initialized");
+ nasm_error(ERR_NONFATAL, "BSS segments may not be initialized");
/* just reserve the space for now... */
membufwrite(segto, databuf, 1);
} 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");
membufwrite(segto, data, size);
} else if (type == OUT_ADDRESS) {
membufwrite(segto, databuf, size);
} else if (type == OUT_REL2ADR) {
if (segment == segto)
- error(ERR_PANIC, "intra-segment OUT_REL2ADR");
+ nasm_error(ERR_PANIC, "intra-segment OUT_REL2ADR");
rr.reclen = 8;
rr.offset = getsegmentlength(segto); /* current offset */
membufwrite(segto, &rr.offset, -2);
} else if (type == OUT_REL4ADR) {
if ((segment == segto) && (globalbits != 64))
- error(ERR_PANIC, "intra-segment OUT_REL4ADR");
+ nasm_error(ERR_PANIC, "intra-segment OUT_REL4ADR");
if (segment != NO_SEG && segment % 2) {
- error(ERR_PANIC, "erm... 4 byte segment base ref?");
+ nasm_error(ERR_PANIC, "erm... 4 byte segment base ref?");
}
rr.type = RDFREC_RELOC; /* type signature */
case D_LIBRARY:
n = strlen(value);
if (n >= MODLIB_NAME_MAX) {
- error(ERR_NONFATAL, "name size exceeds %d bytes", MODLIB_NAME_MAX);
+ nasm_error(ERR_NONFATAL, "name size exceeds %d bytes", MODLIB_NAME_MAX);
return 1;
}
if (pass == 1) {
case D_MODULE:
if ((n = strlen(value)) >= MODLIB_NAME_MAX) {
- error(ERR_NONFATAL, "name size exceeds %d bytes", MODLIB_NAME_MAX);
+ nasm_error(ERR_NONFATAL, "name size exceeds %d bytes", MODLIB_NAME_MAX);
return 1;
}
if (pass == 1) {
}
}
-static void rdf2_filename(char *inname, char *outname, efunc error)
+static void rdf2_filename(char *inname, char *outname)
{
- standard_extension(inname, outname, ".rdf", error);
+ standard_extension(inname, outname, ".rdf");
}
extern macros_t rdf2_stdmac[];
{
struct RAA *result;
- if (posn < 0)
- nasm_malloc_error(ERR_PANIC, "negative position in raa_write");
+ nasm_assert(posn >= 0);
while ((UINT32_C(1) << (r->shift + LAYERSHIFT(r))) <= (uint32_t) posn) {
/*
{
void *p;
- if (s->wpos % s->elem_len)
- nasm_malloc_error(ERR_PANIC | ERR_NOFILE,
- "misaligned wpos in saa_wstruct");
+ nasm_assert((s->wpos % s->elem_len) == 0);
if (s->wpos + s->elem_len > s->blk_len) {
- if (s->wpos != s->blk_len)
- nasm_malloc_error(ERR_PANIC | ERR_NOFILE,
- "unfilled block in saa_wstruct");
-
+ nasm_assert(s->wpos == s->blk_len);
if (s->wptr + s->elem_len > s->length)
saa_extend(s);
s->wblk++;
if (s->rptr + s->elem_len > s->datalen)
return NULL;
- if (s->rpos % s->elem_len)
- nasm_malloc_error(ERR_PANIC | ERR_NOFILE,
- "misaligned rpos in saa_rstruct");
+ nasm_assert((s->rpos % s->elem_len) == 0);
if (s->rpos + s->elem_len > s->blk_len) {
s->rblk++;
{
char *d = data;
- if (s->rptr + len > s->datalen) {
- nasm_malloc_error(ERR_PANIC | ERR_NOFILE,
- "overrun in saa_rnbytes");
- return;
- }
+ nasm_assert(s->rptr + len <= s->datalen);
while (len) {
size_t l;
{
size_t ix;
- if (posn + len > s->datalen) {
- nasm_malloc_error(ERR_PANIC | ERR_NOFILE, "overrun in saa_fread");
- return;
- }
+ nasm_assert(posn + len <= s->datalen);
if (likely(s->blk_len == SAA_BLKLEN)) {
ix = posn >> SAA_BLKSHIFT;
{
size_t ix;
- if (posn > s->datalen) {
- /* Seek beyond the end of the existing array not supported */
- nasm_malloc_error(ERR_PANIC | ERR_NOFILE, "overrun in saa_fwrite");
- return;
- }
+ /* Seek beyond the end of the existing array not supported */
+ nasm_assert(posn <= s->datalen);
if (likely(s->blk_len == SAA_BLKLEN)) {
ix = posn >> SAA_BLKSHIFT;