commit 38ab22d6380b1d1c6fa232fa2ee5ef42b4faa77d
parent 1d8b58777ed0e762dd3e79218ed951e05c5e2dff
Author: Roberto E. Vargas Caballero <k0ga@shike2.com>
Date: Fri, 22 Mar 2024 05:12:04 +0100
libmach/coff32: Don't write non allocated sections
Sections not allocated don't have bytes in the output file, thus we have
to skip them we write the data section of them.
Diffstat:
1 file changed, 7 insertions(+), 0 deletions(-)
diff --git a/src/libmach/coff32/coff32write.c b/src/libmach/coff32/coff32write.c
@@ -313,9 +313,16 @@ writedata(Obj *obj, Map *map, FILE *fp)
nsec = hdr->f_nscns;
for (scn = coff->scns; nsec--; scn++) {
+ /* TODO: check if the section is allocated */
+ if (scn->s_flags & STYP_BSS)
+ continue;
+
if ((id = findsec(map, scn->s_name)) < 0)
return 0;
sec = &map->sec[id];
+ if (!sec->fp)
+ return 0;
+
fseek(sec->fp, sec->offset, SEEK_SET);
for (n = sec->end - sec->begin; n > 0; n--)