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 */
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'"),
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(
/** 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.
* 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.
#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)
/** 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.
/** 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
/* 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) \
struct yasm_object {
+ /*@owned@*/ char *src_filename;
+ /*@owned@*/ char *obj_filename;
+
yasm_symtab *symtab;
yasm_linemap *linemap;
/*@-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();
}
/*@=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)
{
/** 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.
/*@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.
yasm_object *object;
yasm_symtab *symtab;
- const char *filename;
yasm_linemap *linemap;
yasm_arch *arch;
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));
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);
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;
}
62
00
00
-2d
+74
+65
+73
+74
+5f
+68
+64
+2e
+63
00
6d
61
00
00
00
-00
-00
-00
-00
-00
-00
-00
-00
ee
00
00
0b
00
00
-61
+69
02
00
00
00
00
00
-38
+40
0e
00
00
00
00
00
-e0
+f0
5c
01
00
00
00
00
-2d
+6c
+65
+62
+31
+32
+38
+5f
+74
+65
+73
+74
+2e
+63
00
74
65
00
00
00
+00
+00
+00
+00
70
01
00
00
00
00
-0c
+18
28
00
00
00
00
00
-d4
+e0
e6
00
00
00
67
01
-2d
-00
-00
-00
-00
-00
-00
-00
-00
+74
+65
+73
+74
+5f
+68
+64
+2e
+63
00
00
00
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;
yasm_object *object;
yasm_symtab *symtab;
- const char *filename;
yasm_linemap *linemap;
yasm_arch *arch;
} yasm_dbgfmt_stabs;
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);
/* 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);
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;
}
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;
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 {
}
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);
/* 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 */
}
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.
}
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 */
}
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;
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.
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));
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];
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;
}
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));
/* 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);
}
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 */
}
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
}
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;
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"));
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()
{
/* 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);
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));
}
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;