Author Topic: Microsoft MASM bug  (Read 1637 times)

jj2007

  • Member
  • *****
  • Posts: 8616
  • Assembler is fun ;-)
    • MasmBasic
Microsoft MASM bug
« on: August 29, 2017, 08:25:15 PM »
Our friend José inspired me to drop important other work and investigate into the behaviour of his favourite tools:
Good rules dictate that developers must always use the latest versions of their tools. That's what I do. Check with release 14 of MASM then.

Here is a tiny little test routine:
Code: [Select]
include \masm32\include\masm32rt.inc

.code
txEbx db " ebx", 13, 10, 0
txLE db "lesser or equal", 13, 10, 0
start:
  mov esi, offset txLE
  or ebx, -1
  useCRT=0
  .Repeat
print str$(ebx)
print offset txEbx
int 3
.if sdword ptr ebx<=0
nop
if useCRT
invoke crt_printf, esi
else
print esi
endif
.endif
int 3
.if ebx<=sdword ptr 0
nop
if useCRT
invoke crt_printf, esi
else
print esi
endif
.endif
inc  ebx
  .Until !Zero?
  pop eax
  inkey
  exit
end start

The output looks like this, of course:
Code: [Select]
-1 ebx
lesser or equal
lesser or equal
0 ebx
lesser or equal
lesser or equal

This builds and runs fine with UAsm, JWasm, AsmC, and MASM, versions 6.14, 6.15, 8.0, 9.0, 10.0. For example, with useCRT=0 and the int 3's enabled, MASM 10.0 generates the following code:
Code: [Select]
CC                   ³int3
83FB 00              ³cmp ebx, 0                 ; .if sdword ptr ebx<=0
7F 07                ³jg short 0040104D
90                   ³nop
56                   ³push esi                   ; ÚArg1
E8 AB000000          ³call StdOut                ; Àsdword_ptr_encodings.StdOut
CC                   ³int3
81FB 00000000        ³cmp ebx, 0                 ; .if ebx<=sdword ptr 0
7F 07                ³jg short 0040105D
90                   ³nop
56                   ³push esi                   ; ÚArg1
E8 9B000000          ³call StdOut                ; Àsdword_ptr_encodings.StdOut

Straightforward, nothing unusual in there... now try with MASM version 14.0:
Code: [Select]
CC                   ³int3
83FB 00              ³cmp ebx, 0
7F 06                ³jg short 004011AC      ; *** invalid address, should be ..AD
90                   ³nop
56                   ³push esi
E8 BBFEFFCB          Àcall CC401068              ; *** invalid pointer
81FB 00000000        cmp ebx, 0
7F 06                jg short 004011BB
90                   nop
56                   push esi
E8 ACFEFF42          call 43401068              ; *** valid pointer

There are more crappy surprises, if you use useCRT=1 or switch between debug and release mode. It seems that ML 14.0 is unusable for serious work. Not as bad as CrippleWareTM ML64 perhaps, but still... crashing applications won't be popular 8)

Nice example when using the CRT:
Code: [Select]
004011B1              .  81FB 00000000        cmp ebx, 0
004011B7              . 7F 0A                jg short 004011C3
004011B9              .  90                   nop
004011BA              .  56                   push esi                    ; ³format
004011BB              .  FF15 B4304000        call near [<&msvcrt.printf> ; ÀMSVCRT.printf
004011C1              .  83C4 43              add esp, 43     ; <<<<<<<<<<<< YEAH!!
004011C4              . 74 BB                je short 00401181

Testbed and ML 14.0 executable attached (has int 3s, so it will definitely "crash")

AW

  • Member
  • *****
  • Posts: 1394
  • Let's Make ASM Great Again!
Re: Microsoft MASM bug
« Reply #1 on: August 29, 2017, 08:35:24 PM »
@JJ
Is the masm32rt.inc distributed by Microsoft or are you simply happy to use it?
Should Microsoft adapt MASM to the masm32rt.inc?

hutch--

  • Administrator
  • Member
  • ******
  • Posts: 5653
  • Mnemonic Driven API Grinder
    • The MASM32 SDK
Re: Microsoft MASM bug
« Reply #2 on: August 29, 2017, 08:37:22 PM »
I don't know what you guys are whinging about, MASM has always had "features" that you needed to be highly familiar with.  :P
hutch at movsd dot com
http://www.masm32.com    :biggrin:  :biggrin:

jj2007

  • Member
  • *****
  • Posts: 8616
  • Assembler is fun ;-)
    • MasmBasic
Re: Microsoft MASM bug
« Reply #3 on: August 29, 2017, 09:22:45 PM »
MASM has always had "features" that you needed to be highly familiar with.  :P

I know, I know... but some of these features have not been officially announced or documented by M$. Here is a test with the other ML.exe included in VS 14.0 (same code as above):

C:\Program Files (x86)\Microsoft Visual Studio 14.0\VC\bin\amd64_x86\ml.exe
Code: [Select]
\masm32\include\windows.inc(24749)size
\masm32\include\windows.inc(24749) : error A2042:statement too comMicrosoft (R) Macro Assembler Version 14.00.24210.0
Copyright (C) Microsoft Corporation

The error message looks garbled and no, that's not my fault :icon_cool:

@JJ
Is the masm32rt.inc distributed by Microsoft or are you simply happy to use it?
Should Microsoft adapt MASM to the masm32rt.inc?

So far I was happy to use masm32rt.inc, all my 5,000+ assembler sources work just fine with masm32rt.inc. But now that your "rules" dictate that one has to use the latest tools from Micros**t, I may have to look for an alternative SDK. Do you have one that you can recommend, José?

AW

  • Member
  • *****
  • Posts: 1394
  • Let's Make ASM Great Again!
Re: Microsoft MASM bug
« Reply #4 on: August 29, 2017, 09:41:13 PM »
So far I was happy to use masm32rt.inc, all my 5,000+ assembler sources work just fine with masm32rt.inc. But now that your "rules" dictate that one has to use the latest tools from Micros**t, I may have to look for an alternative SDK. Do you have one that you can recommend, José?
Normally, I don't use 3rd party include files. I don't like blind dates.

hutch--

  • Administrator
  • Member
  • ******
  • Posts: 5653
  • Mnemonic Driven API Grinder
    • The MASM32 SDK
Re: Microsoft MASM bug
« Reply #5 on: August 29, 2017, 11:20:02 PM »
The content of the runtime include files is no mystery, its a plain text file that anyone can read. Its done as a convenience so people do not have to look up which function is in which include file, it also puts the files in the right order as far as having the equates and structures first.
hutch at movsd dot com
http://www.masm32.com    :biggrin:  :biggrin:

AW

  • Member
  • *****
  • Posts: 1394
  • Let's Make ASM Great Again!
Re: Microsoft MASM bug
« Reply #6 on: August 29, 2017, 11:40:11 PM »
The content of the runtime include files is no mystery, its a plain text file that anyone can read. Its done as a convenience so people do not have to look up which function is in which include file, it also puts the files in the right order as far as having the equates and structures first.
I am not saying that the include directory is not valuable, it is valuable.  :t

jj2007

  • Member
  • *****
  • Posts: 8616
  • Assembler is fun ;-)
    • MasmBasic
Re: Microsoft MASM bug
« Reply #7 on: July 19, 2018, 11:22:40 PM »
The MASM bug in ML versions 14 and higher hit me again, therefore here a very short demo:
Code: [Select]
include \masm32\include\masm32rt.inc

.code
start:
  xor ebx, ebx
  m2m esi, 9
  .While ebx<esi && sdword ptr esi>=0
print str$(ebx), " "
inc ebx
  .Endw
  inkey chr$(13, 10, "ML14+ sucks")
  exit

end start

An even shorter version without the print statement:
Code: [Select]
  int 3
  .While ebx<esi && sdword ptr esi>=0
inc ebx
  .Endw
  nop
  nop

Note there are two nops. Now the disassembly:
Code: [Select]
00401105             .  CC                   int3
00401106             . EB 01                jmp short 00401109
00401108             .  43                   inc ebx
00401109             >  3BDE                 cmp ebx, esi
0040110B             . 73 04                jae short 00401111   ; BUG ************
0040110D             .  83FE 00              cmp esi, 0
00401110             . 7D 90                jge short 004010A2   ; BUG ************
00401112             .  90                   nop
00401113             .  68 00204000          push offset 00402000          ; ÚArg1 = ASCII CR,LF,"ML14+ sucks"
One of the two nops disappeared, and the jge short 004010A2 is a jump to no man's land 8)

ML 10.00.40219.01 still behaves OK. Grateful if somebody can test it with ML 11 ... 13 or higher ML versions. Maybe they have fixed the bug. In any case, my recommendation: UAsm :t

hutch--

  • Administrator
  • Member
  • ******
  • Posts: 5653
  • Mnemonic Driven API Grinder
    • The MASM32 SDK
Re: Microsoft MASM bug
« Reply #8 on: July 20, 2018, 12:25:40 AM »
 :biggrin:

You know how I sob silently about MASM bugz, you just call them features and get on with it.  :P

The later version have a new feature, the error messages are unintelligible where the older ones tended to make sense. You tell the men from the boys by the paper they use (large sheet of XXXX sandpaper in the loo), MASM is an industrial tool, don't expect it to hold you hand, it will bite it instead.  :badgrin:
hutch at movsd dot com
http://www.masm32.com    :biggrin:  :biggrin:

AW

  • Member
  • *****
  • Posts: 1394
  • Let's Make ASM Great Again!
Re: Microsoft MASM bug
« Reply #9 on: July 20, 2018, 01:29:37 AM »
For reporting bugs, Microsoft has a Virtual Agent with optional contact with a real person along the process at:
https://support.microsoft.com/en-us

I had not tried it yet.  ::)

But the best approach is probably from here:
https://developercommunity.visualstudio.com/spaces/8/index.html

I had not tried it as well, but this one might work.    :idea:

Later:
Yeap, I found a bug under investigation here:
https://developercommunity.visualstudio.com/search.html?f=&type=question+OR+problem+OR+idea&type=question+OR+problem+OR+idea&c=&redirect=search%2Fsearch&sort=relevance&q=MASM+14.0+.if+signed+comparison+bug

Probably someone from here can advance and report the other bugs.

jj2007

  • Member
  • *****
  • Posts: 8616
  • Assembler is fun ;-)
    • MasmBasic
Re: Microsoft MASM bug
« Reply #10 on: July 20, 2018, 04:14:36 AM »
makteam provides a solution, too:
Quote
One potential workaround is to insert a nop before the .endif:

.if sbyte ptr al >= "a"
sub al, 20h
if @Version ge 1400
nop
endif
;compat
.endif

(The nop gets consumed by the bug leaving only intended code.)

zedd151

  • Member
  • ****
  • Posts: 847
Re: Microsoft MASM bug
« Reply #11 on: July 20, 2018, 06:28:50 AM »
makteam provides a solution, too:




Interesting, but does it work?
I'm not always the sharpest knife in the drawer, but I have my moments.  :P

jj2007

  • Member
  • *****
  • Posts: 8616
  • Assembler is fun ;-)
    • MasmBasic
Re: Microsoft MASM bug
« Reply #12 on: July 20, 2018, 11:59:00 AM »
No. That's why I proposed the other solution: use UAsm :P

hutch--

  • Administrator
  • Member
  • ******
  • Posts: 5653
  • Mnemonic Driven API Grinder
    • The MASM32 SDK
Re: Microsoft MASM bug
« Reply #13 on: July 20, 2018, 01:08:35 PM »
> No. That's why I proposed the other solution: use UAsm

MASM has been around for over 35 years, should we hold our breath waiting for the alternatives ?  :P

Watcom died in the arse, JWASM barely made 5 years and MASM is still going strong, should we be worried ?  :lol:
hutch at movsd dot com
http://www.masm32.com    :biggrin:  :biggrin:

daydreamer

  • Member
  • ***
  • Posts: 499
Re: Microsoft MASM bug
« Reply #14 on: July 20, 2018, 03:23:57 PM »
Do the newer masm also have the bug,where it takes time ala a coffee break while using big numbers in DUP?
Quote from Flashdance
Nick  :  When you give up your dream, you die.
*wears a flameproof asbestos suit*