#181 DDK headers: Undefined symbols __readgsword, _InterlockedOr

closed-fixed
nobody
header (101)
5
2010-07-23
2010-07-23
Henry N.
No

Hello,

since removing the "static" from "FORCEINLINE" in include/ntdef.h, have unresolved symbols __readgsword, _InterlockedOr and more.
I'm using sezero builds and copy over the DDK headers from SVN http://mingw-w64.svn.sourceforge.net/svnroot/mingw-w64/experimental/ddk_test.

Last working was SVN revision 2685.
First error have with SVN revision 2737.

Here is a simple example. Build with mingw-w64-bin_x86_64-linux_20100711_sezero.tar.gz and headers from experimental SVN r2737 or later will fail:

>>> cut driver.c >>>
#include <ntddk.h>

NTSTATUS
NTAPI
DriverEntry(
IN PDRIVER_OBJECT DriverObject,
IN PUNICODE_STRING RegistryPath)
{
return STATUS_NOT_IMPLEMENTED;
}
<<< end cut <<<

$ x86_64-w64-mingw32-gcc \ -Wall -Os -O2 -fms-extensions \ -I/tmp/gcc445/x86_64-w64-mingw32/include/ddk \ -c -o driver.o driver.c

$ x86_64-w64-mingw32-gcc \ -Wl,--subsystem,native \ -Wl,--image-base,0x10000 \ -Wl,--entry,DriverEntry \ -shared -nostartfiles -nostdlib \ -o driver.sys \ driver.o -lntoskrnl -lhal

driver.o:driver.c:(.text+0x5ea): undefined reference to `__readgsword'
driver.o:driver.c:(.text+0x772): undefined reference to `_InterlockedOr'
driver.o:driver.c:(.text+0x791): undefined reference to `_InterlockedOr'
driver.o:driver.c:(.text+0x7b1): undefined reference to `_InterlockedOr'
driver.o:driver.c:(.text+0x7c8): undefined reference to `__movsw'
driver.o:driver.c:(.text+0x7d7): undefined reference to `_InterlockedOr'
driver.o:driver.c:(.text+0x7f8): undefined reference to `__movsd'
driver.o:driver.c:(.text+0x807): undefined reference to `_InterlockedOr'
driver.o:driver.c:(.text+0x828): undefined reference to `__movsb'
driver.o:driver.c:(.text+0x837): undefined reference to `_InterlockedOr'
driver.o:driver.c:(.text+0x95e): undefined reference to `__stosb'
driver.o:driver.c:(.text+0x975): undefined reference to `__readcr8'
driver.o:driver.c:(.text+0x991): undefined reference to `__readcr8'
driver.o:driver.c:(.text+0x99d): undefined reference to `__writecr8'
driver.o:driver.c:(.text+0x9c6): undefined reference to `__readcr8'
driver.o:driver.c:(.text+0x9d3): undefined reference to `__writecr8'
driver.o:driver.c:(.text+0x9e6): undefined reference to `__readcr8'
driver.o:driver.c:(.text+0x9f3): undefined reference to `__writecr8'
driver.o:driver.c:(.text+0xa19): undefined reference to `_InterlockedExchangeAdd64'
driver.o:driver.c:(.text+0x60e): undefined reference to `__readgsqword'
driver.o:driver.c:(.text+0x62e): undefined reference to `__readgsqword'
driver.o:driver.c:(.text+0x64e): undefined reference to `__readgsqword'
driver.o:driver.c:(.text+0x7ec): undefined reference to `__movsw'
driver.o:driver.c:(.text+0x81c): undefined reference to `__movsd'
driver.o:driver.c:(.text+0x84c): undefined reference to `__movsb'
driver.o:driver.c:(.text+0x85f): undefined reference to `__outword'
driver.o:driver.c:(.text+0x87c): undefined reference to `__outdword'
driver.o:driver.c:(.text+0x88f): undefined reference to `__outbyte'
driver.o:driver.c:(.text+0x8ac): undefined reference to `__outwordstring'
driver.o:driver.c:(.text+0x8bc): undefined reference to `__outdwordstring'
driver.o:driver.c:(.text+0x8cc): undefined reference to `__outbytestring'
driver.o:driver.c:(.text+0x8dc): undefined reference to `__inword'
driver.o:driver.c:(.text+0x8ec): undefined reference to `__indword'
driver.o:driver.c:(.text+0x8fc): undefined reference to `__inbyte'
driver.o:driver.c:(.text+0x90c): undefined reference to `__inwordstring'
driver.o:driver.c:(.text+0x91c): undefined reference to `__indwordstring'
driver.o:driver.c:(.text+0x92c): undefined reference to `__inbytestring'
driver.o:driver.c:(.text+0x93f): undefined reference to `_bittest64'
driver.o:driver.c:(.text+0xa0c): undefined reference to `__writecr8'
collect2: ld returned 1 exit status

--
Henry N.

Discussion

  • Ozkan Sezer

    Ozkan Sezer - 2010-07-23

    Hmm, we always had that definition without the static in winnt.h, that is why I had removed that from ntdef.h at that time. Looking at r/os version of _mingw.h, they have the __forceinline with the extern keyword added while we do not.

    Kai, any insight on this? Do we really need static (or extern) with the __always_inline__ attribute?

     
  • Ozkan Sezer

    Ozkan Sezer - 2010-07-23

    ntddk.h has

    FORCEINLINE
    PKPCR
    KeGetPcr(VOID)
    {
    return (PKPCR)__readgsqword(FIELD_OFFSET(KPCR, Self));
    }

    And it seems like without the static (or probably extern) added to FORCEINLINE definition, it is actually generating code for that KeGetPcr() function, and since you are not linking to any standard libs, it cannot find the __readgsqword sym and fails.

    Still waiting Kai to respond.

    As a side note, this may be a deeper problem than it might look. in our main headers, we declare those MS intrinsics as __CRT_INLINE and not as static inline always_inline which means trouble will probably be waiting for us.

     
  • Ozkan Sezer

    Ozkan Sezer - 2010-07-23

    Added "extern" to __forceinline and FORCEINLINE definitions at all places, trunk@2936, v1.0@2937, ddk_test@2938.
    I think this should be fixed. Please verify.

     
  • Henry N.

    Henry N. - 2010-07-23
    • status: open --> closed-fixed
     
  • Henry N.

    Henry N. - 2010-07-23

    Yes, ddk_test@2938 works as before.
    Thanks.

     

Log in to post a comment.