From: Peter Johnson Date: Wed, 23 Nov 2005 07:27:41 +0000 (-0000) Subject: * coff-objfmt.c: Support section names >8 characters when outputting Win32 X-Git-Tag: v0.5.0rc1~57 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=5e99873c61fd05c18ce67a319edd62fe35204c13;p=yasm * coff-objfmt.c: Support section names >8 characters when outputting Win32 or Win64 object files, which support a string table extensison of section names. svn path=/trunk/yasm/; revision=1321 --- diff --git a/modules/objfmts/coff/coff-objfmt.c b/modules/objfmts/coff/coff-objfmt.c index cf05b97c..792e2fc3 100644 --- a/modules/objfmts/coff/coff-objfmt.c +++ b/modules/objfmts/coff/coff-objfmt.c @@ -113,6 +113,7 @@ typedef struct coff_section_data { unsigned long relptr; /* file ptr to relocation */ unsigned long nreloc; /* number of relocation entries >64k -> error */ unsigned long flags2; /* internal flags (see COFF_FLAG_* above) */ + unsigned long strtab_name; /* strtab offset of name if name > 8 chars */ } coff_section_data; typedef enum coff_symrec_sclass { @@ -584,6 +585,15 @@ coff_objfmt_output_section(yasm_section *sect, /*@null@*/ void *d) csd = yasm_section_get_data(sect, &coff_section_data_cb); assert(csd != NULL); + /* Add to strtab if in win32 format and name > 8 chars */ + if (info->objfmt_coff->win32) { + size_t namelen = strlen(yasm_section_get_name(sect)); + if (namelen > 8) { + csd->strtab_name = info->strtab_offset; + info->strtab_offset += namelen + 1; + } + } + csd->addr = info->addr; if ((csd->flags & COFF_STYP_STD_MASK) == COFF_STYP_BSS) { @@ -655,6 +665,28 @@ coff_objfmt_output_section(yasm_section *sect, /*@null@*/ void *d) return 0; } +static int +coff_objfmt_output_sectstr(yasm_section *sect, /*@null@*/ void *d) +{ + /*@null@*/ coff_objfmt_output_info *info = (coff_objfmt_output_info *)d; + const char *name; + size_t len; + + /* Don't output absolute sections into the section table */ + if (yasm_section_is_absolute(sect)) + return 0; + + /* Add to strtab if in win32 format and name > 8 chars */ + if (!info->objfmt_coff->win32) + return 0; + + name = yasm_section_get_name(sect); + len = strlen(name); + if (len > 8) + fwrite(name, len+1, 1, info->f); + return 0; +} + static int coff_objfmt_output_secthead(yasm_section *sect, /*@null@*/ void *d) { @@ -684,8 +716,13 @@ coff_objfmt_output_secthead(yasm_section *sect, /*@null@*/ void *d) align >>= 1; } + /* section name */ localbuf = info->buf; - strncpy((char *)localbuf, yasm_section_get_name(sect), 8);/* section name */ + if (strlen(yasm_section_get_name(sect)) > 8) { + /* 9 because snprintf always forces a terminating NUL */ + snprintf((char *)localbuf, 9, "/%ld", csd->strtab_name); + } else + strncpy((char *)localbuf, yasm_section_get_name(sect), 8); localbuf += 8; YASM_WRITE_32_L(localbuf, csd->addr); /* physical address */ if (COFF_SET_VMA) @@ -972,6 +1009,8 @@ coff_objfmt_output(yasm_objfmt *objfmt, FILE *f, const char *obj_filename, /* String table */ yasm_fwrite_32_l(info.strtab_offset, f); /* total length */ + yasm_object_sections_traverse(objfmt_coff->object, &info, + coff_objfmt_output_sectstr); yasm_symtab_traverse(objfmt_coff->symtab, &info, coff_objfmt_output_str); /* Write headers */ @@ -1027,6 +1066,7 @@ coff_objfmt_init_new_section(yasm_objfmt_coff *objfmt_coff, data->relptr = 0; data->nreloc = 0; data->flags2 = flags2; + data->strtab_name = 0; yasm_section_add_data(sect, &coff_section_data_cb, data); sym = yasm_symtab_define_label(objfmt_coff->symtab, sectname, @@ -1092,9 +1132,10 @@ coff_objfmt_section_switch(yasm_objfmt *objfmt, yasm_valparamhead *valparams, return NULL; sectname = vp->val; - if (strlen(sectname) > 8) { - /* TODO: win32 format supports >8 character section names in object - * files via "/nnnn" (where nnnn is decimal offset into string table). + if (strlen(sectname) > 8 && !objfmt_coff->win32) { + /* win32 format supports >8 character section names in object + * files via "/nnnn" (where nnnn is decimal offset into string table), + * so only warn for regular COFF. */ yasm__warning(YASM_WARN_GENERAL, line, N_("COFF section names limited to 8 characters: truncating")); diff --git a/modules/objfmts/win32/tests/win32-longsect.asm b/modules/objfmts/win32/tests/win32-longsect.asm new file mode 100644 index 00000000..db4380c5 --- /dev/null +++ b/modules/objfmts/win32/tests/win32-longsect.asm @@ -0,0 +1,10 @@ +[section this_is_a_very_long_section_name] +dd 0 +[section another.long.section] +dd 0 +[section exactly8] +dd 0 +[section onemorex9] +dd 0 +[section juuust7] +dd 0 diff --git a/modules/objfmts/win32/tests/win32-longsect.errwarn b/modules/objfmts/win32/tests/win32-longsect.errwarn new file mode 100644 index 00000000..e69de29b diff --git a/modules/objfmts/win32/tests/win32-longsect.hex b/modules/objfmts/win32/tests/win32-longsect.hex new file mode 100644 index 00000000..dbac4fcd --- /dev/null +++ b/modules/objfmts/win32/tests/win32-longsect.hex @@ -0,0 +1,664 @@ +4c +01 +06 +00 +00 +00 +00 +00 +18 +01 +00 +00 +0e +00 +00 +00 +00 +00 +0c +01 +2e +74 +65 +78 +74 +00 +00 +00 +00 +00 +00 +00 +00 +00 +00 +00 +00 +00 +00 +00 +00 +00 +00 +00 +00 +00 +00 +00 +00 +00 +00 +00 +00 +00 +00 +00 +20 +00 +50 +60 +2f +34 +00 +78 +74 +00 +00 +00 +00 +00 +00 +00 +00 +00 +00 +00 +04 +00 +00 +00 +04 +01 +00 +00 +00 +00 +00 +00 +00 +00 +00 +00 +00 +00 +00 +00 +20 +00 +00 +60 +2f +33 +37 +00 +74 +00 +00 +00 +04 +00 +00 +00 +00 +00 +00 +00 +04 +00 +00 +00 +08 +01 +00 +00 +00 +00 +00 +00 +00 +00 +00 +00 +00 +00 +00 +00 +20 +00 +00 +60 +65 +78 +61 +63 +74 +6c +79 +38 +08 +00 +00 +00 +00 +00 +00 +00 +04 +00 +00 +00 +0c +01 +00 +00 +00 +00 +00 +00 +00 +00 +00 +00 +00 +00 +00 +00 +20 +00 +00 +60 +2f +35 +38 +00 +74 +6c +79 +38 +0c +00 +00 +00 +00 +00 +00 +00 +04 +00 +00 +00 +10 +01 +00 +00 +00 +00 +00 +00 +00 +00 +00 +00 +00 +00 +00 +00 +20 +00 +00 +60 +6a +75 +75 +75 +73 +74 +37 +00 +10 +00 +00 +00 +00 +00 +00 +00 +04 +00 +00 +00 +14 +01 +00 +00 +00 +00 +00 +00 +00 +00 +00 +00 +00 +00 +00 +00 +20 +00 +00 +60 +00 +00 +00 +00 +00 +00 +00 +00 +00 +00 +00 +00 +00 +00 +00 +00 +00 +00 +00 +00 +2e +66 +69 +6c +65 +00 +00 +00 +00 +00 +00 +00 +fe +ff +00 +00 +67 +01 +2d +00 +00 +00 +00 +00 +00 +00 +00 +00 +00 +00 +00 +00 +00 +00 +00 +00 +2e +74 +65 +78 +74 +00 +00 +00 +00 +00 +00 +00 +01 +00 +00 +00 +03 +01 +00 +00 +00 +00 +00 +00 +00 +00 +00 +00 +00 +00 +00 +00 +00 +00 +00 +00 +00 +00 +00 +00 +44 +00 +00 +00 +00 +00 +00 +00 +02 +00 +00 +00 +03 +01 +04 +00 +00 +00 +00 +00 +00 +00 +00 +00 +00 +00 +00 +00 +00 +00 +00 +00 +00 +00 +00 +00 +65 +00 +00 +00 +00 +00 +00 +00 +03 +00 +00 +00 +03 +01 +04 +00 +00 +00 +00 +00 +00 +00 +00 +00 +00 +00 +00 +00 +00 +00 +00 +00 +65 +78 +61 +63 +74 +6c +79 +38 +00 +00 +00 +00 +04 +00 +00 +00 +03 +01 +04 +00 +00 +00 +00 +00 +00 +00 +00 +00 +00 +00 +00 +00 +00 +00 +00 +00 +00 +00 +00 +00 +7a +00 +00 +00 +00 +00 +00 +00 +05 +00 +00 +00 +03 +01 +04 +00 +00 +00 +00 +00 +00 +00 +00 +00 +00 +00 +00 +00 +00 +00 +00 +00 +6a +75 +75 +75 +73 +74 +37 +00 +00 +00 +00 +00 +06 +00 +00 +00 +03 +01 +04 +00 +00 +00 +00 +00 +00 +00 +00 +00 +00 +00 +00 +00 +00 +00 +00 +00 +84 +00 +00 +00 +74 +68 +69 +73 +5f +69 +73 +5f +61 +5f +76 +65 +72 +79 +5f +6c +6f +6e +67 +5f +73 +65 +63 +74 +69 +6f +6e +5f +6e +61 +6d +65 +00 +61 +6e +6f +74 +68 +65 +72 +2e +6c +6f +6e +67 +2e +73 +65 +63 +74 +69 +6f +6e +00 +6f +6e +65 +6d +6f +72 +65 +78 +39 +00 +74 +68 +69 +73 +5f +69 +73 +5f +61 +5f +76 +65 +72 +79 +5f +6c +6f +6e +67 +5f +73 +65 +63 +74 +69 +6f +6e +5f +6e +61 +6d +65 +00 +61 +6e +6f +74 +68 +65 +72 +2e +6c +6f +6e +67 +2e +73 +65 +63 +74 +69 +6f +6e +00 +6f +6e +65 +6d +6f +72 +65 +78 +39 +00