Skip to content

Commit

Permalink
Bugfix: Emit zeroes as BSS section contents
Browse files Browse the repository at this point in the history
  • Loading branch information
mkostoevr authored Feb 28, 2021
1 parent 4e4fe56 commit 4e4efbf
Showing 1 changed file with 15 additions and 3 deletions.
18 changes: 15 additions & 3 deletions main.c
Original file line number Diff line number Diff line change
Expand Up @@ -214,10 +214,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");
Expand Down

0 comments on commit 4e4efbf

Please sign in to comment.