llvm / llvm-project

The LLVM Project is a collection of modular and reusable compiler and toolchain technologies.
http://llvm.org
Other
28.98k stars 11.95k forks source link

[OpenMP] build error: undefined reference to `std::__glibcxx_assert_fail` #73248

Open tgymnich opened 11 months ago

tgymnich commented 11 months ago

Enabling libstdc++ assertions (-D_GLIBCXX_ASSERTIONS) introduces an unwanted dependency on libstdc++ for libomp. This causes a linker error when building libomp with assertions enabled (-DLLVM_ENABLE_ASSERTIONS=ON) when using libstdc++ >= 12.

Build error:

[45/71] Linking C shared library openmp/runtime/src/libomp.so
FAILED: openmp/runtime/src/libomp.so
: && /tmp/llvm-project/build/./bin/clang --target=x86_64-unknown-linux-gnu -fPIC -fPIC -fno-semantic-interposition -Werror=date-time -Werror=unguarded-availability-new -Wall -Wextra -Wno-unused-parameter -Wwrite-strings -Wcast-qual -Wmissing-field-initializers -Wimplicit-fallthrough -Wcovered-switch-default -Wstring-conversion -Wmisleading-indentation -Wctad-maybe-unsupported -fdiagnostics-color -Wall -Wcast-qual -Wformat-pedantic -Wimplicit-fallthrough -Wsign-compare -Wno-enum-constexpr-conversion -Wno-extra -Wno-pedantic -g  -Wl,-z,defs -Wl,-z,nodelete -fuse-ld=gold -Wl,--gdb-index  -Wl,--as-needed -Wl,--version-script=/tmp/llvm-project/openmp/runtime/src/exports_so.txt -static-libgcc -Wl,-z,noexecstack -shared -Wl,-soname,libomp.so -o openmp/runtime/src/libomp.so openmp/runtime/src/CMakeFiles/omp.dir/kmp_alloc.cpp.o openmp/runtime/src/CMakeFiles/omp.dir/kmp_atomic.cpp.o openmp/runtime/src/CMakeFiles/omp.dir/kmp_csupport.cpp.o openmp/runtime/src/CMakeFiles/omp.dir/kmp_debug.cpp.o openmp/runtime/src/CMakeFiles/omp.dir/kmp_itt.cpp.o openmp/runtime/src/CMakeFiles/omp.dir/kmp_environment.cpp.o openmp/runtime/src/CMakeFiles/omp.dir/kmp_error.cpp.o openmp/runtime/src/CMakeFiles/omp.dir/kmp_global.cpp.o openmp/runtime/src/CMakeFiles/omp.dir/kmp_i18n.cpp.o openmp/runtime/src/CMakeFiles/omp.dir/kmp_io.cpp.o openmp/runtime/src/CMakeFiles/omp.dir/kmp_runtime.cpp.o openmp/runtime/src/CMakeFiles/omp.dir/kmp_settings.cpp.o openmp/runtime/src/CMakeFiles/omp.dir/kmp_str.cpp.o openmp/runtime/src/CMakeFiles/omp.dir/kmp_tasking.cpp.o openmp/runtime/src/CMakeFiles/omp.dir/kmp_threadprivate.cpp.o openmp/runtime/src/CMakeFiles/omp.dir/kmp_utility.cpp.o openmp/runtime/src/CMakeFiles/omp.dir/kmp_barrier.cpp.o openmp/runtime/src/CMakeFiles/omp.dir/kmp_wait_release.cpp.o openmp/runtime/src/CMakeFiles/omp.dir/kmp_affinity.cpp.o openmp/runtime/src/CMakeFiles/omp.dir/kmp_dispatch.cpp.o openmp/runtime/src/CMakeFiles/omp.dir/kmp_lock.cpp.o openmp/runtime/src/CMakeFiles/omp.dir/kmp_sched.cpp.o openmp/runtime/src/CMakeFiles/omp.dir/kmp_collapse.cpp.o openmp/runtime/src/CMakeFiles/omp.dir/z_Linux_util.cpp.o openmp/runtime/src/CMakeFiles/omp.dir/kmp_gsupport.cpp.o openmp/runtime/src/CMakeFiles/omp.dir/thirdparty/ittnotify/ittnotify_static.cpp.o openmp/runtime/src/CMakeFiles/omp.dir/kmp_taskdeps.cpp.o openmp/runtime/src/CMakeFiles/omp.dir/kmp_cancel.cpp.o openmp/runtime/src/CMakeFiles/omp.dir/kmp_ftn_cdecl.cpp.o openmp/runtime/src/CMakeFiles/omp.dir/kmp_ftn_extra.cpp.o openmp/runtime/src/CMakeFiles/omp.dir/kmp_version.cpp.o openmp/runtime/src/CMakeFiles/omp.dir/ompt-general.cpp.o openmp/runtime/src/CMakeFiles/omp.dir/ompd-specific.cpp.o openmp/runtime/src/CMakeFiles/omp.dir/z_Linux_asm.S.o  -lm  -ldl && cd /tmp/llvm-project/build/runtimes/runtimes-bins/openmp/runtime/src && /usr/bin/cmake -E create_symlink libomp.so libgomp.so && /usr/bin/cmake -E create_symlink libomp.so libiomp5.so
/usr/lib/gcc/x86_64-linux-gnu/12/../../../../include/c++/12/bits/atomic_base.h:485: error: undefined reference to 'std::__glibcxx_assert_fail(char const*, int, char const*, char const*)'
/usr/lib/gcc/x86_64-linux-gnu/12/../../../../include/c++/12/bits/atomic_base.h:486: error: undefined reference to 'std::__glibcxx_assert_fail(char const*, int, char const*, char const*)'
/usr/lib/gcc/x86_64-linux-gnu/12/../../../../include/c++/12/bits/atomic_base.h:485: error: undefined reference to 'std::__glibcxx_assert_fail(char const*, int, char const*, char const*)'
/usr/lib/gcc/x86_64-linux-gnu/12/../../../../include/c++/12/bits/atomic_base.h:486: error: undefined reference to 'std::__glibcxx_assert_fail(char const*, int, char const*, char const*)'
clang: error: linker command failed with exit code 1 (use -v to see invocation)

How To Reproduce:

Here is a Dockerfile to reproduce the issue.

Related issues:

llvmbot commented 11 months ago

@llvm/issue-subscribers-openmp

Author: Tim Gymnich (tgymnich)

[Enabling libstdc++ assertions](https://reviews.llvm.org/D142279) (`-D_GLIBCXX_ASSERTIONS`) introduces an unwanted dependency on libstdc++ for libomp. This causes a linker error when building libomp with assertions enabled (`-DLLVM_ENABLE_ASSERTIONS=ON`) when using libstdc++ >= 12. ### Build error: ``` [45/71] Linking C shared library openmp/runtime/src/libomp.so FAILED: openmp/runtime/src/libomp.so : && /tmp/llvm-project/build/./bin/clang --target=x86_64-unknown-linux-gnu -fPIC -fPIC -fno-semantic-interposition -Werror=date-time -Werror=unguarded-availability-new -Wall -Wextra -Wno-unused-parameter -Wwrite-strings -Wcast-qual -Wmissing-field-initializers -Wimplicit-fallthrough -Wcovered-switch-default -Wstring-conversion -Wmisleading-indentation -Wctad-maybe-unsupported -fdiagnostics-color -Wall -Wcast-qual -Wformat-pedantic -Wimplicit-fallthrough -Wsign-compare -Wno-enum-constexpr-conversion -Wno-extra -Wno-pedantic -g -Wl,-z,defs -Wl,-z,nodelete -fuse-ld=gold -Wl,--gdb-index -Wl,--as-needed -Wl,--version-script=/tmp/llvm-project/openmp/runtime/src/exports_so.txt -static-libgcc -Wl,-z,noexecstack -shared -Wl,-soname,libomp.so -o openmp/runtime/src/libomp.so openmp/runtime/src/CMakeFiles/omp.dir/kmp_alloc.cpp.o openmp/runtime/src/CMakeFiles/omp.dir/kmp_atomic.cpp.o openmp/runtime/src/CMakeFiles/omp.dir/kmp_csupport.cpp.o openmp/runtime/src/CMakeFiles/omp.dir/kmp_debug.cpp.o openmp/runtime/src/CMakeFiles/omp.dir/kmp_itt.cpp.o openmp/runtime/src/CMakeFiles/omp.dir/kmp_environment.cpp.o openmp/runtime/src/CMakeFiles/omp.dir/kmp_error.cpp.o openmp/runtime/src/CMakeFiles/omp.dir/kmp_global.cpp.o openmp/runtime/src/CMakeFiles/omp.dir/kmp_i18n.cpp.o openmp/runtime/src/CMakeFiles/omp.dir/kmp_io.cpp.o openmp/runtime/src/CMakeFiles/omp.dir/kmp_runtime.cpp.o openmp/runtime/src/CMakeFiles/omp.dir/kmp_settings.cpp.o openmp/runtime/src/CMakeFiles/omp.dir/kmp_str.cpp.o openmp/runtime/src/CMakeFiles/omp.dir/kmp_tasking.cpp.o openmp/runtime/src/CMakeFiles/omp.dir/kmp_threadprivate.cpp.o openmp/runtime/src/CMakeFiles/omp.dir/kmp_utility.cpp.o openmp/runtime/src/CMakeFiles/omp.dir/kmp_barrier.cpp.o openmp/runtime/src/CMakeFiles/omp.dir/kmp_wait_release.cpp.o openmp/runtime/src/CMakeFiles/omp.dir/kmp_affinity.cpp.o openmp/runtime/src/CMakeFiles/omp.dir/kmp_dispatch.cpp.o openmp/runtime/src/CMakeFiles/omp.dir/kmp_lock.cpp.o openmp/runtime/src/CMakeFiles/omp.dir/kmp_sched.cpp.o openmp/runtime/src/CMakeFiles/omp.dir/kmp_collapse.cpp.o openmp/runtime/src/CMakeFiles/omp.dir/z_Linux_util.cpp.o openmp/runtime/src/CMakeFiles/omp.dir/kmp_gsupport.cpp.o openmp/runtime/src/CMakeFiles/omp.dir/thirdparty/ittnotify/ittnotify_static.cpp.o openmp/runtime/src/CMakeFiles/omp.dir/kmp_taskdeps.cpp.o openmp/runtime/src/CMakeFiles/omp.dir/kmp_cancel.cpp.o openmp/runtime/src/CMakeFiles/omp.dir/kmp_ftn_cdecl.cpp.o openmp/runtime/src/CMakeFiles/omp.dir/kmp_ftn_extra.cpp.o openmp/runtime/src/CMakeFiles/omp.dir/kmp_version.cpp.o openmp/runtime/src/CMakeFiles/omp.dir/ompt-general.cpp.o openmp/runtime/src/CMakeFiles/omp.dir/ompd-specific.cpp.o openmp/runtime/src/CMakeFiles/omp.dir/z_Linux_asm.S.o -lm -ldl && cd /tmp/llvm-project/build/runtimes/runtimes-bins/openmp/runtime/src && /usr/bin/cmake -E create_symlink libomp.so libgomp.so && /usr/bin/cmake -E create_symlink libomp.so libiomp5.so /usr/lib/gcc/x86_64-linux-gnu/12/../../../../include/c++/12/bits/atomic_base.h:485: error: undefined reference to 'std::__glibcxx_assert_fail(char const*, int, char const*, char const*)' /usr/lib/gcc/x86_64-linux-gnu/12/../../../../include/c++/12/bits/atomic_base.h:486: error: undefined reference to 'std::__glibcxx_assert_fail(char const*, int, char const*, char const*)' /usr/lib/gcc/x86_64-linux-gnu/12/../../../../include/c++/12/bits/atomic_base.h:485: error: undefined reference to 'std::__glibcxx_assert_fail(char const*, int, char const*, char const*)' /usr/lib/gcc/x86_64-linux-gnu/12/../../../../include/c++/12/bits/atomic_base.h:486: error: undefined reference to 'std::__glibcxx_assert_fail(char const*, int, char const*, char const*)' clang: error: linker command failed with exit code 1 (use -v to see invocation) ``` ### How To Reproduce: [Here](https://gist.github.com/tgymnich/aaaad86dd351166df3aceb056e7399ee) is a Dockerfile to reproduce the issue. ### Related issues: - https://github.com/llvm/llvm-project/issues/71805 - https://reviews.llvm.org/D143168
jdoerfert commented 11 months ago

@jhuber6 is this fixed by your patch not to include LLVM options for runtimes?

jhuber6 commented 11 months ago

@jhuber6 is this fixed by your patch not to include LLVM options for runtimes?

I got it on a debug build before that patch, and after pulling it seems to have gone away. Can you confirm @tgymnich?

shiltian commented 11 months ago

73249 should be the fix for this I think

tgymnich commented 11 months ago

@jhuber6 The issue seems fixed on main. Shall we close #73249 then?

jhuber6 commented 11 months ago

@jhuber6 The issue seems fixed on main. Shall we close #73249 then?

Yeah this was probably due to picking up some configurations from another project. Hopefully we can keep things cleaner now. Go ahead and close that revision if you no longer need it. Thanks for confirming.

tannal commented 10 months ago

Any update on this issue? Since https://github.com/llvm/llvm-project/pull/73031 is reverted,

tgymnich commented 9 months ago

Not as far as I know. It might still be a good idea to merge https://github.com/llvm/llvm-project/pull/73249 as a stop-gap solution for now, while we look for a solution for #73031

jhuber6 commented 9 months ago

I think this is a more general problem. I've seen it manifest in some of AMD's builds recently. Seems there might be a bug in the GCC12 headers that changes the visibility of the assert function.