LLVM r201936 restores the use of a relative rpath but this breaks LLDB
on FreeBSD. For now I've disabled CMAKE_BUILD_WITH_INSTALL_RPATH
locally until the fix can be found, in the top-level LLVM
CMakeLists.txt:
It seems probable that either ld flags aren't being set correctly to
indicate that $ORIGIN is in use, or that there's an issue in FreeBSD's
handling of $ORIGIN (on at least FreeBSD 9.2).
LLVM r201936 restores the use of a relative rpath but this breaks LLDB
on FreeBSD. For now I've disabled CMAKE_BUILD_WITH_INSTALL_RPATH
locally until the fix can be found, in the top-level LLVM
CMakeLists.txt:
It seems probable that either ld flags aren't being set correctly to
indicate that $ORIGIN is in use, or that there's an issue in FreeBSD's
handling of $ORIGIN (on at least FreeBSD 9.2).
Hi Rafael - normally I would wait until I had useful information to
post something like this, but I wanted to make sure anyone else who
runs into the same problem is aware that something's up and can work
around it in the short term.
Which library fails to load?
liblldb - here's what lld shows:
bin/lldb:
liblldb.so.3.5 => not found (0)
librt.so.1 => /usr/lib/librt.so.1 (0x80082f000)
libtinfo.so.5.9 => /usr/local/lib/libtinfo.so.5.9 (0x800a34000)
<and system and Python-related libraries>
The buildbot uses the configure build and is green, so it "works" I
guess -- but I do not know if it's using $ORIGIN or an absolute rpath,
and will have to wait until I can complete a configure build locally
to find out.
bin/lldb:
liblldb.so.3.5 => not found (0)
librt.so.1 => /usr/lib/librt.so.1 (0x80082f000)
libtinfo.so.5.9 => /usr/local/lib/libtinfo.so.5.9 (0x800a34000)
<and system and Python-related libraries>
The buildbot uses the configure build and is green, so it "works" I
guess -- but I do not know if it's using $ORIGIN or an absolute rpath,
and will have to wait until I can complete a configure build locally
to find out.
That is so strange. The Makefile.rules used by the configure build has
LD.Flags += $(RPATH) -Wl,'$$ORIGIN/../lib
so I would expect it to behave the same as the current cmake build.
This at least has a straightforward explanation -- for the configure
build my binary ends up with an rpath containing both the
$ORIGIN-based relative path as well as an absolute path:
OK. We should probably get the same to happen with cmake. What is the
command line used to link ./Debug+Asserts/bin/lldb? I assume the
relative path is being added by llvm's Makefile.rules. Is the absolute
one being added by lldb's?
Brand, is there a way to add to rpath from an inner CMakeLists.txt?
on each library or executable target as it is created. One may
append to an individual target's INSTALL_RPATH property or may
set CMAKE_INSTALL_RPATH in the current directory scope to influence
targets in the directory and below.
IIUC the reason LLVM can use BUILD_WITH_INSTALL_RPATH is because
it is careful to lay out the build tree binaries the same way as
they appear in the install tree so $ORIGIN/../lib works in both
places. If LLDB is building externally then its binaries will not
appear in the right relative location to use that RPATH. It could
consider using INSTALL_RPATH_USE_LINK_PATH:
LLVM r201936 restores the use of a relative rpath but this breaks LLDB
on FreeBSD. For now I've disabled CMAKE_BUILD_WITH_INSTALL_RPATH
locally until the fix can be found, in the top-level LLVM
CMakeLists.txt:
I found out what the problem is -- the -zorigin flag isn't being
passed to the linker, so the ORIGIN flag isn't set. I guess either
the GNU runtime linker doesn't check, or a later version of GNU ld
sets the flag automatically; either way, FreeBSD needs -zorigin. I
applied this patch:
diff --git a/CMakeLists.txt b/CMakeLists.txt
index 2ce214a..86bb4c5 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -445,6 +445,7 @@ if (APPLE)
else(UNIX)
if(NOT DEFINED CMAKE_INSTALL_RPATH)
set(CMAKE_INSTALL_RPATH "\$ORIGIN/../lib")
+ set(CMAKE_EXE_LINKER_FLAGS "-Wl,-zorigin")
endif(NOT DEFINED CMAKE_INSTALL_RPATH)
endif()
I found out what the problem is -- the -zorigin flag isn't being
passed to the linker, so the ORIGIN flag isn't set. I guess either
the GNU runtime linker doesn't check, or a later version of GNU ld
sets the flag automatically; either way, FreeBSD needs -zorigin. I
applied this patch:
Interesting. Where is that coming from in the configure build? I don't
see it anywhere in llvm or lldb.
It isn't being set in the configure build. With the configure build
rtld first fails on the $ORIGIN due to the missing flag, but still
finds the library via the the "backup" absolute path. It will still
need an equivalent change.
It isn't being set in the configure build. With the configure build
rtld first fails on the $ORIGIN due to the missing flag, but still
finds the library via the the "backup" absolute path. It will still
need an equivalent change.
Ah, OK.
So, this is not lldb specific (the -DBUILD_SHARED_LIBS=ON build is
probably broken on freebsd right now). It seems to be freebsd specific
(i don't see zorigin anywhere in binutils). Maybe what we should do is
apply the attached patch to llvm?
True. My thinking was that there is probably no reason not to have it,
but the fact that it is not implicit in freebsd probably means there
is a reason for not having it sometimes.
Based on this I think that FreeBSD's rtld is actually in the wrong
here, and an executable's rpath that contains $ORIGIN should undergo
substitution, regardless of the state of the DF_ORIGIN flag. If I
understand correctly DF_ORIGIN should be necessary only in the case of
an executable that does not use $ORIGIN in an rpath, but later
dlopen()s a library that does.
That said, it still seems safe to just set the flag always.