This is an archive of the discontinued LLVM Phabricator instance.

[CMake] Fix libc++abi __aeabi_idiv() link error.
AbandonedPublic

Authored by logan on Aug 31 2016, 8:40 AM.

Details

Summary

This commit fixes __aeabi_idiv() link error when we are building
libc++abi with compiler-rt.

When compiler-rt is enabled, the option --rtlib=compiler-rt will be
added to link flags. However, if -nodefaultlibs is specified
simultaneously, --rtlib will be ignored and compiler-rt libraries will
not be linked. Consequently, several ARM built-in functions, e.g.
__aeabi_idiv(), will not be available.

Diff Detail

Event Timeline

logan updated this revision to Diff 69864.Aug 31 2016, 8:40 AM
logan retitled this revision from to [CMake] Fix libc++abi __aeabi_idiv() link error..
logan updated this object.
logan added reviewers: mclow.lists, rengolin, EricWF.
logan added a subscriber: cfe-commits.
rengolin edited edge metadata.Aug 31 2016, 11:14 AM

This looks like a work around the fact that --rtlib is being ignored with --nodefaultlibs. I'm not sure that's a sane behaviour, if you explicitly specify --rtlib.

EricWF edited edge metadata.Sep 3 2016, 7:11 PM

This is not correct. We need the -nodefaultlibs on most platforms to prevent libstdc++ from being linked. I think the correct fix is to change --rtlib=<foo>

logan added a comment.Sep 6 2016, 4:05 AM

Hi @rengolin and @EricWF,

After tracing the commit log of clang, it seems that --rtlib= is ignored intentionally when -nodefaultlibs is present. (see also: rL254535)

And, unfortunately, we don't have a command line option to ask clang to link compiler-rt built-in library along (regardless the -nodefaultlibs option.)

One solution might be adding the libclang_rt.builtins.${arch}.a detection rules[1] to CMakeLists.txt, and manually specify -lclang_rt.builtins-${arch}.a when LIBCXXABI_USE_COMPILER_RT is enabled. How do you think about this solution?

[1] There is a function named ToolChain::getCompilerRT() in ${clang}/lib/Driver/ToolChain.cpp which is responsible to detect and pick the correct compiler-rt library.

EricWF added a comment.Sep 6 2016, 4:23 AM

One solution might be adding the libclang_rt.builtins.${arch}.a detection rules[1] to CMakeLists.txt, and manually specify -lclang_rt.builtins-${arch}.a when LIBCXXABI_USE_COMPILER_RT is enabled. How do you think about this solution?

That SGTM. There's a similar workaround in libc++ to link the sanitizer run-times on OS X (found here).

One solution might be adding the libclang_rt.builtins.${arch}.a detection rules[1] to CMakeLists.txt, and manually specify -lclang_rt.builtins-${arch}.a when LIBCXXABI_USE_COMPILER_RT is enabled. How do you think about this solution?

That SGTM. There's a similar workaround in libc++ to link the sanitizer run-times on OS X (found here).

+1

Was this abandoned? Merged?

logan added a comment.Dec 15 2016, 8:59 AM

Sorry, I don't have time to work on this recently. Here's the plan:

  1. Add another flag to specify the path to libclang_rt-builtin.a.
  1. If that flag was not specified and the compiler is clang, then run clang -### to extract for -L option and -l option for libclang_rt-builtin.a.
  1. If neither (1) nor (2) are available, then report an error.

I hope I can get back to this next week.

logan abandoned this revision.Jun 29 2018, 8:24 PM