<html><head><meta http-equiv="Content-Type" content="text/html; charset=us-ascii"></head><body style="word-wrap: break-word; -webkit-nbsp-mode: space; line-break: after-white-space;" class="">LLVM is natively a cross compiler. You don't need to specify `CMAKE_CROSSCOMPILING` that option wound signify if you were compiling LLVM to run on arm, not LLVM to generate arm code.<div class=""><br class=""></div><div class="">You do need to build compiler-rt for your target, not your host. Cross targeting runtime libraries is a bit more complicated of a build configuration. If you want a full C++ runtime for the bare metal arm you'll need to remove libcxx, libcxxabi, and compiler-rt from `LLVM_ENABLE_PROJECTS` and instead spicy them to `LLVM_ENABLE_RUNTIMES`.</div><div class=""><br class=""></div><div class="">You will also need to set `LLVM_BUILTIN_TARGETS` and `LLVM_RUNTIME_TARGETS` to include the triples you want to build the runtimes for. You'll also need to set the compiler options for those targets so that the proper sysroots can be found.</div><div class=""><br class=""></div><div class="">Probably the best example of this kind of configuration is under clang/cmake/caches/Android-stage2.cmake.</div><div class=""><br class=""></div><div class="">-Chris</div><div class=""><div><br class=""><blockquote type="cite" class=""><div class="">On Oct 10, 2019, at 3:19 PM, kiwan maeng via llvm-dev <<a href="mailto:llvm-dev@lists.llvm.org" class="">llvm-dev@lists.llvm.org</a>> wrote:</div><br class="Apple-interchange-newline"><div class="">
  

    <meta http-equiv="content-type" content="text/html; charset=UTF-8" class="">
  
  <div text="#000000" bgcolor="#FFFFFF" class=""><p class="">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 class="">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 class="">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 class="">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" class="">
      <li dir="ltr" style="list-style-type: decimal; font-size: 11pt; font-family: Arial; background-color: transparent; font-weight: 400; font-style: normal; font-variant-ligatures: normal; font-variant-caps: normal; font-variant-east-asian: normal; font-variant-position: normal; text-decoration: none; vertical-align: baseline; white-space: pre;" class=""><div style="line-height: 1.38; margin-top: 0pt; margin-bottom: 0pt;" class=""><span style="font-size: 11pt; font-family: Arial; background-color: transparent; font-weight: 400; font-style: normal; font-variant-ligatures: normal; font-variant-caps: normal; font-variant-east-asian: normal; font-variant-position: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;" class="">git clone </span><a href="https://github.com/llvm/llvm-project.git" style="text-decoration:none;" class=""><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;" class="">https://github.com/llvm/llvm-project.git</span></a><span style="font-size: 11pt; font-family: Arial; background-color: transparent; font-weight: 400; font-style: normal; font-variant-ligatures: normal; font-variant-caps: normal; font-variant-east-asian: normal; font-variant-position: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;" class=""> llvm-v9</span></div></li>
      <li dir="ltr" style="list-style-type: decimal; font-size: 11pt; font-family: Arial; background-color: transparent; font-weight: 400; font-style: normal; font-variant-ligatures: normal; font-variant-caps: normal; font-variant-east-asian: normal; font-variant-position: normal; text-decoration: none; vertical-align: baseline; white-space: pre;" class=""><div style="line-height: 1.38; margin-top: 0pt; margin-bottom: 0pt;" class=""><span style="font-size: 11pt; font-family: Arial; background-color: transparent; font-weight: 400; font-style: normal; font-variant-ligatures: normal; font-variant-caps: normal; font-variant-east-asian: normal; font-variant-position: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;" class="">cd ..</span></div></li>
      <li dir="ltr" style="list-style-type: decimal; font-size: 11pt; font-family: Arial; background-color: transparent; font-weight: 400; font-style: normal; font-variant-ligatures: normal; font-variant-caps: normal; font-variant-east-asian: normal; font-variant-position: normal; text-decoration: none; vertical-align: baseline; white-space: pre;" class=""><div style="line-height: 1.38; margin-top: 0pt; margin-bottom: 0pt;" class=""><span style="font-size: 11pt; font-family: Arial; background-color: transparent; font-weight: 400; font-style: normal; font-variant-ligatures: normal; font-variant-caps: normal; font-variant-east-asian: normal; font-variant-position: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;" class="">mkdir llvm-install && mkdir llvm-build && cd llvm-build</span><span style="font-size: 11pt; font-family: Arial; background-color: transparent; font-weight: 400; font-style: normal; font-variant-ligatures: normal; font-variant-caps: normal; font-variant-east-asian: normal; font-variant-position: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;" class=""></span></div></li>
      <li dir="ltr" style="list-style-type: decimal; font-size: 11pt; font-family: Arial; background-color: transparent; font-weight: 400; font-style: normal; font-variant-ligatures: normal; font-variant-caps: normal; font-variant-east-asian: normal; font-variant-position: normal; text-decoration: none; vertical-align: baseline; white-space: pre;" class=""><div style="line-height: 1.38; margin-top: 0pt; margin-bottom: 0pt;" class=""><span style="font-size: 11pt; font-family: Arial; background-color: transparent; font-weight: 400; font-style: normal; font-variant-ligatures: normal; font-variant-caps: normal; font-variant-east-asian: normal; font-variant-position: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;" class="">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; background-color: transparent; font-weight: 400; font-style: italic; font-variant-ligatures: normal; font-variant-caps: normal; font-variant-east-asian: normal; font-variant-position: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;" class="">-DLLVM_BUILD_EXTERNAL_COMPILER_RT=On </span><span style="font-size: 11pt; font-family: Arial; background-color: transparent; font-weight: 400; font-style: normal; font-variant-ligatures: normal; font-variant-caps: normal; font-variant-east-asian: normal; font-variant-position: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;" class="">-DCMAKE_LINKER=/usr/bin/ld.gold -DCMAKE_INSTALL_PREFIX=../llvm-install/ ../llvm-v9/llvm/</span></div></li>
      <li dir="ltr" style="list-style-type: decimal; font-size: 11pt; font-family: Arial; background-color: transparent; font-weight: 400; font-style: normal; font-variant-ligatures: normal; font-variant-caps: normal; font-variant-east-asian: normal; font-variant-position: normal; text-decoration: none; vertical-align: baseline; white-space: pre;" class=""><span style="font-size: 11pt; font-family: Arial; background-color: transparent; font-weight: 400; font-style: normal; font-variant-ligatures: normal; font-variant-caps: normal; font-variant-east-asian: normal; font-variant-position: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;" class="">make && make install
</span></li>
    </ol><p class="">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 class="">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 class="">
    </p><p class="">(<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 class="">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 class="">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 class="">Alternatively, I just tried downloading clang from apt-get
      install, but that again complained about not having clang_rt.</p><p class="">I would not mind using a lower version of LLVM if that is easier.</p><p class="">Any help or insight would be highly appreciated!</p><p class="">Also, kindly let me know if this is a wrong thread to post. I am
      new, as you can see.</p><p class="">Thank you,</p><p class="">Best Regards,</p><p class="">Kiwan<br class="">
    </p><p class=""><br class="">
    </p>
  </div>

_______________________________________________<br class="">LLVM Developers mailing list<br class=""><a href="mailto:llvm-dev@lists.llvm.org" class="">llvm-dev@lists.llvm.org</a><br class="">https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-dev<br class=""></div></blockquote></div><br class=""></div></body></html>