<html xmlns:v="urn:schemas-microsoft-com:vml" xmlns:o="urn:schemas-microsoft-com:office:office" xmlns:w="urn:schemas-microsoft-com:office:word" xmlns:m="http://schemas.microsoft.com/office/2004/12/omml" xmlns="http://www.w3.org/TR/REC-html40">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=us-ascii">
<meta name="Generator" content="Microsoft Word 15 (filtered medium)">
<style><!--
/* Font Definitions */
@font-face
        {font-family:"Cambria Math";
        panose-1:2 4 5 3 5 4 6 3 2 4;}
@font-face
        {font-family:Calibri;
        panose-1:2 15 5 2 2 2 4 3 2 4;}
@font-face
        {font-family:"Malgun Gothic";
        panose-1:2 11 5 3 2 0 0 2 0 4;}
@font-face
        {font-family:"\@Malgun Gothic";
        panose-1:2 11 5 3 2 0 0 2 0 4;}
/* Style Definitions */
p.MsoNormal, li.MsoNormal, div.MsoNormal
        {margin:0in;
        margin-bottom:.0001pt;
        font-size:11.0pt;
        font-family:"Calibri",sans-serif;}
a:link, span.MsoHyperlink
        {mso-style-priority:99;
        color:#0563C1;
        text-decoration:underline;}
a:visited, span.MsoHyperlinkFollowed
        {mso-style-priority:99;
        color:#954F72;
        text-decoration:underline;}
p.MsoListParagraph, li.MsoListParagraph, div.MsoListParagraph
        {mso-style-priority:34;
        margin-top:0in;
        margin-right:0in;
        margin-bottom:0in;
        margin-left:.5in;
        margin-bottom:.0001pt;
        font-size:11.0pt;
        font-family:"Calibri",sans-serif;}
span.EmailStyle17
        {mso-style-type:personal-compose;
        font-family:"Calibri",sans-serif;
        color:windowtext;}
.MsoChpDefault
        {mso-style-type:export-only;}
@page WordSection1
        {size:8.5in 11.0in;
        margin:1.0in 1.0in 1.0in 1.0in;}
div.WordSection1
        {page:WordSection1;}
--></style><!--[if gte mso 9]><xml>
<o:shapedefaults v:ext="edit" spidmax="1026" />
</xml><![endif]--><!--[if gte mso 9]><xml>
<o:shapelayout v:ext="edit">
<o:idmap v:ext="edit" data="1" />
</o:shapelayout></xml><![endif]-->
</head>
<body lang="EN-US" link="#0563C1" vlink="#954F72">
<div class="WordSection1">
<p class="MsoNormal">Dear LLVM developers,<o:p></o:p></p>
<p class="MsoNormal"><o:p> </o:p></p>
<p class="MsoNormal">Hello,<o:p></o:p></p>
<p class="MsoNormal">I’m trying to find a way of cross-compiling my c code against Baremetal Cortex-M device (so target triple will be arm-none-eabi) only using LLVM/Clang, and not using anything from GNU (ld or libc).<o:p></o:p></p>
<p class="MsoNormal">I’m doing this to know which one of LLVM/clang and GCC produces smaller flash image size because saving flash is a big deal in our projects.<o:p></o:p></p>
<p class="MsoNormal"><o:p> </o:p></p>
<p class="MsoNormal">1) When I just follow this - <a href="https://clang.llvm.org/docs/CrossCompilation.html">
https://clang.llvm.org/docs/CrossCompilation.html</a> using LLVM/Clang Prebuilt binary 5.0.0, I got this error,<o:p></o:p></p>
<p class="MsoNormal" style="margin-left:.5in"><i>daniel@daniel-VirtualBox:~/clang/crosscompile$ make clean all<o:p></o:p></i></p>
<p class="MsoNormal" style="margin-left:.5in"><i>rm -f main *.o *.map *.a<o:p></o:p></i></p>
<p class="MsoNormal" style="margin-left:.5in"><i>"clang+llvm-5.0.0-linux-x86_64-ubuntu16.04/bin"/clang -static --target=arm-none-eabi -mcpu=cortex-m0   -c -o main.o main.c<o:p></o:p></i></p>
<p class="MsoNormal" style="margin-left:.5in"><i>"clang+llvm-5.0.0-linux-x86_64-ubuntu16.04/bin"/clang -static --target=arm-none-eabi -mcpu=cortex-m0   -c -o a.o a.c<o:p></o:p></i></p>
<p class="MsoNormal" style="margin-left:.5in"><i>"clang+llvm-5.0.0-linux-x86_64-ubuntu16.04/bin"/clang -static --target=arm-none-eabi -mcpu=cortex-m0   -c -o reset.o reset.c<o:p></o:p></i></p>
<p class="MsoNormal" style="margin-left:.5in"><i>"clang+llvm-5.0.0-linux-x86_64-ubuntu16.04/bin"/clang -v -static --target=armv6m-none-eabi -o main main.o a.o reset.o<o:p></o:p></i></p>
<p class="MsoNormal" style="margin-left:.5in"><i>clang version 5.0.0 (tags/RELEASE_500/final)<o:p></o:p></i></p>
<p class="MsoNormal" style="margin-left:.5in"><i>Target: armv6m-none--eabi<o:p></o:p></i></p>
<p class="MsoNormal" style="margin-left:.5in"><i>Thread model: single<o:p></o:p></i></p>
<p class="MsoNormal" style="margin-left:.5in"><i>InstalledDir: clang+llvm-5.0.0-linux-x86_64-ubuntu16.04/bin<o:p></o:p></i></p>
<p class="MsoNormal" style="margin-left:.5in"><i>"clang+llvm-5.0.0-linux-x86_64-ubuntu16.04/bin/ld.lld" main.o a.o reset.o -Bstatic -Lclang+llvm-5.0.0-linux-x86_64-ubuntu16.04/lib/clang/5.0.0/lib/baremetal -lc -lm -lclang_rt.builtins-armv6m.a -o main<o:p></o:p></i></p>
<p class="MsoNormal" style="margin-left:.5in"><i>clang+llvm-5.0.0-linux-x86_64-ubuntu16.04/bin/ld.lld: error:
<b>unable to find library -lc</b><o:p></o:p></i></p>
<p class="MsoNormal" style="margin-left:.5in"><i>clang+llvm-5.0.0-linux-x86_64-ubuntu16.04/bin/ld.lld: error:
<b>unable to find library -lm</b><o:p></o:p></i></p>
<p class="MsoNormal" style="margin-left:.5in"><i>clang+llvm-5.0.0-linux-x86_64-ubuntu16.04/bin/ld.lld: error:
<b>unable to find library -lclang_rt.builtins-armv6m.a</b><o:p></o:p></i></p>
<p class="MsoNormal" style="margin-left:.5in"><i>clang-5.0: error: ld.lld command failed with exit code 1 (use -v to see invocation)<o:p></o:p></i></p>
<p class="MsoNormal" style="margin-left:.5in"><i>makefile:33: recipe for target 'main' failed<o:p></o:p></i></p>
<p class="MsoNormal" style="margin-left:.5in"><i>make: *** [main] Error 1</i><o:p></o:p></p>
<p class="MsoNormal"><o:p> </o:p></p>
<p class="MsoNormal">2) To get clang_rt.builtins-armv6m.a or libc, libm, I tried to build LLVM/Clang (compiler_rt) from LLVM/Clang source following this -
<a href="http://llvm.org/docs/HowToCrossCompileLLVM.html">http://llvm.org/docs/HowToCrossCompileLLVM.html</a> but I got this error,<o:p></o:p></p>
<p class="MsoNormal" style="margin-left:.5in"><i>TARGET_TRIPLE=arm-none-eabi<o:p></o:p></i></p>
<p class="MsoNormal" style="margin-left:.5in"><i>MYHOSTBIN=${HOME}/clang/source/build_x64/bin<o:p></o:p></i></p>
<p class="MsoNormal" style="margin-left:.5in"><i>MYGNUARM_ROOT=${HOME}/opt/gcc-arm-none-eabi-6-2017-q2-update<o:p></o:p></i></p>
<p class="MsoNormal" style="margin-left:.5in"><i>MYCFLAGS="--specs=nosys.specs -mcpu=cortex-m4 -mthumb -mfloat-abi=softfp -mfpu=fpv4-sp-d16"<o:p></o:p></i></p>
<p class="MsoNormal" style="margin-left:.5in"><i>cmake -G "Ninja" \<o:p></o:p></i></p>
<p class="MsoNormal" style="margin-left:.5in"><i>               -DCMAKE_CROSSCOMPILING=True \<o:p></o:p></i></p>
<p class="MsoNormal" style="margin-left:.5in"><i>               -DCMAKE_BUILD_TYPE=Release \<o:p></o:p></i></p>
<p class="MsoNormal" style="margin-left:.5in"><i>               -DCMAKE_INSTALL_PREFIX=${HOME}/clang/toInstall \<o:p></o:p></i></p>
<p class="MsoNormal" style="margin-left:.5in"><i>               -DLLVM_TABLEGEN=${MYHOSTBIN}/llvm-tblgen \<o:p></o:p></i></p>
<p class="MsoNormal" style="margin-left:.5in"><i>               -DCLANG_TABLEGEN=${MYHOSTBIN}/clang-tblgen \<o:p></o:p></i></p>
<p class="MsoNormal" style="margin-left:.5in"><i>               -DLLVM_DEFAULT_TARGET_TRIPLE=arm-none-eabi \<o:p></o:p></i></p>
<p class="MsoNormal" style="margin-left:.5in"><i>               -DLLVM_TARGET_ARCH=ARM \<o:p></o:p></i></p>
<p class="MsoNormal" style="margin-left:.5in"><i>               -DLLVM_TARGETS_TO_BUILD=ARM \<o:p></o:p></i></p>
<p class="MsoNormal" style="margin-left:.5in"><i>               -DLLVM_ENABLE_LTO=Full \<o:p></o:p></i></p>
<p class="MsoNormal" style="margin-left:.5in"><i>               -DCMAKE_C_FLAGS="${MYCFLAGS}" \<o:p></o:p></i></p>
<p class="MsoNormal" style="margin-left:.5in"><i>               -DCMAKE_CXX_FLAGS="${MYCFLAGS}" \<o:p></o:p></i></p>
<p class="MsoNormal" style="margin-left:.5in"><i>               -DCMAKE_SYSROOT=${MYGNUARM_ROOT} \<o:p></o:p></i></p>
<p class="MsoNormal" style="margin-left:.5in"><i>               -DCMAKE_TOOLCHAIN_FILE=../toolchain.txt \<o:p></o:p></i></p>
<p class="MsoNormal" style="margin-left:.5in"><i>               -DCMAKE_C_COMPILER=${MYGNUARM_ROOT}/bin/arm-none-eabi-gcc \<o:p></o:p></i></p>
<p class="MsoNormal" style="margin-left:.5in"><i>               -DCMAKE_CXX_COMPILER=${MYGNUARM_ROOT}/bin/arm-none-eabi-g++ \<o:p></o:p></i></p>
<p class="MsoNormal" style="margin-left:.5in"><i>               -DCMAKE_ASM_COMPILER=${MYGNUARM_ROOT}/bin/arm-none-eabi-as \<o:p></o:p></i></p>
<p class="MsoNormal" style="margin-left:.5in"><i>               ../llvm<o:p></o:p></i></p>
<p class="MsoNormal" style="margin-left:.5in"><i>…<o:p></o:p></i></p>
<p class="MsoNormal" style="margin-left:.5in"><i>-- Looking for __atomic_load_8 in atomic<o:p></o:p></i></p>
<p class="MsoNormal" style="margin-left:.5in"><i>-- Looking for __atomic_load_8 in atomic - not found<o:p></o:p></i></p>
<p class="MsoNormal" style="margin-left:.5in"><i>CMake Error at cmake/modules/CheckAtomic.cmake:74 (message):<o:p></o:p></i></p>
<p class="MsoNormal" style="margin-left:.5in"><i>  <b>Host compiler appears to require libatomic, but cannot find it</b>.<o:p></o:p></i></p>
<p class="MsoNormal" style="margin-left:.5in"><i>Call Stack (most recent call first):<o:p></o:p></i></p>
<p class="MsoNormal" style="margin-left:.5in"><i>  cmake/config-ix.cmake:350 (include)<o:p></o:p></i></p>
<p class="MsoNormal" style="margin-left:.5in"><i>  CMakeLists.txt:585 (include)</i><o:p></o:p></p>
<p class="MsoNormal"><o:p> </o:p></p>
<p class="MsoNormal">arm-none-eabi toolchain doesn’t contain libatomic, but I need to build compiler_rt using this tool to get the runtime for ARM, so it’s confusing. Or building compiler_rt using arm-none-eabi toolchain is completely wrong idea in the first
 place.<o:p></o:p></p>
<p class="MsoNormal"><o:p> </o:p></p>
<p class="MsoNormal">3) Then I found this mail thread  <a href="http://lists.llvm.org/pipermail/llvm-dev/2017-August/116134.html">http://lists.llvm.org/pipermail/llvm-dev/2017-August/116134.html</a> which seems very close to the thing I’m trying, but the mail
 thread is unfinished.<o:p></o:p></p>
<p class="MsoNormal"><o:p> </o:p></p>
<p class="MsoNormal">So, my question is, <o:p></o:p></p>
<p class="MsoNormal">Is there a way of cross-compiling c code against Baremetal Cortex-M device only using LLVM/Clang, and not using anything from GNU (ld or libc)?<o:p></o:p></p>
<p class="MsoNormal">If so, do I have to build LLVM/Clang source code to get clang_rt.builtins-armv6m.a or libc, libm for ARM?<o:p></o:p></p>
<p class="MsoNormal">If so, the method 2) or 3) above is the right approach? Or are there any other instruction?<o:p></o:p></p>
<p class="MsoNormal"><o:p> </o:p></p>
<p class="MsoNormal">Any advice would be a great help for me.<o:p></o:p></p>
<p class="MsoNormal"><o:p> </o:p></p>
<p class="MsoNormal">Thank you<o:p></o:p></p>
<p class="MsoNormal">Daniel<o:p></o:p></p>
<p class="MsoNormal"><o:p> </o:p></p>
<p class="MsoNormal"><o:p> </o:p></p>
</div>
<p style="font-size:10pt; line-height:12pt; font-family: 'Cambria','times roman',serif;">
<br>
This message and any attachments may contain confidential information from Cypress or its subsidiaries. If it has been received in error, please advise the sender and immediately delete this message.
</p>
</body>
</html>