Bug 176901

Summary: [bsd.cmake.mk] disable rpath removal
Product: Ports & Packages Reporter: Dmitry Marakasov <amdmi3>
Component: Individual Port(s)Assignee: Dmitry Marakasov <amdmi3>
Status: Closed FIXED    
Severity: Affects Only Me    
Priority: Normal    
Version: Latest   
Hardware: Any   
OS: Any   
Attachments:
Description Flags
bsd.cmake.mk.patch none

Description Dmitry Marakasov freebsd_committer freebsd_triage 2013-03-13 01:50:00 UTC
When cmake builds a binary or a library, it adds an RPATH to it pointing to the build directory. This is needed so when a binary is ran from the build directory, it's able to find all its libraries without using LD_LIBRARY_PATH.

When cmake installs binaries, RPATHs are removed, as installed software will pick its libraries from the systemwide path known to dynamic linker. However, cmake removes _all_ RPATHs, including ones explicitly provided via e.g. LDFLAGS.

The problem arises when the port is build with newer gcc (USE_GCC=4.6+). The resulting binaries may depend on C++ features (for example, C++11 bits) support for whuch is only present in newer gcc's libstdc++ (/usr/local/lib/gcc46/libstdc++.so), but not in the base system /usr/lib/libstdc++.so. The former rpath is added by bsd.gcc.mk, but it has no effect as cmake removes it. In result, a binary will use /usr/lib/libstdc++.so, and won't run with the following message:

/usr/lib/libstdc++.so.6: version GLIBCXX_3.4.11 required by <binary> not found

This may be fixed by adding LD_LIBRARY_PATH=/usr/local/lib/gcc46 to the environement.

To fix that globally I propose the attached path. It disables adding build rpath to the binaries (we don't need it since ports are not intended to be ran from work/ anyway), which as well makes cmake _not_ remove RPATHs from installed binaries. With it, binaries use correct libstdc++ from the newer gcc and run without LD_LIBRARY_PATH hacks.

I'm not sure which side effects it may have, so exp-run is advised.
Comment 1 Edwin Groothuis freebsd_committer freebsd_triage 2013-03-13 01:50:12 UTC
Responsible Changed
From-To: freebsd-ports-bugs->kde

bsd.cmake.mk is kde territory (via the GNATS Auto Assign Tool)
Comment 2 Andriy Gapon freebsd_committer freebsd_triage 2013-03-13 06:57:38 UTC
Perhaps it's better to use CMAKE_INSTALL_RPATH_USE_LINK_PATH=TRUE.
This is what I've been doing for ages.
This page has a rather good description of CMake's handling of RPATH:
http://www.cmake.org/Wiki/CMake_RPATH_handling

Advantage of CMAKE_INSTALL_RPATH_USE_LINK_PATH is that it allows both to use
in-tree paths during build and to keep out-of-tree paths during installation.
So, setting this variable should both achieve the desired effect for
installation and preserve the current behavior during build.

What do you think?
-- 
Andriy Gapon
Comment 3 Dmitry Marakasov 2013-04-17 19:02:52 UTC
* Andriy Gapon (avg@FreeBSD.org) wrote:
> 
> Perhaps it's better to use CMAKE_INSTALL_RPATH_USE_LINK_PATH=TRUE.
> This is what I've been doing for ages.
> This page has a rather good description of CMake's handling of RPATH:
> http://www.cmake.org/Wiki/CMake_RPATH_handling
> 
> Advantage of CMAKE_INSTALL_RPATH_USE_LINK_PATH is that it allows both to use
> in-tree paths during build and to keep out-of-tree paths during installation.
> So, setting this variable should both achieve the desired effect for
> installation and preserve the current behavior during build.
> 
> What do you think?

Yes, that looks better. It seems that I've picked the first suitable
option, while there could've be better ones.

Anyway, we need this in the tree pretty much ASAP.

Updated patch:

--- cmake.mk.patch begins here ---
Index: Mk/Uses/cmake.mk
===================================================================
--- Mk/Uses/cmake.mk	(revision 315999)
+++ Mk/Uses/cmake.mk	(working copy)
@@ -88,7 +88,8 @@
 			-DCMAKE_SHARED_LINKER_FLAGS:STRING="${LDFLAGS}" \
 			-DCMAKE_INSTALL_PREFIX:PATH="${PREFIX}" \
 			-DCMAKE_BUILD_TYPE:STRING="${CMAKE_BUILD_TYPE}" \
-			-DTHREADS_HAVE_PTHREAD_ARG:BOOL=YES
+			-DTHREADS_HAVE_PTHREAD_ARG:BOOL=YES \
+			-DCMAKE_INSTALL_RPATH_USE_LINK_PATH=YES
 
 .if defined(BATCH) || defined(PACKAGE_BUILDING)
 CMAKE_VERBOSE=		yes
--- cmake.mk.patch ends here ---

-- 
Dmitry Marakasov   .   55B5 0596 FF1E 8D84 5F56  9510 D35A 80DD F9D2 F77D
amdmi3@amdmi3.ru  ..:  jabber: amdmi3@jabber.ru    http://www.amdmi3.ru
Comment 4 Bryan Drewery freebsd_committer freebsd_triage 2013-09-27 20:17:09 UTC
Responsible Changed
From-To: kde->bdrewery

Take for exp-run
Comment 5 Bryan Drewery freebsd_committer freebsd_triage 2013-09-28 16:18:26 UTC
Responsible Changed
From-To: bdrewery->amdmi3

exp-run done, no new failures on a head build
Comment 6 sean_bruno 2013-12-18 01:07:54 UTC
This definitely fixes user issues with audio/clementine-player on
stable/9 as it needs newer gcc to deal with the c++11 stuffs which
requires not stripping the clementine-player binary.

sean
Comment 7 dfilter service freebsd_committer freebsd_triage 2013-12-22 14:04:43 UTC
Author: makc
Date: Sun Dec 22 14:04:37 2013
New Revision: 337190
URL: http://svnweb.freebsd.org/changeset/ports/337190

Log:
  - Don't remove rpath from binaries during install [1]
  - Remove outdated comment
  
  PR:		ports/176901 [1]
  Submitted by:	amdmi3, avg
  Exp-run by:	bdrewery

Modified:
  head/Mk/Uses/cmake.mk

Modified: head/Mk/Uses/cmake.mk
==============================================================================
--- head/Mk/Uses/cmake.mk	Sun Dec 22 13:50:38 2013	(r337189)
+++ head/Mk/Uses/cmake.mk	Sun Dec 22 14:04:37 2013	(r337190)
@@ -35,10 +35,6 @@
 #			Debug otherwise
 # CMAKE_SOURCE_PATH	- Path to the source directory
 #			Default: ${WRKSRC}
-#
-# Deprecated variables:
-# CMAKE_OUTSOURCE	- Instruct to perform an out-of-source build.
-#			Deprecated, use 'USES+=	cmake:outsource' instead.
 
 .if !defined(_INCLUDE_USES_CMAKE_MK)
 _INCLUDE_USES_CMAKE_MK=	yes
@@ -88,7 +84,8 @@ CMAKE_ARGS+=		-DCMAKE_C_COMPILER:STRING=
 			-DCMAKE_SHARED_LINKER_FLAGS:STRING="${LDFLAGS}" \
 			-DCMAKE_INSTALL_PREFIX:PATH="${PREFIX}" \
 			-DCMAKE_BUILD_TYPE:STRING="${CMAKE_BUILD_TYPE}" \
-			-DTHREADS_HAVE_PTHREAD_ARG:BOOL=YES
+			-DTHREADS_HAVE_PTHREAD_ARG:BOOL=YES \
+			-DCMAKE_INSTALL_RPATH_USE_LINK_PATH=YES
 
 .if defined(BATCH) || defined(PACKAGE_BUILDING)
 CMAKE_VERBOSE=		yes
_______________________________________________
svn-ports-all@freebsd.org mailing list
http://lists.freebsd.org/mailman/listinfo/svn-ports-all
To unsubscribe, send any mail to "svn-ports-all-unsubscribe@freebsd.org"
Comment 8 Max Brazhnikov freebsd_committer freebsd_triage 2013-12-22 14:22:49 UTC
State Changed
From-To: open->closed

Committed! Thanks a lot to all involved!