diff options
author | Peter Johnson <peter@tortall.net> | 2010-03-28 19:28:54 +0000 |
---|---|---|
committer | Peter Johnson <peter@tortall.net> | 2010-03-28 19:28:54 +0000 |
commit | 323153d55a9e88184a5feea6644b61d13fa0d0ec (patch) | |
tree | f3dae69de2cbe003b6f01e7597e0f8083274e222 | |
parent | e56ece9a7d2f05233460b528fa5d04f46a30b370 (diff) | |
download | yasm-323153d55a9e88184a5feea6644b61d13fa0d0ec.tar.gz |
Instead of initializing unknown sections en-masse during objfmt_output(),
add new objfmt interface function init_new_section() to initialize as we
go.
This fixes several issues, primarily with debug formats that create sections.
Reported by: Brian Gladman
svn path=/trunk/yasm/; revision=2310
-rw-r--r-- | libyasm/objfmt.h | 15 | ||||
-rw-r--r-- | libyasm/section.c | 3 | ||||
-rw-r--r-- | modules/dbgfmts/dwarf2/tests/passwin64/dwarfwin64_testhd.hex | 48 | ||||
-rw-r--r-- | modules/dbgfmts/stabs/tests/stabs-elf.hex | 16 | ||||
-rw-r--r-- | modules/objfmts/bin/bin-objfmt.c | 20 | ||||
-rw-r--r-- | modules/objfmts/coff/coff-objfmt.c | 70 | ||||
-rw-r--r-- | modules/objfmts/dbg/dbg-objfmt.c | 18 | ||||
-rw-r--r-- | modules/objfmts/elf/elf-objfmt.c | 86 | ||||
-rw-r--r-- | modules/objfmts/macho/macho-objfmt.c | 18 | ||||
-rw-r--r-- | modules/objfmts/rdf/rdf-objfmt.c | 16 | ||||
-rw-r--r-- | modules/objfmts/xdf/xdf-objfmt.c | 19 |
11 files changed, 144 insertions, 185 deletions
diff --git a/libyasm/objfmt.h b/libyasm/objfmt.h index d30e75e2..6abba74d 100644 --- a/libyasm/objfmt.h +++ b/libyasm/objfmt.h @@ -108,6 +108,11 @@ struct yasm_objfmt_module { */ yasm_section * (*add_default_section) (yasm_object *object); + /** Module-level implementation of yasm_objfmt_init_new_section(). + * Call yasm_objfmt_init_new_section() instead of calling this function. + */ + void (*init_new_section) (yasm_section *section, unsigned long line); + /** Module-level implementation of yasm_objfmt_section_switch(). * Call yasm_objfmt_section_switch() instead of calling this function. */ @@ -156,6 +161,13 @@ void yasm_objfmt_destroy(/*@only@*/ yasm_objfmt *objfmt); */ yasm_section *yasm_objfmt_add_default_section(yasm_object *object); +/** Initialize the object-format specific portion of a section. Called + * by yasm_object_get_general(); in general should not be directly called. + * \param section section + * \param line virtual line (from yasm_linemap) + */ +void yasm_objfmt_init_new_section(yasm_object *object, unsigned long line); + /** Switch object file sections. The first val of the valparams should * be the section name. Calls yasm_object_get_general() to actually get * the section. @@ -196,6 +208,9 @@ yasm_section *yasm_objfmt_add_default_section(yasm_object *object); #define yasm_objfmt_add_default_section(object) \ ((yasm_objfmt_base *)((object)->objfmt))->module->add_default_section \ (object) +#define yasm_objfmt_init_new_section(section, line) \ + ((yasm_objfmt_base *)((object)->objfmt))->module->init_new_section \ + (section, line) #define yasm_objfmt_get_special_sym(object, name, parser) \ ((yasm_objfmt_base *)((object)->objfmt))->module->get_special_sym \ (object, name, parser) diff --git a/libyasm/section.c b/libyasm/section.c index 3271e391..bb796308 100644 --- a/libyasm/section.c +++ b/libyasm/section.c @@ -346,6 +346,9 @@ yasm_object_get_general(yasm_object *object, const char *name, s->res_only = res_only; s->def = 0; + /* Initialize object format specific data */ + yasm_objfmt_init_new_section(s, line); + *isnew = 1; return s; } diff --git a/modules/dbgfmts/dwarf2/tests/passwin64/dwarfwin64_testhd.hex b/modules/dbgfmts/dwarf2/tests/passwin64/dwarfwin64_testhd.hex index eb9cfe81..114906bf 100644 --- a/modules/dbgfmts/dwarf2/tests/passwin64/dwarfwin64_testhd.hex +++ b/modules/dbgfmts/dwarf2/tests/passwin64/dwarfwin64_testhd.hex @@ -66,8 +66,8 @@ 00 00 00 -04 -01 +00 +00 00 00 00 @@ -106,8 +106,8 @@ c0 00 00 00 -ec -01 +00 +00 00 00 00 @@ -146,8 +146,8 @@ f3 00 00 00 -37 -05 +00 +00 00 00 00 @@ -186,8 +186,8 @@ f3 00 00 00 -d6 -05 +04 +01 00 00 00 @@ -226,8 +226,8 @@ d6 00 00 00 -22 -06 +00 +00 00 00 00 @@ -266,8 +266,8 @@ ce 00 00 00 -6a -06 +50 +01 00 00 00 @@ -306,8 +306,8 @@ c0 00 00 00 -b2 -06 +00 +00 00 00 00 @@ -346,8 +346,8 @@ b2 00 00 00 -bf -08 +00 +00 00 00 00 @@ -386,8 +386,8 @@ bf 00 00 00 -da -08 +00 +00 00 00 00 @@ -426,8 +426,8 @@ da 00 00 00 -0a -09 +00 +00 00 00 00 @@ -466,8 +466,8 @@ aa 00 00 00 -54 -0b +98 +01 00 00 00 @@ -506,8 +506,8 @@ f4 00 00 00 -77 -0b +bb +01 00 00 00 diff --git a/modules/dbgfmts/stabs/tests/stabs-elf.hex b/modules/dbgfmts/stabs/tests/stabs-elf.hex index c2e9e3cf..71cd7c9f 100644 --- a/modules/dbgfmts/stabs/tests/stabs-elf.hex +++ b/modules/dbgfmts/stabs/tests/stabs-elf.hex @@ -599,7 +599,7 @@ c3 00 00 01 -04 +02 00 00 00 @@ -862,9 +862,11 @@ c3 00 f1 ff +69 00 00 00 +3d 00 00 00 @@ -874,9 +876,7 @@ ff 00 00 00 -03 -00 -0b +04 00 00 00 @@ -892,13 +892,11 @@ ff 00 03 00 -09 +0b 00 -69 00 00 00 -3d 00 00 00 @@ -908,7 +906,9 @@ ff 00 00 00 -04 +03 +00 +09 00 00 00 diff --git a/modules/objfmts/bin/bin-objfmt.c b/modules/objfmts/bin/bin-objfmt.c index 6f2d14d6..8d3abf8c 100644 --- a/modules/objfmts/bin/bin-objfmt.c +++ b/modules/objfmts/bin/bin-objfmt.c @@ -1388,10 +1388,11 @@ define_section_symbol(yasm_symtab *symtab, yasm_section *sect, yasm_symrec_add_data(sym, &bin_symrec_data_cb, bsymd); } -static bin_section_data * -bin_objfmt_init_new_section(yasm_object *object, yasm_section *sect, - const char *sectname, unsigned long line) +static void +bin_objfmt_init_new_section(yasm_section *sect, unsigned long line) { + yasm_object *object = yasm_section_get_object(sect); + const char *sectname = yasm_section_get_name(sect); /*yasm_objfmt_bin *objfmt_bin = (yasm_objfmt_bin *)object->objfmt;*/ bin_section_data *data; @@ -1414,8 +1415,6 @@ bin_objfmt_init_new_section(yasm_object *object, yasm_section *sect, SSYM_VSTART, line); define_section_symbol(object->symtab, sect, sectname, ".length", SSYM_LENGTH, line); - - return data; } static yasm_section * @@ -1425,10 +1424,8 @@ bin_objfmt_add_default_section(yasm_object *object) int isnew; retval = yasm_object_get_general(object, ".text", 0, 1, 0, &isnew, 0); - if (isnew) { - bin_objfmt_init_new_section(object, retval, ".text", 0); + if (isnew) yasm_section_set_default(retval, 1); - } return retval; } @@ -1568,10 +1565,7 @@ bin_objfmt_section_switch(yasm_object *object, yasm_valparamhead *valparams, retval = yasm_object_get_general(object, sectname, 0, (int)data.code, (int)data.bss, &isnew, line); - if (isnew) - bsd = bin_objfmt_init_new_section(object, retval, sectname, line); - else - bsd = yasm_section_get_data(retval, &bin_section_data_cb); + bsd = yasm_section_get_data(retval, &bin_section_data_cb); if (isnew || yasm_section_is_default(retval)) { yasm_section_set_default(retval, 0); @@ -1820,6 +1814,7 @@ yasm_objfmt_module yasm_bin_LTX_objfmt = { bin_objfmt_output, bin_objfmt_destroy, bin_objfmt_add_default_section, + bin_objfmt_init_new_section, bin_objfmt_section_switch, bin_objfmt_get_special_sym }; @@ -1972,6 +1967,7 @@ yasm_objfmt_module yasm_dosexe_LTX_objfmt = { dosexe_objfmt_output, bin_objfmt_destroy, bin_objfmt_add_default_section, + bin_objfmt_init_new_section, bin_objfmt_section_switch, bin_objfmt_get_special_sym }; diff --git a/modules/objfmts/coff/coff-objfmt.c b/modules/objfmts/coff/coff-objfmt.c index b4191572..7ad087ce 100644 --- a/modules/objfmts/coff/coff-objfmt.c +++ b/modules/objfmts/coff/coff-objfmt.c @@ -369,10 +369,11 @@ win64_objfmt_create(yasm_object *object) return (yasm_objfmt *)objfmt_coff; } -static coff_section_data * -coff_objfmt_init_new_section(yasm_object *object, yasm_section *sect, - const char *sectname, unsigned long line) +static void +coff_objfmt_init_new_section(yasm_section *sect, unsigned long line) { + yasm_object *object = yasm_section_get_object(sect); + const char *sectname = yasm_section_get_name(sect); yasm_objfmt_coff *objfmt_coff = (yasm_objfmt_coff *)object->objfmt; coff_section_data *data; yasm_symrec *sym; @@ -388,6 +389,15 @@ coff_objfmt_init_new_section(yasm_object *object, yasm_section *sect, data->flags2 = 0; data->strtab_name = 0; data->isdebug = 0; + + if (yasm__strncasecmp(sectname, ".debug", 6)==0) { + data->flags = COFF_STYP_DATA; + if (objfmt_coff->win32) + data->flags |= COFF_STYP_DISCARD|COFF_STYP_READ; + data->isdebug = 1; + } else + data->flags = COFF_STYP_TEXT; + yasm_section_add_data(sect, &coff_section_data_cb, data); sym = yasm_symtab_define_label(object->symtab, sectname, @@ -395,31 +405,6 @@ coff_objfmt_init_new_section(yasm_object *object, yasm_section *sect, yasm_symrec_declare(sym, YASM_SYM_GLOBAL, line); coff_objfmt_sym_set_data(sym, COFF_SCL_STAT, 1, COFF_SYMTAB_AUX_SECT); data->sym = sym; - return data; -} - -static int -coff_objfmt_init_remaining_section(yasm_section *sect, /*@null@*/ void *d) -{ - /*@null@*/ coff_objfmt_output_info *info = (coff_objfmt_output_info *)d; - /*@dependent@*/ /*@null@*/ coff_section_data *csd; - - assert(info != NULL); - csd = yasm_section_get_data(sect, &coff_section_data_cb); - if (!csd) { - /* Initialize new one */ - const char *sectname = yasm_section_get_name(sect); - csd = coff_objfmt_init_new_section(info->object, sect, sectname, 0); - if (yasm__strncasecmp(sectname, ".debug", 6)==0) { - csd->flags = COFF_STYP_DATA; - if (info->objfmt_coff->win32) - csd->flags |= COFF_STYP_DISCARD|COFF_STYP_READ; - csd->isdebug = 1; - } else - csd->flags = COFF_STYP_TEXT; - } - - return 0; } static int @@ -1182,12 +1167,6 @@ coff_objfmt_output(yasm_object *object, FILE *f, int all_syms, info.f = f; info.buf = yasm_xmalloc(REGULAR_OUTBUF_SIZE); - /* Initialize section data (and count in parse_scnum) any sections that - * we've not initialized so far. - */ - yasm_object_sections_traverse(object, &info, - coff_objfmt_init_remaining_section); - /* Allocate space for headers by seeking forward */ if (fseek(f, (long)(20+40*(objfmt_coff->parse_scnum-1)), SEEK_SET) < 0) { yasm__fatal(N_("could not seek on output file")); @@ -1288,7 +1267,7 @@ coff_objfmt_add_default_section(yasm_object *object) retval = yasm_object_get_general(object, ".text", 16, 1, 0, &isnew, 0); if (isnew) { - csd = coff_objfmt_init_new_section(object, retval, ".text", 0); + csd = yasm_section_get_data(retval, &coff_section_data_cb); csd->flags = COFF_STYP_TEXT; if (objfmt_coff->win32) csd->flags |= COFF_STYP_EXECUTE | COFF_STYP_READ; @@ -1571,14 +1550,10 @@ coff_objfmt_section_switch(yasm_object *object, yasm_valparamhead *valparams, retval = yasm_object_get_general(object, realname, align, iscode, resonly, &isnew, line); - - if (isnew) - csd = coff_objfmt_init_new_section(object, retval, realname, line); - else - csd = yasm_section_get_data(retval, &coff_section_data_cb); - yasm_xfree(realname); + csd = yasm_section_get_data(retval, &coff_section_data_cb); + if (isnew || yasm_section_is_default(retval)) { yasm_section_set_default(retval, 0); csd->flags = data.flags; @@ -1676,8 +1651,7 @@ dir_export(yasm_object *object, yasm_valparamhead *valparams, /* Initialize directive section if needed */ if (isnew) { coff_section_data *csd; - csd = coff_objfmt_init_new_section(object, sect, - yasm_section_get_name(sect), line); + csd = yasm_section_get_data(sect, &coff_section_data_cb); csd->flags = COFF_STYP_INFO | COFF_STYP_DISCARD | COFF_STYP_READ; } @@ -1724,7 +1698,7 @@ dir_safeseh(yasm_object *object, yasm_valparamhead *valparams, /* Initialize sxdata section if needed */ if (isnew) { coff_section_data *csd; - csd = coff_objfmt_init_new_section(object, sect, ".sxdata", line); + csd = yasm_section_get_data(sect, &coff_section_data_cb); csd->flags = COFF_STYP_INFO; } @@ -2134,7 +2108,7 @@ dir_endproc_frame(yasm_object *object, /*@null@*/ yasm_valparamhead *valparams, /* Initialize xdata section if needed */ if (isnew) { - csd = coff_objfmt_init_new_section(object, sect, ".xdata", line); + csd = yasm_section_get_data(sect, &coff_section_data_cb); csd->flags = COFF_STYP_DATA | COFF_STYP_READ; yasm_section_set_align(sect, 8, line); } @@ -2159,7 +2133,7 @@ dir_endproc_frame(yasm_object *object, /*@null@*/ yasm_valparamhead *valparams, /* Initialize pdata section if needed */ if (isnew) { - csd = coff_objfmt_init_new_section(object, sect, ".pdata", line); + csd = yasm_section_get_data(sect, &coff_section_data_cb); csd->flags = COFF_STYP_DATA | COFF_STYP_READ; csd->flags2 = COFF_FLAG_NOBASE; yasm_section_set_align(sect, 4, line); @@ -2209,6 +2183,7 @@ yasm_objfmt_module yasm_coff_LTX_objfmt = { coff_objfmt_output, coff_objfmt_destroy, coff_objfmt_add_default_section, + coff_objfmt_init_new_section, coff_objfmt_section_switch, coff_objfmt_get_special_sym }; @@ -2261,6 +2236,7 @@ yasm_objfmt_module yasm_win32_LTX_objfmt = { coff_objfmt_output, coff_objfmt_destroy, coff_objfmt_add_default_section, + coff_objfmt_init_new_section, coff_objfmt_section_switch, coff_objfmt_get_special_sym }; @@ -2315,6 +2291,7 @@ yasm_objfmt_module yasm_win64_LTX_objfmt = { coff_objfmt_output, coff_objfmt_destroy, coff_objfmt_add_default_section, + coff_objfmt_init_new_section, coff_objfmt_section_switch, coff_objfmt_get_special_sym }; @@ -2332,6 +2309,7 @@ yasm_objfmt_module yasm_x64_LTX_objfmt = { coff_objfmt_output, coff_objfmt_destroy, coff_objfmt_add_default_section, + coff_objfmt_init_new_section, coff_objfmt_section_switch, coff_objfmt_get_special_sym }; diff --git a/modules/objfmts/dbg/dbg-objfmt.c b/modules/objfmts/dbg/dbg-objfmt.c index 5a71c4f1..a6017f09 100644 --- a/modules/objfmts/dbg/dbg-objfmt.c +++ b/modules/objfmts/dbg/dbg-objfmt.c @@ -89,6 +89,17 @@ dbg_objfmt_destroy(yasm_objfmt *objfmt) yasm_xfree(objfmt); } +static void +dbg_objfmt_init_new_section(yasm_section *sect, unsigned long line) +{ + yasm_object *object = yasm_section_get_object(sect); + yasm_objfmt_dbg *objfmt_dbg = (yasm_objfmt_dbg *)object->objfmt; + fprintf(objfmt_dbg->dbgfile, "init_new_section(\"%s\", %lu)\n", + yasm_section_get_name(sect), line); + yasm_symtab_define_label(object->symtab, ".text", + yasm_section_bcs_first(sect), 1, 0); +} + static yasm_section * dbg_objfmt_add_default_section(yasm_object *object) { @@ -96,11 +107,9 @@ dbg_objfmt_add_default_section(yasm_object *object) yasm_section *retval; int isnew; + fprintf(objfmt_dbg->dbgfile, "add_default_section()\n"); retval = yasm_object_get_general(object, ".text", 0, 0, 0, &isnew, 0); if (isnew) { - fprintf(objfmt_dbg->dbgfile, "(new) "); - yasm_symtab_define_label(object->symtab, ".text", - yasm_section_bcs_first(retval), 1, 0); yasm_section_set_default(retval, 1); } return retval; @@ -132,8 +141,6 @@ dbg_objfmt_section_switch(yasm_object *object, yasm_valparamhead *valparams, &isnew, line); if (isnew) { fprintf(objfmt_dbg->dbgfile, "(new) "); - yasm_symtab_define_label(object->symtab, vp->val, - yasm_section_bcs_first(retval), 1, line); } yasm_section_set_default(retval, 0); fprintf(objfmt_dbg->dbgfile, "\"%s\" section\n", vp->val); @@ -171,6 +178,7 @@ yasm_objfmt_module yasm_dbg_LTX_objfmt = { dbg_objfmt_output, dbg_objfmt_destroy, dbg_objfmt_add_default_section, + dbg_objfmt_init_new_section, dbg_objfmt_section_switch, dbg_objfmt_get_special_sym }; diff --git a/modules/objfmts/elf/elf-objfmt.c b/modules/objfmts/elf/elf-objfmt.c index df5bf233..04bc7baa 100644 --- a/modules/objfmts/elf/elf-objfmt.c +++ b/modules/objfmts/elf/elf-objfmt.c @@ -634,45 +634,6 @@ elf_objfmt_output_bytecode(yasm_bytecode *bc, /*@null@*/ void *d) } static int -elf_objfmt_create_dbg_secthead(yasm_section *sect, /*@null@*/ void *d) -{ - /*@null@*/ elf_objfmt_output_info *info = (elf_objfmt_output_info *)d; - elf_secthead *shead; - elf_section_type type=SHT_PROGBITS; - elf_size entsize=0; - const char *sectname; - /*@dependent@*/ yasm_symrec *sym; - elf_strtab_entry *name; - - shead = yasm_section_get_data(sect, &elf_section_data); - if (shead) - return 0; /* only create new secthead if missing */ - - sectname = yasm_section_get_name(sect); - name = elf_strtab_append_str(info->objfmt_elf->shstrtab, sectname); - - if (yasm__strcasecmp(sectname, ".stab")==0) { - entsize = 12; - } else if (yasm__strcasecmp(sectname, ".stabstr")==0) { - type = SHT_STRTAB; - } else if (yasm__strncasecmp(sectname, ".debug_", 7)==0) { - ; - } else - yasm_internal_error(N_("Unrecognized section without data")); - - shead = elf_secthead_create(name, type, 0, 0, 0); - elf_secthead_set_entsize(shead, entsize); - - sym = yasm_symtab_define_label(info->object->symtab, sectname, - yasm_section_bcs_first(sect), 1, 0); - elf_secthead_set_sym(shead, sym); - - yasm_section_add_data(sect, &elf_section_data, shead); - - return 0; -} - -static int elf_objfmt_output_section(yasm_section *sect, /*@null@*/ void *d) { /*@null@*/ elf_objfmt_output_info *info = (elf_objfmt_output_info *)d; @@ -795,11 +756,6 @@ elf_objfmt_output(yasm_object *object, FILE *f, int all_syms, return; } - /* Create missing section headers */ - if (yasm_object_sections_traverse(object, &info, - elf_objfmt_create_dbg_secthead)) - return; - /* add all (local) syms to symtab because relocation needs a symtab index * if all_syms, register them by name. if not, use strtab entry 0 */ buildsym_info.object = object; @@ -925,25 +881,33 @@ elf_objfmt_destroy(yasm_objfmt *objfmt) yasm_xfree(objfmt); } -static elf_secthead * -elf_objfmt_init_new_section(yasm_object *object, yasm_section *sect, - const char *sectname, unsigned long type, - unsigned long flags, unsigned long line) +static void +elf_objfmt_init_new_section(yasm_section *sect, unsigned long line) { + yasm_object *object = yasm_section_get_object(sect); + const char *sectname = yasm_section_get_name(sect); yasm_objfmt_elf *objfmt_elf = (yasm_objfmt_elf *)object->objfmt; elf_secthead *esd; yasm_symrec *sym; elf_strtab_entry *name = elf_strtab_append_str(objfmt_elf->shstrtab, sectname); - esd = elf_secthead_create(name, type, flags, 0, 0); + elf_section_type type=SHT_PROGBITS; + elf_size entsize=0; + + if (yasm__strcasecmp(sectname, ".stab")==0) { + entsize = 12; + } else if (yasm__strcasecmp(sectname, ".stabstr")==0) { + type = SHT_STRTAB; + } + + esd = elf_secthead_create(name, type, 0, 0, 0); + elf_secthead_set_entsize(esd, entsize); yasm_section_add_data(sect, &elf_section_data, esd); sym = yasm_symtab_define_label(object->symtab, sectname, yasm_section_bcs_first(sect), 1, line); elf_secthead_set_sym(esd, sym); - - return esd; } static yasm_section * @@ -951,12 +915,15 @@ elf_objfmt_add_default_section(yasm_object *object) { yasm_section *retval; int isnew; - elf_secthead *esd; retval = yasm_object_get_general(object, ".text", 16, 1, 0, &isnew, 0); - esd = elf_objfmt_init_new_section(object, retval, ".text", SHT_PROGBITS, - SHF_ALLOC + SHF_EXECINSTR, 0); - yasm_section_set_default(retval, 1); + if (isnew) + { + elf_secthead *esd = yasm_section_get_data(retval, &elf_section_data); + elf_secthead_set_typeflags(esd, SHT_PROGBITS, + SHF_ALLOC + SHF_EXECINSTR); + yasm_section_set_default(retval, 1); + } return retval; } @@ -1145,11 +1112,7 @@ elf_objfmt_section_switch(yasm_object *object, yasm_valparamhead *valparams, (data.flags & SHF_EXECINSTR) != 0, resonly, &isnew, line); - if (isnew) - esd = elf_objfmt_init_new_section(object, retval, sectname, data.type, - data.flags, line); - else - esd = yasm_section_get_data(retval, &elf_section_data); + esd = yasm_section_get_data(retval, &elf_section_data); if (isnew || yasm_section_is_default(retval)) { yasm_section_set_default(retval, 0); @@ -1359,6 +1322,7 @@ yasm_objfmt_module yasm_elf_LTX_objfmt = { elf_objfmt_output, elf_objfmt_destroy, elf_objfmt_add_default_section, + elf_objfmt_init_new_section, elf_objfmt_section_switch, elf_objfmt_get_special_sym }; @@ -1377,6 +1341,7 @@ yasm_objfmt_module yasm_elf32_LTX_objfmt = { elf_objfmt_output, elf_objfmt_destroy, elf_objfmt_add_default_section, + elf_objfmt_init_new_section, elf_objfmt_section_switch, elf_objfmt_get_special_sym }; @@ -1395,6 +1360,7 @@ yasm_objfmt_module yasm_elf64_LTX_objfmt = { elf_objfmt_output, elf_objfmt_destroy, elf_objfmt_add_default_section, + elf_objfmt_init_new_section, elf_objfmt_section_switch, elf_objfmt_get_special_sym }; diff --git a/modules/objfmts/macho/macho-objfmt.c b/modules/objfmts/macho/macho-objfmt.c index a57c4c73..5f96571a 100644 --- a/modules/objfmts/macho/macho-objfmt.c +++ b/modules/objfmts/macho/macho-objfmt.c @@ -1242,10 +1242,11 @@ macho_objfmt_destroy(yasm_objfmt *objfmt) yasm_xfree(objfmt); } -static macho_section_data * -macho_objfmt_init_new_section(yasm_object *object, yasm_section *sect, - const char *sectname, unsigned long line) +static void +macho_objfmt_init_new_section(yasm_section *sect, unsigned long line) { + yasm_object *object = yasm_section_get_object(sect); + const char *sectname = yasm_section_get_name(sect); yasm_objfmt_macho *objfmt_macho = (yasm_objfmt_macho *)object->objfmt; macho_section_data *data; yasm_symrec *sym; @@ -1265,7 +1266,6 @@ macho_objfmt_init_new_section(yasm_object *object, yasm_section *sect, sym = yasm_symtab_define_label(object->symtab, sectname, yasm_section_bcs_first(sect), 1, line); data->sym = sym; - return data; } static yasm_section * @@ -1278,7 +1278,7 @@ macho_objfmt_add_default_section(yasm_object *object) retval = yasm_object_get_general(object, "LC_SEGMENT.__TEXT.__text", 0, 1, 0, &isnew, 0); if (isnew) { - msd = macho_objfmt_init_new_section(object, retval, ".text", 0); + msd = yasm_section_get_data(retval, &macho_section_data_cb); msd->segname = yasm__xstrdup("__TEXT"); msd->sectname = yasm__xstrdup("__text"); msd->flags = S_ATTR_PURE_INSTRUCTIONS; @@ -1471,10 +1471,7 @@ macho_objfmt_section_switch(yasm_object *object, yasm_valparamhead *valparams, &isnew, line); yasm_xfree(realname); - if (isnew) - msd = macho_objfmt_init_new_section(object, retval, sectname, line); - else - msd = yasm_section_get_data(retval, &macho_section_data_cb); + msd = yasm_section_get_data(retval, &macho_section_data_cb); if (isnew || yasm_section_is_default(retval)) { yasm_section_set_default(retval, 0); @@ -1564,6 +1561,7 @@ yasm_objfmt_module yasm_macho_LTX_objfmt = { macho_objfmt_output, macho_objfmt_destroy, macho_objfmt_add_default_section, + macho_objfmt_init_new_section, macho_objfmt_section_switch, macho_objfmt_get_special_sym }; @@ -1582,6 +1580,7 @@ yasm_objfmt_module yasm_macho32_LTX_objfmt = { macho_objfmt_output, macho_objfmt_destroy, macho_objfmt_add_default_section, + macho_objfmt_init_new_section, macho_objfmt_section_switch, macho_objfmt_get_special_sym }; @@ -1600,6 +1599,7 @@ yasm_objfmt_module yasm_macho64_LTX_objfmt = { macho_objfmt_output, macho_objfmt_destroy, macho_objfmt_add_default_section, + macho_objfmt_init_new_section, macho_objfmt_section_switch, macho_objfmt_get_special_sym }; diff --git a/modules/objfmts/rdf/rdf-objfmt.c b/modules/objfmts/rdf/rdf-objfmt.c index 8b704a54..69ce08b5 100644 --- a/modules/objfmts/rdf/rdf-objfmt.c +++ b/modules/objfmts/rdf/rdf-objfmt.c @@ -811,10 +811,11 @@ rdf_objfmt_destroy(yasm_objfmt *objfmt) yasm_xfree(objfmt); } -static rdf_section_data * -rdf_objfmt_init_new_section(yasm_object *object, yasm_section *sect, - const char *sectname, unsigned long line) +static void +rdf_objfmt_init_new_section(yasm_section *sect, unsigned long line) { + yasm_object *object = yasm_section_get_object(sect); + const char *sectname = yasm_section_get_name(sect); yasm_objfmt_rdf *objfmt_rdf = (yasm_objfmt_rdf *)object->objfmt; rdf_section_data *data; yasm_symrec *sym; @@ -830,7 +831,6 @@ rdf_objfmt_init_new_section(yasm_object *object, yasm_section *sect, sym = yasm_symtab_define_label(object->symtab, sectname, yasm_section_bcs_first(sect), 1, line); data->sym = sym; - return data; } static yasm_section * @@ -842,7 +842,7 @@ rdf_objfmt_add_default_section(yasm_object *object) retval = yasm_object_get_general(object, ".text", 0, 1, 0, &isnew, 0); if (isnew) { - rsd = rdf_objfmt_init_new_section(object, retval, ".text", 0); + rsd = yasm_section_get_data(retval, &rdf_section_data_cb); rsd->type = RDF_SECT_CODE; rsd->reserved = 0; yasm_section_set_default(retval, 1); @@ -950,10 +950,7 @@ rdf_objfmt_section_switch(yasm_object *object, yasm_valparamhead *valparams, retval = yasm_object_get_general(object, sectname, 0, 1, data.type == RDF_SECT_BSS, &isnew, line); - if (isnew) - rsd = rdf_objfmt_init_new_section(object, retval, sectname, line); - else - rsd = yasm_section_get_data(retval, &rdf_section_data_cb); + rsd = yasm_section_get_data(retval, &rdf_section_data_cb); if (isnew || yasm_section_is_default(retval)) { yasm_section_set_default(retval, 0); @@ -1088,6 +1085,7 @@ yasm_objfmt_module yasm_rdf_LTX_objfmt = { rdf_objfmt_output, rdf_objfmt_destroy, rdf_objfmt_add_default_section, + rdf_objfmt_init_new_section, rdf_objfmt_section_switch, rdf_objfmt_get_special_sym }; diff --git a/modules/objfmts/xdf/xdf-objfmt.c b/modules/objfmts/xdf/xdf-objfmt.c index 8f109d20..c96786b1 100644 --- a/modules/objfmts/xdf/xdf-objfmt.c +++ b/modules/objfmts/xdf/xdf-objfmt.c @@ -604,10 +604,11 @@ xdf_objfmt_destroy(yasm_objfmt *objfmt) yasm_xfree(objfmt); } -static xdf_section_data * -xdf_objfmt_init_new_section(yasm_object *object, yasm_section *sect, - const char *sectname, unsigned long line) +static void +xdf_objfmt_init_new_section(yasm_section *sect, unsigned long line) { + yasm_object *object = yasm_section_get_object(sect); + const char *sectname = yasm_section_get_name(sect); yasm_objfmt_xdf *objfmt_xdf = (yasm_objfmt_xdf *)object->objfmt; xdf_section_data *data; yasm_symrec *sym; @@ -626,21 +627,17 @@ xdf_objfmt_init_new_section(yasm_object *object, yasm_section *sect, sym = yasm_symtab_define_label(object->symtab, sectname, yasm_section_bcs_first(sect), 1, line); data->sym = sym; - return data; } static yasm_section * xdf_objfmt_add_default_section(yasm_object *object) { yasm_section *retval; - xdf_section_data *xsd; int isnew; retval = yasm_object_get_general(object, ".text", 0, 1, 0, &isnew, 0); - if (isnew) { - xsd = xdf_objfmt_init_new_section(object, retval, ".text", 0); + if (isnew) yasm_section_set_default(retval, 1); - } return retval; } @@ -750,10 +747,7 @@ xdf_objfmt_section_switch(yasm_object *object, yasm_valparamhead *valparams, retval = yasm_object_get_general(object, sectname, align, 1, resonly, &isnew, line); - if (isnew) - xsd = xdf_objfmt_init_new_section(object, retval, sectname, line); - else - xsd = yasm_section_get_data(retval, &xdf_section_data_cb); + xsd = yasm_section_get_data(retval, &xdf_section_data_cb); if (isnew || yasm_section_is_default(retval)) { yasm_section_set_default(retval, 0); @@ -847,6 +841,7 @@ yasm_objfmt_module yasm_xdf_LTX_objfmt = { xdf_objfmt_output, xdf_objfmt_destroy, xdf_objfmt_add_default_section, + xdf_objfmt_init_new_section, xdf_objfmt_section_switch, xdf_objfmt_get_special_sym }; |