0
0
mirror of https://github.com/netwide-assembler/nasm.git synced 2025-07-24 10:25:42 -04:00

Make limits 64 bits, add globallines limit to configurable limits

Make all limit counters 64 bits, in case someone really has a usage
for an insanely large program. The globallines limit was omitted, add
it to the list of configurable limits.

Signed-off-by: H. Peter Anvin <hpa@zytor.com>
This commit is contained in:
H. Peter Anvin 2018-06-15 17:51:39 -07:00
parent cd133a6f2d
commit a3d96d02b0
5 changed files with 27 additions and 23 deletions

View File

@ -72,7 +72,7 @@ static void *scpriv;
static int *opflags; static int *opflags;
static struct eval_hints *hint; static struct eval_hints *hint;
static int deadman; static int64_t deadman;
/* /*

View File

@ -94,7 +94,8 @@ static bool abort_on_panic = ABORT_ON_PANIC;
static bool keep_all; static bool keep_all;
bool tasm_compatible_mode = false; bool tasm_compatible_mode = false;
int pass0, passn; int pass0;
int64_t passn;
static int pass1, pass2; /* XXX: Get rid of these, they are redundant */ static int pass1, pass2; /* XXX: Get rid of these, they are redundant */
int globalrel = 0; int globalrel = 0;
int globalbnd = 0; int globalbnd = 0;
@ -106,8 +107,7 @@ const char *outname;
static const char *listname; static const char *listname;
static const char *errname; static const char *errname;
static int globallineno; /* for forward-reference tracking */ static int64_t globallineno; /* for forward-reference tracking */
#define GLOBALLINENO_MAX INT32_MAX
/* static int pass = 0; */ /* static int pass = 0; */
const struct ofmt *ofmt = &OF_DEFAULT; const struct ofmt *ofmt = &OF_DEFAULT;
@ -159,10 +159,10 @@ static char *(*quote_for_make)(const char *) = quote_for_pmake;
* Execution limits that can be set via a command-line option or %pragma * Execution limits that can be set via a command-line option or %pragma
*/ */
#define LIMIT_MAX_VAL (INT_MAX >> 1) /* Effectively unlimited */ #define LIMIT_MAX_VAL (INT64_MAX >> 1) /* Effectively unlimited */
int nasm_limit[LIMIT_MAX+1] = int64_t nasm_limit[LIMIT_MAX+1] =
{ LIMIT_MAX_VAL, 1000, 1000000, 1000000, 1000000 }; { LIMIT_MAX_VAL, 1000, 1000000, 1000000, 1000000, 2000000000 };
struct limit_info { struct limit_info {
const char *name; const char *name;
@ -173,7 +173,8 @@ static const struct limit_info limit_info[LIMIT_MAX+1] = {
{ "stalled-passes", "number of passes without forward progress" }, { "stalled-passes", "number of passes without forward progress" },
{ "macro-levels", "levels of macro expansion"}, { "macro-levels", "levels of macro expansion"},
{ "rep", "%rep count" }, { "rep", "%rep count" },
{ "eval", "expression evaluation descent"} { "eval", "expression evaluation descent"},
{ "lines", "total source lines processed"}
}; };
enum directive_result enum directive_result
@ -1378,7 +1379,7 @@ static void assemble_file(const char *fname, StrList **depend_ptr)
insn output_ins; insn output_ins;
int i; int i;
uint64_t prev_offset_changed; uint64_t prev_offset_changed;
int stall_count = 0; /* Make sure we make forward progress... */ int64_t stall_count = 0; /* Make sure we make forward progress... */
switch (cmd_sb) { switch (cmd_sb) {
case 16: case 16:
@ -1432,10 +1433,10 @@ static void assemble_file(const char *fname, StrList **depend_ptr)
globallineno = 0; globallineno = 0;
while ((line = preproc->getline())) { while ((line = preproc->getline())) {
if (globallineno++ == GLOBALLINENO_MAX) if (++globallineno > nasm_limit[LIMIT_LINES])
nasm_error(ERR_FATAL, nasm_fatal(0,
"overall line number reaches the maximum %d\n", "overall line count exceeds the maximum %"PRId64"\n",
GLOBALLINENO_MAX); nasm_limit[LIMIT_LINES]);
/* /*
* Here we parse our directives; this is not handled by the * Here we parse our directives; this is not handled by the
@ -1639,7 +1640,7 @@ static void assemble_file(const char *fname, StrList **depend_ptr)
*/ */
nasm_error(ERR_NONFATAL, nasm_error(ERR_NONFATAL,
"Can't find valid values for all labels " "Can't find valid values for all labels "
"after %d passes, giving up.", passn); "after %"PRId64" passes, giving up.", passn);
nasm_error(ERR_NONFATAL, nasm_error(ERR_NONFATAL,
"Possible causes: recursive EQUs, macro abuse."); "Possible causes: recursive EQUs, macro abuse.");
break; break;
@ -1650,7 +1651,8 @@ static void assemble_file(const char *fname, StrList **depend_ptr)
lfmt->cleanup(); lfmt->cleanup();
if (!terminate_after_phase && opt_verbose_info) { if (!terminate_after_phase && opt_verbose_info) {
/* -On and -Ov switches */ /* -On and -Ov switches */
fprintf(stdout, "info: assembly required 1+%d+1 passes\n", passn-3); fprintf(stdout, "info: assembly required 1+%"PRId64"+1 passes\n",
passn-3);
} }
} }
@ -1955,7 +1957,7 @@ static void help(const char xopt)
printf(" %-15s %s (default ", printf(" %-15s %s (default ",
limit_info[i].name, limit_info[i].help); limit_info[i].name, limit_info[i].help);
if (nasm_limit[i] < LIMIT_MAX_VAL) { if (nasm_limit[i] < LIMIT_MAX_VAL) {
printf("%d)\n", nasm_limit[i]); printf("%"PRId64")\n", nasm_limit[i]);
} else { } else {
printf("unlimited)\n"); printf("unlimited)\n");
} }

View File

@ -3044,7 +3044,7 @@ issue_error:
count = reloc_value(evalresult); count = reloc_value(evalresult);
if (count > nasm_limit[LIMIT_REP]) { if (count > nasm_limit[LIMIT_REP]) {
nasm_error(ERR_NONFATAL, nasm_error(ERR_NONFATAL,
"`%%rep' count %"PRId64" exceeds limit (currently %d)", "`%%rep' count %"PRId64" exceeds limit (currently %"PRId64")",
count, nasm_limit[LIMIT_REP]); count, nasm_limit[LIMIT_REP]);
count = 0; count = 0;
} else if (count < 0) { } else if (count < 0) {
@ -4195,7 +4195,7 @@ static Token *expand_smacro(Token * tline)
Token *org_tline = tline; Token *org_tline = tline;
Context *ctx; Context *ctx;
const char *mname; const char *mname;
int deadman = nasm_limit[LIMIT_MACROS]; int64_t deadman = nasm_limit[LIMIT_MACROS];
bool expanded; bool expanded;
/* /*

View File

@ -760,10 +760,11 @@ enum nasm_limit {
LIMIT_STALLED, LIMIT_STALLED,
LIMIT_MACROS, LIMIT_MACROS,
LIMIT_REP, LIMIT_REP,
LIMIT_EVAL LIMIT_EVAL,
LIMIT_LINES
}; };
#define LIMIT_MAX LIMIT_EVAL #define LIMIT_MAX LIMIT_LINES
extern int nasm_limit[LIMIT_MAX+1]; extern int64_t nasm_limit[LIMIT_MAX+1];
extern enum directive_result nasm_set_limit(const char *, const char *); extern enum directive_result nasm_set_limit(const char *, const char *);
/* /*
@ -1242,7 +1243,7 @@ enum decorator_tokens {
*/ */
extern int pass0; extern int pass0;
extern int passn; /* Actual pass number */ extern int64_t passn; /* Actual pass number */
extern bool tasm_compatible_mode; extern bool tasm_compatible_mode;
extern int optimizing; extern int optimizing;

View File

@ -75,7 +75,8 @@ static void dbg_init(void)
static void dbg_reset(void) static void dbg_reset(void)
{ {
fprintf(ofile, "*** pass reset: pass0 = %d, passn = %d\n", pass0, passn); fprintf(ofile, "*** pass reset: pass0 = %d, passn = %"PRId64"\n",
pass0, passn);
} }
static void dbg_cleanup(void) static void dbg_cleanup(void)