<div>If I try to compile with clang, I get this error:</div><div> </div><div><div> CMake Error at cmake/modules/CheckAtomic.cmake:49 (message):</div><div>   Host compiler must support std::atomic!</div><div> Call Stack (most recent call first):</div><div>   cmake/config-ix.cmake:292 (include)</div><div>   CMakeLists.txt:566 (include)</div><div> </div><div> </div><div>Finally I found a safe set of options that gets my toolchain to compile. Here it is:</div><div> </div><div><span>    CLANG_DEFAULT_CXX_STDLIB = libc++</span></div><div><span>    CLANG_DEFAULT_RTLIB = compiler-rt</span></div><div><span>    LLVM_DEFAULT_TARGET_TRIPLE = x86_64-pc-linux-musl</span></div><div><span>    GCC_INSTALL_PREFIX = /path/to/gcc-stub</span></div></div><div><span>    DEFAULT_SYSROOT = /path/to/musl</span></div><div><span>    LLVM_TARGETS_TO_BUILD = X86</span></div><div><span>    LLVM_ENABLE_LLD = ON</span></div><div> </div><div><span>It configures and compiles fine (without a single warning!), but there are few problems left.</span></div><div> </div><div>1. Clang works for C code, links fine with GNU ld, but not with lld:</div><div> </div><div>$ clang -fuse-ld=lld -v hello.c</div><div><div>    clang version 4.0.0 (https://github.com/llvm-mirror/clang d0cab3401199d4d112c52969df80b84470e685f5) (https://github.com/llvm-mirror/llvm 52e39958c8f9fab06d2b4c9549cc20019f92a8b4)</div><div>    Target: x86_64-pc-linux-musl</div><div>    Thread model: posix</div><div>    InstalledDir: /path/to/llvm/bin</div><div>     "/path/to/llvm/bin/clang-4.0" -cc1 -triple x86_64-pc-linux-musl -emit-obj -mrelax-all -disable-free -disable-llvm-verifier -discard-value-names -main-file-name hello.c -mrelocation-model static -mthread-model posix -mdisable-fp-elim -fmath-errno -masm-verbose -mconstructor-aliases -munwind-tables -target-cpu x86-64 -v -dwarf-column-info -debugger-tuning=gdb -resource-dir /path/to/llvm/lib/clang/4.0.0 -isysroot /path/to/musl -internal-isystem /path/to/musl/usr/local/include -internal-isystem /path/to/llvm/lib/clang/4.0.0/include -internal-externc-isystem /path/to/musl/include -internal-externc-isystem /path/to/musl/usr/include -fdebug-compilation-dir /path/to/hello -ferror-limit 19 -fmessage-length 150 -fobjc-runtime=gcc -fdiagnostics-show-option -fcolor-diagnostics -o /tmp/hello-67034f.o -x c hello.c</div><div>    clang -cc1 version 4.0.0 based upon LLVM 4.0.0svn default target x86_64-pc-linux-musl</div><div>    ignoring nonexistent directory "/path/to/musl/usr/local/include"</div><div>    ignoring nonexistent directory "/path/to/musl/usr/include"</div><div>    #include "..." search starts here:</div><div>    #include <...> search starts here:</div><div>     /path/to/llvm/lib/clang/4.0.0/include</div><div>     /path/to/musl/include</div><div>    End of search list.</div><div>     "/path/to/llvm/bin/ld.lld" --sysroot=/path/to/musl -z relro --hash-style=gnu --eh-frame-hdr -m elf_x86_64 -dynamic-linker /lib/ld-musl-x86_64.so.1 -o a.out /path/to/musl/lib/crt1.o /path/to/musl/lib/crti.o /path/to/musl/lib/crtbegin.o -L/path/to/musl/lib /tmp/hello-67034f.o /path/to/llvm/lib/clang/4.0.0/lib/linux/libclang_rt.builtins-x86_64.a -lc /path/to/llvm/lib/clang/4.0.0/lib/linux/libclang_rt.builtins-x86_64.a /path/to/musl/lib/crtend.o /path/to/musl/lib/crtn.o</div><div>    /path/to/llvm/bin/ld.lld: error: crt1.c:(function _start_c): cannot preempt symbol '__libc_start_main' defined in /path/to/musl/lib/libc.so</div><div>    /path/to/llvm/bin/ld.lld: error: hello.c:(function main): cannot preempt symbol 'printf' defined in /path/to/musl/lib/libc.so</div><div>    clang-4.0: error: linker command failed with exit code 1 (use -v to see invocation)</div><div> </div><div><br />2. libcxx's <locale> refers to strtoll_l, strtoull_l, strtof_l, strtod_l, strtold_l that are not in musl, so for use with musl they should be replaced with strtoll, strtoull, strtof, strtod, strtold respectively.</div><div> </div><div>3. There are few other problems with compiling C++ code, but I didn't yet figure out what causes them (probably doing something wrong again).</div></div><div> </div><div>Regards,</div><div>Dmitry Golovin</div><div> </div><div>03.12.2016, 07:10, "Saleem Abdulrasool" <compnerd@compnerd.org>:</div><blockquote type="cite"><div>On Fri, Dec 2, 2016 at 1:28 PM, Vedant Kumar <span><<a target="_blank" href="mailto:vsk@apple.com">vsk@apple.com</a>></span> wrote:<div><div> <blockquote style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-color:rgb(204,204,204);border-left-style:solid;padding-left:1ex;"><span>> On Dec 2, 2016, at 4:57 AM, Dmitry Golovin via llvm-dev <<a href="mailto:llvm-dev@lists.llvm.org">llvm-dev@lists.llvm.org</a>> wrote:<br />><br />> I want to build LLVM-based toolchain with Musl, I have LLVM sources with clang and lld (under `tools` directory) and libunwind, compiler-rt, libcxx and libcxxabi (under `projects` directory). All are the latest versions cloned from GitHub mirror, branch `master`.<br />><br />> I'm trying to configure with the following options:<br />>    CLANG_DEFAULT_CXX_STDLIB = libc++<br />>    CLANG_DEFAULT_RTLIB = compiler-rt<br />>    LIBCXX_CXX_ABI = libcxxabi<br />>    LLVM_DEFAULT_TARGET_TRIPLE = x86_64-pc-linux-musl<br />>    LIBCXXABI_TARGET_TRIPLE = x86_64-pc-linux-musl<br />>    LIBUNWIND_TARGET_TRIPLE = x86_64-pc-linux-musl<br />>    DEFAULT_SYSROOT = /path/to/musl<br />>    GCC_INSTALL_PREFIX = /path/to/gcc-stub<br />>    LLVM_TARGETS_TO_BUILD = X86<br />>    LIBCXXABI_USE_COMPILER_RT = ON<br />>    LIBCXXABI_USE_LLVM_UNWINDER = ON<br />>    LIBCXX_HAS_MUSL_LIBC = ON<br />>    LIBCXX_USE_COMPILER_RT = ON<br />>    LLVM_ENABLE_LIBCXX = ON<br />>    LLVM_ENABLE_LLD = ON<br />><br />> When I try to configure, I get the following error messages:<br />><br />> CMake Warning at cmake/modules/HandleLLVMStdlib.cmake:24 (message):<br />>   Can't specify libc++ with '-stdlib='<br />> Call Stack (most recent call first):<br />>   cmake/config-ix.cmake:15 (include)<br />>   CMakeLists.txt:566 (include)</span><br /><br />^ This seems harmless. You'll probably end up building with libstdc++.<br /><br /><span>><br />> CMake Error at projects/libunwind/src/CMakeLists.txt:70 (message):<br />>   Compiler doesn't support generation of unwind tables if exception support<br />>   is disabled.  Building libunwind DSO with runtime dependency on C++ ABI<br />>   library is not supported.</span><br /><br />It looks like your host compiler doesn't support -funwind-tables.</blockquote><div> </div><div>Hmm, so we try to generate unwind tables without exceptions as we don't want to use exceptions in the unwinding code path itself.</div><div> </div><div>It sounds like your compiler might not support `-fno-exceptions -funwind-tables` together although it supports them together.  What target are you building libunwind for?  Linux x86, x86_64 use a DWARF-esque encoding in eh_frame.  However, other targets need unwind tables with custom information.  Perhaps we are being too stringent here.  At least libitm uses both these flags together with gcc, so it and clang should support this.</div><div> </div><blockquote style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-color:rgb(204,204,204);border-left-style:solid;padding-left:1ex;">Try building with clang?</blockquote><div> </div><div>That should work. </div><div> </div><blockquote style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-color:rgb(204,204,204);border-left-style:solid;padding-left:1ex;">I've CC'd Saleem who might know more about this.<br /><br />best,<br />vedant<div><div><br />><br />> I'm probably doing something wrong, but I can't figure out what exactly. If I omit some of the flags, I get different errors, but I never get successful configuration.<br />><br />> I'm on Ubuntu 16.04 (if it is important) and have not yet tried on other machines, but I'm pretty sure it is possible to reproduce it.<br />><br />> Regards,<br />> Dmitry Golovin<br /> </div></div></blockquote></div> <div> </div>--<div>Saleem Abdulrasool<br />compnerd (at) compnerd (dot) org</div></div></div></blockquote>