Skip to content

Commit efe066e

Browse files
author
H. Peter Anvin (Intel)
committed
nasm.c: if enabled, print a pass report even on failure
If printing a pass report is enabled, then do so even if the assembly session failed -- except for a critical or panic failure (e.g. if running out of memory, which could cause recursive failures.) This can help discovering e.g. why certain error messages don't appear when one would expect them (because they have not been detected in the current pass.) Signed-off-by: H. Peter Anvin (Intel) <[email protected]>
1 parent ab8787a commit efe066e

File tree

1 file changed

+39
-7
lines changed

1 file changed

+39
-7
lines changed

asm/nasm.c

Lines changed: 39 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1579,6 +1579,21 @@ static void forward_refs(insn *instruction)
15791579
}
15801580
}
15811581

1582+
static void print_pass_report(bool failure)
1583+
{
1584+
/* This test is here to reduce the likelihood of a recursive failure */
1585+
if (unlikely(opt_verbose_info >= 1)) {
1586+
enum pass_type t = pass_type();
1587+
1588+
if (t >= PASS_FIRST) {
1589+
unsigned int end_passes = t > PASS_OPT ? t - PASS_OPT : 0;
1590+
nasm_info(1, "assembly %s after 1+%"PRId64"+%u passes",
1591+
failure ? "failed" : "completed",
1592+
pass_count()-1-end_passes, end_passes);
1593+
}
1594+
}
1595+
}
1596+
15821597
static void assemble_file(const char *fname, struct strlist *depend_list)
15831598
{
15841599
char *line;
@@ -1758,10 +1773,8 @@ static void assemble_file(const char *fname, struct strlist *depend_list)
17581773
reset_warnings();
17591774
}
17601775

1761-
if (pass_final()) {
1762-
/* -On and -Ov switches */
1763-
nasm_info(1, "assembly required 1+%"PRId64"+2 passes\n", pass_count()-3);
1764-
}
1776+
if (terminate_after_phase || pass_final())
1777+
print_pass_report(terminate_after_phase);
17651778

17661779
lfmt->cleanup();
17671780
strlist_free(&warn_list);
@@ -1871,10 +1884,24 @@ static const char no_file_name[] = "nasm"; /* What to print if no file name */
18711884

18721885
/*
18731886
* For fatal/critical/panic errors, kill this process.
1887+
*
1888+
* For FATAL errors doing cleanups, tidying up the list process,
1889+
* and so in is acceptable.
1890+
*
1891+
* For CRITICAL errors, minimize dependencies on memory allocation
1892+
* and/or having a system valid state.
1893+
*
1894+
* For PANIC, if abort_on_panic is set, abort without any other action.
18741895
*/
18751896
static_fatal_func die_hard(errflags true_type, errflags severity)
18761897
{
18771898
if (true_type < ERR_PANIC || !abort_on_panic) {
1899+
if (true_type < ERR_CRITICAL) {
1900+
/* FATAL shutdown, general cleanup actions are valid */
1901+
print_pass_report(true);
1902+
lfmt->cleanup();
1903+
}
1904+
18781905
fflush(NULL);
18791906

18801907
if (ofile) {
@@ -1887,10 +1914,15 @@ static_fatal_func die_hard(errflags true_type, errflags severity)
18871914
if (severity & ERR_USAGE)
18881915
usage();
18891916

1890-
/* Terminate immediately */
1917+
/* Terminate immediately (exit closes any still open files) */
18911918
exit(true_type - ERR_FATAL + 1);
18921919
}
18931920

1921+
/*
1922+
* abort() shouldn't ever return, but be paranoid about this,
1923+
* plus it helps some compilers clue in to the fact that this
1924+
* function can never, ever return.
1925+
*/
18941926
while (1)
18951927
abort();
18961928
}
@@ -1932,8 +1964,8 @@ fatal_func nasm_verror_critical(errflags severity, const char *fmt, va_list args
19321964
errflags true_type = severity & ERR_MASK;
19331965
static bool been_here = false;
19341966

1935-
if (unlikely(been_here))
1936-
abort(); /* Recursive error... just die */
1967+
while (unlikely(been_here))
1968+
abort(); /* Recursive critical error... just die */
19371969

19381970
been_here = true;
19391971

0 commit comments

Comments
 (0)