The LLVM compiler toolchain has a gcc that is compatible with normal gcc. The advantage of using llvm-gcc is that is goes to an arbitrary target, meaning normal gcc will say no such target when you try to compile to a random architecture, say mips-apple-darwin. llvm-gcc will, however, actually build a compiler for Mac OS X on a mips processor.
Here's the catch however: to build to a random target, you need the binutils built for that target already. So if you have a target that llvm would compile to but binutils can't, then you can't make the compiler because the GNU Binutils doesn't support that target.
So... Here's the question: Is there an equivalent llvm-binutils like an llvm-gcc that is compatable with GNU Binutils? (meaning one that builds to an arbitrary target, not one from a list.)
EDIT:
By arbitrary, I mean I don't pick the target when I run llvm-gcc, I pick the target when I compile llvm-gcc. Meaning: If I try to compile GCC for mips-apple-darwin, I get a target not supported. But If I build llvm-gcc for mips-apple-darwin, it works as long as I have mips-apple-darwin-as and mips-apple-darwin-ld.
As far as I can tell, LLVM does not compile for an arbitrary target. You must have all includes and definition to fit your target, and normally, llvm has a back-end to generate code for your said target. Read "Can I compile C or C++ code to platform-independent LLVM bitcode?" from http://llvm.org/docs/FAQ.html .
To answer the question, llvm does not uses GNU binutils, llvm has its own 'binutils' to generate code (called LLVM core project). Disassembler and debugger are part of LLDB project.
Where LLVM bring some independence, it's on the language level. Your project can be coded in C/C++, Ada, Fortran, etc ... llvm come with the ability to transform your code in an intermediate representation. That IR will eventually generate code.
llvm-gcc doesn't support arbitrary targets. llvm-gcc has to be built specifically for any given target. clang + LLVM can. I'm trying to do exactly that with ellcc: http://ellcc.org. I'm using binutils for assembly and linking.
Related
I cloned and built the RISC-V GNU toolchain. I built the Newlib version for RV32I architecture(--with-arch=rv32i). However, I also need to have the RV32IM architecture build. Problem is, if I build the compiler for RV32IM, and compile my RISC-V code for RV32I, the compiler emulates multiply/divide operations for the RV32I architecture but still uses mul instrucions. I think this happens because there are mul instructions in the libgcc.a file, because that's the architecture it was built for. This is why I desire to have two seperate builds, i.e. RV32I and RV32IM.
Is this possible? If so, how can I achieve this?
I guess a multilib version could be built. riscv-none-embed-gcc-xpack is such a multilib version without libgloss, but I haven't delved into the details of implementation. Hope it'll help.
GCC is a compiler collection that generates machine code from different programming languages. For that you have to compile the compiler to run on your architecture and operating system. But you also have to define what kind of machine code and file format is generated.
Now my questions:
Is the output file of GCC only configurable at compilation time of GCC?
And can GCC be compiled so that it supports multiple architectures and file formats?
gcc and binutils are designed to build for one architecture/family at a time. So if you build them as a cross compiler for ARM then you cannot build mips, but you can have multiple/many installations so you can also build one to target mips and use that one.
clang/llvm if when you build you don't tell it not to it will build a tool for all targets it knows. This tool will get you up to the object level for any of the supported targets with the one tool, but linking is another story you need to tell it to builds its linker (and then I don't remember if the linker will support any target or one). You can use binutils to assemble/link for clang/llvm (and then you definitely have a single target assembler/linker).
How I can to know what is a minimal version of glibc for gcc or binutils?
Regards.
binutils doesn't generally have a minimal glibc requirement because it doesn't have too much glibc-specific details in it. it's merely a collection of low level tools like an assembler and linker and objdumper all of which are built on code included in binutils.
gcc is a different beast -- it needs to know intimate details about C library capabilities. in the specific version of gcc you have, consult the INSTALL/index.html file (and particularly, the Prerequisites page) for the requirements.
I want to compile a plugin for an application as a dynamic library. Usually, plugins are compiled with VisualC++, but I'd like to use G++. The SDK Documentation explicitly states
The compiler options for Pointer-to-member representation must be set to "General-Purpose Always" and "Point to Single-Inheritance Classes" in C++ tab/C++ language (/vmg /vms). If not set the plugin will crash instantly!
And indeed, it does crash instantly as soon as I pass values from my plugin to the application. Are there any options that result in the same behaviour as /vmg /vms in VisualC++?
Platform: Windows 7 x64
Compiler: MingW32 G++ 4.6.2
Since pointer-to-member representation is an implementation detail, and GCC ABI is not designed to be compatible with that of MSVC, there is never going to be an equivalent.
You will not be able to mix binaries compiled with said compilers as long as the working depends on implementation-specific (unspecified) details like the pointer representations.
I want to compile C# to LLVM IR. So I think translate compiled CIL to LLVM IR is one way I can try.
There are some tools I can use such as vmkit and mono-llvm.
Is anybody using this tools? Or how can I translate CIL to LLVM?
The answer depends on your goals. Why do you want to translate C# to LLVM?
VMKit was designed as a framework for building virtual machine implementations. I believe it had some support for the CLR at one point, but that support since stagnated in favor of its JVM implementation. Its purpose is to make building a VM from scratch.
Mono-llvm is a project that replaces the mono JIT backend with an LLVM back end. It's goal is to improve the performance of JITed code on Mono.
If your goal is to use Mono, with better performance, mono-llvm is a good choice.
If you want to build an entire VM from scratch, then VMKit might work.
If you are just looking to implement an ahead-of-time compiler that produces executables with no CLR dependencies, you can just download the LLVM core libraries from:
http://llvm.org/
Basically it would translate the CIL into a textual representation of LLVM IR and then use the LLVM APIs to compile it to native machine code.
I don't know if LLVM will generate object files for you. You may have to generate them yourself, but that's pretty easy. It's basically just stuffing the machine code into a data structure, building up string, section, and symbol tables, and then serializing everything to disk.
To get LLVM IR code from CIL you need to use the tool il2bc (other name C# Native) which you can download from http://csnative.codeplex.com/.
You just need to perform some simple steps.
Il2Bc.exe <Your DLL>.dll
If you want to generate an executable from it, you need to compile the generated .ll file (LLVM IR Code).
For example, you have your "Hello World" app
Compile it (it will generate a helloworld.ll file)
Il2Bc.exe helloworld.cs /corelib:CoreLib.dll
Generate LLVM IR file for the core library (it will generate corelib.ll file)
Il2Bc.exe CoreLib.dll
You need to generate an EXE file (it will generate a .EXE file):
llc -filetype=obj -mtriple=i686-w64-mingw32 CoreLib.ll
llc -filetype=obj -mtriple=i686-w64-mingw32 helloworld.ll
g++ -o helloworld.exe helloworld.obj CoreLib.obj -lstdc++ -lgc-lib -march=i686 -L .
I think I understand the question to be that you want to use LLVM IR in the same way that the GCC can compile Java using gcj?
The LLVM had an option to output CIL directly from whatever front end you used (So in theory you could do C/C++ to CIL). The following command options:
llc -march=msil
would output CIL from (in theory) any supported LLVM Front-End.
Going from C# or CIL to LLVM IR hasn't been done yet (or at least finished). You'd need a C# front-end.
VMKit had some kind of C# front end scaffolding. Support was never feature complete and interest has since faded. They've moved to just supporting Java. You might try their source repository and see if there are any remnants of their early C# work can be reworked into a full C# frontend.
Also note that you can write your own C# to LLVM IR compiler in C# (using Mono or whatever) and use P/Invoke to call into LLVM libraries and create LLVM IR. There are some good information out there such as Writing Your Own Toy Compiler Using Flex, Bison and LLVM.
This area is also getting interesting now that the compiler as a service (Roslyn) project has had its first couple of CTP releases, and Mono has its Mono.CSharp project. Though I think Roslyn is a bit more feature-rich.