NetBSD Problem Report #60000

From www@netbsd.org  Fri Feb 13 08:04:00 2026
Return-Path: <www@netbsd.org>
Received: from mail.netbsd.org (mail.netbsd.org [199.233.217.200])
	(using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)
	 key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256
	 client-signature RSA-PSS (2048 bits) client-digest SHA256)
	(Client CN "mail.netbsd.org", Issuer "R13" (verified OK))
	by mollari.NetBSD.org (Postfix) with ESMTPS id 12BD21A9239
	for <gnats-bugs@gnats.NetBSD.org>; Fri, 13 Feb 2026 08:04:00 +0000 (UTC)
Message-Id: <20260213080358.C35371A923C@mollari.NetBSD.org>
Date: Fri, 13 Feb 2026 08:03:58 +0000 (UTC)
From: campbell+netbsd@mumble.net
Reply-To: campbell+netbsd@mumble.net
To: gnats-bugs@NetBSD.org
Subject: split debug data rules broke ${.TARGET}-dependent flags
X-Send-Pr-Version: www-1.0
X-From4GNATS: "campbell+netbsd@mumble.net via gnats" <gnats-admin@NetBSD.org>

>Number:         60000
>Category:       toolchain
>Synopsis:       split debug data rules broke ${.TARGET}-dependent flags
>Confidential:   no
>Severity:       serious
>Priority:       medium
>Responsible:    toolchain-manager
>State:          pending-pullups
>Class:          sw-bug
>Submitter-Id:   net
>Arrival-Date:   Fri Feb 13 08:05:00 +0000 2026
>Closed-Date:    
>Last-Modified:  Sat Feb 14 16:10:01 +0000 2026
>Originator:     Taylor R Campbell
>Release:        current, 11?
>Organization:
The ${.TARGET}BSD Foundation
>Environment:
>Description:

	Once upon a time, we built program foo and its debug data
	foo.debug by two recipes, which roughly reduce to:

foo: foo.o bar.o baz.o
	ld -o foo foo.o bar.o baz.o ${LDFLAGS}

foo.debug: foo
	objcopy --only-keep-debug foo foo.debug
	objcopy --strip-debug \
	    -p -R .gnu_debuglink --add-gnu-debuglink=foo.debug \
	    foo

	The foo.debug rule is troublesome, though, because it
	overwrites foo in place -- this breaks parallel runs and
	changes the mtime of foo.debug's own prerequisite foo.

	To fix this, I split it into three recipes with appropriate
	dependencies:

foo.link: foo.o bar.o baz.o
	ld -o foo foo.o bar.o baz.o ${LDFLAGS}

foo.debug: foo.link
	objcopy --only-keep-debug foo.link foo.debug

foo: foo.link
	objcopy --strip-debug \
	    -p -R .gnu_debuglink --add-gnu-debuglink=foo.debug \
	    foo.link foo

	Unfortunately, this change had a side effect: any
	${.TARGET}-dependent expansion in LDFLAGS is now different,
	because previously ${.TARGET} was `foo' and now ${.TARGET} is
	`foo.link'.  So logic like this changed:

LDFLAGS+=	${"${LDSTATIC.${.TARGET}}" == "-static" :? : ${PIE_LDFLAGS}}

https://nxr.netbsd.org/xref/src/share/mk/bsd.prog.mk?r=1.361#41

	Before, if you defined LDSTATIC.foo=-static, it would prevent
	LDFLAGS from having `-pie' added.  But after the change, you
	would have to define LDSTATIC.foo.link=-static to have the same
	effect.

>How-To-Repeat:

	cd src/tests/lib/csu && nbmake-$MACHINE h_initfini2

	This should be a static _non-pie_ because LDSTATIC.h_initfini2
	is set to `-static', but instead it is built as a static pie.

>Fix:

	1. Audit all the .TARGET-dependent variables.
	2. In this case, consider instead using:

.for _P in ${PROGS}
LDFLAGS.${_P}+=	${"${LDSTATIC.${_P}}" == "-static" :? : ${PIE_LDFLAGS}}
.endfor

>Release-Note:

>Audit-Trail:
From: Taylor R Campbell <riastradh@NetBSD.org>
To: gnats-bugs@NetBSD.org, netbsd-bugs@NetBSD.org
Cc: Nick Hudson <skrll@NetBSD.org>
Subject: Re: toolchain/60000: split debug data rules broke ${.TARGET}-dependent flags
Date: Fri, 13 Feb 2026 08:11:36 +0000

 This is a multi-part message in MIME format.
 --=_3GH/d8a4GiEuk6sY511/abKYWvHzDwXu

 Attached patch aims to fix this.  I searched for `.${.TARGET}' and
 this is the only one that came up, so maybe we're already otherwise
 clean of this problem.

 --=_3GH/d8a4GiEuk6sY511/abKYWvHzDwXu
 Content-Type: text/plain; charset="ISO-8859-1"; name="pr60000-bsdprogmkldstaticpie"
 Content-Transfer-Encoding: quoted-printable
 Content-Disposition: attachment; filename="pr60000-bsdprogmkldstaticpie.patch"

 # HG changeset patch
 # User Taylor R Campbell <riastradh@NetBSD.org>
 # Date 1770970107 0
 #      Fri Feb 13 08:08:27 2026 +0000
 # Branch trunk
 # Node ID f083a332526e1831201892f13204a6af0aabba6c
 # Parent  1b592182187334d0db950753ee819bfab9e74ed8
 # EXP-Topic riastradh-pr60000-bsdprogmkldstaticpie
 bsd.prog.mk: Respect LDSTATIC.${PROG}, not LDSTATIC.${PROG}.link.

 PR toolchain/60000: split debug data rules broke ${.TARGET}-dependent
 flags

 diff -r 1b5921821873 -r f083a332526e share/mk/bsd.prog.mk
 --- a/share/mk/bsd.prog.mk	Fri Feb 13 05:26:10 2026 +0000
 +++ b/share/mk/bsd.prog.mk	Fri Feb 13 08:08:27 2026 +0000
 @@ -38,7 +38,7 @@ CLEANFILES+=3D a.out [Ee]rrs mklog core *.
  .if defined(MKPIE) && (${MKPIE} !=3D "no") && !defined(NOPIE)
  CFLAGS+=3D	${PIE_CFLAGS}
  AFLAGS+=3D	${PIE_AFLAGS}
 -LDFLAGS+=3D	${"${LDSTATIC.${.TARGET}}" =3D=3D "-static" :? : ${PIE_LDFLAGS=
 }}
 +# PIE_LDFLAGS added on a per-PROG basis below depending on LDSTATIC.${PROG}
  .endif
 =20
  CFLAGS+=3D	${COPTS}
 @@ -470,6 +470,7 @@ PAXCTL_FLAGS.${_P}=3D +a
  _DPADD.${_P}=3D		${DPADD}    ${DPADD.${_P}}
  _LDADD.${_P}=3D		${LDADD}    ${LDADD.${_P}}
  _LDFLAGS.${_P}=3D		${LDFLAGS}  ${LDFLAGS.${_P}}
 +_LDFLAGS.${_P}+=3D	${"${LDSTATIC.${_P}}" =3D=3D "-static" :? : ${PIE_LDFLA=
 GS}}
  .if ${MKSANITIZER} !=3D "yes"
  # Sanitizers don't support static build.
  _LDSTATIC.${_P}=3D	${LDSTATIC} ${LDSTATIC.${_P}}

 --=_3GH/d8a4GiEuk6sY511/abKYWvHzDwXu--

From: "Nick Hudson" <skrll@netbsd.org>
To: gnats-bugs@gnats.NetBSD.org
Cc: 
Subject: PR/60000 CVS commit: src/share/mk
Date: Fri, 13 Feb 2026 15:59:52 +0000

 Module Name:	src
 Committed By:	skrll
 Date:		Fri Feb 13 15:59:51 UTC 2026

 Modified Files:
 	src/share/mk: bsd.prog.mk

 Log Message:
 bsd.prog.mk: Respect LDSTATIC.${PROG}, not LDSTATIC.${PROG}.link.

 PR toolchain/60000: split debug data rules broke ${.TARGET}-dependent
 flags

 From riastradh@


 To generate a diff of this commit:
 cvs rdiff -u -r1.361 -r1.362 src/share/mk/bsd.prog.mk

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

State-Changed-From-To: open->pending-pullups
State-Changed-By: skrll@NetBSD.org
State-Changed-When: Fri, 13 Feb 2026 16:01:05 +0000
State-Changed-Why:
fix committed


From: "Taylor R Campbell" <riastradh@netbsd.org>
To: gnats-bugs@gnats.NetBSD.org
Cc: 
Subject: PR/60000 CVS commit: src/share/mk
Date: Sat, 14 Feb 2026 16:07:25 +0000

 Module Name:	src
 Committed By:	riastradh
 Date:		Sat Feb 14 16:07:25 UTC 2026

 Modified Files:
 	src/share/mk: bsd.prog.mk

 Log Message:
 bsd.prog.mk: Respect LDSTATIC.${PROG}, not LDSTATIC.${PROG}.link.

 Take two: make sure to do this only if we're actually making PIEs.

 PR toolchain/60000: split debug data rules broke ${.TARGET}-dependent
 flags


 To generate a diff of this commit:
 cvs rdiff -u -r1.363 -r1.364 src/share/mk/bsd.prog.mk

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

>Unformatted:

NetBSD Home
NetBSD PR Database Search

(Contact us) $NetBSD: query-full-pr,v 1.47 2022/09/11 19:34:41 kim Exp $
$NetBSD: gnats_config.sh,v 1.9 2014/08/02 14:16:04 spz Exp $
Copyright © 1994-2026 The NetBSD Foundation, Inc. ALL RIGHTS RESERVED.