From 71787fda1b4c60201a9d83a14e325f30a99100a5 Mon Sep 17 00:00:00 2001 From: Cyrill Gorcunov Date: Fri, 24 Sep 2010 15:24:42 +0400 Subject: [PATCH 1/7] BR3074517: Print %macro name inside %rep blocks If we're to print inside %rep block we should find out which %macro it belongs. Reported-by: Rob Neff Signed-off-by: Cyrill Gorcunov --- preproc.c | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-) diff --git a/preproc.c b/preproc.c index 1a1905a4..19de89e9 100644 --- a/preproc.c +++ b/preproc.c @@ -4746,12 +4746,22 @@ static int expand_mmacro(Token * tline) static void verror(int severity, const char *fmt, va_list arg) { char buff[1024]; + MMacro *mmac = NULL; + int delta = 0; vsnprintf(buff, sizeof(buff), fmt, arg); - if (istk && istk->mstk && istk->mstk->name) - nasm_error(severity, "(%s:%d) %s", istk->mstk->name, - istk->mstk->lineno, buff); + /* get %macro name */ + if (istk && istk->mstk) { + mmac = istk->mstk; + /* but %rep blocks should be skipped */ + while (mmac && !mmac->name) + mmac = mmac->next_active, delta++; + } + + if (mmac) + nasm_error(severity, "(%s:%d) %s", + mmac->name, mmac->lineno - delta, buff); else nasm_error(severity, "%s", buff); } From 2c157002f2dd9bd4109fe23848ee12dc8182a12c Mon Sep 17 00:00:00 2001 From: Cyrill Gorcunov Date: Sat, 2 Oct 2010 01:21:00 +0400 Subject: [PATCH 2/7] BR3079550: NASM crash on run-time for OMF output format We could have accessed malloc'ed data on external symbols in obj and ieee output formats. Fix it by using nasm_zalloc. Reported-by: Jiri Malak Patch-by: Jiri Malak Signed-off-by: Cyrill Gorcunov --- output/outieee.c | 4 ++-- output/outobj.c | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/output/outieee.c b/output/outieee.c index c6923fd4..a8f6901c 100644 --- a/output/outieee.c +++ b/output/outieee.c @@ -372,7 +372,7 @@ static void ieee_deflabel(char *name, int32_t segment, i = segment / 2; eb = ebhead; if (!eb) { - eb = *ebtail = nasm_malloc(sizeof(*eb)); + eb = *ebtail = nasm_zalloc(sizeof(*eb)); eb->next = NULL; ebtail = &eb->next; } @@ -380,7 +380,7 @@ static void ieee_deflabel(char *name, int32_t segment, if (eb && eb->next) eb = eb->next; else { - eb = *ebtail = nasm_malloc(sizeof(*eb)); + eb = *ebtail = nasm_zalloc(sizeof(*eb)); eb->next = NULL; ebtail = &eb->next; } diff --git a/output/outobj.c b/output/outobj.c index e62bc3f0..b07a7e49 100644 --- a/output/outobj.c +++ b/output/outobj.c @@ -993,7 +993,7 @@ static void obj_deflabel(char *name, int32_t segment, i = segment / 2; eb = ebhead; if (!eb) { - eb = *ebtail = nasm_malloc(sizeof(*eb)); + eb = *ebtail = nasm_zalloc(sizeof(*eb)); eb->next = NULL; ebtail = &eb->next; } @@ -1001,7 +1001,7 @@ static void obj_deflabel(char *name, int32_t segment, if (eb && eb->next) eb = eb->next; else { - eb = *ebtail = nasm_malloc(sizeof(*eb)); + eb = *ebtail = nasm_zalloc(sizeof(*eb)); eb->next = NULL; ebtail = &eb->next; } From 582b3d0c70586ef088b3b48529173ffd573c051a Mon Sep 17 00:00:00 2001 From: Frank Kotler Date: Tue, 5 Oct 2010 18:37:57 +0400 Subject: [PATCH 3/7] BR3079777: Explain %00 in documentation Signed-off-by: Frank Kotler Signed-off-by: Cyrill Gorcunov --- doc/nasmdoc.src | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/doc/nasmdoc.src b/doc/nasmdoc.src index 03ad4b23..4b2c2acd 100644 --- a/doc/nasmdoc.src +++ b/doc/nasmdoc.src @@ -2673,6 +2673,13 @@ number of parameters. It can be used as an argument to \c{%rep} Examples are given in \k{rotate}. +\S{percent00} \i\c{%00}: \I{label preceeding macro}Label Preceeding Macro + +\c{%00} will return the label preceeding the macro invocation, if any. The +label must be on the same line as the macro invocation, may be a local label +(see \k{locallab}), and need not end in a colon. + + \S{rotate} \i\c{%rotate}: \i{Rotating Macro Parameters} Unix shell programmers will be familiar with the \I{shift From 0457bcbf2e97a822cd6635e1e50c89172ad19a2c Mon Sep 17 00:00:00 2001 From: Cyrill Gorcunov Date: Thu, 7 Oct 2010 19:30:54 +0400 Subject: [PATCH 4/7] preproc: Issue warning on unterminated %{ construct As being pointed by "matching braces" topic on [ http://forum.nasm.us/index.php?topic=905.0 ] we don't issue warning on missed match for "{" brace opened. Strictly speaking we should issue error instead and force user to fix asm source code but since it's here for a long time already -- lets be "admissive". Reported-by: Klod CC: Frank Kotler Signed-off-by: Cyrill Gorcunov --- preproc.c | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/preproc.c b/preproc.c index 19de89e9..af466637 100644 --- a/preproc.c +++ b/preproc.c @@ -907,10 +907,14 @@ static Token *tokenize(char *line) type = TOK_PREPROC_ID; } else if (*p == '{') { p++; - while (*p && *p != '}') { + while (*p) { + if (*p == '}') + break; p[-1] = *p; p++; } + if (*p != '}') + error(ERR_WARNING | ERR_PASS1, "unterminated %{ construct"); p[-1] = '\0'; if (*p) p++; From 6cdc900d8d56106e9ac62247968e618355b08938 Mon Sep 17 00:00:00 2001 From: Cyrill Gorcunov Date: Wed, 27 Oct 2010 21:43:03 +0400 Subject: [PATCH 5/7] preproc.c: Restore concat rules on context local variables This is a backport of commits 8dcbbd7af0d6d07b455de0b6460dca6db6113553 575d4289c9b1fb47774cb79764a24899a69a8d52 Signed-off-by: Cyrill Gorcunov --- preproc.c | 184 ++++++++++++++++++++++++++++-------------------------- 1 file changed, 95 insertions(+), 89 deletions(-) diff --git a/preproc.c b/preproc.c index af466637..d7a96d82 100644 --- a/preproc.c +++ b/preproc.c @@ -212,6 +212,13 @@ enum pp_token_type { TOK_MAX = INT_MAX /* Keep compiler from reducing the range */ }; +#define PP_CONCAT_MASK(x) (1 << (x)) + +struct tokseq_match { + int mask_head; + int mask_tail; +}; + struct Token { Token *next; char *text; @@ -3642,12 +3649,14 @@ static int find_cc(Token * t) return i; } -static bool paste_tokens(Token **head, bool handle_paste_tokens) +static bool paste_tokens(Token **head, const struct tokseq_match *m, + int mnum, bool handle_paste_tokens) { Token **tail, *t, *tt; Token **paste_head; bool did_paste = false; char *tmp; + int i; /* Now handle token pasting... */ paste_head = NULL; @@ -3663,51 +3672,6 @@ static bool paste_tokens(Token **head, bool handle_paste_tokens) tail = &t->next; } break; - case TOK_ID: - case TOK_PREPROC_ID: - case TOK_NUMBER: - case TOK_FLOAT: - { - size_t len = 0; - char *tmp, *p; - - while (tt && (tt->type == TOK_ID || tt->type == TOK_PREPROC_ID || - tt->type == TOK_NUMBER || tt->type == TOK_FLOAT || - tt->type == TOK_OTHER)) { - len += strlen(tt->text); - tt = tt->next; - } - - /* - * Now tt points to the first token after - * the potential paste area... - */ - if (tt != t->next) { - /* We have at least two tokens... */ - len += strlen(t->text); - p = tmp = nasm_malloc(len+1); - - while (t != tt) { - strcpy(p, t->text); - p = strchr(p, '\0'); - t = delete_Token(t); - } - - t = *tail = tokenize(tmp); - nasm_free(tmp); - - while (t->next) { - tail = &t->next; - t = t->next; - } - t->next = tt; /* Attach the remaining token chain */ - - did_paste = true; - } - paste_head = tail; - tail = &t->next; - break; - } case TOK_PASTE: /* %+ */ if (handle_paste_tokens) { /* Zap %+ and whitespace tokens to the right */ @@ -3721,7 +3685,6 @@ static bool paste_tokens(Token **head, bool handle_paste_tokens) tt = t->next; while (tok_type_(tt, TOK_WHITESPACE)) tt = t->next = delete_Token(tt); - if (tt) { tmp = nasm_strcat(t->text, tt->text); delete_Token(t); @@ -3741,9 +3704,55 @@ static bool paste_tokens(Token **head, bool handle_paste_tokens) } /* else fall through */ default: - tail = &t->next; - if (!tok_type_(t->next, TOK_WHITESPACE)) - paste_head = tail; + /* + * Concatenation of tokens might look nontrivial + * but in real it's pretty simple -- the caller + * prepares the masks of token types to be concatenated + * and we simply find matched sequences and slip + * them together + */ + for (i = 0; i < mnum; i++) { + if (PP_CONCAT_MASK(t->type) & m[i].mask_head) { + size_t len = 0; + char *tmp, *p; + + while (tt && (PP_CONCAT_MASK(tt->type) & m[i].mask_tail)) { + len += strlen(tt->text); + tt = tt->next; + } + + /* + * Now tt points to the first token after + * the potential paste area... + */ + if (tt != t->next) { + /* We have at least two tokens... */ + len += strlen(t->text); + p = tmp = nasm_malloc(len+1); + while (t != tt) { + strcpy(p, t->text); + p = strchr(p, '\0'); + t = delete_Token(t); + } + t = *tail = tokenize(tmp); + nasm_free(tmp); + while (t->next) { + tail = &t->next; + t = t->next; + } + t->next = tt; /* Attach the remaining token chain */ + did_paste = true; + } + paste_head = tail; + tail = &t->next; + break; + } + } + if (i >= mnum) { /* no match */ + tail = &t->next; + if (!tok_type_(t->next, TOK_WHITESPACE)) + paste_head = tail; + } break; } } @@ -3977,35 +3986,6 @@ static Token *expand_mmac_params(Token * tline) } delete_Token(t); changed = true; - } else if (tline->type == TOK_PREPROC_ID && - tline->text[0] == '%' && - tline->text[1] == '$' && - !tok_type_(tline->next, TOK_WHITESPACE) && - (tok_type_(tline->next, TOK_ID) || - tok_type_(tline->next, TOK_PREPROC_ID) || - tok_type_(tline->next, TOK_NUMBER) || - tok_type_(tline->next, TOK_OTHER) || - tok_type_(tline->next, TOK_FLOAT))) { - /* - * In a sake of backward compatibility we allow - * to expand local single macro that early before - * pasting token code have place - * - * NOTE: that new code MUST use %+ macro to obtain - * same result - */ - t = tline; - tline = tline->next; - tt = tokenize(t->text); - tt = expand_smacro(tt); - *tail = tt; - while (tt) { - tt->a.mac = NULL; - tail = &tt->next; - tt = tt->next; - } - delete_Token(t); - changed = true; } else { t = *tail = tline; tline = tline->next; @@ -4015,8 +3995,23 @@ static Token *expand_mmac_params(Token * tline) } *tail = NULL; - if (changed) - paste_tokens(&thead, false); + if (changed) { + const struct tokseq_match t[] = { + { + PP_CONCAT_MASK(TOK_ID) | + PP_CONCAT_MASK(TOK_FLOAT), /* head */ + PP_CONCAT_MASK(TOK_ID) | + PP_CONCAT_MASK(TOK_NUMBER) | + PP_CONCAT_MASK(TOK_FLOAT) | + PP_CONCAT_MASK(TOK_OTHER) /* tail */ + }, + { + PP_CONCAT_MASK(TOK_NUMBER), /* head */ + PP_CONCAT_MASK(TOK_NUMBER) /* tail */ + } + }; + paste_tokens(&thead, t, ARRAY_SIZE(t), false); + } return thead; } @@ -4327,14 +4322,25 @@ again: * Also we look for %+ tokens and concatenate the tokens before and after * them (without white spaces in between). */ - if (expanded && paste_tokens(&thead, true)) { - /* - * If we concatenated something, *and* we had previously expanded - * an actual macro, scan the lines again for macros... - */ - tline = thead; - expanded = false; - goto again; + if (expanded) { + const struct tokseq_match t[] = { + { + PP_CONCAT_MASK(TOK_ID) | + PP_CONCAT_MASK(TOK_PREPROC_ID), /* head */ + PP_CONCAT_MASK(TOK_ID) | + PP_CONCAT_MASK(TOK_PREPROC_ID) | + PP_CONCAT_MASK(TOK_NUMBER) /* tail */ + } + }; + if (paste_tokens(&thead, t, ARRAY_SIZE(t), true)) { + /* + * If we concatenated something, *and* we had previously expanded + * an actual macro, scan the lines again for macros... + */ + tline = thead; + expanded = false; + goto again; + } } err: From fdbe8baf7ad251231161043837364be214412979 Mon Sep 17 00:00:00 2001 From: Cyrill Gorcunov Date: Wed, 27 Oct 2010 21:50:20 +0400 Subject: [PATCH 6/7] doc: Update changes for 2.09.03 Signed-off-by: Cyrill Gorcunov --- doc/changes.src | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/doc/changes.src b/doc/changes.src index a6a54f14..4ecb14ed 100644 --- a/doc/changes.src +++ b/doc/changes.src @@ -8,6 +8,21 @@ The NASM 2 series support x86-64, and is the production version of NASM since 2007. +\S{cl-2.09.03} Version 2.09.03 + +\b Print \c{%macro} name inside \c{%rep} blocks on error. + +\b Fix preprocessor expansion behaviour. It happened sometime + too early and sometime simply wrong. Move behaviour back to + the origins (down to NASM 2.05.01). + +\b Fix unitialized data dereference on OMF output format. + +\b Issue warning on unterminated \c{%{} construct. + +\b Fix for documentation typo. + + \S{cl-2.09.02} Version 2.09.02 \b Fix reversed tokens when \c{%deftok} produces more than one output token. From 4794de2f5b1850d5b456d903bead541fee351566 Mon Sep 17 00:00:00 2001 From: Cyrill Gorcunov Date: Wed, 27 Oct 2010 21:52:40 +0400 Subject: [PATCH 7/7] NASM 2.09.03 Signed-off-by: Cyrill Gorcunov --- version | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/version b/version index 401fc593..1ae21323 100644 --- a/version +++ b/version @@ -1 +1 @@ -2.09.02 +2.09.03