NetBSD Problem Report #57685

From www@netbsd.org  Tue Nov  7 12:19:28 2023
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))
	(Client CN "mail.NetBSD.org", Issuer "mail.NetBSD.org CA" (not verified))
	by mollari.NetBSD.org (Postfix) with ESMTPS id ABCF01A9238
	for <gnats-bugs@gnats.NetBSD.org>; Tue,  7 Nov 2023 12:19:28 +0000 (UTC)
Message-Id: <20231107121927.2D3E71A9239@mollari.NetBSD.org>
Date: Tue,  7 Nov 2023 12:19:27 +0000 (UTC)
From: cryintothebluesky@gmail.com
Reply-To: cryintothebluesky@gmail.com
To: gnats-bugs@NetBSD.org
Subject: Pkgsrc bootstrap does not  correctly apply custom LDFLAGS to binaries
X-Send-Pr-Version: www-1.0

>Number:         57685
>Category:       pkg
>Synopsis:       Pkgsrc bootstrap does not  correctly apply custom LDFLAGS to binaries
>Confidential:   no
>Severity:       serious
>Priority:       medium
>Responsible:    pkg-manager
>State:          open
>Class:          sw-bug
>Submitter-Id:   net
>Arrival-Date:   Tue Nov 07 12:20:00 +0000 2023
>Originator:     Sad Clouds
>Release:        pkgsrc-2023Q3
>Organization:
>Environment:
SunOS pkgsrc 5.11 11.3 sun4v sparc SUNW,SPARC-Enterprise-T5220
>Description:
I have a custom GCC compiler installed under /opt/gcc-13.2.0/

I use the following script to bootstrap pkgsrc:

MAKE_JOBS=64
GCC_VER="13.2.0"
GCC_BASE="/opt/gcc-${GCC_VER:?}"
NETBSD_BASE="/opt/netbsd"
PKGSRC_VER="2023Q3"
PKGSRC_BASE="${NETBSD_BASE:?}/pkgsrc-${PKGSRC_VER:?}"
PKG_BASE="/opt/pkg-${PKGSRC_VER:?}"
PATH="${GCC_BASE:?}/bin:${GCC_BASE:?}/devutils/bin:${PKG_BASE:?}/bin:${PKG_BASE:?}/sbin:/bin:/usr/bin:/sbin:/usr/sbin"
export PATH

env \
MAKECONF="" \
DISTDIR="${NETBSD_BASE:?}/pkg.distfiles" \
PKGSRC_COMPILER=gcc \
USE_NATIVE_GCC=yes \
CC=gcc \
CXX=g++ \
CFLAGS="-O2 -mcpu=v9" \
CXXFLAGS="-O2 -mcpu=v9" \
LDFLAGS="\
-L${GCC_BASE:?}/lib \
-R${GCC_BASE:?}/lib \
-L${GCC_BASE:?}/lib/sparcv9 \
-R${GCC_BASE:?}/lib/sparcv9" \
"${PKGSRC_BASE:?}/bootstrap/bootstrap" \
--prefer-pkgsrc yes \
--make-jobs "${MAKE_JOBS:?}" \
--workdir "${NETBSD_BASE:?}/pkg.objects/bootstrap" \
--prefix "${PKG_BASE:?}" \
--pkgdbdir "${PKG_BASE:?}/db/pkg"

However LDFLAGS are not applied correctly and bootstrap binaries reference wrong GCC libssp.so under /usr/lib/64

# ldd /opt/pkg-2023Q3/bin/bmake
        libssp.so.0 =>   /usr/lib/64/libssp.so.0
        libc.so.1 =>     /lib/64/libc.so.1

# elfdump -d /opt/pkg-2023Q3/bin/bmake | grep PATH
      [4]  RUNPATH         0x1c12       /opt/pkg-2023Q3/lib
      [5]  RPATH           0x1c12       /opt/pkg-2023Q3/lib

So my custom RPATH is stripped and only pkgsrc lib remains there.
>How-To-Repeat:

>Fix:
Workaround is to create the following GCC wrappers:

# cat /tmp/gcc /tmp/g++
#!/bin/sh
GCC_BASE="/opt/gcc-13.2.0"
exec ${GCC_BASE:?}/bin/gcc "$@" \
  -L${GCC_BASE:?}/lib -R${GCC_BASE:?}/lib \
  -L${GCC_BASE:?}/lib/sparcv9 -R${GCC_BASE:?}/lib/sparcv9
#!/bin/sh
GCC_BASE="/opt/gcc-13.2.0"
exec ${GCC_BASE:?}/bin/g++ "$@" \
  -L${GCC_BASE:?}/lib -R${GCC_BASE:?}/lib \
  -L${GCC_BASE:?}/lib/sparcv9 -R${GCC_BASE:?}/lib/sparcv9

This results in correct linkage:
# ldd /opt/pkg-2023Q3/bin/bmake
        libssp.so.0 =>   /opt/gcc-13.2.0/lib/sparcv9/libssp.so.0
        libc.so.1 =>     /lib/64/libc.so.1

However, pkgsrc make files need proper fix in order to correctly use custom LDFLAGS.

PS. I have used GCC wrapper scripts for years with pkgsrc, due to these types of issues, but recently decided to try LDFLAGS again, hoping this was fixed. Alas, the issue is still there.

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-2023 The NetBSD Foundation, Inc. ALL RIGHTS RESERVED.