pkgsrc-Users archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

rpath not set correctly on aix when gcc invoked as linker



On aix, if a program is linked by calling gcc instead of ld, whether
gcc is invoked directly or via libtool, the rpath will not be properly
set, and runtime linking won't be enabled.

The problem is that _WRAP_CMD_SINK.CC is getting set to cmd-sink,
which doesn't do any of the special rpath handling that aix needs.
cmd-sink-aix-cc has the special rpath handling, but is specific to
IBM's C compiler, and won't work with gcc.

I've attached a patch that adds cmd-sink-aix-gcc, which copies the
rpath handling from cmd-sink-aix-cc.  It leaves out the bits of
cmd-sink-aix-cc that are specific to IBM's C compiler.  I also modify
the rpath so that /usr/lib and /lib are put on the end instead of the
beginning so that pkgsrc libs will be used in preference to system
libs.
Index: bsd.wrapper.mk
===================================================================
RCS file: /cvsroot/pkgsrc/mk/wrapper/bsd.wrapper.mk,v
retrieving revision 1.93
diff -u -r1.93 bsd.wrapper.mk
--- bsd.wrapper.mk	27 Apr 2015 19:59:07 -0000	1.93
+++ bsd.wrapper.mk	13 Feb 2016 06:48:55 -0000
@@ -311,6 +311,10 @@
 .if !empty(PKGSRC_COMPILER:Mgcc)
 _WRAP_TRANSFORM.CC=	${WRAPPER_TMPDIR}/transform-gcc
 _WRAP_TRANSFORM.CXX=	${_WRAP_TRANSFORM.CC}
+.  if ${OPSYS} == "AIX"
+_WRAP_CMD_SINK.CC=	${WRAPPER_TMPDIR}/cmd-sink-aix-gcc
+_WRAP_CMD_SINK.CXX=	${_WRAP_CMD_SINK.CC}
+.  endif
 .endif
 
 _WRAP_CMD_SINK.LD=		${WRAPPER_TMPDIR}/cmd-sink-ld
@@ -505,6 +509,7 @@
 	arg-pp-mipspro-cc \
 	arg-pp-sunpro-cxx \
 	cmd-sink-aix-cc \
+	cmd-sink-aix-gcc \
 	cmd-sink-aix-ld \
 	cmd-sink-aix-xlc \
 	cmd-sink-darwin-xlc \
Index: cmd-sink-aix-gcc
===================================================================
RCS file: cmd-sink-aix-gcc
diff -N cmd-sink-aix-gcc
--- /dev/null	1 Jan 1970 00:00:00 -0000
+++ cmd-sink-aix-gcc	13 Feb 2016 06:48:55 -0000
@@ -0,0 +1,111 @@
+# $NetBSD: cmd-sink-aix-gcc,v 1.9 2009/06/11 10:38:28 sno Exp $
+#
+# Copyright (c) 2005 The NetBSD Foundation, Inc.
+# All rights reserved.
+#
+# This code is derived from software contributed to The NetBSD Foundation
+# by Grant Beattie.
+#
+# Redistribution and use in source and binary forms, with or without
+# modification, are permitted provided that the following conditions
+# are met:
+# 1. Redistributions of source code must retain the above copyright
+#    notice, this list of conditions and the following disclaimer.
+# 2. Redistributions in binary form must reproduce the above copyright
+#    notice, this list of conditions and the following disclaimer in the
+#    documentation and/or other materials provided with the distribution.
+# 3. All advertising materials mentioning features or use of this software
+#    must display the following acknowledgement:
+#        This product includes software developed by the NetBSD
+#        Foundation, Inc. and its contributors.
+# 4. Neither the name of The NetBSD Foundation nor the names of its
+#    contributors may be used to endorse or promote products derived
+#    from this software without specific prior written permission.
+#
+# THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
+# ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
+# TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+# PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
+# BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+# CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+# SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+# INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+# CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+# ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+# POSSIBILITY OF SUCH DAMAGE.
+
+# Empty out the command buffer and build up the command line in $cmd.
+blibpath=
+orig_blibpath=
+dynamic=
+
+while ! queue_is_empty cmdbuf; do
+	pop_queue cmdbuf arg
+	$debug_log $wrapperlog "    (cmd-sink-aix-gcc) pop:  $arg"
+	case $arg in
+	-blibpath:*)
+		orig_blibpath=${arg#-blibpath:}
+		$debug_log $wrapperlog "    (cmd-sink-aix-gcc) drop: $dir [setting orig_blibpath]"
+		dynamic=yes
+		;;
+	-Wl,-blibpath:*)
+		orig_blibpath=${arg#-Wl,-blibpath:}
+		$debug_log $wrapperlog "    (cmd-sink-aix-gcc) drop: $dir [setting orig_blibpath]"
+		dynamic=yes
+		;;
+	##############################################################
+	# AIX ld(1) doesn't support -Wl,-rpath,* but accumulate them
+	# into a path collection we can later append to command line
+	# using -blibpath.
+	##############################################################
+	-R*|-Wl,-R*|-Wl,-rpath,*|-Wl,-rpath-link,*|-Wl,--rpath,*)
+		case $arg in
+		-R*)			R="-R" ;;
+		-Wl,-R*)		R="-Wl,-R" ;;
+		-Wl,-rpath,*)		R="-Wl,-rpath," ;;
+		-Wl,-rpath-link,*)	R="-Wl,-rpath-link," ;;
+		-Wl,--rpath,*)		R="-Wl,--rpath," ;;
+		esac
+		dir="${arg#$R}"
+		case "$blibpath" in
+		"")	blibpath="$dir" ;;
+		*)	blibpath="$blibpath:$dir" ;;
+		esac
+		$debug_log $wrapperlog "    (cmd-sink-aix-gcc) drop: $dir [adding to blibpath]"
+		dynamic=yes
+		;;
+	-rpath)
+		pop_queue cmdbuf dir
+		case $blibpath in
+		"")	blibpath="$dir" ;;
+		*)	blibpath="$blibpath:$dir" ;;
+		esac
+		$debug_log $wrapperlog "    (cmd-sink-aix-gcc) drop: $dir [adding to blibpath]"
+		;;
+	*)
+		. $buildcmd
+		;;
+	esac
+done
+
+# AIX ld(1) uses -blibpath to set the runtime library search path.
+arg="/usr/lib:/lib"
+if $test -n "$orig_blibpath"; then
+	arg="$orig_blibpath:$arg"
+fi
+if $test -n "$blibpath"; then
+        arg="$blibpath:$arg"
+fi
+arg="-Wl,-blibpath:$arg"
+$debug_log $wrapperlog "    (cmd-sink-aix-gcc) pop: $arg"
+. $buildcmd
+
+# If we are dynamically linking, make sure the runtime linker is used.
+if $test -n "$dynamic"; then
+	arg=-Wl,-brtl
+	$debug_log $wrapperlog "    (cmd-sink-aix-gcc) pop: $arg"
+	. $buildcmd
+	arg=-Wl,-bdynamic
+	$debug_log $wrapperlog "    (cmd-sink-aix-gcc) pop: $arg"
+	. $buildcmd
+fi


Home | Main Index | Thread Index | Old Index