Version 1 (modified by JoelSherrill, on Jul 1, 2011 at 6:17:22 PM) (diff)

new page


This page is intended to capture notes and information about using Clang to compile RTEMS.

All supporting files, patches, replacement files, etc. needed should be in If something is missing, let Joel know.

Base Tools

For now, you need the regular RTEMS toolchain installed. We are using the normal RTEMS binutils and gdb. In addition, the way I have been building requires using the CPU-rtems4.11-gcc as a helper wrapper.

Building Clang

Check out LLVM and Clang using the instructions at In my case, I started in a working directory (/users/joel/llvm) and checked out into /users/joel/llvm/llvm. After the checkout completed, I performed the following commands:

cd /users/joel/llvm
mkdir b-llvm
cd b-llvm
../llvm/configure --prefix=/users/joel/llvm/install
make install

After this completed, I ensured that my PATH included /opt/rtems-4.11/bin and /users/joel/llvm/install/bin for subsequent builds.

Building Newlib With Clang

I created a script file named /users/joel/llvm/j-newlib with the following contents.

../newlib-1.19.0/configure --host=${CPU}-rtems4.11 \
  --prefix=/users/joel/llvm/install \
  --with-newlib \
  CC="clang -ccc-host-triple ${CPU}-rtems4.11 -ccc-gcc-name ${CPU}-rtems4.11-gcc" \
  CC_FOR_TARGET="clang -ccc-host-triple ${CPU}-rtems4.11 -ccc-gcc-name ${CPU}-rtems4.11-gcc" \
  CC_FOR_BUILD="clang " \
  PONIES=true \
  AR=${CPU}-rtems4.11-ar \
  AS=${CPU}-rtems4.11-as >c.log 2>&1 && \
make -j4 >b.log 2>&1 && \
make install >i.log 2>&1 

echo $?

newlib must be patched as appropriate for the version of RTEMS being built.

I used the j-newlib script to build newlib as follows:

cd /users/joel/llvm
mkdir b-newlib
cd b-newlib
sh -x ../j-newlib

clang cannot build the file newlib/libc/sys/rtems/crt0.c. There is a replacement of that file on the ftp site. I am not sure if this is a clang bug, questionable code in crt0.c or a combination of the two.

Building RTEMS

I have not successfully built RTEMS yet. I assume the problem is that I must pass in some combination of CC, CC_FOR_TARGET, and CC_FOR_BUILD in a way that makes the RTEMS build happy.