Re: Compiler bug in the DDK--be aware of it



No one ever said that the DDK compiler was perfect, just that it was the
only supported compiler for device driver development. That still holds
true. So you found a bug? Are there others? Probably. I'm really glad that
the VS 2005 compiler does not have that bug, but I wander what other bugs it
does have? Does the VS compiler have equivalent bugs? I am very sure it
does. Oh yeah ... the biggest reason for not using the VS compiler ... it's
not a compiler supported by Microsoft for DDK work.

Serious? A showstopper? I think not. In 10 years of writting driver code,
that is the first time I have ever seen InterlockedOr used. In that time
frame I've found other compiler anomalies. In the 30 years I've been doing
this I've found them in every compiler or assembler I've ever used. I simply
adjust for them, or fix them if I am responsible for the build tools.

But thank you for publishing your findings, I'll be sure to not use
InterlockedOr, and use one of a dozen other ways to do the same thing.

--
The personal opinion of
Gary G. Little

<440gtx@xxxxxxxxx> wrote in message
news:1153830650.166359.4900@xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
Hi guys, I ran into a compiler bug in the latest ddk that is very
serious. I have a piece of code I want to execute exactly one time, but
discovered it gets run every single time. It is written as follows:


void func(void)
{
static LONG Init = 0;

if (InterlockedOr(&Init, 1) == 0)
{
...do one time stuff here...
}
}


The problem is the inner code executes every single time the function
is invoked. I traced it down to a bug in the compiler. I then
recompiled the driver using the Visual Studio 2005 compiler and the
problem was fixed. I have attached the code each generated below. I'm
now concerned about shipping any future drivers compiled using the DDK
build environment because I don't know what all functions besides this
particular example would generate corrupt code.



;------------------------------------;
; Windows 2003 DDK SP1 (3790.1830)
;------------------------------------;
mov ecx, 1
mov edx, OFFSET FLAT:?Init
mov eax, DWORD PTR [edx]
$L14033:
mov esi, eax
or esi, ecx
lock cmpxchg DWORD PTR [edx], esi
jne $L14033
jne $L14011

;------------------------------------
; Visual Studio 2005
;------------------------------------
mov ecx, 1
mov edx, OFFSET ?Init
mov eax, DWORD PTR [edx]
$LN4
mov esi, eax
or esi, ecx
lock cmpxchg DWORD PTR [edx], esi
jne SHORT $LN4
test eax, eax ; <---------fixed
jne SHORT $LN2



.



Relevant Pages

  • Re: compiler generated output
    ... compiler to generate code which only uses 386 instruction). ... Thus, while replacing mov/and with movzx, the jump is still there. ... 00000001`00001c65 66894c2408 mov,cx ...
    (comp.lang.asm.x86)
  • Re: Compiler bug in the DDK--be aware of it
    ... I am new to driver development. ... I traced it down to a bug in the compiler. ... mov edx, OFFSET FLAT:?Init ... mov esi, eax ...
    (microsoft.public.development.device.drivers)
  • Re: Help with running IBM-COBOL ver 1.0 on Windows 2000/XP
    ... 0BA3:17E9 xchg dx,ax ... 0BA3:17EE mov,al ... IBM Personal Computer COBOL Compiler ...
    (comp.lang.cobol)
  • Re: PCI Grafikkarte Empfehlung gesucht
    ... zusammen mit einer XOR-Operation (wohl aber für MOV). ... Solche Dinge machen es einem Compiler ... der Z80 kommt ja vom gleichen Vater: ... Der Witz einer Hochsprache ist es aber eben, eigentlich kein Assembler ...
    (de.comp.hardware.graphik)
  • Re: PCI Grafikkarte Empfehlung gesucht
    ... zusammen mit einer XOR-Operation (wohl aber für MOV). ... Solche Dinge machen es einem Compiler ... bei Intel mit dem 8080 fertig war und sich dort zerstritten hat, machte er seine eigene Firma Zilog auf und schuf den Z80. ... Also Register kann ich nie Genug bekommen. ...
    (de.comp.hardware.graphik)

Loading