[clink] Fill BSS section by zeroes

git-svn-id: svn://kolibrios.org@8618 a494cfbc-eb01-0410-851d-a64ba20cac60
This commit is contained in:
Magomed Kostoev (mkostoevr) 2021-02-28 15:28:03 +00:00
parent 07643c3fde
commit bbfb3b311f

View File

@ -217,10 +217,22 @@ static void build(ObjectIr *ir) {
if (!epep_get_section_header_by_index(epep, &sh, id.sec_id)) { if (!epep_get_section_header_by_index(epep, &sh, id.sec_id)) {
ERROR_EPEP(epep); ERROR_EPEP(epep);
} }
char *buf = malloc(sh.SizeOfRawData);
// 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)) { if (!epep_get_section_contents(epep, &sh, buf)) {
ERROR_EPEP(epep); ERROR_EPEP(epep);
} }
}
fwrite(buf, 1, sh.SizeOfRawData, out); fwrite(buf, 1, sh.SizeOfRawData, out);
} }
printf("Done.\n"); printf("Done.\n");