From fc0ff223b203c5e90cdf59707edb5ad965bc4b18 Mon Sep 17 00:00:00 2001 From: "H. Peter Anvin" Date: Mon, 7 Mar 2016 21:46:04 -0800 Subject: [PATCH] labels: emit the same label name to the output and debug backends!! When a local label was seen, the debug backend would not receive the full label name! In order to both simplify the code and avoid this kind of discrepancy again, make both the output and debug format calls from a common static function. However, none of the current debug format backends want to see NASM special symbols (that start with .. but not ..@) so filter those from the debug backend. Finally, fix an incorrect comment in nasm.h: the debug format is called *after* the output format. Signed-off-by: H. Peter Anvin Cc: Jim Kukunas --- labels.c | 52 ++++++++++++++++++++++++++--------------------- nasm.h | 2 +- test/cv8struc.asm | 6 ++++++ 3 files changed, 36 insertions(+), 24 deletions(-) diff --git a/labels.c b/labels.c index 94c2ae6f..d7cdb8c3 100644 --- a/labels.c +++ b/labels.c @@ -1,6 +1,6 @@ /* ----------------------------------------------------------------------- * * - * Copyright 1996-2014 The NASM Authors - All Rights Reserved + * Copyright 1996-2016 The NASM Authors - All Rights Reserved * See the file AUTHORS included with the NASM distribution for * the specific copyright holders. * @@ -126,6 +126,22 @@ static bool initialized = false; char lprefix[PREFIX_MAX] = { 0 }; char lpostfix[PREFIX_MAX] = { 0 }; +/* + * Emit a symdef to the output and the debug format backends. + */ +static void out_symdef(char *name, int32_t segment, int64_t offset, + int is_global, char *special) +{ + ofmt->symdef(name, segment, offset, is_global, special); + + /* + * NASM special symbols are not passed to the debug format; none + * of the current backends want to see them. + */ + if (!(name[0] == '.' && name[1] == '.' && name[2] != '@')) + dfmt->debug_deflabel(name, segment, offset, is_global, special); +} + /* * Internal routine: finds the `union label' corresponding to the * given label name. Creates a new one, if it isn't found, and if @@ -260,17 +276,13 @@ void redefine_label(char *label, int32_t segment, int64_t offset, char *special, snprintf(xsymbol, slen, "%s%s%s", lprefix, lptr->defn.label, lpostfix); - ofmt->symdef(xsymbol, segment, offset, exi, - special ? special : lptr->defn.special); - dfmt->debug_deflabel(xsymbol, segment, offset, exi, - special ? special : lptr->defn.special); -/** nasm_free(xsymbol); ! outobj.c stores the pointer; ouch!!! **/ + out_symdef(xsymbol, segment, offset, exi, + special ? special : lptr->defn.special); + /** nasm_free(xsymbol); ! outobj.c stores the pointer; ouch!!! **/ } else { if ((lptr->defn.is_global & (GLOBAL_BIT | EXTERN_BIT)) != EXTERN_BIT) { - ofmt->symdef(lptr->defn.label, segment, offset, exi, - special ? special : lptr->defn.special); - dfmt->debug_deflabel(label, segment, offset, exi, - special ? special : lptr->defn.special); + out_symdef(lptr->defn.label, segment, offset, exi, + special ? special : lptr->defn.special); } } } /* if (pass0 == 1) */ @@ -325,17 +337,13 @@ void define_label(char *label, int32_t segment, int64_t offset, char *special, snprintf(xsymbol, slen, "%s%s%s", lprefix, lptr->defn.label, lpostfix); - ofmt->symdef(xsymbol, segment, offset, exi, - special ? special : lptr->defn.special); - dfmt->debug_deflabel(xsymbol, segment, offset, exi, - special ? special : lptr->defn.special); -/** nasm_free(xsymbol); ! outobj.c stores the pointer; ouch!!! **/ + out_symdef(xsymbol, segment, offset, exi, + special ? special : lptr->defn.special); + /** nasm_free(xsymbol); ! outobj.c stores the pointer; ouch!!! **/ } else { if ((lptr->defn.is_global & (GLOBAL_BIT | EXTERN_BIT)) != EXTERN_BIT) { - ofmt->symdef(lptr->defn.label, segment, offset, exi, - special ? special : lptr->defn.special); - dfmt->debug_deflabel(label, segment, offset, exi, - special ? special : lptr->defn.special); + out_symdef(lptr->defn.label, segment, offset, exi, + special ? special : lptr->defn.special); } } } /* if (pass0 == 1) */ @@ -369,10 +377,8 @@ void define_common(char *label, int32_t segment, int32_t size, char *special) if (pass0 == 0) return; - ofmt->symdef(lptr->defn.label, segment, size, 2, - special ? special : lptr->defn.special); - dfmt->debug_deflabel(lptr->defn.label, segment, size, 2, - special ? special : lptr->defn.special); + out_symdef(lptr->defn.label, segment, size, 2, + special ? special : lptr->defn.special); } void declare_as_global(char *label, char *special) diff --git a/nasm.h b/nasm.h index ea715c52..16d4ae81 100644 --- a/nasm.h +++ b/nasm.h @@ -887,7 +887,7 @@ struct dfmt { /* * debug_deflabel - called whenever a label is defined. Parameters * are the same as to 'symdef()' in the output format. This function - * would be called before the output format version. + * is called after the output format version. */ void (*debug_deflabel)(char *name, int32_t segment, int64_t offset, diff --git a/test/cv8struc.asm b/test/cv8struc.asm index 83fce799..eac6d8bb 100644 --- a/test/cv8struc.asm +++ b/test/cv8struc.asm @@ -6,3 +6,9 @@ a_struc: istruc A_STRUC at A_STRUC._a, dw 1 iend + + section .data +foo: + dd 0x11111111 +.bar: + dd 0x22222222