Question

I tried to compile the following .asm file in VS2008 (as part of an empty Win32 dll project to which I added this single .asm file):

.386
.model flat, stdcall
option casemap:none

TRUE                        equ 1

.code
start:
DllEntry proc instance:DWORD, reason:DWORD, reserved:DWORD
    mov     eax, TRUE
    ret
DllEntry endp

CPUIDIsSupported proc uses ebx edx        
    mov  eax, 0

    pushfd
    pop  eax                    ; Get EFLAGS to EAX
    mov  ecx, eax               ; Preserve it in ECX

    xor  eax, 200000h           ; Check if CPUID bit can toggle
    push eax
    popfd                       ; Restore the modified EAX
                                ; to EFLAGS

    pushfd                      ; Get the EFLAGS again
    pop  ebx                    ; to EBX
    xor  eax, ebx               ; Has it toggled?
    and  eax, 200000h
    jnz  __not_supported        ; No? CPUID is not supported

    mov  eax, 1
    jmp  _ciis_ret_             ; Yes? CPUID is supported

    __not_supported:
    xor  eax, eax

    _ciis_ret_:
    push ecx                    ; Restore the original EFLAGS
    popfd

    ret
CPUIDIsSupported endp

.586
__cpuid proc stdcall public uses ebx edi __funcNumber:dword, __eax:dword, __ebx:dword, __ecx:dword, __edx:dword

    ; Must be 80586 and above
    call    CPUIDIsSupported
    dec     eax
    jz      _cpuid_begin_

    ; No CPUID instruction
    xor     eax, eax
    jmp     _cpuid_ret_

    _cpuid_begin_:
    mov     eax, __funcNumber
    cpuid

    mov     edi, __eax
    mov     dword ptr [edi], eax
    mov     edi, __ecx
    mov     dword ptr [edi], ecx
    mov     edi, __edx
    mov     dword ptr [edi], edx
    mov     edi, __ebx
    mov     dword ptr [edi], ebx

    mov     eax, 1

    _cpuid_ret_:
    ret
__cpuid endp

end start

The code was originally posted HERE.

When I build I get a warning:

warning LNK4086: entrypoint '_start' is not __stdcall with 12 bytes of arguments; image may not run

However, a .dll is generated.

When trying to use that dll I get an exception because "Unable to find entrypoint CPUIDIsSupported in dll"

But now here is the kicker:

If I compile exactly the same asm file in MASM32, I still get the LNK4086 but the dll can be properly called.

I would like to include the asm file in my VS2008 solution and build it from there instead of having to use MASM32. Therefore I would like to know what I need to change about my build process in order to get a working dll. Also I am interested to hear how I can create a 64 bit version of the dll from within VS2008.

Was it helpful?

Solution

Changing the end start to end DllEntry should fix the issues. VS2008 has a much newer version of ML to the one included with MASM32 and it may be more strict with regards to the entry point.

DllEntry and start are actually the same point, which is why the code runs. I would guess that when the warning appears no entry point is actually specified in the PE header.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top