This is an archive of the discontinued LLVM Phabricator instance.

[CMake][libcxxabi] Use -nodefaultlibs for CMake checks
ClosedPublic

Authored by phosek on Apr 3 2017, 6:59 PM.

Details

Summary

Since libc++abi is built with -nodefaultlibs, we should be using this option even for CMake checks to avoid any inconsistency and also to avoid dependency on a working C++ standard library just for the setting up the build itself because check_cxx_compile_flags adds the flag to COMPILE_DEFINITIONS when calling try_compile and this variable is only considered for compilation but not for linking where -nodefaultlibs actually makes a difference.. The implementation is largely similar to the one used by libc++.

Diff Detail

Repository
rL LLVM

Event Timeline

phosek created this revision.Apr 3 2017, 6:59 PM
phosek edited the summary of this revision. (Show Details)Apr 3 2017, 7:45 PM

Ping, can someone please look at this one as well?

beanz accepted this revision.Apr 5 2017, 2:01 PM

This looks reasonable to me.

This revision is now accepted and ready to land.Apr 5 2017, 2:01 PM
This revision was automatically updated to reflect the committed changes.
kaz7 added a subscriber: kaz7.Jan 19 2021, 5:11 AM

Hi, I have a question about this patch. I appreciate any answers. Thanks!

libcxxabi/trunk/cmake/config-ix.cmake
26

Hi!

Is it possible to ask about this implementation?

I'm trying to build libcxxabi.so and libclang_rt.builtins-ve.a for VE architecture. However, generated libcxxabi.so requires libclang_rt.builtins-ve.a for __multi3 function. Then, ld causes following errors, when I compile any c++ test programs using generated clang++, libc++.so, libcxxabi.so, and libclang_rt.builtins-ve.a. I think that this is an error trying to refer __multi3 function in libclang_rt.builtins-ve.a from libcxxabi.so.

/opt/nec/ve/bin/nld: cmTC_f428b: hidden symbol `__veabi_multi3' in /home/jam/llvm-upstream/install/lib/clang/12.0.0/lib/linux/libclang_rt.builtins-ve.a(multi3.c.o) is referenced by DSO
    /opt/nec/ve/bin/nld: final link failed: Bad value

In order to solve this problem, I can add following CMakefile code to link libcxxabi.so with libclang_rt.builtins-ve.a at build-time. It works fine for VE. But, I'm not sure whther this modification works for all other architectures or not. Or, I guess, there is better answer for this problem.

     list(APPEND CMAKE_REQUIRED_FLAGS -rtlib=compiler-rt)
     find_compiler_rt_library(builtins LIBCXXABI_BUILTINS_LIBRARY)
     list(APPEND CMAKE_REQUIRED_LIBRARIES "${LIBCXXABI_BUILTINS_LIBRARY}")
+    # CMAKE_REQUIRED_LIBRARIES is not used to link libc++abi.so, so
+    # append builtins to LIBCXXABI_SHARED_LIBRARIES too
+    list(APPEND LIBCXXABI_SHARED_LIBRARIES "${LIBCXXABI_BUILTINS_LIBRARY}")

I appreciate if you have any suggestions for me here. Thanks!

phosek added inline comments.Jan 19 2021, 10:46 AM
libcxxabi/trunk/cmake/config-ix.cmake
26

I think this is because no other target requires builtins, looks like VE architecture is the first one that does. Rather than using the LIBCXXABI_SHARED_LIBRARIES global variable, we prefer to set dependencies directly for each target which is a more modern CMake approach. See how this is implemented in libcxx: https://github.com/llvm/llvm-project/blob/cfc60730179042a93cb9cb338982e71d20707a24/libcxx/CMakeLists.txt#L750. I'd prefer to use a similar implementation for libcxxabi.

kaz7 added inline comments.Jan 19 2021, 3:47 PM
libcxxabi/trunk/cmake/config-ix.cmake
26

Thank you for your answer. That makes sense. I appreciate if you have time to modify it in described way. Or, I can try to modify config-ix.cmake following your suggestions. Please let me know which way is good for you. Thanks!

kaz7 added inline comments.Jan 24 2021, 5:36 AM
libcxxabi/trunk/cmake/config-ix.cmake
26

I was working on CMakeLists, but I've understood modifying libcxxabi/CMakeLists.txt similar to libcxx/CMakeLists.txt is not easy...

So, I'll submit a patch to modify only this config-ix.cmake. Thank you for your previous answer.