Closed ishmael1851 closed 8 months ago
@llvm/issue-subscribers-openmp
No idea what the problem might be. Googling shows people had similar problem about a year ago (https://github.com/tpoechtrager/osxcross/issues/267), and the suggestion was: either build natively or use pre-built binaries.
For native builds people have same linking problem when outdated xcode used, but I am not sure if it is related to cross build somehow.
I'm seeing the same issue natively, though: trying to build LLVM 16.0.0 rc1/rc2 on arm64-apple-darwin21.6.0
with Command Line Tools for Xcode 14.2 (the latest version) shows the same link error. When I continue with ninja -k0 check-all
, the issue hits again:
FAILED: tools/flang/unittests/Runtime/FlangRuntimeTests
[...]
Undefined symbols for architecture arm64:
"___divdc3", referenced from:
double complex tgpowi<double complex, int>(double complex, int) in libFortranRuntime.a(complex-powi.cpp.o)
double complex tgpowi<double complex, long long>(double complex, long long) in libFortranRuntime.a(complex-powi.cpp.o)
"___divsc3", referenced from:
float complex tgpowi<float complex, int>(float complex, int) in libFortranRuntime.a(complex-powi.cpp.o)
float complex tgpowi<float complex, long long>(float complex, long long) in libFortranRuntime.a(complex-powi.cpp.o)
ld: symbol(s) not found for architecture arm64
clang-16: error: linker command failed with exit code 1 (use -v to see invocation)
I've not yet investigated more closely, though.
What I've now found is that those missing symbols live in libclang_rt.osx.a
: usually clang
always links with that archive library implicitly, irrespective of creating an executable or dynamic library. For some weird reason, this doesn't happen when linking libomp.dylib
.
I tried with a Debug
build of llvm 16.0.0 rc3 to check what happens in clang/lib/Driver/ToolChains/Darwin.cpp:DarwinClang::AddLinkRuntimeLibArgs
and AddLinkRuntimeLib(Args, CmdArgs, "builtins");
. Unfortunately, I cannot debug clang
with the bundled lldb
in an ssh
session:
error: process exited with status -1 (this is a non-interactive debug session, cannot get permission to debug processes.)
I've encountered this with 18.1.0-rc1 in conda-forge, with a build recipe that has successfully cross-compiled previous versions (17, 16, 15, ...) for osx-arm64
from osx-64
. It looks like somewhere a linkage to compiler-rt
isn't being inserted correctly anymore...?
We generally don't need any other project to build OpenMP but Apple Silicon platform is an exception because certain functions are not provided by the system. Compiler-rt happens to have them. I think we need to "copy" the implementation of those functions to OpenMP.
this happens when not linking libclang_rt, a manual way to solve this is add target clang_rt library to linker flags to where having this problem
Any plans to resolve this in the upcoming 18.1 release?
It's not in the plan yet but I'll at least fix it in trunk soon. If that is merged before 18.1 release, we can cherry pick it.
I did a detailed check. Now I think compiler-rt
is required to compile libomp
on macOS. Basically on a Linux system, libomp
will link against libgcc.a
, which is the compiler rt for GCC. For LLVM/OpenMP on macOS, we will need a clang that has compiler-rt
. The system clang definitely has so there is no problem building OpenMP with it.
it is possible when self bootstrapping scene, at least I met this problem when bootstrapping on iOS, where host compiler have clang_rt but stage1 clang may not automatically passing it to linker, even there is a stage1 compiler-rt. But I only triggers this error when linking flang
Does putting openmp
into LLVM_ENABLE_RUNTIMES
help?
Update: probably not since compiler-rt might not be installed into clang's directory.
Haven't tried that yet, but libunwind configure failed due to no target clang_rt path passed to its CMake args, while this sub project flags was not handled by user but the top Makefile/build.ninja
You don't have to explicitly pass argument to use compiler-rt IIUC. As long as it is installed properly into ${llvm_install_dir}/lib/${version}/lib/${os}/
, clang
can pick it up automatically.
Then this might be the problem that clang_rt not installed to stage1 clang search path after build, thus affecting all stage2 subprojects that using it
Does putting
openmp
intoLLVM_ENABLE_RUNTIMES
help?Update: probably not since compiler-rt might not be installed into clang's directory.
It will have the same issue as building libomptarget (with c++ default rtl set to libc++) on a system where you don't have libc++ installed yet. compiler-rt and libc++ are also built as LLVM_ENABLE_RUNTIMES and not available at the time you build libomptarget.
Yeah, the installation will only happen after the runtime build.
I filed a new issue for this since it is still a problem https://github.com/llvm/llvm-project/issues/105997
Cross-compiling libomp for MacOSX on a Linux machine gives the following error. Any ideas? Source code was downloaded from here: https://github.com/llvm/llvm-project/releases/download/llvmorg-14.0.0/openmp-14.0.0.src.tar.xz