Compiling for Cortex M3 bare metal - c++11

Is there a guide somewhere that describes how to get LLVM to emit a binary for Cortex-M3 that I can massage into running bare metal? I've spent considerable time playing with LLVM on Windows and Ubuntu to no avail. I can get ARM-like assembly out. I can get bit code out, but what I really need is ELF, DWARF, Hobbit, Gandalf or any other Lord of the Rings critter that has a file format specification. Any and all help appreciated! I'm compiling LLVM 3.4 with CLANG on Ubuntu, Windows and/or OS X.

I created a firmware framework - PolyMCU https://github.com/labapart/polymcu - that is based on CMake that support GCC and LLVM. Because it is based on CMake you can build your firmware on Linux/Windows/MacOS.
It also uses Newlib and supports Baremetal/CMSIS RTOS (RTX)/FreeRTOS.
The benefit of using PolyMCU is this framework does not add any software layer on top of the libc and the MCU vendor's SDKs.
Another benefit is you can easily switch toolchains. I used this feature to get more feedback on my code by testing it with many compilers.
I also wrote a blog where I compared GCC and LLVM build size on ARM Cortex-M: http://labapart.com/blogs/3-the-importance-of-the-toolchain-version-in-embedded-space Interesting results, Clang generated code is not much bigger than GCC on Cortex-M...

The best guide that I know of is here: http://wiki.osdev.org/LLVM_Cross-Compiler. It's mostly about building an LLVM cross-compiler, but it does show a "Usage" section. However, that section specifically shows an example for a Cortex-A processor, but you should be able to get the general idea.
I have created an simple clang bare metal Cortex-M3 "hello world" program, but I don't have it in front of me. IIRC, the only options I needed were -march=thumb -mcpu=cortex-m3 as long as the LLVM compiler backend was built with the ARM thumb backend support (Again, see http://wiki.osdev.org/LLVM_Cross-Compiler). I did, however, need to link with arm-none-eabi-ld from the GCC toolchain here (http://launchpad.net/gcc-arm-embedded), and I believe that is how you can get your ELF binary.
I've since moved on to the D programming language, and I have a simple example using LDC (The LLVM D compiler) here (http://wiki.dlang.org/Extremely_minimal_semihosted_%22Hello_World%22)
So, I believe compiling bare metal ARM Cortex-M3 software with LLVM can be done, but it seems not many people have tried.

It is possible to use clang++ pulled from http://llvm.org/builds with https://launchpad.net/gcc-arm-embedded as a base, at least for the compile step.
Required extra arguments are the include paths hardcoded into gcc and certain arm-none-eabi defaults:
--target=arm-none-eabi -fshort-enums -isystem "../arm-none-eabi/include/c++/5.2.1" [-isystem ...]

Related

Is it possible to build gcc 1.0 without a C compiler?

Is it possible to build gcc 1.0 with only an assembler, without any C compilers? If it is possible, how can I build it? If it is not possible, how did the first C compiler come out?
Let's say if we have a new architecture of CPU with a new set of instructions, and the only software that has been made for it, is the assembler, then how can I build a gcc compiler for it?
Early versions of GCC were written in C. At the time, the operating systems GCC targeted came with at least a rudimentary C compiler (maybe for K&R C only, without support for prototypes). There was no bootstrap from assembler code involved, even in the first release. For those who did not or could not build GCC by themselves, the FSF provided pre-built binaries on tape, for a fee.
Support for new architectures (if they support self-hosting at all) was and still is implemented using cross-compilers.

What it takes to make OpenACC/OpenMP4.0 offloading to nvidia/mic work om GCC?

I am trying to understand how exactly I can use OpenACC to offload computation to my nvidia GPU on GCC 5.3. The more I google things the more confused I become. All the guides I find, they involve recompiling the entire gcc along with two libs called nvptx-tools and nvptx-newlib. Other sources say that OpenACC is part of GOMP library. Other sources say that the development for OpenACC support will continue only on GCC 6.x. Also I have read that support for OpenACC is in the main brunch of GCC. However if I compile a program with -fopenacc and -foffload=nvptx-non is just wont work. Can someone explain to me what exactly it takes to compiler and run OpenACC code with gcc 5.3+?
Why some guides seem to require (re)compilation of nvptx-tools, nvptx-newlib, and GCC, if, as some internet sources say, OpenACC support is part of GCC's main branch?
What is the role of the GOMP library in all this?
Is it true that development for OpenACC support will only be happening for GCC 6+ from now on?
When OpenACC support matures, is it the goal to enable it in a similar way we enable OpenMP (i.e., by just adding a couple of compiler flags)?
Can someone also provide answers to all the above after replacing "OpenACC" with "OpenMP 4.0 GPU/MIC offload capability"?
Thanks in advance
The link below contains a script that will compile gcc for OpenACC support.
https://github.com/olcf/OLCFHack15/blob/master/GCC5OffloadTest/auto-gcc5-offload-openacc-build-install.sh
OpenACC is part of GCC's main branch now, but there are some points to note. Even if there are libraries that are part of gcc, when you compile gcc, you have to specify which libraries to compile. Not all of them will be compiled by default. For OpenACC there's an additional problem. Since, NVIDIA drivers are not open source, GCC cannot compile OpenACC directly to binaries. It needs to compile OpenACC to the intermediate NVPTX instructions which the Nvidia runtime will handle. Therefore you also need to install nvptx libs.
GOMP library is the intermediate library that handles both OpenMP and OpenACC
Yes, I think OpenACC development will only be happening in GCC 6, but it may still be backported to GCC 5. But your best best would be to use GCC 6.
While I cannot comment on what GCC developers decide to do, I think in the first point I have already stated what the problems are. Unless NVIDIA make their drivers open source, I think an extra step will always be necessary.
I believe right now OpenMP is planned only for CPU's and MIC. I believe OpenMP support for both will probably become default behavior. I am not sure whether OpenMP targeting NVIDIA GPU's are immediately part of their target, but since GCC is using GOMP for both OpenMP and OpenACC, I believe eventually they might be able to do it. Also, GCC is also targeting HSA using OpenMP, so basically AMD APU's. I am not sure whether AMD GPU's will work the same way, but it maybe possible. Since, AMD is making their drivers open source, I believe they maybe easier to integrate into default behavior.

What is a prebuilt gcc?

I would like to know what they mean with "prebuilt gcc"?
gcc is the compiler, but what do they mean by prebuilt? And why does google offer a prebuilt gcc for their android. Can I just not use the regular gcc?
GCC has a source code repository available via SVN.
In some scenarios, you need to download the source code and build the GCC yourself (specially when you have custom hardware). But for most cases, 'pre-built' GCC for your hardware and OS is enough.

Compiler differences

I'm an iOS developer, I don't know how compilers work and I want to ask what is the difference between the LLVM GCC 4.2, the Xcode 4 default compiler and the GCC 4.2 compiler, the Xcode 3 default compiler.
Here is my understanding
GCC 4.2 is the (mostly) stock standard open source GNU C compiler that works with C, C++ and Objective-C. Its pretty much the standard compiler used in all open source, and its tried and true tested. But because its old technology, its just a compiler, it has no hooks for other uses. And its quite generic, being CPU and platform agnostic.
LLVM is the next generation of compilation software. It's syntax and semantically aware, compiling to a byte code and then to native, and it provides hooks so IDE's and other tools can use its knowledge. It's this awareness that allows Apple to improve auto-completion, implement fixit and do the build and analyze stuff in Xcode 4. LLVM is the future for Apple, and the future for GCC. LLVM also produces allegedly tighter code, as its optimizations are smarter (not sure about this). LLVM also allows for more dynamic language bindings at some point.
LLVM GCC is the half-way mark, the syntax and semantic preprocessing of LLVM with the old GCC back end compiler.
The way I use them
I use LLVM during development, as it keeps me warned of any and all issues. Really helped when I ran it the first time on legacy code and found some issues.
I use GCC to produce the final executable for iOS 3.1.3 apps, and LLVM for all the iOS 4.0 / Mac 10.6 apps.

GPS Application in ARM7

I'm developing a GPS application under Linux, with ARM7 microprocessor.
Which compiler do you recommend? Do you know if there is any toolkit with libraries ready to develop GPS applications?
A friend of mine recommended gcc... what do you guys think about it?
Thank you
I don't think that the compiler matters that much. What is more important is your precise understanding of the library you are using, or of the actual device you are invoking.
However, I will recommend GCC, and I do recommend using a very recent version of GCC. For instance, GCC 4.6.2 is appearing these days, and there have been lot of work recently put in GCC to improve its perfomance for ARM processors. So, if possible, us a 4.6 GCC, not a 4.3 one (some hardware vendors don't give recent GCC with their ARM development kit; you should consider in that case building your GCC (and perhaps binutils) from their source code.
I know nothing about GPS itself.

Resources