Windows NT will not load drivers that do not have a correct checksum.
You can apply this patch to binutils to solve the problem:
http://sources.redhat.com/ml/binutils/2002-01/msg00395.html
It writes a checksum to a PE image.
Alternatively you can search for a tool that will do the same and use it on
an image generated with MinGW.
Here is an example of a makefile that will generate a .sys file that Windows
NT will load (if ld has the checksum patch applied).
TOOLBASE = /usr/local/cross-tools/bin
GCC = $(TOOLBASE)/i386-mingw32msv-gcc
DLLTOOL = $(TOOLBASE)/i386-mingw32msv-dlltool
BASENAME = null
FULLNAME = $(BASENAME).sys
CFLAGS = -I../
OBJECTS = $(BASENAME).o
DDKLIBS = ntoskrnl.a
all: $(FULLNAME)
$(FULLNAME): $(OBJECTS)
$(GCC) -Wl,--base-file,base.tmp -Wl,--entry,_DriverEntry -nostartfiles -nostdlib -o junk.tmp $(OBJECTS) $(DDKLIBS)
$(DLLTOOL) --dllname $(FULLNAME) --base-file base.tmp --output-exp temp.exp
$(GCC) $(TARGET_LFLAGS) -Wl,--subsystem,native -Wl,--image-base,0x10000 -Wl,--file-alignment,0x1000 -Wl,--section-alignment,0x1000 -Wl,--entry,_DriverEntry -Wl,temp.exp -mdll -nostartfiles -nostdlib -o $(FULLNAME) $(OBJECTS) $(DDKLIBS)
%.o: %.c
$(GCC) $(CFLAGS) -c $< -o $@
///////////////////////////////////////////////////////////////////////////////////////////////
Is the use of DLLTOOL really needed ? I though ld could now generate the dll
relocation data automatically. Would this be enough:
$(FULLNAME): $(OBJECTS)
$(GCC) $(TARGET_LFLAGS) -Wl,--subsystem,native -Wl,--entry,_DriverEntry -shared -nostartfiles -nostdlib -o $(FULLNAME) $(OBJECTS) $(DDKLIBS)