From bbfb3b311f37106cb6ddac19c5266dcff29756f2 Mon Sep 17 00:00:00 2001 From: "Magomed Kostoev (mkostoevr)" Date: Sun, 28 Feb 2021 15:28:03 +0000 Subject: [PATCH] [clink] Fill BSS section by zeroes git-svn-id: svn://kolibrios.org@8618 a494cfbc-eb01-0410-851d-a64ba20cac60 --- programs/develop/clink/main.c | 18 +++++++++++++++--- 1 file changed, 15 insertions(+), 3 deletions(-) diff --git a/programs/develop/clink/main.c b/programs/develop/clink/main.c index 0065dcaf2f..6ce0988f36 100644 --- a/programs/develop/clink/main.c +++ b/programs/develop/clink/main.c @@ -217,10 +217,22 @@ static void build(ObjectIr *ir) { if (!epep_get_section_header_by_index(epep, &sh, id.sec_id)) { ERROR_EPEP(epep); } - char *buf = malloc(sh.SizeOfRawData); - if (!epep_get_section_contents(epep, &sh, buf)) { - ERROR_EPEP(epep); + + // If the section contains uninitialized data (BSS) + // it should be filled by zeroes + // Yes, current implementation emits BSS sections too + // cause KOS has no idea they should be allocated automatically + // cause FASM has no idea they should be generated without contents + // cause Tomasz Grysztar didn't care + char *buf = calloc(sh.SizeOfRawData, 1); + + // Othervice it should be filled by its contents from source object + if (!(sh.Characteristics & 0x00000080)) { + if (!epep_get_section_contents(epep, &sh, buf)) { + ERROR_EPEP(epep); + } } + fwrite(buf, 1, sh.SizeOfRawData, out); } printf("Done.\n");