NetBSD-Bugs archive

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

Re: pkg/51400: bootstrap 32 bits in NetBSD amd64



This happens because the libfetch build tries, via the rules in
pkgtools/bootstrap-mk-files/files/bsd.lib.mk, to do:

	${LD} -r ${.TARGET}.o -o ${.TARGET}

i.e.:

	ld -r common.o.o -o common.o

Since common.o.o was built with -m32 because of the `--abi 32'
bootstrap argument, it's an i386 binary.  But the system ld expects to
be creating an amd64 output.  To make it produce an i386 output, we
have to additionally specify `-m elf_i386' to ld.

The attached patch does this (and creates the infrastructure to do it
for other architectures).  Since it's somewhat late in the branch
cycle, I think I'll hold off on committing it until January.
From 5828dee6b34fa382d8e61294b91bc96c9dec3a0f Mon Sep 17 00:00:00 2001
From: Taylor R Campbell <riastradh%NetBSD.org@localhost>
Date: Mon, 11 Dec 2023 00:42:17 +0000
Subject: [PATCH] mk/platform/NetBSD.mk: Handle i386-on-amd64 builds.

XXX This should be extended to other compat32-on-64bit builds, and
the wackier variations on that theme one finds in MIPS systems -- may
require spelunking through the ld emulation schemes in GNU binutils.

PR pkg/51400
---
 mk/bsd.prefs.mk       |  5 +++++
 mk/platform/NetBSD.mk | 12 ++++++++++++
 2 files changed, 17 insertions(+)

diff --git a/mk/bsd.prefs.mk b/mk/bsd.prefs.mk
index 9b7954ebebca..fbd067b8def7 100644
--- a/mk/bsd.prefs.mk
+++ b/mk/bsd.prefs.mk
@@ -158,6 +158,11 @@ MACHINE_GNU_ARCH?=		${GNU_ARCH.${MACHINE_ARCH}:U${MACHINE_ARCH}}
 .if ${NATIVE_OPSYS} == "NetBSD"
 NATIVE_LOWER_OPSYS?=	netbsd
 
+.  if !defined(HOST_MACHINE_ARCH)
+HOST_MACHINE_ARCH!=	${UNAME} -m
+MAKEFLAGS+=		HOST_MACHINE_ARCH=${HOST_MACHINE_ARCH:Q}
+.  endif
+
 .elif ${NATIVE_OPSYS} == "AIX"
 .  if exists(/usr/bin/oslevel)
 _NATIVE_OS_VERSION!=	/usr/bin/oslevel
diff --git a/mk/platform/NetBSD.mk b/mk/platform/NetBSD.mk
index 5c40361b16bb..8484fa18708a 100644
--- a/mk/platform/NetBSD.mk
+++ b/mk/platform/NetBSD.mk
@@ -223,3 +223,15 @@ _OPSYS_CAN_CHECK_SSP=		no  # only supports libssp at this time
 # check for maximum command line length and set it in configure's environment,
 # to avoid a test required by the libtool script that takes forever.
 _OPSYS_MAX_CMDLEN_CMD=	/sbin/sysctl -n kern.argmax
+
+# ABI selection.  (XXX Can we do this in terms of ${ABI} instead of
+# ${MACHINE_ARCH} vs ${HOST_MACHINE_ARCH} (uname -m)?  Complication is
+# I don't know how to get the value of ${ABI} that ld is configured for
+# by default.)
+_OPSYS_LDEMUL.i386=		elf_i386
+
+.if ${MACHINE_ARCH} != ${HOST_MACHINE_ARCH} && \
+    defined(_OPSYS_LDEMUL.${MACHINE_ARCH})
+_WRAP_EXTRA_ARGS.LD+=	-m ${_OPSYS_LDEMUL.${MACHINE_ARCH}}
+CWRAPPERS_APPEND.ld+=	-m ${_OPSYS_LDEMUL.${MACHINE_ARCH}}
+.endif


Home | Main Index | Thread Index | Old Index