llvm 32bit with 64bit output?

I am looking at starting a project to make a toy language that is targeted
purely at 64bit windows. I have never used llvm or anything like it i am
just trying to learn new things.

However there are several problems, as far as i have seen, with compiling
llvm in 64bit on windows. So i was wondering if i compile a 32bit version of
llvm and use that can my resulting compiler output 64bit binaries?

Secondary question, should i use mingw or msvc to build llvm and my
compiler? i would like to use cygwin mingw but i think that still makes the
resulting binaries require cygwin1.dll but not sure if there is a way to get
out of that.

EDIT: To clarify i dont mind if i have to use cygwin (normal cygwin gcc or
mingw) solong as the binary my compiler outputs does not require cygwin1.dll
then i am happy. The compiler requiring cygwin1.dll is not so much of a
problem for me i just want my toy language/compiler to be win64 binaries
that do not require the cygwin1.dll.

You can generate 64-bit binaries with a 32-bit LLVM without any issue. The target machine in your case may differ from the "host target", but it shouldn't be any problem.

I have managed to compile LLVM on Windows using the compiler from Windows 7 SDK (and CMake). I don't remember what runtime binaries it required, but I guess it was the regular MSVC runtime.

-Krzysztof

At the moment i have set up cygwin using its llvm package to learn with and,
as i prefer developing in that unix style environment and using the command
line i will stick with that for a bit. Since you say a 32bit llvm can
generate 64bit binaries i also assume that they shouldnt require the cygwin
runtime (cygwin1.dll) but if it does i could at that point switch to mingw
with cygwin hopefully or if all else fails msvc.

Just so long as i can output the binaries i want, standalone 64bit binaries,
i dont mind what compiler toolchain or environment i use. However i do
prefer cygwin for now cause its easy and unix like unless it shoots me in
the foot with cygwin1.dll requirements.

Not sure if i will be able to make a compiler that will be able to have a
winmain to run the resulting binaries of my language without a console if
asked. But that is way way ahead of me haha, sorry. I digress.

Thanks Krysztof, it is very good to know finally so i can start working in
my little project.

LLVM will only generate object files. You will need to link them to get the final executable. This will determine whether (and if) you need any special DLLs. If your language allows the programmer to call functions provided by the OS, or some emulation of Unix's libc, then you will need to have some sort of a runtime library. In the simplest scenario, the runtime will simply be the standard Windows DLLs (kernel32.dll, etc.).

-Krzysztof

Correction: linking will associate your executable with specific libraries. Whether you need them or not will depend on the features that your language provides.

-Krzysztof

ah i see so even if i output the object files i want i would still need to
either link them with cygwin linker but tell it to not use cygwin1.dll but
say msvcrt.dll like the old -mno-cygwin for gcc used to do... or use the
mingw64-x86_64 linker instead if the cygwin one cant do that.

I believe general cygwin applications link in both kernel32.dll and
cygwin1.dll, not sure how much my language will need to fulfill its goals, i
want to be able to call c libraries and run a console-less application
allowing my language to at least basic graphical or gui tasks.

Come to think of it however if i want to link with the majority of graphical
libraries etc on windows i should probably move to msvc at some point then,
i guess that would solve these linking issues.

I am looking at starting a project to make a toy language that is targeted
purely at 64bit windows. I have never used llvm or anything like it i am
just trying to learn new things.

However there are several problems, as far as i have seen, with compiling
llvm in 64bit on windows. So i was wondering if i compile a 32bit version of
llvm and use that can my resulting compiler output 64bit binaries?

It would be possible with targetting x86_64-w64-mingw32, if you live
on cygwin or mingw-w64.
Note, JIT would not work with i686 binary. You shall build llvm with
x64 compilers (msvc x64, x86_64-w64-mingw32-g++) if you would use x64
JIT.

Currently, you will need x86_64-w64-mingw32's binutils, esp, ld.exe.
"LLVM" does not have linker driver or such. You will need to invoke
ld.exe in your application.

Depends on which host your application is built, cygwin, i686-mingw,
x86-64-mingw;

  - Seek "mingw-w64"
  - Install mingw-w64 binutils on cygwin. You may find
x86_64-w64-mingw32-ld.exe then.

Secondary question, should i use mingw or msvc to build llvm and my
compiler? i would like to use cygwin mingw but i think that still makes the
resulting binaries require cygwin1.dll but not sure if there is a way to get
out of that.

Theologically, llvm can be built for i686-mingw32 (free from
cygwin1.dll) on cygwin, like cross build.
I have not tried on cygwin.

/path/to/configure --host=i686-pc-mingw32 --build=i686-pc-cygwin

You may also try "MSYS", targetting for i686-mingw32, like subset of cygwin.

EDIT: To clarify i dont mind if i have to use cygwin (normal cygwin gcc or
mingw) solong as the binary my compiler outputs does not require cygwin1.dll
then i am happy. The compiler requiring cygwin1.dll is not so much of a
problem for me i just want my toy language/compiler to be win64 binaries
that do not require the cygwin1.dll.

As I mentioned above, you would need x64 JIT (built with x64) or
x64-aware linker.
In most cases, generated binaries would not need cygwin1.dll, but some
runtime libraries.

I suggest you to play with x86_64-w64-mingw32-gcc.exe on cygwin, at first.

ps. personally, I have not tested x86_64-mingw32 for one year. I am
afraid if it might be broken.

...Takumi

I did try the cygwin mingw-x86_64 but i couldn't get llvm to compile, but i
did try and compile clang and compiler_rt as well, may have to try again
soon. On windows i'm not interesting in i686 or any 32 bit compiling just 64
bit alone but i don't need a jit anyways for my language.

If i use the cygwin environment to build llvm do i have to use cmake or can
i use the standard configure scripts and make off of that. I know that cmake
can output msys and mingw makefiles but i thought they where for msys shells
and mingw being used from the windows command prompt, whereas cygwin being a
more or less complete posix environment emulation im not sure if it needs
cmake or which make system to output.

I did try the cygwin mingw-x86_64 but i couldn't get llvm to compile, but i
did try and compile clang and compiler_rt as well, may have to try again
soon. On windows i'm not interesting in i686 or any 32 bit compiling just 64
bit alone but i don't need a jit anyways for my language.

Ok. The host doesn't matter, either i686 or x86-64, as far as the
target triple is "x86_64-{mingw32|win32}".

As I said, PE+(x64)-aware linker and corresponding runtime libraries
(x86_64-w64-mingw32's libgcc or msvc runtime) would be required to
you.

It would be great if you could use compiler-rt for your target. AFAIK,
no one would try to use compiler-rt on x64.
(compiler-rt is libgcc's alternative in this case. *-mingw32 is expected)

If i use the cygwin environment to build llvm do i have to use cmake or can
i use the standard configure scripts and make off of that. I know that cmake
can output msys and mingw makefiles but i thought they where for msys shells
and mingw being used from the windows command prompt, whereas cygwin being a
more or less complete posix environment emulation im not sure if it needs
cmake or which make system to output.

On cygwin, configure is expected to work. I heard cmake would work as
well, though, I have not used cmake on cygwin.

Without cygwin, you may take cmake for mingw, not only msys. Ninja
build is better (than msys gnu make or mingw32-make) if you will play
llvm with cmake.

...Takumi