0
0
mirror of https://github.com/netwide-assembler/nasm.git synced 2025-09-22 10:43:39 -04:00

codeview: use nasm_realpath() to find the canonical name of the outfile

Concatenating the cwd with the name of the output file is incorrect
for filenames which are specified as absolute.  We already have
nasm_realpath() for this purpose, use it.

Cc: Jim Kukunas <james.t.kukunas@intel.com>
Signed-off-by: H. Peter Anvin <hpa@linux.intel.com>
This commit is contained in:
H. Peter Anvin
2016-05-24 23:34:32 -07:00
parent 8794350751
commit 0183894895

View File

@@ -154,7 +154,10 @@ struct cv8_state {
unsigned symbol_lengths; unsigned symbol_lengths;
unsigned total_syms; unsigned total_syms;
char *cwd; struct {
char *name;
size_t namebytes;
} outfile;
}; };
struct cv8_state cv8_state; struct cv8_state cv8_state;
@@ -181,8 +184,6 @@ static void cv8_init(void)
cv8_state.symbols = saa_init(sizeof(struct cv8_symbol)); cv8_state.symbols = saa_init(sizeof(struct cv8_symbol));
cv8_state.last_sym = NULL; cv8_state.last_sym = NULL;
cv8_state.cwd = nasm_realpath(".");
} }
static struct source_file *register_file(const char *filename); static struct source_file *register_file(const char *filename);
@@ -308,6 +309,9 @@ static void cv8_cleanup(void)
struct coff_Section *symbol_sect = coff_sects[cv8_state.symbol_sect]; struct coff_Section *symbol_sect = coff_sects[cv8_state.symbol_sect];
struct coff_Section *type_sect = coff_sects[cv8_state.type_sect]; struct coff_Section *type_sect = coff_sects[cv8_state.type_sect];
cv8_state.outfile.name = nasm_realpath(coff_outfile);
cv8_state.outfile.namebytes = strlen(cv8_state.outfile.name) + 1;
build_symbol_table(symbol_sect); build_symbol_table(symbol_sect);
build_type_table(type_sect); build_type_table(type_sect);
@@ -318,13 +322,12 @@ static void cv8_cleanup(void)
} }
hash_free(&cv8_state.file_hash); hash_free(&cv8_state.file_hash);
if (cv8_state.cwd != NULL)
nasm_free(cv8_state.cwd);
saa_rewind(cv8_state.symbols); saa_rewind(cv8_state.symbols);
while ((sym = saa_rstruct(cv8_state.symbols))) while ((sym = saa_rstruct(cv8_state.symbols)))
nasm_free(sym->name); nasm_free(sym->name);
saa_free(cv8_state.symbols); saa_free(cv8_state.symbols);
nasm_free(cv8_state.outfile.name);
} }
/******************************************************************************* /*******************************************************************************
@@ -604,19 +607,16 @@ static void write_linenumber_table(struct coff_Section *const sect)
} }
} }
static uint16_t write_symbolinfo_obj(struct coff_Section *sect, static uint16_t write_symbolinfo_obj(struct coff_Section *sect)
const char sep)
{ {
uint16_t obj_len; uint16_t obj_len;
obj_len = 2 + 4 + strlen(cv8_state.cwd)+ 1 + strlen(coff_outfile) +1; obj_len = 2 + 4 + cv8_state.outfile.namebytes;
section_write16(sect, obj_len); section_write16(sect, obj_len);
section_write16(sect, 0x1101); section_write16(sect, 0x1101);
section_write32(sect, 0); /* ASM language */ section_write32(sect, 0); /* ASM language */
section_wbytes(sect, cv8_state.cwd, strlen(cv8_state.cwd)); section_wbytes(sect, cv8_state.outfile.name, cv8_state.outfile.namebytes);
section_write8(sect, sep);
section_wbytes(sect, coff_outfile, strlen(coff_outfile)+1);
return obj_len; return obj_len;
} }
@@ -704,15 +704,14 @@ static uint16_t write_symbolinfo_symbols(struct coff_Section *sect)
static void write_symbolinfo_table(struct coff_Section *const sect) static void write_symbolinfo_table(struct coff_Section *const sect)
{ {
const char sep = '\\'; static const char creator_str[] = "The Netwide Assembler " NASM_VER;
const char *creator_str = "The Netwide Assembler " NASM_VER;
uint16_t obj_length, creator_length, sym_length; uint16_t obj_length, creator_length, sym_length;
uint32_t field_length = 0, out_len; uint32_t field_length = 0, out_len;
/* signature, language, workingdir / coff_outfile NULL */ nasm_assert(cv8_state.outfile.namebytes);
obj_length = 2 + 4 + strlen(cv8_state.cwd)+ 1 + strlen(coff_outfile) +1;
/* signature, language, outfile NULL */
obj_length = 2 + 4 + cv8_state.outfile.namebytes;
creator_length = 2 + 4 + 4 + 4 + 4 + strlen(creator_str)+1 + 2; creator_length = 2 + 4 + 4 + 4 + 4 + strlen(creator_str)+1 + 2;
sym_length = ( cv8_state.num_syms[SYMTYPE_CODE] * 7) + sym_length = ( cv8_state.num_syms[SYMTYPE_CODE] * 7) +
@@ -730,7 +729,7 @@ static void write_symbolinfo_table(struct coff_Section *const sect)
/* for sub fields, length preceeds type */ /* for sub fields, length preceeds type */
out_len = write_symbolinfo_obj(sect, sep); out_len = write_symbolinfo_obj(sect);
nasm_assert(out_len == obj_length); nasm_assert(out_len == obj_length);
out_len = write_symbolinfo_properties(sect, creator_str); out_len = write_symbolinfo_properties(sect, creator_str);
@@ -799,5 +798,3 @@ static void build_type_table(struct coff_Section *const sect)
section_write32(sect, 0); /*num params */ section_write32(sect, 0); /*num params */
} }
} }