Index | Thread | Search

From:
Klemens Nanni <kn@openbsd.org>
Subject:
Re: binutils: enable ld.bfd ?
To:
Frederic Cambus <fred@statdns.com>, ports <ports@openbsd.org>
Date:
Sat, 13 Dec 2025 15:54:19 +0000

Download raw body.

Thread
04.12.2025 22:11, Klemens Nanni пишет:
> 03.12.2025 23:20, Jeremie Courreges-Anglas пишет:
>> On Mon, Dec 01, 2025 at 10:12:36PM +0000, Klemens Nanni wrote:
>>> 30.11.2025 19:17, Klemens Nanni пишет:
>>>> 30.11.2025 18:58, Jeremie Courreges-Anglas пишет:
>>>>> Nothing depends on binutils at the moment.  Indeed this port will need
>>>>> some tweaks on some architectures (backports from base probably).
>>>>> Sigh.  Maybe restricting this to amd64 and arm64 is more reasonable
>>>>> indeed...
>>>>
>>>> Yes, hence my uncertainty as to what's the best approach here.
>>>
>>> I'm starting to prefer a small subset of archs;  the Makefile bits are
>>> not much and so far only two would use ld.bfd, so looking into build
>>> failures on archs like arm is eating time that I'd like to spend on
>>> productive stuff instead.
>>
>> ack, but...
>>
>>>>
>>>>> I wonder if it would be less effort to provide a stripped down
>>>>> binutils port for bare x86_64, like arm-none-eabi/binutils.  Care to
>>>>> show your ipxe port and how it is currently using gld from binutils?
>>>>
>>>> - "new net/ipxe" https://marc.info/?l=openbsd-ports&m=176381141712670&w=2
>>>> - https://github.com/jasperla/openbsd-wip/tree/master/net/ipxe
>>>>   (since got updated and gained .iso images, rest is the same)
>>>>
>>>> tl;dr:  Usual COMPILER* for gcc15 and AS=gas, etc. via MAKE_FLAGS.
>>>>
>>>>>> Could someone please give this a try on anything other than:
>>>>>> arm64 amd64 i386 octeon?
>>>>>
>>>>> Builds and packages on sparc64
>>>>
>>>> Thanks!
>>>>
>>>>> The list of "safe" architectures where we could enable gld without
>>>>> patches can probably be determined, but gotta head out now.
>>>>
>>>> I'll try to cover more architectures.
>>>
>>> riscv64 builds fine as-is, arm needs the equivalent to arm64's configure.tgt
>>> patch, but then further fails with
>>>
>>> earmelf_obsd.c:56:5: error: non-void function 'gldarmelf_obsd_get_script' should return a value [-Wreturn-mismatch]
>>>    56 |     return
>>>       |     ^
>>>
>>> Oddly enough, that file does not exist under WRKDIR.
>>
>> That error I can reproduce on arm64, using your diff from
>> https://marc.info/?l=openbsd-ports&m=176451477006648&w=2
>>
>> The build process isn't very helpful since it actively deletes the
>> source file.  It seems retrying with a random number of make jobs
>> makes it build, but I wouldn't vouch for the quality of the end
>> result...
> 
> I see it now as well... it doesn't always fail for me, guess I got (un)lucky.
> 
> Thanks for testing!
> 
>>
>> Do you have a diff that works on amd64 and arm64?
> 
> Not yet, I'll try to find the culprit on arm64 and come back this weekend.
Well... haven't found a solution (yet), so my proposal is to build ld.bfd
only on amd64 until the arm64/gmake/whatever bug is fixed.

Diff is the same and includes the patch needed for arm64, I merely omitted
it from LD_ARCHS and added a comment.

OK?

Index: Makefile
===================================================================
RCS file: /cvs/ports/devel/binutils/Makefile,v
diff -u -p -r1.23 Makefile
--- Makefile	29 Nov 2025 18:11:04 -0000	1.23
+++ Makefile	13 Dec 2025 15:52:43 -0000
@@ -3,7 +3,7 @@ COMMENT =	GNU binary utilities
 # keep version synchronized with devel/gas
 V =		2.45.1
 DISTNAME =	binutils-${V}
-REVISION =	0
+REVISION =	1
 
 CATEGORIES =	devel
 
@@ -28,13 +28,23 @@ CONFIGURE_STYLE =	gnu
 
 CONFIGURE_ARGS +=	--disable-gas \
 			--disable-gprof \
-			--disable-ld \
 			--disable-libctf \
 			--disable-nls \
 			--disable-install-libbfd \
 			--program-prefix=g \
 			--without-msgpack \
 			--with-system-zlib
+
+SEPARATE_BUILD =	Yes
+
+# XXX arm64 sporadically fails, rerunning make eventually builds
+LD_ARCHS =		amd64
+SUBST_VARS =		LD_ARCHS
+.if ${LD_ARCHS:M${MACHINE_ARCH}}
+PKG_ARGS =		-Dld=1
+.else
+CONFIGURE_ARGS +=	--disable-ld
+.endif
 
 USE_GMAKE =	Yes
 
Index: patches/patch-ld_configure_tgt
===================================================================
RCS file: patches/patch-ld_configure_tgt
diff -N patches/patch-ld_configure_tgt
--- /dev/null	1 Jan 1970 00:00:00 -0000
+++ patches/patch-ld_configure_tgt	13 Dec 2025 15:51:24 -0000
@@ -0,0 +1,15 @@
+recognise arm64
+
+Index: ld/configure.tgt
+--- ld/configure.tgt.orig
++++ ld/configure.tgt
+@@ -98,6 +98,9 @@ aarch64-*-freebsd*)	targ_emul=aarch64fbsd
+ aarch64-*-fuchsia*)	targ_emul=aarch64elf
+ 			targ_extra_emuls="aarch64elfb armelf armelfb"
+ 			;;
++aarch64-*-openbsd*)	targ_emul=aarch64obsd
++			targ_extra_emuls="aarch64obsdb aarch64elf"
++			;;
+ aarch64_be-*-linux-gnu_ilp32)
+ 			targ_emul=aarch64linux32b
+ 			targ_extra_libpath="aarch64linuxb aarch64linux aarch64linux32 armelfb_linux_eabi armelf_linux_eabi"
Index: pkg/DESCR
===================================================================
RCS file: /cvs/ports/devel/binutils/pkg/DESCR,v
diff -u -p -r1.1.1.1 DESCR
--- pkg/DESCR	7 Aug 2022 20:44:09 -0000	1.1.1.1
+++ pkg/DESCR	13 Dec 2025 15:49:54 -0000
@@ -4,6 +4,7 @@ This package contains the following GNU 
 - ar - A utility for creating, modifying and extracting from archives.
 - c++filt - Filter to demangle encoded C++ symbols.
 - elfedit - Update ELF header and program property of ELF files.
+- ld - Links files. (only on ${LD_ARCHS})
 - nm - Lists symbols from object files.
 - objcopy - Copies and translates object files.
 - objdump - Displays information from object files.
Index: pkg/PLIST
===================================================================
RCS file: /cvs/ports/devel/binutils/pkg/PLIST,v
diff -u -p -r1.4 PLIST
--- pkg/PLIST	24 Sep 2025 17:03:55 -0000	1.4
+++ pkg/PLIST	13 Dec 2025 15:49:54 -0000
@@ -28,3 +28,4 @@
 @man man/man1/gstrip.1
 @comment @man man/man1/gwindmc.1
 @comment @man man/man1/gwindres.1
+%%ld%%