<html>
  <head>

    <meta http-equiv="content-type" content="text/html; charset=UTF-8">
  </head>
  <body text="#000000" bgcolor="#FFFFFF">
    <p>I am trying to build an LLVM toolchain so that it can
      cross-compile code to my ARMv7EM-based STM32F7 chip (I want to
      compile the code on an x86 machine and run it on ARM).</p>
    <p>However, a lot of the documents in the web is outdated, pointing
      to different versions of LLVM (with a different folder structure!)
      and I am not skilled enough to deduce a right way to build with
      the scattered information.</p>
    <p>I am mainly looking into this:
      (<a class="moz-txt-link-freetext" href="https://llvm.org/docs/HowToCrossCompileLLVM.html">https://llvm.org/docs/HowToCrossCompileLLVM.html</a>), and fiddled
      around to build something that is partially working.</p>
    <p>This is the command I am using:</p>
    <ol style="margin-top:0;margin-bottom:0;"
      id="docs-internal-guid-e2702ebf-7fff-c0e7-2bf3-6a8aabe7aec1">
      <li dir="ltr" style="list-style-type:decimal;font-size:11pt;font-family:Arial;color:#000000;background-color:transparent;font-weight:400;font-style:normal;font-variant:normal;text-decoration:none;vertical-align:baseline;white-space:pre;"><p dir="ltr" style="line-height:1.38;margin-top:0pt;margin-bottom:0pt;"><span style="font-size:11pt;font-family:Arial;color:#000000;background-color:transparent;font-weight:400;font-style:normal;font-variant:normal;text-decoration:none;vertical-align:baseline;white-space:pre;white-space:pre-wrap;">git clone </span><a href="https://github.com/llvm/llvm-project.git" style="text-decoration:none;"><span style="font-size:11pt;font-family:Arial;color:#1155cc;background-color:transparent;font-weight:400;font-style:normal;font-variant:normal;text-decoration:underline;-webkit-text-decoration-skip:none;text-decoration-skip-ink:none;vertical-align:baseline;white-space:pre;white-space:pre-wrap;">https://github.com/llvm/llvm-project.git</span></a><span style="font-size:11pt;font-family:Arial;color:#000000;background-color:transparent;font-weight:400;font-style:normal;font-variant:normal;text-decoration:none;vertical-align:baseline;white-space:pre;white-space:pre-wrap;"> llvm-v9</span></p></li>
      <li dir="ltr" style="list-style-type:decimal;font-size:11pt;font-family:Arial;color:#000000;background-color:transparent;font-weight:400;font-style:normal;font-variant:normal;text-decoration:none;vertical-align:baseline;white-space:pre;"><p dir="ltr" style="line-height:1.38;margin-top:0pt;margin-bottom:0pt;"><span style="font-size:11pt;font-family:Arial;color:#000000;background-color:transparent;font-weight:400;font-style:normal;font-variant:normal;text-decoration:none;vertical-align:baseline;white-space:pre;white-space:pre-wrap;">cd ..</span></p></li>
      <li dir="ltr" style="list-style-type:decimal;font-size:11pt;font-family:Arial;color:#000000;background-color:transparent;font-weight:400;font-style:normal;font-variant:normal;text-decoration:none;vertical-align:baseline;white-space:pre;"><p dir="ltr" style="line-height:1.38;margin-top:0pt;margin-bottom:0pt;"><span style="font-size:11pt;font-family:Arial;color:#000000;background-color:transparent;font-weight:400;font-style:normal;font-variant:normal;text-decoration:none;vertical-align:baseline;white-space:pre;white-space:pre-wrap;">mkdir llvm-install && mkdir llvm-build && cd llvm-build</span><span style="font-size:11pt;font-family:Arial;color:#000000;background-color:transparent;font-weight:400;font-style:normal;font-variant:normal;text-decoration:none;vertical-align:baseline;white-space:pre;white-space:pre-wrap;"></span></p></li>
      <li dir="ltr" style="list-style-type:decimal;font-size:11pt;font-family:Arial;color:#000000;background-color:transparent;font-weight:400;font-style:normal;font-variant:normal;text-decoration:none;vertical-align:baseline;white-space:pre;"><p dir="ltr" style="line-height:1.38;margin-top:0pt;margin-bottom:0pt;"><span style="font-size:11pt;font-family:Arial;color:#000000;background-color:transparent;font-weight:400;font-style:normal;font-variant:normal;text-decoration:none;vertical-align:baseline;white-space:pre;white-space:pre-wrap;">cmake -G "Unix Makefiles" -DCMAKE_CROSSCOMPILING=True -DLLVM_OPTIMIZED_TABLEGEN=1 -DCMAKE_BUILD_TYPE=Release -DLLVM_TARGETS_TO_BUILD=ARM -DLLVM_TARGET_ARCH=ARMV7EM -DLLVM_DEFAULT_TARGET_TRIPLE=armv7em-none-eabihf -DLLVM_ENABLE_PROJECTS="clang;libcxx;libcxxabi;compiler-rt;lld;polly" </span><span style="font-size:11pt;font-family:Arial;color:#000000;background-color:transparent;font-weight:400;font-style:italic;font-variant:normal;text-decoration:none;vertical-align:baseline;white-space:pre;white-space:pre-wrap;">-DLLVM_BUILD_EXTERNAL_COMPILER_RT=On </span><span style="font-size:11pt;font-family:Arial;color:#000000;background-color:transparent;font-weight:400;font-style:normal;font-variant:normal;text-decoration:none;vertical-align:baseline;white-space:pre;white-space:pre-wrap;">-DCMAKE_LINKER=/usr/bin/ld.gold -DCMAKE_INSTALL_PREFIX=../llvm-install/ ../llvm-v9/llvm/</span></p></li>
      <li dir="ltr" style="list-style-type:decimal;font-size:11pt;font-family:Arial;color:#000000;background-color:transparent;font-weight:400;font-style:normal;font-variant:normal;text-decoration:none;vertical-align:baseline;white-space:pre;"><span style="font-size:11pt;font-family:Arial;color:#000000;background-color:transparent;font-weight:400;font-style:normal;font-variant:normal;text-decoration:none;vertical-align:baseline;white-space:pre;white-space:pre-wrap;">make && make install
</span></li>
    </ol>
    <p>It compiles, and if I try to compile C code using the compiled
      clang, it complains about not having clang_rt on the linking stage
      (it generates up to assembly file).</p>
    <p>I think it is weird that clang_rt is not there because I enable
      compiler-rt as you can see; anyways, I tried to separately compile
      clang_rt by looking at<br>
    </p>
    <p>(<a class="moz-txt-link-freetext" href="https://llvm.org/docs/HowToCrossCompileBuiltinsOnArm.html">https://llvm.org/docs/HowToCrossCompileBuiltinsOnArm.html</a>) but
      it wasn't successful.</p>
    <p>I spent weeks trying out different flag options (some won't even
      compile), or using a gcc-arm-none-eabi linker at the last stage,
      etc., but with no luck.</p>
    <p>Can anyone guide me to a more concrete example of how to compile
      LLVM for ARM cross-compilation, or help me out with what is wrong
      with the cmake options I am using?</p>
    <p>Alternatively, I just tried downloading clang from apt-get
      install, but that again complained about not having clang_rt.</p>
    <p>I would not mind using a lower version of LLVM if that is easier.</p>
    <p>Any help or insight would be highly appreciated!</p>
    <p>Also, kindly let me know if this is a wrong thread to post. I am
      new, as you can see.</p>
    <p>Thank you,</p>
    <p>Best Regards,</p>
    <p>Kiwan<br>
    </p>
    <p><br>
    </p>
  </body>
</html>