Skip to content

Commit

Permalink
mz format: stack written if not last segment
Browse files Browse the repository at this point in the history
  • Loading branch information
Baron-von-Riedesel committed Jun 17, 2024
1 parent ab8a297 commit 768b7ea
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 12 deletions.
7 changes: 7 additions & 0 deletions History.txt
Original file line number Diff line number Diff line change
@@ -1,6 +1,13 @@

Changelog

__.__.____, v2.19:

Bugfixes:

- format mz: stack segment was never written. That's a fault if it isn't
located at the end of the binary; see stack1.asm.

09.06.2024, v2.18:

Bugfixes:
Expand Down
4 changes: 2 additions & 2 deletions src/H/globals.h
Original file line number Diff line number Diff line change
Expand Up @@ -184,8 +184,8 @@ char *strupr(char *);
#include "queue.h"

/* JWasm version info */
#define _JWASM_VERSION_STR_ "2.18"
#define _JWASM_VERSION_INT_ 218
#define _JWASM_VERSION_STR_ "2.19"
#define _JWASM_VERSION_INT_ 219
#define _JWASM_VERSION_SUFFIX_ ""
#define _JWASM_VERSION_ _JWASM_VERSION_STR_ _JWASM_VERSION_SUFFIX_

Expand Down
33 changes: 23 additions & 10 deletions src/bin.c
Original file line number Diff line number Diff line change
Expand Up @@ -239,8 +239,10 @@ static void CalcOffset( struct dsym *curr, struct calc_param *cp )
DebugMsg(("CalcOffset(%s): abs seg, offset=%" I32_SPEC "Xh\n",
curr->sym.name, curr->e.seginfo->start_offset ));
return;
} else if ( curr->e.seginfo->information )
} else if ( curr->e.seginfo->information ) {
DebugMsg(("CalcOffset(%s): info seg, ignored\n", curr->sym.name ));
return;
}

grp = (struct dsym *)curr->e.seginfo->group;
if ( cp->alignment > curr->e.seginfo->alignment )
Expand All @@ -265,7 +267,7 @@ static void CalcOffset( struct dsym *curr, struct calc_param *cp )
/* v2.13: sizebss removed */
//offset = cp->fileoffset + cp->sizebss - cp->sizehdr; // + alignbytes;
offset = cp->fileoffset - cp->sizehdr; // + alignbytes;
DebugMsg(("CalcOffset(%s): ofs=%" I32_SPEC "Xh\n", curr->sym.name, offset ));
DebugMsg(("CalcOffset(%s): no group, ofs=%" I32_SPEC "Xh\n", curr->sym.name, offset ));
} else {
/* grp->sym.included is FALSE for the first segment of the group.
*/
Expand All @@ -275,7 +277,7 @@ static void CalcOffset( struct dsym *curr, struct calc_param *cp )
grp->sym.offset = cp->fileoffset - cp->sizehdr;
grp->sym.included = TRUE;
offset = 0;
DebugMsg(("CalcOffset(%s): first segment of group, grp.ofs initialized\n", curr->sym.name ));
DebugMsg(("CalcOffset(%s): first segment of group %s, grp.ofs initialized\n", curr->sym.name, grp->sym.name ));
} else {
/* v2.12: the old way wasn't correct. if there's a segment between the
* segments of a group, it affects the offset as well ( if it
Expand Down Expand Up @@ -329,7 +331,12 @@ static void CalcOffset( struct dsym *curr, struct calc_param *cp )
;
else
#endif
#if MZ_SUPPORT
/* v2.19: changed */
cp->fileoffset += (ModuleInfo.sub_format == SFORMAT_MZ ) ? curr->sym.max_offset : curr->sym.max_offset - curr->e.seginfo->start_loc;
#else
cp->fileoffset += curr->sym.max_offset - curr->e.seginfo->start_loc;
#endif

//if ( cp->first && ModuleInfo.sub_format == SFORMAT_NONE ) {
if ( ModuleInfo.sub_format == SFORMAT_NONE ) {
Expand Down Expand Up @@ -1864,7 +1871,6 @@ static ret_code bin_write_module( struct module_info *modinfo )
SortSegments( 1 );
}
for( curr = SymTables[TAB_SEG].head; curr; curr = curr->next ) {
/* ignore absolute segments */
CalcOffset( curr, &cp );
DebugMsg(("bin_write_module(%s): start ofs=%" I32_SPEC "Xh, size=%" I32_SPEC "Xh, file ofs=%" I32_SPEC "Xh, grp=%s\n",
curr->sym.name, curr->e.seginfo->start_offset, curr->sym.max_offset - curr->e.seginfo->start_loc, curr->e.seginfo->fileoffset, (curr->e.seginfo->group ? curr->e.seginfo->group->name : "NULL" )));
Expand All @@ -1879,9 +1885,10 @@ static ret_code bin_write_module( struct module_info *modinfo )
// return( ERROR );
DoFixup( curr, &cp );
#if MZ_SUPPORT
if ( stack == NULL &&
curr->e.seginfo->combine == COMB_STACK )
if ( stack == NULL && curr->e.seginfo->combine == COMB_STACK ) {
stack = curr;
DebugMsg(("bin_write_module: %s set as stack segment\n", curr->sym.name ));
}
#endif
}
/* v2.04: return if any errors occured during fixup handling */
Expand Down Expand Up @@ -2002,13 +2009,19 @@ static ret_code bin_write_module( struct module_info *modinfo )
continue;
}
#if PE_SUPPORT
if ( ModuleInfo.sub_format == SFORMAT_PE &&
if ( modinfo->sub_format == SFORMAT_PE &&
( curr->e.seginfo->segtype == SEGTYPE_BSS || curr->e.seginfo->information ) )
size = 0;
else
else
#endif
/* v2.05: changed */
/* v2.19: don't do this for MZ */
//size = curr->sym.max_offset - curr->e.seginfo->start_loc;
#if MZ_SUPPORT
size = ( modinfo->sub_format == SFORMAT_MZ ) ? curr->sym.max_offset : curr->sym.max_offset - curr->e.seginfo->start_loc;
#else
size = curr->sym.max_offset - curr->e.seginfo->start_loc;
#endif
/* v2.05: changed */
size = curr->sym.max_offset - curr->e.seginfo->start_loc;
//size = sizemem;
sizemem = bFirst ? size : curr->sym.max_offset;
/* if no bytes have been written to the segment, check if there's
Expand Down

0 comments on commit 768b7ea

Please sign in to comment.