News:

Masm32 SDK description, downloads and other helpful links
Message to All Guests

Main Menu

MASM 6.15 produces Heisenbugs

Started by jj2007, December 13, 2020, 10:27:14 PM

Previous topic - Next topic

jj2007

Just a little warning:

Until now, I sometimes assembled my major sources with MASM version 6.15, because that is one of the early versions that is easy to get from the web, and because I generally care for backwards compatibility (I can't use the earlier 6.14 that comes with the Masm32 SDK because of SSE code in my sources).

Today I was struck the second time by an odd bug caused by this version. It is impossible to hunt it down (the source is over 40,000 lines), but it's pretty obvious that it produces, in very rare occasions, garbage; in this case, a wrong address that fortunately made my code crash.

The source assembles fine with MASM versions 8, 10 and 14, UAsm and AsmC. It is known that M$ made major changes between 6.15 and 8.0, so that might explain the problem.

The bug does not raise its ugly head in small sources; it is clearly related to the size of the source. This is not the first time I encounter such behaviour with version 6.15; sometimes I solved the problem by shuffling code around, i.e. moving macros and/or procs higher up or downwards. Now I have given up and will simply test occasionally if it still assembles with the higher MASM versions 8 to 10 (version 14 has other problems, not sure how the latest ones behave).

hutch--

Just a little warning:

Watcom derivatives are not MASM compatible.

_japheth

Quote from: jj2007 on December 13, 2020, 10:27:14 PM

in this case, a wrong address that fortunately made my code crash.

The bug does not raise its ugly head in small sources; it is clearly related to the size of the source.

I remember vaguely a similar bug ( perhaps identical ) in v6.15: it may occur if the first line of a procedure, when the assembler is about to generate the prologue, is a macro. That's why you may find NOPs at procedure's start in my code.
Dummheit, gepaart mit Dreistigkeit - eine furchtbare Macht.

jj2007

Quote from: _japheth on December 21, 2020, 05:45:40 PMif the first line of a procedure, when the assembler is about to generate the prologue, is a macro. That's why you may find NOPs at procedure's start in my code.

I can't confirm that one, see below, but I remember you had a dedicated page :cool:
include \masm32\include\masm32rt.inc

.code
MyTest proc arg
  mov ecx, ustr$(arg)
  print hex$(ecx), 13, 10
  print arg
  ret
MyTest endp
start:
  cls
  invoke MyTest, chr$("hello")
  exit
end start

hutch--

I wonder why so many MASM folks can use a variety of MASM versions yet the UASM / JWASM folks have so many problems. Is it that they are trying to compare the Watcom derivatives with MASM rather than successfully use MASM as so many have done ?

_japheth

Quote from: jj2007 on December 21, 2020, 09:42:25 PM
I can't confirm that one, see below, but I remember you had a dedicated page :cool:

Ok, I found some source with NOP at the procedure start, but this isn't to avoid wrong code being created -
it's to avoid weird listings. To see, assemble this code with "ml -c -Fl -Sg":



.386
.model flat,stdcall

@prologue macro procname,flag,parmbyte,localbyte,reglist,userparms

push ebp
mov ebp,esp
sub esp,localbyte

for r,reglist
push r
endm

exitm %localbyte
endm

@epilogue macro procname,flag,parmbyte,localbyte,reglist,userparms

for r,reglist
pop r
endm
mov esp, ebp
pop ebp
ret parmbyte
endm

.code

@someusefulmacro macro
xchg eax,eax
xchg ebx,ebx
xchg ecx,ecx
endm

option prologue:@prologue
option epilogue:@epilogue

testmacro proc public uses ebx p1:dword
local hr:DWORD
@someusefulmacro
mov eax,hr
ret
testmacro endp
end


the first line of the macro has disappeared in the listing, and it is somewhat out of alignment.
Dummheit, gepaart mit Dreistigkeit - eine furchtbare Macht.

jj2007

Quote from: _japheth on December 23, 2020, 03:40:34 PMthe first line of the macro has disappeared in the listing, and it is somewhat out of alignment.

Same for Masm 14.0:
00000007  90      1 exitm %04H
00000008  87 DB      1 xchg ebx,ebx
0000000A  87 C9      1 xchg ecx,ecx
0000000C  8B 45 FC mov eax,hr
ret