From 800c1686880acd74b964de00f58c7a2d8f14eff3 Mon Sep 17 00:00:00 2001 From: "H. Peter Anvin (Intel)" Date: Fri, 14 Dec 2018 12:22:11 -0800 Subject: --no-line: new option to ignore %line directives For debugging preprocessed code, it is useful to be able to ignore %line directives rather than having to filter them out externally. Signed-off-by: H. Peter Anvin (Intel) --- asm/nasm.c | 9 ++++++++- asm/preproc-nop.c | 11 ++++++----- asm/preproc.c | 4 ++++ asm/preproc.h | 1 + doc/changes.src | 3 +++ doc/nasmdoc.src | 34 ++++++++++++++++++---------------- 6 files changed, 40 insertions(+), 22 deletions(-) diff --git a/asm/nasm.c b/asm/nasm.c index 35693761..c6e82eaf 100644 --- a/asm/nasm.c +++ b/asm/nasm.c @@ -142,6 +142,7 @@ static const struct forwrefinfo *forwref; static const struct preproc_ops *preproc; static StrList *include_path; +bool pp_noline; /* Ignore %line directives */ #define OP_NORMAL (1U << 0) #define OP_PREPROCESS (1U << 1) @@ -839,7 +840,8 @@ enum text_options { OPT_PRAGMA, OPT_BEFORE, OPT_LIMIT, - OPT_KEEP_ALL + OPT_KEEP_ALL, + OPT_NO_LINE }; struct textargs { const char *label; @@ -863,6 +865,7 @@ static const struct textargs textopts[] = { {"before", OPT_BEFORE, true, 0}, {"limit-", OPT_LIMIT, true, 0}, {"keep-all", OPT_KEEP_ALL, false, 0}, + {"no-line", OPT_NO_LINE, false, 0}, {NULL, OPT_BOGUS, false, 0} }; @@ -1210,6 +1213,9 @@ static bool process_arg(char *p, char *q, int pass) case OPT_KEEP_ALL: keep_all = true; break; + case OPT_NO_LINE: + pp_noline = true; + break; case OPT_HELP: help(0); exit(0); @@ -2001,6 +2007,7 @@ static void help(const char xopt) " --lprefix str prepend the given string to all other symbols\n" " --lpostfix str append the given string to all other symbols\n" " --keep-all output files will not be removed even if an error happens\n" + " --no-line ignore %%line directives in input\n" " --limit-X val set execution limit X\n"); for (i = 0; i <= LIMIT_MAX; i++) { diff --git a/asm/preproc-nop.c b/asm/preproc-nop.c index 6f7aaf9e..3244889d 100644 --- a/asm/preproc-nop.c +++ b/asm/preproc-nop.c @@ -86,7 +86,6 @@ static char *nop_getline(void) src_set_linnum(src_get_linnum() + nop_lineinc); while (1) { /* Loop to handle %line */ - p = buffer; while (1) { /* Loop to handle long lines */ q = fgets(p, bufsize - (p - buffer), nop_fp); @@ -119,13 +118,15 @@ static char *nop_getline(void) int32_t ln; int li; char *nm = nasm_malloc(strlen(buffer)); - if (sscanf(buffer + 5, "%"PRId32"+%d %s", &ln, &li, nm) == 3) { - src_set(ln, nm); + int conv = sscanf(buffer + 5, "%"PRId32"+%d %s", &ln, &li, nm); + if (conv >= 2) { + if (!pp_noline) + src_set(ln, conv >= 3 ? nm : NULL); nop_lineinc = li; - nasm_free(nm); - continue; } nasm_free(nm); + if (conv >= 2) + continue; } break; } diff --git a/asm/preproc.c b/asm/preproc.c index b134414a..95ca56fc 100644 --- a/asm/preproc.c +++ b/asm/preproc.c @@ -3662,6 +3662,10 @@ issue_error: /* * Syntax is `%line nnn[+mmm] [filename]' */ + if (unlikely(pp_noline)) { + free_tlist(origline); + return DIRECTIVE_FOUND; + } tline = tline->next; skip_white_(tline); if (!tok_type_(tline, TOK_NUMBER)) { diff --git a/asm/preproc.h b/asm/preproc.h index fcf8695b..14d4cfd3 100644 --- a/asm/preproc.h +++ b/asm/preproc.h @@ -43,6 +43,7 @@ extern const char * const pp_directives[]; extern const uint8_t pp_directives_len[]; +extern bool pp_noline; /* Pointer to a macro chain */ typedef const unsigned char macros_t; diff --git a/doc/changes.src b/doc/changes.src index 8e0bc060..d279b0ad 100644 --- a/doc/changes.src +++ b/doc/changes.src @@ -37,6 +37,9 @@ failure instead which is very slow and not easy to debug. \b Duplicate definitions of the same label \e{with the same value} is now explicitly permitted (2.14 would allow it in some circumstances.) +\b Add the option \c{--no-line} to ignore \c{%line} directives in the +source. See \k{opt-no-line} and \k{line}. + \S{cl-2.14} Version 2.14 \b Changed \c{-I} option semantics by adding a trailing path separator diff --git a/doc/nasmdoc.src b/doc/nasmdoc.src index f1abc507..bdec6b6e 100644 --- a/doc/nasmdoc.src +++ b/doc/nasmdoc.src @@ -368,10 +368,10 @@ To get further usage instructions from NASM, try typing \c nasm -h -\c{--help} option is also the same. +The option \c{--help} is an alias for the \c{-h} option. -As \c{-hf}, this will also list the available output file formats, and what they -are. +The option \c{-hf} will also list the available output file formats, +and what they are. If you use Linux but aren't sure whether your system is \c{a.out} or \c{ELF}, type @@ -992,7 +992,14 @@ In example, running this limits the maximum line count to be 1000. \S{opt-keep-all} The \i\c{--keep-all} Option -This option doesn't delete any output files even if an error happens. +This option prevents NASM from deleting any output files even if an +error happens. + +\S{opt-no-line} The \i\c{--no-line} Option + +If this option is given, all \i\c{%line} directives in the source code +are ignored. This can be useful for debugging already preprocessed +code. See \k{line}. \S{nasmenv} The \i\c{NASMENV} \i{Environment} Variable @@ -3747,15 +3754,6 @@ the user. For example: \H{otherpreproc} \i{Other Preprocessor Directives} -NASM also has preprocessor directives which allow access to -information from external sources. Currently they include: - -\b\c{%line} enables NASM to correctly handle the output of another -preprocessor (see \k{line}). - -\b\c{%!} enables NASM to read in the value of an environment variable, -which can then be used in your program (see \k{getenv}). - \S{line} \i\c{%line} Directive The \c{%line} directive is used to notify NASM that the input line @@ -3766,9 +3764,9 @@ directive allows NASM to output messages which indicate the line number of the original source file, instead of the file that is being read by NASM. -This preprocessor directive is not generally of use to programmers, -by may be of interest to preprocessor authors. The usage of the -\c{%line} preprocessor directive is as follows: +This preprocessor directive is not generally used directly by +programmers, but may be of interest to preprocessor authors. The +usage of the \c{%line} preprocessor directive is as follows: \c %line nnn[+mmm] [filename] @@ -3783,6 +3781,10 @@ After reading a \c{%line} preprocessor directive, NASM will report all file name and line numbers relative to the values specified therein. +If the command line option \i\c{--no-line} is given, all \c{%line} +directives are ignored. This may be useful for debugging preprocessed +code. See \k{opt-no-line}. + \S{getenv} \i\c{%!}\e{variable}: Read an Environment Variable. -- cgit v1.2.1 From 0402a2d40233acdae005b8cad33d502f95da63df Mon Sep 17 00:00:00 2001 From: "H. Peter Anvin (Intel)" Date: Fri, 14 Dec 2018 13:01:39 -0800 Subject: labels.c: redefine test should be passn, not pass0 Stupid thinko: lpass should be passn + 1, not pass0 + 1. Signed-off-by: H. Peter Anvin (Intel) --- asm/labels.c | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/asm/labels.c b/asm/labels.c index a3ed0066..20107603 100644 --- a/asm/labels.c +++ b/asm/labels.c @@ -442,7 +442,7 @@ void define_label(const char *label, int32_t segment, * The backend may invoke this before pass 1, so treat that as * a special "pass". */ - const int64_t lpass = pass0 + 1; + const int64_t lpass = passn + 1; /* * Phase errors here can be one of two types: a new label appears, @@ -521,9 +521,10 @@ void define_label(const char *label, int32_t segment, src_set(saved_line, saved_fname); } else if (changed && pass0 > 1 && lptr->defn.type != LBL_SPECIAL) { /* - * WARN_LABEL_LATE defaults to an error, as this should never actually happen. - * Just in case this is a backwards compatibility problem, still make it a - * warning so that the user can suppress or demote it. + * WARN_LABEL_LATE defaults to an error, as this should never + * actually happen. Just in case this is a backwards + * compatibility problem, still make it a warning so that the + * user can suppress or demote it. * * As a special case, LBL_SPECIAL symbols are allowed to be changed * even during the last pass. -- cgit v1.2.1 From 1e2358b17f69c713ca0567bd892e2b8cadeb3a22 Mon Sep 17 00:00:00 2001 From: "H. Peter Anvin (Intel)" Date: Fri, 14 Dec 2018 13:02:39 -0800 Subject: Document the -Ov option, minor fix for gcc -Og The -Ov option is useful but was undocumented. Add an initialization to keep gcc from complaining at optimization level -Og. Signed-off-by: H. Peter Anvin (Intel) --- asm/nasm.c | 4 +++- doc/nasmdoc.src | 7 ++++++- 2 files changed, 9 insertions(+), 2 deletions(-) diff --git a/asm/nasm.c b/asm/nasm.c index c6e82eaf..1c5a5fc5 100644 --- a/asm/nasm.c +++ b/asm/nasm.c @@ -1135,6 +1135,7 @@ static bool process_arg(char *p, char *q, int pass) break; } + olen = 0; /* Placate gcc at lower optimization levels */ plen = strlen(p); for (tx = textopts; tx->label; tx++) { olen = strlen(tx->label); @@ -1985,10 +1986,11 @@ static void help(const char xopt) " -l listfile write listing to a listfile\n\n" " -Ipath add a pathname to the include file path\n"); printf - (" -Olevel optimize opcodes, immediates and branch offsets\n" + (" -Oflags... optimize opcodes, immediates and branch offsets\n" " -O0 no optimization\n" " -O1 minimal optimization\n" " -Ox multipass optimization (default)\n" + " -Ov display the number of passes executed at the end\n" " -Pfile pre-include a file (also --include)\n" " -Dmacro[=str] pre-define a macro\n" " -Umacro undefine a macro\n" diff --git a/doc/nasmdoc.src b/doc/nasmdoc.src index bdec6b6e..ea6f10f2 100644 --- a/doc/nasmdoc.src +++ b/doc/nasmdoc.src @@ -746,7 +746,9 @@ with a \i{stub preprocessor} which does nothing. \S{opt-O} The \i\c{-O} Option: Specifying \i{Multipass Optimization} Using the \c{-O} option, you can tell NASM to carry out different -levels of optimization. The syntax is: +levels of optimization. Multiple flags can be specified after the +\c{-O} options, some of which can be combined in a single option, +e.g. \c{-Oxv}. \b \c{-O0}: No optimization. All operands take their long forms, if a short form is not specified, except conditional jumps. @@ -764,6 +766,9 @@ levels of optimization. The syntax is: releases, the letter \c{x} may also be any number greater than one. This number has no effect on the actual number of passes. +\b \c{-Ov}: At the end of assembly, print the number of passes + actually executed. + The \c{-Ox} mode is recommended for most uses, and is the default since NASM 2.09. -- cgit v1.2.1 From bc7f5fd93c55ef9fdb5e6c0ef7403a383bee841e Mon Sep 17 00:00:00 2001 From: "H. Peter Anvin (Intel)" Date: Fri, 14 Dec 2018 13:08:39 -0800 Subject: NASM 2.14.01rc5 --- version | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/version b/version index 593b3ac6..2a616f00 100644 --- a/version +++ b/version @@ -1 +1 @@ -2.14.01rc4 +2.14.01rc5 -- cgit v1.2.1