From: Peter Johnson Date: Wed, 1 Feb 2006 07:01:47 +0000 (-0000) Subject: Implement DWARF2 .file "foo.c" (sans file number) so that it actually sets X-Git-Tag: v0.5.0rc1~24 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=f7665e25c5512076ed1bbd4307436faed0205f77;p=yasm Implement DWARF2 .file "foo.c" (sans file number) so that it actually sets the source filename stored in the object file (as GAS does). The internals of this move the source and object filename data into the yasm_object structure and simplify the dbgfmt and objfmt interfaces to remove this information from function parameters. * section.c (yasm_object_create): Add src_filename and obj_filename params. (yasm_object_set_source_fn, yasm_object_get_source_fn) (yasm_object_get_object_fn): New. * section.h: Prototype. * objfmt.h (yasm_objfmt_create): Remove in_filename param. (yasm_objfmt_output): Remove obj_filename param. * bin-objfmt.c, dbg-objfmt.c, coff-objfmt.c, xdf-objfmt.c: Update. * elf-objfmt.c: Update. * elf.c (elf_strtab_entry_set_str): New ELF support function. * elf.h (elf_strtab_entry_set_str): Prototype. * dbgfmt.h (yasm_dbgfmt_create): Remove in_filename and obj_filename params. * null-dbgfmt.c, stabs-dbgfmt.c, dwarf2-dbgfmt.c: Update. * dwarf2-dbgfmt.c (dwarf2_dbgfmt_directive): Implement .file "foo.c". * yasm.c (main): Update to match yasm_object, objfmt and dbgfmt changes. svn path=/trunk/yasm/; revision=1356 --- diff --git a/frontends/yasm/yasm.c b/frontends/yasm/yasm.c index b212910a..f943b2d6 100644 --- a/frontends/yasm/yasm.c +++ b/frontends/yasm/yasm.c @@ -406,8 +406,20 @@ main(int argc, char *argv[]) return EXIT_SUCCESS; } + /* determine the object filename if not specified */ + if (!obj_filename) { + if (in == stdin) + /* Default to yasm.out if no obj filename specified */ + obj_filename = yasm__xstrdup("yasm.out"); + else + /* replace (or add) extension */ + obj_filename = replace_extension(in_filename, + cur_objfmt_module->extension, + "yasm.out"); + } + /* Create object */ - object = yasm_object_create(); + object = yasm_object_create(in_filename, obj_filename); yasm_linemap_set(yasm_object_get_linemap(object), in_filename, 1, 1); /* Default to x86 as the architecture */ @@ -525,21 +537,8 @@ main(int argc, char *argv[]) return EXIT_FAILURE; } - /* determine the object filename if not specified */ - if (!obj_filename) { - if (in == stdin) - /* Default to yasm.out if no obj filename specified */ - obj_filename = yasm__xstrdup("yasm.out"); - else - /* replace (or add) extension */ - obj_filename = replace_extension(in_filename, - cur_objfmt_module->extension, - "yasm.out"); - } - /* Initialize the object format */ - cur_objfmt = yasm_objfmt_create(cur_objfmt_module, in_filename, object, - cur_arch); + cur_objfmt = yasm_objfmt_create(cur_objfmt_module, object, cur_arch); if (!cur_objfmt) { print_error( _("%s: object format `%s' does not support architecture `%s' machine `%s'"), @@ -557,8 +556,7 @@ main(int argc, char *argv[]) def_sect = yasm_objfmt_add_default_section(cur_objfmt, object); /* Initialize the debug format */ - cur_dbgfmt = yasm_dbgfmt_create(cur_dbgfmt_module, in_filename, - obj_filename, object, cur_objfmt, + cur_dbgfmt = yasm_dbgfmt_create(cur_dbgfmt_module, object, cur_objfmt, cur_arch); if (!cur_dbgfmt) { print_error( diff --git a/libyasm/dbgfmt.h b/libyasm/dbgfmt.h index c355a8b6..323b538a 100644 --- a/libyasm/dbgfmt.h +++ b/libyasm/dbgfmt.h @@ -55,16 +55,13 @@ typedef struct yasm_dbgfmt_module { /** Create debug format. * Module-level implementation of yasm_dbgfmt_create(). * The filenames are provided solely for informational purposes. - * \param in_filename primary input filename - * \param obj_filename object filename * \param object object * \param of object format in use * \param a architecture in use * \return NULL if object format does not provide needed support. */ /*@null@*/ /*@only@*/ yasm_dbgfmt * (*create) - (const char *in_filename, const char *obj_filename, - yasm_object *object, yasm_objfmt *of, yasm_arch *a); + (yasm_object *object, yasm_objfmt *of, yasm_arch *a); /** Module-level implementation of yasm_dbgfmt_destroy(). * Call yasm_dbgfmt_destroy() instead of calling this function. @@ -94,16 +91,13 @@ const char *yasm_dbgfmt_keyword(const yasm_dbgfmt *dbgfmt); * format functions. The filenames are provided solely for informational * purposes. * \param module debug format module - * \param in_filename primary input filename - * \param obj_filename object filename * \param object object to generate debugging information for * \param of object format in use * \param a architecture in use * \return NULL if object format does not provide needed support. */ /*@null@*/ /*@only@*/ yasm_dbgfmt *yasm_dbgfmt_create - (const yasm_dbgfmt_module *module, const char *in_filename, - const char *obj_filename, yasm_object *object, yasm_objfmt *of, + (const yasm_dbgfmt_module *module, yasm_object *object, yasm_objfmt *of, yasm_arch *a); /** Cleans up any allocated debug format memory. @@ -136,8 +130,8 @@ void yasm_dbgfmt_generate(yasm_dbgfmt *dbgfmt); #define yasm_dbgfmt_keyword(dbgfmt) \ (((yasm_dbgfmt_base *)dbgfmt)->module->keyword) -#define yasm_dbgfmt_create(module, in_filename, obj_filename, object, of, a) \ - module->create(in_filename, obj_filename, object, of, a) +#define yasm_dbgfmt_create(module, object, of, a) \ + module->create(object, of, a) #define yasm_dbgfmt_destroy(dbgfmt) \ ((yasm_dbgfmt_base *)dbgfmt)->module->destroy(dbgfmt) diff --git a/libyasm/objfmt.h b/libyasm/objfmt.h index 0bdd6483..b988197d 100644 --- a/libyasm/objfmt.h +++ b/libyasm/objfmt.h @@ -80,19 +80,17 @@ typedef struct yasm_objfmt_module { /** Create object format. * Module-level implementation of yasm_objfmt_create(). * Call yasm_objfmt_create() instead of calling this function. - * \param in_filename main input filename (e.g. "file.asm") * \param object object * \param a architecture in use * \return NULL if architecture/machine combination not supported. */ - /*@null@*/ /*@only@*/ yasm_objfmt * (*create) - (const char *in_filename, yasm_object *object, yasm_arch *a); + /*@null@*/ /*@only@*/ yasm_objfmt * (*create) (yasm_object *object, + yasm_arch *a); /** Module-level implementation of yasm_objfmt_output(). * Call yasm_objfmt_output() instead of calling this function. */ - void (*output) (yasm_objfmt *of, FILE *f, const char *obj_filename, - int all_syms, yasm_dbgfmt *df); + void (*output) (yasm_objfmt *of, FILE *f, int all_syms, yasm_dbgfmt *df); /** Module-level implementation of yasm_objfmt_destroy(). * Call yasm_objfmt_destroy() instead of calling this function. @@ -139,27 +137,24 @@ typedef struct yasm_objfmt_module { /** Create object format. * \param module object format module - * \param in_filename main input filename (e.g. "file.asm") * \param object object * \param a architecture in use * \return NULL if architecture/machine combination not supported. */ /*@null@*/ /*@only@*/ yasm_objfmt *yasm_objfmt_create - (const yasm_objfmt_module *module, const char *in_filename, - yasm_object *object, yasm_arch *a); + (const yasm_objfmt_module *module, yasm_object *object, yasm_arch *a); /** Write out (post-optimized) sections to the object file. * This function may call yasm_symrec_* functions as necessary (including * yasm_symrec_traverse()) to retrieve symbolic information. * \param objfmt object format * \param f output object file - * \param obj_filename output filename (e.g. "file.o") * \param all_syms if nonzero, all symbols should be included in * the object file * \param df debug format in use */ -void yasm_objfmt_output(yasm_objfmt *objfmt, FILE *f, const char *obj_filename, - int all_syms, yasm_dbgfmt *df); +void yasm_objfmt_output(yasm_objfmt *objfmt, FILE *f, int all_syms, + yasm_dbgfmt *df); /** Cleans up any allocated object format memory. * \param objfmt object format @@ -235,12 +230,10 @@ int yasm_objfmt_directive(yasm_objfmt *objfmt, const char *name, /* Inline macro implementations for objfmt functions */ -#define yasm_objfmt_create(module, in_filename, object, a) \ - module->create(in_filename, object, a) +#define yasm_objfmt_create(module, object, a) module->create(object, a) #define yasm_objfmt_output(objfmt, f, obj_fn, all_syms, df) \ - ((yasm_objfmt_base *)objfmt)->module->output(objfmt, f, obj_fn, all_syms, \ - df) + ((yasm_objfmt_base *)objfmt)->module->output(objfmt, f, all_syms, df) #define yasm_objfmt_destroy(objfmt) \ ((yasm_objfmt_base *)objfmt)->module->destroy(objfmt) #define yasm_objfmt_section_switch(objfmt, vpms, oe_vpms, line) \ diff --git a/libyasm/section.c b/libyasm/section.c index 89a4bc3a..4a7283af 100644 --- a/libyasm/section.c +++ b/libyasm/section.c @@ -46,6 +46,9 @@ struct yasm_object { + /*@owned@*/ char *src_filename; + /*@owned@*/ char *obj_filename; + yasm_symtab *symtab; yasm_linemap *linemap; @@ -92,10 +95,13 @@ static void yasm_section_destroy(/*@only@*/ yasm_section *sect); /*@-compdestroy@*/ yasm_object * -yasm_object_create(void) +yasm_object_create(const char *src_filename, const char *obj_filename) { yasm_object *object = yasm_xmalloc(sizeof(yasm_object)); + object->src_filename = yasm__xstrdup(src_filename); + object->obj_filename = yasm__xstrdup(obj_filename); + /* Create empty symtab and linemap */ object->symtab = yasm_symtab_create(); object->linemap = yasm_linemap_create(); @@ -198,6 +204,25 @@ yasm_object_create_absolute(yasm_object *object, yasm_expr *start, } /*@=onlytrans@*/ +void +yasm_object_set_source_fn(yasm_object *object, const char *src_filename) +{ + yasm_xfree(object->src_filename); + object->src_filename = yasm__xstrdup(src_filename); +} + +const char * +yasm_object_get_source_fn(const yasm_object *object) +{ + return object->src_filename; +} + +const char * +yasm_object_get_object_fn(const yasm_object *object) +{ + return object->obj_filename; +} + yasm_symtab * yasm_object_get_symtab(const yasm_object *object) { diff --git a/libyasm/section.h b/libyasm/section.h index c4132186..c48fae40 100644 --- a/libyasm/section.h +++ b/libyasm/section.h @@ -50,9 +50,12 @@ struct yasm_reloc { /** Create a new object. A default section is created as the first section. * An empty symbol table (yasm_symtab) and line mapping (yasm_linemap) are * automatically created. + * \param src_filename source filename (e.g. "file.asm") + * \param obj_filename object filename (e.g. "file.o") * \return Newly allocated object. */ -/*@only@*/ yasm_object *yasm_object_create(void); +/*@only@*/ yasm_object *yasm_object_create(const char *src_filename, + const char *obj_filename); /** Create a new, or continue an existing, general section. The section is * added to the object if there's not already a section by that name. @@ -122,6 +125,24 @@ int yasm_object_sections_traverse /*@dependent@*/ /*@null@*/ yasm_section *yasm_object_find_general (yasm_object *object, const char *name); +/** Change the source filename for an object. + * \param object object + * \param src_filename new source filename (e.g. "file.asm") + */ +void yasm_object_set_source_fn(yasm_object *object, const char *src_filename); + +/** Get an object's source filename. + * \param object object + * \return Source filename. + */ +const char *yasm_object_get_source_fn(const yasm_object *object); + +/** Get an object's object filename. + * \param object object + * \return Object filename. + */ +const char *yasm_object_get_object_fn(const yasm_object *object); + /** Get an object's symbol table (#yasm_symtab). * \param object object * \return Symbol table. diff --git a/modules/dbgfmts/dwarf2/dwarf2-dbgfmt.c b/modules/dbgfmts/dwarf2/dwarf2-dbgfmt.c index 2b7c86a1..a5fc92d3 100644 --- a/modules/dbgfmts/dwarf2/dwarf2-dbgfmt.c +++ b/modules/dbgfmts/dwarf2/dwarf2-dbgfmt.c @@ -105,7 +105,6 @@ typedef struct yasm_dbgfmt_dwarf2 { yasm_object *object; yasm_symtab *symtab; - const char *filename; yasm_linemap *linemap; yasm_arch *arch; @@ -234,8 +233,7 @@ yasm_dbgfmt_module yasm_dwarf2_LTX_dbgfmt; static /*@null@*/ /*@only@*/ yasm_dbgfmt * -dwarf2_dbgfmt_create(const char *in_filename, const char *obj_filename, - yasm_object *object, yasm_objfmt *of, yasm_arch *a) +dwarf2_dbgfmt_create(yasm_object *object, yasm_objfmt *of, yasm_arch *a) { yasm_dbgfmt_dwarf2 *dbgfmt_dwarf2 = yasm_xmalloc(sizeof(yasm_dbgfmt_dwarf2)); @@ -243,7 +241,6 @@ dwarf2_dbgfmt_create(const char *in_filename, const char *obj_filename, dbgfmt_dwarf2->dbgfmt.module = &yasm_dwarf2_LTX_dbgfmt; - dbgfmt_dwarf2->filename = in_filename; dbgfmt_dwarf2->object = object; dbgfmt_dwarf2->symtab = yasm_object_get_symtab(object); dbgfmt_dwarf2->linemap = yasm_object_get_linemap(object); @@ -927,7 +924,7 @@ dwarf2_dbgfmt_directive(yasm_dbgfmt *dbgfmt, const char *name, if (vp->val) { /* Just a bare filename */ - /* TODO: this should change the in_filename the objfmt uses */ + yasm_object_set_source_fn(dbgfmt_dwarf2->object, vp->val); return 0; } diff --git a/modules/dbgfmts/dwarf2/tests/pass32/dwarf32_testhd.hex b/modules/dbgfmts/dwarf2/tests/pass32/dwarf32_testhd.hex index b7fdd349..edaf1bcb 100644 --- a/modules/dbgfmts/dwarf2/tests/pass32/dwarf32_testhd.hex +++ b/modules/dbgfmts/dwarf2/tests/pass32/dwarf32_testhd.hex @@ -3027,7 +3027,15 @@ e7 62 00 00 -2d +74 +65 +73 +74 +5f +68 +64 +2e +63 00 6d 61 @@ -5166,14 +5174,6 @@ e7 00 00 00 -00 -00 -00 -00 -00 -00 -00 -00 ee 00 00 @@ -5234,7 +5234,7 @@ d4 0b 00 00 -61 +69 02 00 00 @@ -5270,7 +5270,7 @@ e6 00 00 00 -38 +40 0e 00 00 diff --git a/modules/dbgfmts/dwarf2/tests/pass64/dwarf64_leb128.hex b/modules/dbgfmts/dwarf2/tests/pass64/dwarf64_leb128.hex index 8890ea32..5733368b 100644 --- a/modules/dbgfmts/dwarf2/tests/pass64/dwarf64_leb128.hex +++ b/modules/dbgfmts/dwarf2/tests/pass64/dwarf64_leb128.hex @@ -38,7 +38,7 @@ 00 00 00 -e0 +f0 5c 01 00 @@ -48839,7 +48839,19 @@ a7 00 00 00 -2d +6c +65 +62 +31 +32 +38 +5f +74 +65 +73 +74 +2e +63 00 74 65 @@ -89374,6 +89386,10 @@ f5 00 00 00 +00 +00 +00 +00 70 01 00 @@ -89470,7 +89486,7 @@ be 00 00 00 -0c +18 28 00 00 @@ -89526,7 +89542,7 @@ be 00 00 00 -d4 +e0 e6 00 00 diff --git a/modules/dbgfmts/dwarf2/tests/passwin64/dwarfwin64_testhd.hex b/modules/dbgfmts/dwarf2/tests/passwin64/dwarfwin64_testhd.hex index aaf7f730..8c76e4c5 100644 --- a/modules/dbgfmts/dwarf2/tests/passwin64/dwarfwin64_testhd.hex +++ b/modules/dbgfmts/dwarf2/tests/passwin64/dwarfwin64_testhd.hex @@ -4391,15 +4391,15 @@ ff 00 67 01 -2d -00 -00 -00 -00 -00 -00 -00 -00 +74 +65 +73 +74 +5f +68 +64 +2e +63 00 00 00 diff --git a/modules/dbgfmts/null/null-dbgfmt.c b/modules/dbgfmts/null/null-dbgfmt.c index 04fbf75d..e5c9e4c0 100644 --- a/modules/dbgfmts/null/null-dbgfmt.c +++ b/modules/dbgfmts/null/null-dbgfmt.c @@ -35,8 +35,7 @@ yasm_dbgfmt_module yasm_null_LTX_dbgfmt; static /*@null@*/ /*@only@*/ yasm_dbgfmt * -null_dbgfmt_create(const char *in_filename, const char *obj_filename, - yasm_object *object, yasm_objfmt *of, yasm_arch *a) +null_dbgfmt_create(yasm_object *object, yasm_objfmt *of, yasm_arch *a) { yasm_dbgfmt_base *dbgfmt = yasm_xmalloc(sizeof(yasm_dbgfmt_base)); dbgfmt->module = &yasm_null_LTX_dbgfmt; diff --git a/modules/dbgfmts/stabs/stabs-dbgfmt.c b/modules/dbgfmts/stabs/stabs-dbgfmt.c index 75939fb9..c59b9df4 100644 --- a/modules/dbgfmts/stabs/stabs-dbgfmt.c +++ b/modules/dbgfmts/stabs/stabs-dbgfmt.c @@ -85,7 +85,6 @@ typedef struct yasm_dbgfmt_stabs { yasm_object *object; yasm_symtab *symtab; - const char *filename; yasm_linemap *linemap; yasm_arch *arch; } yasm_dbgfmt_stabs; @@ -161,12 +160,10 @@ yasm_dbgfmt_module yasm_stabs_LTX_dbgfmt; static /*@null@*/ /*@only@*/ yasm_dbgfmt * -stabs_dbgfmt_create(const char *in_filename, const char *obj_filename, - yasm_object *object, yasm_objfmt *of, yasm_arch *a) +stabs_dbgfmt_create(yasm_object *object, yasm_objfmt *of, yasm_arch *a) { yasm_dbgfmt_stabs *dbgfmt_stabs = yasm_xmalloc(sizeof(yasm_dbgfmt_stabs)); dbgfmt_stabs->dbgfmt.module = &yasm_stabs_LTX_dbgfmt; - dbgfmt_stabs->filename = in_filename; dbgfmt_stabs->object = object; dbgfmt_stabs->symtab = yasm_object_get_symtab(object); dbgfmt_stabs->linemap = yasm_object_get_linemap(object); @@ -370,7 +367,8 @@ stabs_dbgfmt_generate(yasm_dbgfmt *dbgfmt) /* initial strtab bytecodes */ nullbc = stabs_dbgfmt_append_bcstr(info.stabstr, ""); - filebc = stabs_dbgfmt_append_bcstr(info.stabstr, dbgfmt_stabs->filename); + filebc = stabs_dbgfmt_append_bcstr(info.stabstr, + yasm_object_get_source_fn(dbgfmt_stabs->object)); stext = yasm_object_find_general(dbgfmt_stabs->object, ".text"); firstsym = yasm_symtab_use(dbgfmt_stabs->symtab, ".text", 0); diff --git a/modules/objfmts/bin/bin-objfmt.c b/modules/objfmts/bin/bin-objfmt.c index ed57b67f..645ff8f7 100644 --- a/modules/objfmts/bin/bin-objfmt.c +++ b/modules/objfmts/bin/bin-objfmt.c @@ -47,8 +47,7 @@ yasm_objfmt_module yasm_bin_LTX_objfmt; static yasm_objfmt * -bin_objfmt_create(/*@unused@*/ const char *in_filename, yasm_object *object, - yasm_arch *a) +bin_objfmt_create(yasm_object *object, yasm_arch *a) { yasm_objfmt_bin *objfmt_bin = yasm_xmalloc(sizeof(yasm_objfmt_bin)); objfmt_bin->objfmt.module = &yasm_bin_LTX_objfmt; @@ -240,8 +239,8 @@ bin_objfmt_output_bytecode(yasm_bytecode *bc, /*@null@*/ void *d) } static void -bin_objfmt_output(yasm_objfmt *objfmt, FILE *f, const char *obj_filename, - /*@unused@*/ int all_syms, /*@unused@*/ yasm_dbgfmt *df) +bin_objfmt_output(yasm_objfmt *objfmt, FILE *f, /*@unused@*/ int all_syms, + /*@unused@*/ yasm_dbgfmt *df) { yasm_objfmt_bin *objfmt_bin = (yasm_objfmt_bin *)objfmt; /*@observer@*/ /*@null@*/ yasm_section *text, *data, *bss, *prevsect; diff --git a/modules/objfmts/coff/coff-objfmt.c b/modules/objfmts/coff/coff-objfmt.c index fb866aed..0ef6b323 100644 --- a/modules/objfmts/coff/coff-objfmt.c +++ b/modules/objfmts/coff/coff-objfmt.c @@ -182,6 +182,8 @@ typedef struct yasm_objfmt_coff { yasm_object *object; yasm_symtab *symtab; /*@dependent@*/ yasm_arch *arch; + + coff_symrec_data *filesym_data; /* Data for .file symbol */ } yasm_objfmt_coff; typedef struct coff_objfmt_output_info { @@ -239,11 +241,10 @@ coff_objfmt_sym_set_data(yasm_symrec *sym, coff_symrec_sclass sclass, } static yasm_objfmt_coff * -coff_common_create(const char *in_filename, yasm_object *object, yasm_arch *a) +coff_common_create(yasm_object *object, yasm_arch *a) { yasm_objfmt_coff *objfmt_coff = yasm_xmalloc(sizeof(yasm_objfmt_coff)); yasm_symrec *filesym; - coff_symrec_data *data; objfmt_coff->object = object; objfmt_coff->symtab = yasm_object_get_symtab(object); @@ -260,18 +261,19 @@ coff_common_create(const char *in_filename, yasm_object *object, yasm_arch *a) /* FIXME: misuse of NULL bytecode here; it works, but only barely. */ filesym = yasm_symtab_define_special(objfmt_coff->symtab, ".file", YASM_SYM_GLOBAL); - data = coff_objfmt_sym_set_data(filesym, COFF_SCL_FILE, NULL, 1, - COFF_SYMTAB_AUX_FILE); - data->aux[0].fname = yasm__xstrdup(in_filename); + objfmt_coff->filesym_data = + coff_objfmt_sym_set_data(filesym, COFF_SCL_FILE, NULL, 1, + COFF_SYMTAB_AUX_FILE); + /* Filename is set in coff_objfmt_output */ + objfmt_coff->filesym_data->aux[0].fname = NULL; return objfmt_coff; } static yasm_objfmt * -coff_objfmt_create(const char *in_filename, yasm_object *object, yasm_arch *a) +coff_objfmt_create(yasm_object *object, yasm_arch *a) { - yasm_objfmt_coff *objfmt_coff = - coff_common_create(in_filename, object, a); + yasm_objfmt_coff *objfmt_coff = coff_common_create(object, a); if (objfmt_coff) { /* Support x86 and amd64 machines of x86 arch */ @@ -292,10 +294,9 @@ coff_objfmt_create(const char *in_filename, yasm_object *object, yasm_arch *a) } static yasm_objfmt * -win32_objfmt_create(const char *in_filename, yasm_object *object, yasm_arch *a) +win32_objfmt_create(yasm_object *object, yasm_arch *a) { - yasm_objfmt_coff *objfmt_coff = - coff_common_create(in_filename, object, a); + yasm_objfmt_coff *objfmt_coff = coff_common_create(object, a); if (objfmt_coff) { /* Support x86 and amd64 machines of x86 arch. @@ -319,10 +320,9 @@ win32_objfmt_create(const char *in_filename, yasm_object *object, yasm_arch *a) } static yasm_objfmt * -win64_objfmt_create(const char *in_filename, yasm_object *object, yasm_arch *a) +win64_objfmt_create(yasm_object *object, yasm_arch *a) { - yasm_objfmt_coff *objfmt_coff = - coff_common_create(in_filename, object, a); + yasm_objfmt_coff *objfmt_coff = coff_common_create(object, a); if (objfmt_coff) { /* Support amd64 machine of x86 arch */ @@ -946,8 +946,8 @@ coff_objfmt_output_str(yasm_symrec *sym, /*@null@*/ void *d) } static void -coff_objfmt_output(yasm_objfmt *objfmt, FILE *f, const char *obj_filename, - int all_syms, /*@unused@*/ yasm_dbgfmt *df) +coff_objfmt_output(yasm_objfmt *objfmt, FILE *f, int all_syms, + /*@unused@*/ yasm_dbgfmt *df) { yasm_objfmt_coff *objfmt_coff = (yasm_objfmt_coff *)objfmt; coff_objfmt_output_info info; @@ -957,6 +957,11 @@ coff_objfmt_output(yasm_objfmt *objfmt, FILE *f, const char *obj_filename, unsigned long symtab_count; unsigned int flags; + if (objfmt_coff->filesym_data->aux[0].fname) + yasm_xfree(objfmt_coff->filesym_data->aux[0].fname); + objfmt_coff->filesym_data->aux[0].fname = + yasm__xstrdup(yasm_object_get_source_fn(objfmt_coff->object)); + /* Force all syms for win64 because they're needed for relocations. * FIXME: Not *all* syms need to be output, only the ones needed for * relocation. Find a way to do that someday. diff --git a/modules/objfmts/dbg/dbg-objfmt.c b/modules/objfmts/dbg/dbg-objfmt.c index 2b8b83a5..dee20188 100644 --- a/modules/objfmts/dbg/dbg-objfmt.c +++ b/modules/objfmts/dbg/dbg-objfmt.c @@ -43,8 +43,7 @@ yasm_objfmt_module yasm_dbg_LTX_objfmt; static yasm_objfmt * -dbg_objfmt_create(const char *in_filename, yasm_object *object, - yasm_arch *a) +dbg_objfmt_create(yasm_object *object, yasm_arch *a) { yasm_objfmt_dbg *objfmt_dbg = yasm_xmalloc(sizeof(yasm_objfmt_dbg)); @@ -57,14 +56,12 @@ dbg_objfmt_create(const char *in_filename, yasm_object *object, fprintf(stderr, N_("could not open temporary file")); return 0; } - fprintf(objfmt_dbg->dbgfile, "create(\"%s\", %s arch)\n", - in_filename, yasm_arch_keyword(a)); + fprintf(objfmt_dbg->dbgfile, "create(%s arch)\n", yasm_arch_keyword(a)); return (yasm_objfmt *)objfmt_dbg; } static void -dbg_objfmt_output(yasm_objfmt *objfmt, FILE *f, const char *obj_filename, - int all_syms, yasm_dbgfmt *df) +dbg_objfmt_output(yasm_objfmt *objfmt, FILE *f, int all_syms, yasm_dbgfmt *df) { yasm_objfmt_dbg *objfmt_dbg = (yasm_objfmt_dbg *)objfmt; char buf[1024]; diff --git a/modules/objfmts/elf/elf-objfmt.c b/modules/objfmts/elf/elf-objfmt.c index efe0ab6d..8012811a 100644 --- a/modules/objfmts/elf/elf-objfmt.c +++ b/modules/objfmts/elf/elf-objfmt.c @@ -63,6 +63,7 @@ typedef struct yasm_objfmt_elf { yasm_symtab *symtab; /*@dependent@*/ yasm_arch *arch; + elf_strtab_entry *file_strtab_entry;/* .file symbol associated string */ yasm_symrec *dotdotsym; /* ..sym symbol */ } yasm_objfmt_elf; @@ -157,9 +158,8 @@ elf_objfmt_append_local_sym(yasm_symrec *sym, /*@null@*/ void *d) } static yasm_objfmt * -elf_objfmt_create_common(const char *in_filename, yasm_object *object, - yasm_arch *a, yasm_objfmt_module *module, - int bits_pref, +elf_objfmt_create_common(yasm_object *object, yasm_arch *a, + yasm_objfmt_module *module, int bits_pref, const elf_machine_handler **elf_march_out) { yasm_objfmt_elf *objfmt_elf = yasm_xmalloc(sizeof(yasm_objfmt_elf)); @@ -186,8 +186,11 @@ elf_objfmt_create_common(const char *in_filename, yasm_object *object, /* FIXME: misuse of NULL bytecode here; it works, but only barely. */ filesym = yasm_symtab_define_label(objfmt_elf->symtab, ".file", NULL, 0, 0); - entry = elf_symtab_entry_create( - elf_strtab_append_str(objfmt_elf->strtab, in_filename), filesym); + /* Put in current input filename; we'll replace it in output() */ + objfmt_elf->file_strtab_entry = + elf_strtab_append_str(objfmt_elf->strtab, + yasm_object_get_source_fn(object)); + entry = elf_symtab_entry_create(objfmt_elf->file_strtab_entry, filesym); yasm_symrec_add_data(filesym, &elf_symrec_data, entry); elf_symtab_set_nonzero(entry, NULL, SHN_ABS, STB_LOCAL, STT_FILE, NULL, NULL); @@ -201,14 +204,14 @@ elf_objfmt_create_common(const char *in_filename, yasm_object *object, } static yasm_objfmt * -elf_objfmt_create(const char *in_filename, yasm_object *object, yasm_arch *a) +elf_objfmt_create(yasm_object *object, yasm_arch *a) { const elf_machine_handler *elf_march; yasm_objfmt *objfmt; yasm_objfmt_elf *objfmt_elf; - objfmt = elf_objfmt_create_common(in_filename, object, a, - &yasm_elf_LTX_objfmt, 0, &elf_march); + objfmt = elf_objfmt_create_common(object, a, &yasm_elf_LTX_objfmt, 0, + &elf_march); if (objfmt) { objfmt_elf = (yasm_objfmt_elf *)objfmt; /* Figure out which bitness of object format to use */ @@ -221,17 +224,17 @@ elf_objfmt_create(const char *in_filename, yasm_object *object, yasm_arch *a) } static yasm_objfmt * -elf32_objfmt_create(const char *in_filename, yasm_object *object, yasm_arch *a) +elf32_objfmt_create(yasm_object *object, yasm_arch *a) { - return elf_objfmt_create_common(in_filename, object, a, - &yasm_elf32_LTX_objfmt, 32, NULL); + return elf_objfmt_create_common(object, a, &yasm_elf32_LTX_objfmt, 32, + NULL); } static yasm_objfmt * -elf64_objfmt_create(const char *in_filename, yasm_object *object, yasm_arch *a) +elf64_objfmt_create(yasm_object *object, yasm_arch *a) { - return elf_objfmt_create_common(in_filename, object, a, - &yasm_elf64_LTX_objfmt, 64, NULL); + return elf_objfmt_create_common(object, a, &yasm_elf64_LTX_objfmt, 64, + NULL); } static long @@ -587,8 +590,7 @@ elf_objfmt_output_secthead(yasm_section *sect, /*@null@*/ void *d) } static void -elf_objfmt_output(yasm_objfmt *objfmt, FILE *f, const char *obj_filename, - int all_syms, yasm_dbgfmt *df) +elf_objfmt_output(yasm_objfmt *objfmt, FILE *f, int all_syms, yasm_dbgfmt *df) { yasm_objfmt_elf *objfmt_elf = (yasm_objfmt_elf *)objfmt; elf_objfmt_output_info info; @@ -604,6 +606,10 @@ elf_objfmt_output(yasm_objfmt *objfmt, FILE *f, const char *obj_filename, info.objfmt_elf = objfmt_elf; info.f = f; + /* Update filename strtab */ + elf_strtab_entry_set_str(objfmt_elf->file_strtab_entry, + yasm_object_get_source_fn(objfmt_elf->object)); + /* Allocate space for Ehdr by seeking forward */ if (fseek(f, (long)(elf_proghead_get_size()), SEEK_SET) < 0) { yasm__error(0, N_("could not seek on output file")); diff --git a/modules/objfmts/elf/elf.c b/modules/objfmts/elf/elf.c index bab607f1..6e4aad2b 100644 --- a/modules/objfmts/elf/elf.c +++ b/modules/objfmts/elf/elf.c @@ -164,6 +164,14 @@ elf_strtab_entry_create(const char *str) return entry; } +void +elf_strtab_entry_set_str(elf_strtab_entry *entry, const char *str) +{ + if (entry->str) + yasm_xfree(entry->str); + entry->str = yasm__xstrdup(str); +} + elf_strtab_head * elf_strtab_create() { diff --git a/modules/objfmts/elf/elf.h b/modules/objfmts/elf/elf.h index b33bbef2..e7e37339 100644 --- a/modules/objfmts/elf/elf.h +++ b/modules/objfmts/elf/elf.h @@ -421,6 +421,7 @@ void elf_reloc_entry_destroy(void *entry); /* strtab functions */ elf_strtab_entry *elf_strtab_entry_create(const char *str); +void elf_strtab_entry_set_str(elf_strtab_entry *entry, const char *str); elf_strtab_head *elf_strtab_create(void); elf_strtab_entry *elf_strtab_append_str(elf_strtab_head *head, const char *str); void elf_strtab_destroy(elf_strtab_head *head); diff --git a/modules/objfmts/xdf/xdf-objfmt.c b/modules/objfmts/xdf/xdf-objfmt.c index 737adf33..8faa4432 100644 --- a/modules/objfmts/xdf/xdf-objfmt.c +++ b/modules/objfmts/xdf/xdf-objfmt.c @@ -128,7 +128,7 @@ yasm_objfmt_module yasm_xdf_LTX_objfmt; static yasm_objfmt * -xdf_objfmt_create(const char *in_filename, yasm_object *object, yasm_arch *a) +xdf_objfmt_create(yasm_object *object, yasm_arch *a) { yasm_objfmt_xdf *objfmt_xdf = yasm_xmalloc(sizeof(yasm_objfmt_xdf)); @@ -585,8 +585,8 @@ xdf_objfmt_output_str(yasm_symrec *sym, /*@null@*/ void *d) } static void -xdf_objfmt_output(yasm_objfmt *objfmt, FILE *f, const char *obj_filename, - int all_syms, /*@unused@*/ yasm_dbgfmt *df) +xdf_objfmt_output(yasm_objfmt *objfmt, FILE *f, int all_syms, + /*@unused@*/ yasm_dbgfmt *df) { yasm_objfmt_xdf *objfmt_xdf = (yasm_objfmt_xdf *)objfmt; xdf_objfmt_output_info info;