mirror of
https://github.com/netwide-assembler/nasm.git
synced 2025-10-10 00:25:06 -04:00
errors: simplify nasm_fatal() and nasm_panic()
Nearly all instances of nasm_fatal() and nasm_panic() take a flags argument of zero. Simplify the code by making nasm_fatal and nasm_panic default to no flags, and add an alternate version if flags really are desired. This also means that every call site doesn't have to initialize a zero argument. Furthermore, ERR_NOFILE is now often not necessary, as the error code will no longer cause a null reference if there is no current file. Therefore, we can remove many instances of ERR_NOFILE which only deprives the user of information. Signed-off-by: H. Peter Anvin <hpa@zytor.com>
This commit is contained in:
@@ -1317,7 +1317,7 @@ static int64_t calcsize(int32_t segment, int64_t offset, int bits,
|
|||||||
break;
|
break;
|
||||||
|
|
||||||
default:
|
default:
|
||||||
nasm_panic(0, "internal instruction table corrupt"
|
nasm_panic("internal instruction table corrupt"
|
||||||
": instruction code \\%o (0x%02X) given", c, c);
|
": instruction code \\%o (0x%02X) given", c, c);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
@@ -1548,7 +1548,7 @@ static int emit_prefix(struct out_data *data, const int bits, insn *ins)
|
|||||||
case P_none:
|
case P_none:
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
nasm_panic(0, "invalid instruction prefix");
|
nasm_panic("invalid instruction prefix");
|
||||||
}
|
}
|
||||||
if (c) {
|
if (c) {
|
||||||
if (data)
|
if (data)
|
||||||
@@ -1866,7 +1866,7 @@ static void gencode(struct out_data *data, insn *ins)
|
|||||||
|
|
||||||
case 0340:
|
case 0340:
|
||||||
if (ins->oprs[0].segment != NO_SEG)
|
if (ins->oprs[0].segment != NO_SEG)
|
||||||
nasm_panic(0, "non-constant BSS size in pass two");
|
nasm_panic("non-constant BSS size in pass two");
|
||||||
|
|
||||||
out_reserve(data, ins->oprs[0].offset);
|
out_reserve(data, ins->oprs[0].offset);
|
||||||
break;
|
break;
|
||||||
@@ -1976,7 +1976,7 @@ static void gencode(struct out_data *data, insn *ins)
|
|||||||
break;
|
break;
|
||||||
|
|
||||||
default:
|
default:
|
||||||
nasm_panic(0, "internal instruction table corrupt"
|
nasm_panic("internal instruction table corrupt"
|
||||||
": instruction code \\%o (0x%02X) given", c, c);
|
": instruction code \\%o (0x%02X) given", c, c);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
@@ -1986,14 +1986,14 @@ static void gencode(struct out_data *data, insn *ins)
|
|||||||
static opflags_t regflag(const operand * o)
|
static opflags_t regflag(const operand * o)
|
||||||
{
|
{
|
||||||
if (!is_register(o->basereg))
|
if (!is_register(o->basereg))
|
||||||
nasm_panic(0, "invalid operand passed to regflag()");
|
nasm_panic("invalid operand passed to regflag()");
|
||||||
return nasm_reg_flags[o->basereg];
|
return nasm_reg_flags[o->basereg];
|
||||||
}
|
}
|
||||||
|
|
||||||
static int32_t regval(const operand * o)
|
static int32_t regval(const operand * o)
|
||||||
{
|
{
|
||||||
if (!is_register(o->basereg))
|
if (!is_register(o->basereg))
|
||||||
nasm_panic(0, "invalid operand passed to regval()");
|
nasm_panic("invalid operand passed to regval()");
|
||||||
return nasm_regvals[o->basereg];
|
return nasm_regvals[o->basereg];
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -2003,7 +2003,7 @@ static int op_rexflags(const operand * o, int mask)
|
|||||||
int val;
|
int val;
|
||||||
|
|
||||||
if (!is_register(o->basereg))
|
if (!is_register(o->basereg))
|
||||||
nasm_panic(0, "invalid operand passed to op_rexflags()");
|
nasm_panic("invalid operand passed to op_rexflags()");
|
||||||
|
|
||||||
flags = nasm_reg_flags[o->basereg];
|
flags = nasm_reg_flags[o->basereg];
|
||||||
val = nasm_regvals[o->basereg];
|
val = nasm_regvals[o->basereg];
|
||||||
|
|||||||
@@ -395,7 +395,7 @@ bool process_directives(char *directive)
|
|||||||
} else if (passn == 1)
|
} else if (passn == 1)
|
||||||
absolute.offset = 0x100; /* don't go near zero in case of / */
|
absolute.offset = 0x100; /* don't go near zero in case of / */
|
||||||
else
|
else
|
||||||
nasm_panic(0, "invalid ABSOLUTE address "
|
nasm_panic("invalid ABSOLUTE address "
|
||||||
"in pass two");
|
"in pass two");
|
||||||
in_absolute = true;
|
in_absolute = true;
|
||||||
location.segment = NO_SEG;
|
location.segment = NO_SEG;
|
||||||
|
|||||||
26
asm/error.c
26
asm/error.c
@@ -88,7 +88,16 @@ void nasm_error(int severity, const char *fmt, ...)
|
|||||||
va_end(ap);
|
va_end(ap);
|
||||||
}
|
}
|
||||||
|
|
||||||
fatal_func nasm_fatal(int flags, const char *fmt, ...)
|
fatal_func nasm_fatal(const char *fmt, ...)
|
||||||
|
{
|
||||||
|
va_list ap;
|
||||||
|
|
||||||
|
va_start(ap, fmt);
|
||||||
|
nasm_verror(ERR_FATAL, fmt, ap);
|
||||||
|
abort(); /* We should never get here */
|
||||||
|
}
|
||||||
|
|
||||||
|
fatal_func nasm_fatal_fl(int flags, const char *fmt, ...)
|
||||||
{
|
{
|
||||||
va_list ap;
|
va_list ap;
|
||||||
|
|
||||||
@@ -97,7 +106,16 @@ fatal_func nasm_fatal(int flags, const char *fmt, ...)
|
|||||||
abort(); /* We should never get here */
|
abort(); /* We should never get here */
|
||||||
}
|
}
|
||||||
|
|
||||||
fatal_func nasm_panic(int flags, const char *fmt, ...)
|
fatal_func nasm_panic(const char *fmt, ...)
|
||||||
|
{
|
||||||
|
va_list ap;
|
||||||
|
|
||||||
|
va_start(ap, fmt);
|
||||||
|
nasm_verror(ERR_PANIC, fmt, ap);
|
||||||
|
abort(); /* We should never get here */
|
||||||
|
}
|
||||||
|
|
||||||
|
fatal_func nasm_panic_fl(int flags, const char *fmt, ...)
|
||||||
{
|
{
|
||||||
va_list ap;
|
va_list ap;
|
||||||
|
|
||||||
@@ -108,12 +126,12 @@ fatal_func nasm_panic(int flags, const char *fmt, ...)
|
|||||||
|
|
||||||
fatal_func nasm_panic_from_macro(const char *file, int line)
|
fatal_func nasm_panic_from_macro(const char *file, int line)
|
||||||
{
|
{
|
||||||
nasm_panic(ERR_NOFILE, "Internal error at %s:%d\n", file, line);
|
nasm_panic("internal error at %s:%d\n", file, line);
|
||||||
}
|
}
|
||||||
|
|
||||||
fatal_func nasm_assert_failed(const char *file, int line, const char *msg)
|
fatal_func nasm_assert_failed(const char *file, int line, const char *msg)
|
||||||
{
|
{
|
||||||
nasm_panic(0, "assertion %s failed at %s:%d", msg, file, line);
|
nasm_panic("assertion %s failed at %s:%d", msg, file, line);
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
|||||||
@@ -752,7 +752,7 @@ static int64_t eval_ifunc(int64_t val, enum ifunc func)
|
|||||||
break;
|
break;
|
||||||
|
|
||||||
default:
|
default:
|
||||||
nasm_panic(0, "invalid IFUNC token %d", func);
|
nasm_panic("invalid IFUNC token %d", func);
|
||||||
rv = 0;
|
rv = 0;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -732,11 +732,7 @@ static int to_float(const char *str, int s, uint8_t *result,
|
|||||||
const int bits = fmt->bytes * 8;
|
const int bits = fmt->bytes * 8;
|
||||||
const char *strend;
|
const char *strend;
|
||||||
|
|
||||||
if (!str[0]) {
|
nasm_assert(str[0]);
|
||||||
nasm_panic(0,
|
|
||||||
"internal errror: empty string passed to float_const");
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
strend = strchr(str, '\0');
|
strend = strchr(str, '\0');
|
||||||
if (strend[-1] == 'P' || strend[-1] == 'p')
|
if (strend[-1] == 'P' || strend[-1] == 'p')
|
||||||
@@ -916,7 +912,7 @@ int float_const(const char *number, int sign, uint8_t *result, int bytes)
|
|||||||
case 16:
|
case 16:
|
||||||
return to_float(number, sign, result, &ieee_128);
|
return to_float(number, sign, result, &ieee_128);
|
||||||
default:
|
default:
|
||||||
nasm_panic(0, "strange value %d passed to float_const", bytes);
|
nasm_panic("strange value %d passed to float_const", bytes);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
28
asm/nasm.c
28
asm/nasm.c
@@ -463,7 +463,7 @@ int main(int argc, char **argv)
|
|||||||
} else {
|
} else {
|
||||||
dfmt = dfmt_find(ofmt, debug_format);
|
dfmt = dfmt_find(ofmt, debug_format);
|
||||||
if (!dfmt) {
|
if (!dfmt) {
|
||||||
nasm_fatal(ERR_NOFILE | ERR_USAGE,
|
nasm_fatal_fl(ERR_NOFILE | ERR_USAGE,
|
||||||
"unrecognized debug format `%s' for"
|
"unrecognized debug format `%s' for"
|
||||||
" output format `%s'",
|
" output format `%s'",
|
||||||
debug_format, ofmt->shortname);
|
debug_format, ofmt->shortname);
|
||||||
@@ -505,7 +505,7 @@ int main(int argc, char **argv)
|
|||||||
if (outname) {
|
if (outname) {
|
||||||
ofile = nasm_open_write(outname, NF_TEXT);
|
ofile = nasm_open_write(outname, NF_TEXT);
|
||||||
if (!ofile)
|
if (!ofile)
|
||||||
nasm_fatal(ERR_NOFILE,
|
nasm_fatal_fl(ERR_NOFILE,
|
||||||
"unable to open output file `%s'",
|
"unable to open output file `%s'",
|
||||||
outname);
|
outname);
|
||||||
} else
|
} else
|
||||||
@@ -550,7 +550,7 @@ int main(int argc, char **argv)
|
|||||||
if (operating_mode & OP_NORMAL) {
|
if (operating_mode & OP_NORMAL) {
|
||||||
ofile = nasm_open_write(outname, (ofmt->flags & OFMT_TEXT) ? NF_TEXT : NF_BINARY);
|
ofile = nasm_open_write(outname, (ofmt->flags & OFMT_TEXT) ? NF_TEXT : NF_BINARY);
|
||||||
if (!ofile)
|
if (!ofile)
|
||||||
nasm_fatal(ERR_NOFILE,
|
nasm_fatal_fl(ERR_NOFILE,
|
||||||
"unable to open output file `%s'", outname);
|
"unable to open output file `%s'", outname);
|
||||||
|
|
||||||
/*
|
/*
|
||||||
@@ -623,7 +623,7 @@ static char *get_param(char *p, char *q, bool *advance)
|
|||||||
static void copy_filename(const char **dst, const char *src, const char *what)
|
static void copy_filename(const char **dst, const char *src, const char *what)
|
||||||
{
|
{
|
||||||
if (*dst)
|
if (*dst)
|
||||||
nasm_fatal(0, "more than one %s file specified: %s\n", what, src);
|
nasm_fatal("more than one %s file specified: %s\n", what, src);
|
||||||
|
|
||||||
*dst = nasm_strdup(src);
|
*dst = nasm_strdup(src);
|
||||||
}
|
}
|
||||||
@@ -854,7 +854,7 @@ static bool process_arg(char *p, char *q, int pass)
|
|||||||
if (pass == 1) {
|
if (pass == 1) {
|
||||||
ofmt = ofmt_find(param, &ofmt_alias);
|
ofmt = ofmt_find(param, &ofmt_alias);
|
||||||
if (!ofmt) {
|
if (!ofmt) {
|
||||||
nasm_fatal(ERR_NOFILE | ERR_USAGE,
|
nasm_fatal_fl(ERR_NOFILE | ERR_USAGE,
|
||||||
"unrecognised output format `%s' - "
|
"unrecognised output format `%s' - "
|
||||||
"use -hf for a list", param);
|
"use -hf for a list", param);
|
||||||
}
|
}
|
||||||
@@ -895,8 +895,7 @@ static bool process_arg(char *p, char *q, int pass)
|
|||||||
break;
|
break;
|
||||||
|
|
||||||
default:
|
default:
|
||||||
nasm_fatal(0,
|
nasm_fatal("unknown optimization option -O%c\n",
|
||||||
"unknown optimization option -O%c\n",
|
|
||||||
*param);
|
*param);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
@@ -955,7 +954,7 @@ static bool process_arg(char *p, char *q, int pass)
|
|||||||
else if (nasm_stricmp("gnu", param) == 0)
|
else if (nasm_stricmp("gnu", param) == 0)
|
||||||
nasm_set_verror(nasm_verror_gnu);
|
nasm_set_verror(nasm_verror_gnu);
|
||||||
else
|
else
|
||||||
nasm_fatal(ERR_NOFILE | ERR_USAGE,
|
nasm_fatal_fl(ERR_NOFILE | ERR_USAGE,
|
||||||
"unrecognized error reporting format `%s'",
|
"unrecognized error reporting format `%s'",
|
||||||
param);
|
param);
|
||||||
}
|
}
|
||||||
@@ -1354,19 +1353,19 @@ static void parse_cmdline(int argc, char **argv, int pass)
|
|||||||
return;
|
return;
|
||||||
|
|
||||||
if (!inname)
|
if (!inname)
|
||||||
nasm_fatal(ERR_NOFILE | ERR_USAGE, "no input file specified");
|
nasm_fatal_fl(ERR_NOFILE | ERR_USAGE, "no input file specified");
|
||||||
|
|
||||||
else if ((errname && !strcmp(inname, errname)) ||
|
else if ((errname && !strcmp(inname, errname)) ||
|
||||||
(outname && !strcmp(inname, outname)) ||
|
(outname && !strcmp(inname, outname)) ||
|
||||||
(listname && !strcmp(inname, listname)) ||
|
(listname && !strcmp(inname, listname)) ||
|
||||||
(depend_file && !strcmp(inname, depend_file)))
|
(depend_file && !strcmp(inname, depend_file)))
|
||||||
nasm_fatal(ERR_USAGE, "will not overwrite input file");
|
nasm_fatal_fl(ERR_USAGE, "will not overwrite input file");
|
||||||
|
|
||||||
if (errname) {
|
if (errname) {
|
||||||
error_file = nasm_open_write(errname, NF_TEXT);
|
error_file = nasm_open_write(errname, NF_TEXT);
|
||||||
if (!error_file) {
|
if (!error_file) {
|
||||||
error_file = stderr; /* Revert to default! */
|
error_file = stderr; /* Revert to default! */
|
||||||
nasm_fatal(ERR_NOFILE | ERR_USAGE,
|
nasm_fatal_fl(ERR_NOFILE | ERR_USAGE,
|
||||||
"cannot open file `%s' for error messages",
|
"cannot open file `%s' for error messages",
|
||||||
errname);
|
errname);
|
||||||
}
|
}
|
||||||
@@ -1386,11 +1385,11 @@ static void assemble_file(const char *fname, StrList **depend_ptr)
|
|||||||
break;
|
break;
|
||||||
case 32:
|
case 32:
|
||||||
if (!iflag_cpu_level_ok(&cmd_cpu, IF_386))
|
if (!iflag_cpu_level_ok(&cmd_cpu, IF_386))
|
||||||
nasm_fatal(0, "command line: 32-bit segment size requires a higher cpu");
|
nasm_fatal("command line: 32-bit segment size requires a higher cpu");
|
||||||
break;
|
break;
|
||||||
case 64:
|
case 64:
|
||||||
if (!iflag_cpu_level_ok(&cmd_cpu, IF_X86_64))
|
if (!iflag_cpu_level_ok(&cmd_cpu, IF_X86_64))
|
||||||
nasm_fatal(0, "command line: 64-bit segment size requires a higher cpu");
|
nasm_fatal("command line: 64-bit segment size requires a higher cpu");
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
panic();
|
panic();
|
||||||
@@ -1434,8 +1433,7 @@ static void assemble_file(const char *fname, StrList **depend_ptr)
|
|||||||
|
|
||||||
while ((line = preproc->getline())) {
|
while ((line = preproc->getline())) {
|
||||||
if (++globallineno > nasm_limit[LIMIT_LINES])
|
if (++globallineno > nasm_limit[LIMIT_LINES])
|
||||||
nasm_fatal(0,
|
nasm_fatal("overall line count exceeds the maximum %"PRId64"\n",
|
||||||
"overall line count exceeds the maximum %"PRId64"\n",
|
|
||||||
nasm_limit[LIMIT_LINES]);
|
nasm_limit[LIMIT_LINES]);
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
|||||||
@@ -98,7 +98,7 @@ static int prefix_slot(int prefix)
|
|||||||
case P_VEX2:
|
case P_VEX2:
|
||||||
return PPS_VEX;
|
return PPS_VEX;
|
||||||
default:
|
default:
|
||||||
nasm_panic(0, "Invalid value %d passed to prefix_slot()", prefix);
|
nasm_panic("Invalid value %d passed to prefix_slot()", prefix);
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -70,7 +70,7 @@ static void nop_reset(const char *file, int pass, StrList **deplist)
|
|||||||
nop_fp = nasm_open_read(file, NF_TEXT);
|
nop_fp = nasm_open_read(file, NF_TEXT);
|
||||||
|
|
||||||
if (!nop_fp)
|
if (!nop_fp)
|
||||||
nasm_fatal(ERR_NOFILE, "unable to open input file `%s'", file);
|
nasm_fatal_fl(ERR_NOFILE, "unable to open input file `%s'", file);
|
||||||
(void)pass; /* placate compilers */
|
(void)pass; /* placate compilers */
|
||||||
|
|
||||||
nasm_add_string_to_strlist(deplist, file);
|
nasm_add_string_to_strlist(deplist, file);
|
||||||
|
|||||||
@@ -1607,7 +1607,7 @@ static FILE *inc_fopen(const char *file,
|
|||||||
|
|
||||||
if (!path) {
|
if (!path) {
|
||||||
if (omode == INC_NEEDED)
|
if (omode == INC_NEEDED)
|
||||||
nasm_fatal(0, "unable to open include file `%s'", file);
|
nasm_fatal("unable to open include file `%s'", file);
|
||||||
|
|
||||||
if (found_path)
|
if (found_path)
|
||||||
*found_path = NULL;
|
*found_path = NULL;
|
||||||
@@ -2821,7 +2821,7 @@ issue_error:
|
|||||||
nasm_error(ERR_WARNING|ERR_PASS1|ERR_PP_PRECOND,
|
nasm_error(ERR_WARNING|ERR_PASS1|ERR_PP_PRECOND,
|
||||||
"trailing garbage after `%%else' ignored");
|
"trailing garbage after `%%else' ignored");
|
||||||
if (!istk->conds)
|
if (!istk->conds)
|
||||||
nasm_fatal(0, "`%%else: no matching `%%if'");
|
nasm_fatal("`%%else: no matching `%%if'");
|
||||||
switch(istk->conds->state) {
|
switch(istk->conds->state) {
|
||||||
case COND_IF_TRUE:
|
case COND_IF_TRUE:
|
||||||
case COND_DONE:
|
case COND_DONE:
|
||||||
@@ -4986,7 +4986,7 @@ pp_reset(const char *file, int apass, StrList **deplist)
|
|||||||
src_set(0, file);
|
src_set(0, file);
|
||||||
istk->lineinc = 1;
|
istk->lineinc = 1;
|
||||||
if (!istk->fp)
|
if (!istk->fp)
|
||||||
nasm_fatal(ERR_NOFILE, "unable to open input file `%s'", file);
|
nasm_fatal_fl(ERR_NOFILE, "unable to open input file `%s'", file);
|
||||||
defining = NULL;
|
defining = NULL;
|
||||||
nested_mac_count = 0;
|
nested_mac_count = 0;
|
||||||
nested_rep_count = 0;
|
nested_rep_count = 0;
|
||||||
@@ -5094,9 +5094,9 @@ static char *pp_getline(void)
|
|||||||
*/
|
*/
|
||||||
if (defining) {
|
if (defining) {
|
||||||
if (defining->name)
|
if (defining->name)
|
||||||
nasm_panic(0, "defining with name in expansion");
|
nasm_panic("defining with name in expansion");
|
||||||
else if (istk->mstk->name)
|
else if (istk->mstk->name)
|
||||||
nasm_fatal(0, "`%%rep' without `%%endrep' within"
|
nasm_fatal("`%%rep' without `%%endrep' within"
|
||||||
" expansion of macro `%s'",
|
" expansion of macro `%s'",
|
||||||
istk->mstk->name);
|
istk->mstk->name);
|
||||||
}
|
}
|
||||||
@@ -5171,8 +5171,7 @@ static char *pp_getline(void)
|
|||||||
fclose(i->fp);
|
fclose(i->fp);
|
||||||
if (i->conds) {
|
if (i->conds) {
|
||||||
/* nasm_error can't be conditionally suppressed */
|
/* nasm_error can't be conditionally suppressed */
|
||||||
nasm_fatal(0,
|
nasm_fatal("expected `%%endif' before end of file");
|
||||||
"expected `%%endif' before end of file");
|
|
||||||
}
|
}
|
||||||
/* only set line and file name if there's a next node */
|
/* only set line and file name if there's a next node */
|
||||||
if (i->next)
|
if (i->next)
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
/* ----------------------------------------------------------------------- *
|
/* ----------------------------------------------------------------------- *
|
||||||
*
|
*
|
||||||
* Copyright 1996-2017 The NASM Authors - All Rights Reserved
|
* Copyright 1996-2018 The NASM Authors - All Rights Reserved
|
||||||
* See the file AUTHORS included with the NASM distribution for
|
* See the file AUTHORS included with the NASM distribution for
|
||||||
* the specific copyright holders.
|
* the specific copyright holders.
|
||||||
*
|
*
|
||||||
@@ -44,8 +44,10 @@
|
|||||||
* An error reporting function should look like this.
|
* An error reporting function should look like this.
|
||||||
*/
|
*/
|
||||||
void printf_func(2, 3) nasm_error(int severity, const char *fmt, ...);
|
void printf_func(2, 3) nasm_error(int severity, const char *fmt, ...);
|
||||||
fatal_func printf_func(2, 3) nasm_fatal(int flags, const char *fmt, ...);
|
fatal_func printf_func(1, 2) nasm_fatal(const char *fmt, ...);
|
||||||
fatal_func printf_func(2, 3) nasm_panic(int flags, const char *fmt, ...);
|
fatal_func printf_func(1, 2) nasm_panic(const char *fmt, ...);
|
||||||
|
fatal_func printf_func(2, 3) nasm_fatal_fl(int flags, const char *fmt, ...);
|
||||||
|
fatal_func printf_func(2, 3) nasm_panic_fl(int flags, const char *fmt, ...);
|
||||||
fatal_func nasm_panic_from_macro(const char *file, int line);
|
fatal_func nasm_panic_from_macro(const char *file, int line);
|
||||||
#define panic() nasm_panic_from_macro(__FILE__, __LINE__);
|
#define panic() nasm_panic_from_macro(__FILE__, __LINE__);
|
||||||
|
|
||||||
|
|||||||
@@ -37,9 +37,9 @@ void nasm_read(void *ptr, size_t size, FILE *f)
|
|||||||
{
|
{
|
||||||
size_t n = fread(ptr, 1, size, f);
|
size_t n = fread(ptr, 1, size, f);
|
||||||
if (ferror(f)) {
|
if (ferror(f)) {
|
||||||
nasm_fatal(0, "unable to read input: %s", strerror(errno));
|
nasm_fatal("unable to read input: %s", strerror(errno));
|
||||||
} else if (n != size || feof(f)) {
|
} else if (n != size || feof(f)) {
|
||||||
nasm_fatal(0, "fatal short read on input");
|
nasm_fatal("fatal short read on input");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -47,7 +47,7 @@ void nasm_write(const void *ptr, size_t size, FILE *f)
|
|||||||
{
|
{
|
||||||
size_t n = fwrite(ptr, 1, size, f);
|
size_t n = fwrite(ptr, 1, size, f);
|
||||||
if (n != size || ferror(f) || feof(f))
|
if (n != size || ferror(f) || feof(f))
|
||||||
nasm_fatal(0, "unable to write output: %s", strerror(errno));
|
nasm_fatal("unable to write output: %s", strerror(errno));
|
||||||
}
|
}
|
||||||
|
|
||||||
void fwriteint16_t(uint16_t data, FILE * fp)
|
void fwriteint16_t(uint16_t data, FILE * fp)
|
||||||
@@ -119,7 +119,7 @@ FILE *nasm_open_read(const char *filename, enum file_flags flags)
|
|||||||
f = fopen(filename, (flags & NF_TEXT) ? "rt" : "rb");
|
f = fopen(filename, (flags & NF_TEXT) ? "rt" : "rb");
|
||||||
|
|
||||||
if (!f && (flags & NF_FATAL))
|
if (!f && (flags & NF_FATAL))
|
||||||
nasm_fatal(ERR_NOFILE, "unable to open input file: `%s': %s",
|
nasm_fatal_fl(ERR_NOFILE, "unable to open input file: `%s': %s",
|
||||||
filename, strerror(errno));
|
filename, strerror(errno));
|
||||||
|
|
||||||
return f;
|
return f;
|
||||||
@@ -132,7 +132,7 @@ FILE *nasm_open_write(const char *filename, enum file_flags flags)
|
|||||||
f = fopen(filename, (flags & NF_TEXT) ? "wt" : "wb");
|
f = fopen(filename, (flags & NF_TEXT) ? "wt" : "wb");
|
||||||
|
|
||||||
if (!f && (flags & NF_FATAL))
|
if (!f && (flags & NF_FATAL))
|
||||||
nasm_fatal(ERR_NOFILE, "unable to open output file: `%s': %s",
|
nasm_fatal_fl(ERR_NOFILE, "unable to open output file: `%s': %s",
|
||||||
filename, strerror(errno));
|
filename, strerror(errno));
|
||||||
|
|
||||||
return f;
|
return f;
|
||||||
|
|||||||
@@ -44,7 +44,7 @@
|
|||||||
|
|
||||||
static no_return nasm_alloc_failed(void)
|
static no_return nasm_alloc_failed(void)
|
||||||
{
|
{
|
||||||
nasm_fatal(0, "out of memory");
|
nasm_fatal("out of memory");
|
||||||
}
|
}
|
||||||
|
|
||||||
static inline void *validate_ptr(void *p)
|
static inline void *validate_ptr(void *p)
|
||||||
|
|||||||
@@ -480,7 +480,7 @@ static void register_reloc(struct coff_Section *const sect,
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
nasm_panic(0, "codeview: relocation for unregistered symbol: %s", sym);
|
nasm_panic("codeview: relocation for unregistered symbol: %s", sym);
|
||||||
}
|
}
|
||||||
|
|
||||||
static inline void section_write32(struct coff_Section *sect, uint32_t val)
|
static inline void section_write32(struct coff_Section *sect, uint32_t val)
|
||||||
|
|||||||
@@ -498,7 +498,7 @@ static void as86_set_rsize(int size)
|
|||||||
fputc(0x03, ofile);
|
fputc(0x03, ofile);
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
nasm_panic(0, "bizarre relocation size %d", size);
|
nasm_panic("bizarre relocation size %d", size);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -267,8 +267,7 @@ static void bin_cleanup(void)
|
|||||||
if (s->flags & (START_DEFINED | ALIGN_DEFINED | FOLLOWS_DEFINED)) { /* Check for a mixture of real and virtual section attributes. */
|
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 |
|
if (s->flags & (VSTART_DEFINED | VALIGN_DEFINED |
|
||||||
VFOLLOWS_DEFINED))
|
VFOLLOWS_DEFINED))
|
||||||
nasm_fatal(0,
|
nasm_fatal("cannot mix real and virtual attributes"
|
||||||
"cannot mix real and virtual attributes"
|
|
||||||
" in nobits section (%s)", s->name);
|
" in nobits section (%s)", s->name);
|
||||||
/* Real and virtual attributes mean the same thing for nobits sections. */
|
/* Real and virtual attributes mean the same thing for nobits sections. */
|
||||||
if (s->flags & START_DEFINED) {
|
if (s->flags & START_DEFINED) {
|
||||||
@@ -338,11 +337,11 @@ static void bin_cleanup(void)
|
|||||||
s && strcmp(s->name, g->follows);
|
s && strcmp(s->name, g->follows);
|
||||||
sp = &s->next, s = s->next) ;
|
sp = &s->next, s = s->next) ;
|
||||||
if (!s)
|
if (!s)
|
||||||
nasm_fatal(0, "section %s follows an invalid or"
|
nasm_fatal("section %s follows an invalid or"
|
||||||
" unknown section (%s)", g->name, g->follows);
|
" unknown section (%s)", g->name, g->follows);
|
||||||
if (s->next && (s->next->flags & FOLLOWS_DEFINED) &&
|
if (s->next && (s->next->flags & FOLLOWS_DEFINED) &&
|
||||||
!strcmp(s->name, s->next->follows))
|
!strcmp(s->name, s->next->follows))
|
||||||
nasm_fatal(0, "sections %s and %s can't both follow"
|
nasm_fatal("sections %s and %s can't both follow"
|
||||||
" section %s", g->name, s->next->name, s->name);
|
" section %s", g->name, s->next->name, s->name);
|
||||||
/* Find the end of the current follows group (gs). */
|
/* Find the end of the current follows group (gs). */
|
||||||
for (gsp = &g->next, gs = g->next;
|
for (gsp = &g->next, gs = g->next;
|
||||||
@@ -386,7 +385,7 @@ static void bin_cleanup(void)
|
|||||||
if (sections->flags & START_DEFINED) {
|
if (sections->flags & START_DEFINED) {
|
||||||
/* Make sure this section doesn't begin before the origin. */
|
/* Make sure this section doesn't begin before the origin. */
|
||||||
if (sections->start < origin)
|
if (sections->start < origin)
|
||||||
nasm_fatal(0, "section %s begins"
|
nasm_fatal("section %s begins"
|
||||||
" before program origin", sections->name);
|
" before program origin", sections->name);
|
||||||
} else if (sections->flags & ALIGN_DEFINED) {
|
} else if (sections->flags & ALIGN_DEFINED) {
|
||||||
sections->start = ALIGN(origin, sections->align);
|
sections->start = ALIGN(origin, sections->align);
|
||||||
@@ -442,13 +441,13 @@ static void bin_cleanup(void)
|
|||||||
/* Check for section overlap. */
|
/* Check for section overlap. */
|
||||||
if (s) {
|
if (s) {
|
||||||
if (s->start < origin)
|
if (s->start < origin)
|
||||||
nasm_fatal(0, "section %s beings before program origin",
|
nasm_fatal("section %s beings before program origin",
|
||||||
s->name);
|
s->name);
|
||||||
if (g->start > s->start)
|
if (g->start > s->start)
|
||||||
nasm_fatal(0, "sections %s ~ %s and %s overlap!",
|
nasm_fatal("sections %s ~ %s and %s overlap!",
|
||||||
gs->name, g->name, s->name);
|
gs->name, g->name, s->name);
|
||||||
if (pend > s->start)
|
if (pend > s->start)
|
||||||
nasm_fatal(0, "sections %s and %s overlap!",
|
nasm_fatal("sections %s and %s overlap!",
|
||||||
g->name, s->name);
|
g->name, s->name);
|
||||||
}
|
}
|
||||||
/* Remember this section as the latest >0 length section. */
|
/* Remember this section as the latest >0 length section. */
|
||||||
@@ -477,8 +476,7 @@ static void bin_cleanup(void)
|
|||||||
for (s = sections; s && strcmp(g->vfollows, s->name);
|
for (s = sections; s && strcmp(g->vfollows, s->name);
|
||||||
s = s->next) ;
|
s = s->next) ;
|
||||||
if (!s)
|
if (!s)
|
||||||
nasm_fatal(0,
|
nasm_fatal("section %s vfollows unknown section (%s)",
|
||||||
"section %s vfollows unknown section (%s)",
|
|
||||||
g->name, g->vfollows);
|
g->name, g->vfollows);
|
||||||
} else if (g->prev != NULL)
|
} else if (g->prev != NULL)
|
||||||
for (s = sections; s && (s != g->prev); s = s->next) ;
|
for (s = sections; s && (s != g->prev); s = s->next) ;
|
||||||
@@ -516,7 +514,7 @@ static void bin_cleanup(void)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (h)
|
if (h)
|
||||||
nasm_fatal(0, "circular vfollows path detected");
|
nasm_fatal("circular vfollows path detected");
|
||||||
|
|
||||||
#ifdef DEBUG
|
#ifdef DEBUG
|
||||||
nasm_error(ERR_DEBUG,
|
nasm_error(ERR_DEBUG,
|
||||||
@@ -740,7 +738,7 @@ static void bin_out(int32_t segto, const void *data,
|
|||||||
/* Find the segment we are targeting. */
|
/* Find the segment we are targeting. */
|
||||||
s = find_section_by_index(segto);
|
s = find_section_by_index(segto);
|
||||||
if (!s)
|
if (!s)
|
||||||
nasm_panic(0, "code directed to nonexistent segment?");
|
nasm_panic("code directed to nonexistent segment?");
|
||||||
|
|
||||||
/* "Smart" section-type adaptation code. */
|
/* "Smart" section-type adaptation code. */
|
||||||
if (!(s->flags & TYPE_DEFINED)) {
|
if (!(s->flags & TYPE_DEFINED)) {
|
||||||
|
|||||||
@@ -569,7 +569,7 @@ static void coff_out(int32_t segto, const void *data,
|
|||||||
if (!s) {
|
if (!s) {
|
||||||
int tempint; /* ignored */
|
int tempint; /* ignored */
|
||||||
if (segto != coff_section_names(".text", 2, &tempint))
|
if (segto != coff_section_names(".text", 2, &tempint))
|
||||||
nasm_panic(0, "strange segment conditions in COFF driver");
|
nasm_panic("strange segment conditions in COFF driver");
|
||||||
else
|
else
|
||||||
s = coff_sects[coff_nsects - 1];
|
s = coff_sects[coff_nsects - 1];
|
||||||
}
|
}
|
||||||
@@ -658,7 +658,7 @@ static void coff_out(int32_t segto, const void *data,
|
|||||||
" relocations");
|
" relocations");
|
||||||
} else if (type == OUT_REL4ADR) {
|
} else if (type == OUT_REL4ADR) {
|
||||||
if (segment == segto && !(win64)) /* Acceptable for RIP-relative */
|
if (segment == segto && !(win64)) /* Acceptable for RIP-relative */
|
||||||
nasm_panic(0, "intra-segment OUT_REL4ADR");
|
nasm_panic("intra-segment OUT_REL4ADR");
|
||||||
else if (segment == NO_SEG && win32)
|
else if (segment == NO_SEG && win32)
|
||||||
nasm_error(ERR_NONFATAL, "Win32 COFF does not correctly support"
|
nasm_error(ERR_NONFATAL, "Win32 COFF does not correctly support"
|
||||||
" relative references to absolute addresses");
|
" relative references to absolute addresses");
|
||||||
@@ -861,8 +861,7 @@ static inline void coff_adjust_relocs(struct coff_Section *s)
|
|||||||
else
|
else
|
||||||
{
|
{
|
||||||
if (ofmt == &of_coff)
|
if (ofmt == &of_coff)
|
||||||
nasm_fatal(0,
|
nasm_fatal("Too many relocations (%d) for section `%s'",
|
||||||
"Too many relocations (%d) for section `%s'",
|
|
||||||
s->nrelocs, s->name);
|
s->nrelocs, s->name);
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|||||||
@@ -554,7 +554,7 @@ static void elf_deflabel(char *name, int32_t segment, int64_t offset,
|
|||||||
/* we have to be sure at least text section is there */
|
/* we have to be sure at least text section is there */
|
||||||
int tempint;
|
int tempint;
|
||||||
if (segment != elf_section_names(".text", 2, &tempint))
|
if (segment != elf_section_names(".text", 2, &tempint))
|
||||||
nasm_panic(0, "strange segment conditions in ELF driver");
|
nasm_panic("strange segment conditions in ELF driver");
|
||||||
}
|
}
|
||||||
for (i = 0; i < nsects; i++) {
|
for (i = 0; i < nsects; i++) {
|
||||||
if (segment == sects[i]->index) {
|
if (segment == sects[i]->index) {
|
||||||
@@ -808,7 +808,7 @@ static void elf32_out(int32_t segto, const void *data,
|
|||||||
if (!s) {
|
if (!s) {
|
||||||
int tempint; /* ignored */
|
int tempint; /* ignored */
|
||||||
if (segto != elf_section_names(".text", 2, &tempint))
|
if (segto != elf_section_names(".text", 2, &tempint))
|
||||||
nasm_panic(0, "strange segment conditions in ELF driver");
|
nasm_panic("strange segment conditions in ELF driver");
|
||||||
else {
|
else {
|
||||||
s = sects[nsects - 1];
|
s = sects[nsects - 1];
|
||||||
i = nsects - 1;
|
i = nsects - 1;
|
||||||
@@ -963,7 +963,7 @@ rel12adr:
|
|||||||
case OUT_REL4ADR:
|
case OUT_REL4ADR:
|
||||||
addr = *(int64_t *)data - size;
|
addr = *(int64_t *)data - size;
|
||||||
if (segment == segto)
|
if (segment == segto)
|
||||||
nasm_panic(0, "intra-segment OUT_REL4ADR");
|
nasm_panic("intra-segment OUT_REL4ADR");
|
||||||
if (segment != NO_SEG && segment % 2) {
|
if (segment != NO_SEG && segment % 2) {
|
||||||
nasm_error(ERR_NONFATAL, "ELF format does not support"
|
nasm_error(ERR_NONFATAL, "ELF format does not support"
|
||||||
" segment base references");
|
" segment base references");
|
||||||
@@ -1015,7 +1015,7 @@ static void elf64_out(int32_t segto, const void *data,
|
|||||||
if (!s) {
|
if (!s) {
|
||||||
int tempint; /* ignored */
|
int tempint; /* ignored */
|
||||||
if (segto != elf_section_names(".text", 2, &tempint))
|
if (segto != elf_section_names(".text", 2, &tempint))
|
||||||
nasm_panic(0, "strange segment conditions in ELF driver");
|
nasm_panic("strange segment conditions in ELF driver");
|
||||||
else {
|
else {
|
||||||
s = sects[nsects - 1];
|
s = sects[nsects - 1];
|
||||||
i = nsects - 1;
|
i = nsects - 1;
|
||||||
@@ -1049,7 +1049,7 @@ static void elf64_out(int32_t segto, const void *data,
|
|||||||
|
|
||||||
case OUT_RAWDATA:
|
case OUT_RAWDATA:
|
||||||
if (segment != NO_SEG)
|
if (segment != NO_SEG)
|
||||||
nasm_panic(0, "OUT_RAWDATA with other than NO_SEG");
|
nasm_panic("OUT_RAWDATA with other than NO_SEG");
|
||||||
elf_sect_write(s, data, size);
|
elf_sect_write(s, data, size);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
@@ -1086,7 +1086,7 @@ static void elf64_out(int32_t segto, const void *data,
|
|||||||
elf_add_reloc(s, segment, addr, R_X86_64_64);
|
elf_add_reloc(s, segment, addr, R_X86_64_64);
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
nasm_panic(0, "internal error elf64-hpa-871");
|
nasm_panic("internal error elf64-hpa-871");
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
addr = 0;
|
addr = 0;
|
||||||
@@ -1154,7 +1154,7 @@ static void elf64_out(int32_t segto, const void *data,
|
|||||||
addr = 0;
|
addr = 0;
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
nasm_panic(0, "internal error elf64-hpa-903");
|
nasm_panic("internal error elf64-hpa-903");
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
} else if (wrt == elf_plt_sect + 1) {
|
} else if (wrt == elf_plt_sect + 1) {
|
||||||
@@ -1182,7 +1182,7 @@ static void elf64_out(int32_t segto, const void *data,
|
|||||||
rel12adr:
|
rel12adr:
|
||||||
addr = *(int64_t *)data - size;
|
addr = *(int64_t *)data - size;
|
||||||
if (segment == segto)
|
if (segment == segto)
|
||||||
nasm_panic(0, "intra-segment OUT_REL1ADR");
|
nasm_panic("intra-segment OUT_REL1ADR");
|
||||||
if (segment == NO_SEG) {
|
if (segment == NO_SEG) {
|
||||||
/* Do nothing */
|
/* Do nothing */
|
||||||
} else if (segment % 2) {
|
} else if (segment % 2) {
|
||||||
@@ -1203,7 +1203,7 @@ rel12adr:
|
|||||||
case OUT_REL4ADR:
|
case OUT_REL4ADR:
|
||||||
addr = *(int64_t *)data - size;
|
addr = *(int64_t *)data - size;
|
||||||
if (segment == segto)
|
if (segment == segto)
|
||||||
nasm_panic(0, "intra-segment OUT_REL4ADR");
|
nasm_panic("intra-segment OUT_REL4ADR");
|
||||||
if (segment == NO_SEG) {
|
if (segment == NO_SEG) {
|
||||||
/* Do nothing */
|
/* Do nothing */
|
||||||
} else if (segment % 2) {
|
} else if (segment % 2) {
|
||||||
@@ -1241,7 +1241,7 @@ rel12adr:
|
|||||||
case OUT_REL8ADR:
|
case OUT_REL8ADR:
|
||||||
addr = *(int64_t *)data - size;
|
addr = *(int64_t *)data - size;
|
||||||
if (segment == segto)
|
if (segment == segto)
|
||||||
nasm_panic(0, "intra-segment OUT_REL8ADR");
|
nasm_panic("intra-segment OUT_REL8ADR");
|
||||||
if (segment == NO_SEG) {
|
if (segment == NO_SEG) {
|
||||||
/* Do nothing */
|
/* Do nothing */
|
||||||
} else if (segment % 2) {
|
} else if (segment % 2) {
|
||||||
@@ -1295,7 +1295,7 @@ static void elfx32_out(int32_t segto, const void *data,
|
|||||||
if (!s) {
|
if (!s) {
|
||||||
int tempint; /* ignored */
|
int tempint; /* ignored */
|
||||||
if (segto != elf_section_names(".text", 2, &tempint))
|
if (segto != elf_section_names(".text", 2, &tempint))
|
||||||
nasm_panic(0, "strange segment conditions in ELF driver");
|
nasm_panic("strange segment conditions in ELF driver");
|
||||||
else {
|
else {
|
||||||
s = sects[nsects - 1];
|
s = sects[nsects - 1];
|
||||||
i = nsects - 1;
|
i = nsects - 1;
|
||||||
@@ -1329,7 +1329,7 @@ static void elfx32_out(int32_t segto, const void *data,
|
|||||||
|
|
||||||
case OUT_RAWDATA:
|
case OUT_RAWDATA:
|
||||||
if (segment != NO_SEG)
|
if (segment != NO_SEG)
|
||||||
nasm_panic(0, "OUT_RAWDATA with other than NO_SEG");
|
nasm_panic("OUT_RAWDATA with other than NO_SEG");
|
||||||
elf_sect_write(s, data, size);
|
elf_sect_write(s, data, size);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
@@ -1366,7 +1366,7 @@ static void elfx32_out(int32_t segto, const void *data,
|
|||||||
elf_add_reloc(s, segment, addr, R_X86_64_64);
|
elf_add_reloc(s, segment, addr, R_X86_64_64);
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
nasm_panic(0, "internal error elfx32-hpa-871");
|
nasm_panic("internal error elfx32-hpa-871");
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
addr = 0;
|
addr = 0;
|
||||||
@@ -1424,7 +1424,7 @@ static void elfx32_out(int32_t segto, const void *data,
|
|||||||
addr = 0;
|
addr = 0;
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
nasm_panic(0, "internal error elfx32-hpa-903");
|
nasm_panic("internal error elfx32-hpa-903");
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
} else if (wrt == elf_plt_sect + 1) {
|
} else if (wrt == elf_plt_sect + 1) {
|
||||||
@@ -1452,7 +1452,7 @@ static void elfx32_out(int32_t segto, const void *data,
|
|||||||
rel12adr:
|
rel12adr:
|
||||||
addr = *(int64_t *)data - size;
|
addr = *(int64_t *)data - size;
|
||||||
if (segment == segto)
|
if (segment == segto)
|
||||||
nasm_panic(0, "intra-segment OUT_REL1ADR");
|
nasm_panic("intra-segment OUT_REL1ADR");
|
||||||
if (segment == NO_SEG) {
|
if (segment == NO_SEG) {
|
||||||
/* Do nothing */
|
/* Do nothing */
|
||||||
} else if (segment % 2) {
|
} else if (segment % 2) {
|
||||||
@@ -1473,7 +1473,7 @@ rel12adr:
|
|||||||
case OUT_REL4ADR:
|
case OUT_REL4ADR:
|
||||||
addr = *(int64_t *)data - size;
|
addr = *(int64_t *)data - size;
|
||||||
if (segment == segto)
|
if (segment == segto)
|
||||||
nasm_panic(0, "intra-segment OUT_REL4ADR");
|
nasm_panic("intra-segment OUT_REL4ADR");
|
||||||
if (segment == NO_SEG) {
|
if (segment == NO_SEG) {
|
||||||
/* Do nothing */
|
/* Do nothing */
|
||||||
} else if (segment % 2) {
|
} else if (segment % 2) {
|
||||||
|
|||||||
@@ -405,7 +405,7 @@ static void ieee_out(int32_t segto, const void *data,
|
|||||||
if (!any_segs) {
|
if (!any_segs) {
|
||||||
int tempint; /* ignored */
|
int tempint; /* ignored */
|
||||||
if (segto != ieee_segment("__NASMDEFSEG", 2, &tempint))
|
if (segto != ieee_segment("__NASMDEFSEG", 2, &tempint))
|
||||||
nasm_panic(0, "strange segment conditions in IEEE driver");
|
nasm_panic("strange segment conditions in IEEE driver");
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
@@ -415,7 +415,7 @@ static void ieee_out(int32_t segto, const void *data,
|
|||||||
if (seg->index == segto)
|
if (seg->index == segto)
|
||||||
break;
|
break;
|
||||||
if (!seg)
|
if (!seg)
|
||||||
nasm_panic(0, "code directed to nonexistent segment?");
|
nasm_panic("code directed to nonexistent segment?");
|
||||||
|
|
||||||
if (type == OUT_RAWDATA) {
|
if (type == OUT_RAWDATA) {
|
||||||
ucdata = data;
|
ucdata = data;
|
||||||
@@ -521,8 +521,7 @@ static void ieee_write_fixup(int32_t segment, int32_t wrt,
|
|||||||
}
|
}
|
||||||
|
|
||||||
} else
|
} else
|
||||||
nasm_panic(0,
|
nasm_panic("unrecognised WRT value in ieee_write_fixup");
|
||||||
"unrecognised WRT value in ieee_write_fixup");
|
|
||||||
} else
|
} else
|
||||||
nasm_error(ERR_NONFATAL, "target of WRT must be a section ");
|
nasm_error(ERR_NONFATAL, "target of WRT must be a section ");
|
||||||
}
|
}
|
||||||
@@ -563,8 +562,7 @@ static void ieee_write_fixup(int32_t segment, int32_t wrt,
|
|||||||
*/
|
*/
|
||||||
if (eb) {
|
if (eb) {
|
||||||
if (realtype == OUT_REL2ADR || realtype == OUT_REL4ADR) {
|
if (realtype == OUT_REL2ADR || realtype == OUT_REL4ADR) {
|
||||||
nasm_panic(0,
|
nasm_panic("Segment of a rel not supported in ieee_write_fixup");
|
||||||
"Segment of a rel not supported in ieee_write_fixup");
|
|
||||||
} else {
|
} else {
|
||||||
/* If we want the segment */
|
/* If we want the segment */
|
||||||
s.ftype = FT_EXTSEG;
|
s.ftype = FT_EXTSEG;
|
||||||
@@ -574,8 +572,7 @@ static void ieee_write_fixup(int32_t segment, int32_t wrt,
|
|||||||
|
|
||||||
} else
|
} else
|
||||||
/* If we get here the seg value doesn't make sense */
|
/* If we get here the seg value doesn't make sense */
|
||||||
nasm_panic(0,
|
nasm_panic("unrecognised segment value in ieee_write_fixup");
|
||||||
"unrecognised segment value in ieee_write_fixup");
|
|
||||||
}
|
}
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
@@ -629,8 +626,7 @@ static void ieee_write_fixup(int32_t segment, int32_t wrt,
|
|||||||
|
|
||||||
} else
|
} else
|
||||||
/* If we get here the seg value doesn't make sense */
|
/* If we get here the seg value doesn't make sense */
|
||||||
nasm_panic(0,
|
nasm_panic("unrecognised segment value in ieee_write_fixup");
|
||||||
"unrecognised segment value in ieee_write_fixup");
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (size != 2 && s.ftype == FT_SEG)
|
if (size != 2 && s.ftype == FT_SEG)
|
||||||
@@ -969,7 +965,7 @@ static void ieee_write_file(void)
|
|||||||
if (seg->index == ieee_entry_seg)
|
if (seg->index == ieee_entry_seg)
|
||||||
break;
|
break;
|
||||||
if (!seg)
|
if (!seg)
|
||||||
nasm_panic(0, "Start address records are incorrect");
|
nasm_panic("Start address records are incorrect");
|
||||||
else
|
else
|
||||||
ieee_putascii("ASG,R%X,%lX,+.\n", seg->ieee_index,
|
ieee_putascii("ASG,R%X,%lX,+.\n", seg->ieee_index,
|
||||||
ieee_entry_ofs);
|
ieee_entry_ofs);
|
||||||
@@ -1332,7 +1328,7 @@ static void dbgls_linnum(const char *lnfname, int32_t lineno, int32_t segto)
|
|||||||
if (!any_segs) {
|
if (!any_segs) {
|
||||||
int tempint; /* ignored */
|
int tempint; /* ignored */
|
||||||
if (segto != ieee_segment("__NASMDEFSEG", 2, &tempint))
|
if (segto != ieee_segment("__NASMDEFSEG", 2, &tempint))
|
||||||
nasm_panic(0, "strange segment conditions in OBJ driver");
|
nasm_panic("strange segment conditions in OBJ driver");
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
@@ -1342,7 +1338,7 @@ static void dbgls_linnum(const char *lnfname, int32_t lineno, int32_t segto)
|
|||||||
if (seg->index == segto)
|
if (seg->index == segto)
|
||||||
break;
|
break;
|
||||||
if (!seg)
|
if (!seg)
|
||||||
nasm_panic(0, "lineno directed to nonexistent segment?");
|
nasm_panic("lineno directed to nonexistent segment?");
|
||||||
|
|
||||||
for (fn = fnhead; fn; fn = fn->next) {
|
for (fn = fnhead; fn; fn = fn->next) {
|
||||||
if (!nasm_stricmp(lnfname, fn->name))
|
if (!nasm_stricmp(lnfname, fn->name))
|
||||||
|
|||||||
@@ -643,7 +643,7 @@ static void macho_output(int32_t secto, const void *data,
|
|||||||
|
|
||||||
/* should never happen */
|
/* should never happen */
|
||||||
if (!s)
|
if (!s)
|
||||||
nasm_panic(0, "text section not found");
|
nasm_panic("text section not found");
|
||||||
}
|
}
|
||||||
|
|
||||||
/* debug code generation only for sections tagged with
|
/* debug code generation only for sections tagged with
|
||||||
@@ -1146,7 +1146,7 @@ static void macho_symdef(char *name, int32_t section, int64_t offset,
|
|||||||
/* give an error on unfound section if it's not an
|
/* give an error on unfound section if it's not an
|
||||||
** external or common symbol (assemble_file() does a
|
** external or common symbol (assemble_file() does a
|
||||||
** seg_alloc() on every call for them) */
|
** seg_alloc() on every call for them) */
|
||||||
nasm_panic(0, "in-file index for section %d not found, is_global = %d", section, is_global);
|
nasm_panic("in-file index for section %d not found, is_global = %d", section, is_global);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -1339,7 +1339,7 @@ static void macho_calculate_sizes (void)
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (seg_nsects > MAX_SECT) {
|
if (seg_nsects > MAX_SECT) {
|
||||||
nasm_fatal(0, "MachO output is limited to %d sections\n",
|
nasm_fatal("MachO output is limited to %d sections\n",
|
||||||
MAX_SECT);
|
MAX_SECT);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -839,7 +839,7 @@ static void obj_deflabel(char *name, int32_t segment,
|
|||||||
if (!any_segs && segment == first_seg) {
|
if (!any_segs && segment == first_seg) {
|
||||||
int tempint; /* ignored */
|
int tempint; /* ignored */
|
||||||
if (segment != obj_segment("__NASMDEFSEG", 2, &tempint))
|
if (segment != obj_segment("__NASMDEFSEG", 2, &tempint))
|
||||||
nasm_panic(0, "strange segment conditions in OBJ driver");
|
nasm_panic("strange segment conditions in OBJ driver");
|
||||||
}
|
}
|
||||||
|
|
||||||
for (seg = seghead; seg && is_global; seg = seg->next)
|
for (seg = seghead; seg && is_global; seg = seg->next)
|
||||||
@@ -1035,7 +1035,7 @@ static void obj_out(int32_t segto, const void *data,
|
|||||||
if (!any_segs) {
|
if (!any_segs) {
|
||||||
int tempint; /* ignored */
|
int tempint; /* ignored */
|
||||||
if (segto != obj_segment("__NASMDEFSEG", 2, &tempint))
|
if (segto != obj_segment("__NASMDEFSEG", 2, &tempint))
|
||||||
nasm_panic(0, "strange segment conditions in OBJ driver");
|
nasm_panic("strange segment conditions in OBJ driver");
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
@@ -1045,7 +1045,7 @@ static void obj_out(int32_t segto, const void *data,
|
|||||||
if (seg->index == segto)
|
if (seg->index == segto)
|
||||||
break;
|
break;
|
||||||
if (!seg)
|
if (!seg)
|
||||||
nasm_panic(0, "code directed to nonexistent segment?");
|
nasm_panic("code directed to nonexistent segment?");
|
||||||
|
|
||||||
orp = seg->orp;
|
orp = seg->orp;
|
||||||
orp->parm[0] = seg->currentpos;
|
orp->parm[0] = seg->currentpos;
|
||||||
@@ -1213,7 +1213,7 @@ static void obj_write_fixup(ObjRecord * orp, int bytes,
|
|||||||
locat = FIX_16_SELECTOR;
|
locat = FIX_16_SELECTOR;
|
||||||
seg--;
|
seg--;
|
||||||
if (bytes != 2)
|
if (bytes != 2)
|
||||||
nasm_panic(0, "OBJ: 4-byte segment base fixup got"
|
nasm_panic("OBJ: 4-byte segment base fixup got"
|
||||||
" through sanity check");
|
" through sanity check");
|
||||||
} else {
|
} else {
|
||||||
base = false;
|
base = false;
|
||||||
@@ -1259,8 +1259,7 @@ static void obj_write_fixup(ObjRecord * orp, int bytes,
|
|||||||
if (eb)
|
if (eb)
|
||||||
method = 6, e = eb->exts[i], tidx = e->index;
|
method = 6, e = eb->exts[i], tidx = e->index;
|
||||||
else
|
else
|
||||||
nasm_panic(0,
|
nasm_panic("unrecognised segment value in obj_write_fixup");
|
||||||
"unrecognised segment value in obj_write_fixup");
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -1318,8 +1317,7 @@ static void obj_write_fixup(ObjRecord * orp, int bytes,
|
|||||||
if (eb)
|
if (eb)
|
||||||
method |= 0x20, fidx = eb->exts[i]->index;
|
method |= 0x20, fidx = eb->exts[i]->index;
|
||||||
else
|
else
|
||||||
nasm_panic(0,
|
nasm_panic("unrecognised WRT value in obj_write_fixup");
|
||||||
"unrecognised WRT value in obj_write_fixup");
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -1467,7 +1465,7 @@ static int32_t obj_segment(char *name, int pass, int *bits)
|
|||||||
if (!strcmp(grp->name, "FLAT"))
|
if (!strcmp(grp->name, "FLAT"))
|
||||||
break;
|
break;
|
||||||
if (!grp)
|
if (!grp)
|
||||||
nasm_panic(0, "failure to define FLAT?!");
|
nasm_panic("failure to define FLAT?!");
|
||||||
}
|
}
|
||||||
seg->grp = grp;
|
seg->grp = grp;
|
||||||
} else if (!nasm_strnicmp(p, "class=", 6))
|
} else if (!nasm_strnicmp(p, "class=", 6))
|
||||||
@@ -2518,7 +2516,7 @@ static void dbgbi_linnum(const char *lnfname, int32_t lineno, int32_t segto)
|
|||||||
if (!any_segs) {
|
if (!any_segs) {
|
||||||
int tempint; /* ignored */
|
int tempint; /* ignored */
|
||||||
if (segto != obj_segment("__NASMDEFSEG", 2, &tempint))
|
if (segto != obj_segment("__NASMDEFSEG", 2, &tempint))
|
||||||
nasm_panic(0, "strange segment conditions in OBJ driver");
|
nasm_panic("strange segment conditions in OBJ driver");
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
@@ -2528,7 +2526,7 @@ static void dbgbi_linnum(const char *lnfname, int32_t lineno, int32_t segto)
|
|||||||
if (seg->index == segto)
|
if (seg->index == segto)
|
||||||
break;
|
break;
|
||||||
if (!seg)
|
if (!seg)
|
||||||
nasm_panic(0, "lineno directed to nonexistent segment?");
|
nasm_panic("lineno directed to nonexistent segment?");
|
||||||
|
|
||||||
/* for (fn = fnhead; fn; fn = fnhead->next) */
|
/* for (fn = fnhead; fn; fn = fnhead->next) */
|
||||||
for (fn = fnhead; fn; fn = fn->next) /* fbk - Austin Lunnen - John Fine */
|
for (fn = fnhead; fn; fn = fn->next) /* fbk - Austin Lunnen - John Fine */
|
||||||
|
|||||||
@@ -145,8 +145,7 @@ static void rdf2_init(void)
|
|||||||
segdata = seg_alloc();
|
segdata = seg_alloc();
|
||||||
segbss = seg_alloc();
|
segbss = seg_alloc();
|
||||||
if (segtext != 0 || segdata != 2 || segbss != 4)
|
if (segtext != 0 || segdata != 2 || segbss != 4)
|
||||||
nasm_panic(0,
|
nasm_panic("rdf segment numbers not allocated as expected (%d,%d,%d)",
|
||||||
"rdf segment numbers not allocated as expected (%d,%d,%d)",
|
|
||||||
segtext, segdata, segbss);
|
segtext, segdata, segbss);
|
||||||
bsslength = 0;
|
bsslength = 0;
|
||||||
headerlength = 0;
|
headerlength = 0;
|
||||||
@@ -227,7 +226,7 @@ static int32_t rdf2_section_names(char *name, int pass, int *bits)
|
|||||||
code = 3;
|
code = 3;
|
||||||
}
|
}
|
||||||
if (nsegments == RDF_MAXSEGS) {
|
if (nsegments == RDF_MAXSEGS) {
|
||||||
nasm_fatal(0, "reached compiled-in maximum segment limit (%d)",
|
nasm_fatal("reached compiled-in maximum segment limit (%d)",
|
||||||
RDF_MAXSEGS);
|
RDF_MAXSEGS);
|
||||||
return NO_SEG;
|
return NO_SEG;
|
||||||
}
|
}
|
||||||
@@ -235,7 +234,7 @@ static int32_t rdf2_section_names(char *name, int pass, int *bits)
|
|||||||
segments[nsegments].segname = nasm_strdup(name);
|
segments[nsegments].segname = nasm_strdup(name);
|
||||||
i = seg_alloc();
|
i = seg_alloc();
|
||||||
if (i % 2 != 0)
|
if (i % 2 != 0)
|
||||||
nasm_panic(0, "seg_alloc() returned odd number");
|
nasm_panic("seg_alloc() returned odd number");
|
||||||
segments[nsegments].segnumber = i >> 1;
|
segments[nsegments].segnumber = i >> 1;
|
||||||
segments[nsegments].segtype = code;
|
segments[nsegments].segtype = code;
|
||||||
segments[nsegments].segreserved = reserved;
|
segments[nsegments].segreserved = reserved;
|
||||||
@@ -497,7 +496,7 @@ static void membufwrite(int segment, const void *data, int bytes)
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
if (i == nsegments)
|
if (i == nsegments)
|
||||||
nasm_panic(0, "can't find segment %d", segment);
|
nasm_panic("can't find segment %d", segment);
|
||||||
|
|
||||||
if (bytes < 0) {
|
if (bytes < 0) {
|
||||||
b = buf;
|
b = buf;
|
||||||
@@ -520,7 +519,7 @@ static int getsegmentlength(int segment)
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
if (i == nsegments)
|
if (i == nsegments)
|
||||||
nasm_panic(0, "can't find segment %d", segment);
|
nasm_panic("can't find segment %d", segment);
|
||||||
|
|
||||||
return segments[i].seglength;
|
return segments[i].seglength;
|
||||||
}
|
}
|
||||||
@@ -596,7 +595,7 @@ static void rdf2_out(int32_t segto, const void *data,
|
|||||||
membufwrite(segto, databuf, asize);
|
membufwrite(segto, databuf, asize);
|
||||||
} else if (type == OUT_REL2ADR) {
|
} else if (type == OUT_REL2ADR) {
|
||||||
if (segment == segto)
|
if (segment == segto)
|
||||||
nasm_panic(0, "intra-segment OUT_REL2ADR");
|
nasm_panic("intra-segment OUT_REL2ADR");
|
||||||
|
|
||||||
rr.reclen = 8;
|
rr.reclen = 8;
|
||||||
rr.offset = getsegmentlength(segto); /* current offset */
|
rr.offset = getsegmentlength(segto); /* current offset */
|
||||||
@@ -628,9 +627,9 @@ static void rdf2_out(int32_t segto, const void *data,
|
|||||||
membufwrite(segto, &rr.offset, -2);
|
membufwrite(segto, &rr.offset, -2);
|
||||||
} else if (type == OUT_REL4ADR) {
|
} else if (type == OUT_REL4ADR) {
|
||||||
if ((segment == segto) && (globalbits != 64))
|
if ((segment == segto) && (globalbits != 64))
|
||||||
nasm_panic(0, "intra-segment OUT_REL4ADR");
|
nasm_panic("intra-segment OUT_REL4ADR");
|
||||||
if (segment != NO_SEG && segment % 2) {
|
if (segment != NO_SEG && segment % 2) {
|
||||||
nasm_panic(0, "erm... 4 byte segment base ref?");
|
nasm_panic("erm... 4 byte segment base ref?");
|
||||||
}
|
}
|
||||||
|
|
||||||
rr.type = RDFREC_RELOC; /* type signature */
|
rr.type = RDFREC_RELOC; /* type signature */
|
||||||
|
|||||||
@@ -374,7 +374,7 @@ int main(int argc, char **argv)
|
|||||||
/* check against desired name */
|
/* check against desired name */
|
||||||
if (!strcmp(buf, argv[3])) {
|
if (!strcmp(buf, argv[3])) {
|
||||||
if (fread(p = rdbuf, 1, sizeof(rdbuf), fptmp) < 10) {
|
if (fread(p = rdbuf, 1, sizeof(rdbuf), fptmp) < 10) {
|
||||||
nasm_fatal(0, "short read on input");
|
nasm_fatal("short read on input");
|
||||||
}
|
}
|
||||||
l = *(int32_t *)(p + 6);
|
l = *(int32_t *)(p + 6);
|
||||||
fseek(fptmp, l, SEEK_CUR);
|
fseek(fptmp, l, SEEK_CUR);
|
||||||
|
|||||||
@@ -26,15 +26,14 @@ int vsnprintf(char *str, size_t size, const char *format, va_list ap)
|
|||||||
int rv, bytes;
|
int rv, bytes;
|
||||||
|
|
||||||
if (size > BUFFER_SIZE) {
|
if (size > BUFFER_SIZE) {
|
||||||
nasm_panic(ERR_NOFILE,
|
nasm_panic("vsnprintf: size (%d) > BUFFER_SIZE (%d)",
|
||||||
"vsnprintf: size (%d) > BUFFER_SIZE (%d)",
|
|
||||||
size, BUFFER_SIZE);
|
size, BUFFER_SIZE);
|
||||||
size = BUFFER_SIZE;
|
size = BUFFER_SIZE;
|
||||||
}
|
}
|
||||||
|
|
||||||
rv = vsprintf(snprintf_buffer, format, ap);
|
rv = vsprintf(snprintf_buffer, format, ap);
|
||||||
if (rv >= BUFFER_SIZE)
|
if (rv >= BUFFER_SIZE)
|
||||||
nasm_panic(ERR_NOFILE, "vsnprintf buffer overflow");
|
nasm_panic("vsnprintf buffer overflow");
|
||||||
|
|
||||||
if (size > 0) {
|
if (size > 0) {
|
||||||
if ((size_t)rv < size-1)
|
if ((size_t)rv < size-1)
|
||||||
|
|||||||
Reference in New Issue
Block a user