NetBSD Problem Report #37228

From he@bean.urc.uninett.no  Fri Oct 26 23:20:35 2007
Return-Path: <he@bean.urc.uninett.no>
Received: from mail.netbsd.org (mail.netbsd.org [204.152.190.11])
	by narn.NetBSD.org (Postfix) with ESMTP id B2F7363BA35
	for <gnats-bugs@gnats.NetBSD.org>; Fri, 26 Oct 2007 23:20:35 +0000 (UTC)
Message-Id: <20071026221531.20C9241A42@bean.urc.uninett.no>
Date: Sat, 27 Oct 2007 00:15:30 +0200 (CEST)
From: he@NetBSD.org
Reply-To: he@NetBSD.org
To: gnats-bugs@NetBSD.org
Subject: pkgsrc reorders -l<lib> relative to -Wl,-Bstatic / -Wl,-Bdynamic
X-Send-Pr-Version: 3.95

>Number:         37228
>Category:       pkg
>Synopsis:       pkgsrc reorders -l<lib> relative to -Wl,-Bstatic / -Wl,-Bdynamic
>Confidential:   no
>Severity:       serious
>Priority:       medium
>Responsible:    pkg-manager
>State:          closed
>Class:          sw-bug
>Submitter-Id:   net
>Arrival-Date:   Fri Oct 26 23:25:00 +0000 2007
>Closed-Date:    Thu Nov 08 17:49:42 +0000 2007
>Last-Modified:  Thu Nov 08 17:49:42 +0000 2007
>Originator:     Havard Eidnes
>Release:        NetBSD 4.0_RC3 / pkgsrc-current
>Organization:
	I try...
>Environment:
System: NetBSD bean.urc.uninett.no 4.0_RC3 NetBSD 4.0_RC3 (GENERIC.MP) #3: Tue Oct 23 13:25:19 CEST 2007 he@bean.urc.uninett.no:/usr/obj/sys/arch/i386/compile/GENERIC.MP i386
Architecture: i386
Machine: i386
>Description:
	A package I am trying to build is peculiar in that it wants
	to link some libraries statically and some dynamically when
	building a shared object.

	The wrapper system in pkgsrc makes this difficult.
	The reason is that the -Wl,-Bstatic / -Wl,-Bdynamic arguments
	are left in their place in the compiler command, while all
	the libraries referenced via -l<lib> are collected and put at
	the end of the command line, thus disrupting the ordering of
	the "link dynamically" and "link statically" arguments.

>How-To-Repeat:
	Try to package a program which wants to do as specified above;
	watch it fail.  Turning on WRAPPER_DEBUG=yes in the environment
	exposes the problem when the compiler commands are collected in
	work/.work.log.

>Fix:
	This is a non-portable hack but it mirrors how I tweaked the
	package's work/.wrapper/tmp/buildcmd script.  It does however
	illustrate a working workaround.

Index: buildcmd
===================================================================
RCS file: /u/nb/pkgsrc/mk/wrapper/buildcmd,v
retrieving revision 1.1
diff -u -r1.1 buildcmd
--- buildcmd	21 Sep 2004 15:01:41 -0000	1.1
+++ buildcmd	26 Oct 2007 22:13:59 -0000
@@ -55,6 +55,16 @@
 		;;
 	esac
 	;;
+######################################################################
+# Preserve and duplicate the -Wl,-Bstatic / -Wl,-Bdynamic arguments,
+# but also preserve their presence and order relative to the list
+# of libraries.  Someone may want to mix static and dynamic linking.
+######################################################################
+-Wl,-Bdynamic|-Wl,-Bstatic*)
+	shquote "$arg"; arg="$shquoted"
+	cmd="$cmd $arg"
+	libs="$libs $arg"
+	;;
 -l*)
 	case $libs in
 	*" "$arg)

>Release-Note:

>Audit-Trail:
From: Havard Eidnes <he@NetBSD.org>
To: gnats-bugs@NetBSD.org
Cc: pkg-manager@netbsd.org, pkgsrc-bugs@netbsd.org
Subject: Re: pkg/37228: pkgsrc reorders -l<lib> relative to -Wl,-Bstatic /
 -Wl,-Bdynamic
Date: Thu, 08 Nov 2007 14:54:50 +0100 (CET)

 Hi,

 some further context information on this case:

 The mk/wrapper/wrapper.sh script contains

 reorder=3D${WRAPPER_REORDER-no}

 which appears to imply that reordering of the command arguments
 is by default disabled ("set to no"), and I've verified that
 WRAPPER_REORDER is indeed unset in my case, so we end up with
 "reorder=3Dno".

 However, the mk/wrapper/buildcmd script will still reorders many
 of the arguments, among them putting all the libraries at the end
 of the command line, and thus exposing the problem documented in
 this PR, irrespective of the value of "reorder" at the point
 where it's used.

 It is not evident what the intention is here, i.e. whether the
 arguments should not have been reordered if "reorder=3Dno", but the
 current behaviour appears to be somewhat internally inconsistent.

 Regards,

 - H=E5vard

From: Havard Eidnes <he@netbsd.org>
To: gnats-bugs@NetBSD.org
Cc: 
Subject: PR/37228 CVS commit: pkgsrc/mk/wrapper
Date: Thu,  8 Nov 2007 17:38:17 +0000 (UTC)

 Module Name:	pkgsrc
 Committed By:	he
 Date:		Thu Nov  8 17:38:17 UTC 2007

 Modified Files:
 	pkgsrc/mk/wrapper: buildcmd

 Log Message:
 Preserve the -Wl,-Bstatic / -Wl,-Bdynamic arguments, but also
 duplicate them into the list of libraries.  Someone may want to mix
 static and dynamic linking.

 Fixes PR#37228, approved by jlam.

 jlam says that a better long-term fix would be to ensure that all
 the -L specifications come before the -l specifications, instead
 of moving all the -l specifications to the end of the command line.


 To generate a diff of this commit:
 cvs rdiff -r1.1 -r1.2 pkgsrc/mk/wrapper/buildcmd

 Please note that diffs are not public domain; they are subject to the
 copyright notices on the relevant files.

State-Changed-From-To: open->closed
State-Changed-By: he@netbsd.org
State-Changed-When: Thu, 08 Nov 2007 17:49:42 +0000
State-Changed-Why:
Fix committed after private exchange with jlam.


>Unformatted:

NetBSD Home
NetBSD PR Database Search

(Contact us) $NetBSD: query-full-pr,v 1.51 2026/08/10 02:28:17 riastradh Exp $
$NetBSD: gnats_config.sh,v 1.10 2026/05/13 22:00:09 riastradh Exp $
Copyright © 1994-2026 The NetBSD Foundation, Inc. ALL RIGHTS RESERVED.