scc

simple c99 compiler
git clone git://git.simple-cc.org/scc
Log | Files | Refs | Submodules | README | LICENSE

commit 5ef656fab165f6689f688dc814fc30a1ec74b3aa
parent da56b0600b1cc39554afe7ee0e6b64c59678ace8
Author: Roberto E. Vargas Caballero <k0ga@shike2.com>
Date:   Mon, 23 Oct 2023 16:59:06 +0200

libmach/coff32: Support writing ent names > 8

Coff supports directly symbol names longer than 8 using a string table,
but the code was assuming that al the names were smaller than 8 and it
was not using the string table ever.

Diffstat:
Msrc/libmach/coff32/coff32write.c | 23+++++++++++++----------
1 file changed, 13 insertions(+), 10 deletions(-)

diff --git a/src/libmach/coff32/coff32write.c b/src/libmach/coff32/coff32write.c @@ -159,7 +159,7 @@ static int writeents(Obj *obj, FILE *fp) { long i, len, strsiz; - char *strtbl, *s; + char *strtbl, *s, *name; FILHDR *hdr; struct coff32 *coff; unsigned char buf[SYMESZ]; @@ -176,15 +176,18 @@ writeents(Obj *obj, FILE *fp) for (i = 0; i < hdr->f_nsyms; i++) { SYMENT *ent = &coff->ents[i]; - len = strlen(ent->n_name) + 1; - if (len > strsiz - LONG_MAX) - goto err; - s = realloc(strtbl, strsiz + len); - if (!s) - goto err; - memcpy(s + strsiz, ent->n_name, len); - strtbl = s; - strsiz += len; + if (ent->n_zeroes == 0) { + name = &coff->strtbl[ent->n_offset]; + len = strlen(name) + 1; + if (len > strsiz - LONG_MAX) + goto err; + s = realloc(strtbl, strsiz + len); + if (!s) + goto err; + memcpy(s + strsiz, name, len); + strtbl = s; + strsiz += len; + } pack_ent(ORDER(obj->type), buf, ent); if (fwrite(buf, SYMESZ, 1, fp) != 1)