This is an archive of the discontinued LLVM Phabricator instance.

Do not set an RPATH on statically-linked LLVM executables.
AbandonedPublic

Authored by rsmith on Jun 20 2019, 7:25 PM.

Details

Summary

This RPATH breaks the ability to run executables from the build area if
the host compiler provides a libc++ and we also build an
ABI-incompatible libc++ as part of the same monorepo compilation.

(This only works around the problem, which still exists for the
LLVM_ENABLE_SHARED configuration.)

Event Timeline

rsmith created this revision.Jun 20 2019, 7:25 PM
Herald added a project: Restricted Project. · View Herald TranscriptJun 20 2019, 7:25 PM

(Will likely need more eyes than just mine -- RPATH is mostly a mystery to me...)

llvm/cmake/modules/AddLLVM.cmake
758

Just to make sure I understand correctly, *any* time we build a shared library of some form, we'll get here? Even if its libclang.so or some such?

Provided I've understood correctly, then this make sense. However, I wonder, won't this still fail for things like c-index-test?

mgorny requested changes to this revision.Jun 20 2019, 8:26 PM
mgorny added inline comments.
llvm/cmake/modules/AddLLVM.cmake
756

I think this is also needed when building with BUILD_SHARED_LIBS. Possibly also when the target explicitly links to one of the shared-only libraries.

This revision now requires changes to proceed.Jun 20 2019, 8:26 PM
rnk added a comment.Jun 21 2019, 8:59 AM

This RPATH breaks the ability to run executables from the build area if
the host compiler provides a libc++ and we also build an
ABI-incompatible libc++ as part of the same monorepo compilation.

This is the RPATH we set:

set(_install_rpath "\$ORIGIN/../lib${LLVM_LIBDIR_SUFFIX}" ${extra_libdir})

I believe LLVM_LIBDIR_SUFFIX is typically empty.

This is a pretty normal convention, and it should work from the build directory and the install directory. It just says, if there are shared libraries, go to ${root}/bin/../lib/ and search for any shared libs there first.

I think maybe we shouldn't build libc++, and any other shared libraries that might conflict with system shared libraries, into ${builddir}/lib. Don't we install libcxx into lib/clang/9.0.0/lib/... in the end anyway, or is libcxx not treated as a compiler runtime library?

llvm/cmake/modules/AddLLVM.cmake
756

Yep.

758

I think we only come here for executables, but yes, your concern about c-index-test seems warranted. In the standard, static configuration, libclang seems to be a shared library, and c-index-test links to it. Without the rpath, it probably won't find it. But, this code sets the "install rpath", and I think cmake actually goes back and tweaks the rpath when it does the install step, so maybe this won't affect that.

In D63637#1553781, @rnk wrote:

I think maybe we shouldn't build libc++, and any other shared libraries that might conflict with system shared libraries, into ${builddir}/lib.

Yeah, that'd be my preference, but Chandler pointed out that that would be surprising for people who build libc++ in order to use it with GCC. Maybe we can solve that problem with better build logic, though.

Don't we install libcxx into lib/clang/9.0.0/lib/... in the end anyway, or is libcxx not treated as a compiler runtime library?

We don't appear to. I think that would be reasonable for Clang's uses, but I don't think we have any meaningful idea of whether we're building libc++ standalone or as a Clang runtime.

Perhaps (for a monorepo checkout):

  • Default to building runtime libraries into the clang runtimes directory
  • Provide a flag to build standalone runtimes
  • If the flag is specified, then runtimes instead go into <build area>/lib, and we implicitly disable the build of llvm, clang, lldb, lld, and so on in that checkout (eg, llvm_add_executable and llvm_add_library could add build rules that fail with a suitable error).

If we run cmake directly on (eg) the libc++ directory (not as part of a llvm + clang build), it could still default to building standalone runtimes.

Would that make sense?

rsmith abandoned this revision.Jun 21 2019, 3:29 PM