LLVM/Clang Windows XP 32bit - MessageBox

Hello.

I have downloaded CLANG 3.0 and successfuly build on Windows XP.
Now I tried to compile this simple MessageBox Win32 Api program:

#include <windows.h>

int APIENTRY WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdShow) {
MessageBox(NULL, "hello msgbox world\n", "Title", MB_OK);
return 0;
}

I did it this way:

clang -c -emit-llvm main.c
llc -filetype obj main.o -o test.obj
link test.obj user32.lib msvcrt.lib

But when I run test.exe I get : The procedure entry point InterlockedCompareExchange64 could not be located in dynamic link library KERNEL32.dll.

So I dissassembled main.o and there is usage of: (attached to mail)

declare dllimport x86_stdcallcc i64 @InterlockedCompareExchange64(i64*, i64, i64)

But I think this is valid only for 64bit or Vista and more.
So I deleted whole stuff which is not needed to compile it.
Then with:

llvm-dis main.o
edit main.o.ll --remove 64bit stuff
llvm-as main.o.ll -o main.o
llc -filetype obj main.o -o test.obj
link test.obj user32.lib msvcrt.lib

And I got valid test.exe application, which also works.

So my question is: Is this Adding of unwanted stuff correct or is it some kind of bug?

Peter.

main.o.ll (26.6 KB)

Hello.

I have downloaded CLANG 3.0 and successfuly build on Windows XP.
Now I tried to compile this simple MessageBox Win32 Api program:

#include <windows.h>

int APIENTRY WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdShow) {
MessageBox(NULL, “hello msgbox world\n”, “Title”, MB_OK);
return 0;
}

I did it this way:

clang -c -emit-llvm main.c
llc -filetype obj main.o -o test.obj
link test.obj user32.lib msvcrt.lib

But when I run test.exe I get : The procedure entry point InterlockedCompareExchange64 could not be located in dynamic link library KERNEL32.dll.

So I dissassembled main.o and there is usage of: (attached to mail)

declare dllimport x86_stdcallcc i64 @InterlockedCompareExchange64(i64*, i64, i64)

But I think this is valid only for 64bit or Vista and more.
So I deleted whole stuff which is not needed to compile it.
Then with:

llvm-dis main.o
edit main.o.ll --remove 64bit stuff
llvm-as main.o.ll -o main.o
llc -filetype obj main.o -o test.obj
link test.obj user32.lib msvcrt.lib

And I got valid test.exe application, which also works.

So my question is: Is this Adding of unwanted stuff correct or is it some kind of bug?

Did you define the winver macro correctly? Does the problem still occur then?

Ruben

Hello.

Adding this:

#define WINVER 0x0500
#define _WIN32_WINNT 0x0500

before include of <windows.h> helped.

Thanks a lot.

P.S. I attached disassembled main.o, becuase I don’t know if the generated stuff is needed in that bc file.

main.o.ll (15.8 KB)