From fc0ff223b203c5e90cdf59707edb5ad965bc4b18 Mon Sep 17 00:00:00 2001 From: "H. Peter Anvin" Date: Mon, 7 Mar 2016 21:46:04 -0800 Subject: [PATCH 01/12] 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 From 5686a65fe93bf4946bb76fd37f9543851079bfe5 Mon Sep 17 00:00:00 2001 From: "H. Peter Anvin" Date: Mon, 7 Mar 2016 22:02:17 -0800 Subject: [PATCH 02/12] outobj: no need to filter .. symbols in the debug format anymore labels.c now filter ..[^@] special symbols from the debug backend, so we don't have to open-code that everywhere. Signed-off-by: H. Peter Anvin Cc: Jim Kukunas --- output/outobj.c | 14 +++++--------- 1 file changed, 5 insertions(+), 9 deletions(-) diff --git a/output/outobj.c b/output/outobj.c index 57738126..fd6c326a 100644 --- a/output/outobj.c +++ b/output/outobj.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. * @@ -2499,20 +2499,16 @@ static void dbgbi_deflabel(char *name, int32_t segment, (void)special; + /* + * Note: ..[^@] special symbols are filtered in labels.c + */ + /* * If it's a special-retry from pass two, discard it. */ if (is_global == 3) return; - /* - * First check for the double-period, signifying something - * unusual. - */ - if (name[0] == '.' && name[1] == '.' && name[2] != '@') { - return; - } - /* * Case (i): */ From 3def9fcb59fde13cc61184df3eaf49cfed8f6e2c Mon Sep 17 00:00:00 2001 From: "H. Peter Anvin" Date: Mon, 7 Mar 2016 22:04:54 -0800 Subject: [PATCH 03/12] outieee: no need to filter .. symbols in the debug format anymore labels.c now filter ..[^@] special symbols from the debug backend, so we don't have to open-code that everywhere. In the actual output format, don't treat ..@ symbols as special. Signed-off-by: H. Peter Anvin Cc: Jim Kukunas --- output/outieee.c | 16 ++++++---------- 1 file changed, 6 insertions(+), 10 deletions(-) diff --git a/output/outieee.c b/output/outieee.c index 79faa649..f5f6f5a6 100644 --- a/output/outieee.c +++ b/output/outieee.c @@ -1,6 +1,6 @@ /* ----------------------------------------------------------------------- * * - * Copyright 1996-2013 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. * @@ -305,7 +305,7 @@ static void ieee_deflabel(char *name, int32_t segment, * First check for the double-period, signifying something * unusual. */ - if (name[0] == '.' && name[1] == '.') { + if (name[0] == '.' && name[1] == '.' && name[2] != '@') { if (!strcmp(name, "..start")) { ieee_entry_seg = segment; ieee_entry_ofs = offset; @@ -1397,20 +1397,16 @@ static void dbgls_deflabel(char *name, int32_t segment, /* Keep compiler from warning about special */ (void)special; + /* + * Note: ..[^@] special symbols are filtered in labels.c + */ + /* * If it's a special-retry from pass two, discard it. */ if (is_global == 3) return; - /* - * First check for the double-period, signifying something - * unusual. - */ - if (name[0] == '.' && name[1] == '.' && name[2] != '@') { - return; - } - /* * Case (i): */ From bc42cbe36348aca4c33210fa8322bd451e36ef6c Mon Sep 17 00:00:00 2001 From: "H. Peter Anvin" Date: Mon, 7 Mar 2016 21:51:57 -0800 Subject: [PATCH 04/12] codeview: remove hack for handling local labels Now when labels are properly concatenated in common code, there is no reason for the debugging backend to need to be aware of local symbols. We don't have to consider ..[^@] special symbols either, as they are now filtered in labels.c. Signed-off-by: H. Peter Anvin Debugged-by: Jim Kukunas --- output/codeview.c | 19 ++----------------- 1 file changed, 2 insertions(+), 17 deletions(-) diff --git a/output/codeview.c b/output/codeview.c index b5c205ce..f9750bfc 100644 --- a/output/codeview.c +++ b/output/codeview.c @@ -188,8 +188,6 @@ static void cv8_linenum(const char *filename, int32_t linenumber, static void cv8_deflabel(char *name, int32_t segment, int64_t offset, int is_global, char *special) { - int ret; - size_t len; struct cv8_symbol *sym; struct coff_Section *s; @@ -214,21 +212,8 @@ static void cv8_deflabel(char *name, int32_t segment, int64_t offset, sym->size = 0; sym->typeindex = 0; - /* handle local labels */ - if (name[0] == '.' && cv8_state.last_sym != NULL) { - len = strlen(cv8_state.last_sym->name) + strlen(name); - sym->name = nasm_malloc(len + 1); - ret = snprintf(sym->name, len + 1, "%s%s", - cv8_state.last_sym->name, name); - nasm_assert(ret > 0 && (size_t)ret == len); - } else { - len = strlen(name); - sym->name = nasm_malloc(len + 1); - ret = snprintf(sym->name, len + 1, "%s", name); - nasm_assert(ret > 0 && (size_t)ret == len); - } - - cv8_state.symbol_lengths += len + 1; + sym->name = nasm_strdup(name); + cv8_state.symbol_lengths += strlen(sym->name) + 1; if (cv8_state.last_sym && cv8_state.last_sym->section == segment) cv8_state.last_sym->size = offset - cv8_state.last_sym->secrel; From c941a35e5895a5207fb18b07b60a004a217796b6 Mon Sep 17 00:00:00 2001 From: "H. Peter Anvin" Date: Mon, 7 Mar 2016 22:12:19 -0800 Subject: [PATCH 05/12] outelf*: remove null debug functions Instead of duplicating empty functions, use the corresponding null_debug_* functions. Signed-off-by: H. Peter Anvin --- output/outelf32.c | 28 +++++----------------------- output/outelf64.c | 28 +++++----------------------- output/outelfx32.c | 28 +++++----------------------- 3 files changed, 15 insertions(+), 69 deletions(-) diff --git a/output/outelf32.c b/output/outelf32.c index f86106df..3ab8590d 100644 --- a/output/outelf32.c +++ b/output/outelf32.c @@ -1,6 +1,6 @@ /* ----------------------------------------------------------------------- * * - * Copyright 1996-2013 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. * @@ -159,8 +159,6 @@ static struct elf_symbol *lastsym; /* common debugging routines */ static void debug32_typevalue(int32_t); -static void debug32_deflabel(char *, int32_t, int64_t, int, char *); -static void debug32_directive(const char *, const char *); /* stabs debugging routines */ static void stabs32_linenum(const char *filename, int32_t linenumber, int32_t); @@ -1341,8 +1339,8 @@ static struct dfmt df_dwarf = { "dwarf", dwarf32_init, dwarf32_linenum, - debug32_deflabel, - debug32_directive, + null_debug_deflabel, + null_debug_directive, debug32_typevalue, dwarf32_output, dwarf32_cleanup @@ -1352,8 +1350,8 @@ static struct dfmt df_stabs = { "stabs", null_debug_init, stabs32_linenum, - debug32_deflabel, - debug32_directive, + null_debug_deflabel, + null_debug_directive, debug32_typevalue, stabs32_output, stabs32_cleanup @@ -1409,22 +1407,6 @@ static void stabs32_linenum(const char *filename, int32_t linenumber, currentline = linenumber; } -static void debug32_deflabel(char *name, int32_t segment, int64_t offset, int is_global, - char *special) -{ - (void)name; - (void)segment; - (void)offset; - (void)is_global; - (void)special; -} - -static void debug32_directive(const char *directive, const char *params) -{ - (void)directive; - (void)params; -} - static void debug32_typevalue(int32_t type) { int32_t stype, ssize; diff --git a/output/outelf64.c b/output/outelf64.c index 3aee02cb..b6c04d6c 100644 --- a/output/outelf64.c +++ b/output/outelf64.c @@ -1,6 +1,6 @@ /* ----------------------------------------------------------------------- * * - * Copyright 1996-2013 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. * @@ -161,8 +161,6 @@ static struct elf_symbol *lastsym; /* common debugging routines */ static void debug64_typevalue(int32_t); -static void debug64_deflabel(char *, int32_t, int64_t, int, char *); -static void debug64_directive(const char *, const char *); /* stabs debugging routines */ static void stabs64_linenum(const char *filename, int32_t linenumber, int32_t); @@ -1431,8 +1429,8 @@ static struct dfmt df_dwarf = { "dwarf", dwarf64_init, dwarf64_linenum, - debug64_deflabel, - debug64_directive, + null_debug_deflabel, + null_debug_directive, debug64_typevalue, dwarf64_output, dwarf64_cleanup @@ -1442,8 +1440,8 @@ static struct dfmt df_stabs = { "stabs", null_debug_init, stabs64_linenum, - debug64_deflabel, - debug64_directive, + null_debug_deflabel, + null_debug_directive, debug64_typevalue, stabs64_output, stabs64_cleanup @@ -1472,22 +1470,6 @@ struct ofmt of_elf64 = { }; /* common debugging routines */ -static void debug64_deflabel(char *name, int32_t segment, int64_t offset, - int is_global, char *special) -{ - (void)name; - (void)segment; - (void)offset; - (void)is_global; - (void)special; -} - -static void debug64_directive(const char *directive, const char *params) -{ - (void)directive; - (void)params; -} - static void debug64_typevalue(int32_t type) { int32_t stype, ssize; diff --git a/output/outelfx32.c b/output/outelfx32.c index 170c1171..42ab3aa3 100644 --- a/output/outelfx32.c +++ b/output/outelfx32.c @@ -1,6 +1,6 @@ /* ----------------------------------------------------------------------- * * - * Copyright 1996-2013 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. * @@ -160,8 +160,6 @@ static struct elf_symbol *lastsym; /* common debugging routines */ static void debugx32_typevalue(int32_t); -static void debugx32_deflabel(char *, int32_t, int64_t, int, char *); -static void debugx32_directive(const char *, const char *); /* stabs debugging routines */ static void stabsx32_linenum(const char *filename, int32_t linenumber, int32_t); @@ -1390,8 +1388,8 @@ static struct dfmt df_dwarf = { "dwarf", dwarfx32_init, dwarfx32_linenum, - debugx32_deflabel, - debugx32_directive, + null_debug_deflabel, + null_debug_directive, debugx32_typevalue, dwarfx32_output, dwarfx32_cleanup @@ -1401,8 +1399,8 @@ static struct dfmt df_stabs = { "stabs", null_debug_init, stabsx32_linenum, - debugx32_deflabel, - debugx32_directive, + null_debug_deflabel, + null_debug_directive, debugx32_typevalue, stabsx32_output, stabsx32_cleanup @@ -1431,22 +1429,6 @@ struct ofmt of_elfx32 = { }; /* common debugging routines */ -static void debugx32_deflabel(char *name, int32_t segment, int64_t offset, - int is_global, char *special) -{ - (void)name; - (void)segment; - (void)offset; - (void)is_global; - (void)special; -} - -static void debugx32_directive(const char *directive, const char *params) -{ - (void)directive; - (void)params; -} - static void debugx32_typevalue(int32_t type) { int32_t stype, ssize; From 2a74d84d1cf612ab640c62eb1bcd957df1edb716 Mon Sep 17 00:00:00 2001 From: "H. Peter Anvin" Date: Mon, 7 Mar 2016 22:17:10 -0800 Subject: [PATCH 06/12] doc: document fix to the codeview output format Document the label fix; although a global error, it was user-visible in the Codeview backend so document it as such. Signed-off-by: H. Peter Anvin Cc: Jim Kukunas --- doc/changes.src | 3 +++ 1 file changed, 3 insertions(+) diff --git a/doc/changes.src b/doc/changes.src index 62ece40f..26c43b37 100644 --- a/doc/changes.src +++ b/doc/changes.src @@ -14,6 +14,9 @@ since 2007. \b Fix error when not specifying a list file. +\b Correct the handling of macro-local labels in the Codeview + debugging format. + \b Add \c{CLZERO}, \c{MONITORX} and \c{MWAITX} instructions. From 3ab8c5f9c68278fd5a6f75e65dea0a4ba1e850aa Mon Sep 17 00:00:00 2001 From: "H. Peter Anvin" Date: Mon, 7 Mar 2016 22:18:29 -0800 Subject: [PATCH 07/12] NASM 2.12.01rc2 --- version | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/version b/version index e55755c6..53b5e78e 100644 --- a/version +++ b/version @@ -1 +1 @@ -2.12.01rc1 +2.12.01rc2 From 477ae4419cb9ae9f20a2201e60ec4073a9922359 Mon Sep 17 00:00:00 2001 From: "H. Peter Anvin" Date: Mon, 7 Mar 2016 22:53:06 -0800 Subject: [PATCH 08/12] ofmt: get rid of the debuginfo parameter to ofmt->cleanup() Get rid of the completely pointless "debuginfo" parameter to ofmt->cleanup(). Most backends completely ignore it, and the two that care (obj, ieee) can simply test dfmt instead. Also, dfmt is never NULL, so any test for a NULL dfmt is bogus. Signed-off-by: H. Peter Anvin --- nasm.c | 2 +- nasm.h | 2 +- output/outaout.c | 4 +--- output/outas86.c | 4 +--- output/outbin.c | 4 +--- output/outcoff.c | 5 ++--- output/outdbg.c | 3 +-- output/outelf32.c | 18 ++++++------------ output/outelf64.c | 20 +++++++------------- output/outelfx32.c | 20 +++++++------------- output/outieee.c | 10 ++++++---- output/outmacho.c | 4 +--- output/outobj.c | 11 +++++++---- output/outrdf2.c | 4 +--- 14 files changed, 43 insertions(+), 68 deletions(-) diff --git a/nasm.c b/nasm.c index 3c4a1b12..7a699ef6 100644 --- a/nasm.c +++ b/nasm.c @@ -466,7 +466,7 @@ int main(int argc, char **argv) assemble_file(inname, depend_ptr); if (!terminate_after_phase) { - ofmt->cleanup(using_debug_info); + ofmt->cleanup(); cleanup_labels(); fflush(ofile); if (ferror(ofile)) diff --git a/nasm.h b/nasm.h index 16d4ae81..9393e511 100644 --- a/nasm.h +++ b/nasm.h @@ -839,7 +839,7 @@ struct ofmt { * One thing the cleanup routine should always do is to close * the output file pointer. */ - void (*cleanup)(int debuginfo); + void (*cleanup)(void); }; /* diff --git a/output/outaout.c b/output/outaout.c index 66045519..b353600e 100644 --- a/output/outaout.c +++ b/output/outaout.c @@ -211,12 +211,10 @@ static void aoutb_init(void) #endif -static void aout_cleanup(int debuginfo) +static void aout_cleanup(void) { struct Reloc *r; - (void)debuginfo; - aout_pad_sections(); aout_fixup_relocs(&stext); aout_fixup_relocs(&sdata); diff --git a/output/outas86.c b/output/outas86.c index 84e3035c..b69c1d34 100644 --- a/output/outas86.c +++ b/output/outas86.c @@ -138,12 +138,10 @@ static void as86_init(void) as86_add_string(as86_module); } -static void as86_cleanup(int debuginfo) +static void as86_cleanup(void) { struct Piece *p; - (void)debuginfo; - as86_write(); saa_free(stext.data); while (stext.head) { diff --git a/output/outbin.c b/output/outbin.c index 915dc45f..ae07de4f 100644 --- a/output/outbin.c +++ b/output/outbin.c @@ -220,7 +220,7 @@ static struct Section *create_section(char *name) return last_section; } -static void bin_cleanup(int debuginfo) +static void bin_cleanup(void) { struct Section *g, **gp; struct Section *gs = NULL, **gsp; @@ -232,8 +232,6 @@ static void bin_cleanup(int debuginfo) uint64_t pend; int h; - (void)debuginfo; /* placate optimizers */ - #ifdef DEBUG nasm_error(ERR_DEBUG, "bin_cleanup: Sections were initially referenced in this order:\n"); diff --git a/output/outcoff.c b/output/outcoff.c index 935b6540..56d76674 100644 --- a/output/outcoff.c +++ b/output/outcoff.c @@ -223,13 +223,12 @@ static void coff_gen_init(void) def_seg = seg_alloc(); } -static void coff_cleanup(int debuginfo) +static void coff_cleanup(void) { struct coff_Reloc *r; int i; - if (debuginfo && dfmt->cleanup) - dfmt->cleanup(); + dfmt->cleanup(); coff_write(); for (i = 0; i < coff_nsects; i++) { diff --git a/output/outdbg.c b/output/outdbg.c index 83860abd..c68d1990 100644 --- a/output/outdbg.c +++ b/output/outdbg.c @@ -63,9 +63,8 @@ static void dbg_init(void) fprintf(ofile, "NASM Output format debug dump\n"); } -static void dbg_cleanup(int debuginfo) +static void dbg_cleanup(void) { - (void)debuginfo; dfmt->cleanup(); while (dbgsect) { struct Section *tmp = dbgsect; diff --git a/output/outelf32.c b/output/outelf32.c index 3ab8590d..b1596c90 100644 --- a/output/outelf32.c +++ b/output/outelf32.c @@ -217,13 +217,11 @@ static void elf_init(void) def_seg = seg_alloc(); } -static void elf_cleanup(int debuginfo) +static void elf_cleanup(void) { struct elf_reloc *r; int i; - (void)debuginfo; - elf_write(); for (i = 0; i < nsects; i++) { if (sects[i]->type != SHT_NOBITS) @@ -240,9 +238,7 @@ static void elf_cleanup(int debuginfo) saa_free(syms); raa_free(bsym); saa_free(strs); - if (dfmt) { - dfmt->cleanup(); - } + dfmt->cleanup(); } static void add_sectname(char *firsthalf, char *secondhalf) @@ -691,12 +687,10 @@ static void elf_out(int32_t segto, const void *data, } /* again some stabs debugging stuff */ - if (dfmt) { - sinfo.offset = s->len; - sinfo.section = i; - sinfo.name = s->name; - dfmt->debug_output(TY_STABSSYMLIN, &sinfo); - } + sinfo.offset = s->len; + sinfo.section = i; + sinfo.name = s->name; + dfmt->debug_output(TY_STABSSYMLIN, &sinfo); /* end of debugging stuff */ if (s->type == SHT_NOBITS && type != OUT_RESERVE) { diff --git a/output/outelf64.c b/output/outelf64.c index b6c04d6c..878c8e49 100644 --- a/output/outelf64.c +++ b/output/outelf64.c @@ -221,13 +221,11 @@ static void elf_init(void) } -static void elf_cleanup(int debuginfo) +static void elf_cleanup(void) { struct elf_reloc *r; int i; - (void)debuginfo; - elf_write(); for (i = 0; i < nsects; i++) { if (sects[i]->type != SHT_NOBITS) @@ -244,9 +242,7 @@ static void elf_cleanup(int debuginfo) saa_free(syms); raa_free(bsym); saa_free(strs); - if (dfmt) { - dfmt->cleanup(); - } + dfmt->cleanup(); } /* add entry to the elf .shstrtab section */ @@ -707,13 +703,11 @@ static void elf_out(int32_t segto, const void *data, } /* again some stabs debugging stuff */ - if (dfmt) { - sinfo.offset = s->len; - sinfo.section = i; - sinfo.segto = segto; - sinfo.name = s->name; - dfmt->debug_output(TY_DEBUGSYMLIN, &sinfo); - } + sinfo.offset = s->len; + sinfo.section = i; + sinfo.segto = segto; + sinfo.name = s->name; + dfmt->debug_output(TY_DEBUGSYMLIN, &sinfo); /* end of debugging stuff */ if (s->type == SHT_NOBITS && type != OUT_RESERVE) { diff --git a/output/outelfx32.c b/output/outelfx32.c index 42ab3aa3..5af5cfb0 100644 --- a/output/outelfx32.c +++ b/output/outelfx32.c @@ -220,13 +220,11 @@ static void elf_init(void) } -static void elf_cleanup(int debuginfo) +static void elf_cleanup(void) { struct elf_reloc *r; int i; - (void)debuginfo; - elf_write(); for (i = 0; i < nsects; i++) { if (sects[i]->type != SHT_NOBITS) @@ -243,9 +241,7 @@ static void elf_cleanup(int debuginfo) saa_free(syms); raa_free(bsym); saa_free(strs); - if (dfmt) { - dfmt->cleanup(); - } + dfmt->cleanup(); } /* add entry to the elf .shstrtab section */ @@ -706,13 +702,11 @@ static void elf_out(int32_t segto, const void *data, } /* again some stabs debugging stuff */ - if (dfmt) { - sinfo.offset = s->len; - sinfo.section = i; - sinfo.segto = segto; - sinfo.name = s->name; - dfmt->debug_output(TY_DEBUGSYMLIN, &sinfo); - } + sinfo.offset = s->len; + sinfo.section = i; + sinfo.segto = segto; + sinfo.name = s->name; + dfmt->debug_output(TY_DEBUGSYMLIN, &sinfo); /* end of debugging stuff */ if (s->type == SHT_NOBITS && type != OUT_RESERVE) { diff --git a/output/outieee.c b/output/outieee.c index f5f6f5a6..eb4bcf41 100644 --- a/output/outieee.c +++ b/output/outieee.c @@ -185,13 +185,14 @@ static int32_t ieee_entry_seg, ieee_entry_ofs; static int checksum; extern struct ofmt of_ieee; +static struct dfmt ladsoft_debug_form; static void ieee_data_new(struct ieeeSection *); static void ieee_write_fixup(int32_t, int32_t, struct ieeeSection *, int, uint64_t, int32_t); static void ieee_install_fixup(struct ieeeSection *, struct ieeeFixupp *); static int32_t ieee_segment(char *, int, int *); -static void ieee_write_file(int debuginfo); +static void ieee_write_file(void); static void ieee_write_byte(struct ieeeSection *, int); static void ieee_write_word(struct ieeeSection *, int); static void ieee_write_dword(struct ieeeSection *, int32_t); @@ -232,9 +233,9 @@ static int ieee_set_info(enum geninfo type, char **val) /* * Rundown */ -static void ieee_cleanup(int debuginfo) +static void ieee_cleanup(void) { - ieee_write_file(debuginfo); + ieee_write_file(); dfmt->cleanup(); while (seghead) { struct ieeeSection *segtmp = seghead; @@ -899,7 +900,7 @@ static void ieee_filename(char *inname, char *outname) standard_extension(inname, outname, ".o"); } -static void ieee_write_file(int debuginfo) +static void ieee_write_file(void) { struct tm *thetime; time_t reltime; @@ -911,6 +912,7 @@ static void ieee_write_file(int debuginfo) struct ieeeFixupp *fix; struct Array *arr; int i; + const bool debuginfo = (dfmt == &ladsoft_debug_form); /* * Write the module header diff --git a/output/outmacho.c b/output/outmacho.c index b67561c6..26a62ea6 100644 --- a/output/outmacho.c +++ b/output/outmacho.c @@ -1543,14 +1543,12 @@ static void macho_write (void) for the object file, writing, and then freeing all of the data from the file. */ -static void macho_cleanup(int debuginfo) +static void macho_cleanup(void) { struct section *s; struct reloc *r; struct symbol *sym; - (void)debuginfo; - /* Sort all symbols. */ macho_layout_symbols (&nsyms, &strslen); diff --git a/output/outobj.c b/output/outobj.c index fd6c326a..c82b5c26 100644 --- a/output/outobj.c +++ b/output/outobj.c @@ -625,12 +625,13 @@ static struct ExpDef { static int32_t obj_entry_seg, obj_entry_ofs; struct ofmt of_obj; +static struct dfmt borland_debug_form; /* The current segment */ static struct Segment *current_seg; static int32_t obj_segment(char *, int, int *); -static void obj_write_file(int debuginfo); +static void obj_write_file(void); static int obj_directive(enum directives, char *, int); static void obj_init(void) @@ -667,9 +668,10 @@ static int obj_set_info(enum geninfo type, char **val) return 0; } -static void obj_cleanup(int debuginfo) + +static void obj_cleanup(void) { - obj_write_file(debuginfo); + obj_write_file(); dfmt->cleanup(); while (seghead) { struct Segment *segtmp = seghead; @@ -1916,7 +1918,7 @@ static void obj_filename(char *inname, char *outname) standard_extension(inname, outname, ".obj"); } -static void obj_write_file(int debuginfo) +static void obj_write_file(void) { struct Segment *seg, *entry_seg_ptr = 0; struct FileName *fn; @@ -1928,6 +1930,7 @@ static void obj_write_file(int debuginfo) struct ExpDef *export; int lname_idx; ObjRecord *orp; + const bool debuginfo = (dfmt == &borland_debug_form); /* * Write the THEADR module header. diff --git a/output/outrdf2.c b/output/outrdf2.c index e6dcda98..960acb45 100644 --- a/output/outrdf2.c +++ b/output/outrdf2.c @@ -657,14 +657,12 @@ static void rdf2_out(int32_t segto, const void *data, } } -static void rdf2_cleanup(int debuginfo) +static void rdf2_cleanup(void) { int32_t l; struct BSSRec bs; int i; - (void)debuginfo; - /* should write imported & exported symbol declarations to header here */ /* generate the output file... */ From 283b3fb15a91854dcf2f020dcc4fba586d9e0014 Mon Sep 17 00:00:00 2001 From: "H. Peter Anvin" Date: Mon, 7 Mar 2016 23:18:30 -0800 Subject: [PATCH 09/12] Defer debug format search until after command line parsing Avoid funnies with ordering of debug format selection by deferring debug format search until after command line processing. Also permit the -gformat syntax used by many C compilers. Signed-off-by: H. Peter Anvin --- nasm.c | 36 ++++++++++++++++++++++-------------- nasm.txt | 5 ++++- output/outform.c | 2 +- output/outform.h | 2 +- 4 files changed, 28 insertions(+), 17 deletions(-) diff --git a/nasm.c b/nasm.c index 7a699ef6..fc26bba7 100644 --- a/nasm.c +++ b/nasm.c @@ -85,7 +85,9 @@ static void nasm_verror_vc(int severity, const char *fmt, va_list args); static void nasm_verror_common(int severity, const char *fmt, va_list args); static void usage(void); -static int using_debug_info, opt_verbose_info; +static bool using_debug_info, opt_verbose_info; +static const char *debug_format; + bool tasm_compatible_mode = false; int pass0, passn; int globalrel = 0; @@ -356,11 +358,21 @@ int main(int argc, char **argv) return 1; } - /* If debugging info is disabled, suppress any debug calls */ - if (!using_debug_info) + if (!using_debug_info) { + /* No debug info, redirect to the null backend (empty stubs) */ dfmt = &null_debug_form; - else if (!dfmt) + } else if (!debug_format) { + /* Default debug format for this backend */ dfmt = ofmt->default_dfmt; + } else { + dfmt = dfmt_find(ofmt, debug_format); + if (!dfmt) { + nasm_fatal(ERR_NOFILE | ERR_USAGE, + "unrecognized debug format `%s' for" + " output format `%s'", + debug_format, ofmt->shortname); + } + } if (ofmt->stdmac) preproc->extra_stdmac(ofmt->stdmac); @@ -666,7 +678,6 @@ static bool process_arg(char *p, char *q) "unrecognised output format `%s' - " "use -hf for a list", param); } - dfmt = NULL; break; case 'O': /* Optimization level */ @@ -744,14 +755,8 @@ static bool process_arg(char *p, char *q) break; case 'F': /* specify debug format */ - dfmt = dfmt_find(ofmt, param); - if (!dfmt) { - nasm_fatal(ERR_NOFILE | ERR_USAGE, - "unrecognized debug format `%s' for" - " output format `%s'", - param, ofmt->shortname); - } using_debug_info = true; + debug_format = param; break; case 'X': /* specify error reporting format */ @@ -767,6 +772,8 @@ static bool process_arg(char *p, char *q) case 'g': using_debug_info = true; + if (p[2]) + debug_format = nasm_skip_spaces(p + 2); break; case 'h': @@ -775,8 +782,7 @@ static bool process_arg(char *p, char *q) "[-l listfile]\n" " [options...] [--] filename\n" " or nasm -v (or --v) for version info\n\n" - " -t assemble in SciTech TASM compatible mode\n" - " -g generate debug information in selected format\n"); + " -t assemble in SciTech TASM compatible mode\n"); printf (" -E (or -e) preprocess only (writes output to stdout by default)\n" " -a don't preprocess (assemble only)\n" @@ -789,7 +795,9 @@ static bool process_arg(char *p, char *q) " -MP emit phony target\n\n" " -Z redirect error messages to file\n" " -s redirect error messages to stdout\n\n" + " -g generate debugging information\n\n" " -F format select a debugging format\n\n" + " -gformat same as -g -F format\n\n" " -o outfile write output to an outfile\n\n" " -f format select an output format\n\n" " -l listfile write listing to a listfile\n\n" diff --git a/nasm.txt b/nasm.txt index 55f9a05b..a28202f9 100644 --- a/nasm.txt +++ b/nasm.txt @@ -47,7 +47,10 @@ OPTIONS formats, use the *-y* option (for example *-felf -y*). *-g*:: - Causes *nasm* to generate debug information in selected format. + Causes *nasm* to generate debug information. + +*-g*'format':: + Equivalent to **-g -F**__ format__. *-h*:: Causes *nasm* to exit immediately, after giving a summary of its diff --git a/output/outform.c b/output/outform.c index 3d70e2a9..17744bb2 100644 --- a/output/outform.c +++ b/output/outform.c @@ -72,7 +72,7 @@ struct ofmt *ofmt_find(char *name, struct ofmt_alias **ofmt_alias) return NULL; } -struct dfmt *dfmt_find(struct ofmt *ofmt, char *name) +struct dfmt *dfmt_find(struct ofmt *ofmt, const char *name) { struct dfmt **dfp, *df; diff --git a/output/outform.h b/output/outform.h index f52a112a..e34ef752 100644 --- a/output/outform.h +++ b/output/outform.h @@ -371,7 +371,7 @@ static struct ofmt_alias ofmt_aliases[] = { #endif /* BUILD_DRIVERS_ARRAY */ struct ofmt *ofmt_find(char *name, struct ofmt_alias **ofmt_alias); -struct dfmt *dfmt_find(struct ofmt *, char *); +struct dfmt *dfmt_find(struct ofmt *, const char *); void ofmt_list(struct ofmt *, FILE *); void dfmt_list(struct ofmt *ofmt, FILE * fp); extern struct dfmt null_debug_form; From 8da30d0266d97020f297789e68c184c90dd9ba4d Mon Sep 17 00:00:00 2001 From: "H. Peter Anvin" Date: Mon, 7 Mar 2016 23:23:19 -0800 Subject: [PATCH 10/12] Makefiles: run "make alldeps" Automatic update of dependencies. Signed-off-by: H. Peter Anvin --- Makefile.in | 4 ++-- Mkfiles/msvc.mak | 4 ++-- Mkfiles/netware.mak | 6 +++--- Mkfiles/openwcom.mak | 4 ++-- Mkfiles/owlinux.mak | 4 ++-- 5 files changed, 11 insertions(+), 11 deletions(-) diff --git a/Makefile.in b/Makefile.in index f0126fde..4a5b3b08 100644 --- a/Makefile.in +++ b/Makefile.in @@ -356,7 +356,7 @@ listing.$(O): listing.c compiler.h config.h directiv.h insnsi.h listing.h \ macros.$(O): macros.c compiler.h config.h directiv.h hashtbl.h insnsi.h \ nasm.h nasmlib.h opflags.h output/outform.h pptok.h preproc.h regs.h \ tables.h -md5c.$(O): md5c.c md5.h +md5c.$(O): md5c.c compiler.h config.h md5.h nasm.$(O): nasm.c assemble.h compiler.h config.h directiv.h eval.h float.h \ iflag.h iflaggen.h insns.h insnsi.h labels.h listing.h nasm.h nasmlib.h \ opflags.h output/outform.h parser.h pptok.h preproc.h raa.h regs.h saa.h \ @@ -417,7 +417,7 @@ output/outlib.$(O): output/outlib.c compiler.h config.h directiv.h insnsi.h \ tables.h output/outmacho.$(O): output/outmacho.c compiler.h config.h directiv.h \ insnsi.h nasm.h nasmlib.h opflags.h output/outform.h output/outlib.h \ - pptok.h preproc.h raa.h regs.h saa.h tables.h + pptok.h preproc.h raa.h rbtree.h regs.h saa.h tables.h output/outobj.$(O): output/outobj.c compiler.h config.h directiv.h eval.h \ insnsi.h nasm.h nasmlib.h opflags.h output/outform.h output/outlib.h \ pptok.h preproc.h regs.h stdscan.h tables.h diff --git a/Mkfiles/msvc.mak b/Mkfiles/msvc.mak index a2082859..a2775719 100644 --- a/Mkfiles/msvc.mak +++ b/Mkfiles/msvc.mak @@ -265,7 +265,7 @@ listing.$(O): listing.c compiler.h directiv.h insnsi.h listing.h nasm.h \ nasmlib.h opflags.h pptok.h preproc.h regs.h tables.h macros.$(O): macros.c compiler.h directiv.h hashtbl.h insnsi.h nasm.h \ nasmlib.h opflags.h output/outform.h pptok.h preproc.h regs.h tables.h -md5c.$(O): md5c.c md5.h +md5c.$(O): md5c.c compiler.h md5.h nasm.$(O): nasm.c assemble.h compiler.h directiv.h eval.h float.h iflag.h \ iflaggen.h insns.h insnsi.h labels.h listing.h nasm.h nasmlib.h opflags.h \ output/outform.h parser.h pptok.h preproc.h raa.h regs.h saa.h stdscan.h \ @@ -321,7 +321,7 @@ output/outlib.$(O): output/outlib.c compiler.h directiv.h insnsi.h nasm.h \ nasmlib.h opflags.h output/outlib.h pptok.h preproc.h regs.h tables.h output/outmacho.$(O): output/outmacho.c compiler.h directiv.h insnsi.h \ nasm.h nasmlib.h opflags.h output/outform.h output/outlib.h pptok.h \ - preproc.h raa.h regs.h saa.h tables.h + preproc.h raa.h rbtree.h regs.h saa.h tables.h output/outobj.$(O): output/outobj.c compiler.h directiv.h eval.h insnsi.h \ nasm.h nasmlib.h opflags.h output/outform.h output/outlib.h pptok.h \ preproc.h regs.h stdscan.h tables.h diff --git a/Mkfiles/netware.mak b/Mkfiles/netware.mak index 017f1615..c3c8bf64 100644 --- a/Mkfiles/netware.mak +++ b/Mkfiles/netware.mak @@ -173,7 +173,7 @@ listing.o: listing.c compiler.h config.h directiv.h insnsi.h listing.h \ nasm.h nasmlib.h opflags.h pptok.h preproc.h regs.h tables.h macros.o: macros.c compiler.h config.h directiv.h hashtbl.h insnsi.h nasm.h \ nasmlib.h opflags.h outform.h pptok.h preproc.h regs.h tables.h -md5c.o: md5c.c md5.h +md5c.o: md5c.c compiler.h config.h md5.h nasm.o: nasm.c assemble.h compiler.h config.h directiv.h eval.h float.h \ iflag.h iflaggen.h insns.h insnsi.h labels.h listing.h nasm.h nasmlib.h \ opflags.h outform.h parser.h pptok.h preproc.h raa.h regs.h saa.h stdscan.h \ @@ -224,8 +224,8 @@ outieee.o: outieee.c compiler.h config.h directiv.h insnsi.h nasm.h \ outlib.o: outlib.c compiler.h config.h directiv.h insnsi.h nasm.h nasmlib.h \ opflags.h outlib.h pptok.h preproc.h regs.h tables.h outmacho.o: outmacho.c compiler.h config.h directiv.h insnsi.h nasm.h \ - nasmlib.h opflags.h outform.h outlib.h pptok.h preproc.h raa.h regs.h saa.h \ - tables.h + nasmlib.h opflags.h outform.h outlib.h pptok.h preproc.h raa.h rbtree.h \ + regs.h saa.h tables.h outobj.o: outobj.c compiler.h config.h directiv.h eval.h insnsi.h nasm.h \ nasmlib.h opflags.h outform.h outlib.h pptok.h preproc.h regs.h stdscan.h \ tables.h diff --git a/Mkfiles/openwcom.mak b/Mkfiles/openwcom.mak index 2449ae43..7fb9ba51 100644 --- a/Mkfiles/openwcom.mak +++ b/Mkfiles/openwcom.mak @@ -311,7 +311,7 @@ listing.$(O): listing.c compiler.h config.h directiv.h insnsi.h listing.h & macros.$(O): macros.c compiler.h config.h directiv.h hashtbl.h insnsi.h & nasm.h nasmlib.h opflags.h output/outform.h pptok.h preproc.h regs.h & tables.h -md5c.$(O): md5c.c md5.h +md5c.$(O): md5c.c compiler.h config.h md5.h nasm.$(O): nasm.c assemble.h compiler.h config.h directiv.h eval.h float.h & iflag.h iflaggen.h insns.h insnsi.h labels.h listing.h nasm.h nasmlib.h & opflags.h output/outform.h parser.h pptok.h preproc.h raa.h regs.h saa.h & @@ -372,7 +372,7 @@ output/outlib.$(O): output/outlib.c compiler.h config.h directiv.h insnsi.h & tables.h output/outmacho.$(O): output/outmacho.c compiler.h config.h directiv.h & insnsi.h nasm.h nasmlib.h opflags.h output/outform.h output/outlib.h & - pptok.h preproc.h raa.h regs.h saa.h tables.h + pptok.h preproc.h raa.h rbtree.h regs.h saa.h tables.h output/outobj.$(O): output/outobj.c compiler.h config.h directiv.h eval.h & insnsi.h nasm.h nasmlib.h opflags.h output/outform.h output/outlib.h & pptok.h preproc.h regs.h stdscan.h tables.h diff --git a/Mkfiles/owlinux.mak b/Mkfiles/owlinux.mak index c366634e..b6ddad91 100644 --- a/Mkfiles/owlinux.mak +++ b/Mkfiles/owlinux.mak @@ -279,7 +279,7 @@ listing.$(O): listing.c compiler.h directiv.h insnsi.h listing.h nasm.h \ nasmlib.h opflags.h pptok.h preproc.h regs.h tables.h macros.$(O): macros.c compiler.h directiv.h hashtbl.h insnsi.h nasm.h \ nasmlib.h opflags.h output/outform.h pptok.h preproc.h regs.h tables.h -md5c.$(O): md5c.c md5.h +md5c.$(O): md5c.c compiler.h md5.h nasm.$(O): nasm.c assemble.h compiler.h directiv.h eval.h float.h iflag.h \ iflaggen.h insns.h insnsi.h labels.h listing.h nasm.h nasmlib.h opflags.h \ output/outform.h parser.h pptok.h preproc.h raa.h regs.h saa.h stdscan.h \ @@ -335,7 +335,7 @@ output/outlib.$(O): output/outlib.c compiler.h directiv.h insnsi.h nasm.h \ nasmlib.h opflags.h output/outlib.h pptok.h preproc.h regs.h tables.h output/outmacho.$(O): output/outmacho.c compiler.h directiv.h insnsi.h \ nasm.h nasmlib.h opflags.h output/outform.h output/outlib.h pptok.h \ - preproc.h raa.h regs.h saa.h tables.h + preproc.h raa.h rbtree.h regs.h saa.h tables.h output/outobj.$(O): output/outobj.c compiler.h directiv.h eval.h insnsi.h \ nasm.h nasmlib.h opflags.h output/outform.h output/outlib.h pptok.h \ preproc.h regs.h stdscan.h tables.h From 134874848c5a61fbb1c8568dab4f4f00d48325e4 Mon Sep 17 00:00:00 2001 From: "H. Peter Anvin" Date: Mon, 7 Mar 2016 23:58:11 -0800 Subject: [PATCH 11/12] nasmdoc.src: remove unimplemented %comment directive %comment..%endcomment were never implemented, remove from the documentation. Signed-off-by: H. Peter Anvin --- doc/nasmdoc.src | 11 ----------- 1 file changed, 11 deletions(-) diff --git a/doc/nasmdoc.src b/doc/nasmdoc.src index 23a273b3..55be9d97 100644 --- a/doc/nasmdoc.src +++ b/doc/nasmdoc.src @@ -3824,17 +3824,6 @@ variable, for example: \c %defstr C_colon %!'C:' -\H{comment} Comment Blocks: \i\c{%comment} - -The \c{%comment} and \c{%endcomment} directives are used to specify -a block of commented (i.e. unprocessed) code/text. Everything between -\c{%comment} and \c{%endcomment} will be ignored by the preprocessor. - -\c %comment -\c ; some code, text or data to be ignored -\c %endcomment - - \H{stdmac} \i{Standard Macros} NASM defines a set of standard macros, which are already defined From 4bef68a84e1ddd2dad5ec895338bc4920c46a83b Mon Sep 17 00:00:00 2001 From: "H. Peter Anvin" Date: Tue, 8 Mar 2016 00:50:13 -0800 Subject: [PATCH 12/12] msvc.mak: /Ox and /Oy are redundant with /O2 Per the MSVC++ docs, /Ox and /Oy are redundant with /O2, and the docs recommend that they do not be used together. Signed-off-by: H. Peter Anvin --- Mkfiles/msvc.mak | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/Mkfiles/msvc.mak b/Mkfiles/msvc.mak index a2775719..890ad43d 100644 --- a/Mkfiles/msvc.mak +++ b/Mkfiles/msvc.mak @@ -5,6 +5,9 @@ # # Make sure to put the appropriate directories in your PATH, in # the case of MSVC++ 2005, they are ...\VC\bin and ...\Common7\IDE. +# +# This is typically done by opening the Visual Studio Command Prompt. +# top_srcdir = . srcdir = . @@ -18,7 +21,7 @@ mandir = $(prefix)/man CFLAGS = /Od /Zi LDFLAGS = /DEBUG !ELSE -CFLAGS = /O2 /Ox /Oy +CFLAGS = /O2 !ENDIF CC = cl