scc

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

commit 089001cf022662342949760e254ee19f09123350
parent 0f79c5f471ea50fbe25862dfdf257f2e93387ac9
Author: Roberto E. Vargas Caballero <k0ga@shike2.com>
Date:   Thu, 21 Mar 2024 07:24:06 +0100

libmach/coff32: Set f_symptr in coff2write

The file f_symptr is a file offset that points to the symbol table, and
in case of having a symbol table it must be correctly set, but it was not.

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

diff --git a/src/libmach/coff32/coff32write.c b/src/libmach/coff32/coff32write.c @@ -338,13 +338,20 @@ coff32write(Obj *obj, Map *map, FILE *fp) ptr = ftell(fp); obj->pos = ptr; - ptr += FILHSZ + AOUTSZ + n*hdr->f_nscns; n = hdr->f_nscns; + ptr += FILHSZ + hdr->f_opthdr + n*SCNHSZ; for (scn = coff->scns; n--; scn++) { - scn->s_scnptr = ptr; - ptr += scn->s_size; + /* TODO: Check if the section is allocated */ + if (scn->s_flags & STYP_BSS) { + scn->s_scnptr = 0; + continue; + } else { + scn->s_scnptr = ptr; + ptr += scn->s_size; + } } + hdr->f_symptr = (hdr->f_nsyms > 0) ? ptr : 0; n = hdr->f_nscns; for (scn = coff->scns; n--; scn++) {